blob: 7047c37067513da1269b57cee1b514a3c665ec69 [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 */
Ethan Nicholas0df1b042017-03-31 13:56:23 -04007
ethannicholasb3058bd2016-07-01 08:22:01 -07008#ifndef SKSL_FUNCTIONCALL
9#define SKSL_FUNCTIONCALL
10
11#include "SkSLExpression.h"
12#include "SkSLFunctionDeclaration.h"
13
14namespace SkSL {
15
16/**
17 * A function invocation.
18 */
19struct FunctionCall : public Expression {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070020 FunctionCall(int offset, const Type& type, const FunctionDeclaration& function,
ethannicholasb3058bd2016-07-01 08:22:01 -070021 std::vector<std::unique_ptr<Expression>> arguments)
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070022 : INHERITED(offset, kFunctionCall_Kind, type)
ethannicholasb3058bd2016-07-01 08:22:01 -070023 , fFunction(std::move(function))
24 , fArguments(std::move(arguments)) {}
25
Ethan Nicholascb670962017-04-20 19:31:52 -040026 bool hasSideEffects() const override {
27 for (const auto& arg : fArguments) {
28 if (arg->hasSideEffects()) {
29 return true;
30 }
31 }
32 return fFunction.fModifiers.fFlags & Modifiers::kHasSideEffects_Flag;
33 }
34
Ethan Nicholas97ae0c82018-07-12 14:02:00 -040035 std::unique_ptr<Expression> clone() const override {
36 std::vector<std::unique_ptr<Expression>> cloned;
37 for (const auto& arg : fArguments) {
38 cloned.push_back(arg->clone());
39 }
40 return std::unique_ptr<Expression>(new FunctionCall(fOffset, fType, fFunction,
41 std::move(cloned)));
42 }
43
Ethan Nicholas0df1b042017-03-31 13:56:23 -040044 String description() const override {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070045 String result = String(fFunction.fName) + "(";
Ethan Nicholas0df1b042017-03-31 13:56:23 -040046 String separator;
ethannicholasb3058bd2016-07-01 08:22:01 -070047 for (size_t i = 0; i < fArguments.size(); i++) {
48 result += separator;
49 result += fArguments[i]->description();
50 separator = ", ";
51 }
52 result += ")";
53 return result;
54 }
55
ethannicholasd598f792016-07-25 10:08:54 -070056 const FunctionDeclaration& fFunction;
Ethan Nicholas86a43402017-01-19 13:32:00 -050057 std::vector<std::unique_ptr<Expression>> fArguments;
ethannicholasb3058bd2016-07-01 08:22:01 -070058
59 typedef Expression INHERITED;
60};
61
62} // namespace
63
64#endif