class AdLint::Exam::CBuiltin::W0600

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 14036
def initialize(phase_ctxt)
  super
  interp = phase_ctxt[:cc1_interpreter]
  interp.on_sequence_point_reached  += T(:commit_changes)
  interp.on_variable_value_referred += T(:refer_variable)
  interp.on_variable_value_updated  += T(:update_variable)
  @refer_cnt  = [Hash.new(0)]
  @update_cnt = [Hash.new(0)]
end

Private Instance Methods

commit_changes(seqp) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 14047
def commit_changes(seqp)
  if seqp.obvious?
    updated_vars = @update_cnt.map { |hash| hash.keys }.flatten.uniq
    access_count = @refer_cnt.zip(@update_cnt)

    updated_vars.each do |var|
      count = access_count.count { |rhash, uhash|
        rhash.include?(var) && !uhash.include?(var)
      }
      W(seqp.location, var.name) if count > 0
    end
    @refer_cnt  = [Hash.new(0)]
    @update_cnt = [Hash.new(0)]
  else
    @refer_cnt.push(Hash.new(0))
    @update_cnt.push(Hash.new(0))
  end
end
refer_variable(*, var) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 14066
def refer_variable(*, var)
  @refer_cnt.last[var] += 1 if var.named?
end
update_variable(expr, var) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 14070
def update_variable(expr, var)
  if var.named?
    case expr
    when Cc1::SimpleAssignmentExpression, Cc1::CompoundAssignmentExpression
      # NOTE: The expression-statement `i = i + j;' should not be warned.
      #       But the expression-statement `i = i++ + j;' should be warned.
      #       So, side-effects of the assignment-expression are given
      #       special treatment.
    else
      @update_cnt.last[var] += 1
    end
  end
end