Home | History | Annotate | Download | only in ir
      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_SWITCHSTATEMENT
      9 #define SKSL_SWITCHSTATEMENT
     10 
     11 #include "SkSLStatement.h"
     12 #include "SkSLSwitchCase.h"
     13 
     14 namespace SkSL {
     15 
     16 /**
     17  * A 'switch' statement.
     18  */
     19 struct SwitchStatement : public Statement {
     20     SwitchStatement(int offset, bool isStatic, std::unique_ptr<Expression> value,
     21                     std::vector<std::unique_ptr<SwitchCase>> cases,
     22                     const std::shared_ptr<SymbolTable> symbols)
     23     : INHERITED(offset, kSwitch_Kind)
     24     , fIsStatic(isStatic)
     25     , fValue(std::move(value))
     26     , fSymbols(std::move(symbols))
     27     , fCases(std::move(cases)) {}
     28 
     29     String description() const override {
     30         String result;
     31         if (fIsStatic) {
     32             result += "@";
     33         }
     34         result += String::printf("switch (%s) {\n", fValue->description().c_str());
     35         for (const auto& c : fCases) {
     36             result += c->description();
     37         }
     38         result += "}";
     39         return result;
     40     }
     41 
     42     bool fIsStatic;
     43     std::unique_ptr<Expression> fValue;
     44     // it's important to keep fCases defined after (and thus destroyed before) fSymbols, because
     45     // destroying statements can modify reference counts in symbols
     46     const std::shared_ptr<SymbolTable> fSymbols;
     47     std::vector<std::unique_ptr<SwitchCase>> fCases;
     48 
     49     typedef Statement INHERITED;
     50 };
     51 
     52 } // namespace
     53 
     54 #endif
     55