blob: 92f758032be5fe8e9573bb69b2233d23489214a7 [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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
13namespace SkSL {
14
15/**
16 * Represents the construction of a compound type, such as "vec2(x, y)".
17 */
18struct Constructor : public Expression {
ethannicholasd598f792016-07-25 10:08:54 -070019 Constructor(Position position, const Type& type,
ethannicholasb3058bd2016-07-01 08:22:01 -070020 std::vector<std::unique_ptr<Expression>> arguments)
ethannicholasd598f792016-07-25 10:08:54 -070021 : INHERITED(position, kConstructor_Kind, type)
ethannicholasb3058bd2016-07-01 08:22:01 -070022 , fArguments(std::move(arguments)) {}
23
Ethan Nicholasd8df21a2016-11-17 16:13:37 -050024 SkString description() const override {
25 SkString result = fType.description() + "(";
26 SkString separator;
ethannicholasb3058bd2016-07-01 08:22:01 -070027 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