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