class AdLint::Cc1::FunctionInterpreter

Public Class Methods

new(owner) click to toggle source
Calls superclass method AdLint::Cc1::SubInterpreter::new
# File lib/adlint/cc1/interp.rb, line 906
def initialize(owner)
  super(owner, FunctionDefinition)
end

Public Instance Methods

visit_ansi_function_definition(node) click to toggle source
# File lib/adlint/cc1/interp.rb, line 910
def visit_ansi_function_definition(node)
  interpret_function(node)
end
visit_kandr_function_definition(node) click to toggle source
# File lib/adlint/cc1/interp.rb, line 914
def visit_kandr_function_definition(node)
  interpret_function(node)
end

Private Instance Methods

interpret_function(fun_def) click to toggle source
# File lib/adlint/cc1/interp.rb, line 919
def interpret_function(fun_def)
  checkpoint(fun_def.location)

  reset_environment
  resolve_unresolved_type(fun_def)
  fun = lookup_or_define_function(fun_def)
  notify_explicit_function_defined(fun_def, fun)

  interpret_function_body(fun_def, fun) if fun_def.analysis_target?(traits)
end
interpret_function_body(fun_def, fun) click to toggle source
# File lib/adlint/cc1/interp.rb, line 930
def interpret_function_body(fun_def, fun)
  interpreter._enter_function(fun_def)
  scoped_eval do
    notify_function_started(fun_def, fun)
    notify_block_started(fun_def.function_body)

    fun_def.parameter_definitions.each { |param_def| interpret(param_def) }
    BreakEvent.catch do
      fun_def.function_body.block_items.each { |item| interpret(item) }
      notify_implicit_return_evaled(fun_def.function_body.tail_location)
    end

    notify_block_ended(fun_def.function_body)
    notify_function_ended(fun_def, fun)
  end
ensure
  interpreter._leave_function(fun_def)
end
lookup_or_define_function(fun_def) click to toggle source
# File lib/adlint/cc1/interp.rb, line 949
def lookup_or_define_function(fun_def)
  fun_def.type.declarations.each do |dcl|
    dcl.mark_as_referred_by(fun_def.identifier)
  end

  if fun = function_named(fun_def.identifier.value) and fun.explicit?
    fun.declarations_and_definitions.each do |dcl_or_def|
      dcl_or_def.mark_as_referred_by(fun_def.identifier)
    end
    fun.declarations_and_definitions.push(fun_def)
    fun
  else
    define_explicit_function(fun_def)
  end
end