aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/ir/SkSLFieldAccess.h
blob: 0f66dec5a4360ccecf46c7afe2f87f45cb411cd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * 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