ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 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 "SkSLModifiers.h" |
| 12 | #include "SkSLPosition.h" |
| 13 | #include "SkSLSymbol.h" |
| 14 | #include "SkSLType.h" |
| 15 | |
| 16 | namespace SkSL { |
| 17 | |
| 18 | /** |
| 19 | * Represents a variable, whether local, global, or a function parameter. This represents the |
| 20 | * variable itself (the storage location), which is shared between all VariableReferences which |
| 21 | * read or write that storage location. |
| 22 | */ |
| 23 | struct Variable : public Symbol { |
| 24 | enum Storage { |
| 25 | kGlobal_Storage, |
| 26 | kLocal_Storage, |
| 27 | kParameter_Storage |
| 28 | }; |
| 29 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame^] | 30 | Variable(Position position, Modifiers modifiers, SkString name, const Type& type, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 31 | Storage storage) |
| 32 | : INHERITED(position, kVariable_Kind, std::move(name)) |
| 33 | , fModifiers(modifiers) |
| 34 | , fType(type) |
| 35 | , fStorage(storage) |
| 36 | , fIsReadFrom(false) |
| 37 | , fIsWrittenTo(false) {} |
| 38 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame^] | 39 | virtual SkString description() const override { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 40 | return fModifiers.description() + fType.fName + " " + fName; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 41 | } |
| 42 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 43 | mutable Modifiers fModifiers; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 44 | const Type& fType; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 45 | const Storage fStorage; |
| 46 | |
| 47 | mutable bool fIsReadFrom; |
| 48 | mutable bool fIsWrittenTo; |
| 49 | |
| 50 | typedef Symbol INHERITED; |
| 51 | }; |
| 52 | |
| 53 | } // namespace SkSL |
| 54 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 55 | #endif |