Commit 82c29ed2 by Olli Etuaho

Move variable identifier parsing to ParseContext

This change is purely refactoring existing functionality to make it easier to change variable identifier parsing. BUG=angleproject:911 BUG=541551 Change-Id: I282fbb66d40cd71fa0f4804e4a8e893744cd6bfc Reviewed-on: https://chromium-review.googlesource.com/309724Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 08fc7732
...@@ -1182,6 +1182,25 @@ const TVariable *TParseContext::getNamedVariable(const TSourceLoc &location, ...@@ -1182,6 +1182,25 @@ const TVariable *TParseContext::getNamedVariable(const TSourceLoc &location,
return variable; return variable;
} }
TIntermTyped *TParseContext::parseVariableIdentifier(const TSourceLoc &location,
const TString *name,
const TSymbol *symbol)
{
const TVariable *variable = getNamedVariable(location, name, symbol);
if (variable->getType().getQualifier() == EvqConst)
{
TConstantUnion *constArray = variable->getConstPointer();
TType t(variable->getType());
return intermediate.addConstantUnion(constArray, t, location);
}
else
{
return intermediate.addSymbol(variable->getUniqueId(), variable->getName(),
variable->getType(), location);
}
}
// //
// Look up a function name in the symbol table, and make sure it is a function. // Look up a function name in the symbol table, and make sure it is a function.
// //
......
...@@ -115,6 +115,9 @@ class TParseContext : angle::NonCopyable ...@@ -115,6 +115,9 @@ class TParseContext : angle::NonCopyable
// This method is guaranteed to succeed, even if no variable with 'name' exists. // 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); const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol);
TIntermTyped *parseVariableIdentifier(const TSourceLoc &location,
const TString *name,
const TSymbol *symbol);
bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc &line); bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc &line);
......
...@@ -215,21 +215,7 @@ identifier ...@@ -215,21 +215,7 @@ identifier
variable_identifier variable_identifier
: IDENTIFIER { : IDENTIFIER {
// The symbol table search was done in the lexical phase // The symbol table search was done in the lexical phase
const TVariable *variable = context->getNamedVariable(@1, $1.string, $1.symbol); $$ = context->parseVariableIdentifier(@1, $1.string, $1.symbol);
if (variable->getType().getQualifier() == EvqConst)
{
TConstantUnion* constArray = variable->getConstPointer();
TType t(variable->getType());
$$ = context->intermediate.addConstantUnion(constArray, t, @1);
}
else
{
$$ = context->intermediate.addSymbol(variable->getUniqueId(),
variable->getName(),
variable->getType(),
@1);
}
// don't delete $1.string, it's used by error recovery, and the pool // don't delete $1.string, it's used by error recovery, and the pool
// pop will reclaim the memory // pop will reclaim the memory
......
...@@ -694,34 +694,34 @@ static const yytype_uint8 yytranslate[] = ...@@ -694,34 +694,34 @@ static const yytype_uint8 yytranslate[] =
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] = static const yytype_uint16 yyrline[] =
{ {
0, 212, 212, 213, 216, 240, 243, 248, 253, 258, 0, 212, 212, 213, 216, 226, 229, 234, 239, 244,
263, 269, 272, 275, 278, 281, 284, 290, 298, 309, 249, 255, 258, 261, 264, 267, 270, 276, 284, 295,
313, 321, 324, 330, 334, 341, 347, 356, 364, 370, 299, 307, 310, 316, 320, 327, 333, 342, 350, 356,
377, 387, 390, 393, 396, 406, 407, 408, 409, 417, 363, 373, 376, 379, 382, 392, 393, 394, 395, 403,
418, 421, 424, 431, 432, 435, 441, 442, 446, 453, 404, 407, 410, 417, 418, 421, 427, 428, 432, 439,
454, 457, 460, 463, 469, 470, 473, 479, 480, 487, 440, 443, 446, 449, 455, 456, 459, 465, 466, 473,
488, 495, 496, 503, 504, 510, 511, 517, 518, 524, 474, 481, 482, 489, 490, 496, 497, 503, 504, 510,
525, 531, 532, 540, 541, 542, 543, 547, 548, 549, 511, 517, 518, 526, 527, 528, 529, 533, 534, 535,
553, 557, 561, 565, 572, 575, 586, 594, 602, 630, 539, 543, 547, 551, 558, 561, 572, 580, 588, 616,
636, 647, 651, 655, 659, 666, 672, 675, 682, 690, 622, 633, 637, 641, 645, 652, 658, 661, 668, 676,
711, 738, 748, 776, 781, 791, 796, 806, 809, 812, 697, 724, 734, 762, 767, 777, 782, 792, 795, 798,
815, 821, 828, 831, 835, 839, 844, 849, 856, 860, 801, 807, 814, 817, 821, 825, 830, 835, 842, 846,
864, 868, 873, 878, 882, 889, 899, 905, 908, 914, 850, 854, 859, 864, 868, 875, 885, 891, 894, 900,
920, 927, 936, 946, 954, 957, 964, 968, 972, 977, 906, 913, 922, 932, 940, 943, 950, 954, 958, 963,
985, 988, 992, 996, 1005, 1014, 1022, 1032, 1044, 1047, 971, 974, 978, 982, 991, 1000, 1008, 1018, 1030, 1033,
1050, 1056, 1063, 1066, 1072, 1075, 1078, 1084, 1087, 1092, 1036, 1042, 1049, 1052, 1058, 1061, 1064, 1070, 1073, 1078,
1107, 1111, 1115, 1119, 1123, 1127, 1132, 1137, 1142, 1147, 1093, 1097, 1101, 1105, 1109, 1113, 1118, 1123, 1128, 1133,
1152, 1157, 1162, 1167, 1172, 1177, 1182, 1187, 1192, 1197, 1138, 1143, 1148, 1153, 1158, 1163, 1168, 1173, 1178, 1183,
1202, 1207, 1212, 1217, 1222, 1227, 1232, 1236, 1240, 1244, 1188, 1193, 1198, 1203, 1208, 1213, 1218, 1222, 1226, 1230,
1248, 1252, 1256, 1260, 1264, 1268, 1272, 1276, 1280, 1284, 1234, 1238, 1242, 1246, 1250, 1254, 1258, 1262, 1266, 1270,
1288, 1292, 1300, 1308, 1312, 1325, 1325, 1328, 1328, 1334, 1274, 1278, 1286, 1294, 1298, 1311, 1311, 1314, 1314, 1320,
1337, 1353, 1356, 1365, 1369, 1375, 1382, 1397, 1401, 1405, 1323, 1339, 1342, 1351, 1355, 1361, 1368, 1383, 1387, 1391,
1406, 1412, 1413, 1414, 1415, 1416, 1417, 1418, 1422, 1423, 1392, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1408, 1409,
1423, 1423, 1433, 1434, 1438, 1438, 1439, 1439, 1444, 1447, 1409, 1409, 1419, 1420, 1424, 1424, 1425, 1425, 1430, 1433,
1457, 1460, 1466, 1467, 1471, 1479, 1483, 1490, 1490, 1497, 1443, 1446, 1452, 1453, 1457, 1465, 1469, 1476, 1476, 1483,
1500, 1507, 1512, 1527, 1527, 1532, 1532, 1539, 1539, 1547, 1486, 1493, 1498, 1513, 1513, 1518, 1518, 1525, 1525, 1533,
1550, 1556, 1559, 1565, 1569, 1576, 1579, 1582, 1585, 1588, 1536, 1542, 1545, 1551, 1555, 1562, 1565, 1568, 1571, 1574,
1597, 1601, 1608, 1611, 1617, 1617 1583, 1587, 1594, 1597, 1603, 1603
}; };
#endif #endif
...@@ -2356,21 +2356,7 @@ yyreduce: ...@@ -2356,21 +2356,7 @@ yyreduce:
{ {
// The symbol table search was done in the lexical phase // The symbol table search was done in the lexical phase
const TVariable *variable = context->getNamedVariable((yylsp[0]), (yyvsp[0].lex).string, (yyvsp[0].lex).symbol); (yyval.interm.intermTypedNode) = context->parseVariableIdentifier((yylsp[0]), (yyvsp[0].lex).string, (yyvsp[0].lex).symbol);
if (variable->getType().getQualifier() == EvqConst)
{
TConstantUnion* constArray = variable->getConstPointer();
TType t(variable->getType());
(yyval.interm.intermTypedNode) = context->intermediate.addConstantUnion(constArray, t, (yylsp[0]));
}
else
{
(yyval.interm.intermTypedNode) = context->intermediate.addSymbol(variable->getUniqueId(),
variable->getName(),
variable->getType(),
(yylsp[0]));
}
// don't delete $1.string, it's used by error recovery, and the pool // don't delete $1.string, it's used by error recovery, and the pool
// pop will reclaim the memory // pop will reclaim the memory
......
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