blob: c271362071776a29a84fdc9f7b042f4b416e3981 [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_ASTINTERFACEBLOCK
9#define SKSL_ASTINTERFACEBLOCK
10
11#include "SkSLASTVarDeclaration.h"
12
13namespace 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 */
23struct ASTInterfaceBlock : public ASTDeclaration {
24 // valueName is empty when it was not present in the source
25 ASTInterfaceBlock(Position position,
26 ASTModifiers modifiers,
Greg Daniel792d0f12016-11-20 14:53:35 +000027 std::string interfaceName,
28 std::string valueName,
ethannicholas14fe8cc2016-09-07 13:37:16 -070029 std::vector<std::unique_ptr<ASTVarDeclarations>> declarations)
ethannicholasb3058bd2016-07-01 08:22:01 -070030 : INHERITED(position, kInterfaceBlock_Kind)
31 , fModifiers(modifiers)
32 , fInterfaceName(std::move(interfaceName))
33 , fValueName(std::move(valueName))
34 , fDeclarations(std::move(declarations)) {}
35
Greg Daniel792d0f12016-11-20 14:53:35 +000036 std::string description() const override {
37 std::string result = fModifiers.description() + fInterfaceName + " {\n";
ethannicholasb3058bd2016-07-01 08:22:01 -070038 for (size_t i = 0; i < fDeclarations.size(); i++) {
39 result += fDeclarations[i]->description() + "\n";
40 }
41 result += "}";
Greg Daniel792d0f12016-11-20 14:53:35 +000042 if (fValueName.length()) {
ethannicholasb3058bd2016-07-01 08:22:01 -070043 result += " " + fValueName;
44 }
45 return result + ";";
46 }
47
48 const ASTModifiers fModifiers;
Greg Daniel792d0f12016-11-20 14:53:35 +000049 const std::string fInterfaceName;
50 const std::string fValueName;
ethannicholas14fe8cc2016-09-07 13:37:16 -070051 const std::vector<std::unique_ptr<ASTVarDeclarations>> fDeclarations;
ethannicholasb3058bd2016-07-01 08:22:01 -070052
53 typedef ASTDeclaration INHERITED;
54};
55
56} // namespace
57
58#endif