Class: Ikra::AST::ForNode

Inherits:
TreeNode show all
Defined in:
lib/ast/nodes.rb,
lib/ast/printer.rb,
lib/ast/visitor.rb

Constant Summary

Constants inherited from TreeNode

TreeNode::TYPE_INFO_VARS

Instance Attribute Summary collapse

Attributes inherited from Node

#parent

Instance Method Summary collapse

Methods inherited from TreeNode

#==, #enclosing_class, #find_behavior_node, #get_type, #is_begin_node?, #merge_union_type, #register_type_change, #replace, #replace_child, #symbol_table

Methods inherited from Node

#==, #eql?, #hash

Constructor Details

#initialize(iterator_identifier:, range_from:, range_to:, body_stmts: BeginNode.new) ⇒ ForNode

Returns a new instance of ForNode.



443
444
445
446
447
448
449
450
451
452
# File 'lib/ast/nodes.rb', line 443

def initialize(iterator_identifier:, range_from:, range_to:, body_stmts: BeginNode.new)
    @iterator_identifier = iterator_identifier
    @range_from = range_from
    @range_to = range_to
    @body_stmts = body_stmts

    range_from.parent = self
    range_to.parent = self
    body_stmts.parent = self
end

Instance Attribute Details

#body_stmtsObject (readonly)

Returns the value of attribute body_stmts.



441
442
443
# File 'lib/ast/nodes.rb', line 441

def body_stmts
  @body_stmts
end

#iterator_identifierObject (readonly)

Returns the value of attribute iterator_identifier.



438
439
440
# File 'lib/ast/nodes.rb', line 438

def iterator_identifier
  @iterator_identifier
end

#range_fromObject (readonly)

Returns the value of attribute range_from.



439
440
441
# File 'lib/ast/nodes.rb', line 439

def range_from
  @range_from
end

#range_toObject (readonly)

Returns the value of attribute range_to.



440
441
442
# File 'lib/ast/nodes.rb', line 440

def range_to
  @range_to
end

Instance Method Details

#accept(visitor) ⇒ Object



128
129
130
# File 'lib/ast/visitor.rb', line 128

def accept(visitor)
    visitor.visit_for_node(self)
end

#cloneObject



454
455
456
457
458
459
460
# File 'lib/ast/nodes.rb', line 454

def clone
    return ForNode.new(
        iterator_identifier: @iterator_identifier,
        range_from: @range_from.clone,
        range_to: @range_to.clone,
        body_stmts: @body_stmts.clone)
end

#to_sObject



120
121
122
# File 'lib/ast/printer.rb', line 120

def to_s
    return "[ForNode: #{iterator_identifier.to_s} := #{range_from.to_s}...#{range_to.to_s}, #{body_stmts.to_s}]"
end