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