| OLD | NEW |
| 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_VARDECLARATION |
| 9 #define SKSL_VARDECLARATION | 9 #define SKSL_VARDECLARATION |
| 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 variable declaration, which may consist of multiple individual variables. F
or instance |
| 19 * 'int x, y = 1, z[4][2];' is a single VarDeclaration. This declaration would h
ave a type of 'int', | 19 * 'int x, y = 1, z[4][2];' is a single VarDeclaration. This declaration would h
ave a type of 'int', |
| 20 * names ['x', 'y', 'z'], sizes of [[], [], [4, 2]], and values of [null, 1, nul
l]. | 20 * names ['x', 'y', 'z'], sizes of [[], [], [4, 2]], and values of [null, 1, nul
l]. |
| 21 */ | 21 */ |
| 22 struct VarDeclaration : public ProgramElement { | 22 struct VarDeclaration : public ProgramElement { |
| 23 VarDeclaration(Position position, std::vector<std::shared_ptr<Variable>> var
s, | 23 VarDeclaration(Position position, std::vector<const Variable*> vars, |
| 24 std::vector<std::vector<std::unique_ptr<Expression>>> sizes, | 24 std::vector<std::vector<std::unique_ptr<Expression>>> sizes, |
| 25 std::vector<std::unique_ptr<Expression>> values) | 25 std::vector<std::unique_ptr<Expression>> values) |
| 26 : INHERITED(position, kVar_Kind) | 26 : INHERITED(position, kVar_Kind) |
| 27 , fVars(std::move(vars)) | 27 , fVars(std::move(vars)) |
| 28 , fSizes(std::move(sizes)) | 28 , fSizes(std::move(sizes)) |
| 29 , fValues(std::move(values)) {} | 29 , fValues(std::move(values)) {} |
| 30 | 30 |
| 31 std::string description() const override { | 31 std::string description() const override { |
| 32 std::string result = fVars[0]->fModifiers.description(); | 32 std::string result = fVars[0]->fModifiers.description(); |
| 33 std::shared_ptr<Type> baseType = fVars[0]->fType; | 33 const Type* baseType = &fVars[0]->fType; |
| 34 while (baseType->kind() == Type::kArray_Kind) { | 34 while (baseType->kind() == Type::kArray_Kind) { |
| 35 baseType = baseType->componentType(); | 35 baseType = &baseType->componentType(); |
| 36 } | 36 } |
| 37 result += baseType->description(); | 37 result += baseType->description(); |
| 38 std::string separator = " "; | 38 std::string separator = " "; |
| 39 for (size_t i = 0; i < fVars.size(); i++) { | 39 for (size_t i = 0; i < fVars.size(); i++) { |
| 40 result += separator; | 40 result += separator; |
| 41 separator = ", "; | 41 separator = ", "; |
| 42 result += fVars[i]->fName; | 42 result += fVars[i]->fName; |
| 43 for (size_t j = 0; j < fSizes[i].size(); j++) { | 43 for (size_t j = 0; j < fSizes[i].size(); j++) { |
| 44 if (fSizes[i][j]) { | 44 if (fSizes[i][j]) { |
| 45 result += "[" + fSizes[i][j]->description() + "]"; | 45 result += "[" + fSizes[i][j]->description() + "]"; |
| 46 } else { | 46 } else { |
| 47 result += "[]"; | 47 result += "[]"; |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 if (fValues[i]) { | 50 if (fValues[i]) { |
| 51 result += " = " + fValues[i]->description(); | 51 result += " = " + fValues[i]->description(); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 result += ";"; | 54 result += ";"; |
| 55 return result; | 55 return result; |
| 56 } | 56 } |
| 57 | 57 |
| 58 const std::vector<std::shared_ptr<Variable>> fVars; | 58 const std::vector<const Variable*> fVars; |
| 59 const std::vector<std::vector<std::unique_ptr<Expression>>> fSizes; | 59 const std::vector<std::vector<std::unique_ptr<Expression>>> fSizes; |
| 60 const std::vector<std::unique_ptr<Expression>> fValues; | 60 const std::vector<std::unique_ptr<Expression>> fValues; |
| 61 | 61 |
| 62 typedef ProgramElement INHERITED; | 62 typedef ProgramElement INHERITED; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 } // namespace | 65 } // namespace |
| 66 | 66 |
| 67 #endif | 67 #endif |
| OLD | NEW |