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 String description() const override {
31 return fOwner.description() + "." + fOwner.fType.fields()[fFieldIndex].fName;
32 }
33
34 const Variable& fOwner;
35 const int fFieldIndex;
36
37 typedef Symbol INHERITED;
38};
39
40} // namespace SkSL
41
42#endif
43