11 #include "clang/ASTMatchers/ASTMatchFinder.h" 12 #include "clang/ASTMatchers/ASTMatchers.h" 13 #include "clang/Lex/Lexer.h" 18 using namespace ast_matchers;
21 const Stmt &Statement) {
22 return selectFirst<const FunctionDecl>(
23 "function",
match(stmt(hasAncestor(functionDecl().bind(
"function"))),
28 const Expr *E_base = E->IgnoreImpCasts();
29 if (clang::isa<clang::BinaryOperator>(E_base) ||
30 clang::isa<clang::ConditionalOperator>(E_base)) {
34 if (
const auto *Operator =
35 clang::dyn_cast<clang::CXXOperatorCallExpr>(E_base)) {
36 return Operator->isInfixBinaryOp();
43 const LangOptions &LangOpts,
46 if (isa<IntegerLiteral>(Flags)) {
47 if (!SM.isMacroBodyExpansion(Flags->getBeginLoc()) &&
48 !SM.isMacroArgExpansion(Flags->getBeginLoc()))
52 auto MacroName = Lexer::getSourceText(
55 return MacroName == FlagName;
58 if (
const auto *BO = dyn_cast<BinaryOperator>(Flags))
59 if (BO->getOpcode() == clang::BinaryOperatorKind::BO_Or)
61 LangOpts, FlagName) ||
70 const SourceManager *SM) {
72 SourceLocation MacroArgExpansionStartForRangeBegin;
73 SourceLocation MacroArgExpansionStartForRangeEnd;
74 bool RangeIsEntirelyWithinMacroArgument =
76 SM->isMacroArgExpansion(Range.getBegin(),
77 &MacroArgExpansionStartForRangeBegin) &&
78 SM->isMacroArgExpansion(Range.getEnd(),
79 &MacroArgExpansionStartForRangeEnd) &&
80 MacroArgExpansionStartForRangeBegin == MacroArgExpansionStartForRangeEnd;
82 return RangeIsEntirelyWithinMacroArgument;
87 Range.getBegin().isMacroID() || Range.getEnd().isMacroID();
bool IsBinaryOrTernary(const Expr *E)
bool rangeIsEntirelyWithinMacroArgument(SourceRange Range, const SourceManager *SM)
bool rangeContainsMacroExpansion(SourceRange Range, const SourceManager *SM)
bool exprHasBitFlagWithSpelling(const Expr *Flags, const SourceManager &SM, const LangOptions &LangOpts, StringRef FlagName)
Checks whether a macro flag is present in the given argument.
std::vector< std::string > match(const SymbolIndex &I, const FuzzyFindRequest &Req, bool *Incomplete)
const FunctionDecl * getSurroundingFunction(ASTContext &Context, const Stmt &Statement)
llvm::Optional< Range > getTokenRange(const SourceManager &SM, const LangOptions &LangOpts, SourceLocation TokLoc)
Returns the taken range at TokLoc.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
CharSourceRange Range
SourceRange for the file name.
bool rangeCanBeFixed(SourceRange Range, const SourceManager *SM)