+++ /dev/null
-/* ANTLRToken.h\r
- *\r
- * SOFTWARE RIGHTS\r
- *\r
- * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r
- * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r
- * company may do whatever they wish with source code distributed with\r
- * PCCTS or the code generated by PCCTS, including the incorporation of\r
- * PCCTS, or its output, into commerical software.\r
- *\r
- * We encourage users to develop software with PCCTS. However, we do ask\r
- * that credit is given to us for developing PCCTS. By "credit",\r
- * we mean that if you incorporate our source code into one of your\r
- * programs (commercial product, research project, or otherwise) that you\r
- * acknowledge this fact somewhere in the documentation, research report,\r
- * etc... If you like PCCTS and have developed a nice tool with the\r
- * output, please mention that you developed it using PCCTS. In\r
- * addition, we ask that this header remain intact in our source code.\r
- * As long as these guidelines are kept, we expect to continue enhancing\r
- * this system and expect to make other tools available as they are\r
- * completed.\r
- *\r
- * ANTLR 1.33\r
- * Terence Parr\r
- * Parr Research Corporation\r
- * with Purdue University and AHPCRC, University of Minnesota\r
- * 1989-1998\r
- */\r
-\r
-#ifndef ATOKEN_H_GATE\r
-#define ATOKEN_H_GATE\r
-\r
-#include "pcctscfg.h"\r
-\r
-#include "pccts_string.h"\r
-#include "pccts_stdio.h"\r
-#include "pccts_stdlib.h"\r
-\r
-PCCTS_NAMESPACE_STD\r
-\r
-// MR9 RJV (JVincent@novell.com) Not needed for variable length strings\r
-\r
-//// MR9 #ifndef ANTLRCommonTokenTEXTSIZE\r
-//// MR9 #define ANTLRCommonTokenTEXTSIZE 100\r
-//// MR9 #endif\r
-\r
-\r
-/* must define what a char looks like; can make this a class too */\r
-typedef char ANTLRChar;\r
-\r
-/* D E F I N E S M A R T P O I N T E R S */\r
-\r
-//#include ATOKPTR_H not tested yet, leave out\r
-class ANTLRAbstractToken;\r
-typedef ANTLRAbstractToken *_ANTLRTokenPtr;\r
-\r
-class ANTLRAbstractToken {\r
-public:\r
- virtual ~ANTLRAbstractToken() {;}\r
- virtual ANTLRTokenType getType() const = 0;\r
- virtual void setType(ANTLRTokenType t) = 0;\r
- virtual int getLine() const = 0;\r
- virtual void setLine(int line) = 0;\r
- virtual ANTLRChar *getText() const = 0;\r
- virtual void setText(const ANTLRChar *) = 0;\r
-\r
- /* This function will disappear when I can use templates */\r
- virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,\r
- ANTLRChar *text,\r
- int line) = 0;\r
-\r
- /* define to satisfy ANTLRTokenBuffer's need to determine whether or\r
- not a token object can be destroyed. If nref()==0, no one has\r
- a reference, and the object may be destroyed. This function defaults\r
- to 1, hence, if you use deleteTokens() message with a token object\r
- not derived from ANTLRCommonRefCountToken, the parser will compile\r
- but will not delete objects after they leave the token buffer.\r
- */\r
-\r
- virtual unsigned nref() const { return 1; } // MR11\r
- virtual void ref() {;}\r
- virtual void deref() {;}\r
-\r
- virtual void panic(const char *msg) // MR20 const\r
- {\r
- fprintf(stderr, "ANTLRAbstractToken panic: %s\n", msg);\r
- exit(PCCTS_EXIT_FAILURE);\r
- }\r
-};\r
-\r
-/* This class should be subclassed. It cannot store token type or text */\r
-\r
-class ANTLRRefCountToken : public ANTLRAbstractToken {\r
-public:\r
-#ifdef DBG_REFCOUNTTOKEN\r
- static int ctor;\r
- static int dtor;\r
-#endif\r
-protected:\r
- unsigned refcnt_;\r
-#ifdef DBG_REFCOUNTTOKEN\r
- char object[200];\r
-#endif\r
-\r
-public:\r
- ANTLRRefCountToken(ANTLRTokenType t, const ANTLRChar *s)\r
-#ifndef DBG_REFCOUNTTOKEN\r
- {\r
- refcnt_ = 0;\r
- }\r
-#else\r
- {\r
- ctor++;\r
- refcnt_ = 0;\r
- if ( t==1 ) sprintf(object,"tok_EOF");\r
- else sprintf(object,"tok_%s",s);\r
- fprintf(stderr, "ctor %s #%d\n",object,ctor);\r
- }\r
-#endif\r
- ANTLRRefCountToken()\r
-#ifndef DBG_REFCOUNTTOKEN\r
- { refcnt_ = 0; }\r
-#else\r
- {\r
- ctor++;\r
- refcnt_ = 0;\r
- sprintf(object,"tok_blank");\r
- fprintf(stderr, "ctor %s #%d\n",object,ctor);\r
- }\r
- virtual ~ANTLRRefCountToken()\r
- {\r
- dtor++;\r
- if ( dtor>ctor ) fprintf(stderr, "WARNING: dtor>ctor\n");\r
- fprintf(stderr, "dtor %s #%d\n", object, dtor);\r
- object[0]='\0';\r
- }\r
-#endif\r
-\r
- // reference counting stuff needed by ANTLRTokenPtr.\r
- // User should not access these; for C++ language reasons, we had\r
- // to make these public. Yuck.\r
-\r
- void ref() { refcnt_++; }\r
- void deref() { refcnt_--; }\r
- unsigned nref() const { return refcnt_; } // MR11\r
-\r
- virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,\r
- ANTLRChar *txt,\r
- int line)\r
- {\r
- panic("call to ANTLRRefCountToken::makeToken()\n");\r
- return NULL;\r
- }\r
-};\r
-\r
-class ANTLRCommonNoRefCountToken : public ANTLRAbstractToken {\r
-protected:\r
- ANTLRTokenType _type;\r
- int _line;\r
- ANTLRChar *_text; // MR9 RJV\r
-\r
-public:\r
- ANTLRCommonNoRefCountToken(ANTLRTokenType t, const ANTLRChar *s)\r
- { setType(t); _line = 0; _text = NULL; setText(s); }\r
- ANTLRCommonNoRefCountToken()\r
- { setType((ANTLRTokenType)0); _line = 0; _text = NULL; setText(""); }\r
-\r
- ~ANTLRCommonNoRefCountToken() { if (_text) delete [] _text; } // MR9 RJV: Added Destructor to remove string\r
-\r
- ANTLRTokenType getType() const { return _type; }\r
- void setType(ANTLRTokenType t) { _type = t; }\r
- virtual int getLine() const { return _line; }\r
- void setLine(int line) { _line = line; }\r
- ANTLRChar *getText() const { return _text; }\r
- int getLength() const { return strlen(getText()); } // MR11\r
-\r
-// MR9 RJV: Added code for variable length strings to setText()\r
-\r
- void setText(const ANTLRChar *s)\r
- { if (s != _text) {\r
- if (_text) delete [] _text;\r
- if (s != NULL) {\r
- _text = new ANTLRChar[strlen(s)+1];\r
- if (_text == NULL) panic("ANTLRCommonNoRefCountToken::setText new failed");\r
- strcpy(_text,s);\r
- } else {\r
- _text = new ANTLRChar[1];\r
- if (_text == NULL) panic("ANTLRCommonNoRefCountToken::setText new failed");\r
- strcpy(_text,"");\r
- };\r
- };\r
- }\r
-\r
- virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,\r
- ANTLRChar *txt,\r
- int line)\r
- {\r
- ANTLRAbstractToken *t = new ANTLRCommonNoRefCountToken;\r
- t->setType(tt); t->setText(txt); t->setLine(line);\r
- return t;\r
- }\r
-\r
-// MR9 THM Copy constructor required when heap allocated string is used with copy semantics\r
-\r
- ANTLRCommonNoRefCountToken (const ANTLRCommonNoRefCountToken& from) :\r
- ANTLRAbstractToken(from) {\r
- setType(from._type);\r
- setLine(from._line);\r
- _text=NULL;\r
- setText(from._text);\r
- };\r
-\r
-// MR9 THM operator =() required when heap allocated string is used with copy semantics\r
-\r
- virtual ANTLRCommonNoRefCountToken& operator =(const ANTLRCommonNoRefCountToken& rhs) {\r
-\r
-////// MR15 WatCom can't hack use of operator =()\r
-////// Use this: *( (ANTRLAbstractToken *) this)=rhs;\r
-\r
- *( (ANTLRAbstractToken *) this ) = rhs;\r
-\r
- setType(rhs._type);\r
- setLine(rhs._line);\r
- setText(rhs._text);\r
- return *this;\r
- };\r
-};\r
-\r
-class ANTLRCommonToken : public ANTLRRefCountToken {\r
-protected:\r
- ANTLRTokenType _type;\r
- int _line;\r
- ANTLRChar *_text; // MR9 RJV:Added\r
-\r
-public:\r
- ANTLRCommonToken(ANTLRTokenType t, const ANTLRChar *s) : ANTLRRefCountToken(t,s)\r
- { setType(t); _line = 0; _text = NULL; setText(s); } // MR9\r
- ANTLRCommonToken()\r
- { setType((ANTLRTokenType)0); _line = 0; _text = NULL; setText(""); } // MR9\r
-\r
- virtual ~ANTLRCommonToken() { if (_text) delete [] _text; } // MR9 RJV: Added Destructor to remove string\r
-\r
- ANTLRTokenType getType() const { return _type; }\r
- void setType(ANTLRTokenType t) { _type = t; }\r
- virtual int getLine() const { return _line; }\r
- void setLine(int line) { _line = line; }\r
- ANTLRChar *getText() const { return _text; }\r
- int getLength() const { return strlen(getText()); } // MR11\r
-\r
-// MR9 RJV: Added code for variable length strings to setText()\r
-\r
- void setText(const ANTLRChar *s)\r
- { if (s != _text) {\r
- if (_text) delete [] _text;\r
- if (s != NULL) {\r
- _text = new ANTLRChar[strlen(s)+1];\r
- if (_text == NULL) panic("ANTLRCommonToken::setText new failed");\r
- strcpy(_text,s);\r
- } else {\r
- _text = new ANTLRChar[1];\r
- if (_text == NULL) panic("ANTLRCommonToken::setText new failed");\r
- strcpy(_text,"");\r
- };\r
- };\r
- }\r
-\r
- virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,\r
- ANTLRChar *txt,\r
- int line)\r
- {\r
- ANTLRAbstractToken *t = new ANTLRCommonToken(tt,txt);\r
- t->setLine(line);\r
- return t;\r
- }\r
-\r
-// MR9 THM Copy constructor required when heap allocated string is used with copy semantics\r
-\r
- ANTLRCommonToken (const ANTLRCommonToken& from) :\r
- ANTLRRefCountToken(from) {\r
- setType(from._type);\r
- setLine(from._line);\r
- _text=NULL;\r
- setText(from._text);\r
- };\r
-\r
-// MR9 THM operator =() required when heap allocated string is used with copy semantics\r
-\r
- virtual ANTLRCommonToken& operator =(const ANTLRCommonToken& rhs) {\r
-\r
-////// MR15 WatCom can't hack use of operator =()\r
-////// Use this instead: *( (ANTRLRRefCountToken *) this)=rhs;\r
-\r
- *( (ANTLRRefCountToken *) this) = rhs;\r
-\r
- setType(rhs._type);\r
- setLine(rhs._line);\r
- setText(rhs._text);\r
- return *this;\r
- };\r
-};\r
-\r
-// used for backward compatibility\r
-typedef ANTLRCommonToken ANTLRCommonBacktrackingToken;\r
-\r
-#endif\r