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 | */ |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 7 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 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" |
Hal Canary | 6b20a55 | 2017-02-07 14:09:38 -0500 | [diff] [blame] | 15 | #include "SkSLVariable.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 16 | |
| 17 | namespace SkSL { |
| 18 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 19 | /** |
| 20 | * A symbol which should be interpreted as a field access. Fields are added to the symboltable |
| 21 | * whenever a bare reference to an identifier should refer to a struct field; in GLSL, this is the |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 22 | * result of declaring anonymous interface blocks. |
| 23 | */ |
| 24 | struct Field : public Symbol { |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 25 | Field(int offset, const Variable& owner, int fieldIndex) |
| 26 | : INHERITED(offset, kField_Kind, owner.fType.fields()[fieldIndex].fName) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 27 | , fOwner(owner) |
| 28 | , fFieldIndex(fieldIndex) {} |
| 29 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 30 | virtual String description() const override { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 31 | return fOwner.description() + "." + fOwner.fType.fields()[fFieldIndex].fName; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 32 | } |
| 33 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 34 | const Variable& fOwner; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 35 | const int fFieldIndex; |
| 36 | |
| 37 | typedef Symbol INHERITED; |
| 38 | }; |
| 39 | |
| 40 | } // namespace SkSL |
| 41 | |
| 42 | #endif |