Class: Rlang::Parser::Const
- Includes:
- Log
- Defined in:
- lib/rlang/parser/const.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scope_class ⇒ Object
Returns the value of attribute scope_class.
-
#value ⇒ Object
Returns the value of attribute value.
-
#wtype ⇒ Object
Returns the value of attribute wtype.
Instance Method Summary collapse
- #address ⇒ Object
- #class? ⇒ Boolean
- #data=(value) ⇒ Object
-
#initialize(name, value, wtype = WType::DEFAULT) ⇒ Const
constructor
A new instance of Const.
- #module? ⇒ Boolean
-
#path ⇒ Object
Returns an array of successive Const objects that altogether makes the full path of this Const e.g.
-
#path_name ⇒ Object
the symbol form of this constant path e.g.
- #wasm_name ⇒ Object
- #wasm_type ⇒ Object
Methods included from Log
included, logger, #logger, logger=
Constructor Details
#initialize(name, value, wtype = WType::DEFAULT) ⇒ Const
Returns a new instance of Const.
30 31 32 33 34 35 36 |
# File 'lib/rlang/parser/const.rb', line 30 def initialize(name, value, wtype=WType::DEFAULT) @scope_class = nil @name = name @wtype = wtype @data = nil self.value = value if value end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/rlang/parser/const.rb', line 27 def name @name end |
#scope_class ⇒ Object
Returns the value of attribute scope_class.
27 28 29 |
# File 'lib/rlang/parser/const.rb', line 27 def scope_class @scope_class end |
#value ⇒ Object
Returns the value of attribute value.
27 28 29 |
# File 'lib/rlang/parser/const.rb', line 27 def value @value end |
#wtype ⇒ Object
Returns the value of attribute wtype.
28 29 30 |
# File 'lib/rlang/parser/const.rb', line 28 def wtype @wtype end |
Instance Method Details
#address ⇒ Object
106 107 108 |
# File 'lib/rlang/parser/const.rb', line 106 def address @data.address end |
#class? ⇒ Boolean
98 99 100 |
# File 'lib/rlang/parser/const.rb', line 98 def class? @wtype.name == :Class end |
#data=(value) ⇒ Object
70 71 72 |
# File 'lib/rlang/parser/const.rb', line 70 def data=(value) @data = DAta.new(self.path_name.to_sym, value, @wtype) end |
#module? ⇒ Boolean
102 103 104 |
# File 'lib/rlang/parser/const.rb', line 102 def module? @wtype.name == :Module end |
#path ⇒ Object
Returns an array of successive Const objects that altogether makes the full path of this Const e.g. a constant A::B will return [Const(:A), Const(:B)]
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rlang/parser/const.rb', line 84 def path sk = nil; c = self; p = [c] while (sk = c.scope_class) && sk.const != c logger.debug "c: #{c.name}/#{c}, sk: #{sk.name}/#{sk}" c = sk.const p.unshift(c) end # Do not keep Object as the first element of the # const path unless it is the only element p.shift if p.first.name == :Object && p.size > 1 logger.debug "Const#path : #{p.map(&:name)}" p end |
#path_name ⇒ Object
the symbol form of this constant path e.g. a constant A::B will return :“A::B”
76 77 78 79 |
# File 'lib/rlang/parser/const.rb', line 76 def path_name #@scope_class ? "#{@scope_class.path_name}::#{@name}".to_sym : @name self.path.map(&:name).join('::').to_sym end |
#wasm_name ⇒ Object
110 111 112 |
# File 'lib/rlang/parser/const.rb', line 110 def wasm_name "$#{self.path_name}" end |
#wasm_type ⇒ Object
114 115 116 |
# File 'lib/rlang/parser/const.rb', line 114 def wasm_type @wtype.wasm_type end |