blob: 61d2e9f25d53c24b488a32920def1ae3ead76bc4 [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_ASTMODIFIERS
9#define SKSL_ASTMODIFIERS
10
11#include "SkSLASTLayout.h"
12#include "SkSLASTNode.h"
13
14namespace SkSL {
15
16/**
17 * A set of modifier keywords (in, out, uniform, etc.) appearing before a declaration.
18 */
19struct ASTModifiers : public ASTNode {
20 enum Flag {
ethannicholasf789b382016-08-03 12:43:36 -070021 kNo_Flag = 0,
22 kConst_Flag = 1,
23 kIn_Flag = 2,
24 kOut_Flag = 4,
25 kLowp_Flag = 8,
26 kMediump_Flag = 16,
27 kHighp_Flag = 32,
28 kUniform_Flag = 64,
29 kFlat_Flag = 128,
30 kNoPerspective_Flag = 256
ethannicholasb3058bd2016-07-01 08:22:01 -070031 };
32
33 ASTModifiers(ASTLayout layout, int flags)
34 : fLayout(layout)
35 , fFlags(flags) {}
36
Greg Daniel792d0f12016-11-20 14:53:35 +000037 std::string description() const override {
38 std::string result = fLayout.description();
ethannicholasb3058bd2016-07-01 08:22:01 -070039 if (fFlags & kUniform_Flag) {
40 result += "uniform ";
41 }
42 if (fFlags & kConst_Flag) {
43 result += "const ";
44 }
45 if (fFlags & kLowp_Flag) {
46 result += "lowp ";
47 }
48 if (fFlags & kMediump_Flag) {
49 result += "mediump ";
50 }
51 if (fFlags & kHighp_Flag) {
52 result += "highp ";
53 }
ethannicholasf789b382016-08-03 12:43:36 -070054 if (fFlags & kFlat_Flag) {
55 result += "flat ";
56 }
57 if (fFlags & kNoPerspective_Flag) {
58 result += "noperspective ";
59 }
ethannicholasb3058bd2016-07-01 08:22:01 -070060
61 if ((fFlags & kIn_Flag) && (fFlags & kOut_Flag)) {
62 result += "inout ";
63 } else if (fFlags & kIn_Flag) {
64 result += "in ";
65 } else if (fFlags & kOut_Flag) {
66 result += "out ";
67 }
68
69 return result;
70 }
71
72 const ASTLayout fLayout;
73 const int fFlags;
74};
75
76} // namespace
77
78#endif