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_ASTINTERFACEBLOCK |
| 9 | #define SKSL_ASTINTERFACEBLOCK |
| 10 | |
| 11 | #include "SkSLASTVarDeclaration.h" |
| 12 | |
| 13 | namespace SkSL { |
| 14 | |
| 15 | /** |
| 16 | * An interface block, as in: |
| 17 | * |
| 18 | * out gl_PerVertex { |
| 19 | * layout(builtin=0) vec4 gl_Position; |
| 20 | * layout(builtin=1) float gl_PointSize; |
| 21 | * }; |
| 22 | */ |
| 23 | struct ASTInterfaceBlock : public ASTDeclaration { |
| 24 | // valueName is empty when it was not present in the source |
| 25 | ASTInterfaceBlock(Position position, |
| 26 | ASTModifiers modifiers, |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 27 | std::string interfaceName, |
| 28 | std::string valueName, |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 29 | std::vector<std::unique_ptr<ASTVarDeclarations>> declarations) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 30 | : INHERITED(position, kInterfaceBlock_Kind) |
| 31 | , fModifiers(modifiers) |
| 32 | , fInterfaceName(std::move(interfaceName)) |
| 33 | , fValueName(std::move(valueName)) |
| 34 | , fDeclarations(std::move(declarations)) {} |
| 35 | |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 36 | std::string description() const override { |
| 37 | std::string result = fModifiers.description() + fInterfaceName + " {\n"; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 38 | for (size_t i = 0; i < fDeclarations.size(); i++) { |
| 39 | result += fDeclarations[i]->description() + "\n"; |
| 40 | } |
| 41 | result += "}"; |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 42 | if (fValueName.length()) { |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 43 | result += " " + fValueName; |
| 44 | } |
| 45 | return result + ";"; |
| 46 | } |
| 47 | |
| 48 | const ASTModifiers fModifiers; |
Greg Daniel | 792d0f1 | 2016-11-20 14:53:35 +0000 | [diff] [blame^] | 49 | const std::string fInterfaceName; |
| 50 | const std::string fValueName; |
ethannicholas | 14fe8cc | 2016-09-07 13:37:16 -0700 | [diff] [blame] | 51 | const std::vector<std::unique_ptr<ASTVarDeclarations>> fDeclarations; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 52 | |
| 53 | typedef ASTDeclaration INHERITED; |
| 54 | }; |
| 55 | |
| 56 | } // namespace |
| 57 | |
| 58 | #endif |