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_STATEMENT
|
|
|
|
#define SKSL_DSL_STATEMENT
|
|
|
|
|
|
|
|
#include "include/core/SkTypes.h"
|
2021-03-09 18:10:59 +00:00
|
|
|
#include "include/private/SkSLStatement.h"
|
2022-04-20 20:51:26 +00:00
|
|
|
#include "include/sksl/SkSLPosition.h"
|
2021-01-22 20:18:25 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2022-03-18 20:40:58 +00:00
|
|
|
#include <utility>
|
2021-01-22 20:18:25 +00:00
|
|
|
|
|
|
|
namespace SkSL {
|
|
|
|
|
2021-02-02 18:44:27 +00:00
|
|
|
class Expression;
|
2021-01-22 20:18:25 +00:00
|
|
|
|
|
|
|
namespace dsl {
|
|
|
|
|
|
|
|
class DSLBlock;
|
|
|
|
class DSLExpression;
|
2021-02-25 14:45:49 +00:00
|
|
|
class DSLPossibleStatement;
|
2021-01-22 20:18:25 +00:00
|
|
|
|
|
|
|
class DSLStatement {
|
|
|
|
public:
|
2021-03-04 19:30:25 +00:00
|
|
|
DSLStatement();
|
2021-01-22 20:18:25 +00:00
|
|
|
|
|
|
|
DSLStatement(DSLExpression expr);
|
|
|
|
|
2022-04-08 15:37:08 +00:00
|
|
|
DSLStatement(DSLPossibleStatement stmt, Position pos = {});
|
2021-02-25 14:45:49 +00:00
|
|
|
|
2021-01-22 20:18:25 +00:00
|
|
|
DSLStatement(DSLBlock block);
|
|
|
|
|
|
|
|
DSLStatement(DSLStatement&&) = default;
|
|
|
|
|
2021-09-17 22:49:49 +00:00
|
|
|
DSLStatement(std::unique_ptr<SkSL::Statement> stmt);
|
|
|
|
|
|
|
|
DSLStatement(std::unique_ptr<SkSL::Expression> expr);
|
|
|
|
|
2021-02-17 16:17:56 +00:00
|
|
|
~DSLStatement();
|
2021-01-22 20:18:25 +00:00
|
|
|
|
2021-05-06 14:47:06 +00:00
|
|
|
DSLStatement& operator=(DSLStatement&& other) = default;
|
|
|
|
|
2022-04-20 20:51:26 +00:00
|
|
|
Position position() {
|
|
|
|
SkASSERT(this->hasValue());
|
|
|
|
return fStatement->fPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPosition(Position pos) {
|
|
|
|
SkASSERT(this->hasValue());
|
|
|
|
fStatement->fPosition = pos;
|
|
|
|
}
|
|
|
|
|
2021-08-31 20:12:40 +00:00
|
|
|
bool hasValue() { return fStatement != nullptr; }
|
2021-06-25 16:31:44 +00:00
|
|
|
|
2021-01-22 20:18:25 +00:00
|
|
|
std::unique_ptr<SkSL::Statement> release() {
|
2021-08-31 20:12:40 +00:00
|
|
|
SkASSERT(this->hasValue());
|
2021-01-22 20:18:25 +00:00
|
|
|
return std::move(fStatement);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-08-31 20:12:40 +00:00
|
|
|
std::unique_ptr<SkSL::Statement> releaseIfPossible() {
|
2021-06-25 16:31:44 +00:00
|
|
|
return std::move(fStatement);
|
|
|
|
}
|
|
|
|
|
2021-01-22 20:18:25 +00:00
|
|
|
std::unique_ptr<SkSL::Statement> fStatement;
|
|
|
|
|
|
|
|
friend class DSLBlock;
|
|
|
|
friend class DSLCore;
|
2021-02-17 16:17:56 +00:00
|
|
|
friend class DSLExpression;
|
2021-02-25 14:45:49 +00:00
|
|
|
friend class DSLPossibleStatement;
|
2021-02-09 20:22:57 +00:00
|
|
|
friend class DSLWriter;
|
2021-04-19 14:55:18 +00:00
|
|
|
friend DSLStatement operator,(DSLStatement left, DSLStatement right);
|
2021-01-22 20:18:25 +00:00
|
|
|
};
|
|
|
|
|
2021-02-25 14:45:49 +00:00
|
|
|
/**
|
|
|
|
* Represents a Statement which may have failed and/or have pending errors to report. Converting a
|
2022-03-09 15:22:44 +00:00
|
|
|
* PossibleStatement into a Statement requires a Position so that any pending errors can be
|
2021-02-25 14:45:49 +00:00
|
|
|
* reported at the correct position.
|
|
|
|
*
|
|
|
|
* PossibleStatement is used instead of Statement in situations where it is not possible to capture
|
2022-03-09 15:22:44 +00:00
|
|
|
* the Position at the time of Statement construction.
|
2021-02-25 14:45:49 +00:00
|
|
|
*/
|
|
|
|
class DSLPossibleStatement {
|
|
|
|
public:
|
|
|
|
DSLPossibleStatement(std::unique_ptr<SkSL::Statement> stmt);
|
|
|
|
|
|
|
|
DSLPossibleStatement(DSLPossibleStatement&& other) = default;
|
|
|
|
|
|
|
|
~DSLPossibleStatement();
|
|
|
|
|
2021-08-31 20:12:40 +00:00
|
|
|
bool hasValue() { return fStatement != nullptr; }
|
2021-06-25 16:31:44 +00:00
|
|
|
|
2021-02-25 14:45:49 +00:00
|
|
|
std::unique_ptr<SkSL::Statement> release() {
|
2021-06-25 16:31:44 +00:00
|
|
|
return DSLStatement(std::move(*this)).release();
|
2021-02-25 14:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<SkSL::Statement> fStatement;
|
|
|
|
|
|
|
|
friend class DSLStatement;
|
|
|
|
};
|
|
|
|
|
2021-04-19 14:55:18 +00:00
|
|
|
DSLStatement operator,(DSLStatement left, DSLStatement right);
|
|
|
|
|
2021-01-22 20:18:25 +00:00
|
|
|
} // namespace dsl
|
|
|
|
|
|
|
|
} // namespace SkSL
|
|
|
|
|
|
|
|
#endif
|