diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-23 15:26:40 +0100 |
---|---|---|
committer | Andreas Stöckel <andreas@somweyr.de> | 2015-01-23 15:26:40 +0100 |
commit | d4457c98def55d694abc51e008d3fe5663768aab (patch) | |
tree | 95ff09822cef994154a7d3dfef3fcdb81d0814fa /src/core/common/CharReader.cpp | |
parent | b0ab6e4cb077af892046e1fa1504d08e5b66deaf (diff) |
Improved and fixed CharReader
Diffstat (limited to 'src/core/common/CharReader.cpp')
-rw-r--r-- | src/core/common/CharReader.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/core/common/CharReader.cpp b/src/core/common/CharReader.cpp index b0bbade..6fd3d45 100644 --- a/src/core/common/CharReader.cpp +++ b/src/core/common/CharReader.cpp @@ -405,10 +405,10 @@ CharReader::~CharReader() buffer->deleteCursor(peekCursor); } -bool CharReader::readAtCursor(Cursor &cursor, char &c) +bool CharReader::readAtCursor(Buffer::CursorId &cursor, char &c) { // Return false if we're at the end of the stream - if (!buffer->read(cursor.cursor, c)) { + if (!buffer->read(cursor, c)) { return false; } @@ -420,9 +420,9 @@ bool CharReader::readAtCursor(Cursor &cursor, char &c) // Check whether the next character is a continuation of the // current character char c2; - if (buffer->read(cursor.cursor, c2)) { + if (buffer->read(cursor, c2)) { if ((c2 != '\n' && c2 != '\r') || c2 == c) { - buffer->moveCursor(cursor.cursor, -1); + buffer->moveCursor(cursor, -1); } } } @@ -486,8 +486,8 @@ bool CharReader::consumeWhitespace() CharReaderFork CharReader::fork() { - return CharReaderFork(buffer, readCursor, peekCursor, sourceId, offs, - coherent); + return CharReaderFork{buffer, readCursor, peekCursor, + sourceId, offs, coherent}; } size_t CharReader::readRaw(char *buf, size_t size) @@ -502,11 +502,16 @@ size_t CharReader::readRaw(char *buf, size_t size) return res; } -bool CharReader::atEnd() const { return buffer->atEnd(readCursor.cursor); } +bool CharReader::atEnd() const { return buffer->atEnd(readCursor); } -size_t CharReader::getOffset() const +SourceOffset CharReader::getOffset() const { - return buffer->offset(readCursor.cursor) + offs; + return buffer->offset(readCursor) + offs; +} + +SourcePosition CharReader::getPosition() const +{ + return getOffset(); } SourceLocation CharReader::getLocation() const @@ -514,13 +519,19 @@ SourceLocation CharReader::getLocation() const return SourceLocation{sourceId, getOffset()}; } +SourceLocation CharReader::getLocation(SourcePosition start) const +{ + return SourceLocation{sourceId, start, getOffset()}; +} + +SourceId CharReader::getSourceId() const { return sourceId; } + /* Class CharReaderFork */ CharReaderFork::CharReaderFork(std::shared_ptr<Buffer> buffer, Buffer::CursorId parentReadCursor, Buffer::CursorId parentPeekCursor, - SourceContextCallback sourceId, size_t offs, - bool coherent) + SourceId sourceId, size_t offs, bool coherent) : CharReader(buffer, sourceId, offs), parentReadCursor(parentReadCursor), parentPeekCursor(parentPeekCursor) |