/src/skia/src/sksl/ir/SkSLVariable.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2016 Google Inc. |
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_VARIABLE |
9 | | #define SKSL_VARIABLE |
10 | | |
11 | | #include "include/private/SkSLModifiers.h" |
12 | | #include "include/private/SkSLSymbol.h" |
13 | | #include "src/sksl/SkSLPosition.h" |
14 | | #include "src/sksl/ir/SkSLExpression.h" |
15 | | #include "src/sksl/ir/SkSLType.h" |
16 | | #include "src/sksl/ir/SkSLVariableReference.h" |
17 | | |
18 | | namespace SkSL { |
19 | | |
20 | | class Expression; |
21 | | class VarDeclaration; |
22 | | |
23 | | namespace dsl { |
24 | | class DSLCore; |
25 | | class DSLFunction; |
26 | | } // namespace dsl |
27 | | |
28 | | enum class VariableStorage : int8_t { |
29 | | kGlobal, |
30 | | kInterfaceBlock, |
31 | | kLocal, |
32 | | kParameter |
33 | | }; |
34 | | |
35 | | /** |
36 | | * Represents a variable, whether local, global, or a function parameter. This represents the |
37 | | * variable itself (the storage location), which is shared between all VariableReferences which |
38 | | * read or write that storage location. |
39 | | */ |
40 | | class Variable final : public Symbol { |
41 | | public: |
42 | | using Storage = VariableStorage; |
43 | | |
44 | | static constexpr Kind kSymbolKind = Kind::kVariable; |
45 | | |
46 | | Variable(int offset, const Modifiers* modifiers, skstd::string_view name, const Type* type, |
47 | | bool builtin, Storage storage) |
48 | | : INHERITED(offset, kSymbolKind, name, type) |
49 | | , fModifiers(modifiers) |
50 | | , fStorage(storage) |
51 | 21.6M | , fBuiltin(builtin) {} |
52 | | |
53 | | ~Variable() override; |
54 | | |
55 | 23.2M | const Modifiers& modifiers() const { |
56 | 23.2M | return *fModifiers; |
57 | 23.2M | } |
58 | | |
59 | 2.56k | void setModifiers(const Modifiers* modifiers) { |
60 | 2.56k | fModifiers = modifiers; |
61 | 2.56k | } |
62 | | |
63 | 367k | bool isBuiltin() const { |
64 | 367k | return fBuiltin; |
65 | 367k | } |
66 | | |
67 | 2.62M | Storage storage() const { |
68 | 2.62M | return (Storage) fStorage; |
69 | 2.62M | } |
70 | | |
71 | | const Expression* initialValue() const; |
72 | | |
73 | 1.70M | void setDeclaration(VarDeclaration* declaration) { |
74 | 1.70M | SkASSERT(!fDeclaration); |
75 | 1.70M | fDeclaration = declaration; |
76 | 1.70M | } SkSL::Variable::setDeclaration(SkSL::VarDeclaration*) Line | Count | Source | 73 | 305 | void setDeclaration(VarDeclaration* declaration) { | 74 | 305 | SkASSERT(!fDeclaration); | 75 | 305 | fDeclaration = declaration; | 76 | 305 | } |
SkSL::Variable::setDeclaration(SkSL::VarDeclaration*) Line | Count | Source | 73 | 1.70M | void setDeclaration(VarDeclaration* declaration) { | 74 | 1.70M | SkASSERT(!fDeclaration); | 75 | 1.70M | fDeclaration = declaration; | 76 | 1.70M | } |
|
77 | | |
78 | 942k | void detachDeadVarDeclaration() const { |
79 | | // The VarDeclaration is being deleted, so our reference to it has become stale. |
80 | | // This variable is now dead, so it shouldn't matter that we are modifying its symbol. |
81 | 942k | const_cast<Variable*>(this)->fDeclaration = nullptr; |
82 | 942k | } |
83 | | |
84 | 0 | String description() const override { |
85 | 0 | return this->modifiers().description() + this->type().name() + " " + this->name(); |
86 | 0 | } |
87 | | |
88 | | private: |
89 | | VarDeclaration* fDeclaration = nullptr; |
90 | | const Modifiers* fModifiers; |
91 | | VariableStorage fStorage; |
92 | | bool fBuiltin; |
93 | | |
94 | | using INHERITED = Symbol; |
95 | | |
96 | | friend class dsl::DSLCore; |
97 | | friend class dsl::DSLFunction; |
98 | | friend class VariableReference; |
99 | | }; |
100 | | |
101 | | } // namespace SkSL |
102 | | |
103 | | #endif |