Class: Idl::ConditionalStatementAst

Inherits:
AstNode
  • Object
show all
Defined in:
lib/idl/ast.rb

Overview

represents a predicated simple statement

for example:

a = 2 if condition;

Instance Method Summary collapse

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

#actionObject



3773
# File 'lib/idl/ast.rb', line 3773

def action = @children[0]

#conditionObject



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

Parameters:

  • symtab (SymbolTable)

    The symbol table for the context

Raises:

  • ValueError if some part of the statement cannot be executed at compile time



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

Parameters:

  • symtab (SymbolTable)

    The symbol table for the context

Raises:

  • ValueError if some part of the statement cannot be executed at compile time



3804
3805
3806
# File 'lib/idl/ast.rb', line 3804

def execute_unknown(symtab)
  action.execute_unknown(symtab)
end

#to_idlString

Return valid IDL representation of the node (and its subtree)

Returns:

  • (String)

    IDL code for the node



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

Parameters:

Raises:



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