clang-tools 18.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
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()``.
24bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt,
25 ASTContext &Context);
26
27/// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt``.
28llvm::SmallPtrSet<const DeclRefExpr *, 16>
29allDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context);
30
31/// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Decl``.
32llvm::SmallPtrSet<const DeclRefExpr *, 16>
33allDeclRefExprs(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.
37llvm::SmallPtrSet<const DeclRefExpr *, 16>
38constReferenceDeclRefExprs(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``.
43bool 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``.
48bool 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
const FunctionDecl * Decl
const DeclRefExpr * DeclRef
SmallPtrSet< const DeclRefExpr *, 16 > allDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context)
Returns set of all DeclRefExprs to VarDecl within Stmt.
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 ...
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.
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 Decl &Decl, ASTContext &Context)
Returns true if DeclRefExpr is the argument of a copy-assignment operator CallExpr within Decl.