• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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 {
FunctionCallFunctionCall20     FunctionCall(int offset, const Type& type, const FunctionDeclaration& function,
21                  std::vector<std::unique_ptr<Expression>> arguments)
22     : INHERITED(offset, kFunctionCall_Kind, type)
23     , fFunction(std::move(function))
24     , fArguments(std::move(arguments)) {}
25 
hasSideEffectsFunctionCall26     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 
cloneFunctionCall35     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 
descriptionFunctionCall44     String description() const override {
45         String result = String(fFunction.fName) + "(";
46         String separator;
47         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 
56     const FunctionDeclaration& fFunction;
57     std::vector<std::unique_ptr<Expression>> fArguments;
58 
59     typedef Expression INHERITED;
60 };
61 
62 } // namespace
63 
64 #endif
65