blob: ad2a055f5fb97ffb8b1c0b8bb71d341b53d9db2f [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001//===---------- 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
14namespace clang {
15namespace tidy {
16namespace utils {
17// Returns the (closest) Function declaration surrounding |Statement| or NULL.
18const FunctionDecl *getSurroundingFunction(ASTContext &Context,
19 const Stmt &Statement);
20// Determine whether Expr is a Binary or Ternary expression.
21bool 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> | ...
26bool 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.
31bool rangeIsEntirelyWithinMacroArgument(SourceRange Range,
32 const SourceManager *SM);
33
34// Check if the range contains any locations from a macro expansion.
35bool 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.
39bool 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