clang-tools 22.0.0git
clang::tidy::utils::decl_ref_expr Namespace Reference

Functions

template<typename S>
static bool isSetDifferenceEmpty (const S &S1, const S &S2)
template<typename Node>
static void extractNodesByIdTo (ArrayRef< BoundNodes > Matches, StringRef ID, SmallPtrSet< const Node *, 16 > &Nodes)
static bool isSameTypeIgnoringConst (QualType A, QualType B)
static bool hasSameParameterTypes (const CXXMethodDecl &D, const CXXMethodDecl &O)
static const CXXMethodDecl * findConstOverload (const CXXMethodDecl &D)
static bool pointsToSameTypeIgnoringConst (QualType A, QualType B)
static bool isLikelyShallowConst (const CXXMethodDecl &M)
SmallPtrSet< const DeclRefExpr *, 16 > constReferenceDeclRefExprs (const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context, int Indirections)
 Returns set of all DeclRefExprs to VarDecl within Stmt where VarDecl is guaranteed to be accessed in a const fashion.
bool isOnlyUsedAsConst (const VarDecl &Var, const Stmt &Stmt, ASTContext &Context, int Indirections)
 Returns true if all DeclRefExpr to the variable within Stmt do not modify it. See constReferenceDeclRefExprs for the meaning of Indirections.
SmallPtrSet< const DeclRefExpr *, 16 > allDeclRefExprs (const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context)
 Returns set of all DeclRefExprs to VarDecl within Stmt.
SmallPtrSet< const DeclRefExpr *, 16 > allDeclRefExprs (const VarDecl &VarDecl, const Decl &Decl, ASTContext &Context)
 Returns set of all DeclRefExprs to VarDecl within Decl.
bool isCopyConstructorArgument (const DeclRefExpr &DeclRef, const Decl &Decl, ASTContext &Context)
 Returns true if DeclRefExpr is the argument of a copy-constructor call expression within Decl.
bool isCopyAssignmentArgument (const DeclRefExpr &DeclRef, const Decl &Decl, ASTContext &Context)
 Returns true if DeclRefExpr is the argument of a copy-assignment operator CallExpr within Decl.

Function Documentation

◆ allDeclRefExprs() [1/2]

llvm::SmallPtrSet< const DeclRefExpr *, 16 > clang::tidy::utils::decl_ref_expr::allDeclRefExprs ( const VarDecl & VarDecl,
const Decl & Decl,
ASTContext & Context )

Returns set of all DeclRefExprs to VarDecl within Decl.

Definition at line 387 of file DeclRefExprUtils.cpp.

References allDeclRefExprs(), and extractNodesByIdTo().

◆ allDeclRefExprs() [2/2]

llvm::SmallPtrSet< const DeclRefExpr *, 16 > clang::tidy::utils::decl_ref_expr::allDeclRefExprs ( const VarDecl & VarDecl,
const Stmt & Stmt,
ASTContext & Context )

◆ constReferenceDeclRefExprs()

llvm::SmallPtrSet< const DeclRefExpr *, 16 > clang::tidy::utils::decl_ref_expr::constReferenceDeclRefExprs ( const VarDecl & VarDecl,
const Stmt & Stmt,
ASTContext & Context,
int Indirections )

Returns set of all DeclRefExprs to VarDecl within Stmt where VarDecl is guaranteed to be accessed in a const fashion.

If VarDecl is of pointer type, Indirections specifies the level of indirection of the object whose mutations we are tracking.

For example, given:

int i;
int* p;
p = &i; // (A)
*p = 3; // (B)
  • constReferenceDeclRefExprs(P, Stmt, Context, 0) returns the reference

constReferenceDeclRefExprs(P, Stmt, Context, 1) returns the reference

Definition at line 351 of file DeclRefExprUtils.cpp.

References constReferenceDeclRefExprs(), and extractNodesByIdTo().

Referenced by constReferenceDeclRefExprs(), and isOnlyUsedAsConst().

◆ extractNodesByIdTo()

template<typename Node>
void clang::tidy::utils::decl_ref_expr::extractNodesByIdTo ( ArrayRef< BoundNodes > Matches,
StringRef ID,
SmallPtrSet< const Node *, 16 > & Nodes )
static

◆ findConstOverload()

const CXXMethodDecl * clang::tidy::utils::decl_ref_expr::findConstOverload ( const CXXMethodDecl & D)
static

Definition at line 63 of file DeclRefExprUtils.cpp.

References hasSameParameterTypes().

Referenced by isLikelyShallowConst().

◆ hasSameParameterTypes()

bool clang::tidy::utils::decl_ref_expr::hasSameParameterTypes ( const CXXMethodDecl & D,
const CXXMethodDecl & O )
static

Definition at line 49 of file DeclRefExprUtils.cpp.

References isSameTypeIgnoringConst().

Referenced by findConstOverload().

◆ isCopyAssignmentArgument()

bool clang::tidy::utils::decl_ref_expr::isCopyAssignmentArgument ( const DeclRefExpr & DeclRef,
const Decl & Decl,
ASTContext & Context )

Returns true if DeclRefExpr is the argument of a copy-assignment operator CallExpr within Decl.

Definition at line 411 of file DeclRefExprUtils.cpp.

References isCopyAssignmentArgument().

Referenced by clang::tidy::performance::UnnecessaryValueParamCheck::check(), and isCopyAssignmentArgument().

◆ isCopyConstructorArgument()

bool clang::tidy::utils::decl_ref_expr::isCopyConstructorArgument ( const DeclRefExpr & DeclRef,
const Decl & Decl,
ASTContext & Context )

Returns true if DeclRefExpr is the argument of a copy-constructor call expression within Decl.

Definition at line 397 of file DeclRefExprUtils.cpp.

References isCopyConstructorArgument().

Referenced by clang::tidy::performance::UnnecessaryValueParamCheck::check(), and isCopyConstructorArgument().

◆ isLikelyShallowConst()

bool clang::tidy::utils::decl_ref_expr::isLikelyShallowConst ( const CXXMethodDecl & M)
static

◆ isOnlyUsedAsConst()

bool clang::tidy::utils::decl_ref_expr::isOnlyUsedAsConst ( const VarDecl & Var,
const Stmt & Stmt,
ASTContext & Context,
int Indirections )

Returns true if all DeclRefExpr to the variable within Stmt do not modify it. See constReferenceDeclRefExprs for the meaning of Indirections.

Definition at line 363 of file DeclRefExprUtils.cpp.

References allDeclRefExprs(), constReferenceDeclRefExprs(), isOnlyUsedAsConst(), and isSetDifferenceEmpty().

Referenced by isOnlyUsedAsConst().

◆ isSameTypeIgnoringConst()

bool clang::tidy::utils::decl_ref_expr::isSameTypeIgnoringConst ( QualType A,
QualType B )
static

◆ isSetDifferenceEmpty()

template<typename S>
bool clang::tidy::utils::decl_ref_expr::isSetDifferenceEmpty ( const S & S1,
const S & S2 )
static

Definition at line 23 of file DeclRefExprUtils.cpp.

Referenced by isOnlyUsedAsConst().

◆ pointsToSameTypeIgnoringConst()

bool clang::tidy::utils::decl_ref_expr::pointsToSameTypeIgnoringConst ( QualType A,
QualType B )
static

Definition at line 84 of file DeclRefExprUtils.cpp.

References isSameTypeIgnoringConst().

Referenced by isLikelyShallowConst().