Commit 9d30218f by John Kessenich

Generalize the symbol hierarchy to transparently handle anonymous-block members better.

parent 4c706853
......@@ -24,6 +24,7 @@ Link Validation
+ Non ES: value checking of global const initializers
+ Non ES: value checking of uniform initializers
+ Non ES: location match
- gl_TexCoord can only have a max array size of up to gl_MaxTextureCoords
- location aliasing/overlap (except desktop vertex shader inputs)
- 1.0: count the number of uniforms and varyings, compare against limits
+ recursion for functions
......
......@@ -885,6 +885,11 @@ void TIntermediate::addSymbolLinkageNodes(TIntermAggregate*& linkage, EShLanguag
treeRoot = growAggregate(treeRoot, linkage);
}
//
// Add the given name or symbol to the list of nodes at the end of the tree used
// for link-time checking and external linkage.
//
void TIntermediate::addSymbolLinkageNode(TIntermAggregate*& linkage, TSymbolTable& symbolTable, const TString& name)
{
TSymbol* symbol = symbolTable.find(name);
......@@ -892,10 +897,16 @@ void TIntermediate::addSymbolLinkageNode(TIntermAggregate*& linkage, TSymbolTabl
addSymbolLinkageNode(linkage, *symbol->getAsVariable());
}
void TIntermediate::addSymbolLinkageNode(TIntermAggregate*& linkage, const TVariable& variable)
void TIntermediate::addSymbolLinkageNode(TIntermAggregate*& linkage, const TSymbol& symbol)
{
TIntermSymbol* node = new TIntermSymbol(variable.getUniqueId(), variable.getName(), variable.getType());
node->setConstArray(variable.getConstArray());
const TVariable* variable = symbol.getAsVariable();
if (! variable) {
// This must be a member of an anonymous block, and we need to add the whole block
const TAnonMember* anon = symbol.getAsAnonMember();
variable = &anon->getAnonContainer();
}
TIntermSymbol* node = new TIntermSymbol(variable->getUniqueId(), variable->getName(), variable->getType());
node->setConstArray(variable->getConstArray());
linkage = growAggregate(linkage, node);
}
......
......@@ -111,7 +111,7 @@ public:
void precisionQualifierCheck(TSourceLoc, TPublicType&);
void parameterSamplerCheck(TSourceLoc, TStorageQualifier qualifier, const TType& type);
bool containsSampler(const TType& type);
TVariable* redeclareBuiltin(TSourceLoc, const TString&, bool& newDeclaration);
TSymbol* redeclareBuiltin(TSourceLoc, const TString&, bool& newDeclaration);
void paramCheck(TSourceLoc, TStorageQualifier qualifier, TType* type);
void nestedBlockCheck(TSourceLoc);
void nestedStructCheck(TSourceLoc);
......@@ -139,7 +139,7 @@ public:
TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc);
TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc);
bool arraySetMaxSize(TSourceLoc, TIntermSymbol*, int);
void updateMaxArraySize(TSourceLoc, TIntermNode*, int index);
void setScanContext(TScanContext* c) { scanContext = c; }
TScanContext* getScanContext() const { return scanContext; }
......@@ -164,7 +164,7 @@ protected:
const char* getPreamble();
void nonInitConstCheck(TSourceLoc, TString& identifier, TType& type);
TVariable* declareNonArray(TSourceLoc, TString& identifier, TType&, bool& newDeclaration);
void declareArray(TSourceLoc, TString& identifier, const TType&, TVariable*&, bool& newDeclaration);
void declareArray(TSourceLoc, TString& identifier, const TType&, TSymbol*&, bool& newDeclaration);
TIntermNode* executeInitializer(TSourceLoc, TString& identifier, TIntermTyped* initializer, TVariable* variable);
TOperator mapTypeToConstructorOp(const TType&);
......
......@@ -240,7 +240,7 @@ TVariable::TVariable(const TVariable& copyOf) : TSymbol(copyOf)
}
}
TVariable* TVariable::clone()
TVariable* TVariable::clone() const
{
TVariable *variable = new TVariable(*this);
......@@ -261,28 +261,45 @@ TFunction::TFunction(const TFunction& copyOf) : TSymbol(copyOf)
defined = copyOf.defined;
}
TFunction* TFunction::clone()
TFunction* TFunction::clone() const
{
TFunction *function = new TFunction(*this);
return function;
}
TAnonMember* TAnonMember::clone()
TAnonMember* TAnonMember::clone() const
{
// need to implement this once built-in symbols include interface blocks
// Anonymous members of a given block should be cloned at a higher level,
// where they can all be assured to still end up pointing to a single
// copy of the original container.
assert(0);
return 0;
}
TSymbolTableLevel* TSymbolTableLevel::clone()
TSymbolTableLevel* TSymbolTableLevel::clone() const
{
TSymbolTableLevel *symTableLevel = new TSymbolTableLevel();
symTableLevel->anonId = anonId;
tLevel::iterator iter;
for (iter = level.begin(); iter != level.end(); ++iter)
symTableLevel->insert(*iter->second->clone());
std::vector<bool> containerCopied(anonId, false);
tLevel::const_iterator iter;
for (iter = level.begin(); iter != level.end(); ++iter) {
const TAnonMember* anon = iter->second->getAsAnonMember();
if (anon) {
// Insert all the anonymous members of this same container at once,
// avoid inserting the other members in the future, once this has been done,
// allowing them to all be part of the same new container.
if (! containerCopied[anon->getAnonId()]) {
TVariable* container = anon->getAnonContainer().clone();
container->changeName(NewPoolTString(""));
// insert the whole container
symTableLevel->insert(*container);
containerCopied[anon->getAnonId()] = true;
}
} else
symTableLevel->insert(*iter->second->clone());
}
return symTableLevel;
}
......
......@@ -2378,7 +2378,7 @@ function_definition
parseContext.error($1.loc, "function does not return a value:", "", $1.function->getName().c_str());
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
$$ = parseContext.intermediate.growAggregate($1.intermAggregate, $3);
parseContext.intermediate.setAggregateOperator($$, EOpFunction, $1.function->getReturnType(), $1.loc);
parseContext.intermediate.setAggregateOperator($$, EOpFunction, $1.function->getType(), $1.loc);
$$->getAsAggregate()->setName($1.function->getMangledName().c_str());
// store the pragma information for debug and optimize and other vendor specific
......
......@@ -49,7 +49,7 @@ struct TVectorFields {
};
class TSymbolTable;
class TVariable;
class TSymbol;
//
// Set of helper functions to help parse and build the tree.
......@@ -97,7 +97,7 @@ public:
bool postProcess(TIntermNode*, EShLanguage);
void addSymbolLinkageNodes(TIntermAggregate*& linkage, EShLanguage, TSymbolTable&);
void addSymbolLinkageNode(TIntermAggregate*& linkage, TSymbolTable&, const TString&);
void addSymbolLinkageNode(TIntermAggregate*& linkage, const TVariable&);
void addSymbolLinkageNode(TIntermAggregate*& linkage, const TSymbol&);
void addToCallGraph(TInfoSink&, const TString& caller, const TString& callee);
void merge(TInfoSink&, TIntermediate&);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment