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_ASTSWITCHSTATEMENT
      9 #define SKSL_ASTSWITCHSTATEMENT
     10 
     11 #include "SkSLASTStatement.h"
     12 #include "SkSLASTSwitchCase.h"
     13 
     14 namespace SkSL {
     15 
     16 /**
     17  * A 'switch' statement.
     18  */
     19 struct ASTSwitchStatement : public ASTStatement {
     20     ASTSwitchStatement(int offset, bool isStatic, std::unique_ptr<ASTExpression> value,
     21                        std::vector<std::unique_ptr<ASTSwitchCase>> cases)
     22     : INHERITED(offset, kSwitch_Kind)
     23     , fIsStatic(isStatic)
     24     , fValue(std::move(value))
     25     , fCases(std::move(cases)) {}
     26 
     27     String description() const override {
     28         String result;
     29         if (fIsStatic) {
     30             result += "@";
     31         }
     32         result += String::printf("switch (%s) {\n", fValue->description().c_str());
     33         for (const auto& c : fCases) {
     34             result += c->description();
     35         }
     36         result += "}";
     37         return result;
     38     }
     39 
     40     bool fIsStatic;
     41     const std::unique_ptr<ASTExpression> fValue;
     42     const std::vector<std::unique_ptr<ASTSwitchCase>> fCases;
     43 
     44     typedef ASTStatement INHERITED;
     45 };
     46 
     47 } // namespace
     48 
     49 #endif
     50