Doxygen
Loading...
Searching...
No Matches
CharStream.h
Go to the documentation of this file.
1/* Generated By:JavaCC: Do not edit this line. CharStream.h Version 7.0 */
2/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
3#ifndef JAVACC_CHARSTREAM_H_
4#define JAVACC_CHARSTREAM_H_
5
6#include "JavaCC.h"
7
8#ifndef INITIAL_BUFFER_SIZE
9#define INITIAL_BUFFER_SIZE 4096
10#endif
11
12namespace vhdl {
13namespace parser {
14
15/**
16 * This class describes a character stream that maintains line and
17 * column number positions of the characters. It also has the capability
18 * to backup the stream to some extent. An implementation of this
19 * class is used in the TokenManager implementation generated by
20 * JavaCCParser.
21 *
22 * All the methods except backup can be implemented in any fashion. backup
23 * needs to be implemented correctly for the correct operation of the lexer.
24 * Rest of the methods are all used to get information like line number,
25 * column number and the string that constitutes a token and are not used
26 * by the lexer. Hence their implementation won't affect the generated lexer's
27 * operation.
28 */
29
30
32public:
33 void setTabSize(int i) { tabSize = i; }
34 int getTabSize(int i) { return tabSize; }
35
36private:
37 int getBufcolumn(int pos) {
38 if (trackLineColumn && pos>=0) {
39 return bufcolumn[pos];
40 } else {
41 return -1;
42 }
43 }
44 int getBufline(int pos) {
45 if (trackLineColumn && pos>=0) {
46 return bufline[pos];
47 } else {
48 return -1;
49 }
50 }
51
52public:
53 virtual int getColumn() { return getBufcolumn(bufpos); }
54 virtual int getLine() { return getBufline(bufpos); }
55 virtual int getEndColumn() { return getBufcolumn(bufpos); }
56 virtual int getEndLine() { return getBufline(bufpos); }
57 virtual int getBeginColumn() { return getBufcolumn(tokenBegin); }
58 virtual int getBeginLine() { return getBufline(tokenBegin); }
59
60 virtual bool getTrackLineColumn() { return trackLineColumn; }
61 virtual void setTrackLineColumn(bool val) { trackLineColumn = val; }
62
63/**
64 * Backs up the input stream by amount steps. Lexer calls this method if it
65 * had already read some characters, but could not use them to match a
66 * (longer) token. So, they will be used again as the prefix of the next
67 * token and it is the implementation's responsibility to do this right.
68 */
69 virtual inline void backup(int amount) {
70 inBuf += amount;
71 bufpos -= amount;
72 if (bufpos < 0) {
73 bufpos += bufsize;
74 }
75 }
76
77/**
78 * Returns the next character that marks the beginning of the next token.
79 * All characters must remain in the buffer between two successive calls
80 * to this method to implement backup correctly.
81 */
82 virtual inline JJChar BeginToken() {
83 tokenBegin = -1;
84 JJChar c = readChar();
86 return c;
87 }
88
89
90/**
91 * Returns the next character from the selected input. The method
92 * of selecting the input is the responsibility of the class
93 * implementing this class.
94 */
95 virtual inline JJChar readChar() {
96 if (inBuf > 0) {
97 --inBuf;
98 ++bufpos;
99 if (bufpos == bufsize) {
100 bufpos = 0;
101 }
102 return buffer[bufpos];
103 }
104
105 ++bufpos;
106 if (bufpos >= maxNextCharInd) {
107 FillBuff();
108 }
109
110 JJChar c = buffer[bufpos];
111
112 if (trackLineColumn) {
114 }
115
116 return c;
117 }
118
119
120 virtual void ExpandBuff(bool wrapAround);
121 virtual void FillBuff();
122
123 /**
124 * Returns a string made up of characters from the marked token beginning
125 * to the current buffer position. Implementations can return
126 * anything that they want to. For example, for efficiency, one might decide
127 * to just return NULL, which is a valid implementation.
128 */
129 virtual JJString GetImage() {
130 if (bufpos >= tokenBegin)
131 return JJString(buffer + tokenBegin, bufpos - tokenBegin + 1);
132 else
133 return JJString(buffer + tokenBegin, bufsize - tokenBegin).append(buffer, bufpos + 1);
134 }
135
136 /**
137 * Returns an array of characters that make up the suffix of length 'len' for
138 * the currently matched token. This is used to build up the matched string
139 * for use in actions in the case of MORE. A simple and inefficient
140 * implementation of this is as follows :
141 */
142 virtual JJString GetSuffix(int len) {
143 if ((bufpos + 1) >= len) {
144 return JJString(buffer + bufpos - len + 1, len);
145 }
146 return JJString(buffer + bufsize - (len - bufpos - 1), len - bufpos - 1).append(buffer, bufpos + 1);
147 }
148
149 /**
150 * The lexer calls this function to indicate that it is done with the stream
151 * and hence implementations can free any resources held by this class.
152 */
153 virtual void DeleteBuffers();
154
155 virtual ~CharStream() {
156 if (deleteStream) {
157 delete inputStream;
158 }
160 }
161
162 bool endOfInput() {
163 return inBuf == 0 && bufpos + 1 >= maxNextCharInd && inputStream->endOfInput();
164 }
165
166 CharStream(const JJChar *buf, int sz, int startline,
167 int startcolumn, int buffersize) :
168 bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0),
169 tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false),
171 inputStream(nullptr), deleteStream(false) {
172 ReInit(JJString(buf, sz), startline, startcolumn, buffersize);
173 }
174
175 CharStream(const JJChar *buf, int sz, int startline, int startcolumn) :
176 bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0),
177 tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false),
179 inputStream(nullptr), deleteStream(false) {
180 ReInit(JJString(buf, sz), startline, startcolumn, INITIAL_BUFFER_SIZE);
181 }
182
183 CharStream(const JJString& str, int startline,
184 int startcolumn, int buffersize) :
185 bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0),
186 tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false),
188 inputStream(nullptr), deleteStream(false) {
189 ReInit(str, startline, startcolumn, buffersize);
190 }
191
192 CharStream(const JJString& str, int startline, int startcolumn) :
193 bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0),
194 tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false),
196 inputStream(nullptr), deleteStream(false) {
197 ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
198 }
199
200 CharStream(ReaderStream *input_stream, int startline,
201 int startcolumn, int buffersize) :
202 bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0),
203 tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false),
205 inputStream(nullptr), deleteStream(false) {
206 ReInit(input_stream, startline, startcolumn, buffersize);
207 }
208
209 CharStream(ReaderStream *input_stream, int startline, int startcolumn) :
210 bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0),
211 tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false),
213 inputStream(nullptr), deleteStream(false) {
214 ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
215 }
216
217 CharStream(ReaderStream *input_stream) :
218 bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0),
219 tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false),
221 inputStream(nullptr), deleteStream(false) {
222 ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
223 }
224
225 virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn, int buffersize);
226
227 virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn) {
228 ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
229 }
230
231 virtual void ReInit(ReaderStream *input_stream) {
232 ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
233 }
234
235 virtual void ReInit(const JJString& str, int startline,
236 int startcolumn, int buffersize);
237
238 virtual void ReInit(const JJString& str, int startline,
239 int startcolumn) {
240 ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
241 }
242
243 virtual void adjustBeginLineColumn(int newLine, int newCol);
244
245protected:
246 virtual void UpdateLineColumn(JJChar c);
247
255 int line;
260 int inBuf;
265};
266
267}
268}
269
270#endif
271/* JavaCC - OriginalChecksum=bad90284b44db6b5391a68c8a6a7b893 (do not edit this line) */
#define INITIAL_BUFFER_SIZE
Definition CharStream.h:9
JAVACC_STRING_TYPE JJString
Definition JavaCC.h:22
JAVACC_CHAR_TYPE JJChar
Definition JavaCC.h:21
virtual void UpdateLineColumn(JJChar c)
virtual int getEndColumn()
Definition CharStream.h:55
CharStream(const JJString &str, int startline, int startcolumn)
Definition CharStream.h:192
virtual void setTrackLineColumn(bool val)
Definition CharStream.h:61
virtual void ReInit(ReaderStream *input_stream)
Definition CharStream.h:231
virtual void FillBuff()
CharStream(const JJChar *buf, int sz, int startline, int startcolumn)
Definition CharStream.h:175
virtual int getLine()
Definition CharStream.h:54
int getBufcolumn(int pos)
Definition CharStream.h:37
CharStream(ReaderStream *input_stream, int startline, int startcolumn, int buffersize)
Definition CharStream.h:200
virtual int getBeginColumn()
Definition CharStream.h:57
virtual int getBeginLine()
Definition CharStream.h:58
virtual JJChar BeginToken()
Returns the next character that marks the beginning of the next token.
Definition CharStream.h:82
virtual JJString GetImage()
Returns a string made up of characters from the marked token beginning to the current buffer position...
Definition CharStream.h:129
virtual void ReInit(const JJString &str, int startline, int startcolumn)
Definition CharStream.h:238
CharStream(ReaderStream *input_stream, int startline, int startcolumn)
Definition CharStream.h:209
CharStream(ReaderStream *input_stream)
Definition CharStream.h:217
virtual void ReInit(const JJString &str, int startline, int startcolumn, int buffersize)
virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn)
Definition CharStream.h:227
virtual JJChar readChar()
Returns the next character from the selected input.
Definition CharStream.h:95
virtual JJString GetSuffix(int len)
Returns an array of characters that make up the suffix of length 'len' for the currently matched toke...
Definition CharStream.h:142
virtual bool getTrackLineColumn()
Definition CharStream.h:60
virtual void DeleteBuffers()
The lexer calls this function to indicate that it is done with the stream and hence implementations c...
virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn, int buffersize)
int getBufline(int pos)
Definition CharStream.h:44
virtual int getColumn()
Definition CharStream.h:53
virtual int getEndLine()
Definition CharStream.h:56
CharStream(const JJChar *buf, int sz, int startline, int startcolumn, int buffersize)
Definition CharStream.h:166
CharStream(const JJString &str, int startline, int startcolumn, int buffersize)
Definition CharStream.h:183
virtual void ExpandBuff(bool wrapAround)
ReaderStream * inputStream
Definition CharStream.h:263
virtual void backup(int amount)
Backs up the input stream by amount steps.
Definition CharStream.h:69
virtual void adjustBeginLineColumn(int newLine, int newCol)
static void newLine(yyscan_t yyscanner)
Token literal values and constants.
Definition CharStream.h:12