class AdLint::Exam::CBuiltin::W1050

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 20937
def initialize(phase_ctxt)
  super
  @interp = phase_ctxt[:cc1_interpreter]
  @interp.on_explicit_conv_performed += T(:check)
end

Private Instance Methods

check(expr, orig_var, rslt_var) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 20944
def check(expr, orig_var, rslt_var)
  orig_type = orig_var.type
  rslt_type = rslt_var.type

  unless orig_type.scalar? && orig_type.integer? &&
      rslt_type.scalar? && rslt_type.integer? && rslt_type.signed?
    return
  end

  orig_val = orig_var.value
  return unless orig_val.scalar?

  lower_bound = scalar_value_of(rslt_type.min)
  test = orig_val.test_must_be_less_than(lower_bound)
  if test.true?
    W(expr.location,
      *test.evidence.emit_context_messages(self, expr.location))
    return
  end

  upper_bound = scalar_value_of(rslt_type.max)
  test = orig_val.test_must_be_greater_than(upper_bound)
  if test.true?
    W(expr.location,
      *test.evidence.emit_context_messages(self, expr.location))
  end
end
interpreter() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 20972
def interpreter
  @interp
end