class AdLint::Exam::CBuiltin::W0104

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 2456
def initialize(phase_ctxt)
  super
  interp = phase_ctxt[:cc1_interpreter]
  interp.on_function_started       += T(:start_function)
  interp.on_function_ended         += T(:check_constant_parameters)
  interp.on_parameter_defined      += T(:add_parameter)
  interp.on_variable_value_updated += T(:write_parameter)
  @params = nil
end

Private Instance Methods

add_parameter(param_def, var) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 2471
def add_parameter(param_def, var)
  if @params && var.named?
    @params[var.name] = [false, var, param_def.location]
  end
end
check_constant_parameters(*) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 2483
def check_constant_parameters(*)
  return unless @params

  @params.each do |name, (written, var, loc)|
    next if var.type.const?
    next if var.type.array? && var.type.base_type.const?

    W(loc, name) unless written
  end

  @params = nil
end
start_function(*) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 2467
def start_function(*)
  @params = {}
end
write_parameter(*, var) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 2477
def write_parameter(*, var)
  if @params && var.named? && @params.include?(var.name)
    @params[var.name][0] = true
  end
end