Eliminate DSLPossibleStatement.

Unlike DSLPossibleExpression, this was only used in a few rare places,
so it was much easier to remove.

Change-Id: I483dc061691f89d3e808d5bbc23c500bc57b680a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/542662
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
John Stiles 2022-05-31 10:36:14 -04:00 committed by SkCQ
parent 8f7abc5eee
commit 981b140e2f
6 changed files with 39 additions and 88 deletions

View File

@ -52,7 +52,7 @@ private:
friend class DSLCore;
template<class... Cases>
friend DSLPossibleStatement Switch(DSLExpression value, Cases... cases);
friend DSLStatement Switch(DSLExpression value, Cases... cases);
};
} // namespace dsl

View File

@ -15,6 +15,7 @@
#include "include/sksl/DSLExpression.h"
#include "include/sksl/DSLStatement.h"
#include "include/sksl/DSLVar.h"
#include "include/sksl/SkSLPosition.h"
#include <memory>
#include <string>
@ -25,8 +26,6 @@ namespace SkSL {
class Compiler;
class ErrorReporter;
class Position;
struct ForLoopPositions;
struct Program;
struct ProgramSettings;
@ -171,37 +170,31 @@ DSLStatement StaticIf(DSLExpression test, DSLStatement ifTrue,
Position pos = {});
// Internal use only
DSLPossibleStatement PossibleStaticSwitch(DSLExpression value, SkTArray<DSLCase> cases);
DSLStatement StaticSwitch(DSLExpression value, SkTArray<DSLCase> cases,
Position pos = {});
DSLStatement StaticSwitch(DSLExpression value, SkTArray<DSLCase> cases, Position pos = {});
/**
* @switch (value) { cases }
*/
template<class... Cases>
DSLPossibleStatement StaticSwitch(DSLExpression value, Cases... cases) {
DSLStatement StaticSwitch(DSLExpression value, Cases... cases) {
SkTArray<DSLCase> caseArray;
caseArray.reserve_back(sizeof...(cases));
(caseArray.push_back(std::move(cases)), ...);
return PossibleStaticSwitch(std::move(value), std::move(caseArray));
return StaticSwitch(std::move(value), std::move(caseArray), Position{});
}
// Internal use only
DSLPossibleStatement PossibleSwitch(DSLExpression value, SkTArray<DSLCase> cases);
DSLStatement Switch(DSLExpression value, SkTArray<DSLCase> cases,
Position pos = {});
DSLStatement Switch(DSLExpression value, SkTArray<DSLCase> cases, Position pos = {});
/**
* switch (value) { cases }
*/
template<class... Cases>
DSLPossibleStatement Switch(DSLExpression value, Cases... cases) {
DSLStatement Switch(DSLExpression value, Cases... cases) {
SkTArray<DSLCase> caseArray;
caseArray.reserve_back(sizeof...(cases));
(caseArray.push_back(std::move(cases)), ...);
return PossibleSwitch(std::move(value), std::move(caseArray));
return Switch(std::move(value), std::move(caseArray), Position{});
}
/**

View File

@ -23,7 +23,6 @@ namespace dsl {
class DSLBlock;
class DSLExpression;
class DSLPossibleStatement;
class DSLStatement {
public:
@ -31,16 +30,16 @@ public:
DSLStatement(DSLExpression expr);
DSLStatement(DSLPossibleStatement stmt, Position pos = {});
DSLStatement(DSLBlock block);
DSLStatement(DSLStatement&&) = default;
DSLStatement(std::unique_ptr<SkSL::Statement> stmt);
DSLStatement(std::unique_ptr<SkSL::Expression> expr);
DSLStatement(std::unique_ptr<SkSL::Statement> stmt, Position pos);
DSLStatement(std::unique_ptr<SkSL::Statement> stmt);
~DSLStatement();
DSLStatement& operator=(DSLStatement&& other) = default;
@ -72,39 +71,10 @@ private:
friend class DSLBlock;
friend class DSLCore;
friend class DSLExpression;
friend class DSLPossibleStatement;
friend class DSLWriter;
friend DSLStatement operator,(DSLStatement left, DSLStatement right);
};
/**
* Represents a Statement which may have failed and/or have pending errors to report. Converting a
* PossibleStatement into a Statement requires a Position so that any pending errors can be
* reported at the correct position.
*
* PossibleStatement is used instead of Statement in situations where it is not possible to capture
* the Position at the time of Statement construction.
*/
class DSLPossibleStatement {
public:
DSLPossibleStatement(std::unique_ptr<SkSL::Statement> stmt);
DSLPossibleStatement(DSLPossibleStatement&& other) = default;
~DSLPossibleStatement();
bool hasValue() { return fStatement != nullptr; }
std::unique_ptr<SkSL::Statement> release() {
return DSLStatement(std::move(*this)).release();
}
private:
std::unique_ptr<SkSL::Statement> fStatement;
friend class DSLStatement;
};
DSLStatement operator,(DSLStatement left, DSLStatement right);
} // namespace dsl

View File

@ -208,13 +208,15 @@ public:
test.release()), pos);
}
static DSLPossibleStatement For(DSLStatement initializer, DSLExpression test,
static DSLStatement For(DSLStatement initializer, DSLExpression test,
DSLExpression next, DSLStatement stmt, Position pos,
const ForLoopPositions& forLoopPositions) {
return ForStatement::Convert(ThreadContext::Context(), pos, forLoopPositions,
initializer.releaseIfPossible(), test.releaseIfPossible(),
next.releaseIfPossible(), stmt.release(),
ThreadContext::SymbolTable());
return DSLStatement(ForStatement::Convert(ThreadContext::Context(), pos, forLoopPositions,
initializer.releaseIfPossible(),
test.releaseIfPossible(),
next.releaseIfPossible(),
stmt.release(),
ThreadContext::SymbolTable()), pos);
}
static DSLStatement If(DSLExpression test, DSLStatement ifTrue, DSLStatement ifFalse,
@ -344,8 +346,8 @@ public:
return DSLExpression(std::move(result), pos);
}
static DSLPossibleStatement Switch(DSLExpression value, SkTArray<DSLCase> cases,
bool isStatic) {
static DSLStatement Switch(DSLExpression value, SkTArray<DSLCase> cases, bool isStatic,
Position pos) {
ExpressionArray values;
values.reserve_back(cases.count());
StatementArray caseBlocks;
@ -355,14 +357,18 @@ public:
caseBlocks.push_back(SkSL::Block::Make(Position(), std::move(c.fStatements),
Block::Kind::kUnbracedBlock));
}
return SwitchStatement::Convert(ThreadContext::Context(), Position(), isStatic,
value.release(), std::move(values), std::move(caseBlocks),
ThreadContext::SymbolTable());
return DSLStatement(SwitchStatement::Convert(ThreadContext::Context(), pos, isStatic,
value.release(),
std::move(values),
std::move(caseBlocks),
ThreadContext::SymbolTable()), pos);
}
static DSLPossibleStatement While(DSLExpression test, DSLStatement stmt) {
return ForStatement::ConvertWhile(ThreadContext::Context(), Position(), test.release(),
stmt.release(), ThreadContext::SymbolTable());
static DSLStatement While(DSLExpression test, DSLStatement stmt, Position pos) {
return DSLStatement(ForStatement::ConvertWhile(ThreadContext::Context(), pos,
test.release(),
stmt.release(),
ThreadContext::SymbolTable()), pos);
}
};
@ -447,13 +453,13 @@ DSLStatement Do(DSLStatement stmt, DSLExpression test, Position pos) {
DSLStatement For(DSLStatement initializer, DSLExpression test, DSLExpression next,
DSLStatement stmt, Position pos, ForLoopPositions forLoopPositions) {
return DSLStatement(DSLCore::For(std::move(initializer), std::move(test), std::move(next),
std::move(stmt), pos, forLoopPositions), pos);
return DSLCore::For(std::move(initializer), std::move(test), std::move(next),
std::move(stmt), pos, forLoopPositions);
}
DSLStatement If(DSLExpression test, DSLStatement ifTrue, DSLStatement ifFalse, Position pos) {
return DSLCore::If(std::move(test), std::move(ifTrue), std::move(ifFalse), /*isStatic=*/false,
pos);
pos);
}
DSLGlobalVar InterfaceBlock(const DSLModifiers& modifiers, std::string_view typeName,
@ -483,24 +489,16 @@ DSLStatement StaticIf(DSLExpression test, DSLStatement ifTrue, DSLStatement ifFa
pos);
}
DSLPossibleStatement PossibleStaticSwitch(DSLExpression value, SkTArray<DSLCase> cases) {
return DSLCore::Switch(std::move(value), std::move(cases), /*isStatic=*/true);
}
DSLStatement StaticSwitch(DSLExpression value, SkTArray<DSLCase> cases, Position pos) {
return DSLStatement(PossibleStaticSwitch(std::move(value), std::move(cases)), pos);
}
DSLPossibleStatement PossibleSwitch(DSLExpression value, SkTArray<DSLCase> cases) {
return DSLCore::Switch(std::move(value), std::move(cases), /*isStatic=*/false);
return DSLCore::Switch(std::move(value), std::move(cases), /*isStatic=*/true, pos);
}
DSLStatement Switch(DSLExpression value, SkTArray<DSLCase> cases, Position pos) {
return DSLStatement(PossibleSwitch(std::move(value), std::move(cases)), pos);
return DSLCore::Switch(std::move(value), std::move(cases), /*isStatic=*/false, pos);
}
DSLStatement While(DSLExpression test, DSLStatement stmt, Position pos) {
return DSLStatement(DSLCore::While(std::move(test), std::move(stmt)), pos);
return DSLCore::While(std::move(test), std::move(stmt), pos);
}
DSLExpression Abs(DSLExpression x, Position pos) {

View File

@ -44,13 +44,9 @@ DSLStatement::DSLStatement(std::unique_ptr<SkSL::Statement> stmt)
SkASSERT(this->hasValue());
}
DSLStatement::DSLStatement(DSLPossibleStatement stmt, Position pos) {
DSLStatement::DSLStatement(std::unique_ptr<SkSL::Statement> stmt, Position pos)
: fStatement(stmt ? std::move(stmt) : SkSL::Nop::Make()) {
ThreadContext::ReportErrors(pos);
if (stmt.hasValue()) {
fStatement = std::move(stmt.fStatement);
} else {
fStatement = SkSL::Nop::Make();
}
if (pos.valid() && !fStatement->fPosition.valid()) {
fStatement->fPosition = pos;
}
@ -58,11 +54,6 @@ DSLStatement::DSLStatement(DSLPossibleStatement stmt, Position pos) {
DSLStatement::~DSLStatement() {}
DSLPossibleStatement::DSLPossibleStatement(std::unique_ptr<SkSL::Statement> statement)
: fStatement(std::move(statement)) {}
DSLPossibleStatement::~DSLPossibleStatement() {}
DSLStatement operator,(DSLStatement left, DSLStatement right) {
Position pos = left.fStatement->fPosition;
StatementArray stmts;

View File

@ -147,7 +147,6 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLStartup, r, ctxInfo) {
}
static std::string stringize(DSLStatement& stmt) { return stmt.release()->description(); }
static std::string stringize(DSLPossibleStatement& stmt) { return stmt.release()->description(); }
static std::string stringize(DSLExpression& expr) { return expr.release()->description(); }
static std::string stringize(DSLBlock& blck) { return blck.release()->description(); }
static std::string stringize(SkSL::IRNode& node) { return node.description(); }