Ethan Nicholas | 91164d1 | 2019-05-15 15:29:54 -0400 | [diff] [blame] | 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_EXTERNALVALUEREFERENCE |
| 9 | #define SKSL_EXTERNALVALUEREFERENCE |
| 10 | |
Ethan Nicholas | 91164d1 | 2019-05-15 15:29:54 -0400 | [diff] [blame] | 11 | #include "src/sksl/SkSLExternalValue.h" |
Mike Klein | fe0aeb3 | 2019-05-20 10:55:11 -0500 | [diff] [blame] | 12 | #include "src/sksl/ir/SkSLExpression.h" |
Ethan Nicholas | 91164d1 | 2019-05-15 15:29:54 -0400 | [diff] [blame] | 13 | |
| 14 | namespace SkSL { |
| 15 | |
| 16 | /** |
| 17 | * Represents an identifier referring to an ExternalValue. |
| 18 | */ |
| 19 | struct ExternalValueReference : public Expression { |
| 20 | ExternalValueReference(int offset, ExternalValue* ev) |
| 21 | : INHERITED(offset, kExternalValue_Kind, ev->type()) |
| 22 | , fValue(ev) {} |
| 23 | |
Ethan Nicholas | 2a099da | 2020-01-02 14:40:54 -0500 | [diff] [blame] | 24 | bool hasProperty(Property property) const override { |
| 25 | return property == Property::kSideEffects; |
Ethan Nicholas | 91164d1 | 2019-05-15 15:29:54 -0400 | [diff] [blame] | 26 | } |
| 27 | |
Ethan Nicholas | 2dd272b | 2020-05-27 12:21:42 -0400 | [diff] [blame^] | 28 | int nodeCount() const override { |
| 29 | return 1; |
| 30 | } |
| 31 | |
Ethan Nicholas | 91164d1 | 2019-05-15 15:29:54 -0400 | [diff] [blame] | 32 | String description() const override { |
| 33 | return String(fValue->fName); |
| 34 | } |
Ethan Nicholas | 91164d1 | 2019-05-15 15:29:54 -0400 | [diff] [blame] | 35 | |
| 36 | std::unique_ptr<Expression> clone() const override { |
| 37 | return std::unique_ptr<Expression>(new ExternalValueReference(fOffset, fValue)); |
| 38 | } |
| 39 | |
| 40 | ExternalValue* fValue; |
| 41 | |
| 42 | typedef Expression INHERITED; |
| 43 | }; |
| 44 | |
| 45 | } // namespace |
| 46 | |
| 47 | #endif |