Class: Koto::Parser::AST::Processor::Context
- Defined in:
- lib/koto.rb,
lib/koto/parser/ast/processor/context.rb,
lib/koto/parser/ast/processor/context/symbol_table.rb
Defined Under Namespace
Classes: SymbolTable
Instance Attribute Summary collapse
-
#access ⇒ Object
readonly
Returns the value of attribute access.
-
#scopes ⇒ Object
readonly
Returns the value of attribute scopes.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #active_scope ⇒ Object
- #current_scope ⇒ Object
- #get_in(node) ⇒ Object
- #get_out ⇒ Object
- #in_block? ⇒ Boolean
- #in_class? ⇒ Boolean
- #in_def? ⇒ Boolean
- #in_dynamic_block? ⇒ Boolean
- #in_lambda? ⇒ Boolean
- #in_module? ⇒ Boolean
- #in_sclass? ⇒ Boolean
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #save(node) ⇒ Object
- #switch_access_to(access) ⇒ Object
- #symbols ⇒ Object
- #top_level? ⇒ Boolean
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
13 14 15 16 17 18 19 |
# File 'lib/koto/parser/ast/processor/context.rb', line 13 def initialize @scopes = SpaghettiStack.new(SymbolTable.new) @stack = [] @access = :public freeze end |
Instance Attribute Details
#access ⇒ Object (readonly)
Returns the value of attribute access.
11 12 13 |
# File 'lib/koto/parser/ast/processor/context.rb', line 11 def access @access end |
#scopes ⇒ Object (readonly)
Returns the value of attribute scopes.
9 10 11 |
# File 'lib/koto/parser/ast/processor/context.rb', line 9 def scopes @scopes end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
10 11 12 |
# File 'lib/koto/parser/ast/processor/context.rb', line 10 def stack @stack end |
Instance Method Details
#active_scope ⇒ Object
72 73 74 |
# File 'lib/koto/parser/ast/processor/context.rb', line 72 def active_scope @scopes.top end |
#current_scope ⇒ Object
76 77 78 |
# File 'lib/koto/parser/ast/processor/context.rb', line 76 def current_scope @stack.last end |
#get_in(node) ⇒ Object
21 22 23 24 |
# File 'lib/koto/parser/ast/processor/context.rb', line 21 def get_in(node) copy = self.deep_dup copy.send :get_in!, node end |
#get_out ⇒ Object
35 36 37 38 |
# File 'lib/koto/parser/ast/processor/context.rb', line 35 def get_out copy = self.deep_dup copy.send :get_out! end |
#in_block? ⇒ Boolean
114 115 116 117 |
# File 'lib/koto/parser/ast/processor/context.rb', line 114 def in_block? return false if top_level? current_scope.type == :block end |
#in_class? ⇒ Boolean
94 95 96 97 |
# File 'lib/koto/parser/ast/processor/context.rb', line 94 def in_class? return false if top_level? current_scope.type == :class end |
#in_def? ⇒ Boolean
109 110 111 112 |
# File 'lib/koto/parser/ast/processor/context.rb', line 109 def in_def? return false if top_level? current_scope.type == :def end |
#in_dynamic_block? ⇒ Boolean
124 125 126 |
# File 'lib/koto/parser/ast/processor/context.rb', line 124 def in_dynamic_block? in_block? || in_lambda? end |
#in_lambda? ⇒ Boolean
119 120 121 122 |
# File 'lib/koto/parser/ast/processor/context.rb', line 119 def in_lambda? return false if top_level? current_scope.type == :lambda end |
#in_module? ⇒ Boolean
104 105 106 107 |
# File 'lib/koto/parser/ast/processor/context.rb', line 104 def in_module? return false if top_level? current_scope.type == :module end |
#in_sclass? ⇒ Boolean
99 100 101 102 |
# File 'lib/koto/parser/ast/processor/context.rb', line 99 def in_sclass? return false if top_level? current_scope.type == :sclass end |
#save(node) ⇒ Object
54 55 56 57 |
# File 'lib/koto/parser/ast/processor/context.rb', line 54 def save(node) copy = self.deep_dup copy.send :save!, node end |
#switch_access_to(access) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/koto/parser/ast/processor/context.rb', line 80 def switch_access_to(access) return self unless ACCESS_METHODS.include?(access) && access != @access copy = self.dup copy.instance_variable_set(:@access, access) copy.freeze end |
#symbols ⇒ Object
68 69 70 |
# File 'lib/koto/parser/ast/processor/context.rb', line 68 def symbols active_scope.data end |
#top_level? ⇒ Boolean
90 91 92 |
# File 'lib/koto/parser/ast/processor/context.rb', line 90 def top_level? @stack.empty? end |