Clean up storing struct types in the symbol table
Instead of storing struct symbols as TVariable objects, store them
as TStructure objects. This way struct type symbols don't need to
store bogus data that's associated with arbitrary types, and on the
other hand the name and unique id of struct types are only stored in
a single place. This change is a refactoring with no effect on
generated output.
BUG=angleproject:2267
TEST=angle_unittests
Change-Id: I173793e0cc77a890cdac6868d72d9f275ac9461a
Reviewed-on: https://chromium-review.googlesource.com/793814
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/SymbolTable.cpp b/src/compiler/translator/SymbolTable.cpp
index 9e7270d..39f4f54 100644
--- a/src/compiler/translator/SymbolTable.cpp
+++ b/src/compiler/translator/SymbolTable.cpp
@@ -30,10 +30,46 @@
} // anonymous namespace
TSymbol::TSymbol(TSymbolTable *symbolTable, const TString *name)
- : mUniqueId(symbolTable->nextUniqueId()), mName(name), mExtension(TExtension::UNDEFINED)
+ : mName(name), mUniqueId(symbolTable->nextUniqueId()), mExtension(TExtension::UNDEFINED)
{
}
+TVariable::TVariable(TSymbolTable *symbolTable, const TString *name, const TType &t)
+ : TSymbol(symbolTable, name), type(t), unionArray(nullptr)
+{
+}
+
+TStructure::TStructure(TSymbolTable *symbolTable, const TString *name, const TFieldList *fields)
+ : TSymbol(symbolTable, name), TFieldListCollection(fields)
+{
+}
+
+void TStructure::createSamplerSymbols(const TString &namePrefix,
+ const TString &apiNamePrefix,
+ TVector<TIntermSymbol *> *outputSymbols,
+ TMap<TIntermSymbol *, TString> *outputSymbolsToAPINames,
+ TSymbolTable *symbolTable) const
+{
+ ASSERT(containsSamplers());
+ for (const auto *field : *mFields)
+ {
+ const TType *fieldType = field->type();
+ if (IsSampler(fieldType->getBasicType()) || fieldType->isStructureContainingSamplers())
+ {
+ TString fieldName = namePrefix + "_" + field->name();
+ TString fieldApiName = apiNamePrefix + "." + field->name();
+ fieldType->createSamplerSymbols(fieldName, fieldApiName, outputSymbols,
+ outputSymbolsToAPINames, symbolTable);
+ }
+ }
+}
+
+void TStructure::setName(const TString &name)
+{
+ TString *mutableName = const_cast<TString *>(mName);
+ *mutableName = name;
+}
+
//
// Functions have buried pointers to delete.
//
@@ -271,7 +307,7 @@
return insertVariable(currentLevel(), name, type);
}
-TVariable *TSymbolTable::declareStructType(TStructure *str)
+bool TSymbolTable::declareStructType(TStructure *str)
{
return insertStructType(currentLevel(), str);
}
@@ -337,15 +373,14 @@
return nullptr;
}
-TVariable *TSymbolTable::insertStructType(ESymbolLevel level, TStructure *str)
+bool TSymbolTable::insertStructType(ESymbolLevel level, TStructure *str)
{
- TVariable *var = new TVariable(this, &str->name(), TType(str), true);
- if (insert(level, var))
+ ASSERT(str);
+ if (insert(level, str))
{
- var->getType().realize();
- return var;
+ return true;
}
- return nullptr;
+ return false;
}
void TSymbolTable::insertBuiltIn(ESymbolLevel level,