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_FIELD |
| 9 | #define SKSL_FIELD |
| 10 | |
| 11 | #include "SkSLModifiers.h" |
| 12 | #include "SkSLPosition.h" |
| 13 | #include "SkSLSymbol.h" |
| 14 | #include "SkSLType.h" |
| 15 | |
| 16 | namespace SkSL { |
| 17 | |
| 18 | /** |
| 19 | * A symbol which should be interpreted as a field access. Fields are added to the symboltable |
| 20 | * whenever a bare reference to an identifier should refer to a struct field; in GLSL, this is the |
| 21 | * result of declaring anonymous interface blocks. |
| 22 | */ |
| 23 | struct Field : public Symbol { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 24 | Field(Position position, const Variable& owner, int fieldIndex) |
| 25 | : INHERITED(position, kField_Kind, owner.fType.fields()[fieldIndex].fName) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 26 | , fOwner(owner) |
| 27 | , fFieldIndex(fieldIndex) {} |
| 28 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame^] | 29 | virtual SkString description() const override { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 30 | return fOwner.description() + "." + fOwner.fType.fields()[fFieldIndex].fName; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 31 | } |
| 32 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 33 | const Variable& fOwner; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 34 | const int fFieldIndex; |
| 35 | |
| 36 | typedef Symbol INHERITED; |
| 37 | }; |
| 38 | |
| 39 | } // namespace SkSL |
| 40 | |
| 41 | #endif |