class AdLint::Exam::CBuiltin::W0498::AmbiguousExpressionDetector

Public Class Methods

new(phase_ctxt, expr) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 11193
def initialize(phase_ctxt, expr)
  @phase_ctxt      = phase_ctxt
  @target_expr     = expr
  @encl_expr_stack = [expr]
  @add_exprs       = Hash.new(0)
  @sub_exprs       = Hash.new(0)
  @mul_exprs       = Hash.new(0)
  @div_exprs       = Hash.new(0)
end

Public Instance Methods

execute() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 11203
def execute
  @target_expr.accept(self)
end
visit_additive_expression(node) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 11224
def visit_additive_expression(node)
  cur_encl = current_encl_expr
  case node.operator.type
  when "+"
    @add_exprs[cur_encl] += 1
    W(cur_encl.head_location) if include_ambiguous_expr?
  when "-"
    @sub_exprs[cur_encl] += 1
    W(cur_encl.head_location) if include_ambiguous_expr?
  end
  super
end
visit_array_subscript_expression(node) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 11213
def visit_array_subscript_expression(node)
  AmbiguousExpressionDetector.new(@phase_ctxt,
                                  node.array_subscript).execute
end
visit_conditional_expression(node) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 11250
def visit_conditional_expression(node)
  cond_expr = node.condition
  then_expr = node.then_expression
  else_expr = node.else_expression
  AmbiguousExpressionDetector.new(@phase_ctxt, cond_expr).execute
  AmbiguousExpressionDetector.new(@phase_ctxt, then_expr).execute
  AmbiguousExpressionDetector.new(@phase_ctxt, else_expr).execute
end
visit_function_call_expression(node) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 11218
def visit_function_call_expression(node)
  node.argument_expressions.each do |expr|
    AmbiguousExpressionDetector.new(@phase_ctxt, expr).execute
  end
end
visit_grouped_expression(node) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 11207
def visit_grouped_expression(node)
  @encl_expr_stack.push(node)
  super
  @encl_expr_stack.pop
end
visit_multiplicative_expression(node) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 11237
def visit_multiplicative_expression(node)
  cur_encl = current_encl_expr
  case node.operator.type
  when "*"
    @mul_exprs[cur_encl] += 1
    W(cur_encl.head_location) if include_ambiguous_expr?
  when "/"
    @div_exprs[cur_encl] += 1
    W(cur_encl.head_location) if include_ambiguous_expr?
  end
  super
end

Private Instance Methods

current_encl_expr() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 11266
def current_encl_expr
  @encl_expr_stack.last
end
include_ambiguous_expr?() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 11260
def include_ambiguous_expr?
  cur_encl = current_encl_expr
  @add_exprs[cur_encl] > 0 && @sub_exprs[cur_encl] > 0 or
  @mul_exprs[cur_encl] > 0 && @div_exprs[cur_encl] > 0
end
suppressors() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 11278
def suppressors
  @phase_ctxt[:suppressors]
end