1
#ifndef INC_BaseAST_hpp__
2
#define INC_BaseAST_hpp__
4
/* ANTLR Translator Generator
5
* Project led by Terence Parr at http://www.jGuru.com
6
* Software rights: http://www.antlr.org/license.html
8
* $Id: BaseAST.hpp 626096 2007-01-22 06:35:06Z okellogg $
11
#include <antlr/config.hpp>
12
#include <antlr/AST.hpp>
16
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
20
class ANTLR_API BaseAST;
21
typedef ASTRefCount<BaseAST> RefBaseAST;
23
class ANTLR_API BaseAST : public AST {
28
BaseAST(const BaseAST& other)
36
/// Return the class name
37
virtual const char* typeName( void ) const = 0;
39
/// Clone this AST node.
40
virtual RefAST clone( void ) const = 0;
42
/// Is node t equal to this in terms of token type and text?
43
virtual bool equals(RefAST t) const;
45
/** Is t an exact structural and equals() match of this tree. The
46
* 'this' reference is considered the start of a sibling list.
48
virtual bool equalsList(RefAST t) const;
50
/** Is 't' a subtree of this list? The siblings of the root are NOT ignored.
52
virtual bool equalsListPartial(RefAST t) const;
54
/** Is tree rooted at 'this' equal to 't'? The siblings of 'this' are
57
virtual bool equalsTree(RefAST t) const;
59
/** Is 't' a subtree of the tree rooted at 'this'? The siblings of
62
virtual bool equalsTreePartial(RefAST t) const;
64
/** Walk the tree looking for all exact subtree matches. Return
65
* an ASTEnumerator that lets the caller walk the list
66
* of subtree roots found herein.
68
virtual ANTLR_USE_NAMESPACE(std)vector<RefAST> findAll(RefAST t);
70
/** Walk the tree looking for all subtrees. Return
71
* an ASTEnumerator that lets the caller walk the list
72
* of subtree roots found herein.
74
virtual ANTLR_USE_NAMESPACE(std)vector<RefAST> findAllPartial(RefAST t);
76
/// Add a node to the end of the child list for this node
77
virtual void addChild(RefAST c)
82
RefBaseAST tmp = down;
94
/** Get the number of child nodes of this node (shallow e.g. not of the
95
* whole tree it spans).
97
virtual size_t getNumberOfChildren() const;
99
/// Get the first child of this node; null if no children
100
virtual RefAST getFirstChild() const
104
/// Get the next sibling in line after this one
105
virtual RefAST getNextSibling() const
107
return RefAST(right);
110
/// Get the token text for this node
111
virtual ANTLR_USE_NAMESPACE(std)string getText() const
115
/// Get the token type for this node
116
virtual int getType() const
121
/// Remove all children
122
virtual void removeChildren()
124
down = static_cast<BaseAST*>(static_cast<AST*>(nullAST));
127
/// Set the first child of a node.
128
virtual void setFirstChild(RefAST c)
130
down = static_cast<BaseAST*>(static_cast<AST*>(c));
133
/// Set the next sibling after this one.
134
virtual void setNextSibling(RefAST n)
136
right = static_cast<BaseAST*>(static_cast<AST*>(n));
139
/// Set the token text for this node
140
virtual void setText(const ANTLR_USE_NAMESPACE(std)string& txt)
144
/// Set the token type for this node
145
virtual void setType(int type)
149
#ifdef ANTLR_SUPPORT_XML
150
/** print attributes of this node to 'out'. Override to customize XML
152
* @param out the stream to write the AST attributes to.
154
virtual bool attributesToStream( ANTLR_USE_NAMESPACE(std)ostream& out ) const;
155
/** Write this subtree to a stream. Overload this one to customize the XML
156
* output for AST derived AST-types
157
* @param output stream
159
virtual void toStream( ANTLR_USE_NAMESPACE(std)ostream &out ) const;
162
/// Return string representation for the AST
163
virtual ANTLR_USE_NAMESPACE(std)string toString() const
168
/// Print out a child sibling tree in LISP notation
169
virtual ANTLR_USE_NAMESPACE(std)string toStringList() const;
170
virtual ANTLR_USE_NAMESPACE(std)string toStringTree() const;
175
void doWorkForFindAll(ANTLR_USE_NAMESPACE(std)vector<RefAST>& v,
180
/** Is node t equal to this in terms of token type and text?
182
inline bool BaseAST::equals(RefAST t) const
186
return ((getType() == t->getType()) && (getText() == t->getText()));
189
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
193
#endif //INC_BaseAST_hpp__