Class: RLSL::Prism::DefinitionInferer
- Inherits:
-
Object
- Object
- RLSL::Prism::DefinitionInferer
- Defined in:
- lib/rlsl/prism/type_inference/definition_inferer.rb
Instance Method Summary collapse
- #infer_assignment(node) ⇒ Object
- #infer_global_decl(node) ⇒ Object
- #infer_multiple_assignment(node) ⇒ Object
- #infer_var_decl(node) ⇒ Object
-
#initialize(infer:, register:, collection_type_resolver:) ⇒ DefinitionInferer
constructor
A new instance of DefinitionInferer.
Constructor Details
#initialize(infer:, register:, collection_type_resolver:) ⇒ DefinitionInferer
Returns a new instance of DefinitionInferer.
6 7 8 9 10 |
# File 'lib/rlsl/prism/type_inference/definition_inferer.rb', line 6 def initialize(infer:, register:, collection_type_resolver:) @infer = infer @register = register @collection_type_resolver = collection_type_resolver end |
Instance Method Details
#infer_assignment(node) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rlsl/prism/type_inference/definition_inferer.rb', line 19 def infer_assignment(node) @infer.call(node.target) @infer.call(node.value) node.type = node.value.type node end |
#infer_global_decl(node) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/rlsl/prism/type_inference/definition_inferer.rb', line 26 def infer_global_decl(node) @infer.call(node.initializer) if node.initializer node.type ||= @collection_type_resolver.resolve_global_decl(node) @register.call(node.name, node.type) if node.type node end |
#infer_multiple_assignment(node) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/rlsl/prism/type_inference/definition_inferer.rb', line 33 def infer_multiple_assignment(node) @infer.call(node.value) @collection_type_resolver.assign_multiple_targets(node) node.type = nil node end |
#infer_var_decl(node) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/rlsl/prism/type_inference/definition_inferer.rb', line 12 def infer_var_decl(node) @infer.call(node.initializer) if node.initializer node.type ||= node.initializer&.type @register.call(node.name, node.type) if node.type node end |