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 "include/private/SkSLModifiers.h" 12 #include "include/private/SkSLSymbol.h" 13 #include "src/sksl/ir/SkSLType.h" 14 #include "src/sksl/ir/SkSLVariable.h" 15 16 namespace 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 */ 23 class Field final : public Symbol { 24 public: 25 inline static constexpr Kind kSymbolKind = Kind::kField; 26 Field(int line,const Variable * owner,int fieldIndex)27 Field(int line, const Variable* owner, int fieldIndex) 28 : INHERITED(line, kSymbolKind, owner->type().fields()[fieldIndex].fName, 29 owner->type().fields()[fieldIndex].fType) 30 , fOwner(owner) 31 , fFieldIndex(fieldIndex) {} 32 fieldIndex()33 int fieldIndex() const { 34 return fFieldIndex; 35 } 36 owner()37 const Variable& owner() const { 38 return *fOwner; 39 } 40 description()41 String description() const override { 42 return this->owner().description() + "." + this->name(); 43 } 44 45 private: 46 const Variable* fOwner; 47 int fFieldIndex; 48 49 using INHERITED = Symbol; 50 }; 51 52 } // namespace SkSL 53 54 #endif 55