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 "src/sksl/SkSLPosition.h"
12#include "src/sksl/ir/SkSLModifiers.h"
13#include "src/sksl/ir/SkSLSymbol.h"
14#include "src/sksl/ir/SkSLType.h"
15#include "src/sksl/ir/SkSLVariable.h"
16
17namespace SkSL {
18
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
22 * result of declaring anonymous interface blocks.
23 */
24struct Field : public Symbol {
25 Field(int offset, const Variable& owner, int fieldIndex)
26 : INHERITED(offset, kField_Kind, owner.fType.fields()[fieldIndex].fName)
27 , fOwner(owner)
28 , fFieldIndex(fieldIndex) {}
29
30#ifdef SK_DEBUG
31 virtual String description() const override {
32 return fOwner.description() + "." + fOwner.fType.fields()[fFieldIndex].fName;
33 }
34#endif
35
36 const Variable& fOwner;
37 const int fFieldIndex;
38
39 typedef Symbol INHERITED;
40};
41
42} // namespace SkSL
43
44#endif
45