Add full support for uniforms with initializers, including intra-stage link validation of aggregate constant initializers.

This included 
 - encapsulating aggregate constants
 - removal of constant-aggregate comparison algorithms, instead using a flattened and direct std::vector comparison
 - adding structure type comparison for independently declared structures that still might match types



git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23274 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-09-28 04:02:08 +00:00
parent b3345c422d
commit f2ee3dd46a
98 changed files with 3007 additions and 1715 deletions

View file

@ -65,53 +65,6 @@ bool isInf(double x)
const double pi = 3.1415926535897932384626433832795;
// forward reference for mutual recursion
bool CompareStruct(const TType& leftNodeType, TConstUnion* rightUnionArray, TConstUnion* leftUnionArray);
bool CompareStructure(const TType& leftNodeType, TConstUnion* rightUnionArray, TConstUnion* leftUnionArray)
{
if (leftNodeType.isArray()) {
TType typeWithoutArrayness;
typeWithoutArrayness.shallowCopy(leftNodeType); // TODO: arrays of arrays: the shallow copy won't work if arrays are shared and dereferenced
typeWithoutArrayness.dereference();
int arraySize = leftNodeType.getArraySize();
for (int i = 0; i < arraySize; ++i) {
int offset = typeWithoutArrayness.getObjectSize() * i;
if (! CompareStruct(typeWithoutArrayness, &rightUnionArray[offset], &leftUnionArray[offset]))
return false;
}
} else
return CompareStruct(leftNodeType, rightUnionArray, leftUnionArray);
return true;
}
bool CompareStruct(const TType& leftNodeType, TConstUnion* rightUnionArray, TConstUnion* leftUnionArray)
{
TTypeList* fields = leftNodeType.getStruct();
size_t structSize = fields->size();
int index = 0;
for (size_t j = 0; j < structSize; j++) {
int size = (*fields)[j].type->getObjectSize();
for (int i = 0; i < size; i++) {
if ((*fields)[j].type->getBasicType() == EbtStruct) {
if (!CompareStructure(*(*fields)[j].type, &rightUnionArray[index], &leftUnionArray[index]))
return false;
} else {
if (leftUnionArray[index] != rightUnionArray[index])
return false;
index++;
}
}
}
return true;
}
} // end anonymous namespace
@ -132,10 +85,6 @@ namespace glslang {
//
TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNode)
{
TConstUnion *unionArray = getUnionArrayPointer();
int objectSize = getType().getObjectSize();
TConstUnion* newConstArray = 0;
// For most cases, the return type matches the argument type, so set that
// up and just code to exceptions below.
TType returnType;
@ -146,33 +95,46 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
//
TIntermConstantUnion *node = constantNode->getAsConstantUnion();
TConstUnion *rightUnionArray = node->getUnionArrayPointer();
TConstUnionArray unionArray = getConstArray();
TConstUnionArray rightUnionArray = node->getConstArray();
if (constantNode->getType().getObjectSize() == 1 && objectSize > 1) {
// for a case like float f = vec4(2,3,4,5) + 1.2;
rightUnionArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; ++i)
rightUnionArray[i] = *node->getUnionArrayPointer();
} else if (constantNode->getType().getObjectSize() > 1 && objectSize == 1) {
// for a case like float f = 1.2 + vec4(2,3,4,5);
rightUnionArray = node->getUnionArrayPointer();
unionArray = new TConstUnion[constantNode->getType().getObjectSize()];
for (int i = 0; i < constantNode->getType().getObjectSize(); ++i)
unionArray[i] = *getUnionArrayPointer();
returnType.shallowCopy(node->getType());
objectSize = constantNode->getType().getObjectSize();
// Figure out the size of the result
int objectSize;
switch(op) {
case EOpMatrixTimesMatrix:
objectSize = getMatrixRows() * node->getMatrixCols();
break;
case EOpMatrixTimesVector:
objectSize = getMatrixRows();
break;
case EOpVectorTimesMatrix:
objectSize = node->getMatrixCols();
break;
default:
objectSize = getType().getObjectSize();
if (constantNode->getType().getObjectSize() == 1 && getType().getObjectSize() > 1) {
// for a case like vec4 f = vec4(2,3,4,5) + 1.2;
TConstUnionArray smearedArray(objectSize, node->getConstArray()[0]);
rightUnionArray = smearedArray;
} else if (constantNode->getType().getObjectSize() > 1 && getType().getObjectSize() == 1) {
// for a case like vec4 f = 1.2 + vec4(2,3,4,5);
objectSize = constantNode->getType().getObjectSize();
rightUnionArray = node->getConstArray();
TConstUnionArray smearedArray(objectSize, getConstArray()[0]);
unionArray = smearedArray;
returnType.shallowCopy(node->getType());
}
break;
}
int index = 0;
bool boolNodeFlag = false;
TConstUnionArray newConstArray(objectSize);
switch(op) {
case EOpAdd:
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++)
newConstArray[i] = unionArray[i] + rightUnionArray[i];
break;
case EOpSub:
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++)
newConstArray[i] = unionArray[i] - rightUnionArray[i];
break;
@ -180,12 +142,10 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EOpMul:
case EOpVectorTimesScalar:
case EOpMatrixTimesScalar:
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++)
newConstArray[i] = unionArray[i] * rightUnionArray[i];
break;
case EOpMatrixTimesMatrix:
newConstArray = new TConstUnion[getMatrixRows() * node->getMatrixCols()];
for (int row = 0; row < getMatrixRows(); row++) {
for (int column = 0; column < node->getMatrixCols(); column++) {
double sum = 0.0f;
@ -197,7 +157,6 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
returnType.shallowCopy(TType(getType().getBasicType(), EvqConst, 0, getMatrixRows(), node->getMatrixCols()));
break;
case EOpDiv:
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++) {
switch (getType().getBasicType()) {
case EbtDouble:
@ -225,7 +184,6 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
break;
case EOpMatrixTimesVector:
newConstArray = new TConstUnion[getMatrixRows()];
for (int i = 0; i < getMatrixRows(); i++) {
double sum = 0.0f;
for (int j = 0; j < node->getVectorSize(); j++) {
@ -238,7 +196,6 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
break;
case EOpVectorTimesMatrix:
newConstArray = new TConstUnion[node->getMatrixCols()];
for (int i = 0; i < node->getMatrixCols(); i++) {
double sum = 0.0f;
for (int j = 0; j < getVectorSize(); j++)
@ -250,53 +207,44 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
break;
case EOpMod:
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++)
newConstArray[i] = unionArray[i] % rightUnionArray[i];
break;
case EOpRightShift:
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++)
newConstArray[i] = unionArray[i] >> rightUnionArray[i];
break;
case EOpLeftShift:
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++)
newConstArray[i] = unionArray[i] << rightUnionArray[i];
break;
case EOpAnd:
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++)
newConstArray[i] = unionArray[i] & rightUnionArray[i];
break;
case EOpInclusiveOr:
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++)
newConstArray[i] = unionArray[i] | rightUnionArray[i];
break;
case EOpExclusiveOr:
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++)
newConstArray[i] = unionArray[i] ^ rightUnionArray[i];
break;
case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++)
newConstArray[i] = unionArray[i] && rightUnionArray[i];
break;
case EOpLogicalOr: // this code is written for possible future use, will not get executed currently
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++)
newConstArray[i] = unionArray[i] || rightUnionArray[i];
break;
case EOpLogicalXor:
newConstArray = new TConstUnion[objectSize];
for (int i = 0; i < objectSize; i++) {
switch (getType().getBasicType()) {
case EbtBool: newConstArray[i].setBConst((unionArray[i] == rightUnionArray[i]) ? false : true); break;
@ -306,71 +254,27 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
break;
case EOpLessThan:
assert(objectSize == 1);
newConstArray = new TConstUnion[1];
newConstArray->setBConst(*unionArray < *rightUnionArray);
newConstArray[0].setBConst(unionArray[0] < rightUnionArray[0]);
returnType.shallowCopy(TType(EbtBool, EvqConst));
break;
case EOpGreaterThan:
assert(objectSize == 1);
newConstArray = new TConstUnion[1];
newConstArray->setBConst(*unionArray > *rightUnionArray);
newConstArray[0].setBConst(unionArray[0] > rightUnionArray[0]);
returnType.shallowCopy(TType(EbtBool, EvqConst));
break;
case EOpLessThanEqual:
{
assert(objectSize == 1);
TConstUnion constant;
constant.setBConst(*unionArray > *rightUnionArray);
newConstArray = new TConstUnion[1];
newConstArray->setBConst(!constant.getBConst());
newConstArray[0].setBConst(! (unionArray[0] > rightUnionArray[0]));
returnType.shallowCopy(TType(EbtBool, EvqConst));
break;
}
case EOpGreaterThanEqual:
{
assert(objectSize == 1);
TConstUnion constant;
constant.setBConst(*unionArray < *rightUnionArray);
newConstArray = new TConstUnion[1];
newConstArray->setBConst(!constant.getBConst());
newConstArray[0].setBConst(! (unionArray[0] < rightUnionArray[0]));
returnType.shallowCopy(TType(EbtBool, EvqConst));
break;
}
case EOpEqual:
if (getType().getBasicType() == EbtStruct) {
if (! CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
boolNodeFlag = true;
} else {
for (int i = 0; i < objectSize; i++) {
if (unionArray[i] != rightUnionArray[i]) {
boolNodeFlag = true;
break; // break out of for loop
}
}
}
newConstArray = new TConstUnion[1];
newConstArray->setBConst(! boolNodeFlag);
newConstArray[0].setBConst(node->getConstArray() == unionArray);
returnType.shallowCopy(TType(EbtBool, EvqConst));
break;
case EOpNotEqual:
if (getType().getBasicType() == EbtStruct) {
if (CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
boolNodeFlag = true;
} else {
for (int i = 0; i < objectSize; i++) {
if (unionArray[i] == rightUnionArray[i]) {
boolNodeFlag = true;
break; // break out of for loop
}
}
}
newConstArray = new TConstUnion[1];
newConstArray->setBConst(! boolNodeFlag);
newConstArray[0].setBConst(node->getConstArray() != unionArray);
returnType.shallowCopy(TType(EbtBool, EvqConst));
break;
@ -389,19 +293,16 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
//
TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType)
{
TConstUnion *unionArray = getUnionArrayPointer();
int objectSize = getType().getObjectSize();
// First, size the result, which is mostly the same as the argument's size,
// but not always.
TConstUnion* newConstArray;
int resultSize;
switch (op) {
// TODO: functionality: constant folding: finish listing exceptions to size here
case EOpDeterminant:
case EOpAny:
case EOpAll:
case EOpLength:
newConstArray = new TConstUnion[1];
resultSize = 1;
break;
case EOpEmitStreamVertex:
@ -410,10 +311,15 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType)
return 0;
default:
newConstArray = new TConstUnion[objectSize];
resultSize = getType().getObjectSize();
break;
}
TConstUnionArray newConstArray(resultSize);
const TConstUnionArray unionArray = getConstArray();
// Process non-component-wise operations
int objectSize = getType().getObjectSize();
switch (op) {
case EOpLength:
case EOpNormalize:
@ -671,11 +577,11 @@ TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode)
default:
return aggrNode;
}
TConstUnion* newConstArray = new TConstUnion[objectSize];
TConstUnionArray newConstArray(objectSize);
TVector<TConstUnion*> childConstUnions;
TVector<TConstUnionArray> childConstUnions;
for (unsigned int arg = 0; arg < children.size(); ++arg)
childConstUnions.push_back(children[arg]->getAsConstantUnion()->getUnionArrayPointer());
childConstUnions.push_back(children[arg]->getAsConstantUnion()->getConstArray());
// Second, do the actual folding
@ -805,7 +711,7 @@ TIntermTyped* TIntermediate::foldConstructor(TIntermAggregate* aggrNode)
{
bool error = false;
TConstUnion* unionArray = new TConstUnion[aggrNode->getType().getObjectSize()];
TConstUnionArray unionArray(aggrNode->getType().getObjectSize());
if (aggrNode->getSequence().size() == 1)
error = parseConstTree(aggrNode->getLoc(), aggrNode, unionArray, aggrNode->getOp(), aggrNode->getType(), true);
else

View file

@ -757,7 +757,7 @@ TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* true
//
if (cond->getAsConstantUnion() && trueBlock->getAsConstantUnion() && falseBlock->getAsConstantUnion()) {
if (cond->getAsConstantUnion()->getUnionArrayPointer()->getBConst())
if (cond->getAsConstantUnion()->getConstArray()[0].getBConst())
return trueBlock;
else
return falseBlock;
@ -779,9 +779,9 @@ TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* true
// Returns the constant union node created.
//
TIntermConstantUnion* TIntermediate::addConstantUnion(TConstUnion* unionArrayPointer, const TType& t, TSourceLoc loc)
TIntermConstantUnion* TIntermediate::addConstantUnion(const TConstUnionArray& unionArray, const TType& t, TSourceLoc loc)
{
TIntermConstantUnion* node = new TIntermConstantUnion(unionArrayPointer, t);
TIntermConstantUnion* node = new TIntermConstantUnion(unionArray, t);
node->setLoc(loc);
return node;
@ -795,11 +795,10 @@ TIntermTyped* TIntermediate::addSwizzle(TVectorFields& fields, TSourceLoc loc)
node->setLoc(loc);
TIntermConstantUnion* constIntNode;
TIntermSequence &sequenceVector = node->getSequence();
TConstUnion* unionArray;
for (int i = 0; i < fields.num; i++) {
unionArray = new TConstUnion[1];
unionArray->setIConst(fields.offsets[i]);
TConstUnionArray unionArray(1);
unionArray[0].setIConst(fields.offsets[i]);
constIntNode = addConstantUnion(unionArray, TType(EbtInt, EvqConst), loc);
sequenceVector.push_back(constIntNode);
}
@ -896,6 +895,7 @@ void TIntermediate::addSymbolLinkageNode(TIntermAggregate*& linkage, TSymbolTabl
void TIntermediate::addSymbolLinkageNode(TIntermAggregate*& linkage, const TVariable& variable)
{
TIntermSymbol* node = new TIntermSymbol(variable.getUniqueId(), variable.getName(), variable.getType());
node->setConstArray(variable.getConstArray());
linkage = growAggregate(linkage, node);
}
@ -975,8 +975,13 @@ void TIntermediate::mergeLinkerObjects(TInfoSink& infoSink, TIntermSequence& lin
if (symbol->getName() == unitSymbol->getName()) {
// filter out copy
merge = false;
// but if one has an initializer and the other does not, update
// the initializer
if (symbol->getConstArray().empty() && ! unitSymbol->getConstArray().empty())
symbol->setConstArray(unitSymbol->getConstArray());
// Check for consistent types/qualification/etc.
// Check for consistent types/qualification/initializers etc.
linkErrorCheck(infoSink, *symbol, *unitSymbol, false);
}
}
@ -1067,6 +1072,16 @@ void TIntermediate::linkErrorCheck(TInfoSink& infoSink, const TIntermSymbol& sym
writeTypeComparison = true;
}
// Initializers have to match, if both are present, and if we don't already know the types don't match
if (! writeTypeComparison) {
if (! symbol.getConstArray().empty() && ! unitSymbol.getConstArray().empty()) {
if (symbol.getConstArray() != unitSymbol.getConstArray()) {
error(infoSink, "Initializers must match:");
infoSink.info << " " << symbol.getName() << "\n";
}
}
}
if (writeTypeComparison)
infoSink.info << " " << symbol.getName() << ": \"" << symbol.getType().getCompleteString() << "\" versus \"" <<
unitSymbol.getType().getCompleteString() << "\"\n";
@ -1547,12 +1562,12 @@ void TIntermTyped::propagatePrecision(TPrecisionQualifier newPrecision)
TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermConstantUnion* node)
{
TConstUnion *rightUnionArray = node->getUnionArrayPointer();
const TConstUnionArray& rightUnionArray = node->getConstArray();
int size = node->getType().getObjectSize();
TConstUnion *leftUnionArray = new TConstUnion[size];
TConstUnionArray leftUnionArray(size);
for (int i=0; i < size; i++) {
for (int i=0; i < size; i++) {
switch (promoteTo) {
case EbtFloat:
switch (node->getType().getBasicType()) {

View file

@ -464,8 +464,8 @@ TIntermTyped* TParseContext::handleVariable(TSourceLoc loc, TSymbol* symbol, TSt
// it was a member of an anonymous container, have to insert its dereference
const TVariable* variable = anon->getAnonContainer().getAsVariable();
TIntermTyped* container = intermediate.addSymbol(variable->getUniqueId(), variable->getName(), variable->getType(), loc);
TConstUnion* unionArray = new TConstUnion[1];
unionArray->setUConst(anon->getMemberNumber());
TConstUnionArray unionArray(1);
unionArray[0].setUConst(anon->getMemberNumber());
TIntermTyped* constNode = intermediate.addConstantUnion(unionArray, TType(EbtUint, EvqConst), loc);
node = intermediate.addIndex(EOpIndexDirectStruct, container, constNode, loc);
@ -483,10 +483,9 @@ TIntermTyped* TParseContext::handleVariable(TSourceLoc loc, TSymbol* symbol, TSt
// don't delete $1.string, it's used by error recovery, and the pool
// pop will reclaim the memory
if (variable->getType().getQualifier().storage == EvqConst ) {
TConstUnion* constArray = variable->getConstUnionPointer();
node = intermediate.addConstantUnion(constArray, variable->getType(), loc);
} else
if (variable->getType().getQualifier().storage == EvqConst)
node = intermediate.addConstantUnion(variable->getConstArray(), variable->getType(), loc);
else
node = intermediate.addSymbol(variable->getUniqueId(), variable->getName(), variable->getType(), loc);
}
@ -509,30 +508,30 @@ TIntermTyped* TParseContext::handleBracketDereference(TSourceLoc loc, TIntermTyp
} else if (base->getType().getQualifier().storage == EvqConst && index->getQualifier().storage == EvqConst) {
if (base->isArray()) {
// constant folding for arrays
result = addConstArrayNode(index->getAsConstantUnion()->getUnionArrayPointer()->getIConst(), base, loc);
result = addConstArrayNode(index->getAsConstantUnion()->getConstArray()[0].getIConst(), base, loc);
} else if (base->isVector()) {
// constant folding for vectors
TVectorFields fields;
fields.num = 1;
fields.offsets[0] = index->getAsConstantUnion()->getUnionArrayPointer()->getIConst(); // need to do it this way because v.xy sends fields integer array
fields.offsets[0] = index->getAsConstantUnion()->getConstArray()[0].getIConst(); // need to do it this way because v.xy sends fields integer array
result = addConstVectorNode(fields, base, loc);
} else if (base->isMatrix()) {
// constant folding for matrices
result = addConstMatrixNode(index->getAsConstantUnion()->getUnionArrayPointer()->getIConst(), base, loc);
result = addConstMatrixNode(index->getAsConstantUnion()->getConstArray()[0].getIConst(), base, loc);
}
} else {
if (index->getQualifier().storage == EvqConst) {
int indexValue = index->getAsConstantUnion()->getUnionArrayPointer()->getIConst();
int indexValue = index->getAsConstantUnion()->getConstArray()[0].getIConst();
if (! base->isArray() && (base->isVector() && base->getType().getVectorSize() <= indexValue ||
base->isMatrix() && base->getType().getMatrixCols() <= indexValue))
error(loc, "", "[", "index out of range '%d'", index->getAsConstantUnion()->getUnionArrayPointer()->getIConst());
error(loc, "", "[", "index out of range '%d'", index->getAsConstantUnion()->getConstArray()[0].getIConst());
if (base->isArray()) {
if (base->getType().getArraySize() == 0) {
if (base->getType().getMaxArraySize() <= index->getAsConstantUnion()->getUnionArrayPointer()->getIConst())
arraySetMaxSize(loc, base->getAsSymbolNode(), index->getAsConstantUnion()->getUnionArrayPointer()->getIConst() + 1);
} else if ( index->getAsConstantUnion()->getUnionArrayPointer()->getIConst() >= base->getType().getArraySize() ||
index->getAsConstantUnion()->getUnionArrayPointer()->getIConst() < 0)
error(loc, "", "[", "array index out of range '%d'", index->getAsConstantUnion()->getUnionArrayPointer()->getIConst());
if (base->getType().getMaxArraySize() <= index->getAsConstantUnion()->getConstArray()[0].getIConst())
arraySetMaxSize(loc, base->getAsSymbolNode(), index->getAsConstantUnion()->getConstArray()[0].getIConst() + 1);
} else if ( index->getAsConstantUnion()->getConstArray()[0].getIConst() >= base->getType().getArraySize() ||
index->getAsConstantUnion()->getConstArray()[0].getIConst() < 0)
error(loc, "", "[", "array index out of range '%d'", index->getAsConstantUnion()->getConstArray()[0].getIConst());
}
result = intermediate.addIndex(EOpIndexDirect, base, index, loc);
} else {
@ -550,8 +549,8 @@ TIntermTyped* TParseContext::handleBracketDereference(TSourceLoc loc, TIntermTyp
}
if (result == 0) {
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setDConst(0.0);
TConstUnionArray unionArray(1);
unionArray[0].setDConst(0.0);
result = intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), loc);
} else {
TType newType;
@ -599,8 +598,8 @@ TIntermTyped* TParseContext::handleDotDereference(TSourceLoc loc, TIntermTyped*
result->setType(TType(base->getBasicType(), EvqConst, (int) (field).size()));
} else {
if (fields.num == 1) {
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setIConst(fields.offsets[0]);
TConstUnionArray unionArray(1);
unionArray[0].setIConst(fields.offsets[0]);
TIntermTyped* index = intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), loc);
result = intermediate.addIndex(EOpIndexDirect, base, index, loc);
result->setType(TType(base->getBasicType(), EvqTemporary, base->getType().getQualifier().precision));
@ -638,8 +637,8 @@ TIntermTyped* TParseContext::handleDotDereference(TSourceLoc loc, TIntermTyped*
result->getWritableType().getQualifier().storage = EvqConst;
}
} else {
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setIConst(i);
TConstUnionArray unionArray(1);
unionArray[0].setIConst(i);
TIntermTyped* index = intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), loc);
result = intermediate.addIndex(EOpIndexDirectStruct, base, index, loc);
result->setType(*(*fields)[i].type);
@ -761,8 +760,8 @@ TIntermTyped* TParseContext::handleFunctionCall(TSourceLoc loc, TFunction* fnCal
} else
length = intermNode->getAsTyped()->getType().getArraySize();
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setIConst(length);
TConstUnionArray unionArray(1);
unionArray[0].setIConst(length);
result = intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), loc);
} else if (op != EOpNull) {
//
@ -836,8 +835,8 @@ TIntermTyped* TParseContext::handleFunctionCall(TSourceLoc loc, TFunction* fnCal
} else {
// error message was put out by PaFindFunction()
// Put on a dummy node for error recovery
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setDConst(0.0);
TConstUnionArray unionArray(1);
unionArray[0].setDConst(0.0);
result = intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), loc);
}
}
@ -1074,7 +1073,7 @@ bool TParseContext::lValueErrorCheck(TSourceLoc loc, const char* op, TIntermType
for (TIntermSequence::iterator p = aggrNode->getSequence().begin();
p != aggrNode->getSequence().end(); p++) {
int value = (*p)->getAsTyped()->getAsConstantUnion()->getUnionArrayPointer()->getIConst();
int value = (*p)->getAsTyped()->getAsConstantUnion()->getConstArray()[0].getIConst();
offset[value]++;
if (offset[value] > 1) {
error(loc, " l-value of swizzle cannot have duplicate components", op, "", "");
@ -1631,7 +1630,7 @@ void TParseContext::arraySizeCheck(TSourceLoc loc, TIntermTyped* expr, int& size
return;
}
size = constant->getUnionArrayPointer()->getIConst();
size = constant->getConstArray()[0].getIConst();
if (size <= 0) {
error(loc, "array size must be a positive integer", "", "");
@ -1767,7 +1766,7 @@ bool TParseContext::arraySetMaxSize(TSourceLoc loc, TIntermSymbol *node, int siz
// return true;
// }
// int texCoordValue = texCoord->getAsVariable()->getConstUnionPointer()[0].getIConst();
// int texCoordValue = texCoord->getAsVariable()->getConstArray()[0].getIConst();
// if (texCoordValue <= size) {
// error(loc, "", "[", "gl_TexCoord can only have a max array size of up to gl_MaxTextureCoords", "");
// return true;
@ -2087,8 +2086,8 @@ TIntermNode* TParseContext::executeInitializer(TSourceLoc loc, TString& identifi
//
// test for and propagate constant
//
if (qualifier == EvqConst) {
if (qualifier != initializer->getType().getQualifier().storage) {
if (qualifier == EvqConst || qualifier == EvqUniform) {
if (initializer->getType().getQualifier().storage != EvqConst) {
error(loc, " assigning non-constant to", "=", "'%s'", variable->getType().getCompleteString().c_str());
variable->getWritableType().getQualifier().storage = EvqTemporary;
return 0;
@ -2099,20 +2098,13 @@ TIntermNode* TParseContext::executeInitializer(TSourceLoc loc, TString& identifi
variable->getWritableType().getQualifier().storage = EvqTemporary;
return 0;
}
if (initializer->getAsConstantUnion()) {
TConstUnion* unionArray = variable->getConstUnionPointer();
if (type.getObjectSize() == 1 && type.getBasicType() != EbtStruct) {
*unionArray = (initializer->getAsConstantUnion()->getUnionArrayPointer())[0];
} else {
variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer());
}
} else if (initializer->getAsSymbolNode()) {
if (initializer->getAsConstantUnion())
variable->setConstArray(initializer->getAsConstantUnion()->getConstArray());
else if (initializer->getAsSymbolNode()) {
TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getName());
if (const TVariable* tVar = symbol->getAsVariable()) {
TConstUnion* constArray = tVar->getConstUnionPointer();
variable->shareConstPointer(constArray);
} else {
if (const TVariable* tVar = symbol->getAsVariable())
variable->setConstArray(tVar->getConstArray());
else {
error(loc, "expected variable", initializer->getAsSymbolNode()->getName().c_str(), "");
return 0;
}
@ -2121,16 +2113,14 @@ TIntermNode* TParseContext::executeInitializer(TSourceLoc loc, TString& identifi
variable->getWritableType().getQualifier().storage = EvqTemporary;
return 0;
}
}
if (qualifier != EvqConst) {
} else {
TIntermSymbol* intermSymbol = intermediate.addSymbol(variable->getUniqueId(), variable->getName(), variable->getType(), loc);
TIntermNode* initNode = intermediate.addAssign(EOpAssign, intermSymbol, initializer, loc);
if (! initNode)
assignError(loc, "=", intermSymbol->getCompleteString(), initializer->getCompleteString());
return initNode;
}
}
return 0;
}
@ -2559,8 +2549,8 @@ void TParseContext::wrapupSwitchSubsequence(TIntermAggregate* statements, TInter
newExpression != 0 &&
prevExpression->getAsConstantUnion() &&
newExpression->getAsConstantUnion() &&
prevExpression->getAsConstantUnion()->getUnionArrayPointer()->getIConst() ==
newExpression->getAsConstantUnion()->getUnionArrayPointer()->getIConst())
prevExpression->getAsConstantUnion()->getConstArray()[0].getIConst() ==
newExpression->getAsConstantUnion()->getConstArray()[0].getIConst())
error(branchNode->getLoc(), "duplicated value", "case", "");
}
}
@ -2617,22 +2607,16 @@ TIntermTyped* TParseContext::addConstVectorNode(TVectorFields& fields, TIntermTy
TIntermTyped* typedNode;
TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion();
TConstUnion *unionArray;
if (tempConstantNode) {
unionArray = tempConstantNode->getUnionArrayPointer();
if (!unionArray) { // this error message should never be raised
infoSink.info.message(EPrefixInternalError, "TConstUnion not initialized in addConstVectorNode function", loc);
return node;
}
} else { // The node has to be either a symbol node or an aggregate node or a tempConstant node, else, its an error
TConstUnionArray unionArray;
if (tempConstantNode)
unionArray = tempConstantNode->getConstArray();
else { // The node has to be either a symbol node or an aggregate node or a tempConstant node, else, its an error
error(loc, "Cannot offset into the vector", "Error", "");
return 0;
}
TConstUnion* constArray = new TConstUnion[fields.num];
TConstUnionArray constArray(fields.num);
for (int i = 0; i < fields.num; i++) {
if (fields.offsets[i] >= node->getType().getObjectSize()) {
@ -2664,10 +2648,10 @@ TIntermTyped* TParseContext::addConstMatrixNode(int index, TIntermTyped* node, T
}
if (tempConstantNode) {
TConstUnion* unionArray = tempConstantNode->getUnionArrayPointer();
int size = tempConstantNode->getType().getMatrixRows();
// Note: the type is corrected (dereferenced) by the caller
typedNode = intermediate.addConstantUnion(&unionArray[size*index], tempConstantNode->getType(), loc);
const TConstUnionArray& unionArray = tempConstantNode->getConstArray();
int size = tempConstantNode->getType().getMatrixRows();
// Note: the type is corrected (dereferenced) by the caller
typedNode = intermediate.addConstantUnion(TConstUnionArray(unionArray, size * index, size), tempConstantNode->getType(), loc);
} else {
error(loc, "Cannot offset into the matrix", "Error", "");
@ -2701,8 +2685,8 @@ TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, TS
int arrayElementSize = arrayElementType.getObjectSize();
if (tempConstantNode) {
TConstUnion* unionArray = tempConstantNode->getUnionArrayPointer();
typedNode = intermediate.addConstantUnion(&unionArray[arrayElementSize * index], tempConstantNode->getType(), loc);
typedNode = intermediate.addConstantUnion(TConstUnionArray(tempConstantNode->getConstArray(), arrayElementSize * index, arrayElementSize),
tempConstantNode->getType(), loc);
} else {
error(loc, "Cannot offset into the array", "Error", "");
@ -2722,22 +2706,24 @@ TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* n
{
TTypeList* fields = node->getType().getStruct();
TIntermTyped *typedNode;
int instanceSize = 0;
int instanceOffset = 0;
int instanceSize;
unsigned int index = 0;
TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();
for ( index = 0; index < fields->size(); ++index) {
if ((*fields)[index].type->getFieldName() == identifier) {
instanceSize = (*fields)[index].type->getObjectSize();
if ((*fields)[index].type->getFieldName() == identifier)
break;
} else {
instanceSize += (*fields)[index].type->getObjectSize();
}
instanceOffset += instanceSize;
}
if (tempConstantNode) {
TConstUnion* constArray = tempConstantNode->getUnionArrayPointer();
typedNode = intermediate.addConstantUnion(constArray+instanceSize, tempConstantNode->getType(), loc); // type will be changed in the calling function
typedNode = intermediate.addConstantUnion(TConstUnionArray(tempConstantNode->getConstArray(), instanceOffset, instanceSize),
tempConstantNode->getType(), loc);
// type will be changed in the calling function
} else {
error(loc, "Cannot offset into the structure", "Error", "");

View file

@ -171,7 +171,6 @@ protected:
void declareArray(TSourceLoc, TString& identifier, const TType&, TVariable*&, bool& newDeclaration);
TIntermNode* executeInitializer(TSourceLoc, TString& identifier, TType&, TIntermTyped* initializer, TVariable* variable);
public:
//
// Generally, bison productions, the scanner, and the PP need read/write access to these; just give them direct access

View file

@ -231,13 +231,13 @@ TVariable::TVariable(const TVariable& copyOf, TStructureMap& remapper) : TSymbol
type.deepCopy(copyOf.type, remapper);
userType = copyOf.userType;
if (copyOf.unionArray) {
if (! copyOf.unionArray.empty()) {
assert(!copyOf.type.getStruct());
assert(copyOf.type.getObjectSize() == 1);
unionArray = new TConstUnion[1];
unionArray[0] = copyOf.unionArray[0];
} else
unionArray = 0;
TConstUnionArray newArray(1);
newArray[0] = copyOf.unionArray[0];
unionArray = newArray;
}
}
TVariable* TVariable::clone(TStructureMap& remapper)

View file

@ -125,7 +125,7 @@ protected:
//
class TVariable : public TSymbol {
public:
TVariable(const TString *name, const TType& t, bool uT = false ) : TSymbol(name), userType(uT), unionArray(0) { type.shallowCopy(t); }
TVariable(const TString *name, const TType& t, bool uT = false ) : TSymbol(name), userType(uT) { type.shallowCopy(t); }
virtual TVariable* clone(TStructureMap& remapper);
virtual ~TVariable() { }
@ -137,21 +137,8 @@ public:
virtual void dump(TInfoSink &infoSink) const;
TConstUnion* getConstUnionPointer()
{
if (!unionArray)
unionArray = new TConstUnion[type.getObjectSize()];
return unionArray;
}
TConstUnion* getConstUnionPointer() const { return unionArray; }
void shareConstPointer( TConstUnion *constArray)
{
delete unionArray;
unionArray = constArray;
}
const TConstUnionArray& getConstArray() const { return unionArray; }
void setConstArray(const TConstUnionArray& constArray) { unionArray = constArray; }
protected:
explicit TVariable(const TVariable&);
@ -162,7 +149,7 @@ protected:
bool userType;
// we are assuming that Pool Allocator will free the memory allocated to unionArray
// when this object is destroyed
TConstUnion *unionArray;
TConstUnionArray unionArray;
};
//

View file

@ -226,30 +226,30 @@ primary_expression
$$ = $1;
}
| INTCONSTANT {
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setIConst($1.i);
TConstUnionArray unionArray(1);
unionArray[0].setIConst($1.i);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), $1.loc);
}
| UINTCONSTANT {
parseContext.fullIntegerCheck($1.loc, "unsigned literal");
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setUConst($1.u);
TConstUnionArray unionArray(1);
unionArray[0].setUConst($1.u);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtUint, EvqConst), $1.loc);
}
| FLOATCONSTANT {
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setDConst($1.d);
TConstUnionArray unionArray(1);
unionArray[0].setDConst($1.d);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), $1.loc);
}
| DOUBLECONSTANT {
parseContext.doubleCheck($1.loc, "double literal");
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setDConst($1.d);
TConstUnionArray unionArray(1);
unionArray[0].setDConst($1.d);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtDouble, EvqConst), $1.loc);
}
| BOOLCONSTANT {
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setBConst($1.b);
TConstUnionArray unionArray(1);
unionArray[0].setBConst($1.b);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), $1.loc);
}
| LEFT_PAREN expression RIGHT_PAREN {
@ -515,8 +515,8 @@ relational_expression
$$ = parseContext.intermediate.addBinaryMath(EOpLessThan, $1, $3, $2.loc);
if ($$ == 0) {
parseContext.binaryOpError($2.loc, "<", $1->getCompleteString(), $3->getCompleteString());
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setBConst(false);
TConstUnionArray unionArray(1);
unionArray[0].setBConst(false);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), $2.loc);
}
}
@ -524,8 +524,8 @@ relational_expression
$$ = parseContext.intermediate.addBinaryMath(EOpGreaterThan, $1, $3, $2.loc);
if ($$ == 0) {
parseContext.binaryOpError($2.loc, ">", $1->getCompleteString(), $3->getCompleteString());
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setBConst(false);
TConstUnionArray unionArray(1);
unionArray[0].setBConst(false);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), $2.loc);
}
}
@ -533,8 +533,8 @@ relational_expression
$$ = parseContext.intermediate.addBinaryMath(EOpLessThanEqual, $1, $3, $2.loc);
if ($$ == 0) {
parseContext.binaryOpError($2.loc, "<=", $1->getCompleteString(), $3->getCompleteString());
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setBConst(false);
TConstUnionArray unionArray(1);
unionArray[0].setBConst(false);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), $2.loc);
}
}
@ -542,8 +542,8 @@ relational_expression
$$ = parseContext.intermediate.addBinaryMath(EOpGreaterThanEqual, $1, $3, $2.loc);
if ($$ == 0) {
parseContext.binaryOpError($2.loc, ">=", $1->getCompleteString(), $3->getCompleteString());
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setBConst(false);
TConstUnionArray unionArray(1);
unionArray[0].setBConst(false);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), $2.loc);
}
}
@ -555,8 +555,8 @@ equality_expression
$$ = parseContext.intermediate.addBinaryMath(EOpEqual, $1, $3, $2.loc);
if ($$ == 0) {
parseContext.binaryOpError($2.loc, "==", $1->getCompleteString(), $3->getCompleteString());
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setBConst(false);
TConstUnionArray unionArray(1);
unionArray[0].setBConst(false);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), $2.loc);
} else if (($1->isArray() || $3->isArray()))
parseContext.profileRequires($2.loc, ENoProfile, 120, "GL_3DL_array_objects", "==");
@ -565,8 +565,8 @@ equality_expression
$$ = parseContext.intermediate.addBinaryMath(EOpNotEqual, $1, $3, $2.loc);
if ($$ == 0) {
parseContext.binaryOpError($2.loc, "!=", $1->getCompleteString(), $3->getCompleteString());
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setBConst(false);
TConstUnionArray unionArray(1);
unionArray[0].setBConst(false);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), $2.loc);
} else if (($1->isArray() || $3->isArray()))
parseContext.profileRequires($2.loc, ENoProfile, 120, "GL_3DL_array_objects", "!=");
@ -615,8 +615,8 @@ logical_and_expression
$$ = parseContext.intermediate.addBinaryMath(EOpLogicalAnd, $1, $3, $2.loc);
if ($$ == 0) {
parseContext.binaryOpError($2.loc, "&&", $1->getCompleteString(), $3->getCompleteString());
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setBConst(false);
TConstUnionArray unionArray(1);
unionArray[0].setBConst(false);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), $2.loc);
}
}
@ -628,8 +628,8 @@ logical_xor_expression
$$ = parseContext.intermediate.addBinaryMath(EOpLogicalXor, $1, $3, $2.loc);
if ($$ == 0) {
parseContext.binaryOpError($2.loc, "^^", $1->getCompleteString(), $3->getCompleteString());
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setBConst(false);
TConstUnionArray unionArray(1);
unionArray[0].setBConst(false);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), $2.loc);
}
}
@ -641,8 +641,8 @@ logical_or_expression
$$ = parseContext.intermediate.addBinaryMath(EOpLogicalOr, $1, $3, $2.loc);
if ($$ == 0) {
parseContext.binaryOpError($2.loc, "||", $1->getCompleteString(), $3->getCompleteString());
TConstUnion *unionArray = new TConstUnion[1];
unionArray->setBConst(false);
TConstUnionArray unionArray(1);
unionArray[0].setBConst(false);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtBool, EvqConst), $2.loc);
}
}

View file

@ -62,7 +62,7 @@ public:
// Helper functions for printing, not part of traversing.
//
void OutputTreeText(TInfoSink& infoSink, TIntermNode* node, const int depth)
void OutputTreeText(TInfoSink& infoSink, const TIntermNode* node, const int depth)
{
int i;
@ -85,21 +85,6 @@ void OutputTreeText(TInfoSink& infoSink, TIntermNode* node, const int depth)
// return false.
//
void OutputSymbol(TIntermSymbol* node, TIntermTraverser* it)
{
TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);
OutputTreeText(oit->infoSink, node, oit->depth);
const int maxSize = GlslangMaxTypeLength + GlslangMaxTokenLength;
char buf[maxSize];
snprintf(buf, maxSize, "'%s' (%s)\n",
node->getName().c_str(),
node->getCompleteString().c_str());
oit->infoSink.debug << buf;
}
bool OutputBinary(bool /* preVisit */, TIntermBinary* node, TIntermTraverser* it)
{
TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);
@ -127,7 +112,7 @@ bool OutputBinary(bool /* preVisit */, TIntermBinary* node, TIntermTraverser* it
case EOpIndexDirect: out.debug << "direct index"; break;
case EOpIndexIndirect: out.debug << "indirect index"; break;
case EOpIndexDirectStruct:
out.debug << (*node->getLeft()->getType().getStruct())[node->getRight()->getAsConstantUnion()->getUnionArrayPointer()->getIConst()].type->getFieldName();
out.debug << (*node->getLeft()->getType().getStruct())[node->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst()].type->getFieldName();
out.debug << ": direct index for structure"; break;
case EOpVectorSwizzle: out.debug << "vector swizzle"; break;
@ -417,18 +402,15 @@ bool OutputSelection(bool /* preVisit */, TIntermSelection* node, TIntermTravers
return false;
}
void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
void OutputConstantUnion(TInfoSink& out, const TIntermTyped* node, const TConstUnionArray& constUnion, int depth)
{
TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);
TInfoSink& out = oit->infoSink;
int size = node->getType().getObjectSize();
for (int i = 0; i < size; i++) {
OutputTreeText(out, node, oit->depth);
switch (node->getUnionArrayPointer()[i].getType()) {
OutputTreeText(out, node, depth);
switch (constUnion[i].getType()) {
case EbtBool:
if (node->getUnionArrayPointer()[i].getBConst())
if (constUnion[i].getBConst())
out.debug << "true";
else
out.debug << "false";
@ -442,7 +424,7 @@ void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
{
const int maxSize = 300;
char buf[maxSize];
snprintf(buf, maxSize, "%f", node->getUnionArrayPointer()[i].getDConst());
snprintf(buf, maxSize, "%f", constUnion[i].getDConst());
out.debug << buf << "\n";
}
@ -451,7 +433,7 @@ void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
{
const int maxSize = 300;
char buf[maxSize];
snprintf(buf, maxSize, "%d (%s)", node->getUnionArrayPointer()[i].getIConst(), "const int");
snprintf(buf, maxSize, "%d (%s)", constUnion[i].getIConst(), "const int");
out.debug << buf << "\n";
}
@ -460,7 +442,7 @@ void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
{
const int maxSize = 300;
char buf[maxSize];
snprintf(buf, maxSize, "%u (%s)", node->getUnionArrayPointer()[i].getUConst(), "const uint");
snprintf(buf, maxSize, "%u (%s)", constUnion[i].getUConst(), "const uint");
out.debug << buf << "\n";
}
@ -472,6 +454,34 @@ void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
}
}
void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
{
TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);
TInfoSink& out = oit->infoSink;
OutputTreeText(oit->infoSink, node, oit->depth);
oit->infoSink.debug << "Constant:\n";
OutputConstantUnion(oit->infoSink, node, node->getConstArray(), oit->depth + 1);
}
void OutputSymbol(TIntermSymbol* node, TIntermTraverser* it)
{
TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);
OutputTreeText(oit->infoSink, node, oit->depth);
const int maxSize = GlslangMaxTypeLength + GlslangMaxTokenLength;
char buf[maxSize];
snprintf(buf, maxSize, "'%s' (%s)\n",
node->getName().c_str(),
node->getCompleteString().c_str());
oit->infoSink.debug << buf;
if (! node->getConstArray().empty())
OutputConstantUnion(oit->infoSink, node, node->getConstArray(), oit->depth + 1);
}
bool OutputLoop(bool /* preVisit */, TIntermLoop* node, TIntermTraverser* it)
{
TOutputTraverser* oit = static_cast<TOutputTraverser*>(it);

View file

@ -87,9 +87,9 @@ public:
TIntermTyped* addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, TSourceLoc);
TIntermTyped* addComma(TIntermTyped* left, TIntermTyped* right, TSourceLoc);
TIntermTyped* addMethod(TIntermTyped*, const TType&, const TString*, TSourceLoc);
TIntermConstantUnion* addConstantUnion(TConstUnion*, const TType&, TSourceLoc);
TIntermConstantUnion* addConstantUnion(const TConstUnionArray&, const TType&, TSourceLoc);
TIntermTyped* promoteConstantUnion(TBasicType, TIntermConstantUnion*) ;
bool parseConstTree(TSourceLoc, TIntermNode*, TConstUnion*, TOperator, const TType&, bool singleConstantParam = false);
bool parseConstTree(TSourceLoc, TIntermNode*, TConstUnionArray, TOperator, const TType&, bool singleConstantParam = false);
TIntermNode* addLoop(TIntermNode*, TIntermTyped*, TIntermTyped*, bool testFirst, TSourceLoc);
TIntermBranch* addBranch(TOperator, TSourceLoc);
TIntermBranch* addBranch(TOperator, TIntermTyped*, TSourceLoc);

View file

@ -43,11 +43,11 @@ namespace glslang {
class TConstTraverser : public TIntermTraverser {
public:
TConstTraverser(TConstUnion* cUnion, bool singleConstParam, TOperator constructType, const TType& t) : unionArray(cUnion), type(t),
TConstTraverser(const TConstUnionArray& cUnion, bool singleConstParam, TOperator constructType, const TType& t) : unionArray(cUnion), type(t),
constructorType(constructType), singleConstantParam(singleConstParam), error(false), isMatrix(false),
matrixCols(0), matrixRows(0) { index = 0; tOp = EOpNull;}
int index ;
TConstUnion *unionArray;
int index;
TConstUnionArray unionArray;
TOperator tOp;
const TType& type;
TOperator constructorType;
@ -112,7 +112,7 @@ bool ParseAggregate(bool /* preVisit */, TIntermAggregate* node, TIntermTraverse
void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
{
TConstTraverser* oit = static_cast<TConstTraverser*>(it);
TConstUnion* leftUnionArray = oit->unionArray;
TConstUnionArray leftUnionArray(oit->unionArray);
int instanceSize = oit->type.getObjectSize();
if (oit->index >= instanceSize)
@ -121,7 +121,7 @@ void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
if (!oit->singleConstantParam) {
int size = node->getType().getObjectSize();
TConstUnion *rightUnionArray = node->getUnionArrayPointer();
const TConstUnionArray& rightUnionArray = node->getConstArray();
for (int i=0; i < size; i++) {
if (oit->index >= instanceSize)
return;
@ -137,7 +137,7 @@ void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
matrixRows = oit->matrixRows;
isMatrix = oit->isMatrix;
totalSize = oit->index + size;
TConstUnion *rightUnionArray = node->getUnionArrayPointer();
const TConstUnionArray& rightUnionArray = node->getConstArray();
if (! isMatrix) {
int count = 0;
for (int i = oit->index; i < totalSize; i++) {
@ -171,7 +171,7 @@ void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
}
}
bool TIntermediate::parseConstTree(TSourceLoc line, TIntermNode* root, TConstUnion* unionArray, TOperator constructorType, const TType& t, bool singleConstantParam)
bool TIntermediate::parseConstTree(TSourceLoc line, TIntermNode* root, TConstUnionArray unionArray, TOperator constructorType, const TType& t, bool singleConstantParam)
{
if (root == 0)
return false;