Class: Yoda::Typing::Inferencer::Tracer
- Inherits:
-
Object
- Object
- Yoda::Typing::Inferencer::Tracer
- Defined in:
- lib/yoda/typing/inferencer/tracer.rb
Defined Under Namespace
Classes: MaskedMap
Instance Attribute Summary collapse
- #environment ⇒ Model::Environment readonly
- #generator ⇒ Types::Generator readonly
- #node_to_constants ⇒ Hash{ AST::Node => Array<Store::Objects::Base> } readonly
- #node_to_context ⇒ Hash{ AST::Node => Context } readonly
- #node_to_kind ⇒ Hash{ AST::Node => Symbol } readonly
- #node_to_method_candidates ⇒ Hash{ AST::Node => Array<FunctionSignatures::Base> } readonly
- #node_to_receiver_type ⇒ Hash{ AST::Node => Types::Type } readonly
- #node_to_require_paths ⇒ Hash{ AST::Node => Array<String> } readonly
- #node_to_tree ⇒ Hash{ AST::Node => Tree::Base } readonly
- #node_to_type ⇒ Hash{ AST::Node => Types::Base } readonly
Instance Method Summary collapse
- #bind_constants(node:, constants:) ⇒ Object
- #bind_context(node:, context:) ⇒ Object
- #bind_local_variable(variable:, type:, context:) ⇒ Object
- #bind_method_definition(node:, method_candidates:) ⇒ Object
- #bind_require_paths(node:, require_paths:) ⇒ Object
- #bind_send(node:, receiver_type:, method_candidates:) ⇒ Object
- #bind_tree(node:, tree:) ⇒ Object
- #bind_type(node:, type:, context:) ⇒ Object
- #constants(node) ⇒ Array<Store::Objects::Base>
- #context(node) ⇒ Contexts::BaseContext?
- #context_variable_objects(node) ⇒ Hash{ Symbol => Store::Objects::Base }
- #context_variable_types(node) ⇒ Hash{ Symbol => Types::Base }
-
#initialize(environment:, generator:) ⇒ Tracer
constructor
A new instance of Tracer.
- #kind(node) ⇒ Symbol?
- #method_candidates(node) ⇒ Array<FunctionSignatures::Wrapper>
- #node_info(node) ⇒ NodeInfo
- #objects(node) ⇒ Array<Store::Objects::Base>
- #receiver_type(node) ⇒ Types::Type
- #require_paths(node) ⇒ Array<String>
- #tree(node) ⇒ Tree::Base?
- #type(node) ⇒ Types::Type
Constructor Details
#initialize(environment:, generator:) ⇒ Tracer
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 63 def initialize(environment:, generator:) @environment = environment @generator = generator @node_to_kind = MaskedMap.new @node_to_tree = MaskedMap.new @node_to_type = MaskedMap.new @node_to_context = MaskedMap.new @node_to_method_candidates = MaskedMap.new @node_to_receiver_type = MaskedMap.new @node_to_constants = MaskedMap.new @node_to_require_paths = MaskedMap.new end |
Instance Attribute Details
#environment ⇒ Model::Environment (readonly)
6 7 8 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 6 def environment @environment end |
#generator ⇒ Types::Generator (readonly)
9 10 11 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 9 def generator @generator end |
#node_to_constants ⇒ Hash{ AST::Node => Array<Store::Objects::Base> } (readonly)
30 31 32 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 30 def node_to_constants @node_to_constants end |
#node_to_context ⇒ Hash{ AST::Node => Context } (readonly)
21 22 23 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 21 def node_to_context @node_to_context end |
#node_to_kind ⇒ Hash{ AST::Node => Symbol } (readonly)
12 13 14 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 12 def node_to_kind @node_to_kind end |
#node_to_method_candidates ⇒ Hash{ AST::Node => Array<FunctionSignatures::Base> } (readonly)
27 28 29 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 27 def node_to_method_candidates @node_to_method_candidates end |
#node_to_receiver_type ⇒ Hash{ AST::Node => Types::Type } (readonly)
24 25 26 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 24 def node_to_receiver_type @node_to_receiver_type end |
#node_to_require_paths ⇒ Hash{ AST::Node => Array<String> } (readonly)
33 34 35 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 33 def node_to_require_paths @node_to_require_paths end |
#node_to_tree ⇒ Hash{ AST::Node => Tree::Base } (readonly)
15 16 17 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 15 def node_to_tree @node_to_tree end |
#node_to_type ⇒ Hash{ AST::Node => Types::Base } (readonly)
18 19 20 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 18 def node_to_type @node_to_type end |
Instance Method Details
#bind_constants(node:, constants:) ⇒ Object
125 126 127 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 125 def bind_constants(node:, constants:) node_to_constants[node.identifier] = constants end |
#bind_context(node:, context:) ⇒ Object
92 93 94 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 92 def bind_context(node:, context:) node_to_context[node.identifier] = context end |
#bind_local_variable(variable:, type:, context:) ⇒ Object
99 100 101 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 99 def bind_local_variable(variable:, type:, context:) # nop end |
#bind_method_definition(node:, method_candidates:) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 116 def bind_method_definition(node:, method_candidates:) fail TypeError, method_candidates unless method_candidates.all? { |candidate| candidate.is_a?(Model::FunctionSignatures::Wrapper) } node_to_kind[node.identifier] = :send node_to_method_candidates[node.identifier] = method_candidates end |
#bind_require_paths(node:, require_paths:) ⇒ Object
131 132 133 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 131 def bind_require_paths(node:, require_paths:) node_to_require_paths[node.identifier] = require_paths end |
#bind_send(node:, receiver_type:, method_candidates:) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 106 def bind_send(node:, receiver_type:, method_candidates:) fail TypeError, method_candidates unless method_candidates.all? { |candidate| candidate.is_a?(Model::FunctionSignatures::Wrapper) } node_to_kind[node.identifier] = :send node_to_receiver_type[node.identifier] = receiver_type node_to_method_candidates[node.identifier] = method_candidates end |
#bind_tree(node:, tree:) ⇒ Object
79 80 81 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 79 def bind_tree(node:, tree:) node_to_tree[node.identifier] = tree end |
#bind_type(node:, type:, context:) ⇒ Object
86 87 88 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 86 def bind_type(node:, type:, context:) node_to_type[node.identifier] = type end |
#constants(node) ⇒ Array<Store::Objects::Base>
179 180 181 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 179 def constants(node) node_to_constants[node.identifier] || [] end |
#context(node) ⇒ Contexts::BaseContext?
191 192 193 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 191 def context(node) node_to_context[node.identifier] end |
#context_variable_objects(node) ⇒ Hash{ Symbol => Store::Objects::Base }
203 204 205 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 203 def context_variable_objects(node) context(node)&.type_binding&.all_variables&.transform_values { |type| type.value.referred_objects } || {} end |
#context_variable_types(node) ⇒ Hash{ Symbol => Types::Base }
197 198 199 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 197 def context_variable_types(node) context(node)&.type_binding&.all_variables || {} end |
#kind(node) ⇒ Symbol?
137 138 139 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 137 def kind(node) node_to_kind[node.identifier] end |
#method_candidates(node) ⇒ Array<FunctionSignatures::Wrapper>
173 174 175 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 173 def method_candidates(node) node_to_method_candidates[node.identifier] || [] end |
#node_info(node) ⇒ NodeInfo
155 156 157 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 155 def node_info(node) NodeInfo.new(node: node, tracer: self) end |
#objects(node) ⇒ Array<Store::Objects::Base>
161 162 163 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 161 def objects(node) type(node).value.referred_objects end |
#receiver_type(node) ⇒ Types::Type
167 168 169 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 167 def receiver_type(node) node_to_receiver_type[node.identifier] || generator.unknown_type(reason: "not traced") end |
#require_paths(node) ⇒ Array<String>
185 186 187 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 185 def require_paths(node) node_to_require_paths[node.identifier] || [] end |
#tree(node) ⇒ Tree::Base?
143 144 145 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 143 def tree(node) node_to_tree[node.identifier] end |
#type(node) ⇒ Types::Type
149 150 151 |
# File 'lib/yoda/typing/inferencer/tracer.rb', line 149 def type(node) node_to_type[node.identifier] || generator.unknown_type(reason: "not traced") end |