ANTLR Support Libraries 2.7.1+
CommonAST.hpp
Go to the documentation of this file.
1#ifndef INC_CommonAST_hpp__
2#define INC_CommonAST_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/CommonAST.hpp#2 $
9 */
10
11#include <antlr/config.hpp>
12#include <antlr/BaseAST.hpp>
13
14#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
15namespace antlr {
16#endif
17
18class ANTLR_API CommonAST : public BaseAST {
19public:
21 : BaseAST()
22 , ttype( Token::INVALID_TYPE )
23 , text()
24 {
25 }
26
28 : BaseAST()
29 , ttype( t->getType() )
30 , text( t->getText() )
31 {
32 }
33
34 CommonAST( const CommonAST& other )
35 : BaseAST(other)
36 , ttype(other.ttype)
37 , text(other.text)
38 {
39 }
40
41 virtual ~CommonAST()
42 {
43 }
44
45 virtual const char* typeName( void ) const
46 {
48 }
49
51 virtual RefAST clone( void ) const
52 {
53 CommonAST *ast = new CommonAST( *this );
54 return RefAST(ast);
55 }
56
57 virtual ANTLR_USE_NAMESPACE(std)string getText() const
58 {
59 return text;
60 }
61 virtual int getType() const
62 {
63 return ttype;
64 }
65
66 virtual void initialize( int t, const ANTLR_USE_NAMESPACE(std)string& txt )
67 {
68 setType(t);
69 setText(txt);
70 }
71
72 virtual void initialize( RefAST t )
73 {
74 setType(t->getType());
75 setText(t->getText());
76 }
77 virtual void initialize( RefToken t )
78 {
79 setType(t->getType());
80 setText(t->getText());
81 }
82
83#ifdef ANTLR_SUPPORT_XML
84 virtual void initialize( ANTLR_USE_NAMESPACE(std)istream& in );
85#endif
86
87 virtual void setText( const ANTLR_USE_NAMESPACE(std)string& txt )
88 {
89 text = txt;
90 }
91 virtual void setType( int type )
92 {
93 ttype = type;
94 }
95
96 static RefAST factory();
97
98 static const char* const TYPE_NAME;
99protected:
100 int ttype;
102};
103
105
106#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
107}
108#endif
109
110#endif //INC_CommonAST_hpp__
ASTRefCount< AST > RefAST
Definition: ASTRefCount.hpp:92
ASTRefCount< CommonAST > RefCommonAST
Definition: CommonAST.hpp:104
virtual int getType() const =0
Get the token type for this node.
virtual std::string getText() const =0
Get the token text for this node.
Definition: BaseAST.hpp:23
Definition: CommonAST.hpp:18
CommonAST(const CommonAST &other)
Definition: CommonAST.hpp:34
CommonAST(RefToken t)
Definition: CommonAST.hpp:27
virtual void initialize(RefToken t)
Definition: CommonAST.hpp:77
virtual const char * typeName(void) const
Return the class name.
Definition: CommonAST.hpp:45
int ttype
Definition: CommonAST.hpp:100
virtual std::string getText() const
Get the token text for this node.
Definition: CommonAST.hpp:57
virtual ~CommonAST()
Definition: CommonAST.hpp:41
virtual void setText(const std ::string &txt)
Set the token text for this node.
Definition: CommonAST.hpp:87
CommonAST()
Definition: CommonAST.hpp:20
virtual void setType(int type)
Set the token type for this node.
Definition: CommonAST.hpp:91
static const char *const TYPE_NAME
Definition: CommonAST.hpp:98
std::string text
Definition: CommonAST.hpp:101
virtual void initialize(int t, const std ::string &txt)
Definition: CommonAST.hpp:66
virtual RefAST clone(void) const
Clone this AST node.
Definition: CommonAST.hpp:51
virtual int getType() const
Get the token type for this node.
Definition: CommonAST.hpp:61
virtual void initialize(RefAST t)
Definition: CommonAST.hpp:72
Definition: Token.hpp:25
virtual std::string getText() const
Definition: Token.cpp:25
virtual int getType() const
Definition: Token.cpp:30
#define ANTLR_USE_NAMESPACE(_x_)
Definition: config.hpp:18
#define ANTLR_API
Definition: config.hpp:22
Definition: ANTLRException.hpp:15