blob: 515eb2bdbbbbca680eb4830ccb78b1b6ba5ba56f [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_ASTLAYOUT
9#define SKSL_ASTLAYOUT
10
11#include "SkSLASTNode.h"
12#include "SkSLUtil.h"
13
14namespace SkSL {
15
16/**
17 * Represents a layout block appearing before a variable declaration, as in:
18 *
19 * layout (location = 0) int x;
20 */
21struct ASTLayout : public ASTNode {
22 // For all parameters, a -1 means no value
ethannicholasdcfe6db2016-10-10 10:09:00 -070023 ASTLayout(int location, int binding, int index, int set, int builtin, bool originUpperLeft,
24 bool overrideCoverage, bool blendSupportAllEquations)
ethannicholasb3058bd2016-07-01 08:22:01 -070025 : fLocation(location)
26 , fBinding(binding)
27 , fIndex(index)
28 , fSet(set)
ethannicholasf789b382016-08-03 12:43:36 -070029 , fBuiltin(builtin)
ethannicholasdcfe6db2016-10-10 10:09:00 -070030 , fOriginUpperLeft(originUpperLeft)
31 , fOverrideCoverage(overrideCoverage)
32 , fBlendSupportAllEquations(blendSupportAllEquations) {}
ethannicholasb3058bd2016-07-01 08:22:01 -070033
34 std::string description() const {
35 std::string result;
36 std::string separator;
37 if (fLocation >= 0) {
38 result += separator + "location = " + to_string(fLocation);
39 separator = ", ";
40 }
41 if (fBinding >= 0) {
42 result += separator + "binding = " + to_string(fBinding);
43 separator = ", ";
44 }
45 if (fIndex >= 0) {
46 result += separator + "index = " + to_string(fIndex);
47 separator = ", ";
48 }
49 if (fSet >= 0) {
50 result += separator + "set = " + to_string(fSet);
51 separator = ", ";
52 }
53 if (fBuiltin >= 0) {
54 result += separator + "builtin = " + to_string(fBuiltin);
55 separator = ", ";
56 }
ethannicholasf789b382016-08-03 12:43:36 -070057 if (fOriginUpperLeft) {
58 result += separator + "origin_upper_left";
59 separator = ", ";
60 }
ethannicholasdcfe6db2016-10-10 10:09:00 -070061 if (fOverrideCoverage) {
62 result += separator + "override_coverage";
63 separator = ", ";
64 }
65 if (fBlendSupportAllEquations) {
66 result += separator + "blend_support_all_equations";
67 separator = ", ";
68 }
ethannicholasb3058bd2016-07-01 08:22:01 -070069 if (result.length() > 0) {
70 result = "layout (" + result + ")";
71 }
72 return result;
73 }
74
75 const int fLocation;
76 const int fBinding;
77 const int fIndex;
78 const int fSet;
79 const int fBuiltin;
ethannicholasf789b382016-08-03 12:43:36 -070080 const bool fOriginUpperLeft;
ethannicholasdcfe6db2016-10-10 10:09:00 -070081 const bool fOverrideCoverage;
82 const bool fBlendSupportAllEquations;
ethannicholasb3058bd2016-07-01 08:22:01 -070083};
84
85} // namespace
86
87#endif