class AdLint::Exam::CBuiltin::W0033

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 709
def initialize(phase_ctxt)
  super
  interp = phase_ctxt[:cc1_interpreter]
  interp.on_function_started += T(:collect_labels)
  interp.on_goto_stmt_evaled += T(:use_label)
  interp.on_function_ended   += T(:check_unused_label)
  @labels = nil
end

Private Instance Methods

check_unused_label(*) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 735
def check_unused_label(*)
  if @labels
    @labels.each do |name, label|
      W(label[0].location, name) unless label[1]
    end
    @labels = nil
  end
end
collect_labels(fun_def, *) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 719
def collect_labels(fun_def, *)
  @labels = LabelCollector.new.tap { |col|
    fun_def.function_body.accept(col)
  }.labels
end
end_function(*) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 725
def end_function(*)
  @labels = nil
end
use_label(*, label_name) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 729
def use_label(*, label_name)
  if @labels and label = @labels[label_name]
    @labels[label_name] = [label, true]
  end
end