16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/Errc.h"
18#include "llvm/Support/Error.h"
24using namespace transformer;
28using llvm::StringError;
33 return llvm::make_error<StringError>(llvm::errc::invalid_argument, Message);
38 " kind=" + Kind.asStringRef() +
")");
45 " kind=" + Kind.asStringRef() +
")");
51 "' (node id=" + ID +
")");
56 auto &NodesMap =
Nodes.getMap();
57 auto It = NodesMap.find(ID);
58 if (It == NodesMap.end())
110 return SelectedRange.takeError();
119 return SelectedRange.takeError();
121 if (SelectedRange->isTokenRange()) {
130 *Result.SourceManager, Result.Context->
getLangOpts());
131 if (
Range.isInvalid())
133 "after: can't resolve sub-range to valid source range");
134 End =
Range.getEnd();
145 return Node.takeError();
158 return Node.takeError();
168 return BeginRange.takeError();
171 return EndRange.takeError();
176 if (Result.SourceManager->isBeforeInTranslationUnit(E, B)) {
192 return Node.takeError();
195 M->getMemberNameInfo().getSourceRange());
204 return N.takeError();
207 if (!D->getDeclName().isIdentifier())
221 if (!E->getNameInfo().getName().isIdentifier())
227 if (!I->isMemberInitializer() && I->isWritten())
236 Loc = ET.getNamedTypeLoc();
243 "DeclRefExpr, NamedDecl, CXXCtorInitializer, TypeLoc");
254template <
typename T, CharSourceRange (*Func)(const MatchResult &, const T &)>
255class RelativeSelector {
259 RelativeSelector(std::string ID) : ID(
std::move(ID)) {}
264 return N.takeError();
265 if (
const auto *Arg = N->get<T>())
266 return Func(Result, *Arg);
286 return RelativeSelector<CompoundStmt, getStatementsRange>(std::move(ID));
301 return RelativeSelector<CallExpr, getCallArgumentsRange>(std::move(ID));
315 return RelativeSelector<InitListExpr, getElementsRange>(std::move(ID));
323 tok::TokenKind::semi, *Result.Context);
328 return RelativeSelector<IfStmt, getElseRange>(std::move(ID));
335 return SRange.takeError();
336 return Result.SourceManager->getExpansionRange(*SRange);
BoundNodesTreeBuilder Nodes
static Error invalidArgumentError(Twine Message)
static SourceLocation findPreviousTokenKind(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts, tok::TokenKind TK)
static SourceLocation findPreviousTokenStart(SourceLocation Start, const SourceManager &SM, const LangOptions &LangOpts)
static Error missingPropertyError(StringRef ID, Twine Description, StringRef Property)
static Error typeError(StringRef ID, const ASTNodeKind &Kind)
static Expected< DynTypedNode > getNode(const ast_matchers::BoundNodes &Nodes, StringRef ID)
static SourceLocation findOpenParen(const CallExpr &E, const SourceManager &SM, const LangOptions &LangOpts)
Defines a combinator library supporting the definition of selectors, which select source ranges based...
Defines the clang::SourceLocation class and associated facilities.
Defines the clang::TypeLoc interface and its subclasses.
Represents a C++ base or member initializer.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
SourceLocation getRParenLoc() const
Represents a character-granular source range.
static CharSourceRange getCharRange(SourceRange R)
static CharSourceRange getTokenRange(SourceRange R)
CompoundStmt - This represents a group of statements like { stmt stmt }.
SourceLocation getLBracLoc() const
SourceLocation getRBracLoc() const
A reference to a declared variable, function, enum, etc.
Decl - This represents one declaration (or definition), e.g.
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
ASTNodeKind getNodeKind() const
SourceRange getSourceRange() const
For nodes which represent textual entities in the source code, return their SourceRange.
const T * get() const
Retrieve the stored node as type T.
This represents one expression.
IfStmt - This represents an if/then/else.
Describes an C or C++ initializer list.
SourceLocation getLBraceLoc() const
SourceLocation getRBraceLoc() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
static CharSourceRange makeFileCharRange(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts)
Accepts a range and returns a character range with file locations.
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...
static bool getRawToken(SourceLocation Loc, Token &Result, const SourceManager &SM, const LangOptions &LangOpts, bool IgnoreWhiteSpace=false)
Relex the token at the specified location.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
This represents a decl that may have a name.
Smart pointer class that efficiently represents Objective-C method names.
Encodes a location in the source.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
SourceLocation getBeginLoc() const LLVM_READONLY
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
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)) {....
Base wrapper for a particular "section" of type source info.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Maps string IDs to AST nodes matched by parts of a matcher.
A class to allow finding matches over the Clang AST.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
@ Property
The type of a property.
Contains all information for a given match.