Commit 9eedea03 by Zhenyao Mo

Fix code styles in OutputGLSLBase, SymbolTable, and Types.

I came across these three classes in the last CL, so do some cleanup as I touched these classes. BUG= TEST=webgl conformance, no regressions Change-Id: I2819bab5965fcb4917f85c2eded571a7f95ab9a2 Reviewed-on: https://chromium-review.googlesource.com/199423Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tested-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent 487456a3
...@@ -15,52 +15,53 @@ ...@@ -15,52 +15,53 @@
class TOutputGLSLBase : public TIntermTraverser class TOutputGLSLBase : public TIntermTraverser
{ {
public: public:
TOutputGLSLBase(TInfoSinkBase& objSink, TOutputGLSLBase(TInfoSinkBase &objSink,
ShArrayIndexClampingStrategy clampingStrategy, ShArrayIndexClampingStrategy clampingStrategy,
ShHashFunction64 hashFunction, ShHashFunction64 hashFunction,
NameMap& nameMap, NameMap &nameMap,
TSymbolTable& symbolTable, TSymbolTable& symbolTable,
int shaderVersion); int shaderVersion);
protected: protected:
TInfoSinkBase& objSink() { return mObjSink; } TInfoSinkBase &objSink() { return mObjSink; }
void writeTriplet(Visit visit, const char* preStr, const char* inStr, const char* postStr); void writeTriplet(Visit visit, const char *preStr, const char *inStr, const char *postStr);
void writeVariableType(const TType& type); void writeVariableType(const TType &type);
virtual bool writeVariablePrecision(TPrecision precision) = 0; virtual bool writeVariablePrecision(TPrecision precision) = 0;
void writeFunctionParameters(const TIntermSequence& args); void writeFunctionParameters(const TIntermSequence &args);
const ConstantUnion* writeConstantUnion(const TType& type, const ConstantUnion* pConstUnion); const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *pConstUnion);
TString getTypeName(const TType& type); TString getTypeName(const TType &type);
virtual void visitSymbol(TIntermSymbol* node); virtual void visitSymbol(TIntermSymbol *node);
virtual void visitConstantUnion(TIntermConstantUnion* node); virtual void visitConstantUnion(TIntermConstantUnion *node);
virtual bool visitBinary(Visit visit, TIntermBinary* node); virtual bool visitBinary(Visit visit, TIntermBinary *node);
virtual bool visitUnary(Visit visit, TIntermUnary* node); virtual bool visitUnary(Visit visit, TIntermUnary *node);
virtual bool visitSelection(Visit visit, TIntermSelection* node); virtual bool visitSelection(Visit visit, TIntermSelection *node);
virtual bool visitAggregate(Visit visit, TIntermAggregate* node); virtual bool visitAggregate(Visit visit, TIntermAggregate *node);
virtual bool visitLoop(Visit visit, TIntermLoop* node); virtual bool visitLoop(Visit visit, TIntermLoop *node);
virtual bool visitBranch(Visit visit, TIntermBranch* node); virtual bool visitBranch(Visit visit, TIntermBranch *node);
void visitCodeBlock(TIntermNode* node);
void visitCodeBlock(TIntermNode *node);
// Return the original name if hash function pointer is NULL; // Return the original name if hash function pointer is NULL;
// otherwise return the hashed name. // otherwise return the hashed name.
TString hashName(const TString& name); TString hashName(const TString &name);
// Same as hashName(), but without hashing built-in variables. // Same as hashName(), but without hashing built-in variables.
TString hashVariableName(const TString& name); TString hashVariableName(const TString &name);
// Same as hashName(), but without hashing built-in functions. // Same as hashName(), but without hashing built-in functions.
TString hashFunctionName(const TString& mangled_name); TString hashFunctionName(const TString &mangled_name);
// Used to translate function names for differences between ESSL and GLSL // Used to translate function names for differences between ESSL and GLSL
virtual TString translateTextureFunction(TString& name) { return name; } virtual TString translateTextureFunction(TString &name) { return name; }
private: private:
bool structDeclared(const TStructure* structure) const; bool structDeclared(const TStructure *structure) const;
void declareStruct(const TStructure* structure); void declareStruct(const TStructure *structure);
void pushDeclaredStructsScope(); void pushDeclaredStructsScope();
void popDeclaredStructsScope(); void popDeclaredStructsScope();
TInfoSinkBase& mObjSink; void writeBuiltInFunctionTriplet(Visit visit, const char *preStr, bool useEmulatedFunction);
TInfoSinkBase &mObjSink;
bool mDeclaringVariables; bool mDeclaringVariables;
// Structs are declared as the tree is traversed. This list contains all // Structs are declared as the tree is traversed. This list contains all
...@@ -80,9 +81,9 @@ private: ...@@ -80,9 +81,9 @@ private:
// name hashing. // name hashing.
ShHashFunction64 mHashFunction; ShHashFunction64 mHashFunction;
NameMap& mNameMap; NameMap &mNameMap;
TSymbolTable& mSymbolTable; TSymbolTable &mSymbolTable;
const int mShaderVersion; const int mShaderVersion;
}; };
......
...@@ -44,12 +44,13 @@ TSymbolTableLevel::~TSymbolTableLevel() ...@@ -44,12 +44,13 @@ TSymbolTableLevel::~TSymbolTableLevel()
// performance operation, and only intended for symbol tables that // performance operation, and only intended for symbol tables that
// live across a large number of compiles. // live across a large number of compiles.
// //
void TSymbolTableLevel::relateToOperator(const char* name, TOperator op) void TSymbolTableLevel::relateToOperator(const char *name, TOperator op)
{ {
tLevel::iterator it; for (tLevel::iterator it = level.begin(); it != level.end(); ++it)
for (it = level.begin(); it != level.end(); ++it) { {
if ((*it).second->isFunction()) { if ((*it).second->isFunction())
TFunction* function = static_cast<TFunction*>((*it).second); {
TFunction *function = static_cast<TFunction*>((*it).second);
if (function->getName() == name) if (function->getName() == name)
function->relateToOperator(op); function->relateToOperator(op);
} }
...@@ -62,17 +63,17 @@ void TSymbolTableLevel::relateToOperator(const char* name, TOperator op) ...@@ -62,17 +63,17 @@ void TSymbolTableLevel::relateToOperator(const char* name, TOperator op)
// performance operation, and only intended for symbol tables that // performance operation, and only intended for symbol tables that
// live across a large number of compiles. // live across a large number of compiles.
// //
void TSymbolTableLevel::relateToExtension(const char* name, const TString& ext) void TSymbolTableLevel::relateToExtension(const char *name, const TString &ext)
{ {
for (tLevel::iterator it = level.begin(); it != level.end(); ++it) { for (tLevel::iterator it = level.begin(); it != level.end(); ++it)
TSymbol* symbol = it->second; {
if (symbol->getName() == name) { TSymbol *symbol = it->second;
if (symbol->getName() == name)
symbol->relateToExtension(ext); symbol->relateToExtension(ext);
}
} }
} }
TSymbol::TSymbol(const TSymbol& copyOf) TSymbol::TSymbol(const TSymbol &copyOf)
{ {
name = NewPoolTString(copyOf.name->c_str()); name = NewPoolTString(copyOf.name->c_str());
uniqueId = copyOf.uniqueId; uniqueId = copyOf.uniqueId;
...@@ -85,8 +86,10 @@ TSymbol *TSymbolTable::find(const TString &name, int shaderVersion, bool *builtI ...@@ -85,8 +86,10 @@ TSymbol *TSymbolTable::find(const TString &name, int shaderVersion, bool *builtI
do do
{ {
if (level == ESSL3_BUILTINS && shaderVersion != 300) level--; if (level == ESSL3_BUILTINS && shaderVersion != 300)
if (level == ESSL1_BUILTINS && shaderVersion != 100) level--; level--;
if (level == ESSL1_BUILTINS && shaderVersion != 100)
level--;
symbol = table[level]->find(name); symbol = table[level]->find(name);
} }
...@@ -104,8 +107,10 @@ TSymbol *TSymbolTable::findBuiltIn(const TString &name, int shaderVersion) ...@@ -104,8 +107,10 @@ TSymbol *TSymbolTable::findBuiltIn(const TString &name, int shaderVersion)
{ {
for (int level = LAST_BUILTIN_LEVEL; level >= 0; level--) for (int level = LAST_BUILTIN_LEVEL; level >= 0; level--)
{ {
if (level == ESSL3_BUILTINS && shaderVersion != 300) level--; if (level == ESSL3_BUILTINS && shaderVersion != 300)
if (level == ESSL1_BUILTINS && shaderVersion != 100) level--; level--;
if (level == ESSL1_BUILTINS && shaderVersion != 100)
level--;
TSymbol *symbol = table[level]->find(name); TSymbol *symbol = table[level]->find(name);
...@@ -121,3 +126,92 @@ TSymbolTable::~TSymbolTable() ...@@ -121,3 +126,92 @@ TSymbolTable::~TSymbolTable()
while (table.size() > 0) while (table.size() > 0)
pop(); pop();
} }
void TSymbolTable::insertBuiltIn(
ESymbolLevel level, TType *rvalue, const char *name,
TType *ptype1, TType *ptype2, TType *ptype3, TType *ptype4, TType *ptype5)
{
if (ptype1->getBasicType() == EbtGSampler2D)
{
bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name,
new TType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name,
new TType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name,
new TType(EbtUSampler2D), ptype2, ptype3, ptype4, ptype5);
return;
}
if (ptype1->getBasicType() == EbtGSampler3D)
{
bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name,
new TType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name,
new TType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name,
new TType(EbtUSampler3D), ptype2, ptype3, ptype4, ptype5);
return;
}
if (ptype1->getBasicType() == EbtGSamplerCube)
{
bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name,
new TType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name,
new TType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name,
new TType(EbtUSamplerCube), ptype2, ptype3, ptype4, ptype5);
return;
}
if (ptype1->getBasicType() == EbtGSampler2DArray)
{
bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name,
new TType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name,
new TType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name,
new TType(EbtUSampler2DArray), ptype2, ptype3, ptype4, ptype5);
return;
}
TFunction *function = new TFunction(NewPoolTString(name), *rvalue);
TType *types[] = {ptype1, ptype2, ptype3, ptype4, ptype5};
for (size_t ii = 0; ii < sizeof(types) / sizeof(types[0]); ++ii)
{
if (types[ii])
{
TParameter param = {NULL, types[ii]};
function->addParameter(param);
}
}
insert(level, *function);
}
TPrecision TSymbolTable::getDefaultPrecision(TBasicType type)
{
if (!SupportsPrecision(type))
return EbpUndefined;
// unsigned integers use the same precision as signed
TBasicType baseType = (type == EbtUInt) ? EbtInt : type;
int level = static_cast<int>(precisionStack.size()) - 1;
assert(level >= 0); // Just to be safe. Should not happen.
// If we dont find anything we return this. Should we error check this?
TPrecision prec = EbpUndefined;
while (level >= 0)
{
PrecisionStackLevel::iterator it = precisionStack[level]->find(baseType);
if (it != precisionStack[level]->end())
{
prec = (*it).second;
break;
}
level--;
}
return prec;
}
...@@ -19,9 +19,7 @@ TType::TType(const TPublicType &p) ...@@ -19,9 +19,7 @@ TType::TType(const TPublicType &p)
interfaceBlock(0), structure(0) interfaceBlock(0), structure(0)
{ {
if (p.userDef) if (p.userDef)
{
structure = p.userDef->getStruct(); structure = p.userDef->getStruct();
}
} }
bool TType::equals(const TType &other) const bool TType::equals(const TType &other) const
...@@ -34,13 +32,9 @@ bool TType::equals(const TType &other) const ...@@ -34,13 +32,9 @@ bool TType::equals(const TType &other) const
return false; return false;
} }
if (interfaceBlock && !interfaceBlock->equals(*(other.interfaceBlock))) if (interfaceBlock && !interfaceBlock->equals(*(other.interfaceBlock)))
{
return false; return false;
}
if (structure && !structure->equals(*(other.structure))) if (structure && !structure->equals(*(other.structure)))
{
return false; return false;
}
return true; return true;
} }
...@@ -89,30 +83,77 @@ TString TType::buildMangledName() const ...@@ -89,30 +83,77 @@ TString TType::buildMangledName() const
switch (type) switch (type)
{ {
case EbtFloat: mangledName += 'f'; break; case EbtFloat:
case EbtInt: mangledName += 'i'; break; mangledName += 'f';
case EbtUInt: mangledName += 'u'; break; break;
case EbtBool: mangledName += 'b'; break; case EbtInt:
case EbtSampler2D: mangledName += "s2"; break; mangledName += 'i';
case EbtSampler3D: mangledName += "s3"; break; break;
case EbtSamplerCube: mangledName += "sC"; break; case EbtUInt:
case EbtSampler2DArray: mangledName += "s2a"; break; mangledName += 'u';
case EbtSamplerExternalOES: mangledName += "sext"; break; break;
case EbtSampler2DRect: mangledName += "s2r"; break; case EbtBool:
case EbtISampler2D: mangledName += "is2"; break; mangledName += 'b';
case EbtISampler3D: mangledName += "is3"; break; break;
case EbtISamplerCube: mangledName += "isC"; break; case EbtSampler2D:
case EbtISampler2DArray: mangledName += "is2a"; break; mangledName += "s2";
case EbtUSampler2D: mangledName += "us2"; break; break;
case EbtUSampler3D: mangledName += "us3"; break; case EbtSampler3D:
case EbtUSamplerCube: mangledName += "usC"; break; mangledName += "s3";
case EbtUSampler2DArray: mangledName += "us2a"; break; break;
case EbtSampler2DShadow: mangledName += "s2s"; break; case EbtSamplerCube:
case EbtSamplerCubeShadow: mangledName += "sCs"; break; mangledName += "sC";
case EbtSampler2DArrayShadow: mangledName += "s2as"; break; break;
case EbtStruct: mangledName += structure->mangledName(); break; case EbtSampler2DArray:
case EbtInterfaceBlock: mangledName += interfaceBlock->mangledName(); break; mangledName += "s2a";
default: UNREACHABLE(); break;
case EbtSamplerExternalOES:
mangledName += "sext";
break;
case EbtSampler2DRect:
mangledName += "s2r";
break;
case EbtISampler2D:
mangledName += "is2";
break;
case EbtISampler3D:
mangledName += "is3";
break;
case EbtISamplerCube:
mangledName += "isC";
break;
case EbtISampler2DArray:
mangledName += "is2a";
break;
case EbtUSampler2D:
mangledName += "us2";
break;
case EbtUSampler3D:
mangledName += "us3";
break;
case EbtUSamplerCube:
mangledName += "usC";
break;
case EbtUSampler2DArray:
mangledName += "us2a";
break;
case EbtSampler2DShadow:
mangledName += "s2s";
break;
case EbtSamplerCubeShadow:
mangledName += "sCs";
break;
case EbtSampler2DArrayShadow:
mangledName += "s2as";
break;
case EbtStruct:
mangledName += structure->mangledName();
break;
case EbtInterfaceBlock:
mangledName += interfaceBlock->mangledName();
break;
default:
UNREACHABLE();
} }
if (isMatrix()) if (isMatrix())
...@@ -160,8 +201,9 @@ size_t TType::getObjectSize() const ...@@ -160,8 +201,9 @@ size_t TType::getObjectSize() const
bool TStructure::containsArrays() const bool TStructure::containsArrays() const
{ {
for (size_t i = 0; i < mFields->size(); ++i) { for (size_t i = 0; i < mFields->size(); ++i)
const TType* fieldType = (*mFields)[i]->type(); {
const TType *fieldType = (*mFields)[i]->type();
if (fieldType->isArray() || fieldType->isStructureContainingArrays()) if (fieldType->isArray() || fieldType->isStructureContainingArrays())
return true; return true;
} }
...@@ -183,7 +225,8 @@ TString TFieldListCollection::buildMangledName() const ...@@ -183,7 +225,8 @@ TString TFieldListCollection::buildMangledName() const
size_t TFieldListCollection::calculateObjectSize() const size_t TFieldListCollection::calculateObjectSize() const
{ {
size_t size = 0; size_t size = 0;
for (size_t i = 0; i < mFields->size(); ++i) { for (size_t i = 0; i < mFields->size(); ++i)
{
size_t fieldSize = (*mFields)[i]->type()->getObjectSize(); size_t fieldSize = (*mFields)[i]->type()->getObjectSize();
if (fieldSize > INT_MAX - size) if (fieldSize > INT_MAX - size)
size = INT_MAX; size = INT_MAX;
...@@ -196,8 +239,7 @@ size_t TFieldListCollection::calculateObjectSize() const ...@@ -196,8 +239,7 @@ size_t TFieldListCollection::calculateObjectSize() const
int TStructure::calculateDeepestNesting() const int TStructure::calculateDeepestNesting() const
{ {
int maxNesting = 0; int maxNesting = 0;
for (size_t i = 0; i < mFields->size(); ++i) { for (size_t i = 0; i < mFields->size(); ++i)
maxNesting = std::max(maxNesting, (*mFields)[i]->type()->getDeepestStructNesting()); maxNesting = std::max(maxNesting, (*mFields)[i]->type()->getDeepestStructNesting());
}
return 1 + maxNesting; return 1 + maxNesting;
} }
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