blob: abf3529cc0f6b72219ea89a16328f10d0c2f93c1 [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001//===--- 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
16namespace clang {
17namespace tidy {
18namespace utils {
19namespace 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()``.
27bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt,
28 ASTContext &Context);
29
30/// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt``.
31llvm::SmallPtrSet<const DeclRefExpr *, 16>
32allDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context);
33
34/// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Decl``.
35llvm::SmallPtrSet<const DeclRefExpr *, 16>
36allDeclRefExprs(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.
40llvm::SmallPtrSet<const DeclRefExpr *, 16>
41constReferenceDeclRefExprs(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``.
46bool 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``.
51bool 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