blob: 3bee0a4728011758a3c9fed64e7f3a4bf8b18f51 [file] [log] [blame]
Ethan Nicholasaf197692017-02-27 13:26:45 -05001/*
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
14namespace SkSL {
15
16/**
17 * A 'switch' statement.
18 */
19struct ASTSwitchStatement : public ASTStatement {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070020 ASTSwitchStatement(int offset, bool isStatic, std::unique_ptr<ASTExpression> value,
Ethan Nicholasaf197692017-02-27 13:26:45 -050021 std::vector<std::unique_ptr<ASTSwitchCase>> cases)
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070022 : INHERITED(offset, kSwitch_Kind)
Ethan Nicholas5ac13c22017-05-10 15:06:17 -040023 , fIsStatic(isStatic)
Ethan Nicholasaf197692017-02-27 13:26:45 -050024 , fValue(std::move(value))
25 , fCases(std::move(cases)) {}
26
Ethan Nicholas0df1b042017-03-31 13:56:23 -040027 String description() const override {
Ethan Nicholas5ac13c22017-05-10 15:06:17 -040028 String result;
29 if (fIsStatic) {
30 result += "@";
31 }
32 result += String::printf("switch (%s) {\n", fValue->description().c_str());
Ethan Nicholasaf197692017-02-27 13:26:45 -050033 for (const auto& c : fCases) {
34 result += c->description();
35 }
36 result += "}";
37 return result;
38 }
39
Ethan Nicholas5ac13c22017-05-10 15:06:17 -040040 bool fIsStatic;
Ethan Nicholasaf197692017-02-27 13:26:45 -050041 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