Imported Upstream version 1.8.8
[platform/upstream/doxygen.git] / vhdlparser / CharStream.h
1 /* Generated By:JavaCC: Do not edit this line. CharStream.h Version 6.0 */
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) { return tabSize; }
34   virtual int getColumn() { return trackLineColumn ? bufcolumn[bufpos] : -1; }
35   virtual int getLine() { return trackLineColumn ? bufline[bufpos] : -1; }
36   virtual int getEndColumn() { return trackLineColumn ? bufcolumn[bufpos] : -1; }
37   virtual int getEndLine() { return trackLineColumn ? bufline[bufpos] : -1; }
38   virtual int getBeginColumn() { return trackLineColumn ? bufcolumn[tokenBegin] : -1; }
39   virtual int getBeginLine() { return trackLineColumn ? bufline[tokenBegin] : -1; }
40
41   virtual bool getTrackLineColumn() { return trackLineColumn; }
42   virtual void setTrackLineColumn(bool val) { trackLineColumn = val; }
43
44 /**
45  * Backs up the input stream by amount steps. Lexer calls this method if it
46  * had already read some characters, but could not use them to match a
47  * (longer) token. So, they will be used again as the prefix of the next
48  * token and it is the implemetation's responsibility to do this right.
49  */
50 virtual inline void backup(int amount) {
51   inBuf += amount;
52   bufpos -= amount;
53   if (bufpos < 0) {
54     bufpos += bufsize;
55   }
56 }
57
58 /**
59  * Returns the next character that marks the beginning of the next token.
60  * All characters must remain in the buffer between two successive calls
61  * to this method to implement backup correctly.
62  */
63 virtual inline JAVACC_CHAR_TYPE BeginToken() {
64   tokenBegin = -1;
65   JAVACC_CHAR_TYPE c = readChar();
66   tokenBegin = bufpos;
67   return c;
68 }
69
70
71 /**
72  * Returns the next character from the selected input.  The method
73  * of selecting the input is the responsibility of the class
74  * implementing this class.
75  */
76 virtual inline JAVACC_CHAR_TYPE readChar() {
77   if (inBuf > 0) {
78     --inBuf;
79     ++bufpos;
80     if (bufpos == bufsize) {
81       bufpos = 0;
82     }
83
84     return buffer[bufpos];
85   }
86
87   ++bufpos;
88   if (bufpos >= maxNextCharInd) {
89     FillBuff();
90   }
91
92   JAVACC_CHAR_TYPE c = buffer[bufpos];
93
94   if (trackLineColumn) {
95     UpdateLineColumn(c);
96   }
97
98   return c;
99 }
100
101
102   virtual void ExpandBuff(bool wrapAround);
103   virtual void FillBuff();
104
105   /**
106    * Returns a string made up of characters from the marked token beginning
107    * to the current buffer position. Implementations can return
108    * anything that they want to. For example, for efficiency, one might decide
109    * to just return NULL, which is a valid implementation.
110    */
111   virtual JAVACC_STRING_TYPE GetImage() {
112     if (bufpos >= tokenBegin)
113       return JAVACC_STRING_TYPE(buffer + tokenBegin, bufpos - tokenBegin + 1);
114     else
115       return JAVACC_STRING_TYPE(buffer + tokenBegin, bufsize - tokenBegin)
116              .append(buffer, bufpos + 1);
117   }
118
119   /**
120    * Returns an array of characters that make up the suffix of length 'len' for
121    * the currently matched token. This is used to build up the matched string
122    * for use in actions in the case of MORE. A simple and inefficient
123    * implementation of this is as follows :
124    */
125   virtual JAVACC_STRING_TYPE GetSuffix(int len) {
126     if ((bufpos + 1) >= len) {
127       return JAVACC_STRING_TYPE(buffer + bufpos - len + 1, len);
128     }
129     return JAVACC_STRING_TYPE(buffer + bufsize - (len - bufpos - 1), len - bufpos - 1)
130            .append(buffer, bufpos + 1);
131   }
132
133   /**
134    * The lexer calls this function to indicate that it is done with the stream
135    * and hence implementations can free any resources held by this class.
136    */
137   virtual void DeleteBuffers();
138
139   virtual ~CharStream() {
140     if (deleteStream) {
141      delete inputStream;
142     }
143     DeleteBuffers();
144   }
145
146   bool endOfInput() {
147     return inBuf == 0 && bufpos + 1 >= maxNextCharInd &&
148            inputStream->endOfInput();
149   }
150
151   CharStream(const JAVACC_CHAR_TYPE *buf, int sz, int startline,
152                       int startcolumn, int buffersize) :
153     bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
154     buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
155     prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
156     inBuf(0),tabSize(8), trackLineColumn(true) {
157     ReInit(JAVACC_STRING_TYPE(buf, sz), startline, startcolumn, buffersize);
158   }
159
160   CharStream(const JAVACC_CHAR_TYPE *buf, int sz, int startline, int startcolumn) :
161     bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
162     buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
163     prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
164     inBuf(0),tabSize(8), trackLineColumn(true) {
165     ReInit(JAVACC_STRING_TYPE(buf, sz), startline, startcolumn, INITIAL_BUFFER_SIZE);
166   }
167
168   CharStream(const JAVACC_STRING_TYPE& str, int startline,
169                       int startcolumn, int buffersize) :
170     bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
171     buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
172     prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
173     inBuf(0),tabSize(8), trackLineColumn(true) {
174     ReInit(str, startline, startcolumn, buffersize);
175   }
176
177   CharStream(const JAVACC_STRING_TYPE& str, int startline, int startcolumn) :
178     bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
179     buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
180     prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
181     inBuf(0) ,tabSize(8), trackLineColumn(true){
182     ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
183   }
184
185   CharStream(ReaderStream *input_stream, int startline,
186              int startcolumn, int) :
187     bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
188     buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
189     prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
190     inBuf(0),tabSize(8), trackLineColumn(true) {
191     ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
192   }
193
194   CharStream(ReaderStream *input_stream, int startline, int startcolumn) :
195     bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
196     buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
197     prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
198     inBuf(0),tabSize(8), trackLineColumn(true) {
199     ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
200   }
201
202   CharStream(ReaderStream *input_stream) :
203     bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
204     buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
205     prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
206     inBuf(0),tabSize(8), trackLineColumn(true) {
207     ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
208   }
209
210   virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn,
211                       int buffersize);
212
213   virtual void ReInit(ReaderStream *input_stream, int startline,
214                       int startcolumn) {
215     ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
216   }
217
218   virtual void ReInit(ReaderStream *input_stream) {
219     ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
220   }
221
222   virtual void ReInit(const JAVACC_STRING_TYPE& str, int startline,
223                       int startcolumn, int buffersize);
224
225   virtual void ReInit(const JAVACC_STRING_TYPE& str, int startline,
226                       int startcolumn) {
227     ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
228   }
229
230   virtual void adjustBeginLineColumn(int newLine, int newCol);
231
232  protected:
233   virtual void UpdateLineColumn(JAVACC_CHAR_TYPE c);
234
235   int *bufline;
236   int *bufcolumn;
237   ReaderStream *inputStream;
238   bool deleteStream;
239   JAVACC_CHAR_TYPE * buffer;
240   int bufpos;
241   int bufsize;
242   int tokenBegin;
243   int column;
244   int line;
245   bool prevCharIsCR ;
246   bool prevCharIsLF ;
247   int available;
248   int maxNextCharInd;
249   int inBuf ;
250   int tabSize ;
251   bool trackLineColumn;
252 };
253
254 }
255 }
256 #endif
257 /* JavaCC - OriginalChecksum=5eaf75ef6a2c7859369c80cf6fd037e0 (do not edit this line) */