blob: 38023f50b0e639789f42f5d5cb3c6d10d882a3b9 [file] [log] [blame]
Ethan Nicholasaae47c82017-11-10 15:34:03 -05001/*
2 * Copyright 2017 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_ASTENUM
9#define SKSL_ASTENUM
10
11#include "SkSLASTDeclaration.h"
12namespace SkSL {
13
14struct ASTEnum : public ASTDeclaration {
15 ASTEnum(int offset, StringFragment typeName, std::vector<StringFragment> names,
16 std::vector<std::unique_ptr<ASTExpression>> values)
17 : INHERITED(offset, kEnum_Kind)
18 , fTypeName(typeName)
19 , fNames(std::move(names))
20 , fValues(std::move(values)) {
Ethan Nicholasd9d33c32018-06-12 11:05:59 -040021 SkASSERT(fNames.size() == fValues.size());
Ethan Nicholasaae47c82017-11-10 15:34:03 -050022 }
23
24 String description() const override {
25 String result = "enum class " + fTypeName + " {\n";
26 String separator;
27 for (StringFragment name : fNames) {
28 result += separator + " " + name;
29 separator = ",\n";
30 }
31 result += "};";
32 return result;
33 }
34
35 const StringFragment fTypeName;
36 const std::vector<StringFragment> fNames;
37 const std::vector<std::unique_ptr<ASTExpression>> fValues;
38
39 typedef ASTDeclaration INHERITED;
40};
41
42} // namespace
43
44#endif