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_DOSTATEMENT 9 #define SKSL_DOSTATEMENT 10 11 #include "include/private/SkSLStatement.h" 12 #include "src/sksl/ir/SkSLExpression.h" 13 14 namespace SkSL { 15 16 /** 17 * A 'do' statement. 18 */ 19 class DoStatement final : public Statement { 20 public: 21 inline static constexpr Kind kStatementKind = Kind::kDo; 22 DoStatement(int line,std::unique_ptr<Statement> statement,std::unique_ptr<Expression> test)23 DoStatement(int line, std::unique_ptr<Statement> statement, std::unique_ptr<Expression> test) 24 : INHERITED(line, kStatementKind) 25 , fStatement(std::move(statement)) 26 , fTest(std::move(test)) {} 27 28 // Creates an SkSL do-while loop; uses the ErrorReporter to report errors. 29 static std::unique_ptr<Statement> Convert(const Context& context, 30 std::unique_ptr<Statement> stmt, 31 std::unique_ptr<Expression> test); 32 33 // Creates an SkSL do-while loop; reports errors via ASSERT. 34 static std::unique_ptr<Statement> Make(const Context& context, 35 std::unique_ptr<Statement> stmt, 36 std::unique_ptr<Expression> test); 37 statement()38 std::unique_ptr<Statement>& statement() { 39 return fStatement; 40 } 41 statement()42 const std::unique_ptr<Statement>& statement() const { 43 return fStatement; 44 } 45 test()46 std::unique_ptr<Expression>& test() { 47 return fTest; 48 } 49 test()50 const std::unique_ptr<Expression>& test() const { 51 return fTest; 52 } 53 54 std::unique_ptr<Statement> clone() const override; 55 56 String description() const override; 57 58 private: 59 std::unique_ptr<Statement> fStatement; 60 std::unique_ptr<Expression> fTest; 61 62 using INHERITED = Statement; 63 }; 64 65 } // namespace SkSL 66 67 #endif 68