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.
3776 3777 3778 |
# File 'lib/idl/ast.rb', line 3776 def initialize(input, interval, action, condition) super(input, interval, [action, condition]) end |
Instance Method Details
#action ⇒ Object
3773 |
# File 'lib/idl/ast.rb', line 3773 def action = @children[0] |
#condition ⇒ Object
3774 |
# File 'lib/idl/ast.rb', line 3774 def condition = @children[1] |
#execute(symtab) ⇒ void
This method returns an undefined value.
“execute” the statement by updating the variables in the symbol table
3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 |
# File 'lib/idl/ast.rb', line 3788 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
3804 3805 3806 |
# File 'lib/idl/ast.rb', line 3804 def execute_unknown(symtab) action.execute_unknown(symtab) end |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
3809 3810 3811 |
# File 'lib/idl/ast.rb', line 3809 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
3781 3782 3783 3784 3785 |
# File 'lib/idl/ast.rb', line 3781 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 |