Add amend ability for anonymous blocks, so they can grow between function bodies.
This commit is contained in:
@@ -2,5 +2,5 @@
|
||||
// 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).
|
||||
|
||||
#define GLSLANG_REVISION "Overload400-PrecQual.1527"
|
||||
#define GLSLANG_REVISION "Overload400-PrecQual.1528"
|
||||
#define GLSLANG_DATE "29-Sep-2016"
|
||||
|
||||
@@ -196,7 +196,7 @@ void TParseContextBase::growGlobalUniformBlock(TSourceLoc& loc, TType& memberTyp
|
||||
TType blockType(new TTypeList, blockName, blockQualifier);
|
||||
TString* instanceName = NewPoolTString("");
|
||||
globalUniformBlock = new TVariable(instanceName, blockType, true);
|
||||
globalUniformBlockAdded = false;
|
||||
firstNewMember = 0;
|
||||
}
|
||||
|
||||
// add the requested member as a member to the block
|
||||
@@ -205,7 +205,6 @@ void TParseContextBase::growGlobalUniformBlock(TSourceLoc& loc, TType& memberTyp
|
||||
type->setFieldName(memberName);
|
||||
TTypeLoc typeLoc = {type, loc};
|
||||
globalUniformBlock->getType().getWritableStruct()->push_back(typeLoc);
|
||||
globalUniformBlockChanged = true;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -218,17 +217,25 @@ bool TParseContextBase::insertGlobalUniformBlock()
|
||||
if (globalUniformBlock == nullptr)
|
||||
return true;
|
||||
|
||||
if (globalUniformBlockAdded)
|
||||
return ! globalUniformBlockChanged;
|
||||
|
||||
globalUniformBlockChanged = false;
|
||||
globalUniformBlockAdded = symbolTable.insert(*globalUniformBlock);
|
||||
if (globalUniformBlockAdded) {
|
||||
intermediate.addSymbolLinkageNode(linkage, *globalUniformBlock);
|
||||
finalizeGlobalUniformBlockLayout(*globalUniformBlock);
|
||||
int numMembers = globalUniformBlock->getType().getStruct()->size();
|
||||
bool inserted;
|
||||
if (firstNewMember == 0) {
|
||||
// This is the first request; we need a normal symbol table insert
|
||||
inserted = symbolTable.insert(*globalUniformBlock);
|
||||
if (inserted)
|
||||
intermediate.addSymbolLinkageNode(linkage, *globalUniformBlock);
|
||||
} else if (firstNewMember <= numMembers) {
|
||||
// This is a follow-on request; we need to amend the first insert
|
||||
inserted = symbolTable.amend(*globalUniformBlock, firstNewMember);
|
||||
}
|
||||
|
||||
return globalUniformBlockAdded;
|
||||
if (inserted) {
|
||||
finalizeGlobalUniformBlockLayout(*globalUniformBlock);
|
||||
firstNewMember = numMembers;
|
||||
}
|
||||
|
||||
return inserted;
|
||||
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
@@ -158,8 +158,7 @@ protected:
|
||||
|
||||
// Manage the global uniform block (default uniforms in GLSL, $Global in HLSL)
|
||||
TVariable* globalUniformBlock; // the actual block, inserted into the symbol table
|
||||
bool globalUniformBlockAdded; // true once inserted into the symbol table
|
||||
bool globalUniformBlockChanged; // true if members have changed
|
||||
int firstNewMember; // the index of the first member not yet inserted into the symbol table
|
||||
// override this to set the language-specific name
|
||||
virtual const char* getGlobalUniformBlockName() { return ""; }
|
||||
virtual void finalizeGlobalUniformBlockLayout(TVariable&) { }
|
||||
|
||||
@@ -147,7 +147,8 @@ public:
|
||||
TVariable(const TString *name, const TType& t, bool uT = false )
|
||||
: TSymbol(name),
|
||||
userType(uT),
|
||||
constSubtree(nullptr) { type.shallowCopy(t); }
|
||||
constSubtree(nullptr),
|
||||
anonId(-1) { type.shallowCopy(t); }
|
||||
virtual TVariable* clone() const;
|
||||
virtual ~TVariable() { }
|
||||
|
||||
@@ -161,6 +162,8 @@ public:
|
||||
virtual void setConstArray(const TConstUnionArray& array) { constArray = array; }
|
||||
virtual void setConstSubtree(TIntermTyped* subtree) { constSubtree = subtree; }
|
||||
virtual TIntermTyped* getConstSubtree() const { return constSubtree; }
|
||||
virtual void setAnonId(int i) { anonId = i; }
|
||||
virtual int getAnonId() const { return anonId; }
|
||||
|
||||
virtual void dump(TInfoSink &infoSink) const;
|
||||
|
||||
@@ -178,6 +181,7 @@ protected:
|
||||
// constant, or neither, but never both.
|
||||
TConstUnionArray constArray; // for compile-time constant value
|
||||
TIntermTyped* constSubtree; // for specialization constant computation
|
||||
int anonId; // the ID used for anonymous blocks: TODO: see if uniqueId could serve a dual purpose
|
||||
};
|
||||
|
||||
//
|
||||
@@ -305,27 +309,16 @@ public:
|
||||
//
|
||||
// returning true means symbol was added to the table with no semantic errors
|
||||
//
|
||||
tInsertResult result;
|
||||
const TString& name = symbol.getName();
|
||||
if (name == "") {
|
||||
symbol.getAsVariable()->setAnonId(anonId++);
|
||||
// An empty name means an anonymous container, exposing its members to the external scope.
|
||||
// Give it a name and insert its members in the symbol table, pointing to the container.
|
||||
char buf[20];
|
||||
snprintf(buf, 20, "%s%d", AnonymousPrefix, anonId);
|
||||
snprintf(buf, 20, "%s%d", AnonymousPrefix, symbol.getAsVariable()->getAnonId());
|
||||
symbol.changeName(NewPoolTString(buf));
|
||||
|
||||
bool isOkay = true;
|
||||
const TTypeList& types = *symbol.getAsVariable()->getType().getStruct();
|
||||
for (unsigned int m = 0; m < types.size(); ++m) {
|
||||
TAnonMember* member = new TAnonMember(&types[m].type->getFieldName(), m, *symbol.getAsVariable(), anonId);
|
||||
result = level.insert(tLevelPair(member->getMangledName(), member));
|
||||
if (! result.second)
|
||||
isOkay = false;
|
||||
}
|
||||
|
||||
++anonId;
|
||||
|
||||
return isOkay;
|
||||
return insertAnonymousMembers(symbol, 0);
|
||||
} else {
|
||||
// Check for redefinition errors:
|
||||
// - STL itself will tell us if there is a direct name collision, with name mangling, at this level
|
||||
@@ -340,14 +333,35 @@ public:
|
||||
level.insert(tLevelPair(insertName, &symbol));
|
||||
|
||||
return true;
|
||||
} else {
|
||||
result = level.insert(tLevelPair(insertName, &symbol));
|
||||
|
||||
return result.second;
|
||||
}
|
||||
} else
|
||||
return level.insert(tLevelPair(insertName, &symbol)).second;
|
||||
}
|
||||
}
|
||||
|
||||
// Add more members to an already inserted aggregate object
|
||||
bool amend(TSymbol& symbol, int firstNewMember)
|
||||
{
|
||||
// See insert() for comments on basic explanation of insert.
|
||||
// This operates similarly, but more simply.
|
||||
// Only supporting amend of anonymous blocks so far.
|
||||
if (IsAnonymous(symbol.getName()))
|
||||
return insertAnonymousMembers(symbol, firstNewMember);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool insertAnonymousMembers(TSymbol& symbol, int firstMember)
|
||||
{
|
||||
const TTypeList& types = *symbol.getAsVariable()->getType().getStruct();
|
||||
for (unsigned int m = firstMember; m < types.size(); ++m) {
|
||||
TAnonMember* member = new TAnonMember(&types[m].type->getFieldName(), m, *symbol.getAsVariable(), symbol.getAsVariable()->getAnonId());
|
||||
if (! level.insert(tLevelPair(member->getMangledName(), member)).second)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TSymbol* find(const TString& name) const
|
||||
{
|
||||
tLevel::const_iterator it = level.find(name);
|
||||
@@ -546,6 +560,14 @@ public:
|
||||
return table[currentLevel()]->insert(symbol, separateNameSpaces);
|
||||
}
|
||||
|
||||
// Add more members to an already inserted aggregate object
|
||||
bool amend(TSymbol& symbol, int firstNewMember)
|
||||
{
|
||||
// See insert() for comments on basic explanation of insert.
|
||||
// This operates similarly, but more simply.
|
||||
return table[currentLevel()]->amend(symbol, firstNewMember);
|
||||
}
|
||||
|
||||
//
|
||||
// To allocate an internal temporary, which will need to be uniquely
|
||||
// identified by the consumer of the AST, but never need to
|
||||
|
||||
Reference in New Issue
Block a user