Skip to main content

The CharStream Class Reference

This class describes a character stream that maintains line and column number positions of the characters. More...

Declaration

class vhdl::parser::CharStream { ... }

Included Headers

Public Constructors Index

CharStream (const JJChar *buf, int sz, int startline, int startcolumn, int buffersize)
CharStream (const JJChar *buf, int sz, int startline, int startcolumn)
CharStream (const JJString &str, int startline, int startcolumn, int buffersize)
CharStream (const JJString &str, int startline, int startcolumn)
CharStream (ReaderStream *input_stream, int startline, int startcolumn, int buffersize)
CharStream (ReaderStream *input_stream, int startline, int startcolumn)
CharStream (ReaderStream *input_stream)

Public Destructor Index

~CharStream ()

Public Member Functions Index

voidsetTabSize (int i)
intgetTabSize (int i)
intgetColumn ()
intgetLine ()
intgetEndColumn ()
intgetEndLine ()
intgetBeginColumn ()
intgetBeginLine ()
boolgetTrackLineColumn ()
voidsetTrackLineColumn (bool val)
voidbackup (int amount)

Backs up the input stream by amount steps. More...

JJCharBeginToken ()

Returns the next character that marks the beginning of the next token. More...

JJCharreadChar ()

Returns the next character from the selected input. More...

voidExpandBuff (bool wrapAround)
voidFillBuff ()
JJStringGetImage ()

Returns a string made up of characters from the marked token beginning to the current buffer position. More...

JJStringGetSuffix (int len)

Returns an array of characters that make up the suffix of length 'len' for the currently matched token. More...

voidDeleteBuffers ()

The lexer calls this function to indicate that it is done with the stream and hence implementations can free any resources held by this class. More...

boolendOfInput ()
voidReInit (ReaderStream *input_stream, int startline, int startcolumn, int buffersize)
voidReInit (ReaderStream *input_stream, int startline, int startcolumn)
voidReInit (ReaderStream *input_stream)
voidReInit (const JJString &str, int startline, int startcolumn, int buffersize)
voidReInit (const JJString &str, int startline, int startcolumn)
voidadjustBeginLineColumn (int newLine, int newCol)

Protected Member Functions Index

voidUpdateLineColumn (JJChar c)

Private Member Functions Index

intgetBufcolumn (int pos)
intgetBufline (int pos)

Protected Member Attributes Index

int *bufline
int *bufcolumn
JJChar *buffer
intbufpos
intbufsize
inttokenBegin
intcolumn
intline
boolprevCharIsCR
boolprevCharIsLF
intavailable
intmaxNextCharInd
intinBuf
inttabSize
booltrackLineColumn
ReaderStream *inputStream
booldeleteStream

Description

This class describes a character stream that maintains line and column number positions of the characters.

It also has the capability to backup the stream to some extent. An implementation of this class is used in the TokenManager implementation generated by JavaCCParser.

All the methods except backup can be implemented in any fashion. backup needs to be implemented correctly for the correct operation of the lexer. Rest of the methods are all used to get information like line number, column number and the string that constitutes a token and are not used by the lexer. Hence their implementation won't affect the generated lexer's operation.

Definition at line 31 of file CharStream.h.

Public Constructors

CharStream()

vhdl::parser::CharStream::CharStream (const JJChar * buf, int sz, int startline, int startcolumn, int buffersize)
inline

Definition at line 166 of file CharStream.h.

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 }

References available, bufcolumn, buffer, bufline, bufpos, bufsize, column, deleteStream, inBuf, inputStream, line, maxNextCharInd, prevCharIsCR, prevCharIsLF, ReInit, tabSize, tokenBegin and trackLineColumn.

CharStream()

vhdl::parser::CharStream::CharStream (const JJChar * buf, int sz, int startline, int startcolumn)
inline

Definition at line 175 of file CharStream.h.

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 }

References available, bufcolumn, buffer, bufline, bufpos, bufsize, column, deleteStream, inBuf, INITIAL_BUFFER_SIZE, inputStream, line, maxNextCharInd, prevCharIsCR, prevCharIsLF, ReInit, tabSize, tokenBegin and trackLineColumn.

CharStream()

vhdl::parser::CharStream::CharStream (const JJString & str, int startline, int startcolumn, int buffersize)
inline

Definition at line 183 of file CharStream.h.

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 }

References available, bufcolumn, buffer, bufline, bufpos, bufsize, column, deleteStream, inBuf, inputStream, line, maxNextCharInd, prevCharIsCR, prevCharIsLF, ReInit, tabSize, tokenBegin and trackLineColumn.

CharStream()

vhdl::parser::CharStream::CharStream (const JJString & str, int startline, int startcolumn)
inline

Definition at line 192 of file CharStream.h.

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 }

References available, bufcolumn, buffer, bufline, bufpos, bufsize, column, deleteStream, inBuf, INITIAL_BUFFER_SIZE, inputStream, line, maxNextCharInd, prevCharIsCR, prevCharIsLF, ReInit, tabSize, tokenBegin and trackLineColumn.

CharStream()

vhdl::parser::CharStream::CharStream (ReaderStream * input_stream, int startline, int startcolumn, int buffersize)
inline

Definition at line 200 of file CharStream.h.

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 }

References available, bufcolumn, buffer, bufline, bufpos, bufsize, column, deleteStream, inBuf, inputStream, line, maxNextCharInd, prevCharIsCR, prevCharIsLF, ReInit, tabSize, tokenBegin and trackLineColumn.

CharStream()

vhdl::parser::CharStream::CharStream (ReaderStream * input_stream, int startline, int startcolumn)
inline

Definition at line 209 of file CharStream.h.

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 }

References available, bufcolumn, buffer, bufline, bufpos, bufsize, column, deleteStream, inBuf, INITIAL_BUFFER_SIZE, inputStream, line, maxNextCharInd, prevCharIsCR, prevCharIsLF, ReInit, tabSize, tokenBegin and trackLineColumn.

CharStream()

vhdl::parser::CharStream::CharStream (ReaderStream * input_stream)
inline

Definition at line 217 of file CharStream.h.

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 }

References available, bufcolumn, buffer, bufline, bufpos, bufsize, column, deleteStream, inBuf, INITIAL_BUFFER_SIZE, inputStream, line, maxNextCharInd, prevCharIsCR, prevCharIsLF, ReInit, tabSize, tokenBegin and trackLineColumn.

Public Destructor

~CharStream()

virtual vhdl::parser::CharStream::~CharStream ()
inline virtual

Definition at line 155 of file CharStream.h.

155 virtual ~CharStream() {
156 if (deleteStream) {
157 delete inputStream;
158 }
160 }

References DeleteBuffers, deleteStream and inputStream.

Public Member Functions

adjustBeginLineColumn()

virtual void vhdl::parser::CharStream::adjustBeginLineColumn (int newLine, int newCol)
virtual

Definition at line 243 of file CharStream.h.

Reference newLine.

backup()

virtual void vhdl::parser::CharStream::backup (int amount)
inline virtual

Backs up the input stream by amount steps.

Lexer calls this method if it had already read some characters, but could not use them to match a (longer) token. So, they will be used again as the prefix of the next token and it is the implementation's responsibility to do this right.

Definition at line 69 of file CharStream.h.

69 virtual inline void backup(int amount) {
70 inBuf += amount;
71 bufpos -= amount;
72 if (bufpos < 0) {
74 }
75 }

References bufpos, bufsize and inBuf.

BeginToken()

virtual JJChar vhdl::parser::CharStream::BeginToken ()
inline virtual

Returns the next character that marks the beginning of the next token.

All characters must remain in the buffer between two successive calls to this method to implement backup correctly.

Definition at line 82 of file CharStream.h.

82 virtual inline JJChar BeginToken() {
83 tokenBegin = -1;
84 JJChar c = readChar();
86 return c;
87 }

References bufpos, readChar and tokenBegin.

DeleteBuffers()

virtual void vhdl::parser::CharStream::DeleteBuffers ()
virtual

The lexer calls this function to indicate that it is done with the stream and hence implementations can free any resources held by this class.

Definition at line 153 of file CharStream.h.

Referenced by ~CharStream.

endOfInput()

bool vhdl::parser::CharStream::endOfInput ()
inline

Definition at line 162 of file CharStream.h.

162 bool endOfInput() {
163 return inBuf == 0 && bufpos + 1 >= maxNextCharInd && inputStream->endOfInput();
164 }

References bufpos, inBuf, inputStream and maxNextCharInd.

ExpandBuff()

virtual void vhdl::parser::CharStream::ExpandBuff (bool wrapAround)
virtual

Definition at line 120 of file CharStream.h.

FillBuff()

virtual void vhdl::parser::CharStream::FillBuff ()
virtual

Definition at line 121 of file CharStream.h.

Referenced by readChar.

getBeginColumn()

virtual int vhdl::parser::CharStream::getBeginColumn ()
inline virtual

Definition at line 57 of file CharStream.h.

57 virtual int getBeginColumn() { return getBufcolumn(tokenBegin); }

References getBufcolumn and tokenBegin.

getBeginLine()

virtual int vhdl::parser::CharStream::getBeginLine ()
inline virtual

Definition at line 58 of file CharStream.h.

58 virtual int getBeginLine() { return getBufline(tokenBegin); }

References getBufline and tokenBegin.

getColumn()

virtual int vhdl::parser::CharStream::getColumn ()
inline virtual

Definition at line 53 of file CharStream.h.

53 virtual int getColumn() { return getBufcolumn(bufpos); }

References bufpos and getBufcolumn.

getEndColumn()

virtual int vhdl::parser::CharStream::getEndColumn ()
inline virtual

Definition at line 55 of file CharStream.h.

55 virtual int getEndColumn() { return getBufcolumn(bufpos); }

References bufpos and getBufcolumn.

getEndLine()

virtual int vhdl::parser::CharStream::getEndLine ()
inline virtual

Definition at line 56 of file CharStream.h.

56 virtual int getEndLine() { return getBufline(bufpos); }

References bufpos and getBufline.

GetImage()

virtual JJString vhdl::parser::CharStream::GetImage ()
inline virtual

Returns a string made up of characters from the marked token beginning to the current buffer position.

Implementations can return anything that they want to. For example, for efficiency, one might decide to just return NULL, which is a valid implementation.

Definition at line 129 of file CharStream.h.

129 virtual JJString GetImage() {
130 if (bufpos >= tokenBegin)
132 else
133 return JJString(buffer + tokenBegin, bufsize - tokenBegin).append(buffer, bufpos + 1);
134 }

References buffer, bufpos, bufsize and tokenBegin.

getLine()

virtual int vhdl::parser::CharStream::getLine ()
inline virtual

Definition at line 54 of file CharStream.h.

54 virtual int getLine() { return getBufline(bufpos); }

References bufpos and getBufline.

GetSuffix()

virtual JJString vhdl::parser::CharStream::GetSuffix (int len)
inline virtual

Returns an array of characters that make up the suffix of length 'len' for the currently matched token.

This is used to build up the matched string for use in actions in the case of MORE. A simple and inefficient implementation of this is as follows :

Definition at line 142 of file CharStream.h.

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 }

References buffer, bufpos and bufsize.

getTabSize()

int vhdl::parser::CharStream::getTabSize (int i)
inline

Definition at line 34 of file CharStream.h.

34 int getTabSize(int i) { return tabSize; }

Reference tabSize.

getTrackLineColumn()

virtual bool vhdl::parser::CharStream::getTrackLineColumn ()
inline virtual

Definition at line 60 of file CharStream.h.

60 virtual bool getTrackLineColumn() { return trackLineColumn; }

Reference trackLineColumn.

readChar()

virtual JJChar vhdl::parser::CharStream::readChar ()
inline virtual

Returns the next character from the selected input.

The method of selecting the input is the responsibility of the class implementing this class.

Definition at line 95 of file CharStream.h.

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 }

References buffer, bufpos, bufsize, FillBuff, inBuf, maxNextCharInd, trackLineColumn and UpdateLineColumn.

Referenced by BeginToken.

ReInit()

virtual void vhdl::parser::CharStream::ReInit (ReaderStream * input_stream, int startline, int startcolumn, int buffersize)
virtual

Definition at line 225 of file CharStream.h.

Referenced by CharStream, CharStream, CharStream, CharStream, CharStream, CharStream, CharStream, ReInit, ReInit and ReInit.

ReInit()

virtual void vhdl::parser::CharStream::ReInit (ReaderStream * input_stream, int startline, int startcolumn)
inline virtual

Definition at line 227 of file CharStream.h.

227 virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn) {
228 ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
229 }

References INITIAL_BUFFER_SIZE and ReInit.

ReInit()

virtual void vhdl::parser::CharStream::ReInit (ReaderStream * input_stream)
inline virtual

Definition at line 231 of file CharStream.h.

231 virtual void ReInit(ReaderStream *input_stream) {
232 ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
233 }

References INITIAL_BUFFER_SIZE and ReInit.

ReInit()

virtual void vhdl::parser::CharStream::ReInit (const JJString & str, int startline, int startcolumn, int buffersize)
virtual

Definition at line 235 of file CharStream.h.

ReInit()

virtual void vhdl::parser::CharStream::ReInit (const JJString & str, int startline, int startcolumn)
inline virtual

Definition at line 238 of file CharStream.h.

238 virtual void ReInit(const JJString& str, int startline,
239 int startcolumn) {
240 ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
241 }

References INITIAL_BUFFER_SIZE and ReInit.

setTabSize()

void vhdl::parser::CharStream::setTabSize (int i)
inline

Definition at line 33 of file CharStream.h.

33 void setTabSize(int i) { tabSize = i; }

Reference tabSize.

setTrackLineColumn()

virtual void vhdl::parser::CharStream::setTrackLineColumn (bool val)
inline virtual

Definition at line 61 of file CharStream.h.

61 virtual void setTrackLineColumn(bool val) { trackLineColumn = val; }

Reference trackLineColumn.

Protected Member Functions

UpdateLineColumn()

virtual void vhdl::parser::CharStream::UpdateLineColumn (JJChar c)
protected virtual

Definition at line 246 of file CharStream.h.

Referenced by readChar.

Private Member Functions

getBufcolumn()

int vhdl::parser::CharStream::getBufcolumn (int pos)
inline

Definition at line 37 of file CharStream.h.

37 int getBufcolumn(int pos) {
38 if (trackLineColumn && pos>=0) {
39 return bufcolumn[pos];
40 } else {
41 return -1;
42 }
43 }

References bufcolumn and trackLineColumn.

Referenced by getBeginColumn, getColumn and getEndColumn.

getBufline()

int vhdl::parser::CharStream::getBufline (int pos)
inline

Definition at line 44 of file CharStream.h.

44 int getBufline(int pos) {
45 if (trackLineColumn && pos>=0) {
46 return bufline[pos];
47 } else {
48 return -1;
49 }
50 }

References bufline and trackLineColumn.

Referenced by getBeginLine, getEndLine and getLine.

Protected Member Attributes

available

int vhdl::parser::CharStream::available
protected

Definition at line 258 of file CharStream.h.

Referenced by CharStream, CharStream, CharStream, CharStream, CharStream, CharStream and CharStream.

bufcolumn

int* vhdl::parser::CharStream::bufcolumn
protected

Definition at line 249 of file CharStream.h.

Referenced by CharStream, CharStream, CharStream, CharStream, CharStream, CharStream, CharStream and getBufcolumn.

buffer

JJChar* vhdl::parser::CharStream::buffer
protected

bufline

int* vhdl::parser::CharStream::bufline
protected

Definition at line 248 of file CharStream.h.

248 int* bufline;

Referenced by CharStream, CharStream, CharStream, CharStream, CharStream, CharStream, CharStream and getBufline.

bufpos

int vhdl::parser::CharStream::bufpos
protected

bufsize

int vhdl::parser::CharStream::bufsize
protected

column

int vhdl::parser::CharStream::column
protected

Definition at line 254 of file CharStream.h.

254 int column;

Referenced by CharStream, CharStream, CharStream, CharStream, CharStream, CharStream and CharStream.

deleteStream

bool vhdl::parser::CharStream::deleteStream
protected

Definition at line 264 of file CharStream.h.

Referenced by CharStream, CharStream, CharStream, CharStream, CharStream, CharStream, CharStream and ~CharStream.

inBuf

int vhdl::parser::CharStream::inBuf
protected

Definition at line 260 of file CharStream.h.

260 int inBuf;

Referenced by backup, CharStream, CharStream, CharStream, CharStream, CharStream, CharStream, CharStream, endOfInput and readChar.

inputStream

ReaderStream* vhdl::parser::CharStream::inputStream
protected

line

int vhdl::parser::CharStream::line
protected

Definition at line 255 of file CharStream.h.

255 int line;

Referenced by CharStream, CharStream, CharStream, CharStream, CharStream, CharStream and CharStream.

maxNextCharInd

int vhdl::parser::CharStream::maxNextCharInd
protected

prevCharIsCR

bool vhdl::parser::CharStream::prevCharIsCR
protected

Definition at line 256 of file CharStream.h.

Referenced by CharStream, CharStream, CharStream, CharStream, CharStream, CharStream and CharStream.

prevCharIsLF

bool vhdl::parser::CharStream::prevCharIsLF
protected

Definition at line 257 of file CharStream.h.

Referenced by CharStream, CharStream, CharStream, CharStream, CharStream, CharStream and CharStream.

tabSize

int vhdl::parser::CharStream::tabSize
protected

Definition at line 261 of file CharStream.h.

Referenced by CharStream, CharStream, CharStream, CharStream, CharStream, CharStream, CharStream, getTabSize and setTabSize.

tokenBegin

int vhdl::parser::CharStream::tokenBegin
protected

trackLineColumn

bool vhdl::parser::CharStream::trackLineColumn
protected

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus by Doxygen 1.14.0.