blob: 39b8482a7b06ca1101d8a4f50ca861b907cbeb4f [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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
8#ifndef SKSL_VARIABLE
9#define SKSL_VARIABLE
10
11#include "SkSLModifiers.h"
12#include "SkSLPosition.h"
13#include "SkSLSymbol.h"
14#include "SkSLType.h"
15
16namespace SkSL {
17
18/**
19 * Represents a variable, whether local, global, or a function parameter. This represents the
20 * variable itself (the storage location), which is shared between all VariableReferences which
21 * read or write that storage location.
22 */
23struct Variable : public Symbol {
24 enum Storage {
25 kGlobal_Storage,
26 kLocal_Storage,
27 kParameter_Storage
28 };
29
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050030 Variable(Position position, Modifiers modifiers, SkString name, const Type& type,
ethannicholasb3058bd2016-07-01 08:22:01 -070031 Storage storage)
32 : INHERITED(position, kVariable_Kind, std::move(name))
33 , fModifiers(modifiers)
34 , fType(type)
35 , fStorage(storage)
36 , fIsReadFrom(false)
37 , fIsWrittenTo(false) {}
38
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050039 virtual SkString description() const override {
ethannicholasd598f792016-07-25 10:08:54 -070040 return fModifiers.description() + fType.fName + " " + fName;
ethannicholasb3058bd2016-07-01 08:22:01 -070041 }
42
ethannicholasf789b382016-08-03 12:43:36 -070043 mutable Modifiers fModifiers;
ethannicholasd598f792016-07-25 10:08:54 -070044 const Type& fType;
ethannicholasb3058bd2016-07-01 08:22:01 -070045 const Storage fStorage;
46
47 mutable bool fIsReadFrom;
48 mutable bool fIsWrittenTo;
49
50 typedef Symbol INHERITED;
51};
52
53} // namespace SkSL
54
ethannicholasb3058bd2016-07-01 08:22:01 -070055#endif