2016-07-01 15:22:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2017-03-31 17:56:23 +00:00
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
#ifndef SKSL_FIELDACCESS
|
|
|
|
#define SKSL_FIELDACCESS
|
|
|
|
|
|
|
|
#include "SkSLExpression.h"
|
|
|
|
#include "SkSLUtil.h"
|
|
|
|
|
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An expression which extracts a field from a struct, as in 'foo.bar'.
|
|
|
|
*/
|
|
|
|
struct FieldAccess : public Expression {
|
2016-08-03 19:43:36 +00:00
|
|
|
enum OwnerKind {
|
|
|
|
kDefault_OwnerKind,
|
|
|
|
// 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)
|
|
|
|
kAnonymousInterfaceBlock_OwnerKind
|
|
|
|
};
|
|
|
|
|
2017-03-31 17:56:23 +00:00
|
|
|
FieldAccess(std::unique_ptr<Expression> base, int fieldIndex,
|
2016-08-03 19:43:36 +00:00
|
|
|
OwnerKind ownerKind = kDefault_OwnerKind)
|
2017-09-11 20:50:14 +00:00
|
|
|
: INHERITED(base->fOffset, kFieldAccess_Kind, *base->fType.fields()[fieldIndex].fType)
|
2016-07-01 15:22:01 +00:00
|
|
|
, fBase(std::move(base))
|
2016-08-03 19:43:36 +00:00
|
|
|
, fFieldIndex(fieldIndex)
|
|
|
|
, fOwnerKind(ownerKind) {}
|
2016-07-01 15:22:01 +00:00
|
|
|
|
2017-04-20 23:31:52 +00:00
|
|
|
bool hasSideEffects() const override {
|
|
|
|
return fBase->hasSideEffects();
|
|
|
|
}
|
|
|
|
|
|
|
|
String description() const override {
|
2016-07-25 17:08:54 +00:00
|
|
|
return fBase->description() + "." + fBase->fType.fields()[fFieldIndex].fName;
|
2016-07-01 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 18:32:00 +00:00
|
|
|
std::unique_ptr<Expression> fBase;
|
2016-07-01 15:22:01 +00:00
|
|
|
const int fFieldIndex;
|
2016-08-03 19:43:36 +00:00
|
|
|
const OwnerKind fOwnerKind;
|
2016-07-01 15:22:01 +00:00
|
|
|
|
|
|
|
typedef Expression INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|