Class: Idl::ForLoopAst
- Includes:
- Executable, Returns
- Defined in:
- lib/idl/ast.rb
Instance Method Summary collapse
- #condition ⇒ Object
-
#execute_unknown(symtab) ⇒ void
included
from Executable
“execute” the statement, forcing any variable assignments to an unknown state This is used down unknown conditional paths.
- #init ⇒ Object
-
#initialize(input, interval, init, condition, update, stmts) ⇒ ForLoopAst
constructor
A new instance of ForLoopAst.
- #return_value(symtab) ⇒ Object (also: #execute)
- #return_values(symtab) ⇒ Object
- #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.
- #update ⇒ Object
Constructor Details
#initialize(input, interval, init, condition, update, stmts) ⇒ ForLoopAst
Returns a new instance of ForLoopAst.
5150 5151 5152 |
# File 'lib/idl/ast.rb', line 5150 def initialize(input, interval, init, condition, update, stmts) super(input, interval, [init, condition, update] + stmts) end |
Instance Method Details
#condition ⇒ Object
5146 |
# File 'lib/idl/ast.rb', line 5146 def condition = @children[1] |
#execute_unknown(symtab) ⇒ void Originally defined in module Executable
This method returns an undefined value.
“execute” the statement, forcing any variable assignments to an unknown state This is used down unknown conditional paths.
#init ⇒ Object
5145 |
# File 'lib/idl/ast.rb', line 5145 def init = @children[0] |
#return_value(symtab) ⇒ Object Also known as: execute
5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 |
# File 'lib/idl/ast.rb', line 5168 def return_value(symtab) symtab.push(self) begin value_result = value_try do init.execute(symtab) while condition.value(symtab) 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 update.execute(symtab) end end value_else(value_result) do value_error "" end ensure symtab.pop end nil end |
#return_values(symtab) ⇒ Object
5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 |
# File 'lib/idl/ast.rb', line 5199 def return_values(symtab) value_result = value_try do # if there is a known return value, then we are done return [return_value(symtab)] end value_else(value_result) do # see if we can collect a list values = [] symtab.push(self) begin value_result = value_try do init.execute(symtab) while condition.value(symtab) 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 update.execute(symtab) end :ok end ensure symtab.pop end values.uniq end end |
#stmts ⇒ Object
5148 |
# File 'lib/idl/ast.rb', line 5148 def stmts = @children[3..] |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
5245 5246 5247 5248 5249 5250 5251 5252 |
# File 'lib/idl/ast.rb', line 5245 def to_idl idl = "for (#{init.to_idl}; #{condition.to_idl}; #{update.to_idl}) {" stmts.each do |s| idl << s.to_idl end idl << "}" 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
5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 |
# File 'lib/idl/ast.rb', line 5155 def type_check(symtab) symtab.push(self) init.type_check(symtab) condition.type_check(symtab) update.type_check(symtab) stmts.each do |s| s.type_check(symtab) end symtab.pop end |
#update ⇒ Object
5147 |
# File 'lib/idl/ast.rb', line 5147 def update = @children[2] |