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