clang-tools 19.0.0git
ASTUtils.h
Go to the documentation of this file.
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
14namespace clang::tidy::utils {
15// Returns the (closest) Function declaration surrounding |Statement| or NULL.
16const FunctionDecl *getSurroundingFunction(ASTContext &Context,
17 const Stmt &Statement);
18// Determine whether Expr is a Binary or Ternary expression.
19bool isBinaryOrTernary(const Expr *E);
20
21/// Checks whether a macro flag is present in the given argument. Only considers
22/// cases of single match or match in a binary OR expression. For example,
23/// <needed-flag> or <flag> | <needed-flag> | ...
24bool exprHasBitFlagWithSpelling(const Expr *Flags, const SourceManager &SM,
25 const LangOptions &LangOpts,
26 StringRef FlagName);
27
28// Check if the range is entirely contained within a macro argument.
30 const SourceManager *SM);
31
32// Check if the range contains any locations from a macro expansion.
33bool rangeContainsMacroExpansion(SourceRange Range, const SourceManager *SM);
34
35// Can a fix-it be issued for this whole Range?
36// FIXME: false-negative if the entire range is fully expanded from a macro.
37bool rangeCanBeFixed(SourceRange Range, const SourceManager *SM);
38
39// Check if statements are same
40bool areStatementsIdentical(const Stmt *FirstStmt, const Stmt *SecondStmt,
41 const ASTContext &Context, bool Canonical = false);
42
43// Given a field of an anonymous record, find its corresponding
44// IndirectFieldDecl in the outermost possible scope.
45const IndirectFieldDecl *
47
48} // namespace clang::tidy::utils
49
50#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ASTUTILS_H
const Expr * E
CharSourceRange Range
SourceRange for the file name.
bool rangeCanBeFixed(SourceRange Range, const SourceManager *SM)
Definition: ASTUtils.cpp:86
bool isBinaryOrTernary(const Expr *E)
Definition: ASTUtils.cpp:25
bool rangeContainsMacroExpansion(SourceRange Range, const SourceManager *SM)
Definition: ASTUtils.cpp:81
bool areStatementsIdentical(const Stmt *FirstStmt, const Stmt *SecondStmt, const ASTContext &Context, bool Canonical)
Definition: ASTUtils.cpp:91
bool exprHasBitFlagWithSpelling(const Expr *Flags, const SourceManager &SM, const LangOptions &LangOpts, StringRef FlagName)
Checks whether a macro flag is present in the given argument.
Definition: ASTUtils.cpp:38
const IndirectFieldDecl * findOutermostIndirectFieldDeclForField(const FieldDecl *FD)
Definition: ASTUtils.cpp:117
bool rangeIsEntirelyWithinMacroArgument(SourceRange Range, const SourceManager *SM)
Definition: ASTUtils.cpp:65
const FunctionDecl * getSurroundingFunction(ASTContext &Context, const Stmt &Statement)
Definition: ASTUtils.cpp:18