Class: CodeTools::AST::If
- Defined in:
- lib/rubinius/code/ast/control_flow.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#else ⇒ Object
Returns the value of attribute else.
Attributes inherited from Node
Instance Method Summary collapse
- #bytecode(g) ⇒ Object
- #defined(g) ⇒ Object
-
#initialize(line, condition, body, else_body) ⇒ If
constructor
A new instance of If.
- #to_sexp ⇒ Object
Methods inherited from Node
#ascii_graph, #attributes, #children, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, transform, #transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk
Constructor Details
#initialize(line, condition, body, else_body) ⇒ If
Returns a new instance of If.
309 310 311 312 313 314 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 309 def initialize(line, condition, body, else_body) @line = line @condition = condition @body = body || NilLiteral.new(line) @else = else_body || NilLiteral.new(line) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
307 308 309 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 307 def body @body end |
#condition ⇒ Object
Returns the value of attribute condition.
307 308 309 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 307 def condition @condition end |
#else ⇒ Object
Returns the value of attribute else.
307 308 309 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 307 def else @else end |
Instance Method Details
#bytecode(g) ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 316 def bytecode(g) pos(g) done = g.new_label else_label = g.new_label @condition.bytecode(g) g.goto_if_false else_label @body.bytecode(g) g.goto done else_label.set! @else.bytecode(g) # Use line 0 to indicate "compiler generated code" # so that debuggers and such don't get confused by # thinking the then branch jumps into the else branch. g.set_line 0 done.set! end |
#defined(g) ⇒ Object
338 339 340 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 338 def defined(g) g.push_literal "expression" end |
#to_sexp ⇒ Object
342 343 344 345 |
# File 'lib/rubinius/code/ast/control_flow.rb', line 342 def to_sexp else_sexp = @else.kind_of?(NilLiteral) ? nil : @else.to_sexp [:if, @condition.to_sexp, @body.to_sexp, else_sexp] end |