| 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/ir/SkSLModifierFlags.h" |
| 12 |
#include "src/sksl/ir/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 FieldSymbol final : public Symbol { |
| 24 |
public: |
| 25 |
inline static constexpr Kind kIRNodeKind = Kind::kField; |
| 26 |
|
| 27 |
FieldSymbol(Position pos, const Variable* owner, int fieldIndex) |
| 28 |
: INHERITED(pos, kIRNodeKind, owner->type().fields()[fieldIndex].fName, |
| 29 |
owner->type().fields()[fieldIndex].fType) |
| 30 |
, fOwner(owner) |
| 31 |
, fFieldIndex(fieldIndex) {} |
| 32 |
|
| 33 |
int fieldIndex() const { |
| 34 |
return fFieldIndex; |
| 35 |
} |
| 36 |
|
| 37 |
const Variable& owner() const { |
| 38 |
return *fOwner; |
| 39 |
} |
| 40 |
|
| 41 |
std::string description() const override { |
| 42 |
return this->owner().name().empty() |
| 43 |
? std::string(this->name()) |
| 44 |
: (this->owner().description() + "." + std::string(this->name())); |
| 45 |
} |
| 46 |
|
| 47 |
private: |
| 48 |
const Variable* fOwner; |
| 49 |
int fFieldIndex; |
| 50 |
|
| 51 |
using INHERITED = Symbol; |
| 52 |
}; |
| 53 |
|
| 54 |
} // namespace SkSL |
| 55 |
|
| 56 |
#endif |