2021-01-22 20:18:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Google LLC.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SKSL_DSL_BLOCK
|
|
|
|
#define SKSL_DSL_BLOCK
|
|
|
|
|
2021-03-04 19:30:25 +00:00
|
|
|
#include "include/private/SkSLDefines.h"
|
|
|
|
#include "include/sksl/DSLExpression.h"
|
|
|
|
#include "include/sksl/DSLStatement.h"
|
2021-01-22 20:18:25 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
class Statement;
|
|
|
|
|
|
|
|
namespace dsl {
|
|
|
|
|
|
|
|
class DSLBlock {
|
|
|
|
public:
|
|
|
|
template<class... Statements>
|
|
|
|
DSLBlock(Statements... statements) {
|
|
|
|
fStatements.reserve_back(sizeof...(statements));
|
2021-03-04 19:30:25 +00:00
|
|
|
// in C++17, we could just do:
|
|
|
|
// (fStatements.push_back(DSLStatement(statements.release()).release()), ...);
|
|
|
|
int unused[] =
|
|
|
|
{0,
|
|
|
|
(static_cast<void>(fStatements.push_back(DSLStatement(statements.release()).release())),
|
|
|
|
0)...};
|
|
|
|
static_cast<void>(unused);
|
2021-01-22 20:18:25 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 17:39:58 +00:00
|
|
|
DSLBlock(DSLBlock&& other) {
|
|
|
|
fStatements = std::move(other.fStatements);
|
|
|
|
}
|
|
|
|
|
|
|
|
DSLBlock& operator=(DSLBlock&& other) {
|
|
|
|
fStatements = std::move(other.fStatements);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2021-03-04 19:30:25 +00:00
|
|
|
DSLBlock(SkSL::StatementArray statements);
|
2021-01-22 20:18:25 +00:00
|
|
|
|
2021-04-16 17:39:58 +00:00
|
|
|
~DSLBlock();
|
|
|
|
|
2021-01-22 20:18:25 +00:00
|
|
|
void append(DSLStatement stmt);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<SkSL::Statement> release();
|
|
|
|
|
|
|
|
SkSL::StatementArray fStatements;
|
|
|
|
|
|
|
|
friend class DSLStatement;
|
|
|
|
friend class DSLFunction;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dsl
|
|
|
|
|
|
|
|
} // namespace SkSL
|
|
|
|
|
|
|
|
#endif
|