PP: Non-functional: Make a proper class out of the atom <-> string mapping.
This commit is contained in:
parent
224b1f733b
commit
f48faec3ee
@ -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.1720"
|
#define GLSLANG_REVISION "Overload400-PrecQual.1721"
|
||||||
#define GLSLANG_DATE "21-Dec-2016"
|
#define GLSLANG_DATE "21-Dec-2016"
|
||||||
|
|||||||
@ -105,7 +105,7 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save the macro name
|
// save the macro name
|
||||||
const int defAtom = LookUpAddString(ppToken->name);
|
const int defAtom = atomStrings.getAddAtom(ppToken->name);
|
||||||
|
|
||||||
// gather parameters to the macro, between (...)
|
// gather parameters to the macro, between (...)
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
@ -121,7 +121,7 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
mac.emptyArgs = 0;
|
mac.emptyArgs = 0;
|
||||||
const int argAtom = LookUpAddString(ppToken->name);
|
const int argAtom = atomStrings.getAddAtom(ppToken->name);
|
||||||
|
|
||||||
// check for duplication of parameter name
|
// check for duplication of parameter name
|
||||||
bool duplicate = false;
|
bool duplicate = false;
|
||||||
@ -162,10 +162,10 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
|||||||
// "Two replacement lists are identical if and only if the preprocessing tokens in both have the same number,
|
// "Two replacement lists are identical if and only if the preprocessing tokens in both have the same number,
|
||||||
// ordering, spelling, and white-space separation, where all white-space separations are considered identical."
|
// ordering, spelling, and white-space separation, where all white-space separations are considered identical."
|
||||||
if (existing->args.size() != mac.args.size() || existing->emptyArgs != mac.emptyArgs)
|
if (existing->args.size() != mac.args.size() || existing->emptyArgs != mac.emptyArgs)
|
||||||
parseContext.ppError(defineLoc, "Macro redefined; different number of arguments:", "#define", GetAtomString(defAtom));
|
parseContext.ppError(defineLoc, "Macro redefined; different number of arguments:", "#define", atomStrings.getString(defAtom));
|
||||||
else {
|
else {
|
||||||
if (existing->args != mac.args)
|
if (existing->args != mac.args)
|
||||||
parseContext.ppError(defineLoc, "Macro redefined; different argument names:", "#define", GetAtomString(defAtom));
|
parseContext.ppError(defineLoc, "Macro redefined; different argument names:", "#define", atomStrings.getString(defAtom));
|
||||||
RewindTokenStream(existing->body);
|
RewindTokenStream(existing->body);
|
||||||
RewindTokenStream(mac.body);
|
RewindTokenStream(mac.body);
|
||||||
int newToken;
|
int newToken;
|
||||||
@ -176,7 +176,7 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
|||||||
oldToken = ReadToken(existing->body, &oldPpToken);
|
oldToken = ReadToken(existing->body, &oldPpToken);
|
||||||
newToken = ReadToken(mac.body, &newPpToken);
|
newToken = ReadToken(mac.body, &newPpToken);
|
||||||
if (oldToken != newToken || oldPpToken != newPpToken) {
|
if (oldToken != newToken || oldPpToken != newPpToken) {
|
||||||
parseContext.ppError(defineLoc, "Macro redefined; different substitutions:", "#define", GetAtomString(defAtom));
|
parseContext.ppError(defineLoc, "Macro redefined; different substitutions:", "#define", atomStrings.getString(defAtom));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (newToken > 0);
|
} while (newToken > 0);
|
||||||
@ -201,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(LookUpString(ppToken->name));
|
MacroSymbol* macro = lookupMacroDef(atomStrings.getAtom(ppToken->name));
|
||||||
if (macro != nullptr)
|
if (macro != nullptr)
|
||||||
macro->undef = 1;
|
macro->undef = 1;
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
@ -236,7 +236,7 @@ int TPpContext::CPPelse(int matchelse, TPpToken* ppToken)
|
|||||||
if ((token = scanToken(ppToken)) != PpAtomIdentifier)
|
if ((token = scanToken(ppToken)) != PpAtomIdentifier)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int nextAtom = LookUpString(ppToken->name);
|
int nextAtom = atomStrings.getAtom(ppToken->name);
|
||||||
if (nextAtom == PpAtomIf || nextAtom == PpAtomIfdef || nextAtom == PpAtomIfndef) {
|
if (nextAtom == PpAtomIf || nextAtom == PpAtomIfdef || nextAtom == PpAtomIfndef) {
|
||||||
depth++;
|
depth++;
|
||||||
ifdepth++;
|
ifdepth++;
|
||||||
@ -405,7 +405,7 @@ int TPpContext::eval(int token, int precedence, bool shortCircuit, int& res, boo
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
MacroSymbol* macro = lookupMacroDef(LookUpString(ppToken->name));
|
MacroSymbol* macro = lookupMacroDef(atomStrings.getAtom(ppToken->name));
|
||||||
res = macro != nullptr ? !macro->undef : 0;
|
res = macro != nullptr ? !macro->undef : 0;
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
if (needclose) {
|
if (needclose) {
|
||||||
@ -557,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(LookUpString(ppToken->name));
|
MacroSymbol* macro = lookupMacroDef(atomStrings.getAtom(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", "");
|
||||||
@ -651,7 +651,7 @@ int TPpContext::CPPline(TPpToken* ppToken)
|
|||||||
// We need to save a copy of the string instead of pointing
|
// We need to save a copy of the string instead of pointing
|
||||||
// to the name field of the token since the name field
|
// to the name field of the token since the name field
|
||||||
// will likely be overwritten by the next token scan.
|
// will likely be overwritten by the next token scan.
|
||||||
sourceName = GetAtomString(LookUpAddString(ppToken->name));
|
sourceName = atomStrings.getString(atomStrings.getAddAtom(ppToken->name));
|
||||||
parseContext.setCurrentSourceName(sourceName);
|
parseContext.setCurrentSourceName(sourceName);
|
||||||
hasFile = true;
|
hasFile = true;
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
@ -690,7 +690,7 @@ int TPpContext::CPPerror(TPpToken* ppToken)
|
|||||||
} else if (token == PpAtomIdentifier || token == PpAtomConstString) {
|
} else if (token == PpAtomIdentifier || token == PpAtomConstString) {
|
||||||
message.append(ppToken->name);
|
message.append(ppToken->name);
|
||||||
} else {
|
} else {
|
||||||
message.append(GetAtomString(token));
|
message.append(atomStrings.getString(token));
|
||||||
}
|
}
|
||||||
message.append(" ");
|
message.append(" ");
|
||||||
token = scanToken(ppToken);
|
token = scanToken(ppToken);
|
||||||
@ -767,7 +767,7 @@ int TPpContext::CPPversion(TPpToken* ppToken)
|
|||||||
parseContext.notifyVersion(line, versionNumber, nullptr);
|
parseContext.notifyVersion(line, versionNumber, nullptr);
|
||||||
return token;
|
return token;
|
||||||
} else {
|
} else {
|
||||||
int profileAtom = LookUpString(ppToken->name);
|
int profileAtom = atomStrings.getAtom(ppToken->name);
|
||||||
if (profileAtom != PpAtomCore &&
|
if (profileAtom != PpAtomCore &&
|
||||||
profileAtom != PpAtomCompatibility &&
|
profileAtom != PpAtomCompatibility &&
|
||||||
profileAtom != PpAtomEs)
|
profileAtom != PpAtomEs)
|
||||||
@ -831,7 +831,7 @@ int TPpContext::readCPPline(TPpToken* ppToken)
|
|||||||
int token = scanToken(ppToken);
|
int token = scanToken(ppToken);
|
||||||
|
|
||||||
if (token == PpAtomIdentifier) {
|
if (token == PpAtomIdentifier) {
|
||||||
switch (LookUpString(ppToken->name)) {
|
switch (atomStrings.getAtom(ppToken->name)) {
|
||||||
case PpAtomDefine:
|
case PpAtomDefine:
|
||||||
token = CPPdefine(ppToken);
|
token = CPPdefine(ppToken);
|
||||||
break;
|
break;
|
||||||
@ -922,7 +922,7 @@ TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream& arg, TPpToken*
|
|||||||
RewindTokenStream(arg);
|
RewindTokenStream(arg);
|
||||||
do {
|
do {
|
||||||
token = ReadToken(arg, ppToken);
|
token = ReadToken(arg, ppToken);
|
||||||
if (token == PpAtomIdentifier && lookupMacroDef(LookUpString(ppToken->name)) != nullptr)
|
if (token == PpAtomIdentifier && lookupMacroDef(atomStrings.getAtom(ppToken->name)) != nullptr)
|
||||||
break;
|
break;
|
||||||
} while (token != EndOfInput);
|
} while (token != EndOfInput);
|
||||||
|
|
||||||
@ -992,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 (strcmp(pp->GetAtomString(mac->args[i]), ppToken->name) == 0)
|
if (strcmp(pp->atomStrings.getString(mac->args[i]), ppToken->name) == 0)
|
||||||
break;
|
break;
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
TokenStream* arg = expandedArgs[i];
|
TokenStream* arg = expandedArgs[i];
|
||||||
@ -1060,7 +1060,7 @@ 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;
|
||||||
int macroAtom = LookUpString(ppToken->name);
|
int macroAtom = atomStrings.getAtom(ppToken->name);
|
||||||
switch (macroAtom) {
|
switch (macroAtom) {
|
||||||
case PpAtomLineMacro:
|
case PpAtomLineMacro:
|
||||||
ppToken->ival = parseContext.getCurrentLoc().line;
|
ppToken->ival = parseContext.getCurrentLoc().line;
|
||||||
@ -1116,7 +1116,7 @@ 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(macroAtom));
|
parseContext.ppError(loc, "expected '(' following", "macro expansion", atomStrings.getString(macroAtom));
|
||||||
UngetToken(token, ppToken);
|
UngetToken(token, ppToken);
|
||||||
delete in;
|
delete in;
|
||||||
return 0;
|
return 0;
|
||||||
@ -1134,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(macroAtom));
|
parseContext.ppError(loc, "End of input in macro", "macro expansion", atomStrings.getString(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(macroAtom));
|
parseContext.ppError(loc, "End of line in macro substitution:", "macro expansion", atomStrings.getString(macroAtom));
|
||||||
delete in;
|
delete in;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (token == '#') {
|
if (token == '#') {
|
||||||
parseContext.ppError(ppToken->loc, "unexpected '#'", "macro expansion", GetAtomString(macroAtom));
|
parseContext.ppError(ppToken->loc, "unexpected '#'", "macro expansion", atomStrings.getString(macroAtom));
|
||||||
delete in;
|
delete in;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1172,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(macroAtom));
|
parseContext.ppError(loc, "Too few args in Macro", "macro expansion", atomStrings.getString(macroAtom));
|
||||||
else if (token != ')') {
|
else if (token != ')') {
|
||||||
depth=0;
|
depth=0;
|
||||||
while (token != EndOfInput && (depth > 0 || token != ')')) {
|
while (token != EndOfInput && (depth > 0 || token != ')')) {
|
||||||
@ -1184,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(macroAtom));
|
parseContext.ppError(loc, "End of input in macro", "macro expansion", atomStrings.getString(macroAtom));
|
||||||
delete in;
|
delete in;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
parseContext.ppError(loc, "Too many args in macro", "macro expansion", GetAtomString(macroAtom));
|
parseContext.ppError(loc, "Too many args in macro", "macro expansion", atomStrings.getString(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
|
||||||
|
|||||||
@ -149,62 +149,13 @@ 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.
|
|
||||||
//
|
|
||||||
int TPpContext::LookUpAddString(const char* s)
|
|
||||||
{
|
|
||||||
int atom = LookUpString(s);
|
|
||||||
if (atom == 0) {
|
|
||||||
atom = nextAtom++;
|
|
||||||
AddAtomFixed(s, atom);
|
|
||||||
}
|
|
||||||
|
|
||||||
return atom;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Lookup up mapping of atom -> string.
|
|
||||||
//
|
|
||||||
const char* TPpContext::GetAtomString(int atom)
|
|
||||||
{
|
|
||||||
if ((size_t)atom >= stringMap.size())
|
|
||||||
return "<bad token>";
|
|
||||||
|
|
||||||
const TString* atomString = stringMap[atom];
|
|
||||||
|
|
||||||
return atomString ? atomString->c_str() : "<bad token>";
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add mappings:
|
|
||||||
// - string -> atom
|
|
||||||
// - atom -> string
|
|
||||||
//
|
|
||||||
void TPpContext::AddAtomFixed(const char* s, int atom)
|
|
||||||
{
|
|
||||||
auto it = atomMap.insert(std::pair<TString, int>(s, atom)).first;
|
|
||||||
if (stringMap.size() < (size_t)atom + 1)
|
|
||||||
stringMap.resize(atom + 100, 0);
|
|
||||||
stringMap[atom] = &it->first;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initialize the atom table.
|
// Initialize the atom table.
|
||||||
//
|
//
|
||||||
void TPpContext::InitAtomTable()
|
TStringAtomMap::TStringAtomMap()
|
||||||
{
|
{
|
||||||
|
badToken.assign("<bad token>");
|
||||||
|
|
||||||
// Add single character tokens to the atom table:
|
// Add single character tokens to the atom table:
|
||||||
const char* s = "~!%^&*()-+=|,.<>/?;:[]{}#\\";
|
const char* s = "~!%^&*()-+=|,.<>/?;:[]{}#\\";
|
||||||
char t[2];
|
char t[2];
|
||||||
@ -212,13 +163,13 @@ void TPpContext::InitAtomTable()
|
|||||||
t[1] = '\0';
|
t[1] = '\0';
|
||||||
while (*s) {
|
while (*s) {
|
||||||
t[0] = *s;
|
t[0] = *s;
|
||||||
AddAtomFixed(t, s[0]);
|
addAtomFixed(t, s[0]);
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add multiple character scanner tokens :
|
// Add multiple character scanner tokens :
|
||||||
for (size_t ii = 0; ii < sizeof(tokens)/sizeof(tokens[0]); ii++)
|
for (size_t ii = 0; ii < sizeof(tokens)/sizeof(tokens[0]); ii++)
|
||||||
AddAtomFixed(tokens[ii].str, tokens[ii].val);
|
addAtomFixed(tokens[ii].str, tokens[ii].val);
|
||||||
|
|
||||||
nextAtom = PpAtomLast;
|
nextAtom = PpAtomLast;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,8 +87,6 @@ TPpContext::TPpContext(TParseContextBase& pc, const std::string& rootFileName, T
|
|||||||
rootFileName(rootFileName),
|
rootFileName(rootFileName),
|
||||||
currentSourceFile(rootFileName)
|
currentSourceFile(rootFileName)
|
||||||
{
|
{
|
||||||
InitAtomTable();
|
|
||||||
|
|
||||||
ifdepth = 0;
|
ifdepth = 0;
|
||||||
for (elsetracker = 0; elsetracker < maxIfNesting; elsetracker++)
|
for (elsetracker = 0; elsetracker < maxIfNesting; elsetracker++)
|
||||||
elseSeen[elsetracker] = false;
|
elseSeen[elsetracker] = false;
|
||||||
|
|||||||
@ -115,6 +115,62 @@ public:
|
|||||||
char name[MaxTokenLength + 1];
|
char name[MaxTokenLength + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TStringAtomMap {
|
||||||
|
//
|
||||||
|
// Implementation is in PpAtom.cpp
|
||||||
|
//
|
||||||
|
// Maintain a bi-directional mapping between relevant preprocessor strings and
|
||||||
|
// "atoms" which a unique integers (small, contiguous, not hash-like) per string.
|
||||||
|
//
|
||||||
|
public:
|
||||||
|
TStringAtomMap();
|
||||||
|
|
||||||
|
// Map string -> atom.
|
||||||
|
// Return 0 if no existing string.
|
||||||
|
int getAtom(const char* s) const
|
||||||
|
{
|
||||||
|
auto it = atomMap.find(s);
|
||||||
|
return it == atomMap.end() ? 0 : it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map a new or existing string -> atom, inventing a new atom if necessary.
|
||||||
|
int getAddAtom(const char* s)
|
||||||
|
{
|
||||||
|
int atom = getAtom(s);
|
||||||
|
if (atom == 0) {
|
||||||
|
atom = nextAtom++;
|
||||||
|
addAtomFixed(s, atom);
|
||||||
|
}
|
||||||
|
return atom;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map atom -> string.
|
||||||
|
const char* getString(int atom) const { return stringMap[atom]->c_str(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TStringAtomMap(TStringAtomMap&);
|
||||||
|
TStringAtomMap& operator=(TStringAtomMap&);
|
||||||
|
|
||||||
|
TUnorderedMap<TString, int> atomMap;
|
||||||
|
TVector<const TString*> stringMap; // these point into the TString in atomMap
|
||||||
|
int nextAtom;
|
||||||
|
|
||||||
|
// Bad source characters can lead to bad atoms, so gracefully handle those by
|
||||||
|
// pre-filling the table with them (to avoid if tests later).
|
||||||
|
TString badToken;
|
||||||
|
|
||||||
|
// Add bi-directional mappings:
|
||||||
|
// - string -> atom
|
||||||
|
// - atom -> string
|
||||||
|
void addAtomFixed(const char* s, int atom)
|
||||||
|
{
|
||||||
|
auto it = atomMap.insert(std::pair<TString, int>(s, atom)).first;
|
||||||
|
if (stringMap.size() < (size_t)atom + 1)
|
||||||
|
stringMap.resize(atom + 100, &badToken);
|
||||||
|
stringMap[atom] = &it->first;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class TInputScanner;
|
class TInputScanner;
|
||||||
|
|
||||||
// This class is the result of turning a huge pile of C code communicating through globals
|
// This class is the result of turning a huge pile of C code communicating through globals
|
||||||
@ -196,6 +252,7 @@ protected:
|
|||||||
TPpContext(TPpContext&);
|
TPpContext(TPpContext&);
|
||||||
TPpContext& operator=(TPpContext&);
|
TPpContext& operator=(TPpContext&);
|
||||||
|
|
||||||
|
TStringAtomMap atomStrings;
|
||||||
char* preamble; // string to parse, all before line 1 of string 0, it is 0 if no preamble
|
char* preamble; // string to parse, all before line 1 of string 0, it is 0 if no preamble
|
||||||
int preambleLength;
|
int preambleLength;
|
||||||
char** strings; // official strings of shader, starting a string 0 line 1
|
char** strings; // official strings of shader, starting a string 0 line 1
|
||||||
@ -538,21 +595,6 @@ protected:
|
|||||||
std::string rootFileName;
|
std::string rootFileName;
|
||||||
std::stack<TShader::Includer::IncludeResult*> includeStack;
|
std::stack<TShader::Includer::IncludeResult*> includeStack;
|
||||||
std::string currentSourceFile;
|
std::string currentSourceFile;
|
||||||
|
|
||||||
//
|
|
||||||
// From PpAtom.cpp
|
|
||||||
//
|
|
||||||
typedef TUnorderedMap<TString, int> TAtomMap;
|
|
||||||
typedef TVector<const TString*> TStringMap;
|
|
||||||
|
|
||||||
TAtomMap atomMap;
|
|
||||||
TStringMap stringMap;
|
|
||||||
int nextAtom;
|
|
||||||
void InitAtomTable();
|
|
||||||
void AddAtomFixed(const char* s, int atom);
|
|
||||||
int LookUpString(const char* s);
|
|
||||||
int LookUpAddString(const char* s);
|
|
||||||
const char* GetAtomString(int atom);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace glslang
|
} // end namespace glslang
|
||||||
|
|||||||
@ -774,7 +774,7 @@ int TPpContext::tokenize(TPpToken& ppToken)
|
|||||||
parseContext.ppError(ppToken.loc, "character literals not supported", "\'", "");
|
parseContext.ppError(ppToken.loc, "character literals not supported", "\'", "");
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
strcpy(ppToken.name, GetAtomString(token));
|
strcpy(ppToken.name, atomStrings.getString(token));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,8 +836,8 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken)
|
|||||||
case PpAtomAnd:
|
case PpAtomAnd:
|
||||||
case PpAtomOr:
|
case PpAtomOr:
|
||||||
case PpAtomXor:
|
case PpAtomXor:
|
||||||
strcpy(ppToken.name, GetAtomString(resultToken));
|
strcpy(ppToken.name, atomStrings.getString(resultToken));
|
||||||
strcpy(pastedPpToken.name, GetAtomString(token));
|
strcpy(pastedPpToken.name, atomStrings.getString(token));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
parseContext.ppError(ppToken.loc, "not supported for these tokens", "##", "");
|
parseContext.ppError(ppToken.loc, "not supported for these tokens", "##", "");
|
||||||
@ -853,7 +853,7 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken)
|
|||||||
|
|
||||||
// correct the kind of token we are making, if needed (identifiers stay identifiers)
|
// correct the kind of token we are making, if needed (identifiers stay identifiers)
|
||||||
if (resultToken != PpAtomIdentifier) {
|
if (resultToken != PpAtomIdentifier) {
|
||||||
int newToken = LookUpString(ppToken.name);
|
int newToken = atomStrings.getAtom(ppToken.name);
|
||||||
if (newToken > 0)
|
if (newToken > 0)
|
||||||
resultToken = newToken;
|
resultToken = newToken;
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user