Replace remaining usage of TName with TSymbol
TName used to contain just a subset of the information stored in
TSymbol. It makes more sense to use TSymbol directly instead of
converting it to TName.
This also improves type safety a bit by making some functions only
take in TVariable or TFunction instead of the more generic TName.
BUG=angleproject:2267
TEST=angle_unittests
Change-Id: Icb46923c25d33ebbbbc06ddc487da25957dda771
Reviewed-on: https://chromium-review.googlesource.com/829143
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/CollectVariables.cpp b/src/compiler/translator/CollectVariables.cpp
index 0c0dba2..846bc64 100644
--- a/src/compiler/translator/CollectVariables.cpp
+++ b/src/compiler/translator/CollectVariables.cpp
@@ -123,16 +123,20 @@
bool visitBinary(Visit visit, TIntermBinary *binaryNode) override;
private:
- std::string getMappedName(const TName &name) const;
+ std::string getMappedName(const TSymbol *symbol) const;
+ void setFieldOrVariableProperties(const TType &type, ShaderVariable *variableOut) const;
+ void setFieldProperties(const TType &type,
+ const TString &name,
+ ShaderVariable *variableOut) const;
void setCommonVariableProperties(const TType &type,
- const TName &name,
+ const TVariable &variable,
ShaderVariable *variableOut) const;
Attribute recordAttribute(const TIntermSymbol &variable) const;
OutputVariable recordOutputVariable(const TIntermSymbol &variable) const;
Varying recordVarying(const TIntermSymbol &variable) const;
- void recordInterfaceBlock(const TString &instanceName,
+ void recordInterfaceBlock(const char *instanceName,
const TType &interfaceBlockType,
InterfaceBlock *interfaceBlock) const;
Uniform recordUniform(const TIntermSymbol &variable) const;
@@ -247,9 +251,9 @@
{
}
-std::string CollectVariablesTraverser::getMappedName(const TName &name) const
+std::string CollectVariablesTraverser::getMappedName(const TSymbol *symbol) const
{
- return HashName(name, mHashFunction, nullptr).c_str();
+ return HashName(symbol, mHashFunction, nullptr).c_str();
}
void CollectVariablesTraverser::setBuiltInInfoFromSymbolTable(const char *name,
@@ -339,14 +343,16 @@
{
ASSERT(symbol != nullptr);
- if (symbol->getName().isInternal())
+ if (symbol->variable().symbolType() == SymbolType::AngleInternal ||
+ symbol->variable().symbolType() == SymbolType::Empty)
{
- // Internal variables are not collected.
+ // Internal variables or nameless variables are not collected.
return;
}
ShaderVariable *var = nullptr;
- const TString &symbolName = symbol->getName().getString();
+
+ const TString &symbolName = symbol->getName();
// Check the qualifier from the variable, not from the symbol node. The node may have a
// different qualifier if it's the result of a folded ternary node.
@@ -556,14 +562,12 @@
}
}
-void CollectVariablesTraverser::setCommonVariableProperties(const TType &type,
- const TName &name,
- ShaderVariable *variableOut) const
+void CollectVariablesTraverser::setFieldOrVariableProperties(const TType &type,
+ ShaderVariable *variableOut) const
{
ASSERT(variableOut);
const TStructure *structure = type.getStruct();
-
if (!structure)
{
variableOut->type = GLVariableType(type);
@@ -585,26 +589,45 @@
// Regardless of the variable type (uniform, in/out etc.) its fields are always plain
// ShaderVariable objects.
ShaderVariable fieldVariable;
- setCommonVariableProperties(*field->type(), TName(field->name()), &fieldVariable);
+ setFieldProperties(*field->type(), field->name(), &fieldVariable);
variableOut->fields.push_back(fieldVariable);
}
}
- variableOut->name = name.getString().c_str();
- variableOut->mappedName = getMappedName(name);
-
if (auto *arraySizes = type.getArraySizes())
{
variableOut->arraySizes.assign(arraySizes->begin(), arraySizes->end());
}
}
+void CollectVariablesTraverser::setFieldProperties(const TType &type,
+ const TString &name,
+ ShaderVariable *variableOut) const
+{
+ ASSERT(variableOut);
+ setFieldOrVariableProperties(type, variableOut);
+ variableOut->name = name.c_str();
+ variableOut->mappedName = HashName(name, mHashFunction, nullptr).c_str();
+}
+
+void CollectVariablesTraverser::setCommonVariableProperties(const TType &type,
+ const TVariable &variable,
+ ShaderVariable *variableOut) const
+{
+ ASSERT(variableOut);
+
+ setFieldOrVariableProperties(type, variableOut);
+ ASSERT(variable.symbolType() != SymbolType::Empty);
+ variableOut->name = variable.name().c_str();
+ variableOut->mappedName = getMappedName(&variable);
+}
+
Attribute CollectVariablesTraverser::recordAttribute(const TIntermSymbol &variable) const
{
const TType &type = variable.getType();
ASSERT(!type.getStruct());
Attribute attribute;
- setCommonVariableProperties(type, variable.getName(), &attribute);
+ setCommonVariableProperties(type, variable.variable(), &attribute);
attribute.location = type.getLayoutQualifier().location;
return attribute;
@@ -616,7 +639,7 @@
ASSERT(!type.getStruct());
OutputVariable outputVariable;
- setCommonVariableProperties(type, variable.getName(), &outputVariable);
+ setCommonVariableProperties(type, variable.variable(), &outputVariable);
outputVariable.location = type.getLayoutQualifier().location;
return outputVariable;
@@ -627,7 +650,7 @@
const TType &type = variable.getType();
Varying varying;
- setCommonVariableProperties(type, variable.getName(), &varying);
+ setCommonVariableProperties(type, variable.variable(), &varying);
varying.location = type.getLayoutQualifier().location;
switch (type.getQualifier())
@@ -639,8 +662,7 @@
case EvqFlatOut:
case EvqCentroidOut:
case EvqGeometryOut:
- if (mSymbolTable->isVaryingInvariant(std::string(variable.getSymbol().c_str())) ||
- type.isInvariant())
+ if (mSymbolTable->isVaryingInvariant(varying.name) || type.isInvariant())
{
varying.isInvariant = true;
}
@@ -654,7 +676,7 @@
}
// TODO(jiawei.shao@intel.com): implement GL_EXT_shader_io_blocks.
-void CollectVariablesTraverser::recordInterfaceBlock(const TString &instanceName,
+void CollectVariablesTraverser::recordInterfaceBlock(const char *instanceName,
const TType &interfaceBlockType,
InterfaceBlock *interfaceBlock) const
{
@@ -664,9 +686,12 @@
const TInterfaceBlock *blockType = interfaceBlockType.getInterfaceBlock();
ASSERT(blockType);
- interfaceBlock->name = blockType->name().c_str();
- interfaceBlock->mappedName = getMappedName(TName(blockType->name()));
- interfaceBlock->instanceName = instanceName.c_str();
+ interfaceBlock->name = blockType->name().c_str();
+ interfaceBlock->mappedName = getMappedName(blockType);
+ if (instanceName != nullptr)
+ {
+ interfaceBlock->instanceName = instanceName;
+ }
ASSERT(!interfaceBlockType.isArrayOfArrays()); // Disallowed by GLSL ES 3.10 section 4.3.9
interfaceBlock->arraySize = interfaceBlockType.isArray() ? interfaceBlockType.getOutermostArraySize() : 0;
@@ -686,7 +711,7 @@
const TType &fieldType = *field->type();
InterfaceBlockField fieldVariable;
- setCommonVariableProperties(fieldType, TName(field->name()), &fieldVariable);
+ setFieldProperties(fieldType, field->name(), &fieldVariable);
fieldVariable.isRowMajorLayout =
(fieldType.getLayoutQualifier().matrixPacking == EmpRowMajor);
interfaceBlock->fields.push_back(fieldVariable);
@@ -696,7 +721,7 @@
Uniform CollectVariablesTraverser::recordUniform(const TIntermSymbol &variable) const
{
Uniform uniform;
- setCommonVariableProperties(variable.getType(), variable.getName(), &uniform);
+ setCommonVariableProperties(variable.getType(), variable.variable(), &uniform);
uniform.binding = variable.getType().getLayoutQualifier().binding;
uniform.location = variable.getType().getLayoutQualifier().location;
uniform.offset = variable.getType().getLayoutQualifier().offset;
@@ -729,7 +754,7 @@
// uniforms, varyings, outputs and interface blocks cannot be initialized in a shader, we
// must have only TIntermSymbol nodes in the sequence in the cases we are interested in.
const TIntermSymbol &variable = *variableNode->getAsSymbolNode();
- if (variable.getName().isInternal())
+ if (variable.variable().symbolType() == SymbolType::AngleInternal)
{
// Internal variables are not collected.
continue;
@@ -739,7 +764,10 @@
if (typedNode.getBasicType() == EbtInterfaceBlock)
{
InterfaceBlock interfaceBlock;
- recordInterfaceBlock(variable.getSymbol(), variable.getType(), &interfaceBlock);
+ recordInterfaceBlock(variable.variable().symbolType() != SymbolType::Empty
+ ? variable.getName().c_str()
+ : nullptr,
+ variable.getType(), &interfaceBlock);
switch (qualifier)
{
@@ -755,6 +783,7 @@
}
else
{
+ ASSERT(variable.variable().symbolType() != SymbolType::Empty);
switch (qualifier)
{
case EvqAttribute: