• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
60