Class: RLSL::Prism::ControlFlowInferer
- Inherits:
-
Object
- Object
- RLSL::Prism::ControlFlowInferer
- Defined in:
- lib/rlsl/prism/type_inference/control_flow_inferer.rb
Instance Method Summary collapse
- #infer_for_loop(node) ⇒ Object
- #infer_function_definition(node) ⇒ Object
- #infer_if_statement(node) ⇒ Object
- #infer_return(node) ⇒ Object
- #infer_ternary(node) ⇒ Object
- #infer_while_loop(node) ⇒ Object
-
#initialize(infer:, infer_child_scope:, infer_in_scope:) ⇒ ControlFlowInferer
constructor
A new instance of ControlFlowInferer.
Constructor Details
#initialize(infer:, infer_child_scope:, infer_in_scope:) ⇒ ControlFlowInferer
Returns a new instance of ControlFlowInferer.
6 7 8 9 10 |
# File 'lib/rlsl/prism/type_inference/control_flow_inferer.rb', line 6 def initialize(infer:, infer_child_scope:, infer_in_scope:) @infer = infer @infer_child_scope = infer_child_scope @infer_in_scope = infer_in_scope end |
Instance Method Details
#infer_for_loop(node) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rlsl/prism/type_inference/control_flow_inferer.rb', line 35 def infer_for_loop(node) @infer.call(node.range_start) @infer.call(node.range_end) @infer_in_scope.call(node.variable => :int) do @infer.call(node.body) end node.type = nil node end |
#infer_function_definition(node) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rlsl/prism/type_inference/control_flow_inferer.rb', line 54 def infer_function_definition(node) @infer_in_scope.call(node.param_types) do @infer.call(node.body) node.return_type ||= node.body&.type node.type = node.return_type end node end |
#infer_if_statement(node) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/rlsl/prism/type_inference/control_flow_inferer.rb', line 12 def infer_if_statement(node) @infer.call(node.condition) @infer_child_scope.call(node.then_branch) @infer_child_scope.call(node.else_branch) if node.else_branch node.type = node.then_branch.type node end |
#infer_return(node) ⇒ Object
29 30 31 32 33 |
# File 'lib/rlsl/prism/type_inference/control_flow_inferer.rb', line 29 def infer_return(node) @infer.call(node.expression) if node.expression node.type = node.expression&.type node end |
#infer_ternary(node) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rlsl/prism/type_inference/control_flow_inferer.rb', line 21 def infer_ternary(node) @infer.call(node.condition) @infer.call(node.then_expr) @infer.call(node.else_expr) node.type = node.then_expr.type node end |
#infer_while_loop(node) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/rlsl/prism/type_inference/control_flow_inferer.rb', line 47 def infer_while_loop(node) @infer.call(node.condition) @infer_child_scope.call(node.body) node.type = nil node end |