TInputScanner(int n, const char* const s[], size_t L[], const char* const* names = nullptr, int b = 0, int f = 0, bool single = false) :
numSources(n),
sources(reinterpret_cast<const unsigned char* const *>(s)), // up to this point, common usage is "char*", but now we need positive 8-bit characters
- lengths(L), currentSource(0), currentChar(0), stringBias(b), finale(f), singleLogical(single)
+ lengths(L), currentSource(0), currentChar(0), stringBias(b), finale(f), singleLogical(single), endOfFileReached(false)
{
loc = new TSourceLoc[numSources];
for (int i = 0; i < numSources; ++i) {
// retrieve the next character and advance one character
int get()
{
- if (currentSource >= numSources)
- return EndOfInput;
-
int ret = peek();
+ if (ret == EndOfInput) return ret;
++loc[currentSource].column;
++logicalSourceLoc.column;
if (ret == '\n') {
// retrieve the next character, no advance
int peek()
{
- if (currentSource >= numSources)
+ if (currentSource >= numSources) {
+ endOfFileReached = true;
return EndOfInput;
+ }
// Make sure we do not read off the end of a string.
// N.B. Sources can have a length of 0.
int sourceToRead = currentSource;
// go back one character
void unget()
{
+ // Do not roll back if we reached the end of the file.
+ if (endOfFileReached) return;
+
if (currentChar > 0) {
--currentChar;
--loc[currentSource].column;
TSourceLoc logicalSourceLoc;
bool singleLogical; // treats the strings as a single logical string.
// locations will be reported from the first string.
+
+ bool endOfFileReached; // set to true once peak() returns EndOfFile.
};
} // end namespace glslang