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(Position position, std::unique_ptr<Expression> value, 21 std::vector<std::unique_ptr<SwitchCase>> cases) 22 : INHERITED(position, kSwitch_Kind) 23 , fValue(std::move(value)) 24 , fCases(std::move(cases)) {} 25 26 SkString description() const override { 27 SkString result = SkStringPrintf("switch (%s) {\n", + fValue->description().c_str()); 28 for (const auto& c : fCases) { 29 result += c->description(); 30 } 31 result += "}"; 32 return result; 33 } 34 35 std::unique_ptr<Expression> fValue; 36 std::vector<std::unique_ptr<SwitchCase>> fCases; 37 38 typedef Statement INHERITED; 39 }; 40 41 } // namespace 42 43 #endif 44