Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLDoStatement.cpp
Go to the documentation of this file.
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
9
17
18namespace SkSL {
19
20std::unique_ptr<Statement> DoStatement::Convert(const Context& context,
22 std::unique_ptr<Statement> stmt,
23 std::unique_ptr<Expression> test) {
24 if (context.fConfig->strictES2Mode()) {
25 context.fErrors->error(pos, "do-while loops are not supported");
26 return nullptr;
27 }
28 test = context.fTypes.fBool->coerceExpression(std::move(test), context);
29 if (!test) {
30 return nullptr;
31 }
33 return nullptr;
34 }
35 return DoStatement::Make(context, pos, std::move(stmt), std::move(test));
36}
37
38std::unique_ptr<Statement> DoStatement::Make(const Context& context,
40 std::unique_ptr<Statement> stmt,
41 std::unique_ptr<Expression> test) {
42 SkASSERT(!context.fConfig->strictES2Mode());
43 SkASSERT(test->type().matches(*context.fTypes.fBool));
45 return std::make_unique<DoStatement>(pos, std::move(stmt), std::move(test));
46}
47
48std::string DoStatement::description() const {
49 return "do " + this->statement()->description() +
50 " while (" + this->test()->description() + ");";
51}
52
53} // namespace SkSL
54
SkPoint pos
#define SkASSERT(cond)
Definition SkAssert.h:116
const std::unique_ptr< Type > fBool
const BuiltinTypes & fTypes
Definition SkSLContext.h:30
ErrorReporter * fErrors
Definition SkSLContext.h:36
ProgramConfig * fConfig
Definition SkSLContext.h:33
std::unique_ptr< Expression > & test()
static std::unique_ptr< Statement > Make(const Context &context, Position pos, std::unique_ptr< Statement > stmt, std::unique_ptr< Expression > test)
static std::unique_ptr< Statement > Convert(const Context &context, Position pos, std::unique_ptr< Statement > stmt, std::unique_ptr< Expression > test)
std::string description() const override
std::unique_ptr< Statement > & statement()
void error(Position position, std::string_view msg)
bool DetectVarDeclarationWithoutScope(const Statement &stmt, ErrorReporter *errors=nullptr)