Class: Koto::Parser::AST::Processor::Context::SymbolTable

Inherits:
Hash
  • Object
show all
Defined in:
lib/koto/parser/ast/processor/context/symbol_table.rb

Instance Method Summary collapse

Constructor Details

#initialize(symbol = nil) ⇒ SymbolTable

Returns a new instance of SymbolTable.



9
10
11
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 9

def initialize(symbol = nil)
  record symbol if symbol
end

Instance Method Details

#classesObject



75
76
77
78
79
80
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 75

def classes
  constants.select do |_, constant|
    _, value = *constant
    value.type == :class
  end
end

#constantsObject



36
37
38
39
40
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 36

def constants
  select do |_, symbol|
    symbol.type == :casgn
  end
end

#instance_methodsObject



48
49
50
51
52
53
54
55
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 48

def instance_methods
  methods.select do |_, method|
    context = method.context

    method.type == :def and
    context.in_class? or context.in_module?
  end
end

#instance_variablesObject



24
25
26
27
28
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 24

def instance_variables
  variables.select do |_, variable|
    variable.type == :ivasgn
  end
end

#methodsObject



42
43
44
45
46
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 42

def methods
  select do |_, symbol|
    [:def, :defs].include? symbol.type
  end
end

#modulesObject



82
83
84
85
86
87
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 82

def modules
  constants.select do |_, constant|
    _, value = *constant
    value.type == :module
  end
end

#private_instance_methodsObject



69
70
71
72
73
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 69

def private_instance_methods
  instance_methods.select do |_, instance_method|
    instance_method.access == :private
  end
end

#private_instance_variablesObject



30
31
32
33
34
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 30

def private_instance_variables
  instance_variables.select do |_, instance_variable|
    instance_variable.access == :private
  end
end

#private_methodsObject



63
64
65
66
67
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 63

def private_methods
  methods.select do |_, method|
    method.access == :private
  end
end

#record(symbol) ⇒ Object



13
14
15
16
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 13

def record(symbol)
  self[symbol.name] = symbol
  self
end

#singleton_methodsObject



57
58
59
60
61
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 57

def singleton_methods
  methods.select do |_, method|
    method.type == :defs
  end
end

#variablesObject



18
19
20
21
22
# File 'lib/koto/parser/ast/processor/context/symbol_table.rb', line 18

def variables
  select do |_, symbol|
    [:lvasgn, :ivasgn, :cvasgn, :gvasgn].includes? symbol.type
  end
end