blob: 3031a7d2b1fe07dca25d088821713a6ac00a0084 [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 {
20 ASTSwitchStatement(Position position, std::unique_ptr<ASTExpression> value,
21 std::vector<std::unique_ptr<ASTSwitchCase>> 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 const std::unique_ptr<ASTExpression> fValue;
36 const std::vector<std::unique_ptr<ASTSwitchCase>> fCases;
37
38 typedef ASTStatement INHERITED;
39};
40
41} // namespace
42
43#endif