1 /*
2 * Copyright 2021 Google LLC
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 #include "src/sksl/SkSLContext.h"
9 #include "src/sksl/SkSLProgramSettings.h"
10 #include "src/sksl/ir/SkSLDoStatement.h"
11
12 namespace SkSL {
13
Convert(const Context & context,std::unique_ptr<Statement> stmt,std::unique_ptr<Expression> test)14 std::unique_ptr<Statement> DoStatement::Convert(const Context& context,
15 std::unique_ptr<Statement> stmt,
16 std::unique_ptr<Expression> test) {
17 if (context.fConfig->strictES2Mode()) {
18 context.fErrors.error(stmt->fOffset, "do-while loops are not supported");
19 return nullptr;
20 }
21 test = context.fTypes.fBool->coerceExpression(std::move(test), context);
22 if (!test) {
23 return nullptr;
24 }
25 return DoStatement::Make(context, std::move(stmt), std::move(test));
26 }
27
Make(const Context & context,std::unique_ptr<Statement> stmt,std::unique_ptr<Expression> test)28 std::unique_ptr<Statement> DoStatement::Make(const Context& context,
29 std::unique_ptr<Statement> stmt,
30 std::unique_ptr<Expression> test) {
31 SkASSERT(!context.fConfig->strictES2Mode());
32 SkASSERT(test->type() == *context.fTypes.fBool);
33 return std::make_unique<DoStatement>(stmt->fOffset, std::move(stmt), std::move(test));
34 }
35
clone() const36 std::unique_ptr<Statement> DoStatement::clone() const {
37 return std::make_unique<DoStatement>(fOffset, this->statement()->clone(),
38 this->test()->clone());
39 }
40
description() const41 String DoStatement::description() const {
42 return "do " + this->statement()->description() +
43 " while (" + this->test()->description() + ");";
44 }
45
46 } // namespace SkSL
47
48