Only include one variable per declaration statement

This removes VarDeclarationsStatement entirely. VarDeclaration instances
appear directly as statements in Programs. SkSL that declares multiple
variables in a single declaration is transformed to represent that as a
series of VarDeclaration statements.

Similarly, global variable declarations are represented by
GlobalVarDeclaration program elements, one per variable.

Bug: skia:10806
Change-Id: Idd8a2d971a8217733ed57f0dd2249d62f2f0e9c5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/323102
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/SkSLInliner.cpp b/src/sksl/SkSLInliner.cpp
index 26e6e98..5b3fb4e 100644
--- a/src/sksl/SkSLInliner.cpp
+++ b/src/sksl/SkSLInliner.cpp
@@ -49,7 +49,6 @@
 #include "src/sksl/ir/SkSLTernaryExpression.h"
 #include "src/sksl/ir/SkSLUnresolvedFunction.h"
 #include "src/sksl/ir/SkSLVarDeclarations.h"
-#include "src/sksl/ir/SkSLVarDeclarationsStatement.h"
 #include "src/sksl/ir/SkSLVariable.h"
 #include "src/sksl/ir/SkSLVariableReference.h"
 #include "src/sksl/ir/SkSLWhileStatement.h"
@@ -547,6 +546,7 @@
             auto name = std::make_unique<String>(
                     this->uniqueNameForInlineVar(String(old->name()), symbolTableForStatement));
             const String* namePtr = symbolTableForStatement->takeOwnershipOfString(std::move(name));
+            const Type* baseTypePtr = copy_if_needed(&decl.fBaseType, *symbolTableForStatement);
             const Type* typePtr = copy_if_needed(&old->type(), *symbolTableForStatement);
             const Variable* clone = symbolTableForStatement->takeOwnershipOfSymbol(
                     std::make_unique<Variable>(offset,
@@ -557,20 +557,9 @@
                                                old->fStorage,
                                                initialValue.get()));
             (*varMap)[old] = std::make_unique<VariableReference>(offset, clone);
-            return std::make_unique<VarDeclaration>(clone, std::move(sizes),
+            return std::make_unique<VarDeclaration>(clone, baseTypePtr, std::move(sizes),
                                                     std::move(initialValue));
         }
-        case Statement::Kind::kVarDeclarations: {
-            const VarDeclarations& decls = *statement.as<VarDeclarationsStatement>().fDeclaration;
-            std::vector<std::unique_ptr<Statement>> vars;
-            vars.reserve(decls.fVars.size());
-            for (const auto& var : decls.fVars) {
-                vars.push_back(stmt(var));
-            }
-            const Type* typePtr = copy_if_needed(&decls.fBaseType, *symbolTableForStatement);
-            return std::unique_ptr<Statement>(new VarDeclarationsStatement(
-                    std::make_unique<VarDeclarations>(offset, typePtr, std::move(vars))));
-        }
         case Statement::Kind::kWhile: {
             const WhileStatement& w = statement.as<WhileStatement>();
             return std::make_unique<WhileStatement>(offset, expr(w.fTest), stmt(w.fStatement));
@@ -646,20 +635,19 @@
 
         // Prepare the variable declaration (taking extra care with `out` params to not clobber any
         // initial value).
-        std::vector<std::unique_ptr<Statement>> variables;
+        std::unique_ptr<Statement> variable;
         if (initialValue && (modifiers.fFlags & Modifiers::kOut_Flag)) {
-            variables.push_back(std::make_unique<VarDeclaration>(
-                    variableSymbol, /*sizes=*/std::vector<std::unique_ptr<Expression>>{},
-                    (*initialValue)->clone()));
+            variable = std::make_unique<VarDeclaration>(
+                    variableSymbol, type, /*sizes=*/std::vector<std::unique_ptr<Expression>>{},
+                    (*initialValue)->clone());
         } else {
-            variables.push_back(std::make_unique<VarDeclaration>(
-                    variableSymbol, /*sizes=*/std::vector<std::unique_ptr<Expression>>{},
-                    std::move(*initialValue)));
+            variable = std::make_unique<VarDeclaration>(
+                    variableSymbol, type, /*sizes=*/std::vector<std::unique_ptr<Expression>>{},
+                    std::move(*initialValue));
         }
 
         // Add the new variable-declaration statement to our block of extra statements.
-        inlinedBody.children().push_back(std::make_unique<VarDeclarationsStatement>(
-                std::make_unique<VarDeclarations>(offset, type, std::move(variables))));
+        inlinedBody.children().push_back(std::move(variable));
 
         return std::make_unique<VariableReference>(offset, variableSymbol);
     };
@@ -943,13 +931,6 @@
                 this->visitExpression(&varDeclStmt.fValue);
                 break;
             }
-            case Statement::Kind::kVarDeclarations: {
-                VarDeclarationsStatement& varDecls = (*stmt)->as<VarDeclarationsStatement>();
-                for (std::unique_ptr<Statement>& varDecl : varDecls.fDeclaration->fVars) {
-                    this->visitStatement(&varDecl, /*isViableAsEnclosingStatement=*/false);
-                }
-                break;
-            }
             case Statement::Kind::kWhile: {
                 WhileStatement& whileStmt = (*stmt)->as<WhileStatement>();
                 // The loop body is a candidate for inlining.