Front-end: Fix known crashes by early exit on error (issue #29, issue #34, issue #35).

Added -C option to request cascading errors.  By default, will exit early,
to avoid all error-recovery-based crashes.

This works by simulating end-of-file in input on first error, so no
need for exception handling, or stack unwinding, or any complex error
checking/handling to get out of the stack.
This commit is contained in:
John Kessenich 2016-07-09 14:50:57 -06:00
parent 75b0316f6a
commit a86836ede2
11 changed files with 57 additions and 37 deletions

View file

@ -40,7 +40,7 @@
namespace glslang {
// Use a global end-of-input character, so no tranlation is needed across
// Use a global end-of-input character, so no translation is needed across
// layers of encapsulation. Characters are all 8 bit, and positive, so there is
// no aliasing of character 255 onto -1, for example.
const int EndOfInput = -1;
@ -82,7 +82,8 @@ public:
int get()
{
int ret = peek();
if (ret == EndOfInput) return ret;
if (ret == EndOfInput)
return ret;
++loc[currentSource].column;
++logicalSourceLoc.column;
if (ret == '\n') {
@ -123,7 +124,8 @@ public:
void unget()
{
// Do not roll back once we've reached the end of the file.
if (endOfFileReached) return;
if (endOfFileReached)
return;
if (currentChar > 0) {
--currentChar;
@ -196,6 +198,12 @@ public:
loc[getLastValidSourceIndex()].column = col;
}
void setEndOfInput()
{
endOfFileReached = true;
currentSource = numSources;
}
const TSourceLoc& getSourceLoc() const
{
if (singleLogical) {
@ -255,7 +263,7 @@ protected:
bool singleLogical; // treats the strings as a single logical string.
// locations will be reported from the first string.
// set to true once peak() returns EndOfFile, so that we won't roll back
// Set to true once peek() returns EndOfFile, so that we won't roll back
// once we've reached EndOfFile.
bool endOfFileReached;
};