Class: Rlang::Parser::Const

Inherits:
Object show all
Includes:
Log
Defined in:
lib/rlang/parser/const.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/rlang/parser/const.rb', line 27

def name
  @name
end

#scope_classObject

Returns the value of attribute scope_class.



27
28
29
# File 'lib/rlang/parser/const.rb', line 27

def scope_class
  @scope_class
end

#valueObject

Returns the value of attribute value.



27
28
29
# File 'lib/rlang/parser/const.rb', line 27

def value
  @value
end

#wtypeObject

Returns the value of attribute wtype.



28
29
30
# File 'lib/rlang/parser/const.rb', line 28

def wtype
  @wtype
end

Instance Method Details

#addressObject



106
107
108
# File 'lib/rlang/parser/const.rb', line 106

def address
  @data.address
end

#class?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


102
103
104
# File 'lib/rlang/parser/const.rb', line 102

def module?
  @wtype.name == :Module
end

#pathObject

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_nameObject

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_nameObject



110
111
112
# File 'lib/rlang/parser/const.rb', line 110

def wasm_name
  "$#{self.path_name}"
end

#wasm_typeObject



114
115
116
# File 'lib/rlang/parser/const.rb', line 114

def wasm_type
  @wtype.wasm_type
end