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 base type of |
20 * names ['x', 'y', 'z'], sizes of [[], [], [4, 2]], and values of [null, 1, nul
l]. | 20 * 'int', names ['x', 'y', 'z'], sizes of [[], [], [4, 2]], and values of [null,
1, null]. |
21 */ | 21 */ |
22 struct VarDeclaration : public ProgramElement { | 22 struct VarDeclaration : public ProgramElement { |
23 VarDeclaration(Position position, std::vector<const Variable*> vars, | 23 VarDeclaration(Position position, const Type* baseType, std::vector<const Va
riable*> 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 , fBaseType(*baseType) |
27 , fVars(std::move(vars)) | 28 , fVars(std::move(vars)) |
28 , fSizes(std::move(sizes)) | 29 , fSizes(std::move(sizes)) |
29 , fValues(std::move(values)) {} | 30 , fValues(std::move(values)) {} |
30 | 31 |
31 std::string description() const override { | 32 std::string description() const override { |
32 std::string result = fVars[0]->fModifiers.description(); | 33 std::string result = fVars[0]->fModifiers.description(); |
33 const Type* baseType = &fVars[0]->fType; | 34 const Type* baseType = &fVars[0]->fType; |
34 while (baseType->kind() == Type::kArray_Kind) { | 35 while (baseType->kind() == Type::kArray_Kind) { |
35 baseType = &baseType->componentType(); | 36 baseType = &baseType->componentType(); |
36 } | 37 } |
(...skipping 11 matching lines...) Expand all Loading... |
48 } | 49 } |
49 } | 50 } |
50 if (fValues[i]) { | 51 if (fValues[i]) { |
51 result += " = " + fValues[i]->description(); | 52 result += " = " + fValues[i]->description(); |
52 } | 53 } |
53 } | 54 } |
54 result += ";"; | 55 result += ";"; |
55 return result; | 56 return result; |
56 } | 57 } |
57 | 58 |
| 59 const Type& fBaseType; |
58 const std::vector<const Variable*> fVars; | 60 const std::vector<const Variable*> fVars; |
59 const std::vector<std::vector<std::unique_ptr<Expression>>> fSizes; | 61 const std::vector<std::vector<std::unique_ptr<Expression>>> fSizes; |
60 const std::vector<std::unique_ptr<Expression>> fValues; | 62 const std::vector<std::unique_ptr<Expression>> fValues; |
61 | 63 |
62 typedef ProgramElement INHERITED; | 64 typedef ProgramElement INHERITED; |
63 }; | 65 }; |
64 | 66 |
65 } // namespace | 67 } // namespace |
66 | 68 |
67 #endif | 69 #endif |
OLD | NEW |