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