class AdLint::Exam::CBuiltin::FN_PATH

Public Class Methods

new(phase_ctxt) click to toggle source
Calls superclass method AdLint::Examination::new
# File lib/adlint/exam/c_builtin/cc1_metric.rb, line 645
def initialize(phase_ctxt)
  super
  @fpath = phase_ctxt[:sources].first.fpath
  interp = phase_ctxt[:cc1_interpreter]
  interp.on_function_started += T(:enter_function)
  interp.on_function_ended   += T(:leave_function)
  interp.on_branch_started   += M(:enter_branch)
  interp.on_branch_ended     += M(:leave_branch)
  @cur_fun = nil
end

Private Instance Methods

do_execute(*) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_metric.rb, line 658
def do_execute(*) end
do_prepare(*) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_metric.rb, line 657
def do_prepare(*) end
enter_branch(branch) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_metric.rb, line 681
def enter_branch(branch)
  if @cur_fun
    # NOTE: Entering into new branch group.
    if branch.first?
      @paths_in_fun -= @paths_in_branch.last
      @paths_to_enter_branch_group.push(@paths_in_branch.last)
      @paths_in_branch_group.push(0)
    end

    # NOTE: Entering into new branch.
    @paths_in_branch.push(@paths_to_enter_branch_group.last)
    @paths_in_fun += @paths_to_enter_branch_group.last
  end
end
enter_function(fun_def, *) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_metric.rb, line 660
def enter_function(fun_def, *)
  @cur_fun = fun_def
  # NOTE: Number of paths in the current function.
  @paths_in_fun = 1
  # NOTE: Stack of the number of paths to enter the current branch group.
  @paths_to_enter_branch_group = [@paths_in_fun]
  # NOTE: Stack of the number of paths in the current branch.
  @paths_in_branch = [@paths_in_fun]
  # NOTE: Stack of the number of paths in the current branch group.
  @paths_in_branch_group = [@paths_in_fun]
end
leave_branch(branch) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_metric.rb, line 696
def leave_branch(branch)
  if @cur_fun
    paths_in_this_branch = @paths_in_branch.pop

    # NOTE: Leaving from the current branch whose paths are not terminated.
    unless branch.break_with_return?
      @paths_in_branch_group[-1] += paths_in_this_branch
    end

    # NOTE: Leaving from the current branch group.
    if branch.final?
      paths_to_enter_this_branch_group = @paths_to_enter_branch_group.pop
      paths_in_this_branch_group = @paths_in_branch_group.pop

      @paths_in_branch[-1] = paths_in_this_branch_group

      # NOTE: The current branch group is an incomplete branch group.
      unless branch.group.complete?
        @paths_in_fun += paths_to_enter_this_branch_group
        @paths_in_branch[-1] += paths_to_enter_this_branch_group
      end
    end
  end
end
leave_function(*) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_metric.rb, line 672
def leave_function(*)
  if @cur_fun
    FN_PATH(FunctionId.new(@cur_fun.identifier.value,
                           @cur_fun.signature.to_s),
            @cur_fun.location, @paths_in_fun)
    @cur_fun = nil
  end
end