Class: AdLint::Cc1::ForStatement

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(init_stmt, cond_stmt, expr, body_stmt, header_term) ⇒ ForStatement

Returns a new instance of ForStatement.



3814
3815
3816
3817
3818
3819
3820
3821
# File 'lib/adlint/cc1/syntax.rb', line 3814

def initialize(init_stmt, cond_stmt, expr, body_stmt, header_term)
  super()
  @initial_statement   = init_stmt
  @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.



3826
3827
3828
# File 'lib/adlint/cc1/syntax.rb', line 3826

def body_statement
  @body_statement
end

#condition_statementObject (readonly)

Returns the value of attribute condition_statement.



3824
3825
3826
# File 'lib/adlint/cc1/syntax.rb', line 3824

def condition_statement
  @condition_statement
end

#expressionObject (readonly)

Returns the value of attribute expression.



3825
3826
3827
# File 'lib/adlint/cc1/syntax.rb', line 3825

def expression
  @expression
end

#header_terminatorObject (readonly)

Returns the value of attribute header_terminator.



3827
3828
3829
# File 'lib/adlint/cc1/syntax.rb', line 3827

def header_terminator
  @header_terminator
end

#initial_statementObject (readonly)

Returns the value of attribute initial_statement.



3823
3824
3825
# File 'lib/adlint/cc1/syntax.rb', line 3823

def initial_statement
  @initial_statement
end

Instance Method Details

#deduct_controlling_expressionObject



3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
# File 'lib/adlint/cc1/syntax.rb', line 3833

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



3855
3856
3857
3858
3859
3860
3861
# File 'lib/adlint/cc1/syntax.rb', line 3855

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

#locationObject



3829
3830
3831
# File 'lib/adlint/cc1/syntax.rb', line 3829

def location
  head_location
end