123456789_123456789_123456789_123456789_123456789_

Class: RBS::Resolver::ConstantResolver::Table

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/resolver/constant_resolver.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(environment) ⇒ Table

[ GitHub ]

  
# File 'lib/rbs/resolver/constant_resolver.rb', line 10

def initialize(environment)
  @children_table = {}
  @toplevel = {}

  @constants_table = {}

  environment.class_decls.each_key do |name|
    children_table[name] = {}
  end

  environment.class_decls.each do |name, entry|
    unless name.namespace.empty?
      parent = name.namespace.to_type_name

      table = children_table[parent] or raise
      constant = constant_of_module(name, entry)
    else
      table = toplevel
      constant = constant_of_module(name, entry)
    end

    table[name.name] = constant
    constants_table[name] = constant
  end

  environment.constant_decls.each do |name, entry|
    unless name.namespace.empty?
      parent = name.namespace.to_type_name

      table = children_table[parent] or raise
      constant = constant_of_constant(name, entry)
    else
      table = toplevel
      constant = constant_of_constant(name, entry)
    end

    table[name.name] = constant
  end
end

Instance Attribute Details

#children_table (readonly)

[ GitHub ]

  
# File 'lib/rbs/resolver/constant_resolver.rb', line 7

attr_reader :children_table, :toplevel

#constants_table (readonly)

[ GitHub ]

  
# File 'lib/rbs/resolver/constant_resolver.rb', line 8

attr_reader :constants_table

#toplevel (readonly)

[ GitHub ]

  
# File 'lib/rbs/resolver/constant_resolver.rb', line 7

attr_reader :children_table, :toplevel

Instance Method Details

#children(name)

[ GitHub ]

  
# File 'lib/rbs/resolver/constant_resolver.rb', line 50

def children(name)
  children_table[name]
end

#constant(name)

[ GitHub ]

  
# File 'lib/rbs/resolver/constant_resolver.rb', line 54

def constant(name)
  constants_table[name]
end

#constant_of_constant(name, entry)

[ GitHub ]

  
# File 'lib/rbs/resolver/constant_resolver.rb', line 67

def constant_of_constant(name, entry)
  Constant.new(name: name, type: entry.decl.type, entry: entry)
end

#constant_of_module(name, entry)

[ GitHub ]

  
# File 'lib/rbs/resolver/constant_resolver.rb', line 58

def constant_of_module(name, entry)
  type = Types::ClassSingleton.new(
    name: name,
    location: nil
  )

  Constant.new(name: name, type: type, entry: entry)
end