blob: 6e9d941e8799d1fd6596986d9156fc373352391b [file] [log] [blame]
* Copyright 2016 Google Inc.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
#include "src/sksl/SkSLUtil.h"
#include "src/sksl/ir/SkSLExpression.h"
namespace SkSL {
enum class FieldAccessOwnerKind : int8_t {
// this field access is to a field of an anonymous interface block (and thus, the field name
// is actually in global scope, so only the field name needs to be written in GLSL)
* An expression which extracts a field from a struct, as in ''.
class FieldAccess final : public Expression {
using OwnerKind = FieldAccessOwnerKind;
static constexpr Kind kExpressionKind = Kind::kFieldAccess;
FieldAccess(std::unique_ptr<Expression> base, int fieldIndex,
OwnerKind ownerKind = OwnerKind::kDefault)
: INHERITED(base->fOffset, kExpressionKind, base->type().fields()[fieldIndex].fType)
, fFieldIndex(fieldIndex)
, fOwnerKind(ownerKind)
, fBase(std::move(base)) {}
// Returns a field-access expression; reports errors via the ErrorReporter.
static std::unique_ptr<Expression> Convert(const Context& context,
std::unique_ptr<Expression> base,
StringFragment field);
// Returns a field-access expression; reports errors via ASSERT.
static std::unique_ptr<Expression> Make(const Context& context,
std::unique_ptr<Expression> base,
int fieldIndex,
OwnerKind ownerKind = OwnerKind::kDefault);
std::unique_ptr<Expression>& base() {
return fBase;
const std::unique_ptr<Expression>& base() const {
return fBase;
int fieldIndex() const {
return fFieldIndex;
OwnerKind ownerKind() const {
return fOwnerKind;
bool hasProperty(Property property) const override {
return this->base()->hasProperty(property);
std::unique_ptr<Expression> clone() const override {
return std::unique_ptr<Expression>(new FieldAccess(this->base()->clone(),
String description() const override {
return this->base()->description() + "." +
int fFieldIndex;
FieldAccessOwnerKind fOwnerKind;
std::unique_ptr<Expression> fBase;
using INHERITED = Expression;
} // namespace SkSL