Class: Idl::ConditionalReturnStatementAst
- Includes:
- Returns
- Defined in:
- lib/idl/ast.rb
Instance Method Summary collapse
- #condition ⇒ Object
-
#initialize(input, interval, return_expression, condition) ⇒ ConditionalReturnStatementAst
constructor
A new instance of ConditionalReturnStatementAst.
- #return_expression ⇒ Object
-
#return_type(symtab) ⇒ Type
The actual return type.
-
#return_types(symtab) ⇒ Array<Type>
List of actual return types.
-
#return_value(symtab) ⇒ Integer, ...
Evaluate the compile-time return value of this node, or, if the node does not return (e.g., because it is an IfAst but there is no return on the taken path), execute the node and update the symtab.
-
#return_values(symtab) ⇒ Array<Integer>, Array<Boolean>
Evaluate all possible compile-time return values of this node, or, if the node does not return (e.g., because it is an IfAst but there is no return on a possible path), execute the node and update the symtab.
- #to_idl ⇒ Object
-
#type_check(symtab) ⇒ void
type check this node and all children.
Constructor Details
#initialize(input, interval, return_expression, condition) ⇒ ConditionalReturnStatementAst
Returns a new instance of ConditionalReturnStatementAst.
4096 4097 4098 |
# File 'lib/idl/ast.rb', line 4096 def initialize(input, interval, return_expression, condition) super(input, interval, [return_expression, condition]) end |
Instance Method Details
#condition ⇒ Object
4094 |
# File 'lib/idl/ast.rb', line 4094 def condition = @children[1] |
#return_expression ⇒ Object
4093 |
# File 'lib/idl/ast.rb', line 4093 def return_expression = @children[0] |
#return_type(symtab) ⇒ Type
Returns The actual return type.
4108 4109 4110 |
# File 'lib/idl/ast.rb', line 4108 def return_type(symtab) return_expression.return_type(symtab) end |
#return_types(symtab) ⇒ Array<Type>
Returns List of actual return types.
4113 4114 4115 |
# File 'lib/idl/ast.rb', line 4113 def return_types(symtab) return_expression.return_types(symtab) end |
#return_value(symtab) ⇒ Integer, ...
Evaluate the compile-time return value of this node, or, if the node does not return (e.g., because it is an IfAst but there is no return on the taken path), execute the node and update the symtab
4119 4120 4121 4122 4123 4124 4125 4126 4127 |
# File 'lib/idl/ast.rb', line 4119 def return_value(symtab) cond = condition.value(symtab) if cond return_expression.return_value(symtab) else nil end end |
#return_values(symtab) ⇒ Array<Integer>, Array<Boolean>
Evaluate all possible compile-time return values of this node, or, if the node does not return (e.g., because it is an IfAst but there is no return on a possible path), execute the node and update the symtab
4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 |
# File 'lib/idl/ast.rb', line 4130 def return_values(symtab) value_result = value_try do cond = condition.value(symtab) return cond ? return_expression.return_values(symtab) : EMPTY_ARRAY end value_else(value_result) do # condition isn't known, so the return value is always possible return_expression.return_values(symtab) end end |
#to_idl ⇒ Object
4143 |
# File 'lib/idl/ast.rb', line 4143 def to_idl = "#{return_expression.to_idl} if (#{condition.to_idl});" |
#type_check(symtab) ⇒ void
This method returns an undefined value.
type check this node and all children
Calls to #type and/or #value may depend on type_check being called first with the same symtab. If not, those functions may raise an AstNode::InternalError
4101 4102 4103 4104 4105 |
# File 'lib/idl/ast.rb', line 4101 def type_check(symtab) condition.type_check(symtab) type_error "Condition must be boolean" unless condition.type(symtab).kind == :boolean return_expression.type_check(symtab) end |