1 //===--- DeclRefExprUtils.h - clang-tidy-------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
12 #include "clang/AST/ASTContext.h"
13 #include "clang/AST/Type.h"
14 #include "llvm/ADT/SmallPtrSet.h"
16 namespace clang::tidy::utils::decl_ref_expr
{
18 /// Returns true if all ``DeclRefExpr`` to the variable within ``Stmt``
21 /// Returns ``true`` if only const methods or operators are called on the
22 /// variable or the variable is a const reference or value argument to a
24 bool isOnlyUsedAsConst(const VarDecl
&Var
, const Stmt
&Stmt
,
27 /// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt``.
28 llvm::SmallPtrSet
<const DeclRefExpr
*, 16>
29 allDeclRefExprs(const VarDecl
&VarDecl
, const Stmt
&Stmt
, ASTContext
&Context
);
31 /// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Decl``.
32 llvm::SmallPtrSet
<const DeclRefExpr
*, 16>
33 allDeclRefExprs(const VarDecl
&VarDecl
, const Decl
&Decl
, ASTContext
&Context
);
35 /// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt`` where
36 /// ``VarDecl`` is guaranteed to be accessed in a const fashion.
37 llvm::SmallPtrSet
<const DeclRefExpr
*, 16>
38 constReferenceDeclRefExprs(const VarDecl
&VarDecl
, const Stmt
&Stmt
,
41 /// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-constructor
42 /// call expression within ``Decl``.
43 bool isCopyConstructorArgument(const DeclRefExpr
&DeclRef
, const Decl
&Decl
,
46 /// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-assignment
47 /// operator CallExpr within ``Decl``.
48 bool isCopyAssignmentArgument(const DeclRefExpr
&DeclRef
, const Decl
&Decl
,
51 } // namespace clang::tidy::utils::decl_ref_expr
53 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H