class AdLint::Exam::CBuiltin::W0255

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 5511
def initialize(phase_ctxt)
  super
  @interp = phase_ctxt[:cc1_interpreter]
  @interp.on_function_started   += T(:enter_function)
  @interp.on_function_ended     += T(:leave_function)
  @interp.on_return_stmt_evaled += T(:check)
  @cur_fun = nil
end

Private Instance Methods

char_type_family?(type) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 5562
def char_type_family?(type)
  type == char_t || type == signed_char_t || type == unsigned_char_t
end
check(ret_stmt, ret_var) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 5529
def check(ret_stmt, ret_var)
  if @cur_fun && ret_var
    if match?(ret_var.type, @cur_fun.type.return_type)
      W(ret_stmt.location, @cur_fun.name)
    end
  end
end
enter_function(fun_def, fun) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 5521
def enter_function(fun_def, fun)
  @cur_fun = fun
end
from_type() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 5537
def from_type
  char_t
end
interpreter() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 5566
def interpreter
  @interp
end
leave_function(fun_def, fun) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 5525
def leave_function(fun_def, fun)
  @cur_fun = nil
end
match?(expr_type, fun_type) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 5545
def match?(expr_type, fun_type)
  unless expr_type.same_as?(from_type) && fun_type.same_as?(to_type)
    return false
  end

  if char_type_family?(expr_type) &&
      expr_type.explicitly_signed? != from_type.explicitly_signed?
    return false
  end
  if char_type_family?(fun_type) &&
      fun_type.explicitly_signed? != to_type.explicitly_signed?
    return false
  end

  true
end
to_type() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 5541
def to_type
  signed_char_t
end