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