Commit 94bf7f22 by Jamie Madill Committed by Shannon Woods

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/trunk@2211 736b8ea6-26fd-11df-bfd4-992fa37f6226 TRAC #23333 Authored-by: alokp@chromium.org Signed-off-by: Shannon Woods Signed-off-by Nicolas Capens Merged-by: Jamie Madill
parent 7164cf47
......@@ -1145,11 +1145,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].type->getObjectSize();
for (int i = 0; i < size; i++) {
size_t size = (*fields)[j].type->getObjectSize();
for (size_t i = 0; i < size; i++) {
if ((*fields)[j].type->getBasicType() == EbtStruct) {
if (!CompareStructure(*(*fields)[j].type, &rightUnionArray[index], &leftUnionArray[index]))
return false;
......@@ -1170,10 +1170,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;
}
......@@ -1193,7 +1193,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)
{
......@@ -1206,7 +1206,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
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();
}
......@@ -1216,7 +1216,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
{
// 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();
}
......@@ -1232,14 +1232,14 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EOpAdd:
tempConstArray = new ConstantUnion[objectSize];
{
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];
{
for (int i = 0; i < objectSize; i++)
for (size_t i = 0; i < objectSize; i++)
tempConstArray[i] = unionArray[i] - rightUnionArray[i];
}
break;
......@@ -1249,7 +1249,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EOpMatrixTimesScalar:
tempConstArray = new ConstantUnion[objectSize];
{
for (int i = 0; i < objectSize; i++)
for (size_t i = 0; i < objectSize; i++)
tempConstArray[i] = unionArray[i] * rightUnionArray[i];
}
break;
......@@ -1291,7 +1291,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EOpDiv:
{
tempConstArray = new ConstantUnion[objectSize];
for (int i = 0; i < objectSize; i++)
for (size_t i = 0; i < objectSize; i++)
{
switch (getType().getBasicType())
{
......@@ -1399,7 +1399,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];
for (int i = 0; i < objectSize; i++)
for (size_t i = 0; i < objectSize; i++)
{
tempConstArray[i] = unionArray[i] && rightUnionArray[i];
}
......@@ -1409,7 +1409,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];
for (int i = 0; i < objectSize; i++)
for (size_t i = 0; i < objectSize; i++)
{
tempConstArray[i] = unionArray[i] || rightUnionArray[i];
}
......@@ -1419,7 +1419,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EOpLogicalXor:
{
tempConstArray = new ConstantUnion[objectSize];
for (int i = 0; i < objectSize; i++)
for (size_t i = 0; i < objectSize; i++)
{
switch (getType().getBasicType())
{
......@@ -1478,7 +1478,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
}
else
{
for (int i = 0; i < objectSize; i++)
for (size_t i = 0; i < objectSize; i++)
{
if (unionArray[i] != rightUnionArray[i])
{
......@@ -1511,7 +1511,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
}
else
{
for (int i = 0; i < objectSize; i++)
for (size_t i = 0; i < objectSize; i++)
{
if (unionArray[i] == rightUnionArray[i])
{
......@@ -1552,7 +1552,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)
{
......@@ -1590,11 +1590,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())
{
......
......@@ -3008,11 +3008,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 += ", ";
}
......@@ -3244,13 +3245,14 @@ 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);
......@@ -3260,11 +3262,12 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI
}
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)
{
......@@ -3281,9 +3284,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();
......@@ -3340,7 +3344,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)
......@@ -3348,7 +3352,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())
{
......
......@@ -486,7 +486,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;
......@@ -1124,13 +1124,7 @@ bool TParseContext::executeInitializer(const TSourceLoc& line, const TString& id
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(), 0);
const TVariable* tVar = static_cast<const TVariable*>(symbol);
......@@ -1767,7 +1761,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();
......@@ -1840,11 +1834,10 @@ TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, co
index = 0;
}
int arrayElementSize = arrayElementType.getObjectSize();
if (tempConstantNode) {
ConstantUnion* unionArray = tempConstantNode->getUnionArrayPointer();
typedNode = intermediate.addConstantUnion(&unionArray[arrayElementSize * index], tempConstantNode->getType(), line);
size_t arrayElementSize = arrayElementType.getObjectSize();
ConstantUnion* unionArray = tempConstantNode->getUnionArrayPointer();
typedNode = intermediate.addConstantUnion(&unionArray[arrayElementSize * index], tempConstantNode->getType(), line);
} else {
error(line, "Cannot offset into the array", "Error");
recover();
......@@ -1864,12 +1857,9 @@ TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, co
TIntermTyped* TParseContext::addConstStruct(const 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();
size_t instanceSize = 0;
for ( index = 0; index < fields->size(); ++index) {
for (size_t index = 0; index < fields->size(); ++index) {
if ((*fields)[index].type->getFieldName() == identifier) {
break;
} else {
......@@ -1877,6 +1867,8 @@ TIntermTyped* TParseContext::addConstStruct(const TString &identifier, TIntermTy
}
}
TIntermTyped *typedNode;
TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();
if (tempConstantNode) {
ConstantUnion* constArray = tempConstantNode->getUnionArrayPointer();
......
......@@ -17,6 +17,7 @@
#include <stdio.h>
#include <algorithm>
#include <climits>
int TSymbolTableLevel::uniqueId = 0;
......@@ -106,16 +107,42 @@ void TType::buildMangledName(TString& mangledName)
}
}
int TType::getStructSize() const
size_t TType::getObjectSize() const
{
size_t totalSize;
if (getBasicType() == EbtStruct)
totalSize = getStructSize();
else
totalSize = primarySize * secondarySize;
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).type)->getObjectSize();
if (structureSize == 0) {
for (TTypeList::const_iterator tl = getStruct()->begin(); tl != getStruct()->end(); tl++) {
size_t fieldSize = ((*tl).type)->getObjectSize();
if (fieldSize > INT_MAX - structureSize)
structureSize = INT_MAX;
else
structureSize += fieldSize;
}
}
return structureSize;
}
......
......@@ -70,20 +70,7 @@ public:
void setSecondarySize(int ss) { secondarySize = ss; }
// Full size of single instance of type
int getObjectSize() const
{
int totalSize;
if (getBasicType() == EbtStruct)
totalSize = getStructSize();
else
totalSize = primarySize * secondarySize;
if (isArray())
totalSize *= std::max(getArraySize(), getMaxArraySize());
return totalSize;
}
size_t getObjectSize() const;
int elementRegisterCount() const
{
......@@ -243,7 +230,7 @@ public:
private:
void buildMangledName(TString&);
int getStructSize() const;
size_t getStructSize() const;
void computeDeepestStructNesting();
TBasicType type : 6;
......@@ -259,7 +246,7 @@ private:
TType* interfaceBlockType;
TTypeList* structure; // 0 unless this is a struct
mutable int structureSize;
mutable size_t structureSize;
int deepestStructNesting;
TString *fieldName; // for structure field names
......
......@@ -327,9 +327,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,13 +38,13 @@ 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;
int size; // size of the constructor ( 4 for vec4)
size_t size; // size of the constructor ( 4 for vec4)
bool isDiagonalMatrixInit;
int matrixCols; // columns of the matrix
int matrixRows; // rows of the matrix
......@@ -161,16 +161,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 objectSize = node->getType().getObjectSize();
size_t objectSize = node->getType().getObjectSize();
ConstantUnion *rightUnionArray = node->getUnionArrayPointer();
for (int i=0; i < objectSize; i++) {
for (size_t i=0; i < objectSize; i++) {
if (index >= instanceSize)
return;
leftUnionArray[index] = rightUnionArray[i];
......@@ -178,11 +178,11 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
(index)++;
}
} else {
int totalSize = index + size;
size_t totalSize = index + size;
ConstantUnion *rightUnionArray = node->getUnionArrayPointer();
if (!isDiagonalMatrixInit) {
int count = 0;
for (int i = index; i < totalSize; i++) {
for (size_t i = index; i < totalSize; i++) {
if (i >= instanceSize)
return;
......
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