OLD | NEW |
(Empty) | |
| 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_LAYOUT |
| 9 #define SKSL_LAYOUT |
| 10 |
| 11 namespace SkSL { |
| 12 |
| 13 /** |
| 14 * Represents a layout block appearing before a variable declaration, as in: |
| 15 * |
| 16 * layout (location = 0) int x; |
| 17 */ |
| 18 struct Layout { |
| 19 Layout(const ASTLayout& layout) |
| 20 : fLocation(layout.fLocation) |
| 21 , fBinding(layout.fBinding) |
| 22 , fIndex(layout.fIndex) |
| 23 , fSet(layout.fSet) |
| 24 , fBuiltin(layout.fBuiltin) {} |
| 25 |
| 26 Layout(int location, int binding, int index, int set, int builtin) |
| 27 : fLocation(location) |
| 28 , fBinding(binding) |
| 29 , fIndex(index) |
| 30 , fSet(set) |
| 31 , fBuiltin(builtin) {} |
| 32 |
| 33 std::string description() const { |
| 34 std::string result; |
| 35 std::string separator; |
| 36 if (fLocation >= 0) { |
| 37 result += separator + "location = " + to_string(fLocation); |
| 38 separator = ", "; |
| 39 } |
| 40 if (fBinding >= 0) { |
| 41 result += separator + "binding = " + to_string(fBinding); |
| 42 separator = ", "; |
| 43 } |
| 44 if (fIndex >= 0) { |
| 45 result += separator + "index = " + to_string(fIndex); |
| 46 separator = ", "; |
| 47 } |
| 48 if (fSet >= 0) { |
| 49 result += separator + "set = " + to_string(fSet); |
| 50 separator = ", "; |
| 51 } |
| 52 if (fBuiltin >= 0) { |
| 53 result += separator + "builtin = " + to_string(fBuiltin); |
| 54 separator = ", "; |
| 55 } |
| 56 if (result.length() > 0) { |
| 57 result = "layout (" + result + ")"; |
| 58 } |
| 59 return result; |
| 60 } |
| 61 |
| 62 bool operator==(const Layout& other) const { |
| 63 return fLocation == other.fLocation && |
| 64 fBinding == other.fBinding && |
| 65 fIndex == other.fIndex && |
| 66 fSet == other.fSet && |
| 67 fBuiltin == other.fBuiltin; |
| 68 } |
| 69 |
| 70 bool operator!=(const Layout& other) const { |
| 71 return !(*this == other); |
| 72 } |
| 73 |
| 74 const int fLocation; |
| 75 const int fBinding; |
| 76 const int fIndex; |
| 77 const int fSet; |
| 78 const int fBuiltin; |
| 79 }; |
| 80 |
| 81 } // namespace |
| 82 |
| 83 #endif |
OLD | NEW |