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 | */ |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 7 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 8 | #ifndef SKSL_FUNCTIONCALL |
| 9 | #define SKSL_FUNCTIONCALL |
| 10 | |
| 11 | #include "SkSLExpression.h" |
| 12 | #include "SkSLFunctionDeclaration.h" |
| 13 | |
| 14 | namespace SkSL { |
| 15 | |
| 16 | /** |
| 17 | * A function invocation. |
| 18 | */ |
| 19 | struct FunctionCall : public Expression { |
ethannicholas | 471e894 | 2016-10-28 09:02:46 -0700 | [diff] [blame] | 20 | FunctionCall(Position position, const Type& type, const FunctionDeclaration& function, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 21 | std::vector<std::unique_ptr<Expression>> arguments) |
ethannicholas | 471e894 | 2016-10-28 09:02:46 -0700 | [diff] [blame] | 22 | : INHERITED(position, kFunctionCall_Kind, type) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 23 | , fFunction(std::move(function)) |
| 24 | , fArguments(std::move(arguments)) {} |
| 25 | |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 26 | 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 Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 35 | String description() const override { |
| 36 | String result = fFunction.fName + "("; |
| 37 | String separator; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 38 | 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 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 47 | const FunctionDeclaration& fFunction; |
Ethan Nicholas | 86a4340 | 2017-01-19 13:32:00 -0500 | [diff] [blame] | 48 | std::vector<std::unique_ptr<Expression>> fArguments; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 49 | |
| 50 | typedef Expression INHERITED; |
| 51 | }; |
| 52 | |
| 53 | } // namespace |
| 54 | |
| 55 | #endif |