ANTLR Support Libraries 2.7.1+
AST.hpp
Go to the documentation of this file.
1 #ifndef INC_AST_hpp__
2 #define INC_AST_hpp__
3 
4 /* ANTLR Translator Generator
5  * Project led by Terence Parr at http://www.jGuru.com
6  * Software rights: http://www.antlr.org/license.html
7  *
8  * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/antlr/AST.hpp#2 $
9  */
10 
11 #include <antlr/config.hpp>
12 #include <antlr/ASTRefCount.hpp>
13 #include <antlr/Token.hpp>
14 #include <vector>
15 #include <string>
16 
17 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
18 namespace antlr {
19 #endif
20 
21 struct ASTRef;
22 
23 class ANTLR_API AST {
24 public:
25  AST() : ref(0) {}
26  AST(const AST&) : ref(0) {}
27  virtual ~AST() {}
28 
30  virtual const char* typeName( void ) const = 0;
32  virtual RefAST clone( void ) const = 0;
34  virtual bool equals(RefAST t) const = 0;
38  virtual bool equalsList(RefAST t) const = 0;
39 
42  virtual bool equalsListPartial(RefAST t) const = 0;
46  virtual bool equalsTree(RefAST t) const = 0;
50  virtual bool equalsTreePartial(RefAST t) const = 0;
51 
56  virtual ANTLR_USE_NAMESPACE(std)vector<RefAST> findAll(RefAST t) = 0;
57 
62  virtual ANTLR_USE_NAMESPACE(std)vector<RefAST> findAllPartial(RefAST t) = 0;
63 
65  virtual void addChild(RefAST c) = 0;
67  virtual size_t getNumberOfChildren() const = 0;
68 
70  virtual RefAST getFirstChild() const = 0;
72  virtual RefAST getNextSibling() const = 0;
73 
75  virtual ANTLR_USE_NAMESPACE(std)string getText() const = 0;
77  virtual int getType() const = 0;
78 
82  virtual void initialize(int t, const ANTLR_USE_NAMESPACE(std)string& txt) = 0;
83  virtual void initialize(RefAST t) = 0;
84  virtual void initialize(RefToken t) = 0;
85 
86 #ifdef ANTLR_SUPPORT_XML
87 
90  virtual void initialize( ANTLR_USE_NAMESPACE(std)istream& in ) = 0;
91 #endif
92 
94  virtual void setFirstChild(RefAST c) = 0;
96  virtual void setNextSibling(RefAST n) = 0;
97 
99  virtual void setText(const ANTLR_USE_NAMESPACE(std)string& txt) = 0;
101  virtual void setType(int type) = 0;
102 
104  virtual ANTLR_USE_NAMESPACE(std)string toString() const = 0;
105 
107  virtual ANTLR_USE_NAMESPACE(std)string toStringList() const = 0;
108  virtual ANTLR_USE_NAMESPACE(std)string toStringTree() const = 0;
109 
110 #ifdef ANTLR_SUPPORT_XML
111 
116  virtual bool attributesToStream( ANTLR_USE_NAMESPACE(std)ostream& out ) const = 0;
117 
122  virtual void toStream( ANTLR_USE_NAMESPACE(std)ostream &out ) const = 0;
123 
130  friend ANTLR_USE_NAMESPACE(std)ostream& operator<<( ANTLR_USE_NAMESPACE(std)ostream& output, const RefAST& ast );
131 #endif
132 
133 private:
134  friend struct ASTRef;
136 
137  AST(RefAST other);
138  AST& operator=(const AST& other);
139  AST& operator=(RefAST other);
140 };
141 
142 #ifdef ANTLR_SUPPORT_XML
143 inline ANTLR_USE_NAMESPACE(std)ostream& operator<<( ANTLR_USE_NAMESPACE(std)ostream& output, const RefAST& ast )
144 {
145  ast->toStream(output);
146  return output;
147 }
148 #endif
149 
150 extern ANTLR_API RefAST nullAST;
151 extern ANTLR_API AST* const nullASTptr;
152 
153 #ifdef NEEDS_OPERATOR_LESS_THAN
154 // RK: apparently needed by MSVC and a SUN CC, up to and including
155 // 2.7.2 this was undefined ?
156 inline bool operator<( RefAST l, RefAST r )
157 {
158  return nullAST == l ? ( nullAST == r ? false : true ) : l->getType() < r->getType();
159 }
160 #endif
161 
162 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
163 }
164 #endif
165 
166 #endif //INC_AST_hpp__
Definition: ANTLRException.hpp:15
Definition: TokenRefCount.hpp:43
Definition: AST.hpp:23
AST(const AST &)
Definition: AST.hpp:26
virtual int getType() const =0
Get the token type for this node.
#define ANTLR_API
Definition: config.hpp:22
AST *const nullASTptr
Definition: BaseAST.cpp:276
ASTRef * ref
Definition: AST.hpp:135
virtual ~AST()
Definition: AST.hpp:27
RefAST nullAST
Definition: BaseAST.cpp:271
Definition: ASTRefCount.hpp:19
#define ANTLR_USE_NAMESPACE(_x_)
Definition: config.hpp:18
ASTRef & operator=(const ASTRef &)
AST()
Definition: AST.hpp:25