Class: AdLint::Cc1::C99ForStatement

Inherits:
IterationStatement show all
Defined in:
lib/adlint/cc1/syntax.rb

Instance Attribute Summary collapse

Attributes inherited from Statement

#executed

Attributes inherited from SyntaxNode

#head_token, #subsequent_sequence_point, #tail_token

Instance Method Summary collapse

Methods inherited from IterationStatement

#varying_expressions, #varying_variable_names

Methods included from SyntaxNodeCollector

collect_additive_expressions, collect_array_declarators, collect_compound_assignment_expressions, collect_constant_specifiers, collect_equality_expressions, collect_function_declarators, collect_generic_labeled_statements, collect_goto_statements, collect_identifier_declarators, collect_if_else_statements, collect_if_statements, collect_logical_and_expressions, collect_logical_or_expressions, collect_object_specifiers, collect_postfix_decrement_expressions, collect_postfix_increment_expressions, collect_prefix_decrement_expressions, collect_prefix_increment_expressions, collect_relational_expressions, collect_simple_assignment_expressions, collect_typedef_type_specifiers

Methods inherited from Statement

#executed?

Methods inherited from SyntaxNode

#head_location, #short_class_name, #tail_location

Methods included from LocationHolder

#analysis_target?

Methods included from Visitable

#accept

Constructor Details

#initialize(dcl, cond_stmt, expr, body_stmt, header_term) ⇒ C99ForStatement

Returns a new instance of C99ForStatement.



3865
3866
3867
3868
3869
3870
3871
3872
# File 'lib/adlint/cc1/syntax.rb', line 3865

def initialize(dcl, cond_stmt, expr, body_stmt, header_term)
  super()
  @declaration         = dcl
  @condition_statement = cond_stmt
  @expression          = expr
  @body_statement      = body_stmt
  @header_terminator   = header_term
end

Instance Attribute Details

#body_statementObject (readonly)

Returns the value of attribute body_statement.



3877
3878
3879
# File 'lib/adlint/cc1/syntax.rb', line 3877

def body_statement
  @body_statement
end

#condition_statementObject (readonly)

Returns the value of attribute condition_statement.



3875
3876
3877
# File 'lib/adlint/cc1/syntax.rb', line 3875

def condition_statement
  @condition_statement
end

#declarationObject (readonly)

Returns the value of attribute declaration.



3874
3875
3876
# File 'lib/adlint/cc1/syntax.rb', line 3874

def declaration
  @declaration
end

#expressionObject (readonly)

Returns the value of attribute expression.



3876
3877
3878
# File 'lib/adlint/cc1/syntax.rb', line 3876

def expression
  @expression
end

#header_terminatorObject (readonly)

Returns the value of attribute header_terminator.



3878
3879
3880
# File 'lib/adlint/cc1/syntax.rb', line 3878

def header_terminator
  @header_terminator
end

Instance Method Details

#deduct_controlling_expressionObject



3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
# File 'lib/adlint/cc1/syntax.rb', line 3884

def deduct_controlling_expression
  sels = collect_loop_breaking_selection_statements(@body_statement)
  if expr = @condition_statement.expression
    rough_cands = [[expr, expr.to_normalized_logical]] + sels.map { |stmt|
      [stmt.expression,
        stmt.expression.to_normalized_logical.to_complemental_logical]
    }
  else
    rough_cands = sels.map { |stmt|
      [stmt.expression,
        stmt.expression.to_normalized_logical.to_complemental_logical]
    }
  end

  # FIXME: When many loop breaking selection-statements are found, how can
  #        I select one selection-statement?
  # FIXME: When the loop breaking selection-statement is a
  #        if-else-statement and the loop breaking is in the else branch,
  #        the controlling expression should be inverted.
  deduct_controlling_expression_candidates(rough_cands).first
end

#inspect(indent = 0) ⇒ Object



3906
3907
3908
3909
3910
3911
3912
# File 'lib/adlint/cc1/syntax.rb', line 3906

def inspect(indent = 0)
  " " * indent + "#{short_class_name}\n" +
    @declaration.inspect(indent + 1) + "\n" +
    @condition_statement.inspect(indent + 1) +
    (@expression ? "\n#{@expression.inspect(indent + 1)}" : "") +
    "\n" + @body_statement.inspect(indent + 1)
end

#locationObject



3880
3881
3882
# File 'lib/adlint/cc1/syntax.rb', line 3880

def location
  head_location
end