ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 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_ASTMODIFIERS |
| 9 | #define SKSL_ASTMODIFIERS |
| 10 | |
| 11 | #include "SkSLASTLayout.h" |
| 12 | #include "SkSLASTNode.h" |
| 13 | |
| 14 | namespace SkSL { |
| 15 | |
| 16 | /** |
| 17 | * A set of modifier keywords (in, out, uniform, etc.) appearing before a declaration. |
| 18 | */ |
| 19 | struct ASTModifiers : public ASTNode { |
| 20 | enum Flag { |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 21 | 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 |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | ASTModifiers(ASTLayout layout, int flags) |
| 34 | : fLayout(layout) |
| 35 | , fFlags(flags) {} |
| 36 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 37 | std::string description() const override { |
| 38 | std::string result = fLayout.description(); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 39 | 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 | } |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 54 | if (fFlags & kFlat_Flag) { |
| 55 | result += "flat "; |
| 56 | } |
| 57 | if (fFlags & kNoPerspective_Flag) { |
| 58 | result += "noperspective "; |
| 59 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 60 | |
| 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 |