clang-tools  14.0.0git
DeclRefExprUtils.h
Go to the documentation of this file.
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 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 
16 namespace clang {
17 namespace tidy {
18 namespace utils {
19 namespace decl_ref_expr {
20 
21 /// Returns true if all ``DeclRefExpr`` to the variable within ``Stmt``
22 /// do not modify it.
23 ///
24 /// Returns ``true`` if only const methods or operators are called on the
25 /// variable or the variable is a const reference or value argument to a
26 /// ``callExpr()``.
27 bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt,
28  ASTContext &Context);
29 
30 /// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt``.
31 llvm::SmallPtrSet<const DeclRefExpr *, 16>
32 allDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context);
33 
34 /// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Decl``.
35 llvm::SmallPtrSet<const DeclRefExpr *, 16>
36 allDeclRefExprs(const VarDecl &VarDecl, const Decl &Decl, ASTContext &Context);
37 
38 /// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt`` where
39 /// ``VarDecl`` is guaranteed to be accessed in a const fashion.
40 llvm::SmallPtrSet<const DeclRefExpr *, 16>
41 constReferenceDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt,
42  ASTContext &Context);
43 
44 /// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-constructor
45 /// call expression within ``Decl``.
46 bool isCopyConstructorArgument(const DeclRefExpr &DeclRef, const Decl &Decl,
47  ASTContext &Context);
48 
49 /// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-assignment
50 /// operator CallExpr within ``Decl``.
51 bool isCopyAssignmentArgument(const DeclRefExpr &DeclRef, const Decl &Decl,
52  ASTContext &Context);
53 
54 } // namespace decl_ref_expr
55 } // namespace utils
56 } // namespace tidy
57 } // namespace clang
58 
59 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
clang::tidy::utils::decl_ref_expr::allDeclRefExprs
SmallPtrSet< const DeclRefExpr *, 16 > allDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context)
Returns set of all DeclRefExprs to VarDecl within Stmt.
Definition: DeclRefExprUtils.cpp:101
Decl
const FunctionDecl * Decl
Definition: AvoidBindCheck.cpp:100
clang::tidy::utils::decl_ref_expr::isCopyAssignmentArgument
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.
Definition: DeclRefExprUtils.cpp:135
clang::tidy::utils::decl_ref_expr::constReferenceDeclRefExprs
SmallPtrSet< const DeclRefExpr *, 16 > constReferenceDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context)
Returns set of all DeclRefExprs to VarDecl within Stmt where VarDecl is guaranteed to be accessed in ...
Definition: DeclRefExprUtils.cpp:45
clang::tidy::utils::decl_ref_expr::isCopyConstructorArgument
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.
Definition: DeclRefExprUtils.cpp:121
DeclRef
const DeclRefExpr * DeclRef
Definition: UseAfterMoveCheck.cpp:50
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::utils::decl_ref_expr::isOnlyUsedAsConst
bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt, ASTContext &Context)
Returns true if all DeclRefExpr to the variable within Stmt do not modify it.
Definition: DeclRefExprUtils.cpp:88