ANTLR Support Libraries 2.7.1+
|
00001 #ifndef INC_CommonAST_hpp__ 00002 #define INC_CommonAST_hpp__ 00003 00004 /* ANTLR Translator Generator 00005 * Project led by Terence Parr at http://www.jGuru.com 00006 * Software rights: http://www.antlr.org/license.html 00007 * 00008 * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/antlr/CommonAST.hpp#2 $ 00009 */ 00010 00011 #include <antlr/config.hpp> 00012 #include <antlr/BaseAST.hpp> 00013 00014 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE 00015 namespace antlr { 00016 #endif 00017 00018 class ANTLR_API CommonAST : public BaseAST { 00019 public: 00020 CommonAST() 00021 : BaseAST() 00022 , ttype( Token::INVALID_TYPE ) 00023 , text() 00024 { 00025 } 00026 00027 CommonAST( RefToken t ) 00028 : BaseAST() 00029 , ttype( t->getType() ) 00030 , text( t->getText() ) 00031 { 00032 } 00033 00034 CommonAST( const CommonAST& other ) 00035 : BaseAST(other) 00036 , ttype(other.ttype) 00037 , text(other.text) 00038 { 00039 } 00040 00041 virtual ~CommonAST() 00042 { 00043 } 00044 00045 virtual const char* typeName( void ) const 00046 { 00047 return CommonAST::TYPE_NAME; 00048 } 00049 00051 virtual RefAST clone( void ) const 00052 { 00053 CommonAST *ast = new CommonAST( *this ); 00054 return RefAST(ast); 00055 } 00056 00057 virtual ANTLR_USE_NAMESPACE(std)string getText() const 00058 { 00059 return text; 00060 } 00061 virtual int getType() const 00062 { 00063 return ttype; 00064 } 00065 00066 virtual void initialize( int t, const ANTLR_USE_NAMESPACE(std)string& txt ) 00067 { 00068 setType(t); 00069 setText(txt); 00070 } 00071 00072 virtual void initialize( RefAST t ) 00073 { 00074 setType(t->getType()); 00075 setText(t->getText()); 00076 } 00077 virtual void initialize( RefToken t ) 00078 { 00079 setType(t->getType()); 00080 setText(t->getText()); 00081 } 00082 00083 #ifdef ANTLR_SUPPORT_XML 00084 virtual void initialize( ANTLR_USE_NAMESPACE(std)istream& in ); 00085 #endif 00086 00087 virtual void setText( const ANTLR_USE_NAMESPACE(std)string& txt ) 00088 { 00089 text = txt; 00090 } 00091 virtual void setType( int type ) 00092 { 00093 ttype = type; 00094 } 00095 00096 static RefAST factory(); 00097 00098 static const char* const TYPE_NAME; 00099 protected: 00100 int ttype; 00101 ANTLR_USE_NAMESPACE(std)string text; 00102 }; 00103 00104 typedef ASTRefCount<CommonAST> RefCommonAST; 00105 00106 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE 00107 } 00108 #endif 00109 00110 #endif //INC_CommonAST_hpp__