brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · 794adc0 Raw
67 lines · c
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H11 12#include "clang/AST/ASTContext.h"13#include "clang/AST/Type.h"14#include "llvm/ADT/SmallPtrSet.h"15 16namespace clang::tidy::utils::decl_ref_expr {17 18/// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt``.19llvm::SmallPtrSet<const DeclRefExpr *, 16>20allDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context);21 22/// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Decl``.23llvm::SmallPtrSet<const DeclRefExpr *, 16>24allDeclRefExprs(const VarDecl &VarDecl, const Decl &Decl, ASTContext &Context);25 26/// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt`` where27/// ``VarDecl`` is guaranteed to be accessed in a const fashion.28///29/// If ``VarDecl`` is of pointer type, ``Indirections`` specifies the level30/// of indirection of the object whose mutations we are tracking.31///32/// For example, given:33///   ```34///   int i;35///   int* p;36///   p = &i;  // (A)37///   *p = 3;  // (B)38///   ```39///40///   - `constReferenceDeclRefExprs(P, Stmt, Context, 0)` returns the reference41//      to `p` in (B): the pointee is modified, but the pointer is not;42///   - `constReferenceDeclRefExprs(P, Stmt, Context, 1)` returns the reference43//      to `p` in (A): the pointee is modified, but the pointer is not;44llvm::SmallPtrSet<const DeclRefExpr *, 16>45constReferenceDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt,46                           ASTContext &Context, int Indirections);47 48/// Returns true if all ``DeclRefExpr`` to the variable within ``Stmt``49/// do not modify it.50/// See `constReferenceDeclRefExprs` for the meaning of ``Indirections``.51bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt,52                       ASTContext &Context, int Indirections);53 54/// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-constructor55/// call expression within ``Decl``.56bool isCopyConstructorArgument(const DeclRefExpr &DeclRef, const Decl &Decl,57                               ASTContext &Context);58 59/// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-assignment60/// operator CallExpr within ``Decl``.61bool isCopyAssignmentArgument(const DeclRefExpr &DeclRef, const Decl &Decl,62                              ASTContext &Context);63 64} // namespace clang::tidy::utils::decl_ref_expr65 66#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H67