Class: Ikra::AST::ProgramNode

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

Instance Attribute Summary collapse

Attributes inherited from Node

#parent

Instance Method Summary collapse

Methods inherited from Node

#eql?

Constructor Details

#initialize(blocks: [], classes: []) ⇒ ProgramNode

Returns a new instance of ProgramNode.



24
25
26
27
# File 'lib/ast/nodes.rb', line 24

def initialize(blocks: [], classes: [])
    @blocks = blocks
    @classes = classes
end

Instance Attribute Details

#blocksObject (readonly)

First block is program entry point



21
22
23
# File 'lib/ast/nodes.rb', line 21

def blocks
  @blocks
end

#classesObject (readonly)

Returns the value of attribute classes.



22
23
24
# File 'lib/ast/nodes.rb', line 22

def classes
  @classes
end

Instance Method Details

#==(other) ⇒ Object



35
36
37
# File 'lib/ast/nodes.rb', line 35

def ==(other)
    return super(other) && blocks == other.blocks && classes == other.classes
end

#accept(visitor) ⇒ Object



12
13
14
15
16
# File 'lib/ast/visitor.rb', line 12

def accept(visitor)
    def accept(visitor)
        return visitor.visit_program_node(self)
    end
end

#cloneObject



29
30
31
32
33
# File 'lib/ast/nodes.rb', line 29

def clone
    return ProgramNode.new(
        blocks: @blocks.map do |b| b.clone end,
        classes: @classes.map do |c| c.clone end)
end

#hashObject



39
40
41
# File 'lib/ast/nodes.rb', line 39

def hash
    return (blocks.hash + classes.hash) % 4524321
end

#to_sObject



10
11
12
# File 'lib/ast/printer.rb', line 10

def to_s
    return "[ProgramNode: #{blocks.to_s}; #{classes.to_s}]"
end