16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/Errc.h"
18#include "llvm/Support/Error.h"
23using namespace transformer;
27using llvm::StringError;
32 return llvm::make_error<StringError>(llvm::errc::invalid_argument, Message);
37 " kind=" + Kind.asStringRef() +
")");
44 " kind=" + Kind.asStringRef() +
")");
50 "' (node id=" + ID +
")");
55 auto &NodesMap =
Nodes.getMap();
56 auto It = NodesMap.find(ID);
57 if (It == NodesMap.end())
92 return T.getLocation();
102 return SelectedRange.takeError();
111 return SelectedRange.takeError();
113 if (SelectedRange->isTokenRange()) {
122 *Result.SourceManager, Result.Context->
getLangOpts());
125 "after: can't resolve sub-range to valid source range");
137 return Node.takeError();
150 return Node.takeError();
160 return BeginRange.takeError();
163 return EndRange.takeError();
168 if (Result.SourceManager->isBeforeInTranslationUnit(
E, B)) {
184 return Node.takeError();
187 M->getMemberNameInfo().getSourceRange());
196 return N.takeError();
199 if (!
D->getDeclName().isIdentifier())
213 if (!
E->getNameInfo().getName().isIdentifier())
219 if (!I->isMemberInitializer() && I->isWritten())
231 "DeclRefExpr, NamedDecl, CXXCtorInitializer, TypeLoc");
242template <
typename T, CharSourceRange (*Func)(const MatchResult &, const T &)>
243class RelativeSelector {
247 RelativeSelector(std::string ID) : ID(
std::move(ID)) {}
252 return N.takeError();
253 if (
const auto *Arg = N->get<
T>())
254 return Func(Result, *Arg);
274 return RelativeSelector<CompoundStmt, getStatementsRange>(std::move(ID));
291 for (
int i = CE.
getNumArgs() - 1; i >= 0; --i) {
293 if (isa<CXXDefaultArgExpr>(Arg))
305 findArgStartDelimiter(CE, RLoc, *Result.SourceManager,
307 .getLocWithOffset(1),
325 findLastArgEnd(CE, *Result.SourceManager,
335 return RelativeSelector<CallExpr, getCallArgumentsRange>(std::move(ID));
339 return RelativeSelector<CXXConstructExpr, getConstructArgumentsRange>(
354 return RelativeSelector<InitListExpr, getElementsRange>(std::move(ID));
362 tok::TokenKind::semi, *Result.Context);
367 return RelativeSelector<IfStmt, getElseRange>(std::move(ID));
374 return SRange.takeError();
375 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)
MatchFinder::MatchResult MatchResult
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)
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 call to a C++ constructor.
SourceRange getParenOrBraceRange() const
Expr * getArg(unsigned Arg)
Return the specified argument.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ base or member initializer.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.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.
SourceLocation getLocation() const
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
ASTNodeKind getNodeKind() const
const T * get() const
Retrieve the stored node as type T.
SourceRange getSourceRange(bool IncludeQualifier=false) const
For nodes which represent textual entities in the source code, return their SourceRange.
This represents one expression.
IfStmt - This represents an if/then/else.
Describes an C or C++ initializer list.
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.
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.
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.
SourceLocation getEnd() const
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
Token - This structure provides full information about a lexed token.
Base wrapper for a particular "section" of type source info.
const T * getAs() const
Member-template getAs<specific type>'.
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.
The JSON file list parser is used to communicate input to InstallAPI.
@ Property
The type of a property.
const FunctionProtoType * T
Contains all information for a given match.