DeclRefExprUtils.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H
  10. #include "clang/AST/ASTContext.h"
  11. #include "clang/AST/Type.h"
  12. #include "llvm/ADT/SmallPtrSet.h"
  13. namespace clang::tidy::utils::decl_ref_expr {
  14. /// Returns true if all ``DeclRefExpr`` to the variable within ``Stmt``
  15. /// do not modify it.
  16. ///
  17. /// Returns ``true`` if only const methods or operators are called on the
  18. /// variable or the variable is a const reference or value argument to a
  19. /// ``callExpr()``.
  20. bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt,
  21. ASTContext &Context);
  22. /// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt``.
  23. llvm::SmallPtrSet<const DeclRefExpr *, 16>
  24. allDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context);
  25. /// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Decl``.
  26. llvm::SmallPtrSet<const DeclRefExpr *, 16>
  27. allDeclRefExprs(const VarDecl &VarDecl, const Decl &Decl, ASTContext &Context);
  28. /// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Stmt`` where
  29. /// ``VarDecl`` is guaranteed to be accessed in a const fashion.
  30. llvm::SmallPtrSet<const DeclRefExpr *, 16>
  31. constReferenceDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt,
  32. ASTContext &Context);
  33. /// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-constructor
  34. /// call expression within ``Decl``.
  35. bool isCopyConstructorArgument(const DeclRefExpr &DeclRef, const Decl &Decl,
  36. ASTContext &Context);
  37. /// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-assignment
  38. /// operator CallExpr within ``Decl``.
  39. bool isCopyAssignmentArgument(const DeclRefExpr &DeclRef, const Decl &Decl,
  40. ASTContext &Context);
  41. } // namespace clang::tidy::utils::decl_ref_expr
  42. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_DECLREFEXPRUTILS_H