module AdLint::Cc1::DefinableContextTracing

Attributes

predicate[R]

NOTE: Host class must have instance variable named @predicate.

Public Instance Methods

emit_context_messages(report, loc) click to toggle source
# File lib/adlint/cc1/trace.rb, line 238
def emit_context_messages(report, loc)
  traced = Set.new
  msgs = trace_positive_paths(report, loc, traced) +
         trace_negative_paths(report, loc, traced)

  unless msgs.empty?
    [report.C(:C1000, Location.new)] +
      msgs.sort { |a, b| a.location <=> b.location }
  else
    []
  end
end

Private Instance Methods

trace_positive_paths(report, loc, traced) click to toggle source
# File lib/adlint/cc1/trace.rb, line 252
def trace_positive_paths(report, loc, traced)
  # TODO: Evidence of the test result might have two or more contributors.
  #       All the evidences should be complemented by context messages?
  unless pos_trans = sample_positive_transition
    return []
  end

  pos_trans.each_with_object([]) do |ss, msgs|
    branch = ss.tag.at.find { |br| br.ctrlexpr.to_expr }
    while branch
      if expr = branch.ctrlexpr.to_expr and
          expr.location && expr.location < loc
        unless traced.include?(expr)
          msgs.push(report.C(:C1001, expr.location))
          traced.add(expr)
        end
      end
      branch = branch.trunk
    end

    src = ss.tag.by.find { |node|
      node.location && node.location < loc && !traced.include?(node)
    }
    if src && predicate.call(ss.value)
      msgs.push(report.C(:C1006, src.location))
      traced.add(src)
    end
  end
end