Class: RBS::Resolver::ConstantResolver::Table
- Inherits:
-
Object
- Object
- RBS::Resolver::ConstantResolver::Table
- Defined in:
- lib/rbs/resolver/constant_resolver.rb
Instance Attribute Summary collapse
-
#children_table ⇒ Object
readonly
Returns the value of attribute children_table.
-
#constants_table ⇒ Object
readonly
Returns the value of attribute constants_table.
-
#toplevel ⇒ Object
readonly
Returns the value of attribute toplevel.
Instance Method Summary collapse
- #children(name) ⇒ Object
- #constant(name) ⇒ Object
- #constant_of_constant(name, entry) ⇒ Object
- #constant_of_module(name, entry) ⇒ Object
-
#initialize(environment) ⇒ Table
constructor
A new instance of Table.
Constructor Details
#initialize(environment) ⇒ Table
Returns a new instance of Table.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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 ⇒ Object (readonly)
Returns the value of attribute children_table.
7 8 9 |
# File 'lib/rbs/resolver/constant_resolver.rb', line 7 def children_table @children_table end |
#constants_table ⇒ Object (readonly)
Returns the value of attribute constants_table.
8 9 10 |
# File 'lib/rbs/resolver/constant_resolver.rb', line 8 def constants_table @constants_table end |
#toplevel ⇒ Object (readonly)
Returns the value of attribute toplevel.
7 8 9 |
# File 'lib/rbs/resolver/constant_resolver.rb', line 7 def toplevel @toplevel end |
Instance Method Details
#children(name) ⇒ Object
50 51 52 |
# File 'lib/rbs/resolver/constant_resolver.rb', line 50 def children(name) children_table[name] end |
#constant(name) ⇒ Object
54 55 56 |
# File 'lib/rbs/resolver/constant_resolver.rb', line 54 def constant(name) constants_table[name] end |
#constant_of_constant(name, entry) ⇒ Object
67 68 69 |
# 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) ⇒ Object
58 59 60 61 62 63 64 65 |
# 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 |