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