Class: Idl::ConditionalStatementAst
Overview
represents a predicated simple statement
for example:
a = 2 if condition;
Instance Method Summary collapse
- #action ⇒ Object
- #condition ⇒ Object
-
#execute(symtab) ⇒ void
“execute” the statement by updating the variables in the symbol table.
-
#execute_unknown(symtab) ⇒ void
“execute” the statement by updating the variables in the symbol table.
-
#initialize(input, interval, action, condition) ⇒ ConditionalStatementAst
constructor
A new instance of ConditionalStatementAst.
-
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree).
-
#type_check(symtab) ⇒ void
type check this node and all children.
Constructor Details
#initialize(input, interval, action, condition) ⇒ ConditionalStatementAst
Returns a new instance of ConditionalStatementAst.
3799 3800 3801 |
# File 'lib/idl/ast.rb', line 3799 def initialize(input, interval, action, condition) super(input, interval, [action, condition]) end |
Instance Method Details
#action ⇒ Object
3796 |
# File 'lib/idl/ast.rb', line 3796 def action = @children[0] |
#condition ⇒ Object
3797 |
# File 'lib/idl/ast.rb', line 3797 def condition = @children[1] |
#execute(symtab) ⇒ void
This method returns an undefined value.
“execute” the statement by updating the variables in the symbol table
3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 |
# File 'lib/idl/ast.rb', line 3811 def execute(symtab) value_result = value_try do cond = condition.value(symtab) if (cond) action.execute(symtab) end end value_else(value_result) do # force action to set any values to nil action.execute_unknown(symtab) value_error "" end end |
#execute_unknown(symtab) ⇒ void
This method returns an undefined value.
“execute” the statement by updating the variables in the symbol table
3827 3828 3829 |
# File 'lib/idl/ast.rb', line 3827 def execute_unknown(symtab) action.execute_unknown(symtab) end |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
3832 3833 3834 |
# File 'lib/idl/ast.rb', line 3832 def to_idl "#{action.to_idl} if (#{condition.to_idl});" end |
#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
3804 3805 3806 3807 3808 |
# File 'lib/idl/ast.rb', line 3804 def type_check(symtab) action.type_check(symtab) condition.type_check(symtab) type_error "condition is not boolean" unless condition.type(symtab).convertable_to?(:boolean) end |