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 "SkSLExpression.h" 12 #include "SkSLStatement.h" 13 14 namespace SkSL { 15 16 /** 17 * An 'if' statement. 18 */ 19 struct IfStatement : public Statement { IfStatementIfStatement20 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 cloneIfStatement28 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 descriptionIfStatement33 String description() const override { 34 String result; 35 if (fIsStatic) { 36 result += "@"; 37 } 38 result += "if (" + fTest->description() + ") " + fIfTrue->description(); 39 if (fIfFalse) { 40 result += " else " + fIfFalse->description(); 41 } 42 return result; 43 } 44 45 bool fIsStatic; 46 std::unique_ptr<Expression> fTest; 47 std::unique_ptr<Statement> fIfTrue; 48 // may be null 49 std::unique_ptr<Statement> fIfFalse; 50 51 typedef Statement INHERITED; 52 }; 53 54 } // namespace 55 56 #endif 57