Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:22

0001 //===--- DeclRefExprUtils.h - clang-tidy-------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
0011 
0012 #include "clang/AST/ASTContext.h"
0013 #include "clang/AST/Type.h"
0014 #include "llvm/ADT/SmallPtrSet.h"
0015 
0016 namespace clang::tidy::utils::decl_ref_expr {
0017 
0018 /// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt``.
0019 llvm::SmallPtrSet<const DeclRefExpr *, 16>
0020 allDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context);
0021 
0022 /// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Decl``.
0023 llvm::SmallPtrSet<const DeclRefExpr *, 16>
0024 allDeclRefExprs(const VarDecl &VarDecl, const Decl &Decl, ASTContext &Context);
0025 
0026 /// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt`` where
0027 /// ``VarDecl`` is guaranteed to be accessed in a const fashion.
0028 ///
0029 /// If ``VarDecl`` is of pointer type, ``Indirections`` specifies the level
0030 /// of indirection of the object whose mutations we are tracking.
0031 ///
0032 /// For example, given:
0033 ///   ```
0034 ///   int i;
0035 ///   int* p;
0036 ///   p = &i;  // (A)
0037 ///   *p = 3;  // (B)
0038 ///   ```
0039 ///
0040 ///   - `constReferenceDeclRefExprs(P, Stmt, Context, 0)` returns the reference
0041 //      to `p` in (B): the pointee is modified, but the pointer is not;
0042 ///   - `constReferenceDeclRefExprs(P, Stmt, Context, 1)` returns the reference
0043 //      to `p` in (A): the pointee is modified, but the pointer is not;
0044 llvm::SmallPtrSet<const DeclRefExpr *, 16>
0045 constReferenceDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt,
0046                            ASTContext &Context, int Indirections);
0047 
0048 /// Returns true if all ``DeclRefExpr`` to the variable within ``Stmt``
0049 /// do not modify it.
0050 /// See `constReferenceDeclRefExprs` for the meaning of ``Indirections``.
0051 bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt,
0052                        ASTContext &Context, int Indirections);
0053 
0054 /// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-constructor
0055 /// call expression within ``Decl``.
0056 bool isCopyConstructorArgument(const DeclRefExpr &DeclRef, const Decl &Decl,
0057                                ASTContext &Context);
0058 
0059 /// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-assignment
0060 /// operator CallExpr within ``Decl``.
0061 bool isCopyAssignmentArgument(const DeclRefExpr &DeclRef, const Decl &Decl,
0062                               ASTContext &Context);
0063 
0064 } // namespace clang::tidy::utils::decl_ref_expr
0065 
0066 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H