clang-tools 23.0.0git
DeclRefExprUtils.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
11
12#include "clang/AST/ASTContext.h"
13#include "clang/AST/Type.h"
14#include "llvm/ADT/SmallPtrSet.h"
15
17
18/// Returns set of all ``DeclRefExprs`` to ``ValueDecl`` within ``Stmt``.
19llvm::SmallPtrSet<const DeclRefExpr *, 16>
20allDeclRefExprs(const ValueDecl &ValueDecl, const Stmt &Stmt,
21 ASTContext &Context);
22
23/// Returns set of all ``DeclRefExprs`` to ``ValueDecl`` within ``Decl``.
24llvm::SmallPtrSet<const DeclRefExpr *, 16>
25allDeclRefExprs(const ValueDecl &ValueDecl, const Decl &Decl,
26 ASTContext &Context);
27
28/// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt`` where
29/// ``VarDecl`` is guaranteed to be accessed in a const fashion.
30///
31/// If ``VarDecl`` is of pointer type, ``Indirections`` specifies the level
32/// of indirection of the object whose mutations we are tracking.
33///
34/// For example, given:
35/// ```
36/// int i;
37/// int* p;
38/// p = &i; // (A)
39/// *p = 3; // (B)
40/// ```
41///
42/// - `constReferenceDeclRefExprs(P, Stmt, Context, 0)` returns the reference
43// to `p` in (B): the pointee is modified, but the pointer is not;
44/// - `constReferenceDeclRefExprs(P, Stmt, Context, 1)` returns the reference
45// to `p` in (A): the pointee is modified, but the pointer is not;
46llvm::SmallPtrSet<const DeclRefExpr *, 16>
47constReferenceDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt,
48 ASTContext &Context, int Indirections);
49
50/// Returns true if all ``DeclRefExpr`` to the variable within ``Stmt``
51/// do not modify it.
52/// See `constReferenceDeclRefExprs` for the meaning of ``Indirections``.
53bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt,
54 ASTContext &Context, int Indirections);
55
56/// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-constructor
57/// call expression within ``Decl``.
58bool isCopyConstructorArgument(const DeclRefExpr &DeclRef, const Decl &Decl,
59 ASTContext &Context);
60
61/// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-assignment
62/// operator CallExpr within ``Decl``.
63bool isCopyAssignmentArgument(const DeclRefExpr &DeclRef, const Decl &Decl,
64 ASTContext &Context);
65
66} // namespace clang::tidy::utils::decl_ref_expr
67
68#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
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.
SmallPtrSet< const DeclRefExpr *, 16 > allDeclRefExprs(const ValueDecl &ValueDecl, const Stmt &Stmt, ASTContext &Context)
Returns set of all DeclRefExprs to ValueDecl within Stmt.
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 constReferenceDeclR...
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.
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 ...