• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google LLC
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_EXTERNALFUNCTIONCALL
9 #define SKSL_EXTERNALFUNCTIONCALL
10 
11 #include "src/sksl/SkSLExternalValue.h"
12 #include "src/sksl/ir/SkSLExpression.h"
13 #include "src/sksl/ir/SkSLFunctionDeclaration.h"
14 
15 namespace SkSL {
16 
17 /**
18  * An external function invocation.
19  */
20 struct ExternalFunctionCall : public Expression {
ExternalFunctionCallExternalFunctionCall21     ExternalFunctionCall(int offset, const Type& type, ExternalValue* function,
22                          std::vector<std::unique_ptr<Expression>> arguments)
23     : INHERITED(offset, kExternalFunctionCall_Kind, type)
24     , fFunction(function)
25     , fArguments(std::move(arguments)) {}
26 
hasSideEffectsExternalFunctionCall27     bool hasSideEffects() const override {
28         return true;
29     }
30 
cloneExternalFunctionCall31     std::unique_ptr<Expression> clone() const override {
32         std::vector<std::unique_ptr<Expression>> cloned;
33         for (const auto& arg : fArguments) {
34             cloned.push_back(arg->clone());
35         }
36         return std::unique_ptr<Expression>(new ExternalFunctionCall(fOffset,
37                                                                     fType,
38                                                                     fFunction,
39                                                                     std::move(cloned)));
40     }
41 
descriptionExternalFunctionCall42     String description() const override {
43         String result = String(fFunction->fName) + "(";
44         String separator;
45         for (size_t i = 0; i < fArguments.size(); i++) {
46             result += separator;
47             result += fArguments[i]->description();
48             separator = ", ";
49         }
50         result += ")";
51         return result;
52     }
53 
54     ExternalValue* fFunction;
55     std::vector<std::unique_ptr<Expression>> fArguments;
56 
57     typedef Expression INHERITED;
58 };
59 
60 } // namespace
61 
62 #endif
63