Line data Source code
1 : /*
2 : * Copyright 2016 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_ASTIFSTATEMENT
9 : #define SKSL_ASTIFSTATEMENT
10 :
11 : #include "SkSLASTStatement.h"
12 :
13 : namespace SkSL {
14 :
15 : /**
16 : * An 'if' statement.
17 : */
18 0 : struct ASTIfStatement : public ASTStatement {
19 0 : ASTIfStatement(Position position, std::unique_ptr<ASTExpression> test,
20 : std::unique_ptr<ASTStatement> ifTrue, std::unique_ptr<ASTStatement> ifFalse)
21 0 : : INHERITED(position, kIf_Kind)
22 0 : , fTest(std::move(test))
23 0 : , fIfTrue(std::move(ifTrue))
24 0 : , fIfFalse(std::move(ifFalse)) {}
25 :
26 0 : String description() const override {
27 0 : String result("if (");
28 0 : result += fTest->description();
29 0 : result += ") ";
30 0 : result += fIfTrue->description();
31 0 : if (fIfFalse) {
32 0 : result += " else ";
33 0 : result += fIfFalse->description();
34 : }
35 0 : return result;
36 : }
37 :
38 : const std::unique_ptr<ASTExpression> fTest;
39 : const std::unique_ptr<ASTStatement> fIfTrue;
40 : const std::unique_ptr<ASTStatement> fIfFalse;
41 :
42 : typedef ASTStatement INHERITED;
43 : };
44 :
45 : } // namespace
46 :
47 : #endif
|