diff --git a/Test/baseResults/tokenPaste.vert.out b/Test/baseResults/tokenPaste.vert.out index 59971515..b0f7d10c 100755 --- a/Test/baseResults/tokenPaste.vert.out +++ b/Test/baseResults/tokenPaste.vert.out @@ -3,8 +3,9 @@ Warning, version 450 is not yet complete; most version-specific features are pre ERROR: 0:38: '##' : unexpected location ERROR: 0:40: '##' : unexpected location; end of replacement list ERROR: 0:49: '##' : combined tokens are too long -ERROR: 0:52: '##' : only supported for preprocessing identifiers -ERROR: 4 compilation errors. No code generated. +ERROR: 0:52: '##' : not supported for these tokens +ERROR: 0:69: '##' : combined token is invalid +ERROR: 5 compilation errors. No code generated. Shader version: 450 @@ -14,6 +15,35 @@ ERROR: node is still EOpNull! 0:52 'a' (global int) 0:52 Constant: 0:52 11 (const int) +0:58 Sequence +0:58 move second child to first child (temp int) +0:58 'cop' (global int) +0:58 Constant: +0:58 160 (const int) +0:59 Sequence +0:59 move second child to first child (temp bool) +0:59 'dop' (global bool) +0:59 Constant: +0:59 true (const bool) +0:63 Function Definition: ShouldntExpandToThis( (global void) +0:63 Function Parameters: +0:65 Sequence +0:65 Sequence +0:65 move second child to first child (temp int) +0:65 'e' (temp int) +0:65 Constant: +0:65 16 (const int) +0:66 right shift second child into first child (temp int) +0:66 'e' (temp int) +0:66 Constant: +0:66 2 (const int) +0:69 Sequence +0:69 move second child to first child (temp bool) +0:69 'f' (temp bool) +0:69 Compare Greater Than (temp bool) +0:69 'e' (temp int) +0:69 Constant: +0:69 5 (const int) 0:? Linker Objects 0:? 'SecondExpansion' (global int) 0:? 'PostPasteExpansion' (global int) @@ -25,8 +55,14 @@ ERROR: node is still EOpNull! 0:? 'dc1' (global float) 0:? 'dc2' (global float) 0:? 'foo875' (uniform float) -0:? 'ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123451234' (global float) +0:? 'ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345' (global float) 0:? 'a' (global int) +0:? 'aop' (const int) +0:? 10 (const int) +0:? 'bop' (const int) +0:? 4 (const int) +0:? 'cop' (global int) +0:? 'dop' (global bool) 0:? 'gl_VertexID' (gl_VertexId int VertexId) 0:? 'gl_InstanceID' (gl_InstanceId int InstanceId) @@ -42,6 +78,16 @@ ERROR: node is still EOpNull! 0:52 'a' (global int) 0:52 Constant: 0:52 11 (const int) +0:58 Sequence +0:58 move second child to first child (temp int) +0:58 'cop' (global int) +0:58 Constant: +0:58 160 (const int) +0:59 Sequence +0:59 move second child to first child (temp bool) +0:59 'dop' (global bool) +0:59 Constant: +0:59 true (const bool) 0:? Linker Objects 0:? 'SecondExpansion' (global int) 0:? 'PostPasteExpansion' (global int) @@ -53,8 +99,14 @@ ERROR: node is still EOpNull! 0:? 'dc1' (global float) 0:? 'dc2' (global float) 0:? 'foo875' (uniform float) -0:? 'ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123451234' (global float) +0:? 'ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345' (global float) 0:? 'a' (global int) +0:? 'aop' (const int) +0:? 10 (const int) +0:? 'bop' (const int) +0:? 4 (const int) +0:? 'cop' (global int) +0:? 'dop' (global bool) 0:? 'gl_VertexID' (gl_VertexId int VertexId) 0:? 'gl_InstanceID' (gl_InstanceId int InstanceId) diff --git a/Test/tokenPaste.vert b/Test/tokenPaste.vert index 6d6212cc..c30892f0 100644 --- a/Test/tokenPaste.vert +++ b/Test/tokenPaste.vert @@ -50,3 +50,21 @@ float simplePaste(ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01234567 // non-identifiers int a = simplePaste(11,12); + +// operators +#define MAKE_OP(L, R) L ## R +const int aop = 10; +const int bop = 4; +int cop = aop MAKE_OP(<, <) bop; +bool dop = aop MAKE_OP(!,=) bop; + +#define MAKE_OP3(L, M, R) L ## M ## R + +void foo() +{ + int e = 16; + e MAKE_OP3(>,>,=) 2; + + // recovery from bad op + bool f = e MAKE_OP(>,!) 5; +} diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h index 130b7c52..a58d66b4 100644 --- a/glslang/Include/revision.h +++ b/glslang/Include/revision.h @@ -2,5 +2,5 @@ // For the version, it uses the latest git tag followed by the number of commits. // For the date, it uses the current date (when then script is run). -#define GLSLANG_REVISION "Overload400-PrecQual.1719" +#define GLSLANG_REVISION "Overload400-PrecQual.1720" #define GLSLANG_DATE "21-Dec-2016" diff --git a/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/glslang/MachineIndependent/preprocessor/PpScanner.cpp index b514c669..0bdad712 100644 --- a/glslang/MachineIndependent/preprocessor/PpScanner.cpp +++ b/glslang/MachineIndependent/preprocessor/PpScanner.cpp @@ -813,12 +813,52 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken) // get the token after the ## token = scanToken(&pastedPpToken); + // get the token text + switch (resultToken) { + case PpAtomIdentifier: + // already have the correct text in token.names + break; + case '=': + case '!': + case '-': + case '~': + case '+': + case '*': + case '/': + case '%': + case '<': + case '>': + case '|': + case '^': + case '&': + case PpAtomRight: + case PpAtomLeft: + case PpAtomAnd: + case PpAtomOr: + case PpAtomXor: + strcpy(ppToken.name, GetAtomString(resultToken)); + strcpy(pastedPpToken.name, GetAtomString(token)); + break; + default: + parseContext.ppError(ppToken.loc, "not supported for these tokens", "##", ""); + return resultToken; + } + // combine the tokens - if (resultToken != PpAtomIdentifier) - parseContext.ppError(ppToken.loc, "only supported for preprocessing identifiers", "##", ""); - if (strlen(ppToken.name) + strlen(pastedPpToken.name) > MaxTokenLength) + if (strlen(ppToken.name) + strlen(pastedPpToken.name) > MaxTokenLength) { parseContext.ppError(ppToken.loc, "combined tokens are too long", "##", ""); + return resultToken; + } strncat(ppToken.name, pastedPpToken.name, MaxTokenLength - strlen(ppToken.name)); + + // correct the kind of token we are making, if needed (identifiers stay identifiers) + if (resultToken != PpAtomIdentifier) { + int newToken = LookUpString(ppToken.name); + if (newToken > 0) + resultToken = newToken; + else + parseContext.ppError(ppToken.loc, "combined token is invalid", "##", ""); + } } return resultToken;