Remove DSLWrapper helper class.
Without an `operator=` on our expressions and variables, we no longer need to wrap all our expressions with a helper. Change-Id: I8110079f61c9ad01997f7c4b376db223dc4b6e17 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/541063 Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
b143520625
commit
3b4f862d05
@ -136,12 +136,6 @@ generated_cc_atom(
|
||||
],
|
||||
)
|
||||
|
||||
generated_cc_atom(
|
||||
name = "DSLWrapper_hdr",
|
||||
hdrs = ["DSLWrapper.h"],
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
generated_cc_atom(
|
||||
name = "DSL_hdr",
|
||||
hdrs = ["DSL.h"],
|
||||
|
@ -29,7 +29,6 @@ using Modifiers = DSLModifiers;
|
||||
using Parameter = DSLParameter;
|
||||
using Statement = DSLStatement;
|
||||
using Var = DSLVar;
|
||||
template<typename T> using Wrapper = DSLWrapper<T>;
|
||||
|
||||
} // namespace dsl
|
||||
|
||||
|
@ -33,7 +33,6 @@ namespace dsl {
|
||||
class DSLPossibleExpression;
|
||||
class DSLType;
|
||||
class DSLVarBase;
|
||||
template <typename T> class DSLWrapper;
|
||||
|
||||
/**
|
||||
* Represents an expression such as 'cos(x)' or 'a + b'.
|
||||
@ -134,11 +133,9 @@ public:
|
||||
*/
|
||||
DSLPossibleExpression operator[](DSLExpression index);
|
||||
|
||||
DSLPossibleExpression operator()(SkTArray<DSLWrapper<DSLExpression>> args,
|
||||
Position pos = {});
|
||||
DSLPossibleExpression operator()(SkTArray<DSLExpression> args, Position pos = {});
|
||||
|
||||
DSLPossibleExpression operator()(ExpressionArray args,
|
||||
Position pos = {});
|
||||
DSLPossibleExpression operator()(ExpressionArray args, Position pos = {});
|
||||
|
||||
/**
|
||||
* Invokes a prefix operator.
|
||||
@ -198,7 +195,6 @@ private:
|
||||
friend class DSLType;
|
||||
friend class DSLVarBase;
|
||||
friend class DSLWriter;
|
||||
template<typename T> friend class DSLWrapper;
|
||||
};
|
||||
|
||||
DSLPossibleExpression operator+(DSLExpression left, DSLExpression right);
|
||||
@ -303,11 +299,9 @@ public:
|
||||
|
||||
DSLPossibleExpression operator[](DSLExpression index);
|
||||
|
||||
DSLPossibleExpression operator()(SkTArray<DSLWrapper<DSLExpression>> args,
|
||||
Position pos = {});
|
||||
DSLPossibleExpression operator()(SkTArray<DSLExpression> args, Position pos = {});
|
||||
|
||||
DSLPossibleExpression operator()(ExpressionArray args,
|
||||
Position pos = {});
|
||||
DSLPossibleExpression operator()(ExpressionArray args, Position pos = {});
|
||||
|
||||
DSLPossibleExpression operator++();
|
||||
|
||||
|
@ -27,7 +27,6 @@ class FunctionDeclaration;
|
||||
namespace dsl {
|
||||
|
||||
class DSLType;
|
||||
template <typename T> class DSLWrapper;
|
||||
|
||||
class DSLFunction {
|
||||
public:
|
||||
@ -87,8 +86,7 @@ public:
|
||||
/**
|
||||
* Invokes the function with the given arguments.
|
||||
*/
|
||||
DSLExpression call(SkTArray<DSLWrapper<DSLExpression>> args,
|
||||
Position pos = {});
|
||||
DSLExpression call(SkTArray<DSLExpression> args, Position pos = {});
|
||||
|
||||
DSLExpression call(ExpressionArray args, Position pos = {});
|
||||
|
||||
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* 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_WRAPPER
|
||||
#define SKSL_DSL_WRAPPER
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace SkSL {
|
||||
|
||||
namespace dsl {
|
||||
|
||||
/**
|
||||
* Several of the DSL classes override operator= in a non-standard fashion to allow for expressions
|
||||
* like "x = 0" to compile into SkSL code. This makes it impossible to directly use these classes in
|
||||
* C++ containers which expect standard behavior for operator=.
|
||||
*
|
||||
* Wrapper<T> contains a T, where T is a DSL class with non-standard operator=, and provides
|
||||
* standard behavior for operator=, permitting it to be used in standard containers.
|
||||
*/
|
||||
template<typename T>
|
||||
class DSLWrapper {
|
||||
public:
|
||||
DSLWrapper(T value) {
|
||||
fValue.swap(value);
|
||||
}
|
||||
|
||||
DSLWrapper(const DSLWrapper&) = delete;
|
||||
|
||||
DSLWrapper(DSLWrapper&& other) {
|
||||
fValue.swap(other.fValue);
|
||||
}
|
||||
|
||||
T& get() {
|
||||
return fValue;
|
||||
}
|
||||
|
||||
T& operator*() {
|
||||
return fValue;
|
||||
}
|
||||
|
||||
T* operator->() {
|
||||
return &fValue;
|
||||
}
|
||||
|
||||
const T& get() const {
|
||||
return fValue;
|
||||
}
|
||||
|
||||
const T& operator*() const {
|
||||
return fValue;
|
||||
}
|
||||
|
||||
const T* operator->() const {
|
||||
return &fValue;
|
||||
}
|
||||
|
||||
DSLWrapper& operator=(const DSLWrapper&) = delete;
|
||||
|
||||
DSLWrapper& operator=(DSLWrapper&& other) {
|
||||
fValue.swap(other.fValue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
T fValue;
|
||||
};
|
||||
|
||||
} // namespace dsl
|
||||
|
||||
} // namespace SkSL
|
||||
|
||||
#endif
|
@ -245,7 +245,6 @@ SKIA_PUBLIC_HDRS = [
|
||||
"include/sksl/DSLSymbols.h",
|
||||
"include/sksl/DSLType.h",
|
||||
"include/sksl/DSLVar.h",
|
||||
"include/sksl/DSLWrapper.h",
|
||||
"include/sksl/SkSLDebugTrace.h",
|
||||
"include/sksl/SkSLErrorReporter.h",
|
||||
"include/sksl/SkSLOperator.h",
|
||||
|
@ -426,7 +426,6 @@ generated_cc_atom(
|
||||
"//include/sksl:DSLFunction_hdr",
|
||||
"//include/sksl:DSLSymbols_hdr",
|
||||
"//include/sksl:DSLVar_hdr",
|
||||
"//include/sksl:DSLWrapper_hdr",
|
||||
"//include/sksl:DSL_hdr",
|
||||
"//include/sksl:SkSLOperator_hdr",
|
||||
"//src/sksl/dsl/priv:DSLWriter_hdr",
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "include/sksl/DSLFunction.h"
|
||||
#include "include/sksl/DSLSymbols.h"
|
||||
#include "include/sksl/DSLVar.h"
|
||||
#include "include/sksl/DSLWrapper.h"
|
||||
#include "include/sksl/SkSLOperator.h"
|
||||
#include "src/sksl/SkSLCompiler.h"
|
||||
#include "src/sksl/SkSLConstantFolder.h"
|
||||
@ -397,7 +396,7 @@ bool DSLParser::functionDeclarationEnd(Position start,
|
||||
const DSLModifiers& modifiers,
|
||||
DSLType type,
|
||||
const Token& name) {
|
||||
SkTArray<DSLWrapper<DSLParameter>> parameters;
|
||||
SkTArray<DSLParameter> parameters;
|
||||
Token lookahead = this->peek();
|
||||
if (lookahead.fKind == Token::Kind::TK_RPAREN) {
|
||||
// `()` means no parameters at all.
|
||||
@ -407,7 +406,7 @@ bool DSLParser::functionDeclarationEnd(Position start,
|
||||
} else {
|
||||
for (;;) {
|
||||
size_t paramIndex = parameters.size();
|
||||
std::optional<DSLWrapper<DSLParameter>> parameter = this->parameter(paramIndex);
|
||||
std::optional<DSLParameter> parameter = this->parameter(paramIndex);
|
||||
if (!parameter) {
|
||||
return false;
|
||||
}
|
||||
@ -421,8 +420,8 @@ bool DSLParser::functionDeclarationEnd(Position start,
|
||||
return false;
|
||||
}
|
||||
SkTArray<DSLParameter*> parameterPointers;
|
||||
for (DSLWrapper<DSLParameter>& param : parameters) {
|
||||
parameterPointers.push_back(¶m.get());
|
||||
for (DSLParameter& param : parameters) {
|
||||
parameterPointers.push_back(¶m);
|
||||
}
|
||||
DSLFunction result(modifiers, type, this->text(name), parameterPointers,
|
||||
this->rangeFrom(start));
|
||||
@ -721,7 +720,7 @@ SkTArray<dsl::DSLGlobalVar> DSLParser::structVarDeclaration(Position start,
|
||||
}
|
||||
|
||||
/* modifiers type IDENTIFIER (LBRACKET INT_LITERAL RBRACKET)? */
|
||||
std::optional<DSLWrapper<DSLParameter>> DSLParser::parameter(size_t paramIndex) {
|
||||
std::optional<DSLParameter> DSLParser::parameter(size_t paramIndex) {
|
||||
Position pos = this->position(this->peek());
|
||||
DSLModifiers modifiers = this->modifiers();
|
||||
std::optional<DSLType> type = this->type(&modifiers);
|
||||
@ -742,7 +741,7 @@ std::optional<DSLWrapper<DSLParameter>> DSLParser::parameter(size_t paramIndex)
|
||||
if (!this->parseArrayDimensions(pos, &type.value())) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return {{DSLParameter(modifiers, *type, paramText, this->rangeFrom(pos), paramPos)}};
|
||||
return DSLParameter(modifiers, *type, paramText, this->rangeFrom(pos), paramPos);
|
||||
}
|
||||
|
||||
/** EQ INT_LITERAL */
|
||||
|
@ -40,7 +40,6 @@ class DSLBlock;
|
||||
class DSLCase;
|
||||
class DSLGlobalVar;
|
||||
class DSLParameter;
|
||||
template <typename T> class DSLWrapper;
|
||||
|
||||
}
|
||||
|
||||
@ -177,7 +176,7 @@ private:
|
||||
dsl::DSLStatement localVarDeclarationEnd(Position position, const dsl::DSLModifiers& mods,
|
||||
dsl::DSLType baseType, Token name);
|
||||
|
||||
std::optional<dsl::DSLWrapper<dsl::DSLParameter>> parameter(size_t paramIndex);
|
||||
std::optional<dsl::DSLParameter> parameter(size_t paramIndex);
|
||||
|
||||
int layoutInt();
|
||||
|
||||
|
@ -87,7 +87,6 @@ generated_cc_atom(
|
||||
"//include/sksl:DSLExpression_hdr",
|
||||
"//include/sksl:DSLType_hdr",
|
||||
"//include/sksl:DSLVar_hdr",
|
||||
"//include/sksl:DSLWrapper_hdr",
|
||||
"//include/sksl:SkSLOperator_hdr",
|
||||
"//src/sksl:SkSLThreadContext_hdr",
|
||||
"//src/sksl/dsl/priv:DSLWriter_hdr",
|
||||
@ -117,7 +116,6 @@ generated_cc_atom(
|
||||
"//include/sksl:DSLFunction_hdr",
|
||||
"//include/sksl:DSLType_hdr",
|
||||
"//include/sksl:DSLVar_hdr",
|
||||
"//include/sksl:DSLWrapper_hdr",
|
||||
"//src/sksl:SkSLProgramSettings_hdr",
|
||||
"//src/sksl:SkSLThreadContext_hdr",
|
||||
"//src/sksl/dsl/priv:DSLWriter_hdr",
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "include/sksl/DSLCore.h"
|
||||
#include "include/sksl/DSLType.h"
|
||||
#include "include/sksl/DSLVar.h"
|
||||
#include "include/sksl/DSLWrapper.h"
|
||||
#include "include/sksl/SkSLOperator.h"
|
||||
#include "src/sksl/SkSLThreadContext.h"
|
||||
#include "src/sksl/dsl/priv/DSLWriter.h"
|
||||
@ -210,12 +209,11 @@ DSLExpression DSLExpression::index(DSLExpression index, Position pos) {
|
||||
return DSLExpression(std::move(result), pos);
|
||||
}
|
||||
|
||||
DSLPossibleExpression DSLExpression::operator()(SkTArray<DSLWrapper<DSLExpression>> args,
|
||||
Position pos) {
|
||||
DSLPossibleExpression DSLExpression::operator()(SkTArray<DSLExpression> args, Position pos) {
|
||||
ExpressionArray converted;
|
||||
converted.reserve_back(args.count());
|
||||
for (DSLWrapper<DSLExpression>& arg : args) {
|
||||
converted.push_back(arg->release());
|
||||
for (DSLExpression& arg : args) {
|
||||
converted.push_back(arg.release());
|
||||
}
|
||||
return (*this)(std::move(converted), pos);
|
||||
}
|
||||
@ -415,7 +413,7 @@ DSLPossibleExpression DSLPossibleExpression::operator[](DSLExpression index) {
|
||||
return DSLExpression(this->release())[std::move(index)];
|
||||
}
|
||||
|
||||
DSLPossibleExpression DSLPossibleExpression::operator()(SkTArray<DSLWrapper<DSLExpression>> args,
|
||||
DSLPossibleExpression DSLPossibleExpression::operator()(SkTArray<DSLExpression> args,
|
||||
Position pos) {
|
||||
return DSLExpression(this->release())(std::move(args), pos);
|
||||
}
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "include/private/SkSLString.h"
|
||||
#include "include/sksl/DSLType.h"
|
||||
#include "include/sksl/DSLVar.h"
|
||||
#include "include/sksl/DSLWrapper.h"
|
||||
#include "src/sksl/SkSLProgramSettings.h"
|
||||
#include "src/sksl/SkSLThreadContext.h"
|
||||
#include "src/sksl/dsl/priv/DSLWriter.h"
|
||||
@ -123,11 +122,11 @@ void DSLFunction::define(DSLBlock block, Position pos) {
|
||||
ThreadContext::ProgramElements().push_back(std::move(function));
|
||||
}
|
||||
|
||||
DSLExpression DSLFunction::call(SkTArray<DSLWrapper<DSLExpression>> args, Position pos) {
|
||||
DSLExpression DSLFunction::call(SkTArray<DSLExpression> args, Position pos) {
|
||||
ExpressionArray released;
|
||||
released.reserve_back(args.size());
|
||||
for (DSLWrapper<DSLExpression>& arg : args) {
|
||||
released.push_back(arg->release());
|
||||
for (DSLExpression& arg : args) {
|
||||
released.push_back(arg.release());
|
||||
}
|
||||
return this->call(std::move(released));
|
||||
}
|
||||
|
@ -5757,7 +5757,6 @@ generated_cc_atom(
|
||||
"//include/sksl:DSLStatement_hdr",
|
||||
"//include/sksl:DSLType_hdr",
|
||||
"//include/sksl:DSLVar_hdr",
|
||||
"//include/sksl:DSLWrapper_hdr",
|
||||
"//include/sksl:DSL_hdr",
|
||||
"//include/sksl:SkSLErrorReporter_hdr",
|
||||
"//include/sksl:SkSLPosition_hdr",
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "include/sksl/DSLStatement.h"
|
||||
#include "include/sksl/DSLType.h"
|
||||
#include "include/sksl/DSLVar.h"
|
||||
#include "include/sksl/DSLWrapper.h"
|
||||
#include "include/sksl/SkSLErrorReporter.h"
|
||||
#include "include/sksl/SkSLPosition.h"
|
||||
#include "src/gpu/ganesh/GrDirectContextPriv.h"
|
||||
@ -1291,7 +1290,7 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLCall, r, ctxInfo) {
|
||||
{
|
||||
DSLExpression sqrt(SkSL::ThreadContext::Compiler().convertIdentifier(SkSL::Position(),
|
||||
"sqrt"));
|
||||
SkTArray<DSLWrapper<DSLExpression>> args;
|
||||
SkTArray<DSLExpression> args;
|
||||
args.emplace_back(16);
|
||||
EXPECT_EQUAL(sqrt(std::move(args)), "4.0"); // sqrt(16) gets optimized to 4
|
||||
}
|
||||
@ -1301,7 +1300,7 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLCall, r, ctxInfo) {
|
||||
"pow"));
|
||||
DSLVar a(kFloat_Type, "a");
|
||||
DSLVar b(kFloat_Type, "b");
|
||||
SkTArray<DSLWrapper<DSLExpression>> args;
|
||||
SkTArray<DSLExpression> args;
|
||||
args.emplace_back(a);
|
||||
args.emplace_back(b);
|
||||
EXPECT_EQUAL(pow(std::move(args)), "pow(a, b)");
|
||||
@ -2040,19 +2039,6 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLStruct, r, ctxInfo) {
|
||||
"struct NestedStruct { int x; SimpleStruct simple; };");
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLWrapper, r, ctxInfo) {
|
||||
AutoDSLContext context(ctxInfo.directContext()->priv().getGpu());
|
||||
std::vector<Wrapper<DSLExpression>> exprs;
|
||||
exprs.push_back(DSLExpression(1));
|
||||
exprs.emplace_back(2.0);
|
||||
EXPECT_EQUAL(std::move(*exprs[0]), "1");
|
||||
EXPECT_EQUAL(std::move(*exprs[1]), "2.0");
|
||||
|
||||
std::vector<Wrapper<DSLVar>> vars;
|
||||
vars.emplace_back(DSLVar(kInt_Type, "x"));
|
||||
REPORTER_ASSERT(r, DSLWriter::Var(*vars[0])->name() == "x");
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLRTAdjust, r, ctxInfo) {
|
||||
{
|
||||
AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared(),
|
||||
|
Loading…
Reference in New Issue
Block a user