Class: Idl::ElseIfAst

Inherits:
AstNode show all
Includes:
Returns
Defined in:
lib/idl/ast.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, body_interval, cond, body_stmts) ⇒ ElseIfAst

Returns a new instance of ElseIfAst.



5379
5380
5381
5382
# File 'lib/idl/ast.rb', line 5379

def initialize(input, interval, body_interval, cond, body_stmts)
  body = IfBodyAst.new(input, body_interval, body_stmts)
  super(input, interval, [cond, body])
end

Instance Method Details

#bodyObject



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

def body = @children[1]

#condObject



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

def cond = @children[0]

#return_value(symtab) ⇒ Object Originally defined in module Returns

Raises:

  • (NotImplementedError)

#return_values(symtab) ⇒ Object



5400
5401
5402
5403
5404
5405
5406
5407
5408
# File 'lib/idl/ast.rb', line 5400

def return_values(symtab)
  value_result = value_try do
    return cond.value(symtab) ? body.return_values(symtab) : EMPTY_ARRAY
  end
  value_else(value_result) do
    # might be taken, so add the possible return values
    body.return_values(symtab)
  end
end

#to_idlString

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

Returns:

  • (String)

    IDL code for the node



5411
5412
5413
# File 'lib/idl/ast.rb', line 5411

def to_idl
  " else if (#{cond.to_idl}) { #{body.to_idl} }"
end

#type_check(symtab) ⇒ Object



5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
# File 'lib/idl/ast.rb', line 5384

def type_check(symtab)
  cond.type_check(symtab)

  cond_value = nil
  value_try do
    cond_value = cond.value(symtab)
  end

  unless cond.type(symtab).convertable_to?(:boolean)
    type_error "'#{cond.text_value}' is not boolean"
  end

  body.type_check(symtab) unless cond_value == false
end