forked from jasder/antlr
Merge pull request #1690 from mike-lischke/master
Fixed a number of data type + signedness issues in the C++ target
This commit is contained in:
commit
05dad185f3
|
@ -44,15 +44,15 @@ void UnbufferedCharStream::consume() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnbufferedCharStream::sync(size_t want) {
|
void UnbufferedCharStream::sync(size_t want) {
|
||||||
size_t need = (_p + want - 1) - _data.size() + 1; // how many more elements we need?
|
if (_p + want <= _data.size()) // Already enough data loaded?
|
||||||
if (need > 0) {
|
return;
|
||||||
fill(need);
|
|
||||||
}
|
fill(_p + want - _data.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t UnbufferedCharStream::fill(size_t n) {
|
size_t UnbufferedCharStream::fill(size_t n) {
|
||||||
for (size_t i = 0; i < n; i++) {
|
for (size_t i = 0; i < n; i++) {
|
||||||
if (_data.size() > 0 && (size_t)_data.back() == EOF) {
|
if (_data.size() > 0 && _data.back() == (uint32_t)EOF) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,16 +87,24 @@ size_t UnbufferedCharStream::LA(ssize_t i) {
|
||||||
if (i == -1) { // special case
|
if (i == -1) { // special case
|
||||||
return _lastChar;
|
return _lastChar;
|
||||||
}
|
}
|
||||||
sync((size_t)i);
|
|
||||||
|
// We can look back only as many chars as we have buffered.
|
||||||
ssize_t index = (ssize_t)_p + i - 1;
|
ssize_t index = (ssize_t)_p + i - 1;
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
throw IndexOutOfBoundsException();
|
throw IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (i > 0) {
|
||||||
|
sync((size_t)i); // No need to sync if we look back.
|
||||||
|
}
|
||||||
if ((size_t)index >= _data.size()) {
|
if ((size_t)index >= _data.size()) {
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_data[(size_t)index] == (uint32_t)EOF) {
|
||||||
|
return EOF;
|
||||||
|
}
|
||||||
|
|
||||||
return _data[(size_t)index];
|
return _data[(size_t)index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue