]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/VfrCompile/Pccts/h/DLexerBase.h
BaseTools/VfrCompile/Pccts: Add virtual destructor for class DLGInputStream
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / Pccts / h / DLexerBase.h
CommitLineData
30fdf114
LG
1/* DLGLexerBase.h\r
2 *\r
3 * SOFTWARE RIGHTS\r
4 *\r
5 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r
6 * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r
7 * company may do whatever they wish with source code distributed with\r
8 * PCCTS or the code generated by PCCTS, including the incorporation of\r
9 * PCCTS, or its output, into commerical software.\r
10 *\r
11 * We encourage users to develop software with PCCTS. However, we do ask\r
12 * that credit is given to us for developing PCCTS. By "credit",\r
13 * we mean that if you incorporate our source code into one of your\r
14 * programs (commercial product, research project, or otherwise) that you\r
15 * acknowledge this fact somewhere in the documentation, research report,\r
16 * etc... If you like PCCTS and have developed a nice tool with the\r
17 * output, please mention that you developed it using PCCTS. In\r
18 * addition, we ask that this header remain intact in our source code.\r
19 * As long as these guidelines are kept, we expect to continue enhancing\r
20 * this system and expect to make other tools available as they are\r
21 * completed.\r
22 *\r
23 * ANTLR 1.33\r
24 * Terence Parr\r
25 * Parr Research Corporation\r
26 * with Purdue University and AHPCRC, University of Minnesota\r
27 * 1989-2000\r
28 */\r
29\r
30#ifndef DLGX_H\r
31#define DLGX_H\r
32\r
33#include "pcctscfg.h"\r
34#include "pccts_stdio.h"\r
35\r
36PCCTS_NAMESPACE_STD\r
37\r
38#include ATOKEN_H\r
39#include ATOKENSTREAM_H\r
40\r
41class ANTLRParser; // MR1\r
42\r
43/* must define what a char looks like; can make this a class too */\r
44typedef char DLGChar;\r
45\r
46/* Can have it as a class too: (ack this looks weird; is it right?)\r
47class DllExportPCCTS DLGChar {\r
48private:\r
49 int c;\r
50public:\r
51 DLGChar(int ch) { c = ch; }\r
52 int atom() { return c; }\r
53};\r
54*/\r
55\r
56/* user must subclass this */\r
57class DllExportPCCTS DLGInputStream {\r
58public:\r
59 virtual int nextChar() = 0;\r
d5563836 60 virtual ~DLGInputStream() {};\r
30fdf114
LG
61};\r
62\r
63/* Predefined char stream: Input from FILE */\r
64class DllExportPCCTS DLGFileInput : public DLGInputStream {\r
65private:\r
66 int found_eof;\r
67 FILE *input;\r
68public:\r
69 DLGFileInput(FILE *f) { input = f; found_eof = 0; }\r
70 int nextChar() {\r
71 int c;\r
72 if ( found_eof ) return EOF;\r
73 else {\r
74 c=getc(input);\r
75 if ( c==EOF ) found_eof = 1;\r
76 return c;\r
77 }\r
78 }\r
79 void DLGFileReset(FILE *f) {input=f; found_eof = 0; }; // MR11\r
80};\r
81\r
82// MR9 Suggested by Bruce Guenter (bruceg@qcc.sk.ca)\r
83// MR9 Make DLGStringInput const correct\r
84\r
85/* Predefined char stream: Input from string */\r
86class DllExportPCCTS DLGStringInput : public DLGInputStream {\r
87private:\r
88 const DLGChar *input; // MR9\r
89 const DLGChar *p; // MR9\r
90public:\r
91 DLGStringInput(const DLGChar *s) { input = s; p = &input[0];} // MR9\r
92 int nextChar()\r
93 {\r
94 if (*p) return (int) (unsigned char) *p++; // MR14\r
95 else return EOF;\r
96 }\r
97\r
98 void DLGStringReset(const DLGChar *s) {input=s; p= &input[0]; }; // MR11 // MR16\r
99};\r
100\r
101class DllExportPCCTS DLGState {\r
102public:\r
103 DLGInputStream *input;\r
104 int interactive;\r
105 int track_columns;\r
106 int auto_num;\r
107 int add_erase;\r
108 int lookc;\r
109 int char_full;\r
110 int begcol, endcol;\r
111 int line;\r
112 DLGChar *lextext, *begexpr, *endexpr;\r
113 int bufsize;\r
114 int bufovf;\r
115 DLGChar *nextpos;\r
116 int class_num;\r
117 int debugLexerFlag; // MR1\r
118 ANTLRParser *parser; // MR1\r
119};\r
120\r
121/* user must subclass this */\r
122class DllExportPCCTS DLGLexerBase : public ANTLRTokenStream {\r
77dee0b1
HW
123private:\r
124 DLGLexerBase(const DLGLexerBase&); // Prevent copy-construction\r
125 DLGLexerBase& operator=(const DLGLexerBase&); // Prevent assignment\r
30fdf114
LG
126public:\r
127 virtual ANTLRTokenType erraction();\r
128\r
129protected:\r
130 DLGInputStream *input;\r
131 int interactive;\r
132 int track_columns;\r
133 DLGChar *_lextext; /* text of most recently matched token */\r
134 DLGChar *_begexpr; /* beginning of last reg expr recogn. */\r
135 DLGChar *_endexpr; /* beginning of last reg expr recogn. */\r
136 int _bufsize; /* number of characters in lextext */\r
137 int _begcol; /* column that first character of token is in*/\r
138 int _endcol; /* column that last character of token is in */\r
139 int _line; /* line current token is on */\r
140 int ch; /* character to determine next state */\r
141 int bufovf; /* indicates that buffer too small for text */\r
142 int charfull;\r
143 DLGChar *nextpos; /* points to next available position in lextext*/\r
144 int cl;\r
145 int automaton;\r
146 int add_erase;\r
147 DLGChar ebuf[70];\r
148 _ANTLRTokenPtr token_to_fill;\r
149\r
150 int debugLexerFlag; // MR1\r
151 ANTLRParser *parser; // MR1\r
152public:\r
153 virtual _ANTLRTokenPtr getToken(); // MR12 public\r
154 virtual void advance(void) = 0;\r
155 void skip(void); /* erase lextext, look for antoher token */\r
156 void more(void); /* keep lextext, look for another token */\r
157 void mode(int k); /* switch to automaton 'k' */\r
158 void saveState(DLGState *);\r
159 void restoreState(DLGState *);\r
160 virtual ANTLRTokenType nextTokenType(void)=0;/* get next token */\r
161 void replchar(DLGChar c); /* replace last recognized reg. expr. with\r
162 a character */\r
163 void replstr(const DLGChar *s); /* replace last recognized reg. expr. with\r
164 a string */ /* MR20 const */\r
165 virtual int err_in(); // MR1\r
166 virtual void errstd(const char *); // MR1 MR20 const\r
167 int line() { return _line; }\r
168 void set_line(int newValue) { _line=newValue; }; // MR1\r
169 virtual void newline() { _line++; }\r
170 DLGChar *lextext() { return _lextext; }\r
171\r
172 int begcol() { return _begcol; }\r
173 int endcol() { return _endcol; }\r
174 void set_begcol(int a) { _begcol=a; }\r
175 void set_endcol(int a) { _endcol=a; }\r
176 DLGChar *begexpr() { return _begexpr; }\r
177 DLGChar *endexpr() { return _endexpr; }\r
178 int bufsize() { return _bufsize; }\r
179\r
180 void setToken(ANTLRAbstractToken *t) { token_to_fill = t; }\r
181\r
182 void setInputStream(DLGInputStream *);\r
183 DLGLexerBase(DLGInputStream *in,\r
184 unsigned bufsize=2000,\r
185 int interactive=0,\r
186 int track_columns=0);\r
187 void reset(); // MR19\r
188 virtual ~DLGLexerBase() { delete [] _lextext; }\r
189 virtual void panic(const char *msg); // MR1 MR20 const\r
190 void trackColumns() {\r
191 track_columns = 1;\r
192 this->_begcol = 0;\r
193 this->_endcol = 0;\r
194 };\r
195 virtual ANTLRParser *setParser(ANTLRParser *p); // MR1\r
196 virtual ANTLRParser *getParser(); // MR1\r
197 virtual int debugLexer(int value); // MR1\r
198 int lexErrCount; // MR12\r
199 virtual int printMessage(FILE* pFile, const char* pFormat, ...); // MR23\r
200};\r
201\r
202#endif\r