clang 20.0.0git
Classes | Public Member Functions | List of all members
clang::VariablePattern Class Reference

Analyzes the pattern of the referenced variables in a statement. More...

#include "clang/Analysis/CloneDetection.h"

Classes

struct  SuspiciousClonePair
 Describes two clones that reference their variables in a different pattern which could indicate a programming error. More...
 

Public Member Functions

 VariablePattern (const StmtSequence &Sequence)
 Creates an VariablePattern object with information about the given StmtSequence.
 
unsigned countPatternDifferences (const VariablePattern &Other, VariablePattern::SuspiciousClonePair *FirstMismatch=nullptr)
 Counts the differences between this pattern and the given one.
 

Detailed Description

Analyzes the pattern of the referenced variables in a statement.

Definition at line 343 of file CloneDetection.h.

Constructor & Destructor Documentation

◆ VariablePattern()

clang::VariablePattern::VariablePattern ( const StmtSequence Sequence)
inline

Creates an VariablePattern object with information about the given StmtSequence.

Definition at line 373 of file CloneDetection.h.

Member Function Documentation

◆ countPatternDifferences()

unsigned VariablePattern::countPatternDifferences ( const VariablePattern Other,
VariablePattern::SuspiciousClonePair FirstMismatch = nullptr 
)

Counts the differences between this pattern and the given one.

Parameters
OtherThe given VariablePattern to compare with.
FirstMismatchOutput parameter that will be filled with information about the first difference between the two patterns. This parameter can be a nullptr, in which case it will be ignored.
Returns
Returns the number of differences between the pattern this object is following and the given VariablePattern.

For example, the following statements all have the same pattern and this function would return zero:

if (a < b) return a; return b; if (x < y) return x; return y; if (u2 < u1) return u2; return u1;

But the following statement has a different pattern (note the changed variables in the return statements) and would have two differences when compared with one of the statements above.

if (a < b) return b; return a;

This function should only be called if the related statements of the given pattern and the statements of this objects are clones of each other.

Definition at line 561 of file CloneDetection.cpp.

References clang::VariablePattern::SuspiciousClonePair::FirstCloneInfo, clang::Other, clang::VariablePattern::SuspiciousClonePair::SecondCloneInfo, and clang::VariablePattern::SuspiciousClonePair::SuspiciousCloneInfo::Suggestion.

Referenced by clang::MatchingVariablePatternConstraint::constrain().


The documentation for this class was generated from the following files: