8#include "antlr/config.hpp"
12#include "antlr/AST.hpp"
13#include "antlr/BaseAST.hpp"
15ANTLR_USING_NAMESPACE(std)
16#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
37void BaseAST::doWorkForFindAll(
38 ANTLR_USE_NAMESPACE(std)vector<RefAST>& v,
39 RefAST target,
bool partialMatch)
46 if ( (partialMatch && sibling->equalsTreePartial(target)) ||
47 (!partialMatch && sibling->equalsTree(target)) ) {
51 if ( sibling->getFirstChild() ) {
52 RefBaseAST(sibling->getFirstChild())->doWorkForFindAll(v, target, partialMatch);
101 for (;sibling && sub;
104 if (!sibling->
equals(sub))
166 ANTLR_USE_NAMESPACE(std)vector<RefAST> roots;
170 doWorkForFindAll(roots,target,
false);
182 ANTLR_USE_NAMESPACE(std)vector<RefAST> roots;
186 doWorkForFindAll(roots,target,
true);
193 ANTLR_USE_NAMESPACE(std)
string ts=
"";
214ANTLR_USE_NAMESPACE(std)
string BaseAST::toStringTree()
const
216 ANTLR_USE_NAMESPACE(std)
string ts =
"";
233#ifdef ANTLR_SUPPORT_XML
240bool BaseAST::attributesToStream( ANTLR_USE_NAMESPACE(std)ostream& out )
const
242 out <<
"text=\"" << this->
getText()
243 <<
"\" type=\"" << this->
getType() <<
"\"";
248void BaseAST::toStream( ANTLR_USE_NAMESPACE(std)ostream& out )
const
250 for( RefAST node =
this; node != 0; node = node->getNextSibling() )
252 out <<
"<" << this->
typeName() <<
" ";
255 bool need_close_tag = node->attributesToStream( out );
260 if( node->getFirstChild() != 0 )
261 node->getFirstChild()->toStream( out );
264 out <<
"</" << node->typeName() <<
">" << endl;
271ANTLR_API RefAST nullAST;
273#if defined(_MSC_VER) && !defined(__ICL)
275extern ANTLR_API AST*
const nullASTptr = 0;
277ANTLR_API AST*
const nullASTptr = 0;
280#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
virtual RefAST getFirstChild() const =0
Get the first child of this node; null if no children.
virtual RefAST getNextSibling() const =0
Get the next sibling in line after this one.
virtual bool equals(RefAST t) const =0
Is node t equal to this in terms of token type and text?
virtual std::string toStringList() const =0
Print out a child-sibling tree in LISP notation.
virtual bool equalsList(RefAST t) const =0
Is t an exact structural and equals() match of this tree.
virtual bool equalsListPartial(RefAST t) const =0
Is 't' a subtree of this list? The siblings of the root are NOT ignored.
virtual bool equalsListPartial(RefAST t) const
Is 't' a subtree of this list? The siblings of the root are NOT ignored.
virtual std::string getText() const
Get the token text for this node.
virtual size_t getNumberOfChildren() const
Get the number of child nodes of this node (shallow e.g.
virtual std::string toString() const
Return string representation for the AST.
virtual std ::vector< RefAST > findAll(RefAST t)
Walk the tree looking for all exact subtree matches.
virtual bool equalsList(RefAST t) const
Is t an exact structural and equals() match of this tree.
virtual RefAST getFirstChild() const
Get the first child of this node; null if no children.
virtual int getType() const
Get the token type for this node.
virtual bool equals(RefAST t) const
Is node t equal to this in terms of token type and text?
virtual bool equalsTreePartial(RefAST t) const
Is 't' a subtree of the tree rooted at 'this'? The siblings of 'this' are ignored.
virtual std::string toStringList() const
Print out a child sibling tree in LISP notation.
virtual bool equalsTree(RefAST t) const
Is tree rooted at 'this' equal to 't'? The siblings of 'this' are ignored.
virtual RefAST getNextSibling() const
Get the next sibling in line after this one.
virtual const char * typeName(void) const =0
Return the class name.
virtual std ::vector< RefAST > findAllPartial(RefAST t)
Walk the tree looking for all subtrees.