class AdLint::Exam::CBuiltin::W0538

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 12370
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 12377
def check(node)
  return unless node.statement.kind_of?(Cc1::CompoundStatement)

  labeled_stmt, idx = find_default_labeled_statement(node.statement)

  if labeled_stmt
    unless final_clause?(idx, node.statement)
      W(labeled_stmt.location)
    end
  end
end
final_clause?(idx, compound_stmt) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 12402
def final_clause?(idx, compound_stmt)
  idx += 1
  while item = compound_stmt.block_items[idx]
    case item
    when Cc1::GenericLabeledStatement
      item = item.statement
      redo
    when Cc1::CaseLabeledStatement
      return false
    else
      idx += 1
    end
  end
  true
end
find_default_labeled_statement(compound_stmt) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 12389
def find_default_labeled_statement(compound_stmt)
  compound_stmt.block_items.each_with_index do |item, idx|
    case item
    when Cc1::GenericLabeledStatement
      item = item.statement
      redo
    when Cc1::DefaultLabeledStatement
      return item, idx
    end
  end
  return nil, nil
end