class AdLint::Cc1::FunctionTable
Public Class Methods
new(mem_pool)
click to toggle source
# File lib/adlint/cc1/object.rb, line 1102 def initialize(mem_pool) @memory_pool = mem_pool @functions = [{}] @scope_stack = [GlobalScope.new] end
Public Instance Methods
declare_explicitly(dcl)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/adlint/cc1/object.rb, line 1159 def designators @functions.map { |hash| hash.keys }.flatten.to_set end
enter_scope()
click to toggle source
# File lib/adlint/cc1/object.rb, line 1108 def enter_scope @functions.push({}) @scope_stack.push(Scope.new(@scope_stack.size)) end
leave_scope()
click to toggle source
# 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)
click to toggle source
# 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