Class: Ikra::AST::BlockDefNode

Inherits:
BehaviorNode 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 BehaviorNode

#find_behavior_node, #get_type, #lexical_variables_names_and_types, #local_variables_names_and_types, #local_variables_names_and_types=, #merge_union_type, #parameters_names_and_types, #parameters_names_and_types=, #register_type_change, #reset_types_changed, #symbol_table, #types_changed?

Methods inherited from Node

#eql?, #hash

Constructor Details

#initialize(body:, ruby_block:, parameters: nil) ⇒ BlockDefNode

Returns a new instance of BlockDefNode.



184
185
186
187
188
189
190
# File 'lib/ast/nodes.rb', line 184

def initialize(body:, ruby_block:, parameters: nil)
    @body = body
    @ruby_block = ruby_block
    @parameters = parameters

    body.parent = self
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



180
181
182
# File 'lib/ast/nodes.rb', line 180

def body
  @body
end

#parametersObject (readonly)

Returns the value of attribute parameters.



182
183
184
# File 'lib/ast/nodes.rb', line 182

def parameters
  @parameters
end

#ruby_blockObject (readonly)

Returns the value of attribute ruby_block.



181
182
183
# File 'lib/ast/nodes.rb', line 181

def ruby_block
  @ruby_block
end

Instance Method Details

#==(other) ⇒ Object



203
204
205
# File 'lib/ast/nodes.rb', line 203

def ==(other)
    return super(other) && body == other.body && parameters == other.parameters
end

#accept(visitor) ⇒ Object



38
39
40
# File 'lib/ast/visitor.rb', line 38

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

#bindingObject



199
200
201
# File 'lib/ast/nodes.rb', line 199

def binding
    return ruby_block.binding
end

#cloneObject



192
193
194
195
196
197
# File 'lib/ast/nodes.rb', line 192

def clone
    return BlockDefNode.new(
        body: @body.clone,
        ruby_block: @ruby_block,
        parameters: @parameters == nil ? nil : @parameters.dup)
end

#to_sObject



34
35
36
# File 'lib/ast/printer.rb', line 34

def to_s
    return "[BlockDefNode: #{body.to_s}]"
end