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
15namespace SkSL {
16
17/**
18 * An external function invocation.
19 */
20struct ExternalFunctionCall : public Expression {
21 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
27 bool hasProperty(Property property) const override {
28 if (property == Property::kSideEffects) {
29 return true;
30 }
31 for (const auto& arg : fArguments) {
32 if (arg->hasProperty(property)) {
33 return true;
34 }
35 }
36 return false;
37 }
38
39 int nodeCount() const override {
40 int result = 1;
41 for (const auto& a : fArguments) {
42 result += a->nodeCount();
43 }
44 return result;
45 }
46
47 std::unique_ptr<Expression> clone() const override {
48 std::vector<std::unique_ptr<Expression>> cloned;
49 for (const auto& arg : fArguments) {
50 cloned.push_back(arg->clone());
51 }
52 return std::unique_ptr<Expression>(new ExternalFunctionCall(fOffset,
53 fType,
54 fFunction,
55 std::move(cloned)));
56 }
57
58 String description() const override {
59 String result = String(fFunction->fName) + "(";
60 String separator;
61 for (size_t i = 0; i < fArguments.size(); i++) {
62 result += separator;
63 result += fArguments[i]->description();
64 separator = ", ";
65 }
66 result += ")";
67 return result;
68 }
69
70 ExternalValue* fFunction;
71 std::vector<std::unique_ptr<Expression>> fArguments;
72
73 typedef Expression INHERITED;
74};
75
76} // namespace SkSL
77
78#endif
79