Updated glslang.

This commit is contained in:
Бранимир Караџић 2023-03-31 19:02:41 -07:00
parent d87baafbcc
commit 5b5774fbc1
5 changed files with 34 additions and 16 deletions

View File

@ -35,7 +35,7 @@
#define GLSLANG_BUILD_INFO
#define GLSLANG_VERSION_MAJOR 12
#define GLSLANG_VERSION_MINOR 0
#define GLSLANG_VERSION_MINOR 1
#define GLSLANG_VERSION_PATCH 0
#define GLSLANG_VERSION_FLAVOR ""

View File

@ -1126,9 +1126,6 @@ int TPpContext::tMacroInput::scan(TPpToken* ppToken)
pasting = true;
}
// HLSL does expand macros before concatenation
if (pasting && pp->parseContext.isReadingHLSL())
pasting = false;
// TODO: preprocessor: properly handle whitespace (or lack of it) between tokens when expanding
if (token == PpAtomIdentifier) {
@ -1138,9 +1135,12 @@ int TPpContext::tMacroInput::scan(TPpToken* ppToken)
break;
if (i >= 0) {
TokenStream* arg = expandedArgs[i];
if (arg == nullptr || pasting)
bool expanded = !!arg && !pasting;
// HLSL does expand macros before concatenation
if (arg == nullptr || (pasting && !pp->parseContext.isReadingHLSL()) ) {
arg = args[i];
pp->pushTokenStreamInput(*arg, prepaste);
}
pp->pushTokenStreamInput(*arg, prepaste, expanded);
return pp->scanToken(ppToken);
}
@ -1183,6 +1183,9 @@ MacroExpandResult TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, b
{
ppToken->space = false;
int macroAtom = atomStrings.getAtom(ppToken->name);
if (ppToken->fullyExpanded)
return MacroExpandNotStarted;
switch (macroAtom) {
case PpAtomLineMacro:
// Arguments which are macro have been replaced in the first stage.
@ -1214,8 +1217,10 @@ MacroExpandResult TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, b
MacroSymbol* macro = macroAtom == 0 ? nullptr : lookupMacroDef(macroAtom);
// no recursive expansions
if (macro != nullptr && macro->busy)
if (macro != nullptr && macro->busy) {
ppToken->fullyExpanded = true;
return MacroExpandNotStarted;
}
// not expanding undefined macros
if ((macro == nullptr || macro->undef) && ! expandUndef)

View File

@ -102,6 +102,7 @@ public:
i64val = 0;
loc.init();
name[0] = 0;
fullyExpanded = false;
}
// Used for comparing macro definitions, so checks what is relevant for that.
@ -117,6 +118,8 @@ public:
// True if a space (for white space or a removed comment) should also be
// recognized, in front of the token returned:
bool space;
bool fullyExpanded;
// Numeric value of the token:
union {
int ival;
@ -475,16 +478,27 @@ protected:
//
// From PpTokens.cpp
//
void pushTokenStreamInput(TokenStream&, bool pasting = false);
void pushTokenStreamInput(TokenStream&, bool pasting = false, bool expanded = false);
void UngetToken(int token, TPpToken*);
class tTokenInput : public tInput {
public:
tTokenInput(TPpContext* pp, TokenStream* t, bool prepasting) :
tTokenInput(TPpContext* pp, TokenStream* t, bool prepasting, bool expanded) :
tInput(pp),
tokens(t),
lastTokenPastes(prepasting) { }
virtual int scan(TPpToken *ppToken) override { return tokens->getToken(pp->parseContext, ppToken); }
lastTokenPastes(prepasting),
preExpanded(expanded) { }
virtual int scan(TPpToken *ppToken) override {
int token = tokens->getToken(pp->parseContext, ppToken);
ppToken->fullyExpanded = preExpanded;
if (tokens->atEnd() && token == PpAtomIdentifier) {
int macroAtom = pp->atomStrings.getAtom(ppToken->name);
MacroSymbol* macro = macroAtom == 0 ? nullptr : pp->lookupMacroDef(macroAtom);
if (macro && macro->functionLike)
ppToken->fullyExpanded = false;
}
return token;
}
virtual int getch() override { assert(0); return EndOfInput; }
virtual void ungetch() override { assert(0); }
virtual bool peekPasting() override { return tokens->peekTokenizedPasting(lastTokenPastes); }
@ -492,6 +506,7 @@ protected:
protected:
TokenStream* tokens;
bool lastTokenPastes; // true if the last token in the input is to be pasted, rather than consumed as a token
bool preExpanded;
};
class tUngotTokenInput : public tInput {

View File

@ -480,9 +480,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
E_GL_EXT_shader_explicit_arithmetic_types_int16 };
static const int Num_Int16_Extensions = sizeof(Int16_Extensions) / sizeof(Int16_Extensions[0]);
ppToken->ival = 0;
ppToken->i64val = 0;
ppToken->space = false;
ppToken->clear();
ch = getch();
for (;;) {
while (ch == ' ' || ch == '\t') {

View File

@ -195,9 +195,9 @@ bool TPpContext::TokenStream::peekUntokenizedPasting()
return pasting;
}
void TPpContext::pushTokenStreamInput(TokenStream& ts, bool prepasting)
void TPpContext::pushTokenStreamInput(TokenStream& ts, bool prepasting, bool expanded)
{
pushInput(new tTokenInput(this, &ts, prepasting));
pushInput(new tTokenInput(this, &ts, prepasting, expanded));
ts.reset();
}