clang
10.0.0git
|
A helper class for constructing the syntax tree while traversing a clang AST. More...
Public Member Functions | |
TreeBuilder (syntax::Arena &Arena) | |
llvm::BumpPtrAllocator & | allocator () |
void | foldNode (llvm::ArrayRef< syntax::Token > Range, syntax::Tree *New) |
Populate children for New node, assuming it covers tokens from Range . More... | |
void | noticeDeclaratorRange (llvm::ArrayRef< syntax::Token > Range) |
Must be called with the range of each DeclaratorDecl . More... | |
void | noticeDeclaratorWithoutSemicolon (Decl *D) |
Notifies that we should not consume trailing semicolon when computing token range of D . More... | |
void | markStmtChild (Stmt *Child, NodeRole Role) |
Mark the Child node with a corresponding Role . More... | |
void | markExprChild (Expr *Child, NodeRole Role) |
Should be called for expressions in non-statement position to avoid wrapping into expression statement. More... | |
void | markChildToken (SourceLocation Loc, NodeRole R) |
Set role for a token starting at Loc . More... | |
syntax::TranslationUnit * | finalize () && |
Finish building the tree and consume the root node. More... | |
llvm::ArrayRef< syntax::Token > | getRange (SourceLocation First, SourceLocation Last) const |
getRange() finds the syntax tokens corresponding to the passed source locations. More... | |
llvm::ArrayRef< syntax::Token > | getRange (const Decl *D) const |
llvm::ArrayRef< syntax::Token > | getExprRange (const Expr *E) const |
llvm::ArrayRef< syntax::Token > | getStmtRange (const Stmt *S) const |
Find the adjusted range for the statement, consuming the trailing semicolon when needed. More... | |
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 52 of file BuildTree.cpp.
|
inline |
Definition at line 54 of file BuildTree.cpp.
|
inline |
Definition at line 59 of file BuildTree.cpp.
|
inline |
Finish building the tree and consume the root node.
Definition at line 86 of file BuildTree.cpp.
void syntax::TreeBuilder::foldNode | ( | llvm::ArrayRef< syntax::Token > | Range, |
syntax::Tree * | New | ||
) |
Populate children for New
node, assuming it covers tokens from Range
.
Definition at line 608 of file BuildTree.cpp.
|
inline |
Definition at line 122 of file BuildTree.cpp.
References clang::Stmt::getBeginLoc(), and clang::Stmt::getEndLoc().
|
inline |
getRange() 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 104 of file BuildTree.cpp.
References clang::SourceLocation::isValid().
|
inline |
Definition at line 112 of file BuildTree.cpp.
|
inline |
Find the adjusted range for the statement, consuming the trailing semicolon when needed.
Definition at line 127 of file BuildTree.cpp.
void syntax::TreeBuilder::markChildToken | ( | SourceLocation | Loc, |
NodeRole | R | ||
) |
Set role for a token starting at Loc
.
Definition at line 625 of file BuildTree.cpp.
References clang::SourceLocation::isInvalid().
void syntax::TreeBuilder::markExprChild | ( | Expr * | Child, |
NodeRole | Role | ||
) |
Should be called for expressions in non-statement position to avoid wrapping into expression statement.
Definition at line 648 of file BuildTree.cpp.
void syntax::TreeBuilder::markStmtChild | ( | Stmt * | Child, |
NodeRole | Role | ||
) |
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 631 of file BuildTree.cpp.
References clang::syntax::ExpressionStatement_expression.
void syntax::TreeBuilder::noticeDeclaratorRange | ( | llvm::ArrayRef< syntax::Token > | Range | ) |
Must be called with the range of each DeclaratorDecl
.
Ensures the corresponding declarator nodes are covered by SimpleDeclaration
.
Definition at line 613 of file BuildTree.cpp.
References clang::syntax::SimpleDeclaration.
void syntax::TreeBuilder::noticeDeclaratorWithoutSemicolon | ( | Decl * | D | ) |
Notifies that we should not consume trailing semicolon when computing token range of D
.
Definition at line 621 of file BuildTree.cpp.