00001 #ifndef INC_BaseAST_hpp__
00002 #define INC_BaseAST_hpp__
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <antlr/config.hpp>
00012 #include <antlr/AST.hpp>
00013
00014 #include <iostream>
00015
00016 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00017 namespace antlr {
00018 #endif
00019
00020 class ANTLR_API BaseAST;
00021 typedef ASTRefCount<BaseAST> RefBaseAST;
00022
00023 class ANTLR_API BaseAST : public AST {
00024 public:
00025 BaseAST() : AST()
00026 {
00027 }
00028 BaseAST(const BaseAST& other)
00029 : AST(other)
00030 {
00031 }
00032 virtual ~BaseAST()
00033 {
00034 }
00035
00037 virtual const char* typeName( void ) const = 0;
00038
00040 virtual RefAST clone( void ) const = 0;
00041
00043 virtual bool equals(RefAST t) const;
00044
00048 virtual bool equalsList(RefAST t) const;
00049
00052 virtual bool equalsListPartial(RefAST t) const;
00053
00057 virtual bool equalsTree(RefAST t) const;
00058
00062 virtual bool equalsTreePartial(RefAST t) const;
00063
00068 virtual ANTLR_USE_NAMESPACE(std)vector<RefAST> findAll(RefAST t);
00069
00074 virtual ANTLR_USE_NAMESPACE(std)vector<RefAST> findAllPartial(RefAST t);
00075
00077 virtual void addChild(RefAST c)
00078 {
00079 if( !c )
00080 return;
00081
00082 RefBaseAST tmp = down;
00083
00084 if (tmp)
00085 {
00086 while (tmp->right)
00087 tmp = tmp->right;
00088 tmp->right = c;
00089 }
00090 else
00091 down = c;
00092 }
00093
00097 virtual size_t getNumberOfChildren() const;
00098
00100 virtual RefAST getFirstChild() const
00101 {
00102 return RefAST(down);
00103 }
00105 virtual RefAST getNextSibling() const
00106 {
00107 return RefAST(right);
00108 }
00109
00111 virtual ANTLR_USE_NAMESPACE(std)string getText() const
00112 {
00113 return "";
00114 }
00116 virtual int getType() const
00117 {
00118 return 0;
00119 }
00120
00122 virtual void removeChildren()
00123 {
00124 down = static_cast<BaseAST*>(static_cast<AST*>(nullAST));
00125 }
00126
00128 virtual void setFirstChild(RefAST c)
00129 {
00130 down = static_cast<BaseAST*>(static_cast<AST*>(c));
00131 }
00132
00134 virtual void setNextSibling(RefAST n)
00135 {
00136 right = static_cast<BaseAST*>(static_cast<AST*>(n));
00137 }
00138
00140 virtual void setText(const ANTLR_USE_NAMESPACE(std)string& txt)
00141 {
00142 }
00143
00145 virtual void setType(int type)
00146 {
00147 }
00148
00149 #ifdef ANTLR_SUPPORT_XML
00150
00154 virtual bool attributesToStream( ANTLR_USE_NAMESPACE(std)ostream& out ) const;
00159 virtual void toStream( ANTLR_USE_NAMESPACE(std)ostream &out ) const;
00160 #endif
00161
00163 virtual ANTLR_USE_NAMESPACE(std)string toString() const
00164 {
00165 return getText();
00166 }
00167
00169 virtual ANTLR_USE_NAMESPACE(std)string toStringList() const;
00170 virtual ANTLR_USE_NAMESPACE(std)string toStringTree() const;
00171 protected:
00172 RefBaseAST down;
00173 RefBaseAST right;
00174 private:
00175 void doWorkForFindAll(ANTLR_USE_NAMESPACE(std)vector<RefAST>& v,
00176 RefAST target,
00177 bool partialMatch);
00178 };
00179
00182 inline bool BaseAST::equals(RefAST t) const
00183 {
00184 if (!t)
00185 return false;
00186 return ((getType() == t->getType()) && (getText() == t->getText()));
00187 }
00188
00189 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00190 }
00191 #endif
00192
00193 #endif //INC_BaseAST_hpp__