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_EXTERNALFUNCTIONREFERENCE
9 #define SKSL_EXTERNALFUNCTIONREFERENCE
10 
11 #include "src/sksl/ir/SkSLExpression.h"
12 #include "src/sksl/ir/SkSLExternalFunction.h"
13 
14 namespace SkSL {
15 
16 /**
17  * Represents an identifier referring to an ExternalFunction. This is an intermediate value:
18  * ExternalFunctionReferences are always eventually replaced by ExternalFunctionCalls in valid
19  * programs.
20  */
21 class ExternalFunctionReference final : public Expression {
22 public:
23     static constexpr Kind kExpressionKind = Kind::kExternalFunctionReference;
24 
ExternalFunctionReference(int offset,const ExternalFunction * ef)25     ExternalFunctionReference(int offset, const ExternalFunction* ef)
26         : INHERITED(offset, kExpressionKind, &ef->type())
27         , fFunction(*ef) {}
28 
function()29     const ExternalFunction& function() const {
30         return fFunction;
31     }
32 
hasProperty(Property property)33     bool hasProperty(Property property) const override {
34         return property == Property::kSideEffects;
35     }
36 
description()37     String description() const override {
38         return String(this->function().name());
39     }
40 
clone()41     std::unique_ptr<Expression> clone() const override {
42         return std::make_unique<ExternalFunctionReference>(fOffset, &this->function());
43     }
44 
45 private:
46     const ExternalFunction& fFunction;
47 
48     using INHERITED = Expression;
49 };
50 
51 }  // namespace SkSL
52 
53 #endif
54