class AdLint::Exam::CBuiltin::W0653

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

Private Instance Methods

check(var_def, var, init_var) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 15296
def check(var_def, var, init_var)
  if initializer = var_def.initializer
    init_depth = initializer_depth(initializer)
    case
    when init_depth == 0 && init_var.type.array?,
         init_depth == 0 && init_var.type.composite?
      return
    when init_depth == 0 && type_depth(var.type) > 0
      W(initializer.location)
    end
  end
end
initializer_depth(init) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 15309
def initializer_depth(init)
  if inits = init.initializers
    1 + inits.map { |i| initializer_depth(i) }.max
  else
    0
  end
end
type_depth(type) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 15317
def type_depth(type)
  case
  when type.array?
    1 + type_depth(type.base_type)
  when type.composite?
    type.members.empty? ?
      1 : 1 + type.members.map { |memb| type_depth(memb.type) }.max
  else
    0
  end
end