diff --git a/Test/100Limits.vert b/Test/100Limits.vert index d23b7e89..f046219b 100644 --- a/Test/100Limits.vert +++ b/Test/100Limits.vert @@ -36,7 +36,7 @@ void main() for ( int a = 0; a <= 20; a++) { if (ga==0) a = 4; } // ERROR for (float a = 0.0; a <= 20.0; a += 2.0); for (float a = 0.0; a != 20.0; a -= 2.0) { if (ga==0) ga = 4; } - for (float a = 0.0; a == 20.0; a--) for (float a = 0.0; a == 20.0; a--); // two different 'a's, everything okay + for (float a = 0.0; a == 20.0; a--) for (float a = 0.0; a == 20.0; a--); // two different a, everything okay for (float a = 0.0; a <= 20.0; a += 2.0); for (float a = 0.0; a <= 20.0; a += 2.0); for (float a = 0.0; a > 2.0 * 20.0; a += v3.y); diff --git a/Test/100scope.vert b/Test/100scope.vert index 7e9f82ba..a13b1a04 100644 --- a/Test/100scope.vert +++ b/Test/100scope.vert @@ -18,8 +18,8 @@ float b(int a); // ERROR: redefinition float f; // ERROR: redefinition float tan; // okay, built-in is in an outer scope -float sin(float x); // ERROR: can't redefine built-in functions -float cos(float x) // ERROR: can't redefine built-in functions +float sin(float x); // ERROR: cant redefine built-in functions +float cos(float x) // ERROR: cant redefine built-in functions { return 1.0; } @@ -54,7 +54,7 @@ void main() int z = z; // ERROR: z not previously defined. } { - int x = x; // x is initialized to '1' + int x = x; // x is initialized to 1 } struct S @@ -62,7 +62,7 @@ void main() int x; }; { - S S = S(0); // 'S' is only visible as a struct and constructor - S.x; // 'S' is now visible as a variable + S S = S(0); // S is only visible as a struct and constructor + S.x; // S is now visible as a variable } } diff --git a/Test/baseResults/lineContinuation100.vert.out b/Test/baseResults/lineContinuation100.vert.out index 9e20998c..354f3140 100644 --- a/Test/baseResults/lineContinuation100.vert.out +++ b/Test/baseResults/lineContinuation100.vert.out @@ -8,7 +8,15 @@ ERROR: 0:14: 'line continuation' : not supported for this version or the enabled ERROR: 0:15: 'line continuation' : not supported for this version or the enabled extensions ERROR: 0:18: '#error' : e3 ERROR: 0:24: 'line continuation' : not supported for this version or the enabled extensions -ERROR: 9 compilation errors. No code generated. +ERROR: 0:28: 'line continuation' : not supported for this version or the enabled extensions +ERROR: 0:29: 'non-language character ($) in comment' : not supported for this version or the enabled extensions +ERROR: 0:29: 'non-language character (") in comment' : not supported for this version or the enabled extensions +ERROR: 0:29: 'non-language character (') in comment' : not supported for this version or the enabled extensions +ERROR: 0:31: 'non-language character (@) in comment' : not supported for this version or the enabled extensions +ERROR: 0:32: 'non-language character (@) in comment' : not supported for this version or the enabled extensions +ERROR: 0:32: 'non-language character (@) in comment' : not supported for this version or the enabled extensions +ERROR: 0:33: 'non-language character (@) in comment' : not supported for this version or the enabled extensions +ERROR: 17 compilation errors. No code generated. ERROR: node is still EOpNull! diff --git a/Test/lineContinuation.vert b/Test/lineContinuation.vert index 1115027d..7909bf25 100644 --- a/Test/lineContinuation.vert +++ b/Test/lineContinuation.vert @@ -24,3 +24,7 @@ vec4 foo2(vec4 a) vec4 b = a; \ return b; } + +// aoeuntheo unatehutna \ antaehnathe +// anteonuth $ natohe " ' +// anteonuth natohe diff --git a/Test/lineContinuation100.vert b/Test/lineContinuation100.vert index ec1d862a..74855478 100644 --- a/Test/lineContinuation100.vert +++ b/Test/lineContinuation100.vert @@ -6,7 +6,7 @@ ains no errors other than the #error which are there to see if line numbering fo #error e1 float f\ -oo; // same as 'float foo;' +oo; // same as float foo; #error e2 @@ -24,3 +24,10 @@ vec4 foo2(vec4 a) vec4 b = a; \ return b; } + +// aoeuntheo unatehutna \ antaehnathe +// anteonuth $ natohe " ' +// anteonuth natohe +/*@*/ +/* *@/*/ +//@ diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index a7af49f9..34c1b44b 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -1396,6 +1396,10 @@ void TParseContext::reservedPpErrorCheck(TSourceLoc loc, const char* identifier, // void TParseContext::lineContinuationCheck(TSourceLoc loc) { + if ((profile == EEsProfile && version >= 300) || + (profile != EEsProfile && version >= 420)) + return; + const char* message = "line continuation"; if (messages & EShMsgRelaxedErrors) { warn(loc, "not allowed in this version", message, ""); @@ -1406,6 +1410,28 @@ void TParseContext::lineContinuationCheck(TSourceLoc loc) } } +// +// See if this version/profile allows use the given character in a comment. +// +void TParseContext::commentCharacterCheck(TSourceLoc loc, int ch) +{ + if ((profile == EEsProfile && version >= 300) || + (profile != EEsProfile)) + return; + + TString message("non-language character ("); + if (ch > 32 && ch <= 126) + message.push_back(ch); + message.append(") in comment"); + if (messages & EShMsgRelaxedErrors) { + warn(loc, "not allowed in this version", message.c_str(), ""); + } else { + requireProfile(loc, EEsProfile | ECoreProfile | ECompatibilityProfile, message.c_str()); + profileRequires(loc, EEsProfile, 300, 0, message.c_str()); + profileRequires(loc, ECoreProfile | ECompatibilityProfile, 420, 0, message.c_str()); + } +} + bool TParseContext::builtInName(const TString& identifier) { return identifier.compare(0, 3, "gl_") == 0; diff --git a/glslang/MachineIndependent/ParseHelper.h b/glslang/MachineIndependent/ParseHelper.h index 69044b11..d4c8632b 100644 --- a/glslang/MachineIndependent/ParseHelper.h +++ b/glslang/MachineIndependent/ParseHelper.h @@ -77,6 +77,7 @@ public: bool reservedErrorCheck(TSourceLoc, const TString&); void reservedPpErrorCheck(TSourceLoc, const char* name, const char* op); void lineContinuationCheck(TSourceLoc); + void commentCharacterCheck(TSourceLoc, int ch); bool builtInName(const TString&); void handlePragma(TSourceLoc, const TVector&); diff --git a/glslang/MachineIndependent/preprocessor/PpContext.cpp b/glslang/MachineIndependent/preprocessor/PpContext.cpp index ae7817b6..500797b3 100644 --- a/glslang/MachineIndependent/preprocessor/PpContext.cpp +++ b/glslang/MachineIndependent/preprocessor/PpContext.cpp @@ -93,6 +93,46 @@ TPpContext::TPpContext(TParseContext& pc) : for (elsetracker = 0; elsetracker < maxIfNesting; elsetracker++) elseSeen[elsetracker] = false; elsetracker = 0; + + for (int c = 0; c < 256; ++c) + languageCharacters[c] = false; + for (int c = 'a'; c <= 'z'; ++c) + languageCharacters[c] = true; + for (int c = 'A'; c <= 'Z'; ++c) + languageCharacters[c] = true; + languageCharacters['_'] = true; + for (int c = '0'; c <= '9'; ++c) + languageCharacters[c] = true; + languageCharacters['.'] = true; + languageCharacters['+'] = true; + languageCharacters['-'] = true; + languageCharacters['/'] = true; + languageCharacters['*'] = true; + languageCharacters['%'] = true; + languageCharacters['<'] = true; + languageCharacters['>'] = true; + languageCharacters['['] = true; + languageCharacters[']'] = true; + languageCharacters['('] = true; + languageCharacters[')'] = true; + languageCharacters['{'] = true; + languageCharacters['}'] = true; + languageCharacters['^'] = true; + languageCharacters['|'] = true; + languageCharacters['&'] = true; + languageCharacters['~'] = true; + languageCharacters['='] = true; + languageCharacters['!'] = true; + languageCharacters[':'] = true; + languageCharacters[';'] = true; + languageCharacters[','] = true; + languageCharacters['?'] = true; + languageCharacters['#'] = true; + + // white space + languageCharacters[' '] = true; + for (int c = 9; c <= 13; ++c) + languageCharacters[c] = true; } TPpContext::~TPpContext() diff --git a/glslang/MachineIndependent/preprocessor/PpContext.h b/glslang/MachineIndependent/preprocessor/PpContext.h index cf9ac8a6..82059d1c 100644 --- a/glslang/MachineIndependent/preprocessor/PpContext.h +++ b/glslang/MachineIndependent/preprocessor/PpContext.h @@ -209,6 +209,8 @@ protected: InputSrc *currentInput; bool errorOnVersion; + bool languageCharacters[256]; + // // from Pp.cpp // diff --git a/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/glslang/MachineIndependent/preprocessor/PpScanner.cpp index a61f82e9..a5370526 100644 --- a/glslang/MachineIndependent/preprocessor/PpScanner.cpp +++ b/glslang/MachineIndependent/preprocessor/PpScanner.cpp @@ -647,7 +647,8 @@ int TPpContext::sourceScan(TPpContext* pp, InputSrc*, TPpToken* ppToken) else ch = nextch; } - } + } else if (ch > 0 && ! pp->languageCharacters[ch]) + pp->parseContext.commentCharacterCheck(ppToken->loc, ch); } while (ch != '\n' && ch != EOF); if (ch == EOF) return EOF; @@ -659,11 +660,12 @@ int TPpContext::sourceScan(TPpContext* pp, InputSrc*, TPpToken* ppToken) while (ch != '*') { if (ch == '\n') nlcount++; - if (ch == EOF) { + else if (ch == EOF) { pp->parseContext.error(ppToken->loc, "EOF in comment", "comment", ""); return EOF; - } + } else if (! pp->languageCharacters[ch]) + pp->parseContext.commentCharacterCheck(ppToken->loc, ch); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken); } ch = pp->currentInput->getch(pp, pp->currentInput, ppToken); @@ -671,7 +673,8 @@ int TPpContext::sourceScan(TPpContext* pp, InputSrc*, TPpToken* ppToken) pp->parseContext.error(ppToken->loc, "EOF in comment", "comment", ""); return EOF; - } + } else if (! pp->languageCharacters[ch]) + pp->parseContext.commentCharacterCheck(ppToken->loc, ch); } while (ch != '/'); if (nlcount) return '\n';