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_MODIFIERS
9#define SKSL_MODIFIERS
10
11#include "src/sksl/ir/SkSLLayout.h"
12
13namespace SkSL {
14
15/**
16 * A set of modifier keywords (in, out, uniform, etc.) appearing before a declaration.
17 */
18struct Modifiers {
19 enum Flag {
20 kNo_Flag = 0,
21 kConst_Flag = 1 << 0,
22 kIn_Flag = 1 << 1,
23 kOut_Flag = 1 << 2,
24 kUniform_Flag = 1 << 3,
25 kFlat_Flag = 1 << 4,
26 kNoPerspective_Flag = 1 << 5,
27 kReadOnly_Flag = 1 << 6,
28 kWriteOnly_Flag = 1 << 7,
29 kCoherent_Flag = 1 << 8,
30 kVolatile_Flag = 1 << 9,
31 kRestrict_Flag = 1 << 10,
32 kBuffer_Flag = 1 << 11,
33 kHasSideEffects_Flag = 1 << 12,
34 kPLS_Flag = 1 << 13,
35 kPLSIn_Flag = 1 << 14,
36 kPLSOut_Flag = 1 << 15,
37 kVarying_Flag = 1 << 16,
38 };
39
40 Modifiers()
41 : fLayout(Layout())
42 , fFlags(0) {}
43
44 Modifiers(const Layout& layout, int flags)
45 : fLayout(layout)
46 , fFlags(flags) {}
47
48 String description() const {
49 String result = fLayout.description();
50 if (fFlags & kUniform_Flag) {
51 result += "uniform ";
52 }
53 if (fFlags & kConst_Flag) {
54 result += "const ";
55 }
56 if (fFlags & kFlat_Flag) {
57 result += "flat ";
58 }
59 if (fFlags & kNoPerspective_Flag) {
60 result += "noperspective ";
61 }
62 if (fFlags & kReadOnly_Flag) {
63 result += "readonly ";
64 }
65 if (fFlags & kWriteOnly_Flag) {
66 result += "writeonly ";
67 }
68 if (fFlags & kCoherent_Flag) {
69 result += "coherent ";
70 }
71 if (fFlags & kVolatile_Flag) {
72 result += "volatile ";
73 }
74 if (fFlags & kRestrict_Flag) {
75 result += "restrict ";
76 }
77 if (fFlags & kBuffer_Flag) {
78 result += "buffer ";
79 }
80 if (fFlags & kHasSideEffects_Flag) {
81 result += "sk_has_side_effects ";
82 }
83 if (fFlags & kPLS_Flag) {
84 result += "__pixel_localEXT ";
85 }
86 if (fFlags & kPLSIn_Flag) {
87 result += "__pixel_local_inEXT ";
88 }
89 if (fFlags & kPLSOut_Flag) {
90 result += "__pixel_local_outEXT ";
91 }
92 if (fFlags & kVarying_Flag) {
93 result += "varying ";
94 }
95 if ((fFlags & kIn_Flag) && (fFlags & kOut_Flag)) {
96 result += "inout ";
97 } else if (fFlags & kIn_Flag) {
98 result += "in ";
99 } else if (fFlags & kOut_Flag) {
100 result += "out ";
101 }
102
103 return result;
104 }
105
106 bool operator==(const Modifiers& other) const {
107 return fLayout == other.fLayout && fFlags == other.fFlags;
108 }
109
110 bool operator!=(const Modifiers& other) const {
111 return !(*this == other);
112 }
113
114 Layout fLayout;
115 int fFlags;
116};
117
118} // namespace
119
120#endif
121