Classify TSymbols using an enum
Symbols can be either built-ins, user-defined, nameless, or for
ANGLE's internal use. In addition we currently use TFunction symbols
that are not yet resolved - they might later resolve to either a
built-in or a user-defined function. Record this information in each
TSymbol so that TSymbol contains sufficient information for deciding
how to format symbol names in output.
The goal is to eventually replace current uses of TName with pointers
to different TSymbol objects. So far only built-ins and user-defined
symbols have associated TSymbol objects, but that will be expanded to
cover ANGLE's internal symbols as well.
BUG=angleproject:2267
TEST=angle_unittests
Change-Id: I927ce023fe257cc236da82c127700f3bd72bfe96
Reviewed-on: https://chromium-review.googlesource.com/816952
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/SymbolTable.cpp b/src/compiler/translator/SymbolTable.cpp
index 7a9d57e..5fa8741 100644
--- a/src/compiler/translator/SymbolTable.cpp
+++ b/src/compiler/translator/SymbolTable.cpp
@@ -29,21 +29,32 @@
} // anonymous namespace
-TSymbol::TSymbol(TSymbolTable *symbolTable, const TString *name, TExtension extension)
- : mName(name), mUniqueId(symbolTable->nextUniqueId()), mExtension(extension)
+TSymbol::TSymbol(TSymbolTable *symbolTable,
+ const TString *name,
+ SymbolType symbolType,
+ TExtension extension)
+ : mName(name),
+ mUniqueId(symbolTable->nextUniqueId()),
+ mSymbolType(symbolType),
+ mExtension(extension)
{
+ ASSERT(mSymbolType == SymbolType::BuiltIn || mExtension == TExtension::UNDEFINED);
}
TVariable::TVariable(TSymbolTable *symbolTable,
const TString *name,
const TType &t,
+ SymbolType symbolType,
TExtension extension)
- : TSymbol(symbolTable, name, extension), type(t), unionArray(nullptr)
+ : TSymbol(symbolTable, name, symbolType, extension), type(t), unionArray(nullptr)
{
}
-TStructure::TStructure(TSymbolTable *symbolTable, const TString *name, const TFieldList *fields)
- : TSymbol(symbolTable, name), TFieldListCollection(fields)
+TStructure::TStructure(TSymbolTable *symbolTable,
+ const TString *name,
+ const TFieldList *fields,
+ SymbolType symbolType)
+ : TSymbol(symbolTable, name, symbolType), TFieldListCollection(fields)
{
}
@@ -77,8 +88,9 @@
const TString *name,
const TFieldList *fields,
const TLayoutQualifier &layoutQualifier,
+ SymbolType symbolType,
TExtension extension)
- : TSymbol(symbolTable, name, extension),
+ : TSymbol(symbolTable, name, symbolType, extension),
TFieldListCollection(fields),
mBlockStorage(layoutQualifier.blockStorage),
mBinding(layoutQualifier.binding)
@@ -322,7 +334,7 @@
TVariable *TSymbolTable::declareVariable(const TString *name, const TType &type)
{
- return insertVariable(currentLevel(), name, type);
+ return insertVariable(currentLevel(), name, type, SymbolType::UserDefined);
}
bool TSymbolTable::declareStructType(TStructure *str)
@@ -337,12 +349,16 @@
TVariable *TSymbolTable::insertVariable(ESymbolLevel level, const char *name, const TType &type)
{
- return insertVariable(level, NewPoolTString(name), type);
+ ASSERT(level <= LAST_BUILTIN_LEVEL);
+ return insertVariable(level, NewPoolTString(name), type, SymbolType::BuiltIn);
}
-TVariable *TSymbolTable::insertVariable(ESymbolLevel level, const TString *name, const TType &type)
+TVariable *TSymbolTable::insertVariable(ESymbolLevel level,
+ const TString *name,
+ const TType &type,
+ SymbolType symbolType)
{
- TVariable *var = new TVariable(this, name, type);
+ TVariable *var = new TVariable(this, name, type, symbolType);
if (insert(level, var))
{
// Do lazy initialization for struct types, so we allocate to the current scope.
@@ -360,7 +376,7 @@
const char *name,
const TType &type)
{
- TVariable *var = new TVariable(this, NewPoolTString(name), type, ext);
+ TVariable *var = new TVariable(this, NewPoolTString(name), type, SymbolType::BuiltIn, ext);
if (insert(level, var))
{
if (var->getType().getBasicType() == EbtStruct)
@@ -515,7 +531,8 @@
}
else
{
- TFunction *function = new TFunction(this, NewPoolTString(name), rvalue, op, ext);
+ TFunction *function =
+ new TFunction(this, NewPoolTString(name), rvalue, SymbolType::BuiltIn, op, ext);
function->addParameter(TConstParameter(ptype1));
@@ -581,7 +598,7 @@
const char *name)
{
insertUnmangledBuiltInName(name, level);
- insert(level, new TFunction(this, NewPoolTString(name), rvalue, op));
+ insert(level, new TFunction(this, NewPoolTString(name), rvalue, SymbolType::BuiltIn, op));
}
void TSymbolTable::insertBuiltInFunctionNoParametersExt(ESymbolLevel level,
@@ -591,7 +608,7 @@
const char *name)
{
insertUnmangledBuiltInName(name, level);
- insert(level, new TFunction(this, NewPoolTString(name), rvalue, op, ext));
+ insert(level, new TFunction(this, NewPoolTString(name), rvalue, SymbolType::BuiltIn, op, ext));
}
TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const