SkSLFieldAccess.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #ifndef SKSL_FIELDACCESS
  8. #define SKSL_FIELDACCESS
  9. #include "src/sksl/SkSLUtil.h"
  10. #include "src/sksl/ir/SkSLExpression.h"
  11. namespace SkSL {
  12. /**
  13. * An expression which extracts a field from a struct, as in 'foo.bar'.
  14. */
  15. struct FieldAccess : public Expression {
  16. enum OwnerKind {
  17. kDefault_OwnerKind,
  18. // this field access is to a field of an anonymous interface block (and thus, the field name
  19. // is actually in global scope, so only the field name needs to be written in GLSL)
  20. kAnonymousInterfaceBlock_OwnerKind
  21. };
  22. FieldAccess(std::unique_ptr<Expression> base, int fieldIndex,
  23. OwnerKind ownerKind = kDefault_OwnerKind)
  24. : INHERITED(base->fOffset, kFieldAccess_Kind, *base->fType.fields()[fieldIndex].fType)
  25. , fBase(std::move(base))
  26. , fFieldIndex(fieldIndex)
  27. , fOwnerKind(ownerKind) {}
  28. bool hasSideEffects() const override {
  29. return fBase->hasSideEffects();
  30. }
  31. std::unique_ptr<Expression> clone() const override {
  32. return std::unique_ptr<Expression>(new FieldAccess(fBase->clone(), fFieldIndex,
  33. fOwnerKind));
  34. }
  35. String description() const override {
  36. return fBase->description() + "." + fBase->fType.fields()[fFieldIndex].fName;
  37. }
  38. std::unique_ptr<Expression> fBase;
  39. const int fFieldIndex;
  40. const OwnerKind fOwnerKind;
  41. typedef Expression INHERITED;
  42. };
  43. } // namespace
  44. #endif