Doxygen
CharStream.h
浏览该文件的文档.
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 
12 namespace vhdl {
13 namespace 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 
31 class CharStream {
32 public:
33  void setTabSize(int i) { tabSize = i; }
34  int getTabSize(int i) { return tabSize; }
35 
36 private:
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 
52 public:
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 implemetation'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) {
113  UpdateLineColumn(c);
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  }
159  DeleteBuffers();
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),
170  available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true),
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),
178  available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true),
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),
187  available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true),
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),
195  available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true),
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),
204  available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true),
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),
212  available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true),
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),
220  available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true),
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 
245 protected:
246  virtual void UpdateLineColumn(JJChar c);
247 
248  int* bufline;
249  int* bufcolumn;
251  int bufpos;
252  int bufsize;
254  int column;
255  int line;
260  int inBuf;
261  int tabSize;
265 };
266 
267 }
268 }
269 
270 #endif
271 /* JavaCC - OriginalChecksum=c5b4b2e72393f865547f405cc9def169 (do not edit this line) */
vhdl::parser::CharStream::getColumn
virtual int getColumn()
Definition: CharStream.h:53
vhdl::parser::CharStream::line
int line
Definition: CharStream.h:255
INITIAL_BUFFER_SIZE
#define INITIAL_BUFFER_SIZE
Definition: CharStream.h:9
vhdl::parser::CharStream::~CharStream
virtual ~CharStream()
Definition: CharStream.h:155
JJChar
JAVACC_CHAR_TYPE JJChar
Definition: JavaCC.h:21
vhdl::parser::CharStream::UpdateLineColumn
virtual void UpdateLineColumn(JJChar c)
vhdl::parser::CharStream::available
int available
Definition: CharStream.h:258
vhdl::parser::CharStream::getEndLine
virtual int getEndLine()
Definition: CharStream.h:56
vhdl::parser::CharStream::CharStream
CharStream(ReaderStream *input_stream, int startline, int startcolumn, int buffersize)
Definition: CharStream.h:200
vhdl::parser::CharStream::column
int column
Definition: CharStream.h:254
vhdl::parser::CharStream::trackLineColumn
bool trackLineColumn
Definition: CharStream.h:262
vhdl::parser::CharStream::getTabSize
int getTabSize(int i)
Definition: CharStream.h:34
vhdl::parser::CharStream::ReInit
virtual void ReInit(const JJString &str, int startline, int startcolumn)
Definition: CharStream.h:238
vhdl::parser::CharStream::BeginToken
virtual JJChar BeginToken()
Returns the next character that marks the beginning of the next token.
Definition: CharStream.h:82
vhdl::parser::CharStream::GetImage
virtual JJString GetImage()
Returns a string made up of characters from the marked token beginning to the current buffer position...
Definition: CharStream.h:129
vhdl::parser::CharStream::bufpos
int bufpos
Definition: CharStream.h:251
vhdl::parser::CharStream::FillBuff
virtual void FillBuff()
vhdl::parser::CharStream::ReInit
virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn, int buffersize)
vhdl::parser::CharStream::GetSuffix
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
vhdl::parser::CharStream::prevCharIsCR
bool prevCharIsCR
Definition: CharStream.h:256
ReaderStream::endOfInput
virtual bool endOfInput()
Definition: JavaCC.h:31
vhdl::parser::CharStream::getBufcolumn
int getBufcolumn(int pos)
Definition: CharStream.h:37
vhdl::parser::CharStream::ExpandBuff
virtual void ExpandBuff(bool wrapAround)
vhdl::parser::CharStream::getBufline
int getBufline(int pos)
Definition: CharStream.h:44
vhdl::parser::CharStream::bufline
int * bufline
Definition: CharStream.h:248
vhdl
Token literal values and constants.
Definition: CharStream.h:12
vhdl::parser::CharStream::buffer
JJChar * buffer
Definition: CharStream.h:250
vhdl::parser::CharStream::inBuf
int inBuf
Definition: CharStream.h:260
vhdl::parser::CharStream::tabSize
int tabSize
Definition: CharStream.h:261
vhdl::parser::CharStream::getBeginLine
virtual int getBeginLine()
Definition: CharStream.h:58
vhdl::parser::CharStream::ReInit
virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn)
Definition: CharStream.h:227
vhdl::parser::CharStream::getEndColumn
virtual int getEndColumn()
Definition: CharStream.h:55
vhdl::parser::CharStream::setTabSize
void setTabSize(int i)
Definition: CharStream.h:33
vhdl::parser::CharStream::CharStream
CharStream(const JJChar *buf, int sz, int startline, int startcolumn, int buffersize)
Definition: CharStream.h:166
vhdl::parser::CharStream::CharStream
CharStream(const JJString &str, int startline, int startcolumn)
Definition: CharStream.h:192
JJString
JAVACC_STRING_TYPE JJString
Definition: JavaCC.h:22
vhdl::parser::CharStream::bufsize
int bufsize
Definition: CharStream.h:252
vhdl::parser::CharStream::endOfInput
bool endOfInput()
Definition: CharStream.h:162
vhdl::parser::CharStream::backup
virtual void backup(int amount)
Backs up the input stream by amount steps.
Definition: CharStream.h:69
vhdl::parser::CharStream::getTrackLineColumn
virtual bool getTrackLineColumn()
Definition: CharStream.h:60
vhdl::parser::CharStream::prevCharIsLF
bool prevCharIsLF
Definition: CharStream.h:257
vhdl::parser::CharStream::readChar
virtual JJChar readChar()
Returns the next character from the selected input.
Definition: CharStream.h:95
vhdl::parser::CharStream::getLine
virtual int getLine()
Definition: CharStream.h:54
vhdl::parser::CharStream::setTrackLineColumn
virtual void setTrackLineColumn(bool val)
Definition: CharStream.h:61
vhdl::parser::CharStream::adjustBeginLineColumn
virtual void adjustBeginLineColumn(int newLine, int newCol)
vhdl::parser::CharStream::CharStream
CharStream(const JJChar *buf, int sz, int startline, int startcolumn)
Definition: CharStream.h:175
vhdl::parser::CharStream::maxNextCharInd
int maxNextCharInd
Definition: CharStream.h:259
vhdl::parser::CharStream::deleteStream
bool deleteStream
Definition: CharStream.h:264
vhdl::parser::CharStream::CharStream
CharStream(ReaderStream *input_stream, int startline, int startcolumn)
Definition: CharStream.h:209
vhdl::parser::CharStream::DeleteBuffers
virtual void DeleteBuffers()
The lexer calls this function to indicate that it is done with the stream and hence implementations c...
vhdl::parser::CharStream::bufcolumn
int * bufcolumn
Definition: CharStream.h:249
JavaCC.h
vhdl::parser::CharStream::CharStream
CharStream(const JJString &str, int startline, int startcolumn, int buffersize)
Definition: CharStream.h:183
vhdl::parser::CharStream
This class describes a character stream that maintains line and column number positions of the charac...
Definition: CharStream.h:31
ReaderStream
Definition: JavaCC.h:27
vhdl::parser::CharStream::tokenBegin
int tokenBegin
Definition: CharStream.h:253
vhdl::parser::CharStream::ReInit
virtual void ReInit(ReaderStream *input_stream)
Definition: CharStream.h:231
vhdl::parser::CharStream::CharStream
CharStream(ReaderStream *input_stream)
Definition: CharStream.h:217
vhdl::parser::CharStream::getBeginColumn
virtual int getBeginColumn()
Definition: CharStream.h:57
vhdl::parser::CharStream::inputStream
ReaderStream * inputStream
Definition: CharStream.h:263