Clean up TSymbol initialization
Now TSymbol objects always get their id when they are constructed. The
id cannot be changed after the TSymbol is created.
This makes it simpler to insert both mangled and unmangled versions of
a function to the symbol table. These can now both share the same
TSymbol object, unlike before, when inserting the same symbol twice
would have changed its symbol id.
This requires changes to function definition parsing: function
definition nodes now share any symbol created by previous prototype
declarations of the function. The parameters on the symbol get set to
the parameters in the function definition header.
BUG=angleproject:1490
TEST=angle_unittests
Change-Id: I8e600e9b5e5de27d64b85c5042cfd23ff02abe63
Reviewed-on: https://chromium-review.googlesource.com/396838
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/SymbolTable.cpp b/src/compiler/translator/SymbolTable.cpp
index 059c5c7..aa23776 100644
--- a/src/compiler/translator/SymbolTable.cpp
+++ b/src/compiler/translator/SymbolTable.cpp
@@ -21,13 +21,33 @@
int TSymbolTable::uniqueIdCounter = 0;
+TSymbol::TSymbol(const TString *n) : uniqueId(TSymbolTable::nextUniqueId()), name(n)
+{
+}
+
//
// Functions have buried pointers to delete.
//
TFunction::~TFunction()
{
+ clearParameters();
+}
+
+void TFunction::clearParameters()
+{
for (TParamList::iterator i = parameters.begin(); i != parameters.end(); ++i)
delete (*i).type;
+ parameters.clear();
+ mangledName = nullptr;
+}
+
+void TFunction::swapParameters(const TFunction ¶metersSource)
+{
+ clearParameters();
+ for (auto parameter : parametersSource.parameters)
+ {
+ addParameter(parameter);
+ }
}
const TString *TFunction::buildMangledName() const
@@ -53,8 +73,6 @@
bool TSymbolTableLevel::insert(TSymbol *symbol)
{
- symbol->setUniqueId(TSymbolTable::nextUniqueId());
-
// returning true means symbol was added to the table
tInsertResult result = level.insert(tLevelPair(symbol->getMangledName(), symbol));
@@ -63,8 +81,6 @@
bool TSymbolTableLevel::insertUnmangled(TFunction *function)
{
- function->setUniqueId(TSymbolTable::nextUniqueId());
-
// returning true means symbol was added to the table
tInsertResult result = level.insert(tLevelPair(function->getName(), function));