Class: Ikra::AST::MethDefNode

Inherits:
BehaviorNode show all
Defined in:
lib/ast/nodes.rb,
lib/ast/printer.rb,
lib/ast/visitor.rb,
lib/types/inference/ast_inference.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#parent

Class Method Summary collapse

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(name:, body:, ruby_method:, method_binding: nil) ⇒ MethDefNode

Returns a new instance of MethDefNode.



148
149
150
151
152
153
154
155
# File 'lib/ast/nodes.rb', line 148

def initialize(name:, body:, ruby_method:, method_binding: nil)
    @name = name
    @body = body
    @ruby_method = ruby_method
    @binding = method_binding

    body.parent = self
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



146
147
148
# File 'lib/ast/nodes.rb', line 146

def body
  @body
end

#nameObject (readonly)

Returns the value of attribute name.



144
145
146
# File 'lib/ast/nodes.rb', line 144

def name
  @name
end

#receiver_typeObject

Returns the value of attribute receiver_type.



52
53
54
# File 'lib/types/inference/ast_inference.rb', line 52

def receiver_type
  @receiver_type
end

#ruby_methodObject (readonly)

Returns the value of attribute ruby_method.



145
146
147
# File 'lib/ast/nodes.rb', line 145

def ruby_method
  @ruby_method
end

Class Method Details

.new_with_types(name:, body:, parameters_names_and_types:, ruby_method:, receiver_type:, return_type: Types::UnionType.new, method_binding: nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/types/inference/ast_inference.rb', line 59

def self.new_with_types(
        name:,
        body:,
        parameters_names_and_types:,
        ruby_method:,
        receiver_type:,
        return_type: Types::UnionType.new,
        method_binding: nil)

    instance = new(name: name, body: body, ruby_method: ruby_method, method_binding: method_binding)
    instance.initialize_types(receiver_type: receiver_type, return_type: return_type)
    instance.parameters_names_and_types = parameters_names_and_types
    return instance
end

Instance Method Details

#==(other) ⇒ Object



174
175
176
# File 'lib/ast/nodes.rb', line 174

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

#accept(visitor) ⇒ Object



32
33
34
# File 'lib/ast/visitor.rb', line 32

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

#bindingObject



164
165
166
167
168
169
170
171
172
# File 'lib/ast/nodes.rb', line 164

def binding
    if @binding != nil
        return @binding
    elsif ruby_method == nil 
        return nil
    else 
        return ruby_method.send(:binding)
    end
end

#callersObject



74
75
76
# File 'lib/types/inference/ast_inference.rb', line 74

def callers
    @callers ||= []
end

#cloneObject



157
158
159
160
161
162
# File 'lib/ast/nodes.rb', line 157

def clone
    return MethodDefNode.new(
        name: @name,
        body: @body.clone,
        ruby_method: @ruby_method)
end

#initialize_types(receiver_type:, return_type: Types::UnionType.new) ⇒ Object



54
55
56
57
# File 'lib/types/inference/ast_inference.rb', line 54

def initialize_types(receiver_type:, return_type: Types::UnionType.new)
    @receiver_type = receiver_type
    @type = return_type
end

#to_sObject



28
29
30
# File 'lib/ast/printer.rb', line 28

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