Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/sksl/ir/SkSLVarDeclaration.h

Issue 2312233002: refactored SkSL VarDeclaration handling (Closed)
Patch Set: fixed nits Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/sksl/ir/SkSLStatement.h ('k') | src/sksl/ir/SkSLVarDeclarationStatement.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SKSL_VARDECLARATION 8 #ifndef SKSL_VARDECLARATIONS
9 #define SKSL_VARDECLARATION 9 #define SKSL_VARDECLARATIONS
10 10
11 #include "SkSLExpression.h" 11 #include "SkSLExpression.h"
12 #include "SkSLStatement.h" 12 #include "SkSLStatement.h"
13 #include "SkSLVariable.h" 13 #include "SkSLVariable.h"
14 14
15 namespace SkSL { 15 namespace SkSL {
16 16
17 /** 17 /**
18 * A variable declaration, which may consist of multiple individual variables. F or instance 18 * A single variable declaration within a var declaration statement. For instanc e, the statement
19 * 'int x, y = 1, z[4][2];' is a single VarDeclaration. This declaration would h ave a base type of 19 * 'int x = 2, y[3];' is a VarDeclarations statement containing two individual V arDeclaration
20 * 'int', names ['x', 'y', 'z'], sizes of [[], [], [4, 2]], and values of [null, 1, null]. 20 * instances.
21 */ 21 */
22 struct VarDeclaration : public ProgramElement { 22 struct VarDeclaration {
23 VarDeclaration(Position position, const Type* baseType, std::vector<const Va riable*> vars, 23 VarDeclaration(const Variable* var,
24 std::vector<std::vector<std::unique_ptr<Expression>>> sizes, 24 std::vector<std::unique_ptr<Expression>> sizes,
25 std::vector<std::unique_ptr<Expression>> values) 25 std::unique_ptr<Expression> value)
26 : fVar(var)
27 , fSizes(std::move(sizes))
28 , fValue(std::move(value)) {}
29
30 std::string description() const {
31 std::string result = fVar->fName;
32 for (const auto& size : fSizes) {
33 if (size) {
34 result += "[" + size->description() + "]";
35 } else {
36 result += "[]";
37 }
38 }
39 if (fValue) {
40 result += " = " + fValue->description();
41 }
42 return result;
43 }
44
45 const Variable* fVar;
46 std::vector<std::unique_ptr<Expression>> fSizes;
47 std::unique_ptr<Expression> fValue;
48 };
49
50 /**
51 * A variable declaration statement, which may consist of one or more individual variables.
52 */
53 struct VarDeclarations : public ProgramElement {
54 VarDeclarations(Position position, const Type* baseType,
55 std::vector<VarDeclaration> vars)
26 : INHERITED(position, kVar_Kind) 56 : INHERITED(position, kVar_Kind)
27 , fBaseType(*baseType) 57 , fBaseType(*baseType)
28 , fVars(std::move(vars)) 58 , fVars(std::move(vars)) {}
29 , fSizes(std::move(sizes))
30 , fValues(std::move(values)) {}
31 59
32 std::string description() const override { 60 std::string description() const override {
33 std::string result = fVars[0]->fModifiers.description(); 61 if (!fVars.size()) {
34 const Type* baseType = &fVars[0]->fType; 62 return "";
35 while (baseType->kind() == Type::kArray_Kind) {
36 baseType = &baseType->componentType();
37 } 63 }
38 result += baseType->description(); 64 std::string result = fVars[0].fVar->fModifiers.description() + fBaseType .description() +
39 std::string separator = " "; 65 " ";
40 for (size_t i = 0; i < fVars.size(); i++) { 66 std::string separator = "";
67 for (const auto& var : fVars) {
41 result += separator; 68 result += separator;
42 separator = ", "; 69 separator = ", ";
43 result += fVars[i]->fName; 70 result += var.description();
44 for (size_t j = 0; j < fSizes[i].size(); j++) {
45 if (fSizes[i][j]) {
46 result += "[" + fSizes[i][j]->description() + "]";
47 } else {
48 result += "[]";
49 }
50 }
51 if (fValues[i]) {
52 result += " = " + fValues[i]->description();
53 }
54 } 71 }
55 result += ";";
56 return result; 72 return result;
57 } 73 }
58 74
59 const Type& fBaseType; 75 const Type& fBaseType;
60 const std::vector<const Variable*> fVars; 76 const std::vector<VarDeclaration> fVars;
61 const std::vector<std::vector<std::unique_ptr<Expression>>> fSizes;
62 const std::vector<std::unique_ptr<Expression>> fValues;
63 77
64 typedef ProgramElement INHERITED; 78 typedef ProgramElement INHERITED;
65 }; 79 };
66 80
67 } // namespace 81 } // namespace
68 82
69 #endif 83 #endif
OLDNEW
« no previous file with comments | « src/sksl/ir/SkSLStatement.h ('k') | src/sksl/ir/SkSLVarDeclarationStatement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698