Home | History | Annotate | Download | only in ast
      1 /*
      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"
     12 namespace SkSL {
     13 
     14 struct 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)) {
     21         ASSERT(fNames.size() == fValues.size());
     22     }
     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
     45