Doxygen
Loading...
Searching...
No Matches
vhdl::parser::CharStream Class Reference

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

#include <vhdlparser/CharStream.h>

+ Collaboration diagram for vhdl::parser::CharStream:

Public Member Functions

void setTabSize (int i)
 
int getTabSize (int i)
 
virtual int getColumn ()
 
virtual int getLine ()
 
virtual int getEndColumn ()
 
virtual int getEndLine ()
 
virtual int getBeginColumn ()
 
virtual int getBeginLine ()
 
virtual bool getTrackLineColumn ()
 
virtual void setTrackLineColumn (bool val)
 
virtual void backup (int amount)
 Backs up the input stream by amount steps.
 
virtual JJChar BeginToken ()
 Returns the next character that marks the beginning of the next token.
 
virtual JJChar readChar ()
 Returns the next character from the selected input.
 
virtual void ExpandBuff (bool wrapAround)
 
virtual void FillBuff ()
 
virtual JJString GetImage ()
 Returns a string made up of characters from the marked token beginning to the current buffer position.
 
virtual JJString GetSuffix (int len)
 Returns an array of characters that make up the suffix of length 'len' for the currently matched token.
 
virtual void DeleteBuffers ()
 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.
 
virtual ~CharStream ()
 
bool endOfInput ()
 
 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)
 
virtual void ReInit (ReaderStream *input_stream, int startline, int startcolumn, int buffersize)
 
virtual void ReInit (ReaderStream *input_stream, int startline, int startcolumn)
 
virtual void ReInit (ReaderStream *input_stream)
 
virtual void ReInit (const JJString &str, int startline, int startcolumn, int buffersize)
 
virtual void ReInit (const JJString &str, int startline, int startcolumn)
 
virtual void adjustBeginLineColumn (int newLine, int newCol)
 

Protected Member Functions

virtual void UpdateLineColumn (JJChar c)
 

Protected Attributes

int * bufline
 
int * bufcolumn
 
JJCharbuffer
 
int bufpos
 
int bufsize
 
int tokenBegin
 
int column
 
int line
 
bool prevCharIsCR
 
bool prevCharIsLF
 
int available
 
int maxNextCharInd
 
int inBuf
 
int tabSize
 
bool trackLineColumn
 
ReaderStreaminputStream
 
bool deleteStream
 

Private Member Functions

int getBufcolumn (int pos)
 
int getBufline (int pos)
 

Detailed 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.

Constructor & Destructor Documentation

◆ ~CharStream()

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

Definition at line 155 of file CharStream.h.

155 {
156 if (deleteStream) {
157 delete inputStream;
158 }
160 }
virtual void DeleteBuffers()
The lexer calls this function to indicate that it is done with the stream and hence implementations c...
ReaderStream * inputStream
Definition CharStream.h:263

References DeleteBuffers(), deleteStream, and inputStream.

◆ CharStream() [1/7]

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

Definition at line 166 of file CharStream.h.

167 :
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 }
JAVACC_STRING_TYPE JJString
Definition JavaCC.h:22
virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn, int buffersize)

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

◆ CharStream() [2/7]

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

Definition at line 175 of file CharStream.h.

175 :
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 }
#define INITIAL_BUFFER_SIZE
Definition CharStream.h:9

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

◆ CharStream() [3/7]

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

Definition at line 183 of file CharStream.h.

184 :
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() [4/7]

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

Definition at line 192 of file CharStream.h.

192 :
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() [5/7]

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

Definition at line 200 of file CharStream.h.

201 :
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() [6/7]

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

Definition at line 209 of file CharStream.h.

209 :
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() [7/7]

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

Definition at line 217 of file CharStream.h.

217 :
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.

Member Function Documentation

◆ adjustBeginLineColumn()

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

◆ backup()

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

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 {
70 inBuf += amount;
71 bufpos -= amount;
72 if (bufpos < 0) {
73 bufpos += bufsize;
74 }
75 }

References bufpos, bufsize, and inBuf.

◆ BeginToken()

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

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 {
83 tokenBegin = -1;
84 JJChar c = readChar();
86 return c;
87 }
JAVACC_CHAR_TYPE JJChar
Definition JavaCC.h:21
virtual JJChar readChar()
Returns the next character from the selected input.
Definition CharStream.h:95

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.

Referenced by ~CharStream().

◆ endOfInput()

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

Definition at line 162 of file CharStream.h.

162 {
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

◆ FillBuff()

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

Referenced by readChar().

◆ getBeginColumn()

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

Definition at line 57 of file CharStream.h.

57{ return getBufcolumn(tokenBegin); }
int getBufcolumn(int pos)
Definition CharStream.h:37

References getBufcolumn(), and tokenBegin.

◆ getBeginLine()

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

Definition at line 58 of file CharStream.h.

58{ return getBufline(tokenBegin); }
int getBufline(int pos)
Definition CharStream.h:44

References getBufline(), and tokenBegin.

◆ getBufcolumn()

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

Definition at line 37 of file CharStream.h.

37 {
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)
inlineprivate

Definition at line 44 of file CharStream.h.

44 {
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().

◆ getColumn()

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

Definition at line 53 of file CharStream.h.

53{ return getBufcolumn(bufpos); }

References bufpos, and getBufcolumn().

◆ getEndColumn()

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

Definition at line 55 of file CharStream.h.

55{ return getBufcolumn(bufpos); }

References bufpos, and getBufcolumn().

◆ getEndLine()

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

Definition at line 56 of file CharStream.h.

56{ return getBufline(bufpos); }

References bufpos, and getBufline().

◆ GetImage()

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

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 {
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 }

References buffer, bufpos, bufsize, and tokenBegin.

◆ getLine()

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

Definition at line 54 of file CharStream.h.

54{ return getBufline(bufpos); }

References bufpos, and getBufline().

◆ GetSuffix()

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

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 {
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{ return tabSize; }

References tabSize.

◆ getTrackLineColumn()

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

Definition at line 60 of file CharStream.h.

60{ return trackLineColumn; }

References trackLineColumn.

◆ readChar()

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

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 {
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 }
virtual void UpdateLineColumn(JJChar c)
virtual void FillBuff()

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

Referenced by BeginToken().

◆ ReInit() [1/5]

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

Definition at line 238 of file CharStream.h.

239 {
240 ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
241 }

References INITIAL_BUFFER_SIZE, and ReInit().

◆ ReInit() [2/5]

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

◆ ReInit() [3/5]

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

Definition at line 231 of file CharStream.h.

231 {
232 ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
233 }

References INITIAL_BUFFER_SIZE, and ReInit().

◆ ReInit() [4/5]

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

Definition at line 227 of file CharStream.h.

227 {
228 ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
229 }

References INITIAL_BUFFER_SIZE, and ReInit().

◆ ReInit() [5/5]

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

◆ setTabSize()

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

Definition at line 33 of file CharStream.h.

33{ tabSize = i; }

References tabSize.

◆ setTrackLineColumn()

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

Definition at line 61 of file CharStream.h.

61{ trackLineColumn = val; }

References trackLineColumn.

◆ UpdateLineColumn()

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

Referenced by readChar().

Member Data Documentation

◆ available

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

◆ bufcolumn

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

◆ buffer

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

◆ bufline

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

◆ bufpos

◆ bufsize

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

◆ column

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

◆ deleteStream

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

◆ inBuf

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

◆ inputStream

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

◆ line

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

◆ maxNextCharInd

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

◆ prevCharIsCR

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

◆ prevCharIsLF

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

◆ tabSize

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

◆ 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: