clang  10.0.0svn
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 markChildToken (SourceLocation Loc, tok::TokenKind Kind, 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 > getRange (const Stmt *S) const
 

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 45 of file BuildTree.cpp.

Constructor & Destructor Documentation

◆ TreeBuilder()

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

Definition at line 47 of file BuildTree.cpp.

Member Function Documentation

◆ allocator()

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

Definition at line 49 of file BuildTree.cpp.

◆ finalize()

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

Finish building the tree and consume the root node.

Definition at line 59 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 249 of file BuildTree.cpp.

◆ getRange() [1/3]

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 75 of file BuildTree.cpp.

References clang::SourceLocation::isValid().

◆ getRange() [2/3]

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

Definition at line 83 of file BuildTree.cpp.

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

◆ getRange() [3/3]

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

Definition at line 86 of file BuildTree.cpp.

◆ markChildToken()

void syntax::TreeBuilder::markChildToken ( SourceLocation  Loc,
tok::TokenKind  Kind,
NodeRole  R 
)

Set role for a token starting at Loc.

Definition at line 254 of file BuildTree.cpp.

References clang::SourceLocation::isInvalid().


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