Class: Idl::IfBodyAst

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

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, body_stmts) ⇒ IfBodyAst

Returns a new instance of IfBodyAst.



5261
5262
5263
5264
5265
5266
5267
# File 'lib/idl/ast.rb', line 5261

def initialize(input, interval, body_stmts)
  if body_stmts.empty?
    super("", 0...0, EMPTY_ARRAY)
  else
    super(input, interval, body_stmts)
  end
end

Instance Method Details

#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



5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
# File 'lib/idl/ast.rb', line 5333

def execute(symtab)
  err = nil
  stmts.each do |s|
    value_result = value_try do
      if s.is_a?(Returns)
        value_result = value_try do
          v = s.return_value(symtab)
          break unless v.nil? # nil means this is a conditional return and the condition is false

        end
        value_else(value_result) do
          # not known, keep going
          err = :value_error
        end
      else
        s.execute(symtab)
      end
    end
    value_else(value_result) do
      # keep going so that we invalidate everything
      err = :value_error
    end
  end
  throw err unless err.nil?
end

#execute_unknown(symtab) ⇒ Object

nothing to do for a function call



5360
5361
5362
5363
5364
# File 'lib/idl/ast.rb', line 5360

def execute_unknown(symtab)
  stmts.each do |s|
    s.execute_unknown(symtab)
  end
end

#return_value(symtab) ⇒ Object



5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
# File 'lib/idl/ast.rb', line 5283

def return_value(symtab)
  symtab.push(self)
  begin
    stmts.each do |s|
      if s.is_a?(Returns)
        v = s.return_value(symtab)
        unless v.nil?
          return v
        end
      else
        s.execute(symtab)
      end
    end
  ensure
    symtab.pop
  end

  nil
end

#return_values(symtab) ⇒ Object



5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
# File 'lib/idl/ast.rb', line 5304

def return_values(symtab)
  values = []
  symtab.push(self)
  begin
    value_result = value_try do
      stmts.each do |s|
        if s.is_a?(Returns)
          value_result = value_try do
            v = s.return_value(symtab)
            unless v.nil?
              return values.push(v).uniq
            end
          end
          value_else(value_result) do
            values += s.return_values(symtab)
          end
        else
          s.execute(symtab)
        end
      end
    end
  ensure
    symtab.pop
  end

  values.uniq
end

#stmtsObject



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

def stmts = @children

#to_idlString

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

Returns:

  • (String)

    IDL code for the node



5367
5368
5369
# File 'lib/idl/ast.rb', line 5367

def to_idl
  stmts.map(&:to_idl).join("")
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:



5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
# File 'lib/idl/ast.rb', line 5270

def type_check(symtab)
  symtab.push(self)

  begin
    stmts.each do |s|
      s.type_check(symtab)
    end
  ensure
    symtab.pop
  end
end