class AdLint::Exam::CBuiltin::W0052
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 1379 def initialize(phase_ctxt) super interp = phase_ctxt[:cc1_interpreter] interp.on_variable_declared += T(:declare_object) interp.on_variable_defined += T(:declare_object) interp.on_explicit_function_declared += T(:declare_object) interp.on_explicit_function_defined += T(:declare_object) interp.on_block_started += T(:enter_scope) interp.on_block_ended += T(:leave_scope) @dcl_names = [Hash.new { |hash, key| hash[key] = [] }] end
Private Instance Methods
declare_object(dcl_or_def, *)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 1392 def declare_object(dcl_or_def, *) dcl_name = dcl_or_def.identifier pair_names = @dcl_names.map { |name_hash| name_hash[mangle(dcl_name.value)] }.reduce([]) { |all_names, similar_names| all_names + similar_names }.uniq { |id| id.value }.reject { |id| id.value == dcl_name.value } unless pair_names.empty? W(dcl_or_def.location, dcl_name.value, *pair_names.map { |pair| C(:C0001, pair.location, pair.value) }) end @dcl_names.last[mangle(dcl_name.value)].push(dcl_name) end
enter_scope(*)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 1409 def enter_scope(*) @dcl_names.push(Hash.new { |hash, key| hash[key] = [] }) end
leave_scope(*)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 1413 def leave_scope(*) @dcl_names.pop end
mangle(name)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 1417 def mangle(name) name.slice(0...@phase_ctxt.traits.of_compiler.identifier_max) end