Commit 4b721cda by alokp@chromium.org

Removed checks for zero-length arrays because you can never define such arrays.

Also removed support for max-array-size. You can only define a fixed-size array. TEST=WebGL conformance tests Review URL: https://codereview.appspot.com/9697044 git-svn-id: https://angleproject.googlecode.com/svn/trunk@2247 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 91627bc7
...@@ -778,16 +778,6 @@ bool TParseContext::arrayErrorCheck(const TSourceLoc& line, TString& identifier, ...@@ -778,16 +778,6 @@ bool TParseContext::arrayErrorCheck(const TSourceLoc& line, TString& identifier,
return true; return true;
} }
TType* t = variable->getArrayInformationType();
while (t != 0) {
if (t->getMaxArraySize() > type.arraySize) {
error(line, "higher index value already used for the array", identifier.c_str());
return true;
}
t->setArraySize(type.arraySize);
t = t->getArrayInformationType();
}
if (type.arraySize) if (type.arraySize)
variable->getType().setArraySize(type.arraySize); variable->getType().setArraySize(type.arraySize);
} }
...@@ -798,50 +788,6 @@ bool TParseContext::arrayErrorCheck(const TSourceLoc& line, TString& identifier, ...@@ -798,50 +788,6 @@ bool TParseContext::arrayErrorCheck(const TSourceLoc& line, TString& identifier,
return false; return false;
} }
bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, bool updateFlag, const TSourceLoc& line)
{
bool builtIn = false;
TSymbol* symbol = symbolTable.find(node->getSymbol(), &builtIn);
if (symbol == 0) {
error(line, " undeclared identifier", node->getSymbol().c_str());
return true;
}
TVariable* variable = static_cast<TVariable*>(symbol);
type->setArrayInformationType(variable->getArrayInformationType());
variable->updateArrayInformationType(type);
// special casing to test index value of gl_FragData. If the accessed index is >= gl_MaxDrawBuffers
// its an error
if (node->getSymbol() == "gl_FragData") {
TSymbol* fragData = symbolTable.find("gl_MaxDrawBuffers", &builtIn);
ASSERT(fragData);
int fragDataValue = static_cast<TVariable*>(fragData)->getConstPointer()[0].getIConst();
if (fragDataValue <= size) {
error(line, "", "[", "gl_FragData can only have a max array size of up to gl_MaxDrawBuffers");
return true;
}
}
// we dont want to update the maxArraySize when this flag is not set, we just want to include this
// node type in the chain of node types so that its updated when a higher maxArraySize comes in.
if (!updateFlag)
return false;
size++;
variable->getType().setMaxArraySize(size);
type->setMaxArraySize(size);
TType* tt = type;
while(tt->getArrayInformationType() != 0) {
tt = tt->getArrayInformationType();
tt->setMaxArraySize(size);
}
return false;
}
// //
// Enforce non-initializer type/qualifier rules. // Enforce non-initializer type/qualifier rules.
// //
......
...@@ -107,7 +107,6 @@ struct TParseContext { ...@@ -107,7 +107,6 @@ struct TParseContext {
const TFunction* findFunction(const TSourceLoc& line, TFunction* pfnCall, bool *builtIn = 0); const TFunction* findFunction(const TSourceLoc& line, TFunction* pfnCall, bool *builtIn = 0);
bool executeInitializer(const TSourceLoc& line, TString& identifier, TPublicType& pType, bool executeInitializer(const TSourceLoc& line, TString& identifier, TPublicType& pType,
TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0); TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0);
bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, const TSourceLoc&);
TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, const TSourceLoc&); TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, const TSourceLoc&);
TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type); TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type);
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
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),
maxArraySize(0), arrayInformationType(0), structure(0), structureSize(0), deepestStructNesting(0), fieldName(0), mangled(0), typeName(0) structure(0), structureSize(0), deepestStructNesting(0), fieldName(0), mangled(0), typeName(0)
{ {
if (p.userDef) { if (p.userDef) {
structure = p.userDef->getStruct(); structure = p.userDef->getStruct();
...@@ -82,7 +82,7 @@ size_t TType::getObjectSize() const ...@@ -82,7 +82,7 @@ size_t TType::getObjectSize() const
totalSize = size; totalSize = size;
if (isArray()) { if (isArray()) {
size_t arraySize = std::max(getArraySize(), getMaxArraySize()); size_t arraySize = getArraySize();
if (arraySize > INT_MAX / totalSize) if (arraySize > INT_MAX / totalSize)
totalSize = INT_MAX; totalSize = INT_MAX;
else else
......
...@@ -71,15 +71,13 @@ private: ...@@ -71,15 +71,13 @@ private:
// //
class TVariable : public TSymbol { class TVariable : public TSymbol {
public: public:
TVariable(const TString *name, const TType& t, bool uT = false ) : TSymbol(name), type(t), userType(uT), unionArray(0), arrayInformationType(0) { } TVariable(const TString *name, const TType& t, bool uT = false ) : TSymbol(name), type(t), userType(uT), unionArray(0) { }
virtual ~TVariable() { } virtual ~TVariable() { }
virtual bool isVariable() const { return true; } virtual bool isVariable() const { return true; }
TType& getType() { return type; } TType& getType() { return type; }
const TType& getType() const { return type; } const TType& getType() const { return type; }
bool isUserType() const { return userType; } bool isUserType() const { return userType; }
void setQualifier(TQualifier qualifier) { type.setQualifier(qualifier); } void setQualifier(TQualifier qualifier) { type.setQualifier(qualifier); }
void updateArrayInformationType(TType *t) { arrayInformationType = t; }
TType* getArrayInformationType() { return arrayInformationType; }
virtual void dump(TInfoSink &infoSink) const; virtual void dump(TInfoSink &infoSink) const;
...@@ -110,7 +108,6 @@ private: ...@@ -110,7 +108,6 @@ private:
// we are assuming that Pool Allocator will free the memory allocated to unionArray // we are assuming that Pool Allocator will free the memory allocated to unionArray
// when this object is destroyed // when this object is destroyed
ConstantUnion *unionArray; ConstantUnion *unionArray;
TType *arrayInformationType; // this is used for updating maxArraySize in all the references to a given symbol
}; };
// //
......
...@@ -32,13 +32,13 @@ public: ...@@ -32,13 +32,13 @@ public:
TType() {} TType() {}
TType(TBasicType t, TPrecision p, TQualifier q = EvqTemporary, int s = 1, bool m = false, bool a = false) : TType(TBasicType t, TPrecision p, TQualifier q = EvqTemporary, int s = 1, bool m = false, bool a = false) :
type(t), precision(p), qualifier(q), size(s), matrix(m), array(a), arraySize(0), type(t), precision(p), qualifier(q), size(s), matrix(m), array(a), arraySize(0),
maxArraySize(0), arrayInformationType(0), structure(0), structureSize(0), deepestStructNesting(0), fieldName(0), mangled(0), typeName(0) structure(0), structureSize(0), deepestStructNesting(0), fieldName(0), mangled(0), typeName(0)
{ {
} }
explicit TType(const TPublicType &p); explicit TType(const TPublicType &p);
TType(TTypeList* userDef, const TString& n, TPrecision p = EbpUndefined) : TType(TTypeList* userDef, const TString& n, TPrecision p = EbpUndefined) :
type(EbtStruct), precision(p), qualifier(EvqTemporary), size(1), matrix(false), array(false), arraySize(0), type(EbtStruct), precision(p), qualifier(EvqTemporary), size(1), matrix(false), array(false), arraySize(0),
maxArraySize(0), arrayInformationType(0), structure(userDef), structureSize(0), deepestStructNesting(0), fieldName(0), mangled(0) structure(userDef), structureSize(0), deepestStructNesting(0), fieldName(0), mangled(0)
{ {
typeName = NewPoolTString(n.c_str()); typeName = NewPoolTString(n.c_str());
} }
...@@ -64,11 +64,7 @@ public: ...@@ -64,11 +64,7 @@ public:
bool isArray() const { return array ? true : false; } bool isArray() const { return array ? true : false; }
int getArraySize() const { return arraySize; } int getArraySize() const { return arraySize; }
void setArraySize(int s) { array = true; arraySize = s; } void setArraySize(int s) { array = true; arraySize = s; }
int getMaxArraySize () const { return maxArraySize; } void clearArrayness() { array = false; arraySize = 0; }
void setMaxArraySize (int s) { maxArraySize = s; }
void clearArrayness() { array = false; arraySize = 0; maxArraySize = 0; }
void setArrayInformationType(TType* t) { arrayInformationType = t; }
TType* getArrayInformationType() const { return arrayInformationType; }
bool isVector() const { return size > 1 && !matrix; } bool isVector() const { return size > 1 && !matrix; }
bool isScalar() const { return size == 1 && !matrix && !structure; } bool isScalar() const { return size == 1 && !matrix && !structure; }
...@@ -168,8 +164,6 @@ private: ...@@ -168,8 +164,6 @@ private:
unsigned int matrix : 1; unsigned int matrix : 1;
unsigned int array : 1; unsigned int array : 1;
int arraySize; int arraySize;
int maxArraySize;
TType* arrayInformationType;
TTypeList* structure; // 0 unless this is a struct TTypeList* structure; // 0 unless this is a struct
mutable size_t structureSize; mutable size_t structureSize;
......
...@@ -282,15 +282,7 @@ postfix_expression ...@@ -282,15 +282,7 @@ postfix_expression
} }
} else { } else {
if ($1->isArray()) { if ($1->isArray()) {
if ($1->getType().getArraySize() == 0) { if (index >= $1->getType().getArraySize()) {
if ($1->getType().getMaxArraySize() <= index) {
if (context->arraySetMaxSize($1->getAsSymbolNode(), $1->getTypePointer(), index, true, @2))
context->recover();
} else {
if (context->arraySetMaxSize($1->getAsSymbolNode(), $1->getTypePointer(), 0, false, @2))
context->recover();
}
} else if (index >= $1->getType().getArraySize()) {
std::stringstream extraInfoStream; std::stringstream extraInfoStream;
extraInfoStream << "array index out of range '" << index << "'"; extraInfoStream << "array index out of range '" << index << "'";
std::string extraInfo = extraInfoStream.str(); std::string extraInfo = extraInfoStream.str();
...@@ -310,10 +302,6 @@ postfix_expression ...@@ -310,10 +302,6 @@ postfix_expression
$$ = context->intermediate.addIndex(EOpIndexDirect, $1, $3, @2); $$ = context->intermediate.addIndex(EOpIndexDirect, $1, $3, @2);
} }
} else { } else {
if ($1->isArray() && $1->getType().getArraySize() == 0) {
context->error(@2, "", "[", "array must be redeclared with a size before being indexed with a variable");
context->recover();
}
$$ = context->intermediate.addIndex(EOpIndexIndirect, $1, $3, @2); $$ = context->intermediate.addIndex(EOpIndexIndirect, $1, $3, @2);
} }
if ($$ == 0) { if ($$ == 0) {
......
...@@ -714,26 +714,26 @@ static const yytype_int16 yyrhs[] = ...@@ -714,26 +714,26 @@ static const yytype_int16 yyrhs[] =
static const yytype_uint16 yyrline[] = static const yytype_uint16 yyrline[] =
{ {
0, 179, 179, 180, 183, 219, 222, 235, 240, 245, 0, 179, 179, 180, 183, 219, 222, 235, 240, 245,
251, 254, 341, 344, 445, 455, 468, 476, 576, 579, 251, 254, 329, 332, 433, 443, 456, 464, 564, 567,
587, 590, 596, 600, 607, 613, 622, 630, 685, 695, 575, 578, 584, 588, 595, 601, 610, 618, 673, 683,
698, 708, 718, 739, 740, 741, 746, 747, 755, 766, 686, 696, 706, 727, 728, 729, 734, 735, 743, 754,
767, 775, 786, 790, 791, 801, 811, 821, 834, 835, 755, 763, 774, 778, 779, 789, 799, 809, 822, 823,
845, 858, 862, 866, 870, 871, 884, 885, 898, 899, 833, 846, 850, 854, 858, 859, 872, 873, 886, 887,
912, 913, 930, 931, 944, 945, 946, 947, 948, 952, 900, 901, 918, 919, 932, 933, 934, 935, 936, 940,
955, 966, 974, 1001, 1006, 1020, 1057, 1060, 1067, 1075, 943, 954, 962, 989, 994, 1008, 1045, 1048, 1055, 1063,
1096, 1117, 1127, 1155, 1160, 1170, 1175, 1185, 1188, 1191, 1084, 1105, 1115, 1143, 1148, 1158, 1163, 1173, 1176, 1179,
1194, 1200, 1207, 1210, 1232, 1250, 1274, 1297, 1301, 1319, 1182, 1188, 1195, 1198, 1220, 1238, 1262, 1285, 1289, 1307,
1327, 1359, 1379, 1400, 1409, 1432, 1435, 1441, 1449, 1457, 1315, 1347, 1367, 1388, 1397, 1420, 1423, 1429, 1437, 1445,
1465, 1475, 1482, 1485, 1488, 1494, 1497, 1512, 1516, 1520, 1453, 1463, 1470, 1473, 1476, 1482, 1485, 1500, 1504, 1508,
1524, 1528, 1533, 1538, 1543, 1548, 1553, 1558, 1563, 1568, 1512, 1516, 1521, 1526, 1531, 1536, 1541, 1546, 1551, 1556,
1573, 1578, 1583, 1588, 1592, 1596, 1604, 1612, 1616, 1629, 1561, 1566, 1571, 1576, 1580, 1584, 1592, 1600, 1604, 1617,
1629, 1643, 1643, 1652, 1655, 1671, 1707, 1711, 1717, 1724, 1617, 1631, 1631, 1640, 1643, 1659, 1695, 1699, 1705, 1712,
1739, 1743, 1747, 1748, 1754, 1755, 1756, 1757, 1758, 1762, 1727, 1731, 1735, 1736, 1742, 1743, 1744, 1745, 1746, 1750,
1763, 1763, 1763, 1773, 1774, 1778, 1778, 1779, 1779, 1784, 1751, 1751, 1751, 1761, 1762, 1766, 1766, 1767, 1767, 1772,
1787, 1797, 1800, 1806, 1807, 1811, 1819, 1823, 1833, 1838, 1775, 1785, 1788, 1794, 1795, 1799, 1807, 1811, 1821, 1826,
1855, 1855, 1860, 1860, 1867, 1867, 1875, 1878, 1884, 1887, 1843, 1843, 1848, 1848, 1855, 1855, 1863, 1866, 1872, 1875,
1893, 1897, 1904, 1911, 1918, 1925, 1936, 1945, 1949, 1956, 1881, 1885, 1892, 1899, 1906, 1913, 1924, 1933, 1937, 1944,
1959, 1965, 1965 1947, 1953, 1953
}; };
#endif #endif
...@@ -2369,15 +2369,7 @@ yyreduce: ...@@ -2369,15 +2369,7 @@ yyreduce:
} }
} else { } else {
if ((yyvsp[(1) - (4)].interm.intermTypedNode)->isArray()) { if ((yyvsp[(1) - (4)].interm.intermTypedNode)->isArray()) {
if ((yyvsp[(1) - (4)].interm.intermTypedNode)->getType().getArraySize() == 0) { if (index >= (yyvsp[(1) - (4)].interm.intermTypedNode)->getType().getArraySize()) {
if ((yyvsp[(1) - (4)].interm.intermTypedNode)->getType().getMaxArraySize() <= index) {
if (context->arraySetMaxSize((yyvsp[(1) - (4)].interm.intermTypedNode)->getAsSymbolNode(), (yyvsp[(1) - (4)].interm.intermTypedNode)->getTypePointer(), index, true, (yylsp[(2) - (4)])))
context->recover();
} else {
if (context->arraySetMaxSize((yyvsp[(1) - (4)].interm.intermTypedNode)->getAsSymbolNode(), (yyvsp[(1) - (4)].interm.intermTypedNode)->getTypePointer(), 0, false, (yylsp[(2) - (4)])))
context->recover();
}
} else if (index >= (yyvsp[(1) - (4)].interm.intermTypedNode)->getType().getArraySize()) {
std::stringstream extraInfoStream; std::stringstream extraInfoStream;
extraInfoStream << "array index out of range '" << index << "'"; extraInfoStream << "array index out of range '" << index << "'";
std::string extraInfo = extraInfoStream.str(); std::string extraInfo = extraInfoStream.str();
...@@ -2397,10 +2389,6 @@ yyreduce: ...@@ -2397,10 +2389,6 @@ yyreduce:
(yyval.interm.intermTypedNode) = context->intermediate.addIndex(EOpIndexDirect, (yyvsp[(1) - (4)].interm.intermTypedNode), (yyvsp[(3) - (4)].interm.intermTypedNode), (yylsp[(2) - (4)])); (yyval.interm.intermTypedNode) = context->intermediate.addIndex(EOpIndexDirect, (yyvsp[(1) - (4)].interm.intermTypedNode), (yyvsp[(3) - (4)].interm.intermTypedNode), (yylsp[(2) - (4)]));
} }
} else { } else {
if ((yyvsp[(1) - (4)].interm.intermTypedNode)->isArray() && (yyvsp[(1) - (4)].interm.intermTypedNode)->getType().getArraySize() == 0) {
context->error((yylsp[(2) - (4)]), "", "[", "array must be redeclared with a size before being indexed with a variable");
context->recover();
}
(yyval.interm.intermTypedNode) = context->intermediate.addIndex(EOpIndexIndirect, (yyvsp[(1) - (4)].interm.intermTypedNode), (yyvsp[(3) - (4)].interm.intermTypedNode), (yylsp[(2) - (4)])); (yyval.interm.intermTypedNode) = context->intermediate.addIndex(EOpIndexIndirect, (yyvsp[(1) - (4)].interm.intermTypedNode), (yyvsp[(3) - (4)].interm.intermTypedNode), (yylsp[(2) - (4)]));
} }
if ((yyval.interm.intermTypedNode) == 0) { if ((yyval.interm.intermTypedNode) == 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