blob: d1697027104ee9785afdf31ebc1ec6551e06e4d0 [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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
13namespace SkSL {
14
15/**
16 * An 'if' statement.
17 */
18struct ASTIfStatement : public ASTStatement {
19 ASTIfStatement(Position position, std::unique_ptr<ASTExpression> test,
20 std::unique_ptr<ASTStatement> ifTrue, std::unique_ptr<ASTStatement> ifFalse)
21 : INHERITED(position, kIf_Kind)
22 , fTest(std::move(test))
23 , fIfTrue(std::move(ifTrue))
24 , fIfFalse(std::move(ifFalse)) {}
25
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050026 SkString description() const override {
27 SkString result("if (");
ethannicholasb3058bd2016-07-01 08:22:01 -070028 result += fTest->description();
29 result += ") ";
30 result += fIfTrue->description();
31 if (fIfFalse) {
32 result += " else ";
33 result += fIfFalse->description();
34 }
35 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