blob: 44f8c7ed5ad62cef1ad2f3c297f8bbf6b333a650 [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 {
ethannicholas471e8942016-10-28 09:02:46 -070020 FunctionCall(Position position, const Type& type, const FunctionDeclaration& function,
ethannicholasb3058bd2016-07-01 08:22:01 -070021 std::vector<std::unique_ptr<Expression>> arguments)
ethannicholas471e8942016-10-28 09:02:46 -070022 : INHERITED(position, 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 Nicholas0df1b042017-03-31 13:56:23 -040035 String description() const override {
36 String result = fFunction.fName + "(";
37 String separator;
ethannicholasb3058bd2016-07-01 08:22:01 -070038 for (size_t i = 0; i < fArguments.size(); i++) {
39 result += separator;
40 result += fArguments[i]->description();
41 separator = ", ";
42 }
43 result += ")";
44 return result;
45 }
46
ethannicholasd598f792016-07-25 10:08:54 -070047 const FunctionDeclaration& fFunction;
Ethan Nicholas86a43402017-01-19 13:32:00 -050048 std::vector<std::unique_ptr<Expression>> fArguments;
ethannicholasb3058bd2016-07-01 08:22:01 -070049
50 typedef Expression INHERITED;
51};
52
53} // namespace
54
55#endif