Class: Rubex::AST::Statement::IfBlock
- Includes:
- Helper
- Defined in:
- lib/rubex/ast/statement/if_block.rb,
lib/rubex/ast/statement/if_block/else.rb,
lib/rubex/ast/statement/if_block/elsif.rb,
lib/rubex/ast/statement/if_block/helper.rb
Defined Under Namespace
Modules: Helper Classes: Else, Elsif
Instance Attribute Summary collapse
-
#expr ⇒ Object
readonly
Returns the value of attribute expr.
-
#if_tail ⇒ Object
readonly
Returns the value of attribute if_tail.
-
#statements ⇒ Object
readonly
Returns the value of attribute statements.
Attributes inherited from Base
Instance Method Summary collapse
- #analyse_statement(local_scope) ⇒ Object
- #generate_code(code, local_scope) ⇒ Object
- #if_tail_exprs ⇒ Object
-
#initialize(expr, statements, if_tail, location) ⇒ IfBlock
constructor
A new instance of IfBlock.
Methods included from Helper
Methods inherited from Base
Constructor Details
#initialize(expr, statements, if_tail, location) ⇒ IfBlock
Returns a new instance of IfBlock.
9 10 11 12 13 14 |
# File 'lib/rubex/ast/statement/if_block.rb', line 9 def initialize(expr, statements, if_tail, location) super(location) @expr = expr @statements = statements @if_tail = if_tail end |
Instance Attribute Details
#expr ⇒ Object (readonly)
Returns the value of attribute expr.
6 7 8 |
# File 'lib/rubex/ast/statement/if_block.rb', line 6 def expr @expr end |
#if_tail ⇒ Object (readonly)
Returns the value of attribute if_tail.
6 7 8 |
# File 'lib/rubex/ast/statement/if_block.rb', line 6 def if_tail @if_tail end |
#statements ⇒ Object (readonly)
Returns the value of attribute statements.
6 7 8 |
# File 'lib/rubex/ast/statement/if_block.rb', line 6 def statements @statements end |
Instance Method Details
#analyse_statement(local_scope) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubex/ast/statement/if_block.rb', line 16 def analyse_statement(local_scope) @tail_exprs = if_tail_exprs # FIME: gets current expr too. make descriptive. @tail_exprs.each do |tail| tail.analyse_types local_scope tail.allocate_temps local_scope end @tail_exprs.each do |tail| tail.release_temps local_scope end super end |
#generate_code(code, local_scope) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rubex/ast/statement/if_block.rb', line 41 def generate_code(code, local_scope) @tail_exprs.each do |tail| tail.generate_evaluation_code(code, local_scope) end generate_code_for_statement 'if', code, local_scope, self tail = @if_tail while tail if tail.is_a?(Elsif) generate_code_for_statement 'else if', code, local_scope, tail elsif tail.is_a?(Else) generate_code_for_statement 'else', code, local_scope, tail end tail = tail.if_tail end @tail_exprs.each do |tail| tail.generate_disposal_code code end end |
#if_tail_exprs ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rubex/ast/statement/if_block.rb', line 29 def if_tail_exprs tail_exprs = [] temp = self while temp.respond_to?(:if_tail) && !temp.is_a?(Rubex::AST::Statement::IfBlock::Else) tail_exprs << temp.expr temp = temp.if_tail end tail_exprs end |