Move the code for parsing constructor functions from the grammar to TParseContext.

TRAC #23080 Signed-off-by: Nicolas Capens Signed-off-by: Shannon Woods Author: Jamie Madill git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2402 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 3c9d95a8
......@@ -1149,6 +1149,77 @@ TPublicType TParseContext::addFullySpecifiedType(TQualifier qualifier, const TPu
return returnType;
}
TFunction *TParseContext::addConstructorFunc(TPublicType publicType)
{
TOperator op = EOpNull;
if (publicType.userDef)
{
op = EOpConstructStruct;
}
else
{
switch (publicType.type)
{
case EbtFloat:
if (publicType.isMatrix())
{
// TODO: non-square matrices
switch(publicType.getCols())
{
case 2: op = EOpConstructMat2; break;
case 3: op = EOpConstructMat3; break;
case 4: op = EOpConstructMat4; break;
}
}
else
{
switch(publicType.getNominalSize())
{
case 1: op = EOpConstructFloat; break;
case 2: op = EOpConstructVec2; break;
case 3: op = EOpConstructVec3; break;
case 4: op = EOpConstructVec4; break;
}
}
break;
case EbtInt:
switch(publicType.getNominalSize())
{
case 1: op = EOpConstructInt; break;
case 2: op = EOpConstructIVec2; break;
case 3: op = EOpConstructIVec3; break;
case 4: op = EOpConstructIVec4; break;
}
break;
case EbtBool:
switch(publicType.getNominalSize())
{
case 1: op = EOpConstructBool; break;
case 2: op = EOpConstructBVec2; break;
case 3: op = EOpConstructBVec3; break;
case 4: op = EOpConstructBVec4; break;
}
break;
default: break;
}
if (op == EOpNull)
{
error(publicType.line, "cannot construct this type", getBasicString(publicType.type));
recover();
publicType.type = EbtFloat;
op = EOpConstructFloat;
}
}
TString tempString;
TType type(publicType);
return new TFunction(&tempString, type, op);
}
// This function is used to test for the correctness of the parameters passed to various constructor functions
// and also convert them to the right datatype if it is allowed and required.
//
......
......@@ -121,6 +121,7 @@ struct TParseContext {
bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc);
TPublicType addFullySpecifiedType(TQualifier qualifier, const TPublicType& typeSpecifier);
TFunction *addConstructorFunc(TPublicType publicType);
TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, TSourceLoc);
TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type);
TIntermTyped* constructStruct(TIntermNode*, TType*, int, TSourceLoc, bool subset);
......
......@@ -443,59 +443,7 @@ function_call_header
function_identifier
: type_specifier_nonarray {
//
// Constructor
//
TOperator op = EOpNull;
if ($1.userDef) {
op = EOpConstructStruct;
} else {
switch ($1.type) {
case EbtFloat:
if ($1.isMatrix()) {
switch($1.getCols()) {
case 2: op = EOpConstructMat2; break;
case 3: op = EOpConstructMat3; break;
case 4: op = EOpConstructMat4; break;
}
} else {
switch($1.getNominalSize()) {
case 1: op = EOpConstructFloat; break;
case 2: op = EOpConstructVec2; break;
case 3: op = EOpConstructVec3; break;
case 4: op = EOpConstructVec4; break;
}
}
break;
case EbtInt:
switch($1.getNominalSize()) {
case 1: op = EOpConstructInt; break;
case 2: FRAG_VERT_ONLY("ivec2", $1.line); op = EOpConstructIVec2; break;
case 3: FRAG_VERT_ONLY("ivec3", $1.line); op = EOpConstructIVec3; break;
case 4: FRAG_VERT_ONLY("ivec4", $1.line); op = EOpConstructIVec4; break;
}
break;
case EbtBool:
switch($1.getNominalSize()) {
case 1: op = EOpConstructBool; break;
case 2: FRAG_VERT_ONLY("bvec2", $1.line); op = EOpConstructBVec2; break;
case 3: FRAG_VERT_ONLY("bvec3", $1.line); op = EOpConstructBVec3; break;
case 4: FRAG_VERT_ONLY("bvec4", $1.line); op = EOpConstructBVec4; break;
}
break;
default: break;
}
if (op == EOpNull) {
context->error($1.line, "cannot construct this type", getBasicString($1.type));
context->recover();
$1.type = EbtFloat;
op = EOpConstructFloat;
}
}
TString tempString;
TType type($1);
TFunction *function = new TFunction(&tempString, type, op);
$$ = function;
$$ = context->addConstructorFunc($1);
}
| IDENTIFIER {
if (context->reservedErrorCheck($1.line, *$1.string))
......
......@@ -726,6 +726,7 @@ static const yytype_int16 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
<<<<<<< current
0, 187, 187, 222, 225, 230, 235, 240, 246, 249,
252, 255, 258, 268, 281, 289, 389, 392, 400, 404,
411, 415, 422, 428, 437, 445, 500, 507, 517, 520,
......@@ -749,6 +750,31 @@ static const yytype_uint16 yyrline[] =
1849, 1849, 1854, 1854, 1861, 1861, 1869, 1872, 1878, 1881,
1887, 1891, 1898, 1905, 1912, 1919, 1930, 1939, 1943, 1950,
1953, 1959, 1959
=======
0, 192, 192, 227, 230, 235, 240, 245, 251, 254,
257, 260, 263, 273, 286, 294, 394, 397, 405, 409,
416, 420, 427, 433, 442, 450, 456, 463, 473, 476,
486, 496, 517, 518, 519, 524, 525, 534, 546, 547,
555, 566, 570, 571, 581, 591, 601, 614, 615, 625,
638, 642, 646, 650, 651, 664, 665, 678, 679, 692,
693, 710, 711, 724, 725, 726, 727, 728, 732, 735,
746, 754, 762, 789, 794, 805, 809, 813, 820, 858,
861, 868, 876, 897, 918, 929, 958, 963, 973, 978,
988, 991, 994, 997, 1003, 1010, 1013, 1035, 1053, 1077,
1100, 1104, 1122, 1130, 1162, 1182, 1271, 1280, 1286, 1290,
1297, 1303, 1310, 1319, 1328, 1331, 1367, 1374, 1378, 1385,
1389, 1394, 1399, 1404, 1409, 1418, 1428, 1435, 1438, 1441,
1447, 1454, 1457, 1463, 1466, 1476, 1479, 1494, 1498, 1502,
1506, 1515, 1520, 1525, 1530, 1535, 1540, 1545, 1550, 1555,
1560, 1566, 1572, 1578, 1584, 1590, 1596, 1602, 1608, 1614,
1619, 1624, 1633, 1642, 1647, 1660, 1660, 1663, 1663, 1669,
1672, 1687, 1690, 1698, 1702, 1708, 1716, 1732, 1736, 1740,
1741, 1747, 1748, 1749, 1750, 1751, 1755, 1756, 1756, 1756,
1766, 1767, 1771, 1771, 1772, 1772, 1777, 1780, 1790, 1793,
1799, 1800, 1804, 1812, 1816, 1826, 1831, 1848, 1848, 1853,
1853, 1860, 1860, 1868, 1871, 1877, 1880, 1886, 1890, 1897,
1904, 1911, 1918, 1929, 1938, 1942, 1949, 1952, 1958, 1958
>>>>>>> patched
};
#endif
......@@ -2576,6 +2602,7 @@ yyreduce:
//
// Constructor
//
<<<<<<< current
TOperator op = EOpNull;
if ((yyvsp[(1) - (1)].interm.type).userDef) {
op = EOpConstructStruct;
......@@ -2626,6 +2653,9 @@ yyreduce:
TType type((yyvsp[(1) - (1)].interm.type));
TFunction *function = new TFunction(&tempString, type, op);
(yyval.interm.function) = function;
=======
(yyval.interm.function) = context->addConstructorFunc((yyvsp[(1) - (1)].interm.type));
>>>>>>> patched
}
break;
......
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