diff --git a/glslang/MachineIndependent/preprocessor/Pp.cpp b/glslang/MachineIndependent/preprocessor/Pp.cpp index 1985b8bc..82f91484 100644 --- a/glslang/MachineIndependent/preprocessor/Pp.cpp +++ b/glslang/MachineIndependent/preprocessor/Pp.cpp @@ -91,18 +91,10 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace glslang { -int TPpContext::InitCPP() -{ - pool = mem_CreatePool(0, 0); - - return 1; -} - // Handle #define int TPpContext::CPPdefine(TPpToken* ppToken) { MacroSymbol mac; - Symbol *symb; // get macro name int token = scanToken(ppToken); @@ -121,32 +113,28 @@ int TPpContext::CPPdefine(TPpToken* ppToken) // gather parameters to the macro, between (...) token = scanToken(ppToken); if (token == '(' && ! ppToken->space) { - int argc = 0; - int args[maxMacroArgs]; + mac.emptyArgs = 1; do { token = scanToken(ppToken); - if (argc == 0 && token == ')') + if (mac.args.size() == 0 && token == ')') break; if (token != PpAtomIdentifier) { parseContext.ppError(ppToken->loc, "bad argument", "#define", ""); return token; } + mac.emptyArgs = 0; // check for duplication of parameter name bool duplicate = false; - for (int a = 0; a < argc; ++a) { - if (args[a] == ppToken->atom) { + for (size_t a = 0; a < mac.args.size(); ++a) { + if (mac.args[a] == ppToken->atom) { parseContext.ppError(ppToken->loc, "duplicate macro parameter", "#define", ""); duplicate = true; break; } } - if (! duplicate) { - if (argc < maxMacroArgs) - args[argc++] = ppToken->atom; - else - parseContext.ppError(ppToken->loc, "too many macro parameters", "#define", ""); - } + if (! duplicate) + mac.args.push_back(ppToken->atom); token = scanToken(ppToken); } while (token == ','); if (token != ')') { @@ -154,15 +142,12 @@ int TPpContext::CPPdefine(TPpToken* ppToken) return token; } - mac.argc = argc; - mac.args = (int*)mem_Alloc(pool, argc * sizeof(int)); - memcpy(mac.args, args, argc * sizeof(int)); + token = scanToken(ppToken); } // record the definition of the macro TSourceLoc defineLoc = ppToken->loc; // because ppToken is going to go to the next line before we report errors - mac.body = new TokenStream; while (token != '\n' && token != EndOfInput) { RecordToken(mac.body, token, ppToken); token = scanToken(ppToken); @@ -171,27 +156,25 @@ int TPpContext::CPPdefine(TPpToken* ppToken) } // check for duplicate definition - symb = LookUpSymbol(defAtom); - if (symb) { - if (! symb->mac.undef) { + MacroSymbol* existing = lookupMacroDef(defAtom); + if (existing != nullptr) { + if (! existing->undef) { // Already defined -- need to make sure they are identical: // "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." - if (symb->mac.argc != mac.argc) + if (existing->args.size() != mac.args.size() || existing->emptyArgs != mac.emptyArgs) parseContext.ppError(defineLoc, "Macro redefined; different number of arguments:", "#define", GetAtomString(defAtom)); else { - for (int argc = 0; argc < mac.argc; argc++) { - if (symb->mac.args[argc] != mac.args[argc]) - parseContext.ppError(defineLoc, "Macro redefined; different argument names:", "#define", GetAtomString(defAtom)); - } - RewindTokenStream(symb->mac.body); + if (existing->args != mac.args) + parseContext.ppError(defineLoc, "Macro redefined; different argument names:", "#define", GetAtomString(defAtom)); + RewindTokenStream(existing->body); RewindTokenStream(mac.body); int newToken; do { int oldToken; TPpToken oldPpToken; TPpToken newPpToken; - oldToken = ReadToken(symb->mac.body, &oldPpToken); + oldToken = ReadToken(existing->body, &oldPpToken); newToken = ReadToken(mac.body, &newPpToken); if (oldToken != newToken || oldPpToken != newPpToken) { parseContext.ppError(defineLoc, "Macro redefined; different substitutions:", "#define", GetAtomString(defAtom)); @@ -200,11 +183,9 @@ int TPpContext::CPPdefine(TPpToken* ppToken) } while (newToken > 0); } } + *existing = mac; } else - symb = AddSymbol(defAtom); - - delete symb->mac.body; - symb->mac = mac; + addMacroDef(defAtom, mac); return '\n'; } @@ -213,7 +194,6 @@ int TPpContext::CPPdefine(TPpToken* ppToken) int TPpContext::CPPundef(TPpToken* ppToken) { int token = scanToken(ppToken); - Symbol *symb; if (token != PpAtomIdentifier) { parseContext.ppError(ppToken->loc, "must be followed by macro name", "#undef", ""); @@ -222,10 +202,9 @@ int TPpContext::CPPundef(TPpToken* ppToken) parseContext.reservedPpErrorCheck(ppToken->loc, ppToken->name, "#undef"); - symb = LookUpSymbol(ppToken->atom); - if (symb) { - symb->mac.undef = 1; - } + MacroSymbol* macro = lookupMacroDef(ppToken->atom); + if (macro != nullptr) + macro->undef = 1; token = scanToken(ppToken); if (token != '\n') parseContext.ppError(ppToken->loc, "can only be followed by a single macro name", "#undef", ""); @@ -427,8 +406,9 @@ int TPpContext::eval(int token, int precedence, bool shortCircuit, int& res, boo return token; } - Symbol* s = LookUpSymbol(ppToken->atom); - res = s ? ! s->mac.undef : 0; + + MacroSymbol* macro = lookupMacroDef(ppToken->atom); + res = macro != nullptr ? !macro->undef : 0; token = scanToken(ppToken); if (needclose) { if (token != ')') { @@ -568,7 +548,6 @@ int TPpContext::CPPif(TPpToken* ppToken) int TPpContext::CPPifdef(int defined, TPpToken* ppToken) { int token = scanToken(ppToken); - int name = ppToken->atom; if (++ifdepth > maxIfNesting) { parseContext.ppError(ppToken->loc, "maximum nesting depth exceeded", "#ifdef", ""); return 0; @@ -580,14 +559,14 @@ int TPpContext::CPPifdef(int defined, TPpToken* ppToken) else parseContext.ppError(ppToken->loc, "must be followed by macro name", "#ifndef", ""); } else { - Symbol *s = LookUpSymbol(name); + MacroSymbol* macro = lookupMacroDef(ppToken->atom); token = scanToken(ppToken); if (token != '\n') { parseContext.ppError(ppToken->loc, "unexpected tokens following #ifdef directive - expected a newline", "#ifdef", ""); while (token != '\n' && token != EndOfInput) token = scanToken(ppToken); } - if (((s && !s->mac.undef) ? 1 : 0) != defined) + if (((macro != nullptr && !macro->undef) ? 1 : 0) != defined) token = CPPelse(1, ppToken); } @@ -936,13 +915,13 @@ int TPpContext::readCPPline(TPpToken* ppToken) // Macro-expand a macro argument 'arg' to create 'expandedArg'. // Does not replace 'arg'. // 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) { int token; RewindTokenStream(arg); do { token = ReadToken(arg, ppToken); - if (token == PpAtomIdentifier && LookUpSymbol(ppToken->atom)) + if (token == PpAtomIdentifier && lookupMacroDef(ppToken->atom) != nullptr) break; } while (token != EndOfInput); @@ -955,7 +934,7 @@ TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream* arg, TPpToken* while ((token = scanToken(ppToken)) != tMarkerInput::marker) { if (token == PpAtomIdentifier && MacroExpand(ppToken->atom, ppToken, false, newLineOkay) != 0) continue; - RecordToken(expandedArg, token, ppToken); + RecordToken(*expandedArg, token, ppToken); } popInput(); @@ -1009,14 +988,14 @@ int TPpContext::tMacroInput::scan(TPpToken* ppToken) // TODO: preprocessor: properly handle whitespace (or lack of it) between tokens when expanding if (token == PpAtomIdentifier) { int i; - for (i = mac->argc - 1; i >= 0; i--) + for (i = mac->args.size() - 1; i >= 0; i--) if (mac->args[i] == ppToken->atom) break; if (i >= 0) { TokenStream* arg = expandedArgs[i]; if (arg == nullptr || pasting) arg = args[i]; - pp->pushTokenStreamInput(arg, prepaste); + pp->pushTokenStreamInput(*arg, prepaste); return pp->scanToken(ppToken); } @@ -1032,7 +1011,7 @@ int TPpContext::tMacroInput::scan(TPpToken* ppToken) bool TPpContext::tMacroInput::peekMacPasting() { // don't return early, have to restore this - size_t savePos = mac->body->current; + size_t savePos = mac->body.current; // skip white-space int ltoken; @@ -1048,7 +1027,7 @@ bool TPpContext::tMacroInput::peekMacPasting() pasting = true; } - mac->body->current = savePos; + mac->body.current = savePos; return pasting; } @@ -1104,20 +1083,20 @@ int TPpContext::MacroExpand(int atom, TPpToken* ppToken, bool expandUndef, bool break; } - Symbol *sym = LookUpSymbol(atom); + MacroSymbol* macro = lookupMacroDef(atom); int token; int depth = 0; // no recursive expansions - if (sym && sym->mac.busy) + if (macro != nullptr && macro->busy) return 0; // not expanding undefined macros - if ((! sym || sym->mac.undef) && ! expandUndef) + if ((macro == nullptr || macro->undef) && ! expandUndef) return 0; // 0 is the value of an undefined macro - if ((! sym || sym->mac.undef) && expandUndef) { + if ((macro == nullptr || macro->undef) && expandUndef) { pushInput(new tZeroInput(this)); return -1; } @@ -1125,8 +1104,8 @@ int TPpContext::MacroExpand(int atom, TPpToken* ppToken, bool expandUndef, bool tMacroInput *in = new tMacroInput(this); TSourceLoc loc = ppToken->loc; // in case we go to the next line before discovering the error - in->mac = &sym->mac; - if (sym->mac.args) { + in->mac = macro; + if (macro->args.size() > 0 || macro->emptyArgs) { token = scanToken(ppToken); if (newLineOkay) { while (token == '\n') @@ -1140,13 +1119,13 @@ int TPpContext::MacroExpand(int atom, TPpToken* ppToken, bool expandUndef, bool delete in; return 0; } - in->args.resize(in->mac->argc); - for (int i = 0; i < in->mac->argc; i++) + in->args.resize(in->mac->args.size()); + for (size_t i = 0; i < in->mac->args.size(); i++) in->args[i] = new TokenStream; - in->expandedArgs.resize(in->mac->argc); - for (int i = 0; i < in->mac->argc; i++) + in->expandedArgs.resize(in->mac->args.size()); + for (size_t i = 0; i < in->mac->args.size(); i++) in->expandedArgs[i] = nullptr; - int arg = 0; + size_t arg = 0; bool tokenRecorded = false; do { depth = 0; @@ -1170,7 +1149,7 @@ int TPpContext::MacroExpand(int atom, TPpToken* ppToken, bool expandUndef, bool delete in; return 0; } - if (in->mac->argc == 0 && token != ')') + if (in->mac->args.size() == 0 && token != ')') break; if (depth == 0 && (token == ',' || token == ')')) break; @@ -1178,19 +1157,19 @@ int TPpContext::MacroExpand(int atom, TPpToken* ppToken, bool expandUndef, bool depth++; if (token == ')') depth--; - RecordToken(in->args[arg], token, ppToken); + RecordToken(*in->args[arg], token, ppToken); tokenRecorded = true; } if (token == ')') { - if (in->mac->argc == 1 && tokenRecorded == 0) + if (in->mac->args.size() == 1 && tokenRecorded == 0) break; arg++; break; } arg++; - } while (arg < in->mac->argc); + } while (arg < in->mac->args.size()); - if (arg < in->mac->argc) + if (arg < in->mac->args.size()) parseContext.ppError(loc, "Too few args in Macro", "macro expansion", GetAtomString(atom)); else if (token != ')') { depth=0; @@ -1212,13 +1191,13 @@ int TPpContext::MacroExpand(int atom, TPpToken* ppToken, bool expandUndef, bool // We need both expanded and non-expanded forms of the argument, for whether or // not token pasting is in play. - for (int i = 0; i < in->mac->argc; i++) - in->expandedArgs[i] = PrescanMacroArg(in->args[i], ppToken, newLineOkay); + for (size_t i = 0; i < in->mac->args.size(); i++) + in->expandedArgs[i] = PrescanMacroArg(*in->args[i], ppToken, newLineOkay); } pushInput(in); - sym->mac.busy = 1; - RewindTokenStream(sym->mac.body); + macro->busy = 1; + RewindTokenStream(macro->body); return 1; } diff --git a/glslang/MachineIndependent/preprocessor/PpContext.cpp b/glslang/MachineIndependent/preprocessor/PpContext.cpp index 6791fef5..e81b7647 100644 --- a/glslang/MachineIndependent/preprocessor/PpContext.cpp +++ b/glslang/MachineIndependent/preprocessor/PpContext.cpp @@ -83,12 +83,11 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace glslang { TPpContext::TPpContext(TParseContextBase& pc, const std::string& rootFileName, TShader::Includer& inclr) : - preamble(0), strings(0), parseContext(pc), includer(inclr), inComment(false), + preamble(0), strings(0), previous_token('\n'), parseContext(pc), includer(inclr), inComment(false), rootFileName(rootFileName), currentSourceFile(rootFileName) { - InitAtomTable(); - InitScanner(); + InitAtomTable(); ifdepth = 0; for (elsetracker = 0; elsetracker < maxIfNesting; elsetracker++) @@ -98,9 +97,6 @@ TPpContext::TPpContext(TParseContextBase& pc, const std::string& rootFileName, T TPpContext::~TPpContext() { - for (TSymbolMap::iterator it = symbols.begin(); it != symbols.end(); ++it) - delete it->second->mac.body; - mem_FreePool(pool); delete [] preamble; // free up the inputStack diff --git a/glslang/MachineIndependent/preprocessor/PpContext.h b/glslang/MachineIndependent/preprocessor/PpContext.h index 885cf05a..96079f54 100644 --- a/glslang/MachineIndependent/preprocessor/PpContext.h +++ b/glslang/MachineIndependent/preprocessor/PpContext.h @@ -172,39 +172,27 @@ public: size_t current; }; - struct MemoryPool { - struct chunk *next; - uintptr_t free, end; - size_t chunksize; - uintptr_t alignmask; - }; - // // From Pp.cpp // struct MacroSymbol { - MacroSymbol() : argc(0), args(0), body(0), busy(0), undef(0) { } - int argc; - int *args; - TokenStream *body; - unsigned busy:1; - unsigned undef:1; + MacroSymbol() : emptyArgs(0), busy(0), undef(0) { } + TVector args; + TokenStream body; + unsigned emptyArgs : 1; + unsigned busy : 1; + unsigned undef : 1; }; - struct Symbol { - int atom; - MacroSymbol mac; - }; - - struct SymbolList { - struct SymbolList_Rec *next; - Symbol *symb; - }; - - MemoryPool *pool; - typedef TMap TSymbolMap; - TSymbolMap symbols; // this has light use... just defined macros + typedef TMap TSymbolMap; + TSymbolMap macroDefs; // map atoms to macro definitions + MacroSymbol* lookupMacroDef(int atom) + { + auto existingMacroIt = macroDefs.find(atom); + return (existingMacroIt == macroDefs.end()) ? nullptr : &(existingMacroIt->second); + } + void addMacroDef(int atom, MacroSymbol& macroDef) { macroDefs[atom] = macroDef; } protected: TPpContext(TPpContext&); @@ -242,7 +230,6 @@ protected: bool peekPasting() { return !inputStack.empty() && inputStack.back()->peekPasting(); } bool endOfReplacementList() { return inputStack.empty() || inputStack.back()->endOfReplacementList(); } - static const int maxMacroArgs = 64; static const int maxIfNesting = 64; int ifdepth; // current #if-#else-#endif nesting in the cpp.c file (pre-processor) @@ -264,7 +251,7 @@ protected: virtual int getch() { assert(0); return EndOfInput; } virtual void ungetch() { assert(0); } bool peekPasting() override { return prepaste; } - bool endOfReplacementList() override { return mac->body->current >= mac->body->data.size(); } + bool endOfReplacementList() override { return mac->body.current >= mac->body.data.size(); } MacroSymbol *mac; TVector args; @@ -311,7 +298,6 @@ protected: // Used to obtain #include content. TShader::Includer& includer; - int InitCPP(); int CPPdefine(TPpToken * ppToken); int CPPundef(TPpToken * ppToken); int CPPelse(int matchelse, TPpToken * ppToken); @@ -327,27 +313,20 @@ protected: int CPPversion(TPpToken * ppToken); int CPPextension(TPpToken * ppToken); int readCPPline(TPpToken * ppToken); - TokenStream* PrescanMacroArg(TokenStream *a, TPpToken * ppToken, bool newLineOkay); + TokenStream* PrescanMacroArg(TokenStream&, TPpToken*, bool newLineOkay); int MacroExpand(int atom, TPpToken* ppToken, bool expandUndef, bool newLineOkay); - // - // from PpSymbols.cpp - // - Symbol *NewSymbol(int name); - Symbol *AddSymbol(int atom); - Symbol *LookUpSymbol(int atom); - // // From PpTokens.cpp // - void lAddByte(TokenStream *fTok, unsigned char fVal); - int lReadByte(TokenStream *pTok); - void lUnreadByte(TokenStream *pTok); - void RecordToken(TokenStream* pTok, int token, TPpToken* ppToken); - void RewindTokenStream(TokenStream *pTok); - int ReadToken(TokenStream* pTok, TPpToken* ppToken); - void pushTokenStreamInput(TokenStream *ts, bool pasting = false); - void UngetToken(int token, TPpToken* ppToken); + void lAddByte(TokenStream&, unsigned char fVal); + int lReadByte(TokenStream&); + void lUnreadByte(TokenStream&); + void RecordToken(TokenStream&, int token, TPpToken* ppToken); + void RewindTokenStream(TokenStream&); + int ReadToken(TokenStream&, TPpToken*); + void pushTokenStreamInput(TokenStream&, bool pasting = false); + void UngetToken(int token, TPpToken*); class tTokenInput : public tInput { public: @@ -357,7 +336,7 @@ protected: virtual void ungetch() { assert(0); } virtual bool peekPasting() override; protected: - TokenStream *tokens; + TokenStream* tokens; bool lastTokenPastes; // true if the last token in the input is to be pasted, rather than consumed as a token }; @@ -535,7 +514,6 @@ protected: tStringInput stringInput; }; - int InitScanner(); int ScanFromString(char* s); void missingEndifCheck(); int lFloatConst(int len, int ch, TPpToken* ppToken); @@ -576,14 +554,6 @@ protected: void AddAtomFixed(const char* s, int atom); int LookUpAddString(const char* s); const char* GetAtomString(int atom); - - // - // From PpMemory.cpp - // - MemoryPool *mem_CreatePool(size_t chunksize, unsigned align); - void mem_FreePool(MemoryPool*); - void *mem_Alloc(MemoryPool* p, size_t size); - int mem_AddCleanup(MemoryPool* p, void (*fn)(void *, void*), void* arg1, void* arg2); }; } // end namespace glslang diff --git a/glslang/MachineIndependent/preprocessor/PpMemory.cpp b/glslang/MachineIndependent/preprocessor/PpMemory.cpp index 6158a387..4d0f32a4 100644 --- a/glslang/MachineIndependent/preprocessor/PpMemory.cpp +++ b/glslang/MachineIndependent/preprocessor/PpMemory.cpp @@ -76,86 +76,6 @@ TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \****************************************************************************/ -#include -#include -#include - -#include "PpContext.h" - -// default alignment and chunksize, if called with 0 arguments -#define CHUNKSIZE (64*1024) -#define ALIGN 8 - namespace glslang { -struct chunk { - struct chunk *next; -}; - -TPpContext::MemoryPool* TPpContext::mem_CreatePool(size_t chunksize, unsigned int align) -{ - if (align == 0) - align = ALIGN; - if (chunksize == 0) - chunksize = CHUNKSIZE; - if (align & (align - 1)) - return nullptr; - if (chunksize < sizeof(MemoryPool)) - return nullptr; - if (chunksize & (align - 1)) - return nullptr; - - MemoryPool *pool = (MemoryPool*)malloc(chunksize); - if (! pool) - return nullptr; - - pool->next = 0; - pool->chunksize = chunksize; - pool->alignmask = (uintptr_t)(align) - 1; - pool->free = ((uintptr_t)(pool + 1) + pool->alignmask) & ~pool->alignmask; - pool->end = (uintptr_t)pool + chunksize; - - return pool; -} - -void TPpContext::mem_FreePool(MemoryPool *pool) -{ - struct chunk *p, *next; - - for (p = (struct chunk *)pool; p; p = next) { - next = p->next; - free(p); - } -} - -void* TPpContext::mem_Alloc(MemoryPool *pool, size_t size) -{ - struct chunk *ch; - void *rv = (void *)pool->free; - size = (size + pool->alignmask) & ~pool->alignmask; - if (size <= 0) size = pool->alignmask; - pool->free += size; - if (pool->free > pool->end || pool->free < (uintptr_t)rv) { - size_t minreq = (size + sizeof(struct chunk) + pool->alignmask) & ~pool->alignmask; - pool->free = (uintptr_t)rv; - if (minreq >= pool->chunksize) { - // request size is too big for the chunksize, so allocate it as - // a single chunk of the right size - ch = (struct chunk*)malloc(minreq); - if (! ch) - return nullptr; - } else { - ch = (struct chunk*)malloc(pool->chunksize); - if (! ch) - return nullptr; - pool->free = (uintptr_t)ch + minreq; - pool->end = (uintptr_t)ch + pool->chunksize; - } - ch->next = pool->next; - pool->next = ch; - rv = (void *)(((uintptr_t)(ch+1) + pool->alignmask) & ~pool->alignmask); - } - return rv; -} - } // end namespace glslang diff --git a/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/glslang/MachineIndependent/preprocessor/PpScanner.cpp index bc5c0866..a3be5360 100644 --- a/glslang/MachineIndependent/preprocessor/PpScanner.cpp +++ b/glslang/MachineIndependent/preprocessor/PpScanner.cpp @@ -90,17 +90,6 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace glslang { -int TPpContext::InitScanner() -{ - // Add various atoms needed by the CPP line scanner: - if (!InitCPP()) - return 0; - - previous_token = '\n'; - - return 1; -} - /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////// Floating point constants: ///////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/glslang/MachineIndependent/preprocessor/PpSymbols.cpp b/glslang/MachineIndependent/preprocessor/PpSymbols.cpp index b7f1df55..a20a3d85 100644 --- a/glslang/MachineIndependent/preprocessor/PpSymbols.cpp +++ b/glslang/MachineIndependent/preprocessor/PpSymbols.cpp @@ -91,44 +91,4 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace glslang { -/* -* Allocate a new symbol node; -* -*/ -TPpContext::Symbol* TPpContext::NewSymbol(int atom) -{ - Symbol* lSymb; - char* pch; - size_t ii; - - lSymb = (Symbol *) mem_Alloc(pool, sizeof(Symbol)); - lSymb->atom = atom; - - // Clear macro - pch = (char*) &lSymb->mac; - for (ii = 0; ii < sizeof(lSymb->mac); ii++) - *pch++ = 0; - - return lSymb; -} - -TPpContext::Symbol* TPpContext::AddSymbol(int atom) -{ - Symbol *lSymb; - - lSymb = NewSymbol(atom); - symbols[lSymb->atom] = lSymb; - - return lSymb; -} - -TPpContext::Symbol* TPpContext::LookUpSymbol(int atom) -{ - TSymbolMap::iterator it = symbols.find(atom); - if (it == symbols.end()) - return nullptr; - else - return it->second; -} - } // end namespace glslang diff --git a/glslang/MachineIndependent/preprocessor/PpTokens.cpp b/glslang/MachineIndependent/preprocessor/PpTokens.cpp index 724cedd0..3f98df34 100644 --- a/glslang/MachineIndependent/preprocessor/PpTokens.cpp +++ b/glslang/MachineIndependent/preprocessor/PpTokens.cpp @@ -95,32 +95,32 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace glslang { -void TPpContext::lAddByte(TokenStream *fTok, unsigned char fVal) +void TPpContext::lAddByte(TokenStream& fTok, unsigned char fVal) { - fTok->data.push_back(fVal); + fTok.data.push_back(fVal); } /* * Get the next byte from a stream. */ -int TPpContext::lReadByte(TokenStream *pTok) +int TPpContext::lReadByte(TokenStream& pTok) { - if (pTok->current < pTok->data.size()) - return pTok->data[pTok->current++]; + if (pTok.current < pTok.data.size()) + return pTok.data[pTok.current++]; else return EndOfInput; } -void TPpContext::lUnreadByte(TokenStream *pTok) +void TPpContext::lUnreadByte(TokenStream& pTok) { - if (pTok->current > 0) - --pTok->current; + if (pTok.current > 0) + --pTok.current; } /* * Add a token to the end of a list for later playback. */ -void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken* ppToken) +void TPpContext::RecordToken(TokenStream& pTok, int token, TPpToken* ppToken) { const char* s; char* str = NULL; @@ -162,15 +162,15 @@ void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken* ppToken) /* * Reset a token stream in preparation for reading. */ -void TPpContext::RewindTokenStream(TokenStream *pTok) +void TPpContext::RewindTokenStream(TokenStream& pTok) { - pTok->current = 0; + pTok.current = 0; } /* * Read the next token from a token stream (not the source stream, but stream used to hold a tokenized macro). */ -int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken) +int TPpContext::ReadToken(TokenStream& pTok, TPpToken *ppToken) { char* tokenText = ppToken->name; int ltoken, len; @@ -183,7 +183,7 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken) switch (ltoken) { case '#': // Check for ##, unless the current # is the last character - if (pTok->current < pTok->data.size()) { + if (pTok.current < pTok.data.size()) { if (lReadByte(pTok) == '#') { parseContext.requireProfile(ppToken->loc, ~EEsProfile, "token pasting (##)"); parseContext.profileRequires(ppToken->loc, ~EEsProfile, 130, 0, "token pasting (##)"); @@ -274,7 +274,7 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken) int TPpContext::tTokenInput::scan(TPpToken* ppToken) { - return pp->ReadToken(tokens, ppToken); + return pp->ReadToken(*tokens, ppToken); } // We are pasting if the entire macro is preceding a pasting operator @@ -289,7 +289,7 @@ bool TPpContext::tTokenInput::peekPasting() size_t savePos = tokens->current; bool moreTokens = false; do { - int byte = pp->lReadByte(tokens); + int byte = pp->lReadByte(*tokens); if (byte == EndOfInput) break; if (byte != ' ') { @@ -302,9 +302,9 @@ bool TPpContext::tTokenInput::peekPasting() return !moreTokens; } -void TPpContext::pushTokenStreamInput(TokenStream* ts, bool prepasting) +void TPpContext::pushTokenStreamInput(TokenStream& ts, bool prepasting) { - pushInput(new tTokenInput(this, ts, prepasting)); + pushInput(new tTokenInput(this, &ts, prepasting)); RewindTokenStream(ts); }