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_CONSTRUCTOR | 8 #ifndef SKSL_CONSTRUCTOR |
9 #define SKSL_CONSTRUCTOR | 9 #define SKSL_CONSTRUCTOR |
10 | 10 |
11 #include "SkSLExpression.h" | 11 #include "SkSLExpression.h" |
12 | 12 |
13 namespace SkSL { | 13 namespace SkSL { |
14 | 14 |
15 /** | 15 /** |
16 * Represents the construction of a compound type, such as "vec2(x, y)". | 16 * Represents the construction of a compound type, such as "vec2(x, y)". |
17 */ | 17 */ |
18 struct Constructor : public Expression { | 18 struct Constructor : public Expression { |
19 Constructor(Position position, std::shared_ptr<Type> type, | 19 Constructor(Position position, const Type& type, |
20 std::vector<std::unique_ptr<Expression>> arguments) | 20 std::vector<std::unique_ptr<Expression>> arguments) |
21 : INHERITED(position, kConstructor_Kind, std::move(type)) | 21 : INHERITED(position, kConstructor_Kind, type) |
22 , fArguments(std::move(arguments)) {} | 22 , fArguments(std::move(arguments)) {} |
23 | 23 |
24 std::string description() const override { | 24 std::string description() const override { |
25 std::string result = fType->description() + "("; | 25 std::string result = fType.description() + "("; |
26 std::string separator = ""; | 26 std::string separator = ""; |
27 for (size_t i = 0; i < fArguments.size(); i++) { | 27 for (size_t i = 0; i < fArguments.size(); i++) { |
28 result += separator; | 28 result += separator; |
29 result += fArguments[i]->description(); | 29 result += fArguments[i]->description(); |
30 separator = ", "; | 30 separator = ", "; |
31 } | 31 } |
32 result += ")"; | 32 result += ")"; |
33 return result; | 33 return result; |
34 } | 34 } |
35 | 35 |
36 bool isConstant() const override { | 36 bool isConstant() const override { |
37 for (size_t i = 0; i < fArguments.size(); i++) { | 37 for (size_t i = 0; i < fArguments.size(); i++) { |
38 if (!fArguments[i]->isConstant()) { | 38 if (!fArguments[i]->isConstant()) { |
39 return false; | 39 return false; |
40 } | 40 } |
41 } | 41 } |
42 return true; | 42 return true; |
43 } | 43 } |
44 | 44 |
45 const std::vector<std::unique_ptr<Expression>> fArguments; | 45 const std::vector<std::unique_ptr<Expression>> fArguments; |
46 | 46 |
47 typedef Expression INHERITED; | 47 typedef Expression INHERITED; |
48 }; | 48 }; |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 #endif | 52 #endif |
OLD | NEW |