Reland "Remove DSLWrapper helper class."
This reverts commit37c03c8d73
. Reason for revert: using vector<> to avoid skia:13339 Original change's description: > Revert "Remove DSLWrapper helper class." > > This reverts commit3b4f862d05
. > > Reason for revert: might have caused chromium:1326848 > > Original change's description: > > 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> > > Change-Id: I7efb3004913f7c85dc551d9740a6b31971de52d2 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/541736 > Auto-Submit: John Stiles <johnstiles@google.com> > Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Change-Id: If6dd5d3187a4623ae732335b8215f4350e45cd2b Reviewed-on: https://skia-review.googlesource.com/c/skia/+/542137 Commit-Queue: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
dce2889681
commit
effd0aeccd
@ -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:
|
||||
@ -84,8 +83,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",
|
||||
|
@ -427,7 +427,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",
|
||||
"//include/sksl:SkSLVersion_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 "include/sksl/SkSLVersion.h"
|
||||
#include "src/sksl/SkSLCompiler.h"
|
||||
@ -416,7 +415,8 @@ bool DSLParser::functionDeclarationEnd(Position start,
|
||||
const DSLModifiers& modifiers,
|
||||
DSLType type,
|
||||
const Token& name) {
|
||||
SkTArray<DSLWrapper<DSLParameter>> parameters;
|
||||
// TODO(skia:13339): use SkSTArray<8, DSLParameter> once SkTArray is go/cfi compatible
|
||||
std::vector<DSLParameter> parameters;
|
||||
Token lookahead = this->peek();
|
||||
if (lookahead.fKind == Token::Kind::TK_RPAREN) {
|
||||
// `()` means no parameters at all.
|
||||
@ -424,9 +424,10 @@ bool DSLParser::functionDeclarationEnd(Position start,
|
||||
// `(void)` also means no parameters at all.
|
||||
this->nextToken();
|
||||
} else {
|
||||
parameters.reserve(8);
|
||||
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;
|
||||
}
|
||||
@ -439,12 +440,13 @@ bool DSLParser::functionDeclarationEnd(Position start,
|
||||
if (!this->expect(Token::Kind::TK_RPAREN, "')'")) {
|
||||
return false;
|
||||
}
|
||||
SkTArray<DSLParameter*> parameterPointers;
|
||||
for (DSLWrapper<DSLParameter>& param : parameters) {
|
||||
parameterPointers.push_back(¶m.get());
|
||||
SkSTArray<8, DSLParameter*> parameterPointers;
|
||||
parameterPointers.reserve_back(parameters.size());
|
||||
for (DSLParameter& param : parameters) {
|
||||
parameterPointers.push_back(¶m);
|
||||
}
|
||||
DSLFunction result(modifiers, type, this->text(name), parameterPointers,
|
||||
this->rangeFrom(start));
|
||||
this->rangeFrom(start));
|
||||
if (!this->checkNext(Token::Kind::TK_SEMICOLON)) {
|
||||
AutoDSLSymbolTable symbols;
|
||||
for (DSLParameter* var : parameterPointers) {
|
||||
@ -740,7 +742,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);
|
||||
@ -761,7 +763,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"
|
||||
@ -206,12 +205,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);
|
||||
}
|
||||
@ -411,7 +409,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"
|
||||
@ -119,11 +118,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));
|
||||
}
|
||||
|
@ -5745,7 +5745,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"
|
||||
@ -1272,7 +1271,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
|
||||
}
|
||||
@ -1282,7 +1281,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)");
|
||||
@ -1993,19 +1992,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(), default_settings(),
|
||||
|
Loading…
Reference in New Issue
Block a user