clang  10.0.0git
Classes | Public Member Functions | List of all members
syntax::TreeBuilder Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ TreeBuilder()

syntax::TreeBuilder::TreeBuilder ( syntax::Arena &  Arena)
inline

Definition at line 54 of file BuildTree.cpp.

Member Function Documentation

◆ allocator()

llvm::BumpPtrAllocator& syntax::TreeBuilder::allocator ( )
inline

Definition at line 59 of file BuildTree.cpp.

◆ finalize()

syntax::TranslationUnit* syntax::TreeBuilder::finalize ( ) &&
inline

Finish building the tree and consume the root node.

Definition at line 86 of file BuildTree.cpp.

◆ foldNode()

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.

◆ getExprRange()

llvm::ArrayRef<syntax::Token> syntax::TreeBuilder::getExprRange ( const Expr E) const
inline

Definition at line 122 of file BuildTree.cpp.

References clang::Stmt::getBeginLoc(), and clang::Stmt::getEndLoc().

◆ getRange() [1/2]

llvm::ArrayRef<syntax::Token> syntax::TreeBuilder::getRange ( SourceLocation  First,
SourceLocation  Last 
) const
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().

◆ getRange() [2/2]

llvm::ArrayRef<syntax::Token> syntax::TreeBuilder::getRange ( const Decl D) const
inline

Definition at line 112 of file BuildTree.cpp.

◆ getStmtRange()

llvm::ArrayRef<syntax::Token> syntax::TreeBuilder::getStmtRange ( const Stmt S) const
inline

Find the adjusted range for the statement, consuming the trailing semicolon when needed.

Definition at line 127 of file BuildTree.cpp.

◆ markChildToken()

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().

◆ markExprChild()

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.

◆ markStmtChild()

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.

◆ noticeDeclaratorRange()

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.

◆ noticeDeclaratorWithoutSemicolon()

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.


The documentation for this class was generated from the following file: