|
Packit |
1c1d7e |
/* Generated By:JavaCC: Do not edit this line. CharStream.h Version 6.0 */
|
|
Packit |
1c1d7e |
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
|
|
Packit |
1c1d7e |
#ifndef CHARSTREAM_H
|
|
Packit |
1c1d7e |
#define CHARSTREAM_H
|
|
Packit |
1c1d7e |
#include "JavaCC.h"
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#ifndef INITIAL_BUFFER_SIZE
|
|
Packit |
1c1d7e |
#define INITIAL_BUFFER_SIZE 4096
|
|
Packit |
1c1d7e |
#endif
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
namespace vhdl {
|
|
Packit |
1c1d7e |
namespace parser {
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/**
|
|
Packit |
1c1d7e |
* This class describes a character stream that maintains line and
|
|
Packit |
1c1d7e |
* column number positions of the characters. It also has the capability
|
|
Packit |
1c1d7e |
* to backup the stream to some extent. An implementation of this
|
|
Packit |
1c1d7e |
* class is used in the TokenManager implementation generated by
|
|
Packit |
1c1d7e |
* JavaCCParser.
|
|
Packit |
1c1d7e |
*
|
|
Packit |
1c1d7e |
* All the methods except backup can be implemented in any fashion. backup
|
|
Packit |
1c1d7e |
* needs to be implemented correctly for the correct operation of the lexer.
|
|
Packit |
1c1d7e |
* Rest of the methods are all used to get information like line number,
|
|
Packit |
1c1d7e |
* column number and the string that constitutes a token and are not used
|
|
Packit |
1c1d7e |
* by the lexer. Hence their implementation won't affect the generated lexer's
|
|
Packit |
1c1d7e |
* operation.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
class CharStream {
|
|
Packit |
1c1d7e |
public:
|
|
Packit |
1c1d7e |
void setTabSize(int i) { tabSize = i; }
|
|
Packit |
1c1d7e |
int getTabSize(int i) { return tabSize; }
|
|
Packit |
1c1d7e |
virtual int getColumn() { return trackLineColumn ? bufcolumn[bufpos] : -1; }
|
|
Packit |
1c1d7e |
virtual int getLine() { return trackLineColumn ? bufline[bufpos] : -1; }
|
|
Packit |
1c1d7e |
virtual int getEndColumn() { return trackLineColumn ? bufcolumn[bufpos] : -1; }
|
|
Packit |
1c1d7e |
virtual int getEndLine() { return trackLineColumn ? bufline[bufpos] : -1; }
|
|
Packit |
1c1d7e |
virtual int getBeginColumn() { return trackLineColumn ? bufcolumn[tokenBegin] : -1; }
|
|
Packit |
1c1d7e |
virtual int getBeginLine() { return trackLineColumn ? bufline[tokenBegin] : -1; }
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
virtual bool getTrackLineColumn() { return trackLineColumn; }
|
|
Packit |
1c1d7e |
virtual void setTrackLineColumn(bool val) { trackLineColumn = val; }
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/**
|
|
Packit |
1c1d7e |
* Backs up the input stream by amount steps. Lexer calls this method if it
|
|
Packit |
1c1d7e |
* had already read some characters, but could not use them to match a
|
|
Packit |
1c1d7e |
* (longer) token. So, they will be used again as the prefix of the next
|
|
Packit |
1c1d7e |
* token and it is the implemetation's responsibility to do this right.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual inline void backup(int amount) {
|
|
Packit |
1c1d7e |
inBuf += amount;
|
|
Packit |
1c1d7e |
bufpos -= amount;
|
|
Packit |
1c1d7e |
if (bufpos < 0) {
|
|
Packit |
1c1d7e |
bufpos += bufsize;
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/**
|
|
Packit |
1c1d7e |
* Returns the next character that marks the beginning of the next token.
|
|
Packit |
1c1d7e |
* All characters must remain in the buffer between two successive calls
|
|
Packit |
1c1d7e |
* to this method to implement backup correctly.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual inline JAVACC_CHAR_TYPE BeginToken() {
|
|
Packit |
1c1d7e |
tokenBegin = -1;
|
|
Packit |
1c1d7e |
JAVACC_CHAR_TYPE c = readChar();
|
|
Packit |
1c1d7e |
tokenBegin = bufpos;
|
|
Packit |
1c1d7e |
return c;
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/**
|
|
Packit |
1c1d7e |
* Returns the next character from the selected input. The method
|
|
Packit |
1c1d7e |
* of selecting the input is the responsibility of the class
|
|
Packit |
1c1d7e |
* implementing this class.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual inline JAVACC_CHAR_TYPE readChar() {
|
|
Packit |
1c1d7e |
if (inBuf > 0) {
|
|
Packit |
1c1d7e |
--inBuf;
|
|
Packit |
1c1d7e |
++bufpos;
|
|
Packit |
1c1d7e |
if (bufpos == bufsize) {
|
|
Packit |
1c1d7e |
bufpos = 0;
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
return buffer[bufpos];
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
++bufpos;
|
|
Packit |
1c1d7e |
if (bufpos >= maxNextCharInd) {
|
|
Packit |
1c1d7e |
FillBuff();
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
JAVACC_CHAR_TYPE c = buffer[bufpos];
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
if (trackLineColumn) {
|
|
Packit |
1c1d7e |
UpdateLineColumn(c);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
return c;
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
virtual void ExpandBuff(bool wrapAround);
|
|
Packit |
1c1d7e |
virtual void FillBuff();
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/**
|
|
Packit |
1c1d7e |
* Returns a string made up of characters from the marked token beginning
|
|
Packit |
1c1d7e |
* to the current buffer position. Implementations can return
|
|
Packit |
1c1d7e |
* anything that they want to. For example, for efficiency, one might decide
|
|
Packit |
1c1d7e |
* to just return NULL, which is a valid implementation.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual JAVACC_STRING_TYPE GetImage() {
|
|
Packit |
1c1d7e |
if (bufpos >= tokenBegin)
|
|
Packit |
1c1d7e |
return JAVACC_STRING_TYPE(buffer + tokenBegin, bufpos - tokenBegin + 1);
|
|
Packit |
1c1d7e |
else
|
|
Packit |
1c1d7e |
return JAVACC_STRING_TYPE(buffer + tokenBegin, bufsize - tokenBegin)
|
|
Packit |
1c1d7e |
.append(buffer, bufpos + 1);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/**
|
|
Packit |
1c1d7e |
* Returns an array of characters that make up the suffix of length 'len' for
|
|
Packit |
1c1d7e |
* the currently matched token. This is used to build up the matched string
|
|
Packit |
1c1d7e |
* for use in actions in the case of MORE. A simple and inefficient
|
|
Packit |
1c1d7e |
* implementation of this is as follows :
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual JAVACC_STRING_TYPE GetSuffix(int len) {
|
|
Packit |
1c1d7e |
if ((bufpos + 1) >= len) {
|
|
Packit |
1c1d7e |
return JAVACC_STRING_TYPE(buffer + bufpos - len + 1, len);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
return JAVACC_STRING_TYPE(buffer + bufsize - (len - bufpos - 1), len - bufpos - 1)
|
|
Packit |
1c1d7e |
.append(buffer, bufpos + 1);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/**
|
|
Packit |
1c1d7e |
* The lexer calls this function to indicate that it is done with the stream
|
|
Packit |
1c1d7e |
* and hence implementations can free any resources held by this class.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual void DeleteBuffers();
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
virtual ~CharStream() {
|
|
Packit |
1c1d7e |
if (deleteStream) {
|
|
Packit |
1c1d7e |
delete inputStream;
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
DeleteBuffers();
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
bool endOfInput() {
|
|
Packit |
1c1d7e |
return inBuf == 0 && bufpos + 1 >= maxNextCharInd &&
|
|
Packit |
1c1d7e |
inputStream->endOfInput();
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
CharStream(const JAVACC_CHAR_TYPE *buf, int sz, int startline,
|
|
Packit |
1c1d7e |
int startcolumn, int buffersize) :
|
|
Packit |
1c1d7e |
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
|
|
Packit |
1c1d7e |
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
|
|
Packit |
1c1d7e |
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
|
|
Packit |
1c1d7e |
inBuf(0),tabSize(8), trackLineColumn(true) {
|
|
Packit |
1c1d7e |
ReInit(JAVACC_STRING_TYPE(buf, sz), startline, startcolumn, buffersize);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
CharStream(const JAVACC_CHAR_TYPE *buf, int sz, int startline, int startcolumn) :
|
|
Packit |
1c1d7e |
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
|
|
Packit |
1c1d7e |
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
|
|
Packit |
1c1d7e |
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
|
|
Packit |
1c1d7e |
inBuf(0),tabSize(8), trackLineColumn(true) {
|
|
Packit |
1c1d7e |
ReInit(JAVACC_STRING_TYPE(buf, sz), startline, startcolumn, INITIAL_BUFFER_SIZE);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
CharStream(const JAVACC_STRING_TYPE& str, int startline,
|
|
Packit |
1c1d7e |
int startcolumn, int buffersize) :
|
|
Packit |
1c1d7e |
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
|
|
Packit |
1c1d7e |
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
|
|
Packit |
1c1d7e |
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
|
|
Packit |
1c1d7e |
inBuf(0),tabSize(8), trackLineColumn(true) {
|
|
Packit |
1c1d7e |
ReInit(str, startline, startcolumn, buffersize);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
CharStream(const JAVACC_STRING_TYPE& str, int startline, int startcolumn) :
|
|
Packit |
1c1d7e |
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
|
|
Packit |
1c1d7e |
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
|
|
Packit |
1c1d7e |
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
|
|
Packit |
1c1d7e |
inBuf(0) ,tabSize(8), trackLineColumn(true){
|
|
Packit |
1c1d7e |
ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
CharStream(ReaderStream *input_stream, int startline,
|
|
Packit |
1c1d7e |
int startcolumn, int buffersize) :
|
|
Packit |
1c1d7e |
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
|
|
Packit |
1c1d7e |
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
|
|
Packit |
1c1d7e |
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
|
|
Packit |
1c1d7e |
inBuf(0),tabSize(8), trackLineColumn(true) {
|
|
Packit |
1c1d7e |
ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
CharStream(ReaderStream *input_stream, int startline, int startcolumn) :
|
|
Packit |
1c1d7e |
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
|
|
Packit |
1c1d7e |
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
|
|
Packit |
1c1d7e |
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
|
|
Packit |
1c1d7e |
inBuf(0),tabSize(8), trackLineColumn(true) {
|
|
Packit |
1c1d7e |
ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
CharStream(ReaderStream *input_stream) :
|
|
Packit |
1c1d7e |
bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
|
|
Packit |
1c1d7e |
buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
|
|
Packit |
1c1d7e |
prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
|
|
Packit |
1c1d7e |
inBuf(0),tabSize(8), trackLineColumn(true) {
|
|
Packit |
1c1d7e |
ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn,
|
|
Packit |
1c1d7e |
int buffersize);
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
virtual void ReInit(ReaderStream *input_stream, int startline,
|
|
Packit |
1c1d7e |
int startcolumn) {
|
|
Packit |
1c1d7e |
ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
virtual void ReInit(ReaderStream *input_stream) {
|
|
Packit |
1c1d7e |
ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
virtual void ReInit(const JAVACC_STRING_TYPE& str, int startline,
|
|
Packit |
1c1d7e |
int startcolumn, int buffersize);
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
virtual void ReInit(const JAVACC_STRING_TYPE& str, int startline,
|
|
Packit |
1c1d7e |
int startcolumn) {
|
|
Packit |
1c1d7e |
ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
virtual void adjustBeginLineColumn(int newLine, int newCol);
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
protected:
|
|
Packit |
1c1d7e |
virtual void UpdateLineColumn(JAVACC_CHAR_TYPE c);
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
int *bufline;
|
|
Packit |
1c1d7e |
int *bufcolumn;
|
|
Packit |
1c1d7e |
ReaderStream *inputStream;
|
|
Packit |
1c1d7e |
bool deleteStream;
|
|
Packit |
1c1d7e |
JAVACC_CHAR_TYPE * buffer;
|
|
Packit |
1c1d7e |
int bufpos;
|
|
Packit |
1c1d7e |
int bufsize;
|
|
Packit |
1c1d7e |
int tokenBegin;
|
|
Packit |
1c1d7e |
int column;
|
|
Packit |
1c1d7e |
int line;
|
|
Packit |
1c1d7e |
bool prevCharIsCR ;
|
|
Packit |
1c1d7e |
bool prevCharIsLF ;
|
|
Packit |
1c1d7e |
int available;
|
|
Packit |
1c1d7e |
int maxNextCharInd;
|
|
Packit |
1c1d7e |
int inBuf ;
|
|
Packit |
1c1d7e |
int tabSize ;
|
|
Packit |
1c1d7e |
bool trackLineColumn;
|
|
Packit |
1c1d7e |
};
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
#endif
|
|
Packit |
1c1d7e |
/* JavaCC - OriginalChecksum=5eaf75ef6a2c7859369c80cf6fd037e0 (do not edit this line) */
|