Class: Rlang::Parser::Module

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

Direct Known Subclasses

Klass

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

included, logger, #logger, logger=

Constructor Details

#initialize(const, scope_class) ⇒ Module

Returns a new instance of Module.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rlang/parser/module.rb', line 18

def initialize(const, scope_class)
  @const = const
  # upper lexical class or module
  logger.debug "scope_class: #{scope_class}"
  @const.scope_class = scope_class
  # the wtype of a Class/Module is either :Class or :Module
  @wtype = WType.new(@const.path_name)
  # memory space used by ivars in bytes
  @size = 0
  # the wnode implementing the code of the class
  @wnode = nil
  @super_class = nil
  @attrs     = [] # class attributes
  @ivars     = [] # instance variables
  @cvars     = [] # class variables
  # Note: the consts list is fed from the Const class
  # on purpose so that it applies to any constant not jus
  # Classes and modules
  @consts    = [] # class constants
  @methods   = [] # methods
  @offset    = 0  # memory offset of next ivar

  # Modules included/extended/prepended in 
  # this module/class
  @modules   = [] # all modules included, prepended, extended
  @includes  = [] # modules included
  @prepends  = [] # modules prepended
  @extends   = [] # modules extended

  # Is this module extended, included, prepended ?
  @extended  = false
  @included  = false
  @prepended = false

  # Associated constant/value points to the class/module
  @const.value = self
  logger.debug "Created Class/Module #{@const} / #{self}"
end

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs.



14
15
16
# File 'lib/rlang/parser/module.rb', line 14

def attrs
  @attrs
end

#constObject (readonly)

Returns the value of attribute const.



13
14
15
# File 'lib/rlang/parser/module.rb', line 13

def const
  @const
end

#constsObject

Returns the value of attribute consts.



14
15
16
# File 'lib/rlang/parser/module.rb', line 14

def consts
  @consts
end

#cvarsObject

Returns the value of attribute cvars.



14
15
16
# File 'lib/rlang/parser/module.rb', line 14

def cvars
  @cvars
end

#extendsObject

Returns the value of attribute extends.



14
15
16
# File 'lib/rlang/parser/module.rb', line 14

def extends
  @extends
end

#includesObject

Returns the value of attribute includes.



14
15
16
# File 'lib/rlang/parser/module.rb', line 14

def includes
  @includes
end

#ivarsObject

Returns the value of attribute ivars.



14
15
16
# File 'lib/rlang/parser/module.rb', line 14

def ivars
  @ivars
end

#methodsObject

Returns the value of attribute methods.



14
15
16
# File 'lib/rlang/parser/module.rb', line 14

def methods
  @methods
end

#offsetObject

Returns the value of attribute offset.



14
15
16
# File 'lib/rlang/parser/module.rb', line 14

def offset
  @offset
end

#wnodeObject

Returns the value of attribute wnode.



14
15
16
# File 'lib/rlang/parser/module.rb', line 14

def wnode
  @wnode
end

#wtypeObject

Returns the value of attribute wtype.



13
14
15
# File 'lib/rlang/parser/module.rb', line 13

def wtype
  @wtype
end

Instance Method Details

#ancestorsObject



100
101
102
103
# File 'lib/rlang/parser/module.rb', line 100

def ancestors
  @prepends.reverse + [self] + @includes.reverse + @extends.reverse + \
    (@super_class ? @super_class.ancestors : [])
end

#const_get(name) ⇒ Object



105
106
107
# File 'lib/rlang/parser/module.rb', line 105

def const_get(name)
  consts.find { |c| c.name == name}
end

#delete_class_methodsObject



113
114
115
# File 'lib/rlang/parser/module.rb', line 113

def delete_class_methods
  self.methods.select { |m| m.class? }.each { |m| m.wnode.delete!; @methods.delete(m) }
end

#delete_instance_methodsObject



109
110
111
# File 'lib/rlang/parser/module.rb', line 109

def delete_instance_methods
  @methods.select { |m| m.instance? }.each { |m| m.wnode.delete!; @methods.delete(m) }
end

#extend(klass) ⇒ Object



95
96
97
98
# File 'lib/rlang/parser/module.rb', line 95

def extend(klass)
  @modules   |= [klass]
  @extends   |= [klass]
end

#extended!Object



135
# File 'lib/rlang/parser/module.rb', line 135

def extended!; @extended = true; end

#extended?Boolean

Returns:

  • (Boolean)


134
# File 'lib/rlang/parser/module.rb', line 134

def extended?; @extended; end

#include(klass) ⇒ Object



85
86
87
88
# File 'lib/rlang/parser/module.rb', line 85

def include(klass)
  @modules   |= [klass]
  @includes  |= [klass]
end

#included!Object



138
# File 'lib/rlang/parser/module.rb', line 138

def included!; @included = true; end

#included?Boolean

Returns:

  • (Boolean)


137
# File 'lib/rlang/parser/module.rb', line 137

def included?; @included; end

#nameObject



61
62
63
# File 'lib/rlang/parser/module.rb', line 61

def name
  @const.name
end

#nestingObject

Do not include the top class Object in nesting



74
75
76
77
78
79
80
81
82
83
# File 'lib/rlang/parser/module.rb', line 74

def nesting
  sk = nil; k = self; n = [k]
  while (sk = k.const.scope_class) && (sk != k) && !sk.object_class?
    logger.debug "k: #{k.name}/#{k}, sk: #{sk.name}/#{sk}, sk.object_class? #{sk.object_class?}"
    n.unshift(sk)
    k = sk
  end
  logger.debug "Class#nesting : #{n.map(&:name)}"
  n
end

#object_class?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/rlang/parser/module.rb', line 57

def object_class?
  self.const.name == :Object && self.const.scope_class == self
end

#pathObject



65
66
67
# File 'lib/rlang/parser/module.rb', line 65

def path
  @const.path
end

#path_nameObject



69
70
71
# File 'lib/rlang/parser/module.rb', line 69

def path_name
  @const.path_name
end

#prepend(klass) ⇒ Object



90
91
92
93
# File 'lib/rlang/parser/module.rb', line 90

def prepend(klass)
  @modules   |= [klass]
  @prepends  |= [klass]
end

#prepended!Object



141
# File 'lib/rlang/parser/module.rb', line 141

def prepended!; @prepended = true; end

#prepended?Boolean

Returns:

  • (Boolean)


140
# File 'lib/rlang/parser/module.rb', line 140

def prepended?; @prepended; end

#sizeObject



117
118
119
# File 'lib/rlang/parser/module.rb', line 117

def size
  @offset
end

#wasm_nameObject



126
127
128
# File 'lib/rlang/parser/module.rb', line 126

def wasm_name
  @name
end

#wasm_typeObject



130
131
132
# File 'lib/rlang/parser/module.rb', line 130

def wasm_type
  @wtype.wasm_type
end