Add new convenience pool allocators for arbitrary types, and use them to keep all TSymbol content in the pool, so they don't have to be deleted.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@24148 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
e1dba1b59f
commit
23bcc02a20
@ -98,6 +98,16 @@ inline TString* NewPoolTString(const char* s)
|
||||
return new(memory) TString(s);
|
||||
}
|
||||
|
||||
template<class T> inline T* NewPoolObject(T)
|
||||
{
|
||||
return new(GetThreadPoolAllocator().allocate(sizeof(T))) T;
|
||||
}
|
||||
|
||||
template<class T> inline T* NewPoolObject(T, int instances)
|
||||
{
|
||||
return new(GetThreadPoolAllocator().allocate(instances * sizeof(T))) T[instances];
|
||||
}
|
||||
|
||||
//
|
||||
// Pool allocator versions of vectors, lists, and maps
|
||||
//
|
||||
|
@ -413,9 +413,6 @@ TIntermTyped* TParseContext::handleVariable(TSourceLoc loc, TSymbol* symbol, TSt
|
||||
if (! variable)
|
||||
variable = new TVariable(string, TType(EbtVoid));
|
||||
|
||||
// don't delete $1.string, it's used by error recovery, and the pool
|
||||
// pop will reclaim the memory
|
||||
|
||||
if (variable->getType().getQualifier().storage == EvqConst)
|
||||
node = intermediate.addConstantUnion(variable->getConstArray(), variable->getType(), loc);
|
||||
else {
|
||||
@ -833,10 +830,9 @@ TIntermAggregate* TParseContext::handleFunctionDefinition(TSourceLoc loc, TFunct
|
||||
TVariable *variable = new TVariable(param.name, *param.type);
|
||||
|
||||
// Insert the parameters with name in the symbol table.
|
||||
if (! symbolTable.insert(*variable)) {
|
||||
if (! symbolTable.insert(*variable))
|
||||
error(loc, "redefinition", variable->getName().c_str(), "");
|
||||
delete variable;
|
||||
} else {
|
||||
else {
|
||||
// Transfer ownership of name pointer to symbol table.
|
||||
param.name = 0;
|
||||
|
||||
@ -2144,7 +2140,7 @@ bool TParseContext::redeclareBuiltinBlock(TSourceLoc loc, TTypeList& typeList, c
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy the to make a writable version, to insert into the block table after editing
|
||||
// Copy the block to make a writable version, to insert into the block table after editing.
|
||||
block = symbolTable.copyUpDeferredInsert(block);
|
||||
|
||||
if (block->getType().getBasicType() != EbtBlock) {
|
||||
|
@ -501,7 +501,7 @@ bool CompileDeferred(
|
||||
lengths[numStrings + 1] = strlen(strings[numStrings + 1]);
|
||||
TInputScanner fullInput(numStrings + 2, strings, lengths, 1, 1);
|
||||
|
||||
// Push a new symbol allocation scope that can for the shader's globals.
|
||||
// Push a new symbol allocation scope that will get used for the shader's globals.
|
||||
symbolTable.push();
|
||||
|
||||
// Parse the full shader.
|
||||
|
@ -249,8 +249,10 @@ TVariable::TVariable(const TVariable& copyOf) : TSymbol(copyOf)
|
||||
{
|
||||
type.deepCopy(copyOf.type);
|
||||
userType = copyOf.userType;
|
||||
numExtensions = 0;
|
||||
extensions = 0;
|
||||
setExtensions(copyOf.numExtensions, copyOf.extensions);
|
||||
if (copyOf.numExtensions > 0)
|
||||
setExtensions(copyOf.numExtensions, copyOf.extensions);
|
||||
|
||||
if (! copyOf.unionArray.empty()) {
|
||||
assert(!copyOf.type.getStruct());
|
||||
@ -276,8 +278,10 @@ TFunction::TFunction(const TFunction& copyOf) : TSymbol(copyOf)
|
||||
parameters.back().copyParam(copyOf.parameters[i]);
|
||||
}
|
||||
|
||||
extensions = 0;
|
||||
setExtensions(copyOf.numExtensions, copyOf.extensions);
|
||||
numExtensions = 0;
|
||||
extensions = 0;
|
||||
if (copyOf.extensions > 0)
|
||||
setExtensions(copyOf.numExtensions, copyOf.extensions);
|
||||
returnType.deepCopy(copyOf.returnType);
|
||||
mangledName = copyOf.mangledName;
|
||||
op = copyOf.op;
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
explicit TSymbol(const TString *n) : name(n), writable(true), numExtensions(0), extensions(0) { }
|
||||
virtual TSymbol* clone() const = 0;
|
||||
virtual ~TSymbol() { delete [] extensions; }
|
||||
virtual ~TSymbol() { } // rely on all symbol owned memory coming from the pool
|
||||
|
||||
virtual const TString& getName() const { return *name; }
|
||||
virtual void changeName(const TString* newName) { name = newName; }
|
||||
@ -100,8 +100,9 @@ public:
|
||||
virtual void setExtensions(int num, const char* const exts[])
|
||||
{
|
||||
assert(extensions == 0);
|
||||
assert(num > 0);
|
||||
numExtensions = num;
|
||||
extensions = new const char*[numExtensions];
|
||||
extensions = NewPoolObject(exts[0], num);
|
||||
for (int e = 0; e < num; ++e)
|
||||
extensions[e] = exts[e];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user