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 @@
class TOutputGLSLBase : public TIntermTraverser
{
public:
TOutputGLSLBase(TInfoSinkBase& objSink,
public:
TOutputGLSLBase(TInfoSinkBase &objSink,
ShArrayIndexClampingStrategy clampingStrategy,
ShHashFunction64 hashFunction,
NameMap& nameMap,
NameMap &nameMap,
TSymbolTable& symbolTable,
int shaderVersion);
protected:
TInfoSinkBase& objSink() { return mObjSink; }
void writeTriplet(Visit visit, const char* preStr, const char* inStr, const char* postStr);
void writeVariableType(const TType& type);
protected:
TInfoSinkBase &objSink() { return mObjSink; }
void writeTriplet(Visit visit, const char *preStr, const char *inStr, const char *postStr);
void writeVariableType(const TType &type);
virtual bool writeVariablePrecision(TPrecision precision) = 0;
void writeFunctionParameters(const TIntermSequence& args);
const ConstantUnion* writeConstantUnion(const TType& type, const ConstantUnion* pConstUnion);
TString getTypeName(const TType& type);
void writeFunctionParameters(const TIntermSequence &args);
const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *pConstUnion);
TString getTypeName(const TType &type);
virtual void visitSymbol(TIntermSymbol* node);
virtual void visitConstantUnion(TIntermConstantUnion* node);
virtual bool visitBinary(Visit visit, TIntermBinary* node);
virtual bool visitUnary(Visit visit, TIntermUnary* node);
virtual bool visitSelection(Visit visit, TIntermSelection* node);
virtual bool visitAggregate(Visit visit, TIntermAggregate* node);
virtual bool visitLoop(Visit visit, TIntermLoop* node);
virtual bool visitBranch(Visit visit, TIntermBranch* node);
void visitCodeBlock(TIntermNode* node);
virtual void visitSymbol(TIntermSymbol *node);
virtual void visitConstantUnion(TIntermConstantUnion *node);
virtual bool visitBinary(Visit visit, TIntermBinary *node);
virtual bool visitUnary(Visit visit, TIntermUnary *node);
virtual bool visitSelection(Visit visit, TIntermSelection *node);
virtual bool visitAggregate(Visit visit, TIntermAggregate *node);
virtual bool visitLoop(Visit visit, TIntermLoop *node);
virtual bool visitBranch(Visit visit, TIntermBranch *node);
void visitCodeBlock(TIntermNode *node);
// Return the original name if hash function pointer is NULL;
// otherwise return the hashed name.
TString hashName(const TString& name);
TString hashName(const TString &name);
// 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.
TString hashFunctionName(const TString& mangled_name);
TString hashFunctionName(const TString &mangled_name);
// 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:
bool structDeclared(const TStructure* structure) const;
void declareStruct(const TStructure* structure);
private:
bool structDeclared(const TStructure *structure) const;
void declareStruct(const TStructure *structure);
void pushDeclaredStructsScope();
void popDeclaredStructsScope();
TInfoSinkBase& mObjSink;
void writeBuiltInFunctionTriplet(Visit visit, const char *preStr, bool useEmulatedFunction);
TInfoSinkBase &mObjSink;
bool mDeclaringVariables;
// Structs are declared as the tree is traversed. This list contains all
......@@ -80,9 +81,9 @@ private:
// name hashing.
ShHashFunction64 mHashFunction;
NameMap& mNameMap;
NameMap &mNameMap;
TSymbolTable& mSymbolTable;
TSymbolTable &mSymbolTable;
const int mShaderVersion;
};
......
......@@ -44,12 +44,13 @@ TSymbolTableLevel::~TSymbolTableLevel()
// performance operation, and only intended for symbol tables that
// 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 (it = level.begin(); it != level.end(); ++it) {
if ((*it).second->isFunction()) {
TFunction* function = static_cast<TFunction*>((*it).second);
for (tLevel::iterator it = level.begin(); it != level.end(); ++it)
{
if ((*it).second->isFunction())
{
TFunction *function = static_cast<TFunction*>((*it).second);
if (function->getName() == name)
function->relateToOperator(op);
}
......@@ -62,17 +63,17 @@ void TSymbolTableLevel::relateToOperator(const char* name, TOperator op)
// performance operation, and only intended for symbol tables that
// 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) {
TSymbol* symbol = it->second;
if (symbol->getName() == name) {
for (tLevel::iterator it = level.begin(); it != level.end(); ++it)
{
TSymbol *symbol = it->second;
if (symbol->getName() == name)
symbol->relateToExtension(ext);
}
}
}
TSymbol::TSymbol(const TSymbol& copyOf)
TSymbol::TSymbol(const TSymbol &copyOf)
{
name = NewPoolTString(copyOf.name->c_str());
uniqueId = copyOf.uniqueId;
......@@ -85,8 +86,10 @@ TSymbol *TSymbolTable::find(const TString &name, int shaderVersion, bool *builtI
do
{
if (level == ESSL3_BUILTINS && shaderVersion != 300) level--;
if (level == ESSL1_BUILTINS && shaderVersion != 100) level--;
if (level == ESSL3_BUILTINS && shaderVersion != 300)
level--;
if (level == ESSL1_BUILTINS && shaderVersion != 100)
level--;
symbol = table[level]->find(name);
}
......@@ -104,8 +107,10 @@ TSymbol *TSymbolTable::findBuiltIn(const TString &name, int shaderVersion)
{
for (int level = LAST_BUILTIN_LEVEL; level >= 0; level--)
{
if (level == ESSL3_BUILTINS && shaderVersion != 300) level--;
if (level == ESSL1_BUILTINS && shaderVersion != 100) level--;
if (level == ESSL3_BUILTINS && shaderVersion != 300)
level--;
if (level == ESSL1_BUILTINS && shaderVersion != 100)
level--;
TSymbol *symbol = table[level]->find(name);
......@@ -121,3 +126,92 @@ TSymbolTable::~TSymbolTable()
while (table.size() > 0)
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)
interfaceBlock(0), structure(0)
{
if (p.userDef)
{
structure = p.userDef->getStruct();
}
}
bool TType::equals(const TType &other) const
......@@ -34,13 +32,9 @@ bool TType::equals(const TType &other) const
return false;
}
if (interfaceBlock && !interfaceBlock->equals(*(other.interfaceBlock)))
{
return false;
}
if (structure && !structure->equals(*(other.structure)))
{
return false;
}
return true;
}
......@@ -89,30 +83,77 @@ TString TType::buildMangledName() const
switch (type)
{
case EbtFloat: mangledName += 'f'; break;
case EbtInt: mangledName += 'i'; break;
case EbtUInt: mangledName += 'u'; break;
case EbtBool: mangledName += 'b'; break;
case EbtSampler2D: mangledName += "s2"; break;
case EbtSampler3D: mangledName += "s3"; break;
case EbtSamplerCube: mangledName += "sC"; break;
case EbtSampler2DArray: mangledName += "s2a"; 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();
case EbtFloat:
mangledName += 'f';
break;
case EbtInt:
mangledName += 'i';
break;
case EbtUInt:
mangledName += 'u';
break;
case EbtBool:
mangledName += 'b';
break;
case EbtSampler2D:
mangledName += "s2";
break;
case EbtSampler3D:
mangledName += "s3";
break;
case EbtSamplerCube:
mangledName += "sC";
break;
case EbtSampler2DArray:
mangledName += "s2a";
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())
......@@ -160,8 +201,9 @@ size_t TType::getObjectSize() const
bool TStructure::containsArrays() const
{
for (size_t i = 0; i < mFields->size(); ++i) {
const TType* fieldType = (*mFields)[i]->type();
for (size_t i = 0; i < mFields->size(); ++i)
{
const TType *fieldType = (*mFields)[i]->type();
if (fieldType->isArray() || fieldType->isStructureContainingArrays())
return true;
}
......@@ -183,7 +225,8 @@ TString TFieldListCollection::buildMangledName() const
size_t TFieldListCollection::calculateObjectSize() const
{
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();
if (fieldSize > INT_MAX - size)
size = INT_MAX;
......@@ -196,8 +239,7 @@ size_t TFieldListCollection::calculateObjectSize() const
int TStructure::calculateDeepestNesting() const
{
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());
}
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