2021-02-09 20:22:57 +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_CASE
|
|
|
|
#define SKSL_DSL_CASE
|
|
|
|
|
2021-03-04 19:30:25 +00:00
|
|
|
#include "include/private/SkSLDefines.h"
|
|
|
|
#include "include/sksl/DSLExpression.h"
|
|
|
|
#include "include/sksl/DSLStatement.h"
|
2021-02-09 20:22:57 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
class Statement;
|
|
|
|
|
|
|
|
namespace dsl {
|
|
|
|
|
|
|
|
class DSLCase {
|
|
|
|
public:
|
|
|
|
// An empty expression means 'default:'.
|
|
|
|
template<class... Statements>
|
|
|
|
DSLCase(DSLExpression value, Statements... statements)
|
|
|
|
: fValue(std::move(value)) {
|
|
|
|
fStatements.reserve_back(sizeof...(statements));
|
2021-03-04 19:30:25 +00:00
|
|
|
// in C++17, we could just do:
|
|
|
|
// (fStatements.push_back(DSLStatement(std::move(statements)).release()), ...);
|
|
|
|
int unused[] =
|
|
|
|
{0,
|
|
|
|
(static_cast<void>(fStatements.push_back(DSLStatement(std::move(statements)).release())),
|
|
|
|
0)...};
|
|
|
|
static_cast<void>(unused);
|
2021-02-09 20:22:57 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 21:00:09 +00:00
|
|
|
DSLCase(DSLExpression value, SkTArray<DSLStatement> statements,
|
|
|
|
PositionInfo info = PositionInfo::Capture());
|
2021-02-09 20:22:57 +00:00
|
|
|
|
2021-09-03 21:00:09 +00:00
|
|
|
DSLCase(DSLExpression value, SkSL::StatementArray statements,
|
|
|
|
PositionInfo info = PositionInfo::Capture());
|
2021-03-04 19:30:25 +00:00
|
|
|
|
2021-05-06 14:47:06 +00:00
|
|
|
DSLCase(DSLCase&&);
|
|
|
|
|
2021-03-04 19:30:25 +00:00
|
|
|
~DSLCase();
|
2021-02-09 20:22:57 +00:00
|
|
|
|
2021-06-10 21:20:44 +00:00
|
|
|
DSLCase& operator=(DSLCase&&);
|
|
|
|
|
2021-03-04 19:30:25 +00:00
|
|
|
void append(DSLStatement stmt);
|
|
|
|
|
|
|
|
private:
|
2021-02-09 20:22:57 +00:00
|
|
|
DSLExpression fValue;
|
|
|
|
SkSL::StatementArray fStatements;
|
2021-09-03 21:00:09 +00:00
|
|
|
PositionInfo fPosition;
|
2021-03-04 19:30:25 +00:00
|
|
|
|
2021-04-30 16:44:00 +00:00
|
|
|
friend class DSLCore;
|
|
|
|
|
2021-03-04 19:30:25 +00:00
|
|
|
template<class... Cases>
|
|
|
|
friend DSLPossibleStatement Switch(DSLExpression value, Cases... cases);
|
2021-02-09 20:22:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dsl
|
|
|
|
|
|
|
|
} // namespace SkSL
|
|
|
|
|
|
|
|
#endif
|