PP: Non-functional: Only use string <-> atom mapping when needed.
Also, eliminate the 'atom' field of TPpToken. Parsing a real 300 line shader, through to making the AST, is about 10% faster. Memory is slightly reduced (< 1%). The whole google-test suite, inclusive of all testing overhead, SPIR-V generation, etc., runs 3% faster. Since this is a code *simplification* that leads to perf. improvement, I'm not going to invest too much more in measuring the perf. than this. The PP code is simply now in a better state to see how to further rationalize/improve it.
This commit is contained in:
parent
54af2de761
commit
907aabb6b0
@ -2,5 +2,5 @@
|
|||||||
// For the version, it uses the latest git tag followed by the number of commits.
|
// 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).
|
// For the date, it uses the current date (when then script is run).
|
||||||
|
|
||||||
#define GLSLANG_REVISION "Overload400-PrecQual.1713"
|
#define GLSLANG_REVISION "Overload400-PrecQual.1715"
|
||||||
#define GLSLANG_DATE "20-Dec-2016"
|
#define GLSLANG_DATE "20-Dec-2016"
|
||||||
|
|||||||
@ -93,7 +93,7 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
|||||||
{
|
{
|
||||||
MacroSymbol mac;
|
MacroSymbol mac;
|
||||||
|
|
||||||
// get macro name
|
// get the macro name
|
||||||
int token = scanToken(ppToken);
|
int token = scanToken(ppToken);
|
||||||
if (token != PpAtomIdentifier) {
|
if (token != PpAtomIdentifier) {
|
||||||
parseContext.ppError(ppToken->loc, "must be followed by macro name", "#define", "");
|
parseContext.ppError(ppToken->loc, "must be followed by macro name", "#define", "");
|
||||||
@ -104,8 +104,8 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
|||||||
parseContext.reservedPpErrorCheck(ppToken->loc, ppToken->name, "#define");
|
parseContext.reservedPpErrorCheck(ppToken->loc, ppToken->name, "#define");
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the original macro name
|
// save the macro name
|
||||||
const int defAtom = ppToken->atom;
|
const int defAtom = LookUpAddString(ppToken->name);
|
||||||
|
|
||||||
// gather parameters to the macro, between (...)
|
// gather parameters to the macro, between (...)
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
@ -121,17 +121,19 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
mac.emptyArgs = 0;
|
mac.emptyArgs = 0;
|
||||||
|
const int argAtom = LookUpAddString(ppToken->name);
|
||||||
|
|
||||||
// check for duplication of parameter name
|
// check for duplication of parameter name
|
||||||
bool duplicate = false;
|
bool duplicate = false;
|
||||||
for (size_t a = 0; a < mac.args.size(); ++a) {
|
for (size_t a = 0; a < mac.args.size(); ++a) {
|
||||||
if (mac.args[a] == ppToken->atom) {
|
if (mac.args[a] == argAtom) {
|
||||||
parseContext.ppError(ppToken->loc, "duplicate macro parameter", "#define", "");
|
parseContext.ppError(ppToken->loc, "duplicate macro parameter", "#define", "");
|
||||||
duplicate = true;
|
duplicate = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (! duplicate)
|
if (! duplicate)
|
||||||
mac.args.push_back(ppToken->atom);
|
mac.args.push_back(argAtom);
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
} while (token == ',');
|
} while (token == ',');
|
||||||
if (token != ')') {
|
if (token != ')') {
|
||||||
@ -199,7 +201,7 @@ int TPpContext::CPPundef(TPpToken* ppToken)
|
|||||||
|
|
||||||
parseContext.reservedPpErrorCheck(ppToken->loc, ppToken->name, "#undef");
|
parseContext.reservedPpErrorCheck(ppToken->loc, ppToken->name, "#undef");
|
||||||
|
|
||||||
MacroSymbol* macro = lookupMacroDef(ppToken->atom);
|
MacroSymbol* macro = lookupMacroDef(LookUpString(ppToken->name));
|
||||||
if (macro != nullptr)
|
if (macro != nullptr)
|
||||||
macro->undef = 1;
|
macro->undef = 1;
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
@ -234,13 +236,13 @@ int TPpContext::CPPelse(int matchelse, TPpToken* ppToken)
|
|||||||
if ((token = scanToken(ppToken)) != PpAtomIdentifier)
|
if ((token = scanToken(ppToken)) != PpAtomIdentifier)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int atom = ppToken->atom;
|
int nextAtom = LookUpString(ppToken->name);
|
||||||
if (atom == PpAtomIf || atom == PpAtomIfdef || atom == PpAtomIfndef) {
|
if (nextAtom == PpAtomIf || nextAtom == PpAtomIfdef || nextAtom == PpAtomIfndef) {
|
||||||
depth++;
|
depth++;
|
||||||
ifdepth++;
|
ifdepth++;
|
||||||
elsetracker++;
|
elsetracker++;
|
||||||
} else if (atom == PpAtomEndif) {
|
} else if (nextAtom == PpAtomEndif) {
|
||||||
token = extraTokenCheck(atom, ppToken, scanToken(ppToken));
|
token = extraTokenCheck(nextAtom, ppToken, scanToken(ppToken));
|
||||||
elseSeen[elsetracker] = false;
|
elseSeen[elsetracker] = false;
|
||||||
--elsetracker;
|
--elsetracker;
|
||||||
if (depth == 0) {
|
if (depth == 0) {
|
||||||
@ -252,12 +254,12 @@ int TPpContext::CPPelse(int matchelse, TPpToken* ppToken)
|
|||||||
--depth;
|
--depth;
|
||||||
--ifdepth;
|
--ifdepth;
|
||||||
} else if (matchelse && depth == 0) {
|
} else if (matchelse && depth == 0) {
|
||||||
if (atom == PpAtomElse) {
|
if (nextAtom == PpAtomElse) {
|
||||||
elseSeen[elsetracker] = true;
|
elseSeen[elsetracker] = true;
|
||||||
token = extraTokenCheck(atom, ppToken, scanToken(ppToken));
|
token = extraTokenCheck(nextAtom, ppToken, scanToken(ppToken));
|
||||||
// found the #else we are looking for
|
// found the #else we are looking for
|
||||||
break;
|
break;
|
||||||
} else if (atom == PpAtomElif) {
|
} else if (nextAtom == PpAtomElif) {
|
||||||
if (elseSeen[elsetracker])
|
if (elseSeen[elsetracker])
|
||||||
parseContext.ppError(ppToken->loc, "#elif after #else", "#elif", "");
|
parseContext.ppError(ppToken->loc, "#elif after #else", "#elif", "");
|
||||||
/* we decrement ifdepth here, because CPPif will increment
|
/* we decrement ifdepth here, because CPPif will increment
|
||||||
@ -270,13 +272,13 @@ int TPpContext::CPPelse(int matchelse, TPpToken* ppToken)
|
|||||||
|
|
||||||
return CPPif(ppToken);
|
return CPPif(ppToken);
|
||||||
}
|
}
|
||||||
} else if (atom == PpAtomElse) {
|
} else if (nextAtom == PpAtomElse) {
|
||||||
if (elseSeen[elsetracker])
|
if (elseSeen[elsetracker])
|
||||||
parseContext.ppError(ppToken->loc, "#else after #else", "#else", "");
|
parseContext.ppError(ppToken->loc, "#else after #else", "#else", "");
|
||||||
else
|
else
|
||||||
elseSeen[elsetracker] = true;
|
elseSeen[elsetracker] = true;
|
||||||
token = extraTokenCheck(atom, ppToken, scanToken(ppToken));
|
token = extraTokenCheck(nextAtom, ppToken, scanToken(ppToken));
|
||||||
} else if (atom == PpAtomElif) {
|
} else if (nextAtom == PpAtomElif) {
|
||||||
if (elseSeen[elsetracker])
|
if (elseSeen[elsetracker])
|
||||||
parseContext.ppError(ppToken->loc, "#elif after #else", "#elif", "");
|
parseContext.ppError(ppToken->loc, "#elif after #else", "#elif", "");
|
||||||
}
|
}
|
||||||
@ -286,21 +288,21 @@ int TPpContext::CPPelse(int matchelse, TPpToken* ppToken)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call when there should be no more tokens left on a line.
|
// Call when there should be no more tokens left on a line.
|
||||||
int TPpContext::extraTokenCheck(int atom, TPpToken* ppToken, int token)
|
int TPpContext::extraTokenCheck(int contextAtom, TPpToken* ppToken, int token)
|
||||||
{
|
{
|
||||||
if (token != '\n' && token != EndOfInput) {
|
if (token != '\n' && token != EndOfInput) {
|
||||||
static const char* message = "unexpected tokens following directive";
|
static const char* message = "unexpected tokens following directive";
|
||||||
|
|
||||||
const char* label;
|
const char* label;
|
||||||
if (atom == PpAtomElse)
|
if (contextAtom == PpAtomElse)
|
||||||
label = "#else";
|
label = "#else";
|
||||||
else if (atom == PpAtomElif)
|
else if (contextAtom == PpAtomElif)
|
||||||
label = "#elif";
|
label = "#elif";
|
||||||
else if (atom == PpAtomEndif)
|
else if (contextAtom == PpAtomEndif)
|
||||||
label = "#endif";
|
label = "#endif";
|
||||||
else if (atom == PpAtomIf)
|
else if (contextAtom == PpAtomIf)
|
||||||
label = "#if";
|
label = "#if";
|
||||||
else if (atom == PpAtomLine)
|
else if (contextAtom == PpAtomLine)
|
||||||
label = "#line";
|
label = "#line";
|
||||||
else
|
else
|
||||||
label = "";
|
label = "";
|
||||||
@ -388,7 +390,7 @@ 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 (ppToken->atom == PpAtomDefined) {
|
if (strcmp("defined", ppToken->name) == 0) {
|
||||||
bool needclose = 0;
|
bool needclose = 0;
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
if (token == '(') {
|
if (token == '(') {
|
||||||
@ -403,7 +405,7 @@ int TPpContext::eval(int token, int precedence, bool shortCircuit, int& res, boo
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
MacroSymbol* macro = lookupMacroDef(ppToken->atom);
|
MacroSymbol* macro = lookupMacroDef(LookUpString(ppToken->name));
|
||||||
res = macro != nullptr ? !macro->undef : 0;
|
res = macro != nullptr ? !macro->undef : 0;
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
if (needclose) {
|
if (needclose) {
|
||||||
@ -496,7 +498,7 @@ int TPpContext::eval(int token, int precedence, bool shortCircuit, int& res, boo
|
|||||||
// Expand macros, skipping empty expansions, to get to the first real token in those expansions.
|
// Expand macros, skipping empty expansions, to get to the first real token in those expansions.
|
||||||
int TPpContext::evalToToken(int token, bool shortCircuit, int& res, bool& err, TPpToken* ppToken)
|
int TPpContext::evalToToken(int token, bool shortCircuit, int& res, bool& err, TPpToken* ppToken)
|
||||||
{
|
{
|
||||||
while (token == PpAtomIdentifier && ppToken->atom != PpAtomDefined) {
|
while (token == PpAtomIdentifier && strcmp("defined", ppToken->name) != 0) {
|
||||||
int macroReturn = MacroExpand(ppToken, true, false);
|
int macroReturn = MacroExpand(ppToken, true, false);
|
||||||
if (macroReturn == 0) {
|
if (macroReturn == 0) {
|
||||||
parseContext.ppError(ppToken->loc, "can't evaluate expression", "preprocessor evaluation", "");
|
parseContext.ppError(ppToken->loc, "can't evaluate expression", "preprocessor evaluation", "");
|
||||||
@ -555,7 +557,7 @@ int TPpContext::CPPifdef(int defined, TPpToken* ppToken)
|
|||||||
else
|
else
|
||||||
parseContext.ppError(ppToken->loc, "must be followed by macro name", "#ifndef", "");
|
parseContext.ppError(ppToken->loc, "must be followed by macro name", "#ifndef", "");
|
||||||
} else {
|
} else {
|
||||||
MacroSymbol* macro = lookupMacroDef(ppToken->atom);
|
MacroSymbol* macro = lookupMacroDef(LookUpString(ppToken->name));
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
if (token != '\n') {
|
if (token != '\n') {
|
||||||
parseContext.ppError(ppToken->loc, "unexpected tokens following #ifdef directive - expected a newline", "#ifdef", "");
|
parseContext.ppError(ppToken->loc, "unexpected tokens following #ifdef directive - expected a newline", "#ifdef", "");
|
||||||
@ -765,9 +767,10 @@ int TPpContext::CPPversion(TPpToken* ppToken)
|
|||||||
parseContext.notifyVersion(line, versionNumber, nullptr);
|
parseContext.notifyVersion(line, versionNumber, nullptr);
|
||||||
return token;
|
return token;
|
||||||
} else {
|
} else {
|
||||||
if (ppToken->atom != PpAtomCore &&
|
int profileAtom = LookUpString(ppToken->name);
|
||||||
ppToken->atom != PpAtomCompatibility &&
|
if (profileAtom != PpAtomCore &&
|
||||||
ppToken->atom != PpAtomEs)
|
profileAtom != PpAtomCompatibility &&
|
||||||
|
profileAtom != PpAtomEs)
|
||||||
parseContext.ppError(ppToken->loc, "bad profile name; use es, core, or compatibility", "#version", "");
|
parseContext.ppError(ppToken->loc, "bad profile name; use es, core, or compatibility", "#version", "");
|
||||||
parseContext.notifyVersion(line, versionNumber, ppToken->name);
|
parseContext.notifyVersion(line, versionNumber, ppToken->name);
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
@ -828,7 +831,7 @@ int TPpContext::readCPPline(TPpToken* ppToken)
|
|||||||
int token = scanToken(ppToken);
|
int token = scanToken(ppToken);
|
||||||
|
|
||||||
if (token == PpAtomIdentifier) {
|
if (token == PpAtomIdentifier) {
|
||||||
switch (ppToken->atom) {
|
switch (LookUpString(ppToken->name)) {
|
||||||
case PpAtomDefine:
|
case PpAtomDefine:
|
||||||
token = CPPdefine(ppToken);
|
token = CPPdefine(ppToken);
|
||||||
break;
|
break;
|
||||||
@ -913,17 +916,21 @@ int TPpContext::readCPPline(TPpToken* ppToken)
|
|||||||
// Returns nullptr if no expanded argument is created.
|
// Returns nullptr if no expanded argument is created.
|
||||||
TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream& arg, TPpToken* ppToken, bool newLineOkay)
|
TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream& arg, TPpToken* ppToken, bool newLineOkay)
|
||||||
{
|
{
|
||||||
|
// pre-check, to see if anything in the argument needs to be expanded,
|
||||||
|
// to see if we can kick out early
|
||||||
int token;
|
int token;
|
||||||
RewindTokenStream(arg);
|
RewindTokenStream(arg);
|
||||||
do {
|
do {
|
||||||
token = ReadToken(arg, ppToken);
|
token = ReadToken(arg, ppToken);
|
||||||
if (token == PpAtomIdentifier && lookupMacroDef(ppToken->atom) != nullptr)
|
if (token == PpAtomIdentifier && lookupMacroDef(LookUpString(ppToken->name)) != nullptr)
|
||||||
break;
|
break;
|
||||||
} while (token != EndOfInput);
|
} while (token != EndOfInput);
|
||||||
|
|
||||||
|
// if nothing needs to be expanded, kick out early
|
||||||
if (token == EndOfInput)
|
if (token == EndOfInput)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
// expand the argument
|
||||||
TokenStream* expandedArg = new TokenStream;
|
TokenStream* expandedArg = new TokenStream;
|
||||||
pushInput(new tMarkerInput(this));
|
pushInput(new tMarkerInput(this));
|
||||||
pushTokenStreamInput(arg);
|
pushTokenStreamInput(arg);
|
||||||
@ -985,7 +992,7 @@ int TPpContext::tMacroInput::scan(TPpToken* ppToken)
|
|||||||
if (token == PpAtomIdentifier) {
|
if (token == PpAtomIdentifier) {
|
||||||
int i;
|
int i;
|
||||||
for (i = mac->args.size() - 1; i >= 0; i--)
|
for (i = mac->args.size() - 1; i >= 0; i--)
|
||||||
if (mac->args[i] == ppToken->atom)
|
if (strcmp(pp->GetAtomString(mac->args[i]), ppToken->name) == 0)
|
||||||
break;
|
break;
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
TokenStream* arg = expandedArgs[i];
|
TokenStream* arg = expandedArgs[i];
|
||||||
@ -1053,7 +1060,8 @@ int TPpContext::tZeroInput::scan(TPpToken* ppToken)
|
|||||||
int TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOkay)
|
int TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOkay)
|
||||||
{
|
{
|
||||||
ppToken->space = false;
|
ppToken->space = false;
|
||||||
switch (ppToken->atom) {
|
int macroAtom = LookUpString(ppToken->name);
|
||||||
|
switch (macroAtom) {
|
||||||
case PpAtomLineMacro:
|
case PpAtomLineMacro:
|
||||||
ppToken->ival = parseContext.getCurrentLoc().line;
|
ppToken->ival = parseContext.getCurrentLoc().line;
|
||||||
snprintf(ppToken->name, sizeof(ppToken->name), "%d", ppToken->ival);
|
snprintf(ppToken->name, sizeof(ppToken->name), "%d", ppToken->ival);
|
||||||
@ -1079,7 +1087,7 @@ int TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOka
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
MacroSymbol* macro = lookupMacroDef(ppToken->atom);
|
MacroSymbol* macro = macroAtom == 0 ? nullptr : lookupMacroDef(macroAtom);
|
||||||
int token;
|
int token;
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
|
|
||||||
@ -1101,7 +1109,6 @@ int TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOka
|
|||||||
|
|
||||||
TSourceLoc loc = ppToken->loc; // in case we go to the next line before discovering the error
|
TSourceLoc loc = ppToken->loc; // in case we go to the next line before discovering the error
|
||||||
in->mac = macro;
|
in->mac = macro;
|
||||||
int atom = ppToken->atom;
|
|
||||||
if (macro->args.size() > 0 || macro->emptyArgs) {
|
if (macro->args.size() > 0 || macro->emptyArgs) {
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
if (newLineOkay) {
|
if (newLineOkay) {
|
||||||
@ -1109,10 +1116,8 @@ int TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOka
|
|||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
}
|
}
|
||||||
if (token != '(') {
|
if (token != '(') {
|
||||||
parseContext.ppError(loc, "expected '(' following", "macro expansion", GetAtomString(atom));
|
parseContext.ppError(loc, "expected '(' following", "macro expansion", GetAtomString(macroAtom));
|
||||||
UngetToken(token, ppToken);
|
UngetToken(token, ppToken);
|
||||||
ppToken->atom = atom;
|
|
||||||
|
|
||||||
delete in;
|
delete in;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1129,20 +1134,20 @@ int TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOka
|
|||||||
while (1) {
|
while (1) {
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
if (token == EndOfInput) {
|
if (token == EndOfInput) {
|
||||||
parseContext.ppError(loc, "End of input in macro", "macro expansion", GetAtomString(atom));
|
parseContext.ppError(loc, "End of input in macro", "macro expansion", GetAtomString(macroAtom));
|
||||||
delete in;
|
delete in;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (token == '\n') {
|
if (token == '\n') {
|
||||||
if (! newLineOkay) {
|
if (! newLineOkay) {
|
||||||
parseContext.ppError(loc, "End of line in macro substitution:", "macro expansion", GetAtomString(atom));
|
parseContext.ppError(loc, "End of line in macro substitution:", "macro expansion", GetAtomString(macroAtom));
|
||||||
delete in;
|
delete in;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (token == '#') {
|
if (token == '#') {
|
||||||
parseContext.ppError(ppToken->loc, "unexpected '#'", "macro expansion", GetAtomString(atom));
|
parseContext.ppError(ppToken->loc, "unexpected '#'", "macro expansion", GetAtomString(macroAtom));
|
||||||
delete in;
|
delete in;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1167,7 +1172,7 @@ int TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOka
|
|||||||
} while (arg < in->mac->args.size());
|
} while (arg < in->mac->args.size());
|
||||||
|
|
||||||
if (arg < in->mac->args.size())
|
if (arg < in->mac->args.size())
|
||||||
parseContext.ppError(loc, "Too few args in Macro", "macro expansion", GetAtomString(atom));
|
parseContext.ppError(loc, "Too few args in Macro", "macro expansion", GetAtomString(macroAtom));
|
||||||
else if (token != ')') {
|
else if (token != ')') {
|
||||||
depth=0;
|
depth=0;
|
||||||
while (token != EndOfInput && (depth > 0 || token != ')')) {
|
while (token != EndOfInput && (depth > 0 || token != ')')) {
|
||||||
@ -1179,11 +1184,11 @@ int TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOka
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (token == EndOfInput) {
|
if (token == EndOfInput) {
|
||||||
parseContext.ppError(loc, "End of input in macro", "macro expansion", GetAtomString(atom));
|
parseContext.ppError(loc, "End of input in macro", "macro expansion", GetAtomString(macroAtom));
|
||||||
delete in;
|
delete in;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
parseContext.ppError(loc, "Too many args in macro", "macro expansion", GetAtomString(atom));
|
parseContext.ppError(loc, "Too many args in macro", "macro expansion", GetAtomString(macroAtom));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need both expanded and non-expanded forms of the argument, for whether or
|
// We need both expanded and non-expanded forms of the argument, for whether or
|
||||||
|
|||||||
@ -120,7 +120,6 @@ const struct {
|
|||||||
{ PpAtomIncrement, "++" },
|
{ PpAtomIncrement, "++" },
|
||||||
|
|
||||||
{ PpAtomDefine, "define" },
|
{ PpAtomDefine, "define" },
|
||||||
{ PpAtomDefined, "defined" },
|
|
||||||
{ PpAtomUndef, "undef" },
|
{ PpAtomUndef, "undef" },
|
||||||
{ PpAtomIf, "if" },
|
{ PpAtomIf, "if" },
|
||||||
{ PpAtomElif, "elif" },
|
{ PpAtomElif, "elif" },
|
||||||
@ -149,17 +148,29 @@ const struct {
|
|||||||
|
|
||||||
namespace glslang {
|
namespace glslang {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Map an existing string to an atom.
|
||||||
|
//
|
||||||
|
// Return 0 if no existing string.
|
||||||
|
//
|
||||||
|
int TPpContext::LookUpString(const char* s)
|
||||||
|
{
|
||||||
|
auto it = atomMap.find(s);
|
||||||
|
return it == atomMap.end() ? 0 : it->second;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Map a new or existing string to an atom, inventing a new atom if necessary.
|
// Map a new or existing string to an atom, inventing a new atom if necessary.
|
||||||
//
|
//
|
||||||
int TPpContext::LookUpAddString(const char* s)
|
int TPpContext::LookUpAddString(const char* s)
|
||||||
{
|
{
|
||||||
auto it = atomMap.find(s);
|
int atom = LookUpString(s);
|
||||||
if (it == atomMap.end()) {
|
if (atom == 0) {
|
||||||
AddAtomFixed(s, nextAtom);
|
atom = nextAtom++;
|
||||||
return nextAtom++;
|
AddAtomFixed(s, atom);
|
||||||
} else
|
}
|
||||||
return it->second;
|
|
||||||
|
return atom;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@ -92,7 +92,7 @@ namespace glslang {
|
|||||||
|
|
||||||
class TPpToken {
|
class TPpToken {
|
||||||
public:
|
public:
|
||||||
TPpToken() : space(false), ival(0), dval(0.0), i64val(0), atom(0)
|
TPpToken() : space(false), ival(0), dval(0.0), i64val(0)
|
||||||
{
|
{
|
||||||
loc.init();
|
loc.init();
|
||||||
name[0] = 0;
|
name[0] = 0;
|
||||||
@ -112,7 +112,6 @@ public:
|
|||||||
int ival;
|
int ival;
|
||||||
double dval;
|
double dval;
|
||||||
long long i64val;
|
long long i64val;
|
||||||
int atom;
|
|
||||||
char name[MaxTokenLength + 1];
|
char name[MaxTokenLength + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -551,6 +550,7 @@ protected:
|
|||||||
int nextAtom;
|
int nextAtom;
|
||||||
void InitAtomTable();
|
void InitAtomTable();
|
||||||
void AddAtomFixed(const char* s, int atom);
|
void AddAtomFixed(const char* s, int atom);
|
||||||
|
int LookUpString(const char* s);
|
||||||
int LookUpAddString(const char* s);
|
int LookUpAddString(const char* s);
|
||||||
const char* GetAtomString(int atom);
|
const char* GetAtomString(int atom);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -247,7 +247,6 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
|
|||||||
//
|
//
|
||||||
int TPpContext::tStringInput::scan(TPpToken* ppToken)
|
int TPpContext::tStringInput::scan(TPpToken* ppToken)
|
||||||
{
|
{
|
||||||
char* tokenText = ppToken->name;
|
|
||||||
int AlreadyComplained = 0;
|
int AlreadyComplained = 0;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
int ch = 0;
|
int ch = 0;
|
||||||
@ -286,7 +285,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
|
|||||||
case 'z':
|
case 'z':
|
||||||
do {
|
do {
|
||||||
if (len < MaxTokenLength) {
|
if (len < MaxTokenLength) {
|
||||||
tokenText[len++] = (char)ch;
|
ppToken->name[len++] = (char)ch;
|
||||||
ch = getch();
|
ch = getch();
|
||||||
} else {
|
} else {
|
||||||
if (! AlreadyComplained) {
|
if (! AlreadyComplained) {
|
||||||
@ -304,9 +303,8 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
|
|||||||
if (len == 0)
|
if (len == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
tokenText[len] = '\0';
|
ppToken->name[len] = '\0';
|
||||||
ungetch();
|
ungetch();
|
||||||
ppToken->atom = pp->LookUpAddString(tokenText);
|
|
||||||
return PpAtomIdentifier;
|
return PpAtomIdentifier;
|
||||||
case '0':
|
case '0':
|
||||||
ppToken->name[len++] = (char)ch;
|
ppToken->name[len++] = (char)ch;
|
||||||
@ -693,13 +691,13 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
|
|||||||
ch = getch();
|
ch = getch();
|
||||||
while (ch != '"' && ch != '\n' && ch != EndOfInput) {
|
while (ch != '"' && ch != '\n' && ch != EndOfInput) {
|
||||||
if (len < MaxTokenLength) {
|
if (len < MaxTokenLength) {
|
||||||
tokenText[len] = (char)ch;
|
ppToken->name[len] = (char)ch;
|
||||||
len++;
|
len++;
|
||||||
ch = getch();
|
ch = getch();
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
tokenText[len] = '\0';
|
ppToken->name[len] = '\0';
|
||||||
if (ch != '"') {
|
if (ch != '"') {
|
||||||
ungetch();
|
ungetch();
|
||||||
pp->parseContext.ppError(ppToken->loc, "End of line in string", "string", "");
|
pp->parseContext.ppError(ppToken->loc, "End of line in string", "string", "");
|
||||||
@ -821,7 +819,6 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken)
|
|||||||
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", "##", "");
|
parseContext.ppError(ppToken.loc, "combined tokens are too long", "##", "");
|
||||||
strncat(ppToken.name, pastedPpToken.name, MaxTokenLength - strlen(ppToken.name));
|
strncat(ppToken.name, pastedPpToken.name, MaxTokenLength - strlen(ppToken.name));
|
||||||
ppToken.atom = LookUpAddString(ppToken.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultToken;
|
return resultToken;
|
||||||
|
|||||||
@ -218,7 +218,6 @@ int TPpContext::ReadToken(TokenStream& pTok, TPpToken *ppToken)
|
|||||||
|
|
||||||
switch (ltoken) {
|
switch (ltoken) {
|
||||||
case PpAtomIdentifier:
|
case PpAtomIdentifier:
|
||||||
ppToken->atom = LookUpAddString(ppToken->name);
|
|
||||||
break;
|
break;
|
||||||
case PpAtomConstString:
|
case PpAtomConstString:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -134,7 +134,6 @@ enum EFixedAtoms {
|
|||||||
// preprocessor "keywords"
|
// preprocessor "keywords"
|
||||||
|
|
||||||
PpAtomDefine,
|
PpAtomDefine,
|
||||||
PpAtomDefined,
|
|
||||||
PpAtomUndef,
|
PpAtomUndef,
|
||||||
|
|
||||||
PpAtomIf,
|
PpAtomIf,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user