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:9506: '#error' : \ 377
|
||||||
ERROR: 12:9507: '#error' : \ 376
|
ERROR: 12:9507: '#error' : \ 376
|
||||||
ERROR: 12:9508: '#error' : \ 377
|
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: 12:10002: '' : missing #endif
|
||||||
ERROR: 88 compilation errors. No code generated.
|
ERROR: 90 compilation errors. No code generated.
|
||||||
|
|
||||||
|
|
||||||
Shader version: 400
|
Shader version: 400
|
||||||
|
|||||||
@ -337,6 +337,16 @@ int aoeua = FOOOM;
|
|||||||
#error \ 376
|
#error \ 376
|
||||||
#error \377
|
#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
|
#line 10000
|
||||||
#if 1
|
#if 1
|
||||||
#else
|
#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
|
TSourceLoc loc = ppToken->loc; // because we sometimes read the newline before reporting the error
|
||||||
if (token == PpAtomIdentifier) {
|
if (token == PpAtomIdentifier) {
|
||||||
if (strcmp("defined", ppToken->name) == 0) {
|
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;
|
bool needclose = 0;
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
if (token == '(') {
|
if (token == '(') {
|
||||||
|
|||||||
@ -200,6 +200,7 @@ public:
|
|||||||
virtual void ungetch() = 0;
|
virtual void ungetch() = 0;
|
||||||
virtual bool peekPasting() { return false; } // true when about to see ##
|
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 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
|
// Will be called when we start reading tokens from this instance
|
||||||
virtual void notifyActivated() {}
|
virtual void notifyActivated() {}
|
||||||
@ -306,6 +307,7 @@ protected:
|
|||||||
void ungetChar() { inputStack.back()->ungetch(); }
|
void ungetChar() { inputStack.back()->ungetch(); }
|
||||||
bool peekPasting() { return !inputStack.empty() && inputStack.back()->peekPasting(); }
|
bool peekPasting() { return !inputStack.empty() && inputStack.back()->peekPasting(); }
|
||||||
bool endOfReplacementList() { return inputStack.empty() || inputStack.back()->endOfReplacementList(); }
|
bool endOfReplacementList() { return inputStack.empty() || inputStack.back()->endOfReplacementList(); }
|
||||||
|
bool isMacroInput() { return inputStack.size() > 0 && inputStack.back()->isMacroInput(); }
|
||||||
|
|
||||||
static const int maxIfNesting = 64;
|
static const int maxIfNesting = 64;
|
||||||
|
|
||||||
@ -329,6 +331,7 @@ protected:
|
|||||||
virtual void ungetch() override { assert(0); }
|
virtual void ungetch() override { assert(0); }
|
||||||
bool peekPasting() override { return prepaste; }
|
bool peekPasting() override { return prepaste; }
|
||||||
bool endOfReplacementList() override { return mac->body.atEnd(); }
|
bool endOfReplacementList() override { return mac->body.atEnd(); }
|
||||||
|
bool isMacroInput() override { return true; }
|
||||||
|
|
||||||
MacroSymbol *mac;
|
MacroSymbol *mac;
|
||||||
TVector<TokenStream*> args;
|
TVector<TokenStream*> args;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user