Fix memory corruption problem in the preprocessor, removing custom hash-tables/etc. and replacing with std containers.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23623 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
ab3080353a
commit
1f4104fbb1
7 changed files with 172 additions and 957 deletions
|
|
@ -90,237 +90,46 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
/////////////////////////////////// Symbol Table Variables: ///////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace glslang;
|
||||
|
||||
void unlinkScope(void *_scope, void* scopeList)
|
||||
{
|
||||
TPpContext::Scope *scope = (TPpContext::Scope*)_scope;
|
||||
|
||||
if (scope->next)
|
||||
scope->next->prev = scope->prev;
|
||||
if (scope->prev)
|
||||
scope->prev->next = scope->next;
|
||||
else
|
||||
*(TPpContext::Scope**)scopeList = scope->next;
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
namespace glslang {
|
||||
|
||||
/*
|
||||
* NewScope()
|
||||
* Allocate a new symbol node;
|
||||
*
|
||||
*/
|
||||
TPpContext::Scope* TPpContext::NewScopeInPool(MemoryPool *pool)
|
||||
{
|
||||
Scope *lScope;
|
||||
|
||||
lScope = (Scope*)mem_Alloc(pool, sizeof(Scope));
|
||||
lScope->pool = pool;
|
||||
lScope->parent = NULL;
|
||||
lScope->funScope = NULL;
|
||||
lScope->symbols = NULL;
|
||||
|
||||
lScope->level = 0;
|
||||
|
||||
lScope->programs = NULL;
|
||||
if ((lScope->next = ScopeList))
|
||||
ScopeList->prev = lScope;
|
||||
lScope->prev = 0;
|
||||
ScopeList = lScope;
|
||||
mem_AddCleanup(pool, unlinkScope, lScope, &ScopeList);
|
||||
|
||||
return lScope;
|
||||
} // NewScope
|
||||
|
||||
/*
|
||||
* PushScope()
|
||||
*
|
||||
*/
|
||||
|
||||
void TPpContext::PushScope(Scope *fScope)
|
||||
{
|
||||
Scope *lScope;
|
||||
|
||||
if (CurrentScope) {
|
||||
fScope->level = CurrentScope->level + 1;
|
||||
if (fScope->level == 1) {
|
||||
if (!GlobalScope) {
|
||||
/* HACK - CTD -- if GlobalScope==NULL and level==1, we're
|
||||
* defining a function in the superglobal scope. Things
|
||||
* will break if we leave the level as 1, so we arbitrarily
|
||||
* set it to 2 */
|
||||
fScope->level = 2;
|
||||
}
|
||||
}
|
||||
if (fScope->level >= 2) {
|
||||
lScope = fScope;
|
||||
while (lScope->level > 2)
|
||||
lScope = lScope->next;
|
||||
fScope->funScope = lScope;
|
||||
}
|
||||
} else {
|
||||
fScope->level = 0;
|
||||
}
|
||||
fScope->parent = CurrentScope;
|
||||
CurrentScope = fScope;
|
||||
} // PushScope
|
||||
|
||||
/*
|
||||
* PopScope()
|
||||
*
|
||||
*/
|
||||
|
||||
TPpContext::Scope* TPpContext::PopScope(void)
|
||||
{
|
||||
Scope *lScope;
|
||||
|
||||
lScope = CurrentScope;
|
||||
if (CurrentScope)
|
||||
CurrentScope = CurrentScope->parent;
|
||||
return lScope;
|
||||
} // PopScope
|
||||
|
||||
/*
|
||||
* NewSymbol() - Allocate a new symbol node;
|
||||
*
|
||||
*/
|
||||
|
||||
TPpContext::Symbol* TPpContext::NewSymbol(TSourceLoc *loc, Scope *fScope, int name, symbolkind kind)
|
||||
TPpContext::Symbol* TPpContext::NewSymbol(int atom)
|
||||
{
|
||||
Symbol *lSymb;
|
||||
char *pch;
|
||||
int ii;
|
||||
|
||||
lSymb = (Symbol *) mem_Alloc(fScope->pool, sizeof(Symbol));
|
||||
lSymb->left = NULL;
|
||||
lSymb->right = NULL;
|
||||
lSymb->next = NULL;
|
||||
lSymb->name = name;
|
||||
lSymb->loc = *loc;
|
||||
lSymb->kind = kind;
|
||||
lSymb = (Symbol *) mem_Alloc(pool, sizeof(Symbol));
|
||||
lSymb->atom = atom;
|
||||
|
||||
// Clear union area:
|
||||
|
||||
pch = (char *) &lSymb->details;
|
||||
for (ii = 0; ii < sizeof(lSymb->details); ii++)
|
||||
// Clear macro
|
||||
pch = (char *) &lSymb->mac;
|
||||
for (ii = 0; ii < sizeof(lSymb->mac); ii++)
|
||||
*pch++ = 0;
|
||||
|
||||
return lSymb;
|
||||
} // NewSymbol
|
||||
}
|
||||
|
||||
/*
|
||||
* lAddToTree() - Using a binary tree is not a good idea for basic atom values because they
|
||||
* are generated in order. We'll fix this later (by reversing the bit pattern).
|
||||
*/
|
||||
|
||||
void TPpContext::lAddToTree(Symbol **fSymbols, Symbol *fSymb, AtomTable *atable)
|
||||
{
|
||||
TPpContext::Symbol *lSymb;
|
||||
int lrev, frev;
|
||||
|
||||
lSymb = *fSymbols;
|
||||
if (lSymb) {
|
||||
frev = GetReversedAtom(atable, fSymb->name);
|
||||
while (lSymb) {
|
||||
lrev = GetReversedAtom(atable, lSymb->name);
|
||||
if (lrev == frev) {
|
||||
printf("GetAtomString(atable, fSymb->name)");
|
||||
break;
|
||||
} else {
|
||||
if (lrev > frev) {
|
||||
if (lSymb->left) {
|
||||
lSymb = lSymb->left;
|
||||
} else {
|
||||
lSymb->left = fSymb;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (lSymb->right) {
|
||||
lSymb = lSymb->right;
|
||||
} else {
|
||||
lSymb->right = fSymb;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
*fSymbols = fSymb;
|
||||
}
|
||||
} // lAddToTree
|
||||
|
||||
|
||||
/*
|
||||
* AddSymbol() - Add a variable, type, or function name to a scope.
|
||||
*
|
||||
*/
|
||||
|
||||
TPpContext::Symbol* TPpContext::AddSymbol(TSourceLoc *loc, Scope *fScope, int atom, symbolkind kind)
|
||||
TPpContext::Symbol* TPpContext::AddSymbol(int atom)
|
||||
{
|
||||
Symbol *lSymb;
|
||||
|
||||
if (!fScope)
|
||||
fScope = CurrentScope;
|
||||
lSymb = NewSymbol(loc, fScope, atom, kind);
|
||||
lAddToTree(&fScope->symbols, lSymb, &atomTable);
|
||||
lSymb = NewSymbol(atom);
|
||||
symbols[lSymb->atom] = lSymb;
|
||||
|
||||
return lSymb;
|
||||
} // AddSymbol
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************/
|
||||
/************************************ Symbol Semantic Functions ******************************/
|
||||
/*********************************************************************************************/
|
||||
|
||||
/*
|
||||
* LookUpLocalSymbol()
|
||||
*
|
||||
*/
|
||||
|
||||
TPpContext::Symbol* TPpContext::LookUpLocalSymbol(Scope *fScope, int atom)
|
||||
TPpContext::Symbol* TPpContext::LookUpSymbol(int atom)
|
||||
{
|
||||
Symbol *lSymb;
|
||||
int rname, ratom;
|
||||
|
||||
ratom = GetReversedAtom(&atomTable, atom);
|
||||
if (!fScope)
|
||||
fScope = CurrentScope;
|
||||
lSymb = fScope->symbols;
|
||||
while (lSymb) {
|
||||
rname = GetReversedAtom(&atomTable, lSymb->name);
|
||||
if (rname == ratom) {
|
||||
return lSymb;
|
||||
} else {
|
||||
if (rname > ratom) {
|
||||
lSymb = lSymb->left;
|
||||
} else {
|
||||
lSymb = lSymb->right;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
} // LookUpLocalSymbol
|
||||
|
||||
/*
|
||||
* LookUpSymbol()
|
||||
*
|
||||
*/
|
||||
|
||||
TPpContext::Symbol* TPpContext::LookUpSymbol(Scope *fScope, int atom)
|
||||
{
|
||||
Symbol *lSymb;
|
||||
|
||||
if (!fScope)
|
||||
fScope = CurrentScope;
|
||||
while (fScope) {
|
||||
lSymb = LookUpLocalSymbol(fScope, atom);
|
||||
if (lSymb)
|
||||
return lSymb;
|
||||
fScope = fScope->parent;
|
||||
}
|
||||
return NULL;
|
||||
} // LookUpSymbol
|
||||
TSymbol::iterator it = symbols.find(atom);
|
||||
if (it == symbols.end())
|
||||
return 0;
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue