Commit 5c09702f by Jamie Madill

Add a getNamedVariable helper method to TParseContext.

This method will be useful in more than one place, since we need to get a TType from an indentifier when parsing invariant declarations. BUG=angle:711 Change-Id: I1c1befbdcc93ea626428fb4e313b8c6326c158f6 Reviewed-on: https://chromium-review.googlesource.com/212937Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org>
parent 6053a52e
......@@ -1018,6 +1018,45 @@ void TParseContext::handlePragmaDirective(const TSourceLoc& loc, const char* nam
//
/////////////////////////////////////////////////////////////////////////////////
const TVariable *TParseContext::getNamedVariable(const TSourceLoc &location,
const TString *name,
const TSymbol *symbol)
{
const TVariable *variable = NULL;
if (!symbol)
{
error(location, "undeclared identifier", name->c_str());
recover();
}
else if (!symbol->isVariable())
{
error(location, "variable expected", name->c_str());
recover();
}
else
{
variable = static_cast<const TVariable*>(symbol);
if (symbolTable.findBuiltIn(variable->getName(), shaderVersion) &&
!variable->getExtension().empty() &&
extensionErrorCheck(location, variable->getExtension()))
{
recover();
}
}
if (!variable)
{
TType type(EbtFloat, EbpUndefined);
TVariable *fakeVariable = new TVariable(name, type);
symbolTable.declare(fakeVariable);
variable = fakeVariable;
}
return variable;
}
//
// Look up a function name in the symbol table, and make sure it is a function.
//
......
......@@ -77,6 +77,9 @@ struct TParseContext {
void trace(const char* str);
void recover();
// This method is guaranteed to succeed, even if no variable with 'name' exists.
const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol);
bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc& line);
bool parseMatrixFields(const TString&, int matCols, int matRows, TMatrixFields&, const TSourceLoc& line);
......
......@@ -209,38 +209,7 @@ identifier
variable_identifier
: IDENTIFIER {
// The symbol table search was done in the lexical phase
const TSymbol *symbol = $1.symbol;
const TVariable *variable = 0;
if (!symbol)
{
context->error(@1, "undeclared identifier", $1.string->c_str());
context->recover();
}
else if (!symbol->isVariable())
{
context->error(@1, "variable expected", $1.string->c_str());
context->recover();
}
else
{
variable = static_cast<const TVariable*>(symbol);
if (context->symbolTable.findBuiltIn(variable->getName(), context->shaderVersion) &&
!variable->getExtension().empty() &&
context->extensionErrorCheck(@1, variable->getExtension()))
{
context->recover();
}
}
if (!variable)
{
TType type(EbtFloat, EbpUndefined);
TVariable *fakeVariable = new TVariable($1.string, type);
context->symbolTable.declare(fakeVariable);
variable = fakeVariable;
}
const TVariable *variable = context->getNamedVariable(@1, $1.string, $1.symbol);
if (variable->getType().getQualifier() == EvqConst)
{
......
......@@ -795,32 +795,32 @@ static const yytype_int16 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
0, 205, 205, 206, 209, 264, 267, 272, 277, 282,
287, 293, 296, 299, 302, 305, 315, 328, 336, 436,
439, 447, 450, 456, 460, 467, 473, 482, 490, 493,
503, 506, 516, 526, 547, 548, 549, 554, 555, 563,
574, 575, 583, 594, 598, 599, 609, 619, 629, 642,
643, 653, 666, 670, 674, 678, 679, 692, 693, 706,
707, 720, 721, 738, 739, 752, 753, 754, 755, 756,
760, 763, 774, 782, 790, 817, 822, 833, 837, 841,
845, 852, 907, 910, 917, 925, 946, 967, 977, 1005,
1010, 1020, 1025, 1035, 1038, 1041, 1044, 1050, 1057, 1060,
1064, 1068, 1072, 1079, 1083, 1087, 1094, 1098, 1102, 1123,
1132, 1138, 1141, 1147, 1153, 1160, 1169, 1178, 1186, 1189,
1196, 1200, 1207, 1210, 1214, 1218, 1227, 1236, 1244, 1254,
1266, 1269, 1272, 1278, 1285, 1288, 1294, 1297, 1300, 1306,
1309, 1324, 1328, 1332, 1336, 1340, 1344, 1349, 1354, 1359,
1364, 1369, 1374, 1379, 1384, 1389, 1394, 1399, 1404, 1409,
1414, 1419, 1424, 1429, 1434, 1439, 1444, 1449, 1453, 1457,
1461, 1465, 1469, 1473, 1477, 1481, 1485, 1489, 1493, 1497,
1501, 1505, 1509, 1517, 1525, 1529, 1542, 1542, 1545, 1545,
1551, 1554, 1570, 1573, 1582, 1586, 1592, 1599, 1614, 1618,
1622, 1623, 1629, 1630, 1631, 1632, 1633, 1637, 1638, 1638,
1638, 1648, 1649, 1653, 1653, 1654, 1654, 1659, 1662, 1672,
1675, 1681, 1682, 1686, 1694, 1698, 1708, 1713, 1730, 1730,
1735, 1735, 1742, 1742, 1750, 1753, 1759, 1762, 1768, 1772,
1779, 1786, 1793, 1800, 1811, 1820, 1824, 1831, 1834, 1840,
1840
0, 206, 206, 207, 210, 234, 237, 242, 247, 252,
257, 263, 266, 269, 272, 275, 285, 298, 306, 406,
409, 417, 420, 426, 430, 437, 443, 452, 460, 463,
473, 476, 486, 496, 517, 518, 519, 524, 525, 533,
544, 545, 553, 564, 568, 569, 579, 589, 599, 612,
613, 623, 636, 640, 644, 648, 649, 662, 663, 676,
677, 690, 691, 708, 709, 722, 723, 724, 725, 726,
730, 733, 744, 752, 760, 787, 792, 803, 807, 811,
815, 822, 878, 881, 888, 896, 917, 938, 948, 976,
981, 991, 996, 1006, 1009, 1012, 1015, 1021, 1028, 1031,
1035, 1039, 1043, 1050, 1054, 1058, 1065, 1069, 1073, 1094,
1103, 1109, 1112, 1118, 1124, 1131, 1140, 1149, 1157, 1160,
1167, 1171, 1178, 1181, 1185, 1189, 1198, 1207, 1215, 1225,
1237, 1240, 1243, 1249, 1256, 1259, 1265, 1268, 1271, 1277,
1280, 1295, 1299, 1303, 1307, 1311, 1315, 1320, 1325, 1330,
1335, 1340, 1345, 1350, 1355, 1360, 1365, 1370, 1375, 1380,
1385, 1390, 1395, 1400, 1405, 1410, 1415, 1420, 1424, 1428,
1432, 1436, 1440, 1444, 1448, 1452, 1456, 1460, 1464, 1468,
1472, 1476, 1480, 1488, 1496, 1500, 1513, 1513, 1516, 1516,
1522, 1525, 1541, 1544, 1553, 1557, 1563, 1570, 1585, 1589,
1593, 1594, 1600, 1601, 1602, 1603, 1604, 1608, 1609, 1609,
1609, 1619, 1620, 1624, 1624, 1625, 1625, 1630, 1633, 1643,
1646, 1652, 1653, 1657, 1665, 1669, 1679, 1684, 1701, 1701,
1706, 1706, 1713, 1713, 1721, 1724, 1730, 1733, 1739, 1743,
1750, 1757, 1764, 1771, 1782, 1791, 1795, 1802, 1805, 1811,
1811
};
#endif
......@@ -2547,38 +2547,7 @@ yyreduce:
{
// The symbol table search was done in the lexical phase
const TSymbol *symbol = (yyvsp[(1) - (1)].lex).symbol;
const TVariable *variable = 0;
if (!symbol)
{
context->error((yylsp[(1) - (1)]), "undeclared identifier", (yyvsp[(1) - (1)].lex).string->c_str());
context->recover();
}
else if (!symbol->isVariable())
{
context->error((yylsp[(1) - (1)]), "variable expected", (yyvsp[(1) - (1)].lex).string->c_str());
context->recover();
}
else
{
variable = static_cast<const TVariable*>(symbol);
if (context->symbolTable.findBuiltIn(variable->getName(), context->shaderVersion) &&
!variable->getExtension().empty() &&
context->extensionErrorCheck((yylsp[(1) - (1)]), variable->getExtension()))
{
context->recover();
}
}
if (!variable)
{
TType type(EbtFloat, EbpUndefined);
TVariable *fakeVariable = new TVariable((yyvsp[(1) - (1)].lex).string, type);
context->symbolTable.declare(fakeVariable);
variable = fakeVariable;
}
const TVariable *variable = context->getNamedVariable((yylsp[(1) - (1)]), (yyvsp[(1) - (1)].lex).string, (yyvsp[(1) - (1)].lex).symbol);
if (variable->getType().getQualifier() == EvqConst)
{
......
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