class AdLint::Exam::CBuiltin::W0003

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 102
def initialize(phase_ctxt)
  super
  trav = phase_ctxt[:cc1_ast_traversal]
  trav.enter_switch_statement += T(:check)
end

Private Instance Methods

check(node) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 109
def check(node)
  if node.statement.kind_of?(Cc1::CompoundStatement)
    unless have_default_statement?(node.statement)
      W(node.location)
    end
  end
end
have_default_statement?(compound_stmt) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 117
def have_default_statement?(compound_stmt)
  compound_stmt.block_items.any? do |item|
    case item
    when Cc1::GenericLabeledStatement, Cc1::CaseLabeledStatement
      item = item.statement
      redo
    when Cc1::DefaultLabeledStatement
      true
    else
      false
    end
  end
end