blob: f73b6025ec4f5f27c61fd0c4ee1d542b5e01baa1 [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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
16namespace 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 */
23struct Field : public Symbol {
ethannicholasd598f792016-07-25 10:08:54 -070024 Field(Position position, const Variable& owner, int fieldIndex)
25 : INHERITED(position, kField_Kind, owner.fType.fields()[fieldIndex].fName)
ethannicholasb3058bd2016-07-01 08:22:01 -070026 , fOwner(owner)
27 , fFieldIndex(fieldIndex) {}
28
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050029 virtual SkString description() const override {
ethannicholasd598f792016-07-25 10:08:54 -070030 return fOwner.description() + "." + fOwner.fType.fields()[fFieldIndex].fName;
ethannicholasb3058bd2016-07-01 08:22:01 -070031 }
32
ethannicholasd598f792016-07-25 10:08:54 -070033 const Variable& fOwner;
ethannicholasb3058bd2016-07-01 08:22:01 -070034 const int fFieldIndex;
35
36 typedef Symbol INHERITED;
37};
38
39} // namespace SkSL
40
41#endif