Commit 58e54298 by alokp@chromium.org

Cleanup TType and related classes:

1. Removed unused functions 2. Removed unnecessary virtuality of functions 3. Grouped related functions together TEST=conformance tests Review URL: http://codereview.appspot.com/1984047 git-svn-id: https://angleproject.googlecode.com/svn/trunk@400 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 1ac37d80
...@@ -47,6 +47,21 @@ enum TBasicType ...@@ -47,6 +47,21 @@ enum TBasicType
EbtAddress, // should be deprecated?? EbtAddress, // should be deprecated??
}; };
inline const char* getBasicString(TBasicType t)
{
switch (t)
{
case EbtVoid: return "void"; break;
case EbtFloat: return "float"; break;
case EbtInt: return "int"; break;
case EbtBool: return "bool"; break;
case EbtSampler2D: return "sampler2D"; break;
case EbtSamplerCube: return "samplerCube"; break;
case EbtStruct: return "structure"; break;
default: return "unknown type";
}
}
inline bool IsSampler(TBasicType type) inline bool IsSampler(TBasicType type)
{ {
return type > EbtGuardSamplerBegin && type < EbtGuardSamplerEnd; return type > EbtGuardSamplerBegin && type < EbtGuardSamplerEnd;
......
...@@ -591,16 +591,16 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource ...@@ -591,16 +591,16 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource
symbolTable.relateToOperator("all", EOpAll); symbolTable.relateToOperator("all", EOpAll);
// Map language-specific operators. // Map language-specific operators.
switch(language) { switch(language) {
case EShLangVertex: case EShLangVertex:
break; break;
case EShLangFragment: case EShLangFragment:
//symbolTable.relateToOperator("dFdx", EOpDPdx); // OES_standard_derivatives extension //symbolTable.relateToOperator("dFdx", EOpDPdx); // OES_standard_derivatives extension
//symbolTable.relateToOperator("dFdy", EOpDPdy); // OES_standard_derivatives extension //symbolTable.relateToOperator("dFdy", EOpDPdy); // OES_standard_derivatives extension
//symbolTable.relateToOperator("fwidth", EOpFwidth); // OES_standard_derivatives extension //symbolTable.relateToOperator("fwidth", EOpFwidth); // OES_standard_derivatives extension
break; break;
default: break; default: break;
} }
// Finally add resource-specific variables. // Finally add resource-specific variables.
switch(language) { switch(language) {
......
...@@ -303,7 +303,7 @@ TIntermAggregate* TIntermediate::setAggregateOperator(TIntermNode* node, TOperat ...@@ -303,7 +303,7 @@ TIntermAggregate* TIntermediate::setAggregateOperator(TIntermNode* node, TOperat
// //
// Set the operator. // Set the operator.
// //
aggNode->setOperator(op); aggNode->setOp(op);
if (line != 0) if (line != 0)
aggNode->setLine(line); aggNode->setLine(line);
...@@ -515,9 +515,9 @@ TIntermTyped* TIntermediate::addComma(TIntermTyped* left, TIntermTyped* right, T ...@@ -515,9 +515,9 @@ TIntermTyped* TIntermediate::addComma(TIntermTyped* left, TIntermTyped* right, T
return right; return right;
} else { } else {
TIntermTyped *commaAggregate = growAggregate(left, right, line); TIntermTyped *commaAggregate = growAggregate(left, right, line);
commaAggregate->getAsAggregate()->setOperator(EOpComma); commaAggregate->getAsAggregate()->setOp(EOpComma);
commaAggregate->setType(right->getType()); commaAggregate->setType(right->getType());
commaAggregate->getTypePointer()->changeQualifier(EvqTemporary); commaAggregate->getTypePointer()->setQualifier(EvqTemporary);
return commaAggregate; return commaAggregate;
} }
} }
...@@ -640,7 +640,7 @@ bool TIntermediate::postProcess(TIntermNode* root, EShLanguage language) ...@@ -640,7 +640,7 @@ bool TIntermediate::postProcess(TIntermNode* root, EShLanguage language)
// //
TIntermAggregate* aggRoot = root->getAsAggregate(); TIntermAggregate* aggRoot = root->getAsAggregate();
if (aggRoot && aggRoot->getOp() == EOpNull) if (aggRoot && aggRoot->getOp() == EOpNull)
aggRoot->setOperator(EOpSequence); aggRoot->setOp(EOpSequence);
return true; return true;
} }
...@@ -773,12 +773,12 @@ bool TIntermBinary::promote(TInfoSink& infoSink) ...@@ -773,12 +773,12 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
// The result gets promoted to the highest precision. // The result gets promoted to the highest precision.
TPrecision higherPrecision = GetHigherPrecision(left->getPrecision(), right->getPrecision()); TPrecision higherPrecision = GetHigherPrecision(left->getPrecision(), right->getPrecision());
getTypePointer()->changePrecision(higherPrecision); getTypePointer()->setPrecision(higherPrecision);
// Binary operations results in temporary variables unless both // Binary operations results in temporary variables unless both
// operands are const. // operands are const.
if (left->getQualifier() != EvqConst || right->getQualifier() != EvqConst) { if (left->getQualifier() != EvqConst || right->getQualifier() != EvqConst) {
getTypePointer()->changeQualifier(EvqTemporary); getTypePointer()->setQualifier(EvqTemporary);
} }
// //
...@@ -964,7 +964,7 @@ bool TIntermBinary::promote(TInfoSink& infoSink) ...@@ -964,7 +964,7 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
bool CompareStruct(const TType& leftNodeType, ConstantUnion* rightUnionArray, ConstantUnion* leftUnionArray) bool CompareStruct(const TType& leftNodeType, ConstantUnion* rightUnionArray, ConstantUnion* leftUnionArray)
{ {
TTypeList* fields = leftNodeType.getStruct(); const TTypeList* fields = leftNodeType.getStruct();
size_t structSize = fields->size(); size_t structSize = fields->size();
int index = 0; int index = 0;
......
...@@ -791,11 +791,11 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -791,11 +791,11 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
{ {
if (node->getLeft()->isMatrix()) if (node->getLeft()->isMatrix())
{ {
switch (node->getLeft()->getSize()) switch (node->getLeft()->getNominalSize())
{ {
case 2 * 2: mUsesEqualMat2 = true; break; case 2: mUsesEqualMat2 = true; break;
case 3 * 3: mUsesEqualMat3 = true; break; case 3: mUsesEqualMat3 = true; break;
case 4 * 4: mUsesEqualMat4 = true; break; case 4: mUsesEqualMat4 = true; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
...@@ -804,7 +804,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -804,7 +804,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
switch (node->getLeft()->getBasicType()) switch (node->getLeft()->getBasicType())
{ {
case EbtFloat: case EbtFloat:
switch (node->getLeft()->getSize()) switch (node->getLeft()->getNominalSize())
{ {
case 2: mUsesEqualVec2 = true; break; case 2: mUsesEqualVec2 = true; break;
case 3: mUsesEqualVec3 = true; break; case 3: mUsesEqualVec3 = true; break;
...@@ -813,7 +813,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -813,7 +813,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
} }
break; break;
case EbtInt: case EbtInt:
switch (node->getLeft()->getSize()) switch (node->getLeft()->getNominalSize())
{ {
case 2: mUsesEqualIVec2 = true; break; case 2: mUsesEqualIVec2 = true; break;
case 3: mUsesEqualIVec3 = true; break; case 3: mUsesEqualIVec3 = true; break;
...@@ -822,7 +822,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -822,7 +822,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
} }
break; break;
case EbtBool: case EbtBool:
switch (node->getLeft()->getSize()) switch (node->getLeft()->getNominalSize())
{ {
case 2: mUsesEqualBVec2 = true; break; case 2: mUsesEqualBVec2 = true; break;
case 3: mUsesEqualBVec3 = true; break; case 3: mUsesEqualBVec3 = true; break;
...@@ -1288,7 +1288,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1288,7 +1288,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpVectorNotEqual: outputTriplet(visit, "(", " != ", ")"); break; case EOpVectorNotEqual: outputTriplet(visit, "(", " != ", ")"); break;
case EOpMod: case EOpMod:
{ {
switch (node->getSequence()[0]->getAsTyped()->getSize()) // Number of components in the first argument switch (node->getSequence()[0]->getAsTyped()->getNominalSize()) // Number of components in the first argument
{ {
case 1: mUsesMod1 = true; break; case 1: mUsesMod1 = true; break;
case 2: mUsesMod2 = true; break; case 2: mUsesMod2 = true; break;
...@@ -1317,7 +1317,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1317,7 +1317,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpCross: outputTriplet(visit, "cross(", ", ", ")"); break; case EOpCross: outputTriplet(visit, "cross(", ", ", ")"); break;
case EOpFaceForward: case EOpFaceForward:
{ {
switch (node->getSequence()[0]->getAsTyped()->getSize()) // Number of components in the first argument switch (node->getSequence()[0]->getAsTyped()->getNominalSize()) // Number of components in the first argument
{ {
case 1: mUsesFaceforward1 = true; break; case 1: mUsesFaceforward1 = true; break;
case 2: mUsesFaceforward2 = true; break; case 2: mUsesFaceforward2 = true; break;
...@@ -1553,7 +1553,7 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node) ...@@ -1553,7 +1553,7 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node)
if (symbol && constant) if (symbol && constant)
{ {
if (constant->getBasicType() == EbtInt && constant->getSize() == 1) if (constant->getBasicType() == EbtInt && constant->getNominalSize() == 1)
{ {
index = symbol; index = symbol;
initial = constant->getUnionArrayPointer()[0].getIConst(); initial = constant->getUnionArrayPointer()[0].getIConst();
...@@ -1575,7 +1575,7 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node) ...@@ -1575,7 +1575,7 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node)
if (constant) if (constant)
{ {
if (constant->getBasicType() == EbtInt && constant->getSize() == 1) if (constant->getBasicType() == EbtInt && constant->getNominalSize() == 1)
{ {
comparator = test->getOp(); comparator = test->getOp();
limit = constant->getUnionArrayPointer()[0].getIConst(); limit = constant->getUnionArrayPointer()[0].getIConst();
...@@ -1597,7 +1597,7 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node) ...@@ -1597,7 +1597,7 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node)
if (constant) if (constant)
{ {
if (constant->getBasicType() == EbtInt && constant->getSize() == 1) if (constant->getBasicType() == EbtInt && constant->getNominalSize() == 1)
{ {
int value = constant->getUnionArrayPointer()[0].getIConst(); int value = constant->getUnionArrayPointer()[0].getIConst();
...@@ -1848,8 +1848,8 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI ...@@ -1848,8 +1848,8 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI
TType ctorType = type; TType ctorType = type;
ctorType.clearArrayness(); ctorType.clearArrayness();
ctorType.changePrecision(EbpHigh); ctorType.setPrecision(EbpHigh);
ctorType.changeQualifier(EvqTemporary); ctorType.setQualifier(EvqTemporary);
TString ctorName = type.getStruct() ? decorate(name) : name; TString ctorName = type.getStruct() ? decorate(name) : name;
......
...@@ -486,7 +486,7 @@ bool TParseContext::constructorErrorCheck(int line, TIntermNode* node, TFunction ...@@ -486,7 +486,7 @@ bool TParseContext::constructorErrorCheck(int line, TIntermNode* node, TFunction
} }
if (constType) if (constType)
type->changeQualifier(EvqConst); type->setQualifier(EvqConst);
if (type->isArray() && type->getArraySize() != function.getParamCount()) { if (type->isArray() && type->getArraySize() != function.getParamCount()) {
error(line, "array constructor needs one argument per array element", "constructor", ""); error(line, "array constructor needs one argument per array element", "constructor", "");
...@@ -586,14 +586,14 @@ bool TParseContext::samplerErrorCheck(int line, const TPublicType& pType, const ...@@ -586,14 +586,14 @@ bool TParseContext::samplerErrorCheck(int line, const TPublicType& pType, const
{ {
if (pType.type == EbtStruct) { if (pType.type == EbtStruct) {
if (containsSampler(*pType.userDef)) { if (containsSampler(*pType.userDef)) {
error(line, reason, TType::getBasicString(pType.type), "(structure contains a sampler)"); error(line, reason, getBasicString(pType.type), "(structure contains a sampler)");
return true; return true;
} }
return false; return false;
} else if (IsSampler(pType.type)) { } else if (IsSampler(pType.type)) {
error(line, reason, TType::getBasicString(pType.type), ""); error(line, reason, getBasicString(pType.type), "");
return true; return true;
} }
...@@ -879,9 +879,9 @@ bool TParseContext::paramErrorCheck(int line, TQualifier qualifier, TQualifier p ...@@ -879,9 +879,9 @@ bool TParseContext::paramErrorCheck(int line, TQualifier qualifier, TQualifier p
} }
if (qualifier == EvqConst) if (qualifier == EvqConst)
type->changeQualifier(EvqConstReadOnly); type->setQualifier(EvqConstReadOnly);
else else
type->changeQualifier(paramQualifier); type->setQualifier(paramQualifier);
return false; return false;
} }
...@@ -976,13 +976,13 @@ bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPu ...@@ -976,13 +976,13 @@ bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPu
if (qualifier == EvqConst) { if (qualifier == EvqConst) {
if (qualifier != initializer->getType().getQualifier()) { if (qualifier != initializer->getType().getQualifier()) {
error(line, " assigning non-constant to", "=", "'%s'", variable->getType().getCompleteString().c_str()); error(line, " assigning non-constant to", "=", "'%s'", variable->getType().getCompleteString().c_str());
variable->getType().changeQualifier(EvqTemporary); variable->getType().setQualifier(EvqTemporary);
return true; return true;
} }
if (type != initializer->getType()) { if (type != initializer->getType()) {
error(line, " non-matching types for const initializer ", error(line, " non-matching types for const initializer ",
variable->getType().getQualifierString(), ""); variable->getType().getQualifierString(), "");
variable->getType().changeQualifier(EvqTemporary); variable->getType().setQualifier(EvqTemporary);
return true; return true;
} }
if (initializer->getAsConstantUnion()) { if (initializer->getAsConstantUnion()) {
...@@ -1001,7 +1001,7 @@ bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPu ...@@ -1001,7 +1001,7 @@ bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPu
variable->shareConstPointer(constArray); variable->shareConstPointer(constArray);
} else { } else {
error(line, " cannot assign to", "=", "'%s'", variable->getType().getCompleteString().c_str()); error(line, " cannot assign to", "=", "'%s'", variable->getType().getCompleteString().c_str());
variable->getType().changeQualifier(EvqTemporary); variable->getType().setQualifier(EvqTemporary);
return true; return true;
} }
} }
...@@ -1052,7 +1052,7 @@ TIntermTyped* TParseContext::addConstructor(TIntermNode* node, const TType* type ...@@ -1052,7 +1052,7 @@ TIntermTyped* TParseContext::addConstructor(TIntermNode* node, const TType* type
TIntermAggregate* aggrNode = node->getAsAggregate(); TIntermAggregate* aggrNode = node->getAsAggregate();
TTypeList::iterator memberTypes; TTypeList::const_iterator memberTypes;
if (op == EOpConstructStruct) if (op == EOpConstructStruct)
memberTypes = type->getStruct()->begin(); memberTypes = type->getStruct()->begin();
...@@ -1350,7 +1350,7 @@ TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, TS ...@@ -1350,7 +1350,7 @@ TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, TS
// //
TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* node, TSourceLoc line) TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* node, TSourceLoc line)
{ {
TTypeList* fields = node->getType().getStruct(); const TTypeList* fields = node->getType().getStruct();
TIntermTyped *typedNode; TIntermTyped *typedNode;
int instanceSize = 0; int instanceSize = 0;
unsigned int index = 0; unsigned int index = 0;
......
...@@ -65,7 +65,7 @@ int TType::getStructSize() const ...@@ -65,7 +65,7 @@ int TType::getStructSize() const
} }
if (structureSize == 0) if (structureSize == 0)
for (TTypeList::iterator tl = getStruct()->begin(); tl != getStruct()->end(); tl++) for (TTypeList::const_iterator tl = getStruct()->begin(); tl != getStruct()->end(); tl++)
structureSize += ((*tl).type)->getObjectSize(); structureSize += ((*tl).type)->getObjectSize();
return structureSize; return structureSize;
......
...@@ -76,7 +76,7 @@ public: ...@@ -76,7 +76,7 @@ public:
TType& getType() { return type; } TType& getType() { return type; }
const TType& getType() const { return type; } const TType& getType() const { return type; }
bool isUserType() const { return userType; } bool isUserType() const { return userType; }
void changeQualifier(TQualifier qualifier) { type.changeQualifier(qualifier); } void setQualifier(TQualifier qualifier) { type.setQualifier(qualifier); }
void updateArrayInformationType(TType *t) { arrayInformationType = t; } void updateArrayInformationType(TType *t) { arrayInformationType = t; }
TType* getArrayInformationType() { return arrayInformationType; } TType* getArrayInformationType() { return arrayInformationType; }
......
...@@ -82,28 +82,27 @@ typedef TMap<TTypeList*, TTypeList*>::iterator TStructureMapIterator; ...@@ -82,28 +82,27 @@ typedef TMap<TTypeList*, TTypeList*>::iterator TStructureMapIterator;
class TType { class TType {
public: public:
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
explicit TType(TBasicType t, TPrecision p, TQualifier q = EvqTemporary, int s = 1, bool m = false, bool a = false) : TType() {}
type(t), precision(p), qualifier(q), size(s), matrix(m), array(a), arraySize(0), TType(TBasicType t, TPrecision p, TQualifier q = EvqTemporary, int s = 1, bool m = false, bool a = false) :
structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0), typeName(0) type(t), precision(p), qualifier(q), size(s), matrix(m), array(a), arraySize(0),
{ } structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0), typeName(0)
{
}
explicit TType(const TPublicType &p) : explicit TType(const TPublicType &p) :
type(p.type), precision(p.precision), qualifier(p.qualifier), size(p.size), matrix(p.matrix), array(p.array), arraySize(p.arraySize), type(p.type), precision(p.precision), qualifier(p.qualifier), size(p.size), matrix(p.matrix), array(p.array), arraySize(p.arraySize),
structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0), typeName(0) structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0), typeName(0)
{ {
if (p.userDef) { if (p.userDef) {
structure = p.userDef->getStruct(); structure = p.userDef->getStruct();
typeName = NewPoolTString(p.userDef->getTypeName().c_str()); typeName = NewPoolTString(p.userDef->getTypeName().c_str());
} }
} }
explicit TType(TTypeList* userDef, const TString& n, TPrecision p = EbpUndefined) : TType(TTypeList* userDef, const TString& n, TPrecision p = EbpUndefined) :
type(EbtStruct), precision(p), qualifier(EvqTemporary), size(1), matrix(false), array(false), arraySize(0), type(EbtStruct), precision(p), qualifier(EvqTemporary), size(1), matrix(false), array(false), arraySize(0),
structure(userDef), structureSize(0), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0) { structure(userDef), structureSize(0), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0)
typeName = NewPoolTString(n.c_str()); {
} typeName = NewPoolTString(n.c_str());
explicit TType() {} }
virtual ~TType() {}
TType(const TType& type) { *this = type; }
void copyType(const TType& copyOf, TStructureMap& remapper) void copyType(const TType& copyOf, TStructureMap& remapper)
{ {
...@@ -157,77 +156,19 @@ public: ...@@ -157,77 +156,19 @@ public:
return newType; return newType;
} }
virtual void setType(TBasicType t, int s, bool m, bool a, int aS = 0) TBasicType getBasicType() const { return type; }
{ type = t; size = s; matrix = m; array = a; arraySize = aS; } void setBasicType(TBasicType t) { type = t; }
virtual void setType(TBasicType t, int s, bool m, TType* userDef = 0)
{ type = t;
size = s;
matrix = m;
if (userDef)
structure = userDef->getStruct();
// leave array information intact.
}
virtual void setTypeName(const TString& n) { typeName = NewPoolTString(n.c_str()); }
virtual void setFieldName(const TString& n) { fieldName = NewPoolTString(n.c_str()); }
virtual const TString& getTypeName() const
{
assert(typeName);
return *typeName;
}
virtual const TString& getFieldName() const TPrecision getPrecision() const { return precision; }
{ void setPrecision(TPrecision p) { precision = p; }
assert(fieldName);
return *fieldName;
}
virtual TBasicType getBasicType() const { return type; } TQualifier getQualifier() const { return qualifier; }
virtual TPrecision getPrecision() const { return precision; } void setQualifier(TQualifier q) { qualifier = q; }
virtual TQualifier getQualifier() const { return qualifier; }
virtual void changePrecision(TPrecision p) { precision = p; }
virtual void changeQualifier(TQualifier q) { qualifier = q; }
// One-dimensional size of single instance type // One-dimensional size of single instance type
virtual int getNominalSize() const { return size; } int getNominalSize() const { return size; }
void setNominalSize(int s) { size = s; }
// Full-dimensional size of single instance of type // Full size of single instance of type
virtual int getInstanceSize() const
{
if (matrix)
return size * size;
else
return size;
}
virtual bool isMatrix() const { return matrix ? true : false; }
virtual bool isArray() const { return array ? true : false; }
bool isField() const { return fieldName != 0; }
int getArraySize() const { return arraySize; }
void setArraySize(int s) { array = true; arraySize = s; }
void setMaxArraySize (int s) { maxArraySize = s; }
int getMaxArraySize () const { return maxArraySize; }
void clearArrayness() { array = false; arraySize = 0; maxArraySize = 0; }
void setArrayInformationType(TType* t) { arrayInformationType = t; }
TType* getArrayInformationType() const { return arrayInformationType; }
virtual bool isVector() const { return size > 1 && !matrix; }
virtual bool isScalar() const { return size == 1 && !matrix && !structure; }
static const char* getBasicString(TBasicType t) {
switch (t) {
case EbtVoid: return "void"; break;
case EbtFloat: return "float"; break;
case EbtInt: return "int"; break;
case EbtBool: return "bool"; break;
case EbtSampler2D: return "sampler2D"; break;
case EbtSamplerCube: return "samplerCube"; break;
case EbtStruct: return "structure"; break;
default: return "unknown type";
}
}
const char* getBasicString() const { return TType::getBasicString(type); }
const char* getPrecisionString() const { return ::getPrecisionString(precision); }
const char* getQualifierString() const { return ::getQualifierString(qualifier); }
TTypeList* getStruct() { return structure; }
int getObjectSize() const int getObjectSize() const
{ {
int totalSize; int totalSize;
...@@ -245,7 +186,45 @@ public: ...@@ -245,7 +186,45 @@ public:
return totalSize; return totalSize;
} }
bool isMatrix() const { return matrix ? true : false; }
void setMatrix(bool m) { matrix = m; }
bool isArray() const { return array ? true : false; }
int getArraySize() const { return arraySize; }
void setArraySize(int s) { array = true; arraySize = s; }
int getMaxArraySize () const { return maxArraySize; }
void setMaxArraySize (int s) { maxArraySize = s; }
void clearArrayness() { array = false; arraySize = 0; maxArraySize = 0; }
void setArrayInformationType(TType* t) { arrayInformationType = t; }
TType* getArrayInformationType() const { return arrayInformationType; }
bool isVector() const { return size > 1 && !matrix; }
bool isScalar() const { return size == 1 && !matrix && !structure; }
TTypeList* getStruct() const { return structure; } TTypeList* getStruct() const { return structure; }
void setStruct(TTypeList* s) { structure = s; }
const TString& getTypeName() const
{
assert(typeName);
return *typeName;
}
void setTypeName(const TString& n)
{
typeName = NewPoolTString(n.c_str());
}
bool isField() const { return fieldName != 0; }
const TString& getFieldName() const
{
assert(fieldName);
return *fieldName;
}
void setFieldName(const TString& n)
{
fieldName = NewPoolTString(n.c_str());
}
TString& getMangledName() { TString& getMangledName() {
if (!mangled) { if (!mangled) {
mangled = NewPoolTString(""); mangled = NewPoolTString("");
...@@ -255,6 +234,7 @@ public: ...@@ -255,6 +234,7 @@ public:
return *mangled; return *mangled;
} }
bool sameElementType(const TType& right) const { bool sameElementType(const TType& right) const {
return type == right.type && return type == right.type &&
size == right.size && size == right.size &&
...@@ -282,6 +262,10 @@ public: ...@@ -282,6 +262,10 @@ public:
return false; return false;
} }
const char* getBasicString() const { return ::getBasicString(type); }
const char* getPrecisionString() const { return ::getPrecisionString(precision); }
const char* getQualifierString() const { return ::getQualifierString(qualifier); }
TString getCompleteString() const; TString getCompleteString() const;
protected: protected:
...@@ -295,11 +279,12 @@ protected: ...@@ -295,11 +279,12 @@ protected:
unsigned int matrix : 1; unsigned int matrix : 1;
unsigned int array : 1; unsigned int array : 1;
int arraySize; int arraySize;
int maxArraySize;
TType* arrayInformationType;
TTypeList* structure; // 0 unless this is a struct TTypeList* structure; // 0 unless this is a struct
mutable int structureSize; mutable int structureSize;
int maxArraySize;
TType* arrayInformationType;
TString *fieldName; // for structure field names TString *fieldName; // for structure field names
TString *mangled; TString *mangled;
TString *typeName; // for structure field type name TString *typeName; // for structure field type name
......
...@@ -311,7 +311,7 @@ postfix_expression ...@@ -311,7 +311,7 @@ postfix_expression
$$->setType(TType($1->getBasicType(), $1->getPrecision(), EvqTemporary, $1->getNominalSize(), $1->isMatrix())); $$->setType(TType($1->getBasicType(), $1->getPrecision(), EvqTemporary, $1->getNominalSize(), $1->isMatrix()));
if ($1->getType().getQualifier() == EvqConst) if ($1->getType().getQualifier() == EvqConst)
$$->getTypePointer()->changeQualifier(EvqConst); $$->getTypePointer()->setQualifier(EvqConst);
} else if ($1->isMatrix() && $1->getType().getQualifier() == EvqConst) } else if ($1->isMatrix() && $1->getType().getQualifier() == EvqConst)
$$->setType(TType($1->getBasicType(), $1->getPrecision(), EvqConst, $1->getNominalSize())); $$->setType(TType($1->getBasicType(), $1->getPrecision(), EvqConst, $1->getNominalSize()));
else if ($1->isMatrix()) else if ($1->isMatrix())
...@@ -389,7 +389,7 @@ postfix_expression ...@@ -389,7 +389,7 @@ postfix_expression
} }
} else if ($1->getBasicType() == EbtStruct) { } else if ($1->getBasicType() == EbtStruct) {
bool fieldFound = false; bool fieldFound = false;
TTypeList* fields = $1->getType().getStruct(); const TTypeList* fields = $1->getType().getStruct();
if (fields == 0) { if (fields == 0) {
parseContext->error($2.line, "structure has no fields", "Internal Error", ""); parseContext->error($2.line, "structure has no fields", "Internal Error", "");
parseContext->recover(); parseContext->recover();
...@@ -413,7 +413,7 @@ postfix_expression ...@@ -413,7 +413,7 @@ postfix_expression
$$->setType(*(*fields)[i].type); $$->setType(*(*fields)[i].type);
// change the qualifier of the return type, not of the structure field // change the qualifier of the return type, not of the structure field
// as the structure definition is shared between various structures. // as the structure definition is shared between various structures.
$$->getTypePointer()->changeQualifier(EvqConst); $$->getTypePointer()->setQualifier(EvqConst);
} }
} else { } else {
ConstantUnion *unionArray = new ConstantUnion[1]; ConstantUnion *unionArray = new ConstantUnion[1];
...@@ -673,7 +673,7 @@ function_identifier ...@@ -673,7 +673,7 @@ function_identifier
break; break;
} }
if (op == EOpNull) { if (op == EOpNull) {
parseContext->error($1.line, "cannot construct this type", TType::getBasicString($1.type), ""); parseContext->error($1.line, "cannot construct this type", getBasicString($1.type), "");
parseContext->recover(); parseContext->recover();
$1.type = EbtFloat; $1.type = EbtFloat;
op = EOpConstructFloat; op = EOpConstructFloat;
...@@ -1007,12 +1007,12 @@ declaration ...@@ -1007,12 +1007,12 @@ declaration
} }
} }
prototype->setOperator(EOpPrototype); prototype->setOp(EOpPrototype);
$$ = prototype; $$ = prototype;
} }
| init_declarator_list SEMICOLON { | init_declarator_list SEMICOLON {
if ($1.intermAggregate) if ($1.intermAggregate)
$1.intermAggregate->setOperator(EOpDeclaration); $1.intermAggregate->setOp(EOpDeclaration);
$$ = $1.intermAggregate; $$ = $1.intermAggregate;
} }
| PRECISION precision_qualifier type_specifier_no_prec SEMICOLON { | PRECISION precision_qualifier type_specifier_no_prec SEMICOLON {
...@@ -1795,19 +1795,24 @@ struct_declaration ...@@ -1795,19 +1795,24 @@ struct_declaration
} }
for (unsigned int i = 0; i < $$->size(); ++i) { for (unsigned int i = 0; i < $$->size(); ++i) {
// //
// Careful not to replace already know aspects of type, like array-ness // Careful not to replace already known aspects of type, like array-ness
// //
(*$$)[i].type->setType($1.type, $1.size, $1.matrix, $1.userDef); TType* type = (*$$)[i].type;
type->setBasicType($1.type);
type->setNominalSize($1.size);
type->setMatrix($1.matrix);
// don't allow arrays of arrays // don't allow arrays of arrays
if ((*$$)[i].type->isArray()) { if (type->isArray()) {
if (parseContext->arrayTypeErrorCheck($1.line, $1)) if (parseContext->arrayTypeErrorCheck($1.line, $1))
parseContext->recover(); parseContext->recover();
} }
if ($1.array) if ($1.array)
(*$$)[i].type->setArraySize($1.arraySize); type->setArraySize($1.arraySize);
if ($1.userDef) if ($1.userDef) {
(*$$)[i].type->setTypeName($1.userDef->getTypeName()); type->setStruct($1.userDef->getStruct());
type->setTypeName($1.userDef->getTypeName());
}
} }
} }
; ;
...@@ -1873,7 +1878,7 @@ compound_statement ...@@ -1873,7 +1878,7 @@ compound_statement
: LEFT_BRACE RIGHT_BRACE { $$ = 0; } : LEFT_BRACE RIGHT_BRACE { $$ = 0; }
| LEFT_BRACE { parseContext->symbolTable.push(); } statement_list { parseContext->symbolTable.pop(); } RIGHT_BRACE { | LEFT_BRACE { parseContext->symbolTable.push(); } statement_list { parseContext->symbolTable.pop(); } RIGHT_BRACE {
if ($3 != 0) if ($3 != 0)
$3->setOperator(EOpSequence); $3->setOp(EOpSequence);
$$ = $3; $$ = $3;
} }
; ;
...@@ -1890,7 +1895,7 @@ compound_statement_no_new_scope ...@@ -1890,7 +1895,7 @@ compound_statement_no_new_scope
} }
| LEFT_BRACE statement_list RIGHT_BRACE { | LEFT_BRACE statement_list RIGHT_BRACE {
if ($2) if ($2)
$2->setOperator(EOpSequence); $2->setOp(EOpSequence);
$$ = $2; $$ = $2;
} }
; ;
......
...@@ -203,8 +203,10 @@ public: ...@@ -203,8 +203,10 @@ public:
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
TIntermNode() : line(0) {} TIntermNode() : line(0) {}
virtual TSourceLoc getLine() const { return line; }
virtual void setLine(TSourceLoc l) { line = l; } TSourceLoc getLine() const { return line; }
void setLine(TSourceLoc l) { line = l; }
virtual void traverse(TIntermTraverser*) = 0; virtual void traverse(TIntermTraverser*) = 0;
virtual TIntermTyped* getAsTyped() { return 0; } virtual TIntermTyped* getAsTyped() { return 0; }
virtual TIntermConstantUnion* getAsConstantUnion() { return 0; } virtual TIntermConstantUnion* getAsConstantUnion() { return 0; }
...@@ -215,6 +217,7 @@ public: ...@@ -215,6 +217,7 @@ public:
virtual TIntermSymbol* getAsSymbolNode() { return 0; } virtual TIntermSymbol* getAsSymbolNode() { return 0; }
virtual TIntermLoop* getAsLoopNode() { return 0; } virtual TIntermLoop* getAsLoopNode() { return 0; }
virtual ~TIntermNode() { } virtual ~TIntermNode() { }
protected: protected:
TSourceLoc line; TSourceLoc line;
}; };
...@@ -233,22 +236,23 @@ struct TIntermNodePair { ...@@ -233,22 +236,23 @@ struct TIntermNodePair {
class TIntermTyped : public TIntermNode { class TIntermTyped : public TIntermNode {
public: public:
TIntermTyped(const TType& t) : type(t) { } TIntermTyped(const TType& t) : type(t) { }
virtual TIntermTyped* getAsTyped() { return this; } virtual TIntermTyped* getAsTyped() { return this; }
virtual void setType(const TType& t) { type = t; }
virtual const TType& getType() const { return type; } void setType(const TType& t) { type = t; }
virtual TType* getTypePointer() { return &type; } const TType& getType() const { return type; }
TType* getTypePointer() { return &type; }
virtual TBasicType getBasicType() const { return type.getBasicType(); }
virtual TQualifier getQualifier() const { return type.getQualifier(); } TBasicType getBasicType() const { return type.getBasicType(); }
virtual TPrecision getPrecision() const { return type.getPrecision(); } TQualifier getQualifier() const { return type.getQualifier(); }
virtual int getNominalSize() const { return type.getNominalSize(); } TPrecision getPrecision() const { return type.getPrecision(); }
virtual int getSize() const { return type.getInstanceSize(); } int getNominalSize() const { return type.getNominalSize(); }
virtual bool isMatrix() const { return type.isMatrix(); }
virtual bool isArray() const { return type.isArray(); } bool isMatrix() const { return type.isMatrix(); }
virtual bool isVector() const { return type.isVector(); } bool isArray() const { return type.isArray(); }
virtual bool isScalar() const { return type.isScalar(); } bool isVector() const { return type.isVector(); }
const char* getBasicString() const { return type.getBasicString(); } bool isScalar() const { return type.isScalar(); }
const char* getQualifierString() const { return type.getQualifierString(); } const char* getBasicString() const { return type.getBasicString(); }
const char* getQualifierString() const { return type.getQualifierString(); }
TString getCompleteString() const { return type.getCompleteString(); } TString getCompleteString() const { return type.getCompleteString(); }
protected: protected:
...@@ -266,13 +270,16 @@ public: ...@@ -266,13 +270,16 @@ public:
test(aTest), test(aTest),
terminal(aTerminal), terminal(aTerminal),
first(testFirst) { } first(testFirst) { }
virtual TIntermLoop* getAsLoopNode() { return this; } virtual TIntermLoop* getAsLoopNode() { return this; }
virtual void traverse(TIntermTraverser*); virtual void traverse(TIntermTraverser*);
TIntermNode *getInit() { return init; } TIntermNode *getInit() { return init; }
TIntermNode *getBody() { return body; } TIntermNode *getBody() { return body; }
TIntermTyped *getTest() { return test; } TIntermTyped *getTest() { return test; }
TIntermTyped *getTerminal() { return terminal; } TIntermTyped *getTerminal() { return terminal; }
bool testFirst() { return first; } bool testFirst() { return first; }
protected: protected:
TIntermNode *init; TIntermNode *init;
TIntermNode *body; // code to loop over TIntermNode *body; // code to loop over
...@@ -289,9 +296,12 @@ public: ...@@ -289,9 +296,12 @@ public:
TIntermBranch(TOperator op, TIntermTyped* e) : TIntermBranch(TOperator op, TIntermTyped* e) :
flowOp(op), flowOp(op),
expression(e) { } expression(e) { }
virtual void traverse(TIntermTraverser*); virtual void traverse(TIntermTraverser*);
TOperator getFlowOp() { return flowOp; } TOperator getFlowOp() { return flowOp; }
TIntermTyped* getExpression() { return expression; } TIntermTyped* getExpression() { return expression; }
protected: protected:
TOperator flowOp; TOperator flowOp;
TIntermTyped* expression; // non-zero except for "return exp;" statements TIntermTyped* expression; // non-zero except for "return exp;" statements
...@@ -307,10 +317,13 @@ public: ...@@ -307,10 +317,13 @@ public:
// it is essential to use "symbol = sym" to assign to symbol // it is essential to use "symbol = sym" to assign to symbol
TIntermSymbol(int i, const TString& sym, const TType& t) : TIntermSymbol(int i, const TString& sym, const TType& t) :
TIntermTyped(t), id(i) { symbol = sym;} TIntermTyped(t), id(i) { symbol = sym;}
virtual int getId() const { return id; }
virtual const TString& getSymbol() const { return symbol; } int getId() const { return id; }
const TString& getSymbol() const { return symbol; }
virtual void traverse(TIntermTraverser*); virtual void traverse(TIntermTraverser*);
virtual TIntermSymbol* getAsSymbolNode() { return this; } virtual TIntermSymbol* getAsSymbolNode() { return this; }
protected: protected:
int id; int id;
TString symbol; TString symbol;
...@@ -319,11 +332,15 @@ protected: ...@@ -319,11 +332,15 @@ protected:
class TIntermConstantUnion : public TIntermTyped { class TIntermConstantUnion : public TIntermTyped {
public: public:
TIntermConstantUnion(ConstantUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { } TIntermConstantUnion(ConstantUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { }
ConstantUnion* getUnionArrayPointer() const { return unionArrayPointer; } ConstantUnion* getUnionArrayPointer() const { return unionArrayPointer; }
void setUnionArrayPointer(ConstantUnion *c) { unionArrayPointer = c; } void setUnionArrayPointer(ConstantUnion *c) { unionArrayPointer = c; }
virtual TIntermConstantUnion* getAsConstantUnion() { return this; } virtual TIntermConstantUnion* getAsConstantUnion() { return this; }
virtual void traverse(TIntermTraverser* ); virtual void traverse(TIntermTraverser*);
virtual TIntermTyped* fold(TOperator, TIntermTyped*, TInfoSink&);
TIntermTyped* fold(TOperator, TIntermTyped*, TInfoSink&);
protected: protected:
ConstantUnion *unionArrayPointer; ConstantUnion *unionArrayPointer;
}; };
...@@ -334,9 +351,11 @@ protected: ...@@ -334,9 +351,11 @@ protected:
class TIntermOperator : public TIntermTyped { class TIntermOperator : public TIntermTyped {
public: public:
TOperator getOp() const { return op; } TOperator getOp() const { return op; }
void setOp(TOperator o) { op = o; }
bool modifiesState() const; bool modifiesState() const;
bool isConstructor() const; bool isConstructor() const;
virtual bool promote(TInfoSink&) { return true; }
protected: protected:
TIntermOperator(TOperator o) : TIntermTyped(TType(EbtFloat, EbpUndefined)), op(o) {} TIntermOperator(TOperator o) : TIntermTyped(TType(EbtFloat, EbpUndefined)), op(o) {}
TIntermOperator(TOperator o, TType& t) : TIntermTyped(t), op(o) {} TIntermOperator(TOperator o, TType& t) : TIntermTyped(t), op(o) {}
...@@ -349,13 +368,16 @@ protected: ...@@ -349,13 +368,16 @@ protected:
class TIntermBinary : public TIntermOperator { class TIntermBinary : public TIntermOperator {
public: public:
TIntermBinary(TOperator o) : TIntermOperator(o) {} TIntermBinary(TOperator o) : TIntermOperator(o) {}
virtual void traverse(TIntermTraverser*);
virtual void setLeft(TIntermTyped* n) { left = n; }
virtual void setRight(TIntermTyped* n) { right = n; }
virtual TIntermTyped* getLeft() const { return left; }
virtual TIntermTyped* getRight() const { return right; }
virtual TIntermBinary* getAsBinaryNode() { return this; } virtual TIntermBinary* getAsBinaryNode() { return this; }
virtual bool promote(TInfoSink&); virtual void traverse(TIntermTraverser*);
void setLeft(TIntermTyped* n) { left = n; }
void setRight(TIntermTyped* n) { right = n; }
TIntermTyped* getLeft() const { return left; }
TIntermTyped* getRight() const { return right; }
bool promote(TInfoSink&);
protected: protected:
TIntermTyped* left; TIntermTyped* left;
TIntermTyped* right; TIntermTyped* right;
...@@ -368,11 +390,14 @@ class TIntermUnary : public TIntermOperator { ...@@ -368,11 +390,14 @@ class TIntermUnary : public TIntermOperator {
public: public:
TIntermUnary(TOperator o, TType& t) : TIntermOperator(o, t), operand(0) {} TIntermUnary(TOperator o, TType& t) : TIntermOperator(o, t), operand(0) {}
TIntermUnary(TOperator o) : TIntermOperator(o), operand(0) {} TIntermUnary(TOperator o) : TIntermOperator(o), operand(0) {}
virtual void traverse(TIntermTraverser*); virtual void traverse(TIntermTraverser*);
virtual void setOperand(TIntermTyped* o) { operand = o; }
virtual TIntermTyped* getOperand() { return operand; }
virtual TIntermUnary* getAsUnaryNode() { return this; } virtual TIntermUnary* getAsUnaryNode() { return this; }
virtual bool promote(TInfoSink&);
void setOperand(TIntermTyped* o) { operand = o; }
TIntermTyped* getOperand() { return operand; }
bool promote(TInfoSink&);
protected: protected:
TIntermTyped* operand; TIntermTyped* operand;
}; };
...@@ -387,21 +412,24 @@ public: ...@@ -387,21 +412,24 @@ public:
TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), pragmaTable(0) { } TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), pragmaTable(0) { }
TIntermAggregate(TOperator o) : TIntermOperator(o), pragmaTable(0) { } TIntermAggregate(TOperator o) : TIntermOperator(o), pragmaTable(0) { }
~TIntermAggregate() { delete pragmaTable; } ~TIntermAggregate() { delete pragmaTable; }
virtual TIntermAggregate* getAsAggregate() { return this; } virtual TIntermAggregate* getAsAggregate() { return this; }
virtual void setOperator(TOperator o) { op = o; }
virtual TIntermSequence& getSequence() { return sequence; }
virtual void setName(const TString& n) { name = n; }
virtual const TString& getName() const { return name; }
virtual void traverse(TIntermTraverser*); virtual void traverse(TIntermTraverser*);
virtual void setUserDefined() { userDefined = true; }
virtual bool isUserDefined() { return userDefined; } TIntermSequence& getSequence() { return sequence; }
virtual TQualifierList& getQualifier() { return qualifier; } void setName(const TString& n) { name = n; }
const TString& getName() const { return name; }
void setUserDefined() { userDefined = true; }
bool isUserDefined() { return userDefined; }
TQualifierList& getQualifier() { return qualifier; }
void setOptimize(bool o) { optimize = o; } void setOptimize(bool o) { optimize = o; }
void setDebug(bool d) { debug = d; }
bool getOptimize() { return optimize; } bool getOptimize() { return optimize; }
void setDebug(bool d) { debug = d; }
bool getDebug() { return debug; } bool getDebug() { return debug; }
void addToPragmaTable(const TPragmaTable& pTable); void addToPragmaTable(const TPragmaTable& pTable);
const TPragmaTable& getPragmaTable() const { return *pragmaTable; } const TPragmaTable& getPragmaTable() const { return *pragmaTable; }
protected: protected:
TIntermAggregate(const TIntermAggregate&); // disallow copy constructor TIntermAggregate(const TIntermAggregate&); // disallow copy constructor
TIntermAggregate& operator=(const TIntermAggregate&); // disallow assignment operator TIntermAggregate& operator=(const TIntermAggregate&); // disallow assignment operator
...@@ -423,12 +451,15 @@ public: ...@@ -423,12 +451,15 @@ public:
TIntermTyped(TType(EbtVoid, EbpUndefined)), condition(cond), trueBlock(trueB), falseBlock(falseB) {} TIntermTyped(TType(EbtVoid, EbpUndefined)), condition(cond), trueBlock(trueB), falseBlock(falseB) {}
TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) : TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) :
TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {} TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {}
virtual void traverse(TIntermTraverser*); virtual void traverse(TIntermTraverser*);
bool usesTernaryOperator() const { return getBasicType() != EbtVoid; } bool usesTernaryOperator() const { return getBasicType() != EbtVoid; }
virtual TIntermNode* getCondition() const { return condition; } TIntermNode* getCondition() const { return condition; }
virtual TIntermNode* getTrueBlock() const { return trueBlock; } TIntermNode* getTrueBlock() const { return trueBlock; }
virtual TIntermNode* getFalseBlock() const { return falseBlock; } TIntermNode* getFalseBlock() const { return falseBlock; }
virtual TIntermSelection* getAsSelectionNode() { return this; } TIntermSelection* getAsSelectionNode() { return this; }
protected: protected:
TIntermTyped* condition; TIntermTyped* condition;
TIntermNode* trueBlock; TIntermNode* trueBlock;
......
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