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