clang-tools  3.9.0
DeclRefExprUtils.h
Go to the documentation of this file.
1 //===--- DeclRefExprUtils.h - clang-tidy-------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
12 
13 #include "clang/AST/ASTContext.h"
14 #include "clang/AST/Type.h"
15 #include "llvm/ADT/SmallPtrSet.h"
16 
17 namespace clang {
18 namespace tidy {
19 namespace utils {
20 namespace decl_ref_expr {
21 
22 /// \brief Returns true if all ``DeclRefExpr`` to the variable within ``Stmt``
23 /// do not modify it.
24 ///
25 /// Returns ``true`` if only const methods or operators are called on the
26 /// variable or the variable is a const reference or value argument to a
27 /// ``callExpr()``.
28 bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt,
29  ASTContext &Context);
30 
31 // Returns set of all DeclRefExprs to VarDecl in Stmt.
32 llvm::SmallPtrSet<const DeclRefExpr *, 16>
33 allDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context);
34 
35 // Returns set of all DeclRefExprs where VarDecl is guaranteed to be accessed in
36 // a const fashion.
37 llvm::SmallPtrSet<const DeclRefExpr *, 16>
38 constReferenceDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt,
39  ASTContext &Context);
40 
41 // Returns true if DeclRefExpr is the argument of a copy-constructor call expr.
42 bool isCopyConstructorArgument(const DeclRefExpr &DeclRef, const Stmt &Stmt,
43  ASTContext &Context);
44 
45 // Returns true if DeclRefExpr is the argument of a copy-assignment operator
46 // call expr.
47 bool isCopyAssignmentArgument(const DeclRefExpr &DeclRef, const Stmt &Stmt,
48  ASTContext &Context);
49 
50 } // namespace decl_ref_expr
51 } // namespace utils
52 } // namespace tidy
53 } // namespace clang
54 
55 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
SmallPtrSet< const DeclRefExpr *, 16 > allDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context)
bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt, ASTContext &Context)
Returns true if all DeclRefExpr to the variable within Stmt do not modify it.
bool isCopyAssignmentArgument(const DeclRefExpr &DeclRef, const Stmt &Stmt, ASTContext &Context)
bool isCopyConstructorArgument(const DeclRefExpr &DeclRef, const Stmt &Stmt, ASTContext &Context)
SmallPtrSet< const DeclRefExpr *, 16 > constReferenceDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context)
ClangTidyContext & Context
Definition: ClangTidy.cpp:93