ASTUtils.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //===---------- ASTUtils.h - clang-tidy -----------------------------------===//
  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_ASTUTILS_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ASTUTILS_H
  10. #include "clang/AST/AST.h"
  11. namespace clang::tidy::utils {
  12. // Returns the (closest) Function declaration surrounding |Statement| or NULL.
  13. const FunctionDecl *getSurroundingFunction(ASTContext &Context,
  14. const Stmt &Statement);
  15. // Determine whether Expr is a Binary or Ternary expression.
  16. bool isBinaryOrTernary(const Expr *E);
  17. /// Checks whether a macro flag is present in the given argument. Only considers
  18. /// cases of single match or match in a binary OR expression. For example,
  19. /// <needed-flag> or <flag> | <needed-flag> | ...
  20. bool exprHasBitFlagWithSpelling(const Expr *Flags, const SourceManager &SM,
  21. const LangOptions &LangOpts,
  22. StringRef FlagName);
  23. // Check if the range is entirely contained within a macro argument.
  24. bool rangeIsEntirelyWithinMacroArgument(SourceRange Range,
  25. const SourceManager *SM);
  26. // Check if the range contains any locations from a macro expansion.
  27. bool rangeContainsMacroExpansion(SourceRange Range, const SourceManager *SM);
  28. // Can a fix-it be issued for this whole Range?
  29. // FIXME: false-negative if the entire range is fully expanded from a macro.
  30. bool rangeCanBeFixed(SourceRange Range, const SourceManager *SM);
  31. } // namespace clang::tidy::utils
  32. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ASTUTILS_H