ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SKSL_CONSTRUCTOR |
| 9 | #define SKSL_CONSTRUCTOR |
| 10 | |
| 11 | #include "SkSLExpression.h" |
| 12 | |
| 13 | namespace SkSL { |
| 14 | |
| 15 | /** |
| 16 | * Represents the construction of a compound type, such as "vec2(x, y)". |
| 17 | */ |
| 18 | struct Constructor : public Expression { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 19 | Constructor(Position position, const Type& type, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 20 | std::vector<std::unique_ptr<Expression>> arguments) |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 21 | : INHERITED(position, kConstructor_Kind, type) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 22 | , fArguments(std::move(arguments)) {} |
| 23 | |
| 24 | std::string description() const override { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 25 | std::string result = fType.description() + "("; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 26 | std::string separator = ""; |
| 27 | for (size_t i = 0; i < fArguments.size(); i++) { |
| 28 | result += separator; |
| 29 | result += fArguments[i]->description(); |
| 30 | separator = ", "; |
| 31 | } |
| 32 | result += ")"; |
| 33 | return result; |
| 34 | } |
| 35 | |
| 36 | bool isConstant() const override { |
| 37 | for (size_t i = 0; i < fArguments.size(); i++) { |
| 38 | if (!fArguments[i]->isConstant()) { |
| 39 | return false; |
| 40 | } |
| 41 | } |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | const std::vector<std::unique_ptr<Expression>> fArguments; |
| 46 | |
| 47 | typedef Expression INHERITED; |
| 48 | }; |
| 49 | |
| 50 | } // namespace |
| 51 | |
| 52 | #endif |