Always create TVariables for TIntermSymbol nodes

TIntermSymbol nodes are now constructed based on a specific TVariable.
This makes sure that all TIntermSymbol nodes that are created to refer
to a specific temporary in an AST transform will have consistent data.
The TVariable objects are not necessarily added to the symbol table
levels - just those variables that can be referred to by their name
during parsing need to be reachable through there.

In the future this can be taken a step further so that TIntermSymbol
nodes just to point to a TVariable instead of duplicating the
information.

BUG=angleproject:2267
TEST=angle_unittests

Change-Id: I4e7bcdb0637cd3b588d3c202ef02f4b7bd7954a1
Reviewed-on: https://chromium-review.googlesource.com/811925
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/RewriteDoWhile.cpp b/src/compiler/translator/RewriteDoWhile.cpp
index dc3fb7a..80b2cee 100644
--- a/src/compiler/translator/RewriteDoWhile.cpp
+++ b/src/compiler/translator/RewriteDoWhile.cpp
@@ -9,6 +9,7 @@
 
 #include "compiler/translator/RewriteDoWhile.h"
 
+#include "compiler/translator/IntermNode_util.h"
 #include "compiler/translator/IntermTraverse.h"
 
 namespace sh
@@ -70,29 +71,16 @@
             }
 
             // Found a loop to change.
-            nextTemporaryId();
-
-            TType boolType = TType(EbtBool);
+            TType boolType(EbtBool);
+            TVariable *conditionVariable = CreateTempVariable(mSymbolTable, boolType);
 
             // bool temp = false;
-            TIntermDeclaration *tempDeclaration = nullptr;
-            {
-                TConstantUnion *falseConstant = new TConstantUnion();
-                falseConstant->setBConst(false);
-                TIntermTyped *falseValue = new TIntermConstantUnion(falseConstant, boolType);
-
-                tempDeclaration = createTempInitDeclaration(falseValue);
-            }
+            TIntermDeclaration *tempDeclaration =
+                CreateTempInitDeclarationNode(conditionVariable, CreateBoolNode(false));
 
             // temp = true;
-            TIntermBinary *assignTrue = nullptr;
-            {
-                TConstantUnion *trueConstant = new TConstantUnion();
-                trueConstant->setBConst(true);
-                TIntermTyped *trueValue = new TIntermConstantUnion(trueConstant, boolType);
-
-                assignTrue = createTempAssignment(trueValue);
-            }
+            TIntermBinary *assignTrue =
+                CreateTempAssignmentNode(conditionVariable, CreateBoolNode(true));
 
             // if (temp) {
             //   if (!CONDITION) {
@@ -114,17 +102,14 @@
                 TIntermBlock *innerIfBlock = new TIntermBlock();
                 innerIfBlock->getSequence()->push_back(innerIf);
 
-                breakIf = new TIntermIfElse(createTempSymbol(boolType), innerIfBlock, nullptr);
+                breakIf = new TIntermIfElse(CreateTempSymbolNode(conditionVariable), innerIfBlock,
+                                            nullptr);
             }
 
             // Assemble the replacement loops, reusing the do-while loop's body and inserting our
             // statements at the front.
             TIntermLoop *newLoop = nullptr;
             {
-                TConstantUnion *trueConstant = new TConstantUnion();
-                trueConstant->setBConst(true);
-                TIntermTyped *trueValue = new TIntermConstantUnion(trueConstant, boolType);
-
                 TIntermBlock *body = loop->getBody();
                 if (body == nullptr)
                 {
@@ -134,7 +119,7 @@
                 sequence->insert(sequence->begin(), assignTrue);
                 sequence->insert(sequence->begin(), breakIf);
 
-                newLoop = new TIntermLoop(ELoopWhile, nullptr, trueValue, nullptr, body);
+                newLoop = new TIntermLoop(ELoopWhile, nullptr, CreateBoolNode(true), nullptr, body);
             }
 
             TIntermSequence replacement;