Class: AdLint::Cc1::FunctionTable
- Inherits:
-
Object
- Object
- AdLint::Cc1::FunctionTable
- Defined in:
- lib/adlint/cc1/object.rb
Instance Method Summary collapse
- #declare_explicitly(dcl) ⇒ Object
- #declare_implicitly(fun) ⇒ Object
- #define(fun, in_global_scope = false) ⇒ Object
- #designators ⇒ Object
- #enter_scope ⇒ Object
-
#initialize(mem_pool) ⇒ FunctionTable
constructor
A new instance of FunctionTable.
- #leave_scope ⇒ Object
- #lookup(name_str) ⇒ Object
Constructor Details
#initialize(mem_pool) ⇒ FunctionTable
Returns a new instance of FunctionTable.
1102 1103 1104 1105 1106 |
# File 'lib/adlint/cc1/object.rb', line 1102 def initialize(mem_pool) @memory_pool = mem_pool @functions = [{}] @scope_stack = [GlobalScope.new] end |
Instance Method Details
#declare_explicitly(dcl) ⇒ Object
1120 1121 1122 1123 1124 1125 1126 1127 |
# File 'lib/adlint/cc1/object.rb', line 1120 def declare_explicitly(dcl) if fun = lookup(dcl.identifier.value) and fun.explicit? fun.declarations_and_definitions.push(dcl) return fun end define(ExplicitFunction.new(dcl)) end |
#declare_implicitly(fun) ⇒ Object
1129 1130 1131 1132 1133 1134 |
# File 'lib/adlint/cc1/object.rb', line 1129 def declare_implicitly(fun) if fun.named? && fun.implicit? define(fun, true) end fun end |
#define(fun, in_global_scope = false) ⇒ Object
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 |
# File 'lib/adlint/cc1/object.rb', line 1136 def define(fun, in_global_scope = false) # NOTE: A function has a starting address in the TEXT segment. # This is ad-hoc implementation, but it's enough for analysis. fun.bind_to(@memory_pool.allocate_static(0)) if in_global_scope @functions.first[fun.name] = fun else @functions.last[fun.name] = fun if fun.named? end fun end |
#designators ⇒ Object
1159 1160 1161 |
# File 'lib/adlint/cc1/object.rb', line 1159 def designators @functions.map { |hash| hash.keys }.flatten.to_set end |
#enter_scope ⇒ Object
1108 1109 1110 1111 |
# File 'lib/adlint/cc1/object.rb', line 1108 def enter_scope @functions.push({}) @scope_stack.push(Scope.new(@scope_stack.size)) end |
#leave_scope ⇒ Object
1113 1114 1115 1116 1117 1118 |
# File 'lib/adlint/cc1/object.rb', line 1113 def leave_scope @functions.pop.each_value do |fun| @memory_pool.free(fun.binding.memory) end @scope_stack.pop end |
#lookup(name_str) ⇒ Object
1150 1151 1152 1153 1154 1155 1156 1157 |
# File 'lib/adlint/cc1/object.rb', line 1150 def lookup(name_str) @functions.reverse_each do |hash| if fun = hash[name_str] return fun end end nil end |