Class: Idl::IfBodyAst
- Includes:
- Executable, Returns
- Defined in:
- lib/idl/ast.rb
Instance Method Summary collapse
-
#execute(symtab) ⇒ void
“execute” the statement by updating the variables in the symbol table.
-
#execute_unknown(symtab) ⇒ Object
nothing to do for a function call.
-
#initialize(input, interval, body_stmts) ⇒ IfBodyAst
constructor
A new instance of IfBodyAst.
-
#return_value(symtab) ⇒ Integer, ...
Evaluate the compile-time return value of this node, or, if the node does not return (e.g., because it is an IfAst but there is no return on the taken path), execute the node and update the symtab.
-
#return_values(symtab) ⇒ Array<Integer>, Array<Boolean>
Evaluate all possible compile-time return values of this node, or, if the node does not return (e.g., because it is an IfAst but there is no return on a possible path), execute the node and update the symtab.
- #stmts ⇒ Object
-
#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, body_stmts) ⇒ IfBodyAst
Returns a new instance of IfBodyAst.
5296 5297 5298 5299 5300 5301 5302 |
# File 'lib/idl/ast.rb', line 5296 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
5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 |
# File 'lib/idl/ast.rb', line 5368 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
5395 5396 5397 5398 5399 |
# File 'lib/idl/ast.rb', line 5395 def execute_unknown(symtab) stmts.each do |s| s.execute_unknown(symtab) end end |
#return_value(symtab) ⇒ Integer, ...
Evaluate the compile-time return value of this node, or, if the node does not return (e.g., because it is an IfAst but there is no return on the taken path), execute the node and update the symtab
5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 |
# File 'lib/idl/ast.rb', line 5318 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) ⇒ Array<Integer>, Array<Boolean>
Evaluate all possible compile-time return values of this node, or, if the node does not return (e.g., because it is an IfAst but there is no return on a possible path), execute the node and update the symtab
5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 |
# File 'lib/idl/ast.rb', line 5339 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 |
#stmts ⇒ Object
5294 |
# File 'lib/idl/ast.rb', line 5294 def stmts = @children |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
5402 5403 5404 |
# File 'lib/idl/ast.rb', line 5402 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
5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 |
# File 'lib/idl/ast.rb', line 5305 def type_check(symtab) symtab.push(self) begin stmts.each do |s| s.type_check(symtab) end ensure symtab.pop end end |