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_ASTLAYOUT |
| 9 | #define SKSL_ASTLAYOUT |
| 10 | |
| 11 | #include "SkSLASTNode.h" |
| 12 | #include "SkSLUtil.h" |
| 13 | |
| 14 | namespace SkSL { |
| 15 | |
| 16 | /** |
| 17 | * Represents a layout block appearing before a variable declaration, as in: |
| 18 | * |
| 19 | * layout (location = 0) int x; |
| 20 | */ |
| 21 | struct ASTLayout : public ASTNode { |
| 22 | // For all parameters, a -1 means no value |
fmalita | d214d6a | 2016-09-30 08:05:24 -0700 | [diff] [blame^] | 23 | ASTLayout(int location, int binding, int index, int set, int builtin, bool originUpperLeft) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 24 | : fLocation(location) |
| 25 | , fBinding(binding) |
| 26 | , fIndex(index) |
| 27 | , fSet(set) |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 28 | , fBuiltin(builtin) |
fmalita | d214d6a | 2016-09-30 08:05:24 -0700 | [diff] [blame^] | 29 | , fOriginUpperLeft(originUpperLeft) {} |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 30 | |
| 31 | std::string description() const { |
| 32 | std::string result; |
| 33 | std::string separator; |
| 34 | if (fLocation >= 0) { |
| 35 | result += separator + "location = " + to_string(fLocation); |
| 36 | separator = ", "; |
| 37 | } |
| 38 | if (fBinding >= 0) { |
| 39 | result += separator + "binding = " + to_string(fBinding); |
| 40 | separator = ", "; |
| 41 | } |
| 42 | if (fIndex >= 0) { |
| 43 | result += separator + "index = " + to_string(fIndex); |
| 44 | separator = ", "; |
| 45 | } |
| 46 | if (fSet >= 0) { |
| 47 | result += separator + "set = " + to_string(fSet); |
| 48 | separator = ", "; |
| 49 | } |
| 50 | if (fBuiltin >= 0) { |
| 51 | result += separator + "builtin = " + to_string(fBuiltin); |
| 52 | separator = ", "; |
| 53 | } |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 54 | if (fOriginUpperLeft) { |
| 55 | result += separator + "origin_upper_left"; |
| 56 | separator = ", "; |
| 57 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 58 | if (result.length() > 0) { |
| 59 | result = "layout (" + result + ")"; |
| 60 | } |
| 61 | return result; |
| 62 | } |
| 63 | |
| 64 | const int fLocation; |
| 65 | const int fBinding; |
| 66 | const int fIndex; |
| 67 | const int fSet; |
| 68 | const int fBuiltin; |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 69 | const bool fOriginUpperLeft; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | } // namespace |
| 73 | |
| 74 | #endif |