Line data Source code
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 0 : struct ASTSwitchStatement : public ASTStatement {
20 0 : ASTSwitchStatement(Position position, std::unique_ptr<ASTExpression> value,
21 : std::vector<std::unique_ptr<ASTSwitchCase>> cases)
22 0 : : INHERITED(position, kSwitch_Kind)
23 0 : , fValue(std::move(value))
24 0 : , fCases(std::move(cases)) {}
25 :
26 0 : String description() const override {
27 0 : String result = String::printf("switch (%s) {\n", + fValue->description().c_str());
28 0 : for (const auto& c : fCases) {
29 0 : result += c->description();
30 : }
31 0 : result += "}";
32 0 : 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
|