class AdLint::Exam::CBuiltin::W0051

Public Class Methods

new(phase_ctxt) click to toggle source
Calls superclass method AdLint::Examination::new
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 1324
def initialize(phase_ctxt)
  super
  interp = phase_ctxt[:cc1_interpreter]
  interp.on_variable_declared          += T(:add_variable)
  interp.on_variable_defined           += T(:add_variable)
  interp.on_explicit_function_declared += T(:add_function)
  interp.on_explicit_function_defined  += T(:add_function)
  interp.on_translation_unit_ended     += M(:check)
  @obj_dcls = Hash.new { |hash, key| hash[key] = [] }
end

Private Instance Methods

add_function(dcl_or_def, fun) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 1342
def add_function(dcl_or_def, fun)
  if fun.named? && fun.declared_as_extern?
    @obj_dcls[mangle(fun.name)].push(dcl_or_def)
  end
end
add_variable(dcl_or_def, var) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 1336
def add_variable(dcl_or_def, var)
  if var.named? && var.declared_as_extern?
    @obj_dcls[mangle(var.name)].push(dcl_or_def)
  end
end
check(*) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 1348
def check(*)
  @obj_dcls.each_value do |dcls|
    similar_dcls = dcls.uniq { |dcl| dcl.identifier.value }
    next unless similar_dcls.size > 1

    similar_dcls.each do |dcl|
      W(dcl.location, dcl.identifier.value, *similar_dcls.map { |pair_dcl|
        next if pair_dcl == dcl
        C(:C0001, pair_dcl.location, pair_dcl.identifier.value)
      }.compact)
    end
  end
end
mangle(name) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 1362
def mangle(name)
  truncated = name.slice(0...@phase_ctxt.traits.of_linker.identifier_max)
  if @phase_ctxt.traits.of_linker.identifier_ignore_case
    truncated.upcase
  else
    truncated
  end
end