15 #include "llvm/ADT/StringRef.h" 16 #include "llvm/Support/Errc.h" 17 #include "llvm/Support/Error.h" 22 using namespace clang;
23 using namespace tooling;
29 using llvm::StringError;
34 return llvm::make_error<StringError>(llvm::errc::invalid_argument, Message);
45 ExpectedType +
" (node id=" + ID +
52 "' (node id=" + ID +
")");
57 auto &NodesMap = Nodes.
getMap();
58 auto It = NodesMap.find(ID);
59 if (It == NodesMap.end())
111 return SelectedRange.takeError();
120 return SelectedRange.takeError();
121 if (SelectedRange->isCharRange())
124 SelectedRange->getEnd(), 0, Result.Context->getSourceManager(),
125 Result.Context->getLangOpts()));
133 return Node.takeError();
134 return Node->get<
Stmt>() !=
nullptr && Node->get<
Expr>() ==
nullptr 144 return Node.takeError();
153 return BeginRange.takeError();
156 return EndRange.takeError();
161 if (Result.SourceManager->isBeforeInTranslationUnit(E, B)) {
176 return Node.takeError();
179 M->getMemberNameInfo().getSourceRange());
180 return typeError(ID, Node->getNodeKind(),
"MemberExpr");
188 return N.takeError();
191 if (!D->getDeclName().isIdentifier())
200 if (
getText(R, *Result.Context) != D->getName())
205 if (!E->getNameInfo().getName().isIdentifier())
211 if (!I->isMemberInitializer() && I->isWritten())
217 "DeclRefExpr, NamedDecl, CXXCtorInitializer");
225 template <
typename T, CharSourceRange (*Func)(const MatchResult &, const T &)>
226 class RelativeSelector {
230 RelativeSelector(std::string ID) :
ID(std::move(ID)) {}
235 return N.takeError();
236 if (
const auto *Arg = N->get<T>())
237 return Func(Result, *Arg);
257 return RelativeSelector<CompoundStmt, getStatementsRange>(std::move(ID));
266 .getLocWithOffset(1),
272 return RelativeSelector<CallExpr, getCallArgumentsRange>(std::move(ID));
286 return RelativeSelector<InitListExpr, getElementsRange>(std::move(ID));
293 return SRange.takeError();
294 return Result.SourceManager->getExpansionRange(*SRange);
A class to allow finding matches over the Clang AST.
SourceLocation getRBracLoc() const
SourceLocation getRParenLoc() const
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
Smart pointer class that efficiently represents Objective-C method names.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Stmt - This represents one statement.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
StringRef asStringRef() const
String representation of the kind.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
static CharSourceRange getTokenRange(SourceRange R)
const T * get() const
Retrieve the stored node as type T.
static Error missingPropertyError(StringRef ID, Twine Description, StringRef Property)
MatchFinder::MatchResult MatchResult
static SourceLocation findOpenParen(const CallExpr &E, const SourceManager &SM, const LangOptions &LangOpts)
BoundNodesTreeBuilder Nodes
const IDToNodeMap & getMap() const
Retrieve mapping from binding identifiers to bound nodes.
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getRBraceLoc() const
Token - This structure provides full information about a lexed token.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Describes an C or C++ initializer list.
SourceLocation getLBracLoc() const
static bool getRawToken(SourceLocation Loc, Token &Result, const SourceManager &SM, const LangOptions &LangOpts, bool IgnoreWhiteSpace=false)
Relex the token at the specified location.
ASTNodeKind getNodeKind() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
This represents one expression.
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
Represents a character-granular source range.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
static SourceLocation findPreviousTokenKind(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts, tok::TokenKind TK)
Contains all information for a given match.
static Error invalidArgumentError(Twine Message)
static CharSourceRange getCharRange(SourceRange R)
static Error typeError(StringRef ID, const ASTNodeKind &Kind)
Maps string IDs to AST nodes matched by parts of a matcher.
Encodes a location in the source.
clang::ASTContext *const Context
Utilities for interpreting the matched AST structures.
static SourceLocation GetBeginningOfToken(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
Given a location any where in a source buffer, find the location that corresponds to the beginning of...
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
ast_type_traits::DynTypedNode DynTypedNode
const BoundNodes Nodes
Contains the nodes bound on the current match.
ast_type_traits::DynTypedNode Node
Dataflow Directional Tag Classes.
SourceLocation getLBraceLoc() const
Represents a C++ base or member initializer.
static Expected< DynTypedNode > getNode(const ast_matchers::BoundNodes &Nodes, StringRef ID)
Defines a combinator library supporting the definition of selectors, which select source ranges based...
static SourceLocation findPreviousTokenStart(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Defines the clang::SourceLocation class and associated facilities.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
A reference to a declared variable, function, enum, etc.
clang::SourceManager *const SourceManager
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
const LangOptions & getLangOpts() const
This class handles loading and caching of source files into memory.