Class: Ikra::AST::ClassDefNode
- Defined in:
- lib/ast/nodes.rb,
lib/ast/printer.rb,
lib/ast/visitor.rb,
lib/types/inference/ast_inference.rb
Instance Attribute Summary collapse
-
#instance_methods ⇒ Object
readonly
Returns the value of attribute instance_methods.
-
#instance_variables ⇒ Object
readonly
Returns the value of attribute instance_variables.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ruby_class ⇒ Object
readonly
Returns the value of attribute ruby_class.
Attributes inherited from Node
Instance Method Summary collapse
- #==(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #add_instance_method(inst_meth) ⇒ Object
- #add_instance_variable(inst_var) ⇒ Object
- #clone ⇒ Object
- #enclosing_class ⇒ Object
- #get_type ⇒ Object
- #has_instance_method?(selector) ⇒ Boolean
-
#initialize(name:, ruby_class:, instance_variables: [], instance_methods: [], class_variables: [], class_methods: []) ⇒ ClassDefNode
constructor
Class variables/methods are defined as instance variables/methods on the singleton class ClassDefNode.
- #instance_method(selector) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Node
Constructor Details
#initialize(name:, ruby_class:, instance_variables: [], instance_methods: [], class_variables: [], class_methods: []) ⇒ ClassDefNode
Class variables/methods are defined as instance variables/methods on the singleton class ClassDefNode
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ast/nodes.rb', line 53 def initialize( name:, ruby_class:, instance_variables: [], instance_methods: [], class_variables: [], class_methods: []) @name = name @ruby_class = ruby_class @instance_variables = instance_variables @instance_methods = instance_methods end |
Instance Attribute Details
#instance_methods ⇒ Object (readonly)
Returns the value of attribute instance_methods.
47 48 49 |
# File 'lib/ast/nodes.rb', line 47 def instance_methods @instance_methods end |
#instance_variables ⇒ Object (readonly)
Returns the value of attribute instance_variables.
46 47 48 |
# File 'lib/ast/nodes.rb', line 46 def instance_variables @instance_variables end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
45 46 47 |
# File 'lib/ast/nodes.rb', line 45 def name @name end |
#ruby_class ⇒ Object (readonly)
Returns the value of attribute ruby_class.
48 49 50 |
# File 'lib/ast/nodes.rb', line 48 def ruby_class @ruby_class end |
Instance Method Details
#==(other) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/ast/nodes.rb', line 100 def ==(other) return super(other) && name == other.name && ruby_class == other.ruby_class && instance_variables == other.instance_variables && instance_methods == other.instance_methods && class_variables == other.class_variables && class_methods == other.class_methods end |
#accept(visitor) ⇒ Object
20 21 22 |
# File 'lib/ast/visitor.rb', line 20 def accept(visitor) return visitor.visit_class_def_node(self) end |
#add_instance_method(inst_meth) ⇒ Object
81 82 83 84 |
# File 'lib/ast/nodes.rb', line 81 def add_instance_method(inst_meth) instance_methods.push(inst_meth) inst_meth.parent = self end |
#add_instance_variable(inst_var) ⇒ Object
76 77 78 79 |
# File 'lib/ast/nodes.rb', line 76 def add_instance_variable(inst_var) instance_variables.push(inst_var) inst_meth.parent = self end |
#clone ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/ast/nodes.rb', line 66 def clone return ClassDefNode.new( name: @name, ruby_class: @ruby_class, instance_variables: @instance_variables.map do |i| i.clone end, instance_methods: @instance_methods.map do |i| i.clone end, class_variables: @class_variables.map do |c| c.clone end, class_methods: @class_methods.map do |c| c.clone end) end |
#enclosing_class ⇒ Object
96 97 98 |
# File 'lib/ast/nodes.rb', line 96 def enclosing_class return self end |
#get_type ⇒ Object
42 43 44 |
# File 'lib/types/inference/ast_inference.rb', line 42 def get_type return ruby_class.to_ikra_type end |
#has_instance_method?(selector) ⇒ Boolean
86 87 88 |
# File 'lib/ast/nodes.rb', line 86 def has_instance_method?(selector) return instance_method(selector) != nil end |
#instance_method(selector) ⇒ Object
90 91 92 93 94 |
# File 'lib/ast/nodes.rb', line 90 def instance_method(selector) return instance_methods.find do |meth| meth.name == selector end end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/ast/printer.rb', line 16 def to_s return "[ClassDefNode: #{name}; #{instance_variables.to_s}; #{instance_methods.to_s}]" end |