Class: Yadriggy::ASTnode
- Inherits:
-
Object
- Object
- Yadriggy::ASTnode
- Defined in:
- lib/yadriggy/ast.rb,
lib/yadriggy/syntax.rb,
lib/yadriggy/ast_value.rb,
lib/yadriggy/ast_location.rb
Overview
The common ancestor class of AST nodes.
Direct Known Subclasses
ASTree, ArrayLiteral, ArrayRef, BeginEnd, Binary, Break, Call, Conditional, ConstPathRef, Exprs, ForLoop, HashLiteral, Loop, ModuleDef, Name, Number, Parameters, Paren, Program, Rescue, Return, StringInterpolation, StringLiteral, Super, SymbolLiteral, Unary
Defined Under Namespace
Classes: GetLocation
Instance Attribute Summary collapse
-
#parent ⇒ ASTnode
The parent node.
-
#usertype ⇒ Symbol|nil
The user type (or non-terminal symbol) corresponding to this node.
Instance Method Summary collapse
- #add_child(node) ⇒ void
- #add_children(nodes) ⇒ void
-
#const_value ⇒ Object
The value of the name represented by this AST node if the value is immutable.
-
#const_value_in_class(clazz) ⇒ Object
The immutable value of the name represented by this AST node when it is evaluated in the context of ‘clazz`.
-
#get_context_class ⇒ Module
Gets the class including this AST node.
-
#get_receiver_object ⇒ Object
Gets the receiver object.
-
#is_proc?(p) ⇒ Booelan
Checks whether the object is a ‘Proc` or a method.
-
#pretty_print(pp) ⇒ Object
Overrides the printer printer.
-
#root ⇒ ASTnode
The root node.
-
#source_location ⇒ Array
A tuple of the file name, the line number, and the column of this AST node.
-
#source_location_string ⇒ String
The human-readable location of this AST node.
-
#value ⇒ Object
The runtime value of the variable, method name, etc.
-
#value_in_class(clazz) ⇒ Object
The runtime value of this AST node when it is evaluated in the context of ‘clazz`.
Instance Attribute Details
#parent ⇒ ASTnode
46 47 48 |
# File 'lib/yadriggy/ast.rb', line 46 def parent @parent end |
#usertype ⇒ Symbol|nil
The user type (or non-terminal symbol) corresponding to this node.
26 27 28 |
# File 'lib/yadriggy/syntax.rb', line 26 def usertype @usertype end |
Instance Method Details
#add_child(node) ⇒ void
55 56 57 |
# File 'lib/yadriggy/ast.rb', line 55 def add_child(node) node.parent = self unless node.nil? end |
#add_children(nodes) ⇒ void
61 62 63 |
# File 'lib/yadriggy/ast.rb', line 61 def add_children(nodes) nodes.map {|e| e.parent = self unless e.nil? } end |
#const_value ⇒ Object
The value of the name represented by this AST node if the value is immutable. Otherwise, Undef.
11 |
# File 'lib/yadriggy/ast_value.rb', line 11 def const_value() Undef end |
#const_value_in_class(clazz) ⇒ Object
The immutable value of the name represented by this AST node when it is evaluated in the context of ‘clazz`. If the value is mutable, Undef.
18 |
# File 'lib/yadriggy/ast_value.rb', line 18 def const_value_in_class(clazz) const_value end |
#get_context_class ⇒ Module
Gets the class including this AST node.
35 36 37 38 39 40 41 42 |
# File 'lib/yadriggy/ast_value.rb', line 35 def get_context_class c = root.context if c.is_a?(Proc) c.binding.receiver.class else # c is Method or UnboundMethod c.owner end end |
#get_receiver_object ⇒ Object
Gets the receiver object.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/yadriggy/ast_value.rb', line 47 def get_receiver_object c = root.context if c.is_a?(Proc) c.binding.receiver elsif c.is_a?(Method) c.receiver else nil end end |
#is_proc?(p) ⇒ Booelan
Checks whether the object is a ‘Proc` or a method.
61 62 63 |
# File 'lib/yadriggy/ast_value.rb', line 61 def is_proc?(p) p.is_a?(Proc) || p.is_a?(Method) end |
#pretty_print(pp) ⇒ Object
Overrides the printer printer.
49 50 51 |
# File 'lib/yadriggy/ast.rb', line 49 def pretty_print(pp) Yadriggy::simpler_pretty_print(pp, self, '@parent') end |
#root ⇒ ASTnode
66 67 68 |
# File 'lib/yadriggy/ast.rb', line 66 def root parent&.root || self end |
#source_location ⇒ Array
20 21 22 23 24 25 26 27 28 |
# File 'lib/yadriggy/ast_location.rb', line 20 def source_location g = GetLocation.new g.evaluate(self) if g.unknown? && !self.parent.nil? self.parent.source_location else g.result(root.file_name) end end |
#source_location_string ⇒ String
13 14 15 16 |
# File 'lib/yadriggy/ast_location.rb', line 13 def source_location_string loc = source_location "#{loc[0]}:#{loc[1]}" end |
#value ⇒ Object
The runtime value of the variable, method name, etc. represented by this AST node. The default behavior returns Undef. Subclasses override this method.
25 |
# File 'lib/yadriggy/ast_value.rb', line 25 def value() Undef end |
#value_in_class(clazz) ⇒ Object
The runtime value of this AST node when it is evaluated in the context of ‘clazz`.
31 |
# File 'lib/yadriggy/ast_value.rb', line 31 def value_in_class(clazz) value end |