skia2/src/sksl/ir/SkSLFieldAccess.h
Ethan Nicholas 5b5f096a03 Revert "Revert "Switch to the new SkSL lexer.""
This reverts commit 358515491a.

Bug: skia:
Change-Id: I013fac0ed83774d8ae7c6ee6819045cab37f5e97
Reviewed-on: https://skia-review.googlesource.com/45180
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2017-09-11 21:45:20 +00:00

52 lines
1.3 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#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 {
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
};
FieldAccess(std::unique_ptr<Expression> base, int fieldIndex,
OwnerKind ownerKind = kDefault_OwnerKind)
: INHERITED(base->fOffset, kFieldAccess_Kind, *base->fType.fields()[fieldIndex].fType)
, fBase(std::move(base))
, fFieldIndex(fieldIndex)
, fOwnerKind(ownerKind) {}
bool hasSideEffects() const override {
return fBase->hasSideEffects();
}
String description() const override {
return fBase->description() + "." + fBase->fType.fields()[fFieldIndex].fName;
}
std::unique_ptr<Expression> fBase;
const int fFieldIndex;
const OwnerKind fOwnerKind;
typedef Expression INHERITED;
};
} // namespace
#endif