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_IFSTATEMENT
9#define SKSL_IFSTATEMENT
10
11#include "src/sksl/ir/SkSLExpression.h"
12#include "src/sksl/ir/SkSLStatement.h"
13
14namespace SkSL {
15
16/**
17 * An 'if' statement.
18 */
19struct IfStatement : public Statement {
20 IfStatement(int offset, bool isStatic, std::unique_ptr<Expression> test,
21 std::unique_ptr<Statement> ifTrue, std::unique_ptr<Statement> ifFalse)
22 : INHERITED(offset, kIf_Kind)
23 , fIsStatic(isStatic)
24 , fTest(std::move(test))
25 , fIfTrue(std::move(ifTrue))
26 , fIfFalse(std::move(ifFalse)) {}
27
28 std::unique_ptr<Statement> clone() const override {
29 return std::unique_ptr<Statement>(new IfStatement(fOffset, fIsStatic, fTest->clone(),
30 fIfTrue->clone(), fIfFalse ? fIfFalse->clone() : nullptr));
31 }
32
33#ifdef SK_DEBUG
34 String description() const override {
35 String result;
36 if (fIsStatic) {
37 result += "@";
38 }
39 result += "if (" + fTest->description() + ") " + fIfTrue->description();
40 if (fIfFalse) {
41 result += " else " + fIfFalse->description();
42 }
43 return result;
44 }
45#endif
46
47 bool fIsStatic;
48 std::unique_ptr<Expression> fTest;
49 std::unique_ptr<Statement> fIfTrue;
50 // may be null
51 std::unique_ptr<Statement> fIfFalse;
52
53 typedef Statement INHERITED;
54};
55
56} // namespace
57
58#endif
59