Add a helper method to parse invariant declarations.

This pulls out more functionality from the grammar into simple
c++ source files.

BUG=angle:711

Change-Id: I19121d710dc1543585361cb53a0deb2ea0479db9
Reviewed-on: https://chromium-review.googlesource.com/212938
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index 5eceb14..51a1523 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -1347,6 +1347,32 @@
     }
 }
 
+TIntermAggregate* TParseContext::parseInvariantDeclaration(const TSourceLoc &invariantLoc,
+                                                           const TSourceLoc &identifierLoc,
+                                                           const TString *identifier,
+                                                           const TSymbol *symbol)
+{
+    if (globalErrorCheck(invariantLoc, symbolTable.atGlobalLevel(), "invariant varying"))
+    {
+        recover();
+    }
+
+    if (!symbol)
+    {
+        error(identifierLoc, "undeclared identifier declared as invariant", identifier->c_str());
+        recover();
+
+        return NULL;
+    }
+    else
+    {
+        TType type(EbtInvariant);
+        type.setQualifier(EvqInvariantVaryingOut);
+        TIntermSymbol *symbol = intermediate.addSymbol(0, *identifier, type, identifierLoc);
+        return intermediate.makeAggregate(symbol, identifierLoc);
+    }
+}
+
 TIntermAggregate* TParseContext::parseDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration, TSymbol *identifierSymbol, const TSourceLoc& identifierLocation, const TString &identifier)
 {
     if (publicType.type == EbtInvariant && !identifierSymbol)
diff --git a/src/compiler/translator/ParseContext.h b/src/compiler/translator/ParseContext.h
index 3da9420..1f4cbde 100644
--- a/src/compiler/translator/ParseContext.h
+++ b/src/compiler/translator/ParseContext.h
@@ -129,6 +129,8 @@
     TIntermAggregate* parseSingleDeclaration(TPublicType &publicType, const TSourceLoc& identifierLocation, const TString &identifier);
     TIntermAggregate* parseSingleArrayDeclaration(TPublicType &publicType, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& indexLocation, TIntermTyped *indexExpression);
     TIntermAggregate* parseSingleInitDeclaration(TPublicType &publicType, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& initLocation, TIntermTyped *initializer);
+    TIntermAggregate* parseInvariantDeclaration(const TSourceLoc &invariantLoc, const TSourceLoc &identifierLoc, const TString *identifier, const TSymbol *symbol);
+
     TIntermAggregate* parseDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration, TSymbol *identifierSymbol, const TSourceLoc& identifierLocation, const TString &identifier);
     TIntermAggregate* parseArrayDeclarator(TPublicType &publicType, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& arrayLocation, TIntermNode *declaratorList, TIntermTyped *indexExpression);
     TIntermAggregate* parseInitDeclarator(TPublicType &publicType, TIntermAggregate *declaratorList, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& initLocation, TIntermTyped *initializer);
diff --git a/src/compiler/translator/glslang.y b/src/compiler/translator/glslang.y
index 7a6b6a6..831b54c 100644
--- a/src/compiler/translator/glslang.y
+++ b/src/compiler/translator/glslang.y
@@ -1072,21 +1072,8 @@
     }
     | INVARIANT IDENTIFIER {
         VERTEX_ONLY("invariant declaration", @1);
-        if (context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "invariant varying"))
-            context->recover();
         $$.type.setBasic(EbtInvariant, EvqInvariantVaryingOut, @2);
-        if (!$2.symbol)
-        {
-            context->error(@2, "undeclared identifier declared as invariant", $2.string->c_str());
-            context->recover();
-            
-            $$.intermAggregate = 0;
-        }
-        else
-        {
-            TIntermSymbol *symbol = context->intermediate.addSymbol(0, *$2.string, TType($$.type), @2);
-            $$.intermAggregate = context->intermediate.makeAggregate(symbol, @2);
-        }
+        $$.intermAggregate = context->parseInvariantDeclaration(@1, @2, $2.string, $2.symbol);
     }
     ;
 
diff --git a/src/compiler/translator/glslang_tab.cpp b/src/compiler/translator/glslang_tab.cpp
index ccf7984..49c267b 100644
--- a/src/compiler/translator/glslang_tab.cpp
+++ b/src/compiler/translator/glslang_tab.cpp
@@ -805,22 +805,22 @@
      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
+    1035,  1039,  1043,  1050,  1054,  1058,  1065,  1069,  1073,  1081,
+    1090,  1096,  1099,  1105,  1111,  1118,  1127,  1136,  1144,  1147,
+    1154,  1158,  1165,  1168,  1172,  1176,  1185,  1194,  1202,  1212,
+    1224,  1227,  1230,  1236,  1243,  1246,  1252,  1255,  1258,  1264,
+    1267,  1282,  1286,  1290,  1294,  1298,  1302,  1307,  1312,  1317,
+    1322,  1327,  1332,  1337,  1342,  1347,  1352,  1357,  1362,  1367,
+    1372,  1377,  1382,  1387,  1392,  1397,  1402,  1407,  1411,  1415,
+    1419,  1423,  1427,  1431,  1435,  1439,  1443,  1447,  1451,  1455,
+    1459,  1463,  1467,  1475,  1483,  1487,  1500,  1500,  1503,  1503,
+    1509,  1512,  1528,  1531,  1540,  1544,  1550,  1557,  1572,  1576,
+    1580,  1581,  1587,  1588,  1589,  1590,  1591,  1595,  1596,  1596,
+    1596,  1606,  1607,  1611,  1611,  1612,  1612,  1617,  1620,  1630,
+    1633,  1639,  1640,  1644,  1652,  1656,  1666,  1671,  1688,  1688,
+    1693,  1693,  1700,  1700,  1708,  1711,  1717,  1720,  1726,  1730,
+    1737,  1744,  1751,  1758,  1769,  1778,  1782,  1789,  1792,  1798,
+    1798
 };
 #endif
 
@@ -3689,21 +3689,8 @@
 
     {
         VERTEX_ONLY("invariant declaration", (yylsp[(1) - (2)]));
-        if (context->globalErrorCheck((yylsp[(1) - (2)]), context->symbolTable.atGlobalLevel(), "invariant varying"))
-            context->recover();
         (yyval.interm).type.setBasic(EbtInvariant, EvqInvariantVaryingOut, (yylsp[(2) - (2)]));
-        if (!(yyvsp[(2) - (2)].lex).symbol)
-        {
-            context->error((yylsp[(2) - (2)]), "undeclared identifier declared as invariant", (yyvsp[(2) - (2)].lex).string->c_str());
-            context->recover();
-            
-            (yyval.interm).intermAggregate = 0;
-        }
-        else
-        {
-            TIntermSymbol *symbol = context->intermediate.addSymbol(0, *(yyvsp[(2) - (2)].lex).string, TType((yyval.interm).type), (yylsp[(2) - (2)]));
-            (yyval.interm).intermAggregate = context->intermediate.makeAggregate(symbol, (yylsp[(2) - (2)]));
-        }
+        (yyval.interm).intermAggregate = context->parseInvariantDeclaration((yylsp[(1) - (2)]), (yylsp[(2) - (2)]), (yyvsp[(2) - (2)].lex).string, (yyvsp[(2) - (2)].lex).symbol);
     }
     break;