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 | */ |
Ethan Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 7 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 8 | #ifndef SKSL_ASTINTERFACEBLOCK |
| 9 | #define SKSL_ASTINTERFACEBLOCK |
| 10 | |
| 11 | #include "SkSLASTVarDeclaration.h" |
Ethan Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 12 | #include "../ir/SkSLModifiers.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 13 | |
| 14 | namespace SkSL { |
| 15 | |
| 16 | /** |
| 17 | * An interface block, as in: |
| 18 | * |
Ethan Nicholas | bed683a | 2017-09-26 14:23:59 -0400 | [diff] [blame] | 19 | * out sk_PerVertex { |
| 20 | * layout(builtin=0) float4 sk_Position; |
| 21 | * layout(builtin=1) float sk_PointSize; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 22 | * }; |
| 23 | */ |
| 24 | struct ASTInterfaceBlock : public ASTDeclaration { |
| 25 | // valueName is empty when it was not present in the source |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 26 | ASTInterfaceBlock(int offset, |
Ethan Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 27 | Modifiers modifiers, |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 28 | StringFragment typeName, |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 29 | std::vector<std::unique_ptr<ASTVarDeclarations>> declarations, |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 30 | StringFragment instanceName, |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 31 | std::vector<std::unique_ptr<ASTExpression>> sizes) |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 32 | : INHERITED(offset, kInterfaceBlock_Kind) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 33 | , fModifiers(modifiers) |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 34 | , fTypeName(typeName) |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 35 | , fDeclarations(std::move(declarations)) |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 36 | , fInstanceName(instanceName) |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 37 | , fSizes(std::move(sizes)) {} |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 38 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 39 | String description() const override { |
| 40 | String result = fModifiers.description() + fTypeName + " {\n"; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 41 | for (size_t i = 0; i < fDeclarations.size(); i++) { |
| 42 | result += fDeclarations[i]->description() + "\n"; |
| 43 | } |
| 44 | result += "}"; |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 45 | if (fInstanceName.fLength) { |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 46 | result += " " + fInstanceName; |
| 47 | for (const auto& size : fSizes) { |
| 48 | result += "["; |
| 49 | if (size) { |
| 50 | result += size->description(); |
| 51 | } |
| 52 | result += "]"; |
| 53 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 54 | } |
| 55 | return result + ";"; |
| 56 | } |
| 57 | |
Ethan Nicholas | 11d5397 | 2016-11-28 11:23:23 -0500 | [diff] [blame] | 58 | const Modifiers fModifiers; |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 59 | const StringFragment fTypeName; |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 60 | const std::vector<std::unique_ptr<ASTVarDeclarations>> fDeclarations; |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 61 | const StringFragment fInstanceName; |
Ethan Nicholas | 50afc17 | 2017-02-16 14:49:57 -0500 | [diff] [blame] | 62 | const std::vector<std::unique_ptr<ASTExpression>> fSizes; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 63 | |
| 64 | typedef ASTDeclaration INHERITED; |
| 65 | }; |
| 66 | |
| 67 | } // namespace |
| 68 | |
| 69 | #endif |