| 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::tidy::utils::decl_ref_expr { |
| 17 |
|
| 18 |
/// Returns true if all ``DeclRefExpr`` to the variable within ``Stmt`` |
| 19 |
/// do not modify it. |
| 20 |
/// |
| 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 |
| 23 |
/// ``callExpr()``. |
| 24 |
bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt, |
| 25 |
ASTContext &Context); |
| 26 |
|
| 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); |
| 30 |
|
| 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); |
| 34 |
|
| 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, |
| 39 |
ASTContext &Context); |
| 40 |
|
| 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, |
| 44 |
ASTContext &Context); |
| 45 |
|
| 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, |
| 49 |
ASTContext &Context); |
| 50 |
|
| 51 |
} // namespace clang::tidy::utils::decl_ref_expr |
| 52 |
|
| 53 |
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H |