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