Used size_t for object size instead of signed int.

BUG=crbug 179653 R=aedla@chromium.org, kbr@chromium.org Review URL: https://codereview.appspot.com/8834048 git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@2239 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent eff3cf7c
...@@ -1022,11 +1022,11 @@ bool CompareStruct(const TType& leftNodeType, ConstantUnion* rightUnionArray, Co ...@@ -1022,11 +1022,11 @@ bool CompareStruct(const TType& leftNodeType, ConstantUnion* rightUnionArray, Co
const TTypeList* fields = leftNodeType.getStruct(); const TTypeList* fields = leftNodeType.getStruct();
size_t structSize = fields->size(); size_t structSize = fields->size();
int index = 0; size_t index = 0;
for (size_t j = 0; j < structSize; j++) { for (size_t j = 0; j < structSize; j++) {
int size = (*fields)[j]->getObjectSize(); size_t size = (*fields)[j]->getObjectSize();
for (int i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
if ((*fields)[j]->getBasicType() == EbtStruct) { if ((*fields)[j]->getBasicType() == EbtStruct) {
if (!CompareStructure(*(*fields)[j], &rightUnionArray[index], &leftUnionArray[index])) if (!CompareStructure(*(*fields)[j], &rightUnionArray[index], &leftUnionArray[index]))
return false; return false;
...@@ -1047,10 +1047,10 @@ bool CompareStructure(const TType& leftNodeType, ConstantUnion* rightUnionArray, ...@@ -1047,10 +1047,10 @@ bool CompareStructure(const TType& leftNodeType, ConstantUnion* rightUnionArray,
TType typeWithoutArrayness = leftNodeType; TType typeWithoutArrayness = leftNodeType;
typeWithoutArrayness.clearArrayness(); typeWithoutArrayness.clearArrayness();
int arraySize = leftNodeType.getArraySize(); size_t arraySize = leftNodeType.getArraySize();
for (int i = 0; i < arraySize; ++i) { for (size_t i = 0; i < arraySize; ++i) {
int offset = typeWithoutArrayness.getObjectSize() * i; size_t offset = typeWithoutArrayness.getObjectSize() * i;
if (!CompareStruct(typeWithoutArrayness, &rightUnionArray[offset], &leftUnionArray[offset])) if (!CompareStruct(typeWithoutArrayness, &rightUnionArray[offset], &leftUnionArray[offset]))
return false; return false;
} }
...@@ -1070,7 +1070,7 @@ bool CompareStructure(const TType& leftNodeType, ConstantUnion* rightUnionArray, ...@@ -1070,7 +1070,7 @@ bool CompareStructure(const TType& leftNodeType, ConstantUnion* rightUnionArray,
TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNode, TInfoSink& infoSink) TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNode, TInfoSink& infoSink)
{ {
ConstantUnion *unionArray = getUnionArrayPointer(); ConstantUnion *unionArray = getUnionArrayPointer();
int objectSize = getType().getObjectSize(); size_t objectSize = getType().getObjectSize();
if (constantNode) { // binary operations if (constantNode) { // binary operations
TIntermConstantUnion *node = constantNode->getAsConstantUnion(); TIntermConstantUnion *node = constantNode->getAsConstantUnion();
...@@ -1080,13 +1080,13 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1080,13 +1080,13 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
// for a case like float f = 1.2 + vec4(2,3,4,5); // for a case like float f = 1.2 + vec4(2,3,4,5);
if (constantNode->getType().getObjectSize() == 1 && objectSize > 1) { if (constantNode->getType().getObjectSize() == 1 && objectSize > 1) {
rightUnionArray = new ConstantUnion[objectSize]; rightUnionArray = new ConstantUnion[objectSize];
for (int i = 0; i < objectSize; ++i) for (size_t i = 0; i < objectSize; ++i)
rightUnionArray[i] = *node->getUnionArrayPointer(); rightUnionArray[i] = *node->getUnionArrayPointer();
returnType = getType(); returnType = getType();
} else if (constantNode->getType().getObjectSize() > 1 && objectSize == 1) { } else if (constantNode->getType().getObjectSize() > 1 && objectSize == 1) {
// for a case like float f = vec4(2,3,4,5) + 1.2; // for a case like float f = vec4(2,3,4,5) + 1.2;
unionArray = new ConstantUnion[constantNode->getType().getObjectSize()]; unionArray = new ConstantUnion[constantNode->getType().getObjectSize()];
for (int i = 0; i < constantNode->getType().getObjectSize(); ++i) for (size_t i = 0; i < constantNode->getType().getObjectSize(); ++i)
unionArray[i] = *getUnionArrayPointer(); unionArray[i] = *getUnionArrayPointer();
returnType = node->getType(); returnType = node->getType();
objectSize = constantNode->getType().getObjectSize(); objectSize = constantNode->getType().getObjectSize();
...@@ -1100,14 +1100,14 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1100,14 +1100,14 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EOpAdd: case EOpAdd:
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0 {// support MSVC++6.0
for (int i = 0; i < objectSize; i++) for (size_t i = 0; i < objectSize; i++)
tempConstArray[i] = unionArray[i] + rightUnionArray[i]; tempConstArray[i] = unionArray[i] + rightUnionArray[i];
} }
break; break;
case EOpSub: case EOpSub:
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0 {// support MSVC++6.0
for (int i = 0; i < objectSize; i++) for (size_t i = 0; i < objectSize; i++)
tempConstArray[i] = unionArray[i] - rightUnionArray[i]; tempConstArray[i] = unionArray[i] - rightUnionArray[i];
} }
break; break;
...@@ -1117,7 +1117,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1117,7 +1117,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EOpMatrixTimesScalar: case EOpMatrixTimesScalar:
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0 {// support MSVC++6.0
for (int i = 0; i < objectSize; i++) for (size_t i = 0; i < objectSize; i++)
tempConstArray[i] = unionArray[i] * rightUnionArray[i]; tempConstArray[i] = unionArray[i] * rightUnionArray[i];
} }
break; break;
...@@ -1142,7 +1142,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1142,7 +1142,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EOpDiv: case EOpDiv:
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0 {// support MSVC++6.0
for (int i = 0; i < objectSize; i++) { for (size_t i = 0; i < objectSize; i++) {
switch (getType().getBasicType()) { switch (getType().getBasicType()) {
case EbtFloat: case EbtFloat:
if (rightUnionArray[i] == 0.0f) { if (rightUnionArray[i] == 0.0f) {
...@@ -1208,7 +1208,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1208,7 +1208,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0 {// support MSVC++6.0
for (int i = 0; i < objectSize; i++) for (size_t i = 0; i < objectSize; i++)
tempConstArray[i] = unionArray[i] && rightUnionArray[i]; tempConstArray[i] = unionArray[i] && rightUnionArray[i];
} }
break; break;
...@@ -1216,7 +1216,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1216,7 +1216,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EOpLogicalOr: // this code is written for possible future use, will not get executed currently case EOpLogicalOr: // this code is written for possible future use, will not get executed currently
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0 {// support MSVC++6.0
for (int i = 0; i < objectSize; i++) for (size_t i = 0; i < objectSize; i++)
tempConstArray[i] = unionArray[i] || rightUnionArray[i]; tempConstArray[i] = unionArray[i] || rightUnionArray[i];
} }
break; break;
...@@ -1224,7 +1224,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1224,7 +1224,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EOpLogicalXor: case EOpLogicalXor:
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0 {// support MSVC++6.0
for (int i = 0; i < objectSize; i++) for (size_t i = 0; i < objectSize; i++)
switch (getType().getBasicType()) { switch (getType().getBasicType()) {
case EbtBool: tempConstArray[i].setBConst((unionArray[i] == rightUnionArray[i]) ? false : true); break; case EbtBool: tempConstArray[i].setBConst((unionArray[i] == rightUnionArray[i]) ? false : true); break;
default: assert(false && "Default missing"); default: assert(false && "Default missing");
...@@ -1270,7 +1270,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1270,7 +1270,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
if (!CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray)) if (!CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
boolNodeFlag = true; boolNodeFlag = true;
} else { } else {
for (int i = 0; i < objectSize; i++) { for (size_t i = 0; i < objectSize; i++) {
if (unionArray[i] != rightUnionArray[i]) { if (unionArray[i] != rightUnionArray[i]) {
boolNodeFlag = true; boolNodeFlag = true;
break; // break out of for loop break; // break out of for loop
...@@ -1296,7 +1296,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1296,7 +1296,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
if (CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray)) if (CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
boolNodeFlag = true; boolNodeFlag = true;
} else { } else {
for (int i = 0; i < objectSize; i++) { for (size_t i = 0; i < objectSize; i++) {
if (unionArray[i] == rightUnionArray[i]) { if (unionArray[i] == rightUnionArray[i]) {
boolNodeFlag = true; boolNodeFlag = true;
break; // break out of for loop break; // break out of for loop
...@@ -1331,7 +1331,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1331,7 +1331,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
// //
TIntermConstantUnion *newNode = 0; TIntermConstantUnion *newNode = 0;
ConstantUnion* tempConstArray = new ConstantUnion[objectSize]; ConstantUnion* tempConstArray = new ConstantUnion[objectSize];
for (int i = 0; i < objectSize; i++) { for (size_t i = 0; i < objectSize; i++) {
switch(op) { switch(op) {
case EOpNegative: case EOpNegative:
switch (getType().getBasicType()) { switch (getType().getBasicType()) {
...@@ -1362,11 +1362,11 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1362,11 +1362,11 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermConstantUnion* node) TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermConstantUnion* node)
{ {
int size = node->getType().getObjectSize(); size_t size = node->getType().getObjectSize();
ConstantUnion *leftUnionArray = new ConstantUnion[size]; ConstantUnion *leftUnionArray = new ConstantUnion[size];
for (int i=0; i < size; i++) { for (size_t i = 0; i < size; i++) {
switch (promoteTo) { switch (promoteTo) {
case EbtFloat: case EbtFloat:
......
...@@ -152,10 +152,10 @@ const ConstantUnion* TOutputGLSLBase::writeConstantUnion(const TType& type, ...@@ -152,10 +152,10 @@ const ConstantUnion* TOutputGLSLBase::writeConstantUnion(const TType& type,
} }
else else
{ {
int size = type.getObjectSize(); size_t size = type.getObjectSize();
bool writeType = size > 1; bool writeType = size > 1;
if (writeType) out << getTypeName(type) << "("; if (writeType) out << getTypeName(type) << "(";
for (int i = 0; i < size; ++i, ++pConstUnion) for (size_t i = 0; i < size; ++i, ++pConstUnion)
{ {
switch (pConstUnion->getType()) switch (pConstUnion->getType())
{ {
......
...@@ -2679,11 +2679,12 @@ TString OutputHLSL::initializer(const TType &type) ...@@ -2679,11 +2679,12 @@ TString OutputHLSL::initializer(const TType &type)
{ {
TString string; TString string;
for (int component = 0; component < type.getObjectSize(); component++) size_t size = type.getObjectSize();
for (size_t component = 0; component < size; component++)
{ {
string += "0"; string += "0";
if (component < type.getObjectSize() - 1) if (component + 1 < size)
{ {
string += ", "; string += ", ";
} }
...@@ -2833,27 +2834,30 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI ...@@ -2833,27 +2834,30 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI
} }
else else
{ {
int remainingComponents = ctorType.getObjectSize(); size_t remainingComponents = ctorType.getObjectSize();
int parameterIndex = 0; size_t parameterIndex = 0;
while (remainingComponents > 0) while (remainingComponents > 0)
{ {
const TType &parameter = ctorParameters[parameterIndex]; const TType &parameter = ctorParameters[parameterIndex];
bool moreParameters = parameterIndex < (int)ctorParameters.size() - 1; const size_t parameterSize = parameter.getObjectSize();
bool moreParameters = parameterIndex + 1 < ctorParameters.size();
constructor += "x" + str(parameterIndex); constructor += "x" + str(parameterIndex);
if (parameter.isScalar()) if (parameter.isScalar())
{ {
remainingComponents -= parameter.getObjectSize(); ASSERT(parameterSize <= remainingComponents);
remainingComponents -= parameterSize;
} }
else if (parameter.isVector()) else if (parameter.isVector())
{ {
if (remainingComponents == parameter.getObjectSize() || moreParameters) if (remainingComponents == parameterSize || moreParameters)
{ {
remainingComponents -= parameter.getObjectSize(); ASSERT(parameterSize <= remainingComponents);
remainingComponents -= parameterSize;
} }
else if (remainingComponents < parameter.getNominalSize()) else if (remainingComponents < static_cast<size_t>(parameter.getNominalSize()))
{ {
switch (remainingComponents) switch (remainingComponents)
{ {
...@@ -2870,9 +2874,10 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI ...@@ -2870,9 +2874,10 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI
} }
else if (parameter.isMatrix() || parameter.getStruct()) else if (parameter.isMatrix() || parameter.getStruct())
{ {
ASSERT(remainingComponents == parameter.getObjectSize() || moreParameters); ASSERT(remainingComponents == parameterSize || moreParameters);
ASSERT(parameterSize <= remainingComponents);
remainingComponents -= parameter.getObjectSize(); remainingComponents -= parameterSize;
} }
else UNREACHABLE(); else UNREACHABLE();
...@@ -2929,7 +2934,7 @@ const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const Con ...@@ -2929,7 +2934,7 @@ const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const Con
} }
else else
{ {
int size = type.getObjectSize(); size_t size = type.getObjectSize();
bool writeType = size > 1; bool writeType = size > 1;
if (writeType) if (writeType)
...@@ -2937,7 +2942,7 @@ const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const Con ...@@ -2937,7 +2942,7 @@ const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const Con
out << typeString(type) << "("; out << typeString(type) << "(";
} }
for (int i = 0; i < size; i++, constUnion++) for (size_t i = 0; i < size; i++, constUnion++)
{ {
switch (constUnion->getType()) switch (constUnion->getType())
{ {
......
...@@ -489,7 +489,7 @@ bool TParseContext::constructorErrorCheck(const TSourceLoc& line, TIntermNode* n ...@@ -489,7 +489,7 @@ bool TParseContext::constructorErrorCheck(const TSourceLoc& line, TIntermNode* n
// again, there is an extra argument, so 'overfull' will become true. // again, there is an extra argument, so 'overfull' will become true.
// //
int size = 0; size_t size = 0;
bool constType = true; bool constType = true;
bool full = false; bool full = false;
bool overFull = false; bool overFull = false;
...@@ -1036,13 +1036,7 @@ bool TParseContext::executeInitializer(const TSourceLoc& line, TString& identifi ...@@ -1036,13 +1036,7 @@ bool TParseContext::executeInitializer(const TSourceLoc& line, TString& identifi
return true; return true;
} }
if (initializer->getAsConstantUnion()) { if (initializer->getAsConstantUnion()) {
ConstantUnion* unionArray = variable->getConstPointer(); variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer());
if (type.getObjectSize() == 1 && type.getBasicType() != EbtStruct) {
*unionArray = (initializer->getAsConstantUnion()->getUnionArrayPointer())[0];
} else {
variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer());
}
} else if (initializer->getAsSymbolNode()) { } else if (initializer->getAsSymbolNode()) {
const TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol()); const TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol());
const TVariable* tVar = static_cast<const TVariable*>(symbol); const TVariable* tVar = static_cast<const TVariable*>(symbol);
...@@ -1315,7 +1309,7 @@ TIntermTyped* TParseContext::addConstVectorNode(TVectorFields& fields, TIntermTy ...@@ -1315,7 +1309,7 @@ TIntermTyped* TParseContext::addConstVectorNode(TVectorFields& fields, TIntermTy
ConstantUnion* constArray = new ConstantUnion[fields.num]; ConstantUnion* constArray = new ConstantUnion[fields.num];
for (int i = 0; i < fields.num; i++) { for (int i = 0; i < fields.num; i++) {
if (fields.offsets[i] >= node->getType().getObjectSize()) { if (fields.offsets[i] >= node->getType().getNominalSize()) {
std::stringstream extraInfoStream; std::stringstream extraInfoStream;
extraInfoStream << "vector field selection out of range '" << fields.offsets[i] << "'"; extraInfoStream << "vector field selection out of range '" << fields.offsets[i] << "'";
std::string extraInfo = extraInfoStream.str(); std::string extraInfo = extraInfoStream.str();
...@@ -1388,9 +1382,8 @@ TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, co ...@@ -1388,9 +1382,8 @@ TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, co
index = 0; index = 0;
} }
int arrayElementSize = arrayElementType.getObjectSize();
if (tempConstantNode) { if (tempConstantNode) {
size_t arrayElementSize = arrayElementType.getObjectSize();
ConstantUnion* unionArray = tempConstantNode->getUnionArrayPointer(); ConstantUnion* unionArray = tempConstantNode->getUnionArrayPointer();
typedNode = intermediate.addConstantUnion(&unionArray[arrayElementSize * index], tempConstantNode->getType(), line); typedNode = intermediate.addConstantUnion(&unionArray[arrayElementSize * index], tempConstantNode->getType(), line);
} else { } else {
...@@ -1412,12 +1405,9 @@ TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, co ...@@ -1412,12 +1405,9 @@ TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, co
TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* node, const TSourceLoc& line) TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* node, const TSourceLoc& line)
{ {
const TTypeList* fields = node->getType().getStruct(); const TTypeList* fields = node->getType().getStruct();
TIntermTyped *typedNode;
int instanceSize = 0;
unsigned int index = 0;
TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();
for ( index = 0; index < fields->size(); ++index) { size_t instanceSize = 0;
for (size_t index = 0; index < fields->size(); ++index) {
if ((*fields)[index]->getFieldName() == identifier) { if ((*fields)[index]->getFieldName() == identifier) {
break; break;
} else { } else {
...@@ -1425,6 +1415,8 @@ TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* n ...@@ -1425,6 +1415,8 @@ TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* n
} }
} }
TIntermTyped* typedNode = 0;
TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion();
if (tempConstantNode) { if (tempConstantNode) {
ConstantUnion* constArray = tempConstantNode->getUnionArrayPointer(); ConstantUnion* constArray = tempConstantNode->getUnionArrayPointer();
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <stdio.h> #include <stdio.h>
#include <algorithm> #include <algorithm>
#include <climits>
TType::TType(const TPublicType &p) : TType::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),
...@@ -69,16 +70,44 @@ void TType::buildMangledName(TString& mangledName) ...@@ -69,16 +70,44 @@ void TType::buildMangledName(TString& mangledName)
} }
} }
int TType::getStructSize() const size_t TType::getObjectSize() const
{
size_t totalSize = 0;
if (getBasicType() == EbtStruct)
totalSize = getStructSize();
else if (matrix)
totalSize = size * size;
else
totalSize = size;
if (isArray()) {
size_t arraySize = std::max(getArraySize(), getMaxArraySize());
if (arraySize > INT_MAX / totalSize)
totalSize = INT_MAX;
else
totalSize *= arraySize;
}
return totalSize;
}
size_t TType::getStructSize() const
{ {
if (!getStruct()) { if (!getStruct()) {
assert(false && "Not a struct"); assert(false && "Not a struct");
return 0; return 0;
} }
if (structureSize == 0) if (structureSize == 0) {
for (TTypeList::const_iterator tl = getStruct()->begin(); tl != getStruct()->end(); tl++) for (TTypeList::const_iterator tl = getStruct()->begin(); tl != getStruct()->end(); tl++) {
structureSize += (*tl)->getObjectSize(); size_t fieldSize = (*tl)->getObjectSize();
if (fieldSize > INT_MAX - structureSize)
structureSize = INT_MAX;
else
structureSize += fieldSize;
}
}
return structureSize; return structureSize;
} }
......
...@@ -56,22 +56,7 @@ public: ...@@ -56,22 +56,7 @@ public:
int getNominalSize() const { return size; } int getNominalSize() const { return size; }
void setNominalSize(int s) { size = s; } void setNominalSize(int s) { size = s; }
// Full size of single instance of type // Full size of single instance of type
int getObjectSize() const size_t getObjectSize() const;
{
int totalSize;
if (getBasicType() == EbtStruct)
totalSize = getStructSize();
else if (matrix)
totalSize = size * size;
else
totalSize = size;
if (isArray())
totalSize *= std::max(getArraySize(), getMaxArraySize());
return totalSize;
}
int elementRegisterCount() const int elementRegisterCount() const
{ {
...@@ -210,7 +195,7 @@ public: ...@@ -210,7 +195,7 @@ public:
private: private:
void buildMangledName(TString&); void buildMangledName(TString&);
int getStructSize() const; size_t getStructSize() const;
void computeDeepestStructNesting(); void computeDeepestStructNesting();
TBasicType type : 6; TBasicType type : 6;
...@@ -224,7 +209,7 @@ private: ...@@ -224,7 +209,7 @@ private:
TType* arrayInformationType; TType* arrayInformationType;
TTypeList* structure; // 0 unless this is a struct TTypeList* structure; // 0 unless this is a struct
mutable int structureSize; mutable size_t structureSize;
int deepestStructNesting; int deepestStructNesting;
TString *fieldName; // for structure field names TString *fieldName; // for structure field names
......
...@@ -316,9 +316,9 @@ void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -316,9 +316,9 @@ void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node)
{ {
TInfoSinkBase& out = sink; TInfoSinkBase& out = sink;
int size = node->getType().getObjectSize(); size_t size = node->getType().getObjectSize();
for (int i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
OutputTreeText(out, node, depth); OutputTreeText(out, node, depth);
switch (node->getUnionArrayPointer()[i].getType()) { switch (node->getUnionArrayPointer()[i].getType()) {
case EbtBool: case EbtBool:
......
...@@ -38,16 +38,16 @@ protected: ...@@ -38,16 +38,16 @@ protected:
bool visitLoop(Visit visit, TIntermLoop*); bool visitLoop(Visit visit, TIntermLoop*);
bool visitBranch(Visit visit, TIntermBranch*); bool visitBranch(Visit visit, TIntermBranch*);
int index; size_t index;
ConstantUnion *unionArray; ConstantUnion *unionArray;
TType type; TType type;
TOperator constructorType; TOperator constructorType;
bool singleConstantParam; bool singleConstantParam;
TInfoSink& infoSink; TInfoSink& infoSink;
TSymbolTable& symbolTable; TSymbolTable& symbolTable;
int size; // size of the constructor ( 4 for vec4) size_t size; // size of the constructor ( 4 for vec4)
bool isMatrix; bool isMatrix;
int matrixSize; // dimension of the matrix (nominal size and not the instance size) size_t matrixSize; // dimension of the matrix (nominal size and not the instance size)
}; };
// //
...@@ -159,16 +159,16 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -159,16 +159,16 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
} }
ConstantUnion* leftUnionArray = unionArray; ConstantUnion* leftUnionArray = unionArray;
int instanceSize = type.getObjectSize(); size_t instanceSize = type.getObjectSize();
if (index >= instanceSize) if (index >= instanceSize)
return; return;
if (!singleConstantParam) { if (!singleConstantParam) {
int size = node->getType().getObjectSize(); size_t size = node->getType().getObjectSize();
ConstantUnion *rightUnionArray = node->getUnionArrayPointer(); ConstantUnion *rightUnionArray = node->getUnionArrayPointer();
for (int i=0; i < size; i++) { for (size_t i = 0; i < size; i++) {
if (index >= instanceSize) if (index >= instanceSize)
return; return;
leftUnionArray[index] = rightUnionArray[i]; leftUnionArray[index] = rightUnionArray[i];
...@@ -176,11 +176,11 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -176,11 +176,11 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
(index)++; (index)++;
} }
} else { } else {
int totalSize = index + size; size_t totalSize = index + size;
ConstantUnion *rightUnionArray = node->getUnionArrayPointer(); ConstantUnion *rightUnionArray = node->getUnionArrayPointer();
if (!isMatrix) { if (!isMatrix) {
int count = 0; size_t count = 0;
for (int i = index; i < totalSize; i++) { for (size_t i = index; i < totalSize; i++) {
if (i >= instanceSize) if (i >= instanceSize)
return; return;
...@@ -192,9 +192,9 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -192,9 +192,9 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
count++; count++;
} }
} else { // for matrix constructors } else { // for matrix constructors
int count = 0; size_t count = 0;
int element = index; size_t element = index;
for (int i = index; i < totalSize; i++) { for (size_t i = index; i < totalSize; i++) {
if (i >= instanceSize) if (i >= instanceSize)
return; return;
if (element - i == 0 || (i - element) % (matrixSize + 1) == 0 ) if (element - i == 0 || (i - element) % (matrixSize + 1) == 0 )
......
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