Class: Ikra::AST::RootNode

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

Overview

Need to wrap block bodies in RootNode, so that the first node can be replaced if necessary (LastStatementReturnsVisitor)

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(single_child:) ⇒ RootNode

Returns a new instance of RootNode.



266
267
268
269
# File 'lib/ast/nodes.rb', line 266

def initialize(single_child:)
    @single_child = single_child
    single_child.parent = self
end

Instance Attribute Details

#single_childObject (readonly)

Returns the value of attribute single_child.



264
265
266
# File 'lib/ast/nodes.rb', line 264

def single_child
  @single_child
end

Instance Method Details

#accept(visitor) ⇒ Object



44
45
46
# File 'lib/ast/visitor.rb', line 44

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

#cloneObject



271
272
273
# File 'lib/ast/nodes.rb', line 271

def clone
    return RootNode.new(single_child: @single_child.clone)
end

#to_sObject



40
41
42
# File 'lib/ast/printer.rb', line 40

def to_s
    return "[RootNode: #{single_child.to_s}]"
end