mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-08 19:40:06 +00:00
GLSL: Fix #396: Error when 'defined' comes from macro expansion.
This commit is contained in:
parent
65755667d5
commit
2eb135506a
@ -90,8 +90,10 @@ ERROR: 12:9504: '#if' : unexpected tokens following directive
|
||||
ERROR: 12:9506: '#error' : \ 377
|
||||
ERROR: 12:9507: '#error' : \ 376
|
||||
ERROR: 12:9508: '#error' : \ 377
|
||||
ERROR: 12:9602: 'defined' : cannot use in preprocessor expression when expanded from macros
|
||||
ERROR: 12:9603: '#error' : DEF_DEFINED then
|
||||
ERROR: 12:10002: '' : missing #endif
|
||||
ERROR: 88 compilation errors. No code generated.
|
||||
ERROR: 90 compilation errors. No code generated.
|
||||
|
||||
|
||||
Shader version: 400
|
||||
|
@ -337,6 +337,16 @@ int aoeua = FOOOM;
|
||||
#error \ 376
|
||||
#error \377
|
||||
|
||||
// ERROR for macro expansion to yield 'defined'
|
||||
#line 9600
|
||||
#define DEF_MAC
|
||||
#define DEF_DEFINED defined
|
||||
#if DEF_DEFINED DEF_MAC
|
||||
#error DEF_DEFINED then
|
||||
#else
|
||||
#error DEF_DEFINED else
|
||||
#endif
|
||||
|
||||
#line 10000
|
||||
#if 1
|
||||
#else
|
||||
|
@ -393,6 +393,14 @@ int TPpContext::eval(int token, int precedence, bool shortCircuit, int& res, boo
|
||||
TSourceLoc loc = ppToken->loc; // because we sometimes read the newline before reporting the error
|
||||
if (token == PpAtomIdentifier) {
|
||||
if (strcmp("defined", ppToken->name) == 0) {
|
||||
if (isMacroInput()) {
|
||||
if (parseContext.relaxedErrors())
|
||||
parseContext.ppWarn(ppToken->loc, "nonportable when expanded from macros for preprocessor expression",
|
||||
"defined", "");
|
||||
else
|
||||
parseContext.ppError(ppToken->loc, "cannot use in preprocessor expression when expanded from macros",
|
||||
"defined", "");
|
||||
}
|
||||
bool needclose = 0;
|
||||
token = scanToken(ppToken);
|
||||
if (token == '(') {
|
||||
|
@ -200,6 +200,7 @@ public:
|
||||
virtual void ungetch() = 0;
|
||||
virtual bool peekPasting() { return false; } // true when about to see ##
|
||||
virtual bool endOfReplacementList() { return false; } // true when at the end of a macro replacement list (RHS of #define)
|
||||
virtual bool isMacroInput() { return false; }
|
||||
|
||||
// Will be called when we start reading tokens from this instance
|
||||
virtual void notifyActivated() {}
|
||||
@ -306,6 +307,7 @@ protected:
|
||||
void ungetChar() { inputStack.back()->ungetch(); }
|
||||
bool peekPasting() { return !inputStack.empty() && inputStack.back()->peekPasting(); }
|
||||
bool endOfReplacementList() { return inputStack.empty() || inputStack.back()->endOfReplacementList(); }
|
||||
bool isMacroInput() { return inputStack.size() > 0 && inputStack.back()->isMacroInput(); }
|
||||
|
||||
static const int maxIfNesting = 64;
|
||||
|
||||
@ -329,6 +331,7 @@ protected:
|
||||
virtual void ungetch() override { assert(0); }
|
||||
bool peekPasting() override { return prepaste; }
|
||||
bool endOfReplacementList() override { return mac->body.atEnd(); }
|
||||
bool isMacroInput() override { return true; }
|
||||
|
||||
MacroSymbol *mac;
|
||||
TVector<TokenStream*> args;
|
||||
|
Loading…
Reference in New Issue
Block a user