class AdLint::Exam::CBuiltin::W0534
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 12280 def initialize(phase_ctxt) super @interp = phase_ctxt[:cc1_interpreter] @interp.on_for_stmt_started += T(:check_for_stmt) @interp.on_c99_for_stmt_started += T(:check_c99_for_stmt) end
Private Instance Methods
check_c99_for_stmt(node)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 12300 def check_c99_for_stmt(node) inited_var_names = collect_identifier_declarators(node.declaration).map { |id| id.identifier.value } if ctrl_var_name = deduct_ctrl_variable_name(node, inited_var_names) unless inited_var_names.include?(ctrl_var_name) W(node.declaration.location, ctrl_var_name) end end end
check_for_stmt(node)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 12288 def check_for_stmt(node) inited_var_names = collect_object_specifiers(node.initial_statement).map { |os| os.identifier.value } if ctrl_var_name = deduct_ctrl_variable_name(node, inited_var_names) unless inited_var_names.include?(ctrl_var_name) W(node.initial_statement.location, ctrl_var_name) end end end
deduct_ctrl_variable_name(node, inited_var_names)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 12312 def deduct_ctrl_variable_name(node, inited_var_names) var_names = inited_var_names + node.varying_variable_names histo = var_names.each_with_object({}) { |name, hash| hash[name] = 0 } ctrlexpr, * = node.deduct_controlling_expression collect_object_specifiers(ctrlexpr).map { |obj_spec| obj_spec.identifier.value }.each { |obj_name| histo.include?(obj_name) and histo[obj_name] += 1 } histo.to_a.sort { |a, b| b.last <=> a.last }.map(&:first).find do |name| var = variable_named(name) and !var.type.const? end end
interpreter()
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 12326 def interpreter @interp end