blob: fe2af7fa6ebd1102e728446e43cefb85f6bafd5e [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 */
Ethan Nicholas0df1b042017-03-31 13:56:23 -04007
ethannicholasb3058bd2016-07-01 08:22:01 -07008#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 Canary6b20a552017-02-07 14:09:38 -050015#include "SkSLVariable.h"
ethannicholasb3058bd2016-07-01 08:22:01 -070016
17namespace SkSL {
18
Ethan Nicholas0df1b042017-03-31 13:56:23 -040019/**
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
ethannicholasb3058bd2016-07-01 08:22:01 -070022 * result of declaring anonymous interface blocks.
23 */
24struct Field : public Symbol {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070025 Field(int offset, const Variable& owner, int fieldIndex)
26 : INHERITED(offset, kField_Kind, owner.fType.fields()[fieldIndex].fName)
ethannicholasb3058bd2016-07-01 08:22:01 -070027 , fOwner(owner)
28 , fFieldIndex(fieldIndex) {}
29
Ethan Nicholas0df1b042017-03-31 13:56:23 -040030 virtual String description() const override {
ethannicholasd598f792016-07-25 10:08:54 -070031 return fOwner.description() + "." + fOwner.fType.fields()[fFieldIndex].fName;
ethannicholasb3058bd2016-07-01 08:22:01 -070032 }
33
ethannicholasd598f792016-07-25 10:08:54 -070034 const Variable& fOwner;
ethannicholasb3058bd2016-07-01 08:22:01 -070035 const int fFieldIndex;
36
37 typedef Symbol INHERITED;
38};
39
40} // namespace SkSL
41
42#endif