clang 20.0.0git
|
A helper class for constructing the syntax tree while traversing a clang AST. More...
Public Member Functions | |
TreeBuilder (syntax::Arena &Arena, TokenBufferTokenManager &TBTM) | |
llvm::BumpPtrAllocator & | allocator () |
const SourceManager & | sourceManager () const |
void | foldNode (ArrayRef< syntax::Token > Range, syntax::Tree *New, ASTPtr From) |
Populate children for New node, assuming it covers tokens from Range . | |
void | foldNode (ArrayRef< syntax::Token > Range, syntax::Tree *New, TypeLoc L) |
void | foldNode (llvm::ArrayRef< syntax::Token > Range, syntax::Tree *New, NestedNameSpecifierLoc From) |
void | foldList (ArrayRef< syntax::Token > SuperRange, syntax::List *New, ASTPtr From) |
Populate children for New list, assuming it covers tokens from a subrange of SuperRange . | |
void | noticeDeclWithoutSemicolon (Decl *D) |
Notifies that we should not consume trailing semicolon when computing token range of D . | |
void | markStmtChild (Stmt *Child, NodeRole Role) |
Mark the Child node with a corresponding Role . | |
void | markExprChild (Expr *Child, NodeRole Role) |
Should be called for expressions in non-statement position to avoid wrapping into expression statement. | |
void | markChildToken (SourceLocation Loc, NodeRole R) |
Set role for a token starting at Loc . | |
void | markChildToken (const syntax::Token *T, NodeRole R) |
Set role for T . | |
void | markChild (syntax::Node *N, NodeRole R) |
Set role for N . | |
void | markChild (ASTPtr N, NodeRole R) |
Set role for the syntax node matching N . | |
void | markChild (NestedNameSpecifierLoc N, NodeRole R) |
Set role for the syntax node matching N . | |
syntax::TranslationUnit * | finalize () && |
Finish building the tree and consume the root node. | |
const syntax::Token * | findToken (SourceLocation L) const |
Finds a token starting at L . The token must exist if L is valid. | |
ArrayRef< syntax::Token > | getRange (SourceRange Range) const |
Finds the syntax tokens corresponding to the SourceRange . | |
ArrayRef< syntax::Token > | getRange (SourceLocation First, SourceLocation Last) const |
Finds the syntax tokens corresponding to the passed source locations. | |
ArrayRef< syntax::Token > | getTemplateRange (const ClassTemplateSpecializationDecl *D) const |
bool | isResponsibleForCreatingDeclaration (const Decl *D) const |
Returns true if D is the last declarator in a chain and is thus reponsible for creating SimpleDeclaration for the whole chain. | |
ArrayRef< syntax::Token > | getDeclarationRange (Decl *D) |
ArrayRef< syntax::Token > | getExprRange (const Expr *E) const |
ArrayRef< syntax::Token > | getStmtRange (const Stmt *S) const |
Find the adjusted range for the statement, consuming the trailing semicolon when needed. | |
A helper class for constructing the syntax tree while traversing a clang AST.
At each point of the traversal we maintain a list of pending nodes. Initially all tokens are added as pending nodes. When processing a clang AST node, the clients need to:
Note that all children are expected to be processed when building a node.
Call finalize() to finish building the tree and consume the root node.
Definition at line 367 of file BuildTree.cpp.
|
inline |
Definition at line 369 of file BuildTree.cpp.
References clang::syntax::TokenBuffer::expandedTokens(), clang::T, and clang::syntax::TokenBufferTokenManager::tokenBuffer().
|
inline |
Definition at line 377 of file BuildTree.cpp.
References clang::syntax::Arena::getAllocator().
|
inline |
Finish building the tree and consume the root node.
Definition at line 440 of file BuildTree.cpp.
References clang::syntax::TokenBuffer::expandedTokens(), clang::syntax::TreeBuilder::finalize(), clang::syntax::Arena::getAllocator(), and clang::syntax::TokenBufferTokenManager::tokenBuffer().
Referenced by clang::syntax::TreeBuilder::finalize().
const syntax::Token * clang::syntax::TreeBuilder::findToken | ( | SourceLocation | L | ) | const |
Finds a token starting at L
. The token must exist if L
is valid.
Definition at line 1746 of file BuildTree.cpp.
References clang::SourceLocation::isInvalid().
Referenced by clang::syntax::TreeBuilder::getRange().
|
inline |
Populate children for New
list, assuming it covers tokens from a subrange of SuperRange
.
Definition at line 406 of file BuildTree.cpp.
References clang::syntax::TokenBufferTokenManager::tokenBuffer().
|
inline |
Populate children for New
node, assuming it covers tokens from Range
.
Definition at line 384 of file BuildTree.cpp.
References Range, and clang::syntax::TokenBufferTokenManager::tokenBuffer().
Referenced by clang::syntax::TreeBuilder::foldNode().
|
inline |
Definition at line 391 of file BuildTree.cpp.
References clang::syntax::TreeBuilder::foldNode(), and Range.
|
inline |
Definition at line 396 of file BuildTree.cpp.
References Range, and clang::syntax::TokenBufferTokenManager::tokenBuffer().
|
inline |
Definition at line 509 of file BuildTree.cpp.
References D, clang::syntax::TreeBuilder::getRange(), and clang::Decl::getSourceRange().
|
inline |
Definition at line 519 of file BuildTree.cpp.
References E, clang::syntax::TreeBuilder::getRange(), and clang::Stmt::getSourceRange().
|
inline |
Finds the syntax tokens corresponding to the passed source locations.
First
is the start position of the first token and Last
is the start position of the last token.
Definition at line 466 of file BuildTree.cpp.
References clang::syntax::TreeBuilder::findToken(), clang::First, clang::SourceManager::isBeforeInTranslationUnit(), clang::Last, and clang::syntax::TokenBufferTokenManager::sourceManager().
|
inline |
Finds the syntax tokens corresponding to the SourceRange
.
Definition at line 458 of file BuildTree.cpp.
References clang::SourceRange::getBegin(), clang::SourceRange::getEnd(), clang::syntax::TreeBuilder::getRange(), clang::SourceRange::isValid(), and Range.
Referenced by clang::syntax::TreeBuilder::getDeclarationRange(), clang::syntax::TreeBuilder::getExprRange(), clang::syntax::TreeBuilder::getRange(), clang::syntax::TreeBuilder::getStmtRange(), and clang::syntax::TreeBuilder::getTemplateRange().
|
inline |
Find the adjusted range for the statement, consuming the trailing semicolon when needed.
Definition at line 525 of file BuildTree.cpp.
References clang::syntax::TreeBuilder::getRange().
|
inline |
Definition at line 476 of file BuildTree.cpp.
References D, clang::syntax::TreeBuilder::getRange(), and clang::Decl::getSourceRange().
Returns true if D
is the last declarator in a chain and is thus reponsible for creating SimpleDeclaration for the whole chain.
Definition at line 483 of file BuildTree.cpp.
References D, clang::Decl::getBeginLoc(), clang::Decl::getKind(), and clang::Decl::getNextDeclInContext().
void clang::syntax::TreeBuilder::markChild | ( | ASTPtr | N, |
NodeRole | R | ||
) |
Set role for the syntax node matching N
.
Definition at line 1706 of file BuildTree.cpp.
void clang::syntax::TreeBuilder::markChild | ( | NestedNameSpecifierLoc | N, |
NodeRole | R | ||
) |
Set role for the syntax node matching N
.
Definition at line 1711 of file BuildTree.cpp.
void clang::syntax::TreeBuilder::markChild | ( | syntax::Node * | N, |
NodeRole | R | ||
) |
Set role for N
.
Definition at line 1701 of file BuildTree.cpp.
void clang::syntax::TreeBuilder::markChildToken | ( | const syntax::Token * | T, |
NodeRole | R | ||
) |
void clang::syntax::TreeBuilder::markChildToken | ( | SourceLocation | Loc, |
NodeRole | R | ||
) |
Set role for a token starting at Loc
.
Definition at line 1689 of file BuildTree.cpp.
References clang::SourceLocation::isInvalid(), and Loc.
Should be called for expressions in non-statement position to avoid wrapping into expression statement.
Definition at line 1736 of file BuildTree.cpp.
References IgnoreImplicit().
Mark the Child
node with a corresponding Role
.
All marked children should be consumed by foldNode. When called on expressions (clang::Expr is derived from clang::Stmt), wraps expressions into expression statement.
Definition at line 1717 of file BuildTree.cpp.
References clang::syntax::Expression.
void clang::syntax::TreeBuilder::noticeDeclWithoutSemicolon | ( | Decl * | D | ) |
Notifies that we should not consume trailing semicolon when computing token range of D
.
Definition at line 1685 of file BuildTree.cpp.
References D.
|
inline |
Definition at line 378 of file BuildTree.cpp.
References clang::syntax::TokenBufferTokenManager::sourceManager().