Commit 98434bed by John Kessenich

Preprocessor fixes:

- Correctly handle non-directive lines starting with "#" - Correctly ignore unrecognized #pragma - Partial fix for new lines in the middle of macro invocation git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@24266 e7fa87d3-cd2b-0410-9028-fcbf551c1848
parent 3591813a
...@@ -2,8 +2,20 @@ cppComplexExpr.vert ...@@ -2,8 +2,20 @@ cppComplexExpr.vert
ERROR: 0:46: 'xyxwx' : illegal vector field selection ERROR: 0:46: 'xyxwx' : illegal vector field selection
ERROR: 0:46: 'xyxwx' : illegal vector field selection ERROR: 0:46: 'xyxwx' : illegal vector field selection
ERROR: 0:66: '#define' : Macro redefined; different substitutions: BIG ERROR: 0:66: '#define' : Macro redefined; different substitutions: BIG
ERROR: 0:79: '' : missing #endif ERROR: 0:81: 'preprocessor evaluation' : bad expression
ERROR: 4 compilation errors. No code generated. ERROR: 0:81: '#if' : unexpected tokens following directive
ERROR: 0:82: '#error' : good macro
ERROR: 0:89: 'macro expansion' : unexpected '#' foobar
ERROR: 0:90: 'preprocessor evaluation' : bad expression
ERROR: 0:94: 'macro expansion' : unexpected '#' foobar
ERROR: 0:95: 'preprocessor evaluation' : bad expression
ERROR: 0:100: 'preprocessor evaluation' : bad expression
ERROR: 0:100: '#if' : unexpected tokens following directive
ERROR: 0:103: 'macro expansion' : unexpected '#' foobar
ERROR: 0:103: 'preprocessor evaluation' : undefined macro in expression
ERROR: 0:103: '#if' : unexpected tokens following directive
ERROR: 0:104: '' : missing #endif
ERROR: 16 compilation errors. No code generated.
ERROR: node is still EOpNull! ERROR: node is still EOpNull!
...@@ -66,8 +78,14 @@ ERROR: node is still EOpNull! ...@@ -66,8 +78,14 @@ ERROR: node is still EOpNull!
0:47 1 (const int) 0:47 1 (const int)
0:47 Constant: 0:47 Constant:
0:47 3.000000 0:47 3.000000
0:97 Sequence
0:97 move second child to first child (highp float)
0:97 'c' (highp float)
0:98 Constant:
0:98 3.300000
0:? Linker Objects 0:? Linker Objects
0:? 'sum' (highp float) 0:? 'sum' (highp float)
0:? 'c' (highp float)
0:? 'gl_VertexID' (gl_VertexId highp int) 0:? 'gl_VertexID' (gl_VertexId highp int)
0:? 'gl_InstanceID' (gl_InstanceId highp int) 0:? 'gl_InstanceID' (gl_InstanceId highp int)
......
...@@ -6,15 +6,15 @@ ERROR: 0:85: '#error' : good3 ...@@ -6,15 +6,15 @@ ERROR: 0:85: '#error' : good3
ERROR: 0:89: '#error' : good4 ERROR: 0:89: '#error' : good4
ERROR: 0:93: '#error' : good5 ERROR: 0:93: '#error' : good5
ERROR: 0:97: '#error' : good6 ERROR: 0:97: '#error' : good6
ERROR: 0:101: 'preprocessor' : expected ')' ERROR: 0:101: 'preprocessor evaluation' : expected ')'
ERROR: 0:101: '#error' : bad1 ERROR: 0:101: '#error' : bad1
ERROR: 0:104: '#if' : unexpected tokens following directive ERROR: 0:104: '#if' : unexpected tokens following directive
ERROR: 0:105: '#error' : bad2 ERROR: 0:105: '#error' : bad2
ERROR: 0:109: 'preprocessor' : expected ')' ERROR: 0:109: 'preprocessor evaluation' : expected ')'
ERROR: 0:109: '#error' : bad3 ERROR: 0:109: '#error' : bad3
ERROR: 0:112: '#if' : unexpected tokens following directive ERROR: 0:112: '#if' : unexpected tokens following directive
ERROR: 0:113: '#error' : bad4 ERROR: 0:113: '#error' : bad4
ERROR: 0:117: 'preprocessor' : expected ')' ERROR: 0:117: 'preprocessor evaluation' : expected ')'
ERROR: 0:117: '#error' : bad5 ERROR: 0:117: '#error' : bad5
ERROR: 0:120: '#if' : unexpected tokens following directive ERROR: 0:120: '#if' : unexpected tokens following directive
ERROR: 0:121: '#error' : bad6 ERROR: 0:121: '#error' : bad6
...@@ -44,8 +44,25 @@ ERROR: 0:192: '#define' : Macro redefined; different substitutions: m8 ...@@ -44,8 +44,25 @@ ERROR: 0:192: '#define' : Macro redefined; different substitutions: m8
ERROR: 0:196: '#define' : Macro redefined; different argument names: m9 ERROR: 0:196: '#define' : Macro redefined; different argument names: m9
ERROR: 0:204: '#undef' : can't use with built-in names (containing consecutive underscores) ERROR: 0:204: '#undef' : can't use with built-in names (containing consecutive underscores)
ERROR: 0:205: '#undef' : can't use with built-in names ("GL_" prefix) ERROR: 0:205: '#undef' : can't use with built-in names ("GL_" prefix)
ERROR: 0:209: '' : missing #endif ERROR: 0:210: '#' : invalid directive
ERROR: 45 compilation errors. No code generated. ERROR: 0:211: '#' : invalid directive
ERROR: 0:212: '#' : invalid directive
ERROR: 0:213: '#' : invalid directive
ERROR: 0:214: '#' : invalid directive
ERROR: 0:215: '#' : invalid directive
ERROR: 0:224: '#pragma' : optimize pragma syntax is incorrect
ERROR: 0:225: '#pragma' : optimize pragma syntax is incorrect
ERROR: 0:226: '#pragma' : debug pragma syntax is incorrect
ERROR: 0:227: '#pragma' : debug pragma syntax is incorrect
ERROR: 0:229: '#pragma' : optimize pragma syntax is incorrect
ERROR: 0:230: '#pragma' : debug pragma syntax is incorrect
ERROR: 0:233: 'line continuation' : not supported for this version or the enabled extensions
ERROR: 0:235: 'line continuation' : not supported for this version or the enabled extensions
ERROR: 0:236: '#error' : good continuation
ERROR: 0:238: '#' : invalid directive: flizbit
ERROR: 0:242: '#' : invalid directive: directive
ERROR: 0:246: '' : missing #endif
ERROR: 62 compilation errors. No code generated.
ERROR: node is still EOpNull! ERROR: node is still EOpNull!
......
...@@ -75,5 +75,30 @@ float foo() ...@@ -75,5 +75,30 @@ float foo()
#define BIGARGS3(aonthanotehu, bonthanotehu, conthanotehu, donthanotehu, eonthanotehu, fonthanotehu, gonthanotehu, honthanotehu, ionthanotehu, jonthanotehu, konthanotehu) jonthanotehu #define BIGARGS3(aonthanotehu, bonthanotehu, conthanotehu, donthanotehu, eonthanotehu, fonthanotehu, gonthanotehu, honthanotehu, ionthanotehu, jonthanotehu, konthanotehu) jonthanotehu
#define BIGARGS4(aonthanotehu, bonthanotehu, conthanotehu, donthanotehu, eonthanotehu, fonthanotehu, gonthanotehu, honthanotehu, ionthanotehu, jonthanotehu, konthanotehu) jonthanotehu #define BIGARGS4(aonthanotehu, bonthanotehu, conthanotehu, donthanotehu, eonthanotehu, fonthanotehu, gonthanotehu, honthanotehu, ionthanotehu, jonthanotehu, konthanotehu) jonthanotehu
#define foobar(a, b) a + b
#if foobar(1.1, 2.2)
#error good macro
#else
#error bad macro
#endif
#if foobar(1
;
#
#
#endif
#if foobar(1,
;
#
#
#endif
float c = foobar(1.1, 2.2
);
#if foobar(1.1, 2.2
)
#if foobar(1.1, 2.2
#if 0 #if 0
// ERROR, EOF // ERROR, EOF
\ No newline at end of file
...@@ -70,8 +70,8 @@ sum += 0.05; ...@@ -70,8 +70,8 @@ sum += 0.05;
} }
#define A 0 #define A 0
#define B 0 # define B 0
#define C 0 # define C 0
#if (A == B) || (A == C) #if (A == B) || (A == C)
#error good1 #error good1
...@@ -204,6 +204,43 @@ double f = f1; ...@@ -204,6 +204,43 @@ double f = f1;
#undef __VERSION__ #undef __VERSION__
#undef GL_ARB_texture_rectangle #undef GL_ARB_texture_rectangle
#
#
#
##
# #
# 0x25
####
####ff
#########ff fg 0x25
#pragma
#pragma(aoent)
# pragma
#pragma STDGL
#pragma optimize( on)
#pragma optimize(off)
#pragma debug( on)
#pragma debug(off )
#pragma optimize( on) anoteun
#pragma optimize(off
#pragma debug( on) (
#pragma debug(off aoeua)
#pragma optimize( on)
#pragma optimize(off,)
#pragma debug( on, aoeu)
#pragma debugoff )
#pragma aontheu natoeh uantheo uasotea noeahuonea uonethau onethuanoeth aunotehau noeth anthoeua anoethuantoeh uantoehu natoehu naoteh unotaehu noethua onetuh aou
# \
# \
error good continuation
#flizbit
#define directive error
#directive directive was expanded
#if 1 #if 1
#else #else
// ERROR, missing #endif // ERROR, missing #endif
\ No newline at end of file
...@@ -147,87 +147,59 @@ void TParseContext::parserError(const char *s) ...@@ -147,87 +147,59 @@ void TParseContext::parserError(const char *s)
error(getCurrentLoc(), "", "", s, ""); error(getCurrentLoc(), "", "", s, "");
} }
void TParseContext::handlePragma(const char **tokens, int numTokens) void TParseContext::handlePragma(TSourceLoc loc, const TVector<TString>& tokens)
{ {
if (!strcmp(tokens[0], "optimize")) { if (tokens.size() == 0)
if (numTokens != 4) { return;
error(getCurrentLoc(), "optimize pragma syntax is incorrect", "#pragma", "");
if (tokens[0].compare("optimize") == 0) {
if (tokens.size() != 4) {
error(loc, "optimize pragma syntax is incorrect", "#pragma", "");
return; return;
} }
if (strcmp(tokens[1], "(")) { if (tokens[1].compare("(") != 0) {
error(getCurrentLoc(), "\"(\" expected after 'optimize' keyword", "#pragma", ""); error(loc, "\"(\" expected after 'optimize' keyword", "#pragma", "");
return; return;
} }
if (!strcmp(tokens[2], "on")) if (tokens[2].compare("on") == 0)
contextPragma.optimize = true; contextPragma.optimize = true;
else if (!strcmp(tokens[2], "off")) else if (tokens[2].compare("off") == 0)
contextPragma.optimize = false; contextPragma.optimize = false;
else { else {
error(getCurrentLoc(), "\"on\" or \"off\" expected after '(' for 'optimize' pragma", "#pragma", ""); error(loc, "\"on\" or \"off\" expected after '(' for 'optimize' pragma", "#pragma", "");
return; return;
} }
if (strcmp(tokens[3], ")")) { if (tokens[3].compare(")") != 0) {
error(getCurrentLoc(), "\")\" expected to end 'optimize' pragma", "#pragma", ""); error(loc, "\")\" expected to end 'optimize' pragma", "#pragma", "");
return; return;
} }
} else if (!strcmp(tokens[0], "debug")) { } else if (tokens[0].compare("debug") == 0) {
if (numTokens != 4) { if (tokens.size() != 4) {
error(getCurrentLoc(), "debug pragma syntax is incorrect", "#pragma", ""); error(loc, "debug pragma syntax is incorrect", "#pragma", "");
return; return;
} }
if (strcmp(tokens[1], "(")) { if (tokens[1].compare("(") != 0) {
error(getCurrentLoc(), "\"(\" expected after 'debug' keyword", "#pragma", ""); error(loc, "\"(\" expected after 'debug' keyword", "#pragma", "");
return; return;
} }
if (!strcmp(tokens[2], "on")) if (tokens[2].compare("on") == 0)
contextPragma.debug = true; contextPragma.debug = true;
else if (!strcmp(tokens[2], "off")) else if (tokens[2].compare("off") == 0)
contextPragma.debug = false; contextPragma.debug = false;
else { else {
error(getCurrentLoc(), "\"on\" or \"off\" expected after '(' for 'debug' pragma", "#pragma", ""); error(loc, "\"on\" or \"off\" expected after '(' for 'debug' pragma", "#pragma", "");
return; return;
} }
if (strcmp(tokens[3], ")")) { if (tokens[3].compare(")") != 0) {
error(getCurrentLoc(), "\")\" expected to end 'debug' pragma", "#pragma", ""); error(loc, "\")\" expected to end 'debug' pragma", "#pragma", "");
return; return;
} }
} else {
#ifdef PRAGMA_TABLE
//
// implementation specific pragma
// use parseContext.contextPragma.pragmaTable to store the information about pragma
// For now, just ignore the pragma that the implementation cannot recognize
// An Example of one such implementation for a pragma that has a syntax like
// #pragma pragmaname(pragmavalue)
// This implementation stores the current pragmavalue against the pragma name in pragmaTable.
//
if (numTokens == 4 && !strcmp(tokens[1], "(") && !strcmp(tokens[3], ")")) {
TPragmaTable& pragmaTable = parseContext.contextPragma.pragmaTable;
TPragmaTable::iterator iter;
iter = pragmaTable.find(TString(tokens[0]));
if (iter != pragmaTable.end()) {
iter->second = tokens[2];
} else {
pragmaTable[tokens[0]] = tokens[2];
}
} else if (numTokens >= 2) {
TPragmaTable& pragmaTable = parseContext.contextPragma.pragmaTable;
TPragmaTable::iterator iter;
iter = pragmaTable.find(TString(tokens[0]));
if (iter != pragmaTable.end()) {
iter->second = tokens[1];
} else {
pragmaTable[tokens[0]] = tokens[1];
}
}
#endif // PRAGMA_TABLE
} }
} }
......
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
void lineContinuationCheck(TSourceLoc); void lineContinuationCheck(TSourceLoc);
bool builtInName(const TString&); bool builtInName(const TString&);
void handlePragma(const char **tokens, int numTokens); void handlePragma(TSourceLoc, const TVector<TString>&);
TIntermTyped* handleVariable(TSourceLoc, TSymbol* symbol, TString* string); TIntermTyped* handleVariable(TSourceLoc, TSymbol* symbol, TString* string);
TIntermTyped* handleBracketDereference(TSourceLoc, TIntermTyped* base, TIntermTyped* index); TIntermTyped* handleBracketDereference(TSourceLoc, TIntermTyped* base, TIntermTyped* index);
void checkIndex(TSourceLoc, const TType&, int& index); void checkIndex(TSourceLoc, const TType&, int& index);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment