• 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 "include/private/SkTArray.h"
12 #include "src/sksl/ir/SkSLExpression.h"
13 #include "src/sksl/ir/SkSLExternalFunction.h"
14 #include "src/sksl/ir/SkSLFunctionDeclaration.h"
15 
16 namespace SkSL {
17 
18 /**
19  * An external function invocation.
20  */
21 class ExternalFunctionCall final : public Expression {
22 public:
23     inline static constexpr Kind kExpressionKind = Kind::kExternalFunctionCall;
24 
ExternalFunctionCall(int line,const ExternalFunction * function,ExpressionArray arguments)25     ExternalFunctionCall(int line, const ExternalFunction* function, ExpressionArray arguments)
26         : INHERITED(line, kExpressionKind, &function->type())
27         , fFunction(*function)
28         , fArguments(std::move(arguments)) {}
29 
arguments()30     ExpressionArray& arguments() {
31         return fArguments;
32     }
33 
arguments()34     const ExpressionArray& arguments() const {
35         return fArguments;
36     }
37 
function()38     const ExternalFunction& function() const {
39         return fFunction;
40     }
41 
hasProperty(Property property)42     bool hasProperty(Property property) const override {
43         if (property == Property::kSideEffects) {
44             return true;
45         }
46         for (const auto& arg : this->arguments()) {
47             if (arg->hasProperty(property)) {
48                 return true;
49             }
50         }
51         return false;
52     }
53 
clone()54     std::unique_ptr<Expression> clone() const override {
55         return std::make_unique<ExternalFunctionCall>(fLine, &this->function(),
56                                                       this->arguments().clone());
57     }
58 
description()59     std::string description() const override {
60         std::string result = std::string(this->function().name()) + "(";
61         std::string separator;
62         for (const std::unique_ptr<Expression>& arg : this->arguments()) {
63             result += separator;
64             result += arg->description();
65             separator = ", ";
66         }
67         result += ")";
68         return result;
69     }
70 
71 private:
72     const ExternalFunction& fFunction;
73     ExpressionArray fArguments;
74 
75     using INHERITED = Expression;
76 };
77 
78 }  // namespace SkSL
79 
80 #endif
81