Line data Source code
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 :
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 :
16 : namespace 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 : */
23 0 : struct Variable : public Symbol {
24 : enum Storage {
25 : kGlobal_Storage,
26 : kLocal_Storage,
27 : kParameter_Storage
28 : };
29 :
30 0 : Variable(Position position, Modifiers modifiers, String name, const Type& type,
31 : Storage storage)
32 0 : : INHERITED(position, kVariable_Kind, std::move(name))
33 : , fModifiers(modifiers)
34 : , fType(type)
35 : , fStorage(storage)
36 : , fReadCount(0)
37 0 : , fWriteCount(0) {}
38 :
39 0 : virtual String description() const override {
40 0 : return fModifiers.description() + fType.fName + " " + fName;
41 : }
42 :
43 : mutable Modifiers fModifiers;
44 : const Type& fType;
45 : const Storage fStorage;
46 :
47 : // Tracks how many sites read from the variable. If this is zero for a non-out variable (or
48 : // becomes zero during optimization), the variable is dead and may be eliminated.
49 : mutable int fReadCount;
50 : // Tracks how many sites write to the variable. If this is zero, the variable is dead and may be
51 : // eliminated.
52 : mutable int fWriteCount;
53 :
54 : typedef Symbol INHERITED;
55 : };
56 :
57 : } // namespace SkSL
58 :
59 : #endif
|