aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/ir/SkSLFieldAccess.h
blob: fb727e017e3d174e8513bb672ef1179d7b04558b (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
/*
 * 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->fPosition, kFieldAccess_Kind, *base->fType.fields()[fieldIndex].fType)
    , fBase(std::move(base))
    , fFieldIndex(fieldIndex)
    , fOwnerKind(ownerKind) {}

    virtual SkString description() const override {
        return fBase->description() + "." + fBase->fType.fields()[fFieldIndex].fName;
    }

    const std::unique_ptr<Expression> fBase;
    const int fFieldIndex;
    const OwnerKind fOwnerKind;

    typedef Expression INHERITED;
};

} // namespace

#endif