diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-11-10 15:34:03 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-13 14:36:40 +0000 |
commit | aae47c878b83ab6d9742d92a6fa47e762f6b9204 (patch) | |
tree | fd13dbc1dc7c5dc36f8262099cf8ade55ec0cb47 /src/sksl/ast | |
parent | 2d9cb57c83553be3434c04f860d5e9fec30cb453 (diff) |
sksl enum support
Bug: skia:
Change-Id: I4d505b31cf8b59de12bcdbca410aafc085977ba9
Reviewed-on: https://skia-review.googlesource.com/68621
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/ast')
-rw-r--r-- | src/sksl/ast/SkSLASTDeclaration.h | 3 | ||||
-rw-r--r-- | src/sksl/ast/SkSLASTEnum.h | 44 |
2 files changed, 46 insertions, 1 deletions
diff --git a/src/sksl/ast/SkSLASTDeclaration.h b/src/sksl/ast/SkSLASTDeclaration.h index 53aa65f6f2..23d3d7469c 100644 --- a/src/sksl/ast/SkSLASTDeclaration.h +++ b/src/sksl/ast/SkSLASTDeclaration.h @@ -23,7 +23,8 @@ struct ASTDeclaration : public ASTPositionNode { kExtension_Kind, kPrecision_Kind, kModifiers_Kind, - kSection_Kind + kSection_Kind, + kEnum_Kind }; ASTDeclaration(int offset, Kind kind) diff --git a/src/sksl/ast/SkSLASTEnum.h b/src/sksl/ast/SkSLASTEnum.h new file mode 100644 index 0000000000..6fdd091741 --- /dev/null +++ b/src/sksl/ast/SkSLASTEnum.h @@ -0,0 +1,44 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_ASTENUM +#define SKSL_ASTENUM + +#include "SkSLASTDeclaration.h" +namespace SkSL { + +struct ASTEnum : public ASTDeclaration { + ASTEnum(int offset, StringFragment typeName, std::vector<StringFragment> names, + std::vector<std::unique_ptr<ASTExpression>> values) + : INHERITED(offset, kEnum_Kind) + , fTypeName(typeName) + , fNames(std::move(names)) + , fValues(std::move(values)) { + ASSERT(fNames.size() == fValues.size()); + } + + String description() const override { + String result = "enum class " + fTypeName + " {\n"; + String separator; + for (StringFragment name : fNames) { + result += separator + " " + name; + separator = ",\n"; + } + result += "};"; + return result; + } + + const StringFragment fTypeName; + const std::vector<StringFragment> fNames; + const std::vector<std::unique_ptr<ASTExpression>> fValues; + + typedef ASTDeclaration INHERITED; +}; + +} // namespace + +#endif |