Reland "Eliminate DSLPossibleExpression."

This reverts commit 193c16380f.

Reason for revert: fixed google3 warning

Original change's description:
> Revert "Eliminate DSLPossibleExpression."
>
> This reverts commit f2d000328f.
>
> Reason for revert: breaking google3 roll
>
> Original change's description:
> > Eliminate DSLPossibleExpression.
> >
> > The Possible(Expression|Statement) classes were added at
> > http://review.skia.org/375069. These classes were responsible for
> > capturing `__builtin_FILE()` and `__builtin_LINE()` when an
> > expression or statement was added to a hand-authored DSL program. This
> > allowed errors to be reported on the C++ file/line where they were
> > encountered. This was a good feature to have, when the plan was to
> > author the majority of SkSL code via DSL.
> >
> > Later, IRNode positions were converted from an integer line number to
> > SkSL Positions at http://review.skia.org/518137. This gave us range
> > tracking, but at a high memory cost (16 bytes per IRNode, versus four
> > bytes when we tracked line numbers only).
> >
> > Positions were reduced to 8 bytes at http://review.skia.org/521005 by
> > removing the filename, which was only used for hand-authored DSL. (The
> > size was pared all the way back to 4 bytes at
> > http://review.skia.org/533699 by packing the data more efficiently.)
> >
> > __builtin_FILE/LINE capturing was removed entirely at
> > http://review.skia.org/528366; the filename was discarded anyway and
> > the line number didn't have a range and wasn't very meaningful without
> > a filename. Also, it didn't matter very much since we no longer intended
> > to hand-craft our programs in DSL.
> >
> > At this stage, DSLPossibleExpression stopped adding value and simply
> > served to move Expressions around.
> >
> > Change-Id: I29ac33e08dcc1804cc0619c1e8856ba28ebcc51d
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/542145
> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
> > Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> > Auto-Submit: John Stiles <johnstiles@google.com>
>
> Change-Id: I33badbdcce8760200246bf50e4932d42721ea952
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/543078
> Reviewed-by: Tyler Denniston <tdenniston@google.com>
> Owners-Override: Kevin Lubick <kjlubick@google.com>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: Tyler Denniston <tdenniston@google.com>

Change-Id: I71f248b2343806f85cad5f0661470c95334bbe22
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/545236
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2022-05-31 09:38:37 -04:00 committed by SkCQ
parent c123b5a93d
commit c6218799a6
11 changed files with 181 additions and 412 deletions

View File

@ -30,7 +30,6 @@ class ExpressionArray;
namespace dsl {
class DSLPossibleExpression;
class DSLType;
class DSLVarBase;
@ -83,12 +82,8 @@ public:
DSLExpression(DSLVarBase&& var, Position pos = {});
DSLExpression(DSLPossibleExpression expr, Position pos = {});
explicit DSLExpression(std::unique_ptr<SkSL::Expression> expression);
// If expression is null, returns Poison(pos)
DSLExpression(std::unique_ptr<SkSL::Expression> expression, Position pos);
// If expression is null, returns Poison
explicit DSLExpression(std::unique_ptr<SkSL::Expression> expression, Position pos = {});
static DSLExpression Poison(Position pos = {});
@ -103,9 +98,9 @@ public:
void setPosition(Position pos);
/**
* Overloads the '=' operator to create an SkSL assignment statement.
* Performs assignment, like the '=' operator.
*/
DSLPossibleExpression assign(DSLExpression other);
DSLExpression assign(DSLExpression other);
DSLExpression x(Position pos = {});
@ -131,11 +126,11 @@ public:
/**
* Creates an SkSL array index expression.
*/
DSLPossibleExpression operator[](DSLExpression index);
DSLExpression operator[](DSLExpression index);
DSLPossibleExpression operator()(SkTArray<DSLExpression> args, Position pos = {});
DSLExpression operator()(SkTArray<DSLExpression> args, Position pos = {});
DSLPossibleExpression operator()(ExpressionArray args, Position pos = {});
DSLExpression operator()(ExpressionArray args, Position pos = {});
/**
* Invokes a prefix operator.
@ -191,133 +186,49 @@ private:
friend class DSLCore;
friend class DSLFunction;
friend class DSLPossibleExpression;
friend class DSLType;
friend class DSLVarBase;
friend class DSLWriter;
};
DSLPossibleExpression operator+(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator+(DSLExpression expr);
DSLPossibleExpression operator+=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator-(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator-(DSLExpression expr);
DSLPossibleExpression operator-=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator*(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator*=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator/(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator/=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator%(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator%=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator<<(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator<<=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator>>(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator>>=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator&&(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator||(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator&(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator&=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator|(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator|=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator^(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator^=(DSLExpression left, DSLExpression right);
DSLPossibleExpression LogicalXor(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator,(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator,(DSLPossibleExpression left, DSLExpression right);
DSLPossibleExpression operator,(DSLExpression left, DSLPossibleExpression right);
DSLPossibleExpression operator,(DSLPossibleExpression left, DSLPossibleExpression right);
DSLPossibleExpression operator==(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator!=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator>(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator<(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator>=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator<=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator!(DSLExpression expr);
DSLPossibleExpression operator~(DSLExpression expr);
DSLPossibleExpression operator++(DSLExpression expr);
DSLPossibleExpression operator++(DSLExpression expr, int);
DSLPossibleExpression operator--(DSLExpression expr);
DSLPossibleExpression operator--(DSLExpression expr, int);
/**
* Represents an Expression which may have failed and/or have pending errors to report. Converting a
* PossibleExpression into an Expression requires a Position so that any pending errors can be
* reported at the correct position.
*
* PossibleExpression is used instead of Expression in situations where it is not possible to
* capture the Position at the time of Expression construction (notably in operator overloads, where
* we cannot add default parameters).
*/
class DSLPossibleExpression {
public:
DSLPossibleExpression(std::unique_ptr<SkSL::Expression> expression);
DSLPossibleExpression(DSLPossibleExpression&& other);
~DSLPossibleExpression();
bool valid() const {
return fExpression != nullptr;
}
/**
* Reports any pending errors at the specified position.
*/
void reportErrors(Position pos);
DSLType type() const;
std::string description() const;
Position position() const;
DSLExpression x(Position pos = {});
DSLExpression y(Position pos = {});
DSLExpression z(Position pos = {});
DSLExpression w(Position pos = {});
DSLExpression r(Position pos = {});
DSLExpression g(Position pos = {});
DSLExpression b(Position pos = {});
DSLExpression a(Position pos = {});
DSLExpression field(std::string_view name, Position pos = {});
DSLPossibleExpression assign(DSLExpression expr);
DSLPossibleExpression assign(int expr);
DSLPossibleExpression assign(float expr);
DSLPossibleExpression assign(double expr);
DSLPossibleExpression operator[](DSLExpression index);
DSLPossibleExpression operator()(SkTArray<DSLExpression> args, Position pos = {});
DSLPossibleExpression operator()(ExpressionArray args, Position pos = {});
DSLPossibleExpression operator++();
DSLPossibleExpression operator++(int);
DSLPossibleExpression operator--();
DSLPossibleExpression operator--(int);
std::unique_ptr<SkSL::Expression> release(Position pos = {});
private:
std::unique_ptr<SkSL::Expression> fExpression;
friend class DSLExpression;
};
DSLExpression operator+(DSLExpression left, DSLExpression right);
DSLExpression operator+(DSLExpression expr);
DSLExpression operator+=(DSLExpression left, DSLExpression right);
DSLExpression operator-(DSLExpression left, DSLExpression right);
DSLExpression operator-(DSLExpression expr);
DSLExpression operator-=(DSLExpression left, DSLExpression right);
DSLExpression operator*(DSLExpression left, DSLExpression right);
DSLExpression operator*=(DSLExpression left, DSLExpression right);
DSLExpression operator/(DSLExpression left, DSLExpression right);
DSLExpression operator/=(DSLExpression left, DSLExpression right);
DSLExpression operator%(DSLExpression left, DSLExpression right);
DSLExpression operator%=(DSLExpression left, DSLExpression right);
DSLExpression operator<<(DSLExpression left, DSLExpression right);
DSLExpression operator<<=(DSLExpression left, DSLExpression right);
DSLExpression operator>>(DSLExpression left, DSLExpression right);
DSLExpression operator>>=(DSLExpression left, DSLExpression right);
DSLExpression operator&&(DSLExpression left, DSLExpression right);
DSLExpression operator||(DSLExpression left, DSLExpression right);
DSLExpression operator&(DSLExpression left, DSLExpression right);
DSLExpression operator&=(DSLExpression left, DSLExpression right);
DSLExpression operator|(DSLExpression left, DSLExpression right);
DSLExpression operator|=(DSLExpression left, DSLExpression right);
DSLExpression operator^(DSLExpression left, DSLExpression right);
DSLExpression operator^=(DSLExpression left, DSLExpression right);
DSLExpression LogicalXor(DSLExpression left, DSLExpression right);
DSLExpression operator,(DSLExpression left, DSLExpression right);
DSLExpression operator==(DSLExpression left, DSLExpression right);
DSLExpression operator!=(DSLExpression left, DSLExpression right);
DSLExpression operator>(DSLExpression left, DSLExpression right);
DSLExpression operator<(DSLExpression left, DSLExpression right);
DSLExpression operator>=(DSLExpression left, DSLExpression right);
DSLExpression operator<=(DSLExpression left, DSLExpression right);
DSLExpression operator!(DSLExpression expr);
DSLExpression operator~(DSLExpression expr);
DSLExpression operator++(DSLExpression expr);
DSLExpression operator++(DSLExpression expr, int);
DSLExpression operator--(DSLExpression expr);
DSLExpression operator--(DSLExpression expr, int);
} // namespace dsl

View File

@ -23,7 +23,6 @@ namespace dsl {
class DSLBlock;
class DSLExpression;
class DSLPossibleExpression;
class DSLPossibleStatement;
class DSLStatement {
@ -32,8 +31,6 @@ public:
DSLStatement(DSLExpression expr);
DSLStatement(DSLPossibleExpression expr, Position pos = {});
DSLStatement(DSLPossibleStatement stmt, Position pos = {});
DSLStatement(DSLBlock block);

View File

@ -155,18 +155,18 @@ public:
bool isEffectChild() const;
template<typename... Args>
static DSLPossibleExpression Construct(DSLType type, DSLVarBase& var, Args&&... args) {
static DSLExpression Construct(DSLType type, DSLVarBase& var, Args&&... args) {
DSLExpression argArray[] = {var, args...};
return Construct(type, SkMakeSpan(argArray));
}
template<typename... Args>
static DSLPossibleExpression Construct(DSLType type, DSLExpression expr, Args&&... args) {
static DSLExpression Construct(DSLType type, DSLExpression expr, Args&&... args) {
DSLExpression argArray[] = {std::move(expr), std::move(args)...};
return Construct(type, SkMakeSpan(argArray));
}
static DSLPossibleExpression Construct(DSLType type, SkSpan<DSLExpression> argArray);
static DSLExpression Construct(DSLType type, SkSpan<DSLExpression> argArray);
private:
const SkSL::Type& skslType() const;

View File

@ -56,60 +56,60 @@ public:
}
DSLExpression x() {
return DSLExpression(*this, Position()).x();
return DSLExpression(*this).x();
}
DSLExpression y() {
return DSLExpression(*this, Position()).y();
return DSLExpression(*this).y();
}
DSLExpression z() {
return DSLExpression(*this, Position()).z();
return DSLExpression(*this).z();
}
DSLExpression w() {
return DSLExpression(*this, Position()).w();
return DSLExpression(*this).w();
}
DSLExpression r() {
return DSLExpression(*this, Position()).r();
return DSLExpression(*this).r();
}
DSLExpression g() {
return DSLExpression(*this, Position()).g();
return DSLExpression(*this).g();
}
DSLExpression b() {
return DSLExpression(*this, Position()).b();
return DSLExpression(*this).b();
}
DSLExpression a() {
return DSLExpression(*this, Position()).a();
return DSLExpression(*this).a();
}
DSLExpression field(std::string_view name) {
return DSLExpression(*this, Position()).field(name);
return DSLExpression(*this).field(name);
}
DSLPossibleExpression operator[](DSLExpression&& index);
DSLExpression operator[](DSLExpression&& index);
DSLPossibleExpression operator++() {
return ++DSLExpression(*this, Position());
DSLExpression operator++() {
return ++DSLExpression(*this);
}
DSLPossibleExpression operator++(int) {
return DSLExpression(*this, Position())++;
DSLExpression operator++(int) {
return DSLExpression(*this)++;
}
DSLPossibleExpression operator--() {
return --DSLExpression(*this, Position());
DSLExpression operator--() {
return --DSLExpression(*this);
}
DSLPossibleExpression operator--(int) {
return DSLExpression(*this, Position())--;
DSLExpression operator--(int) {
return DSLExpression(*this)--;
}
template <class T> DSLPossibleExpression assign(T&& param) {
template <class T> DSLExpression assign(T&& param) {
return this->assignExpression(DSLExpression(std::forward<T>(param)));
}
@ -119,7 +119,7 @@ protected:
*/
DSLVarBase(VariableStorage storage) : fType(kVoid_Type), fStorage(storage) {}
DSLPossibleExpression assignExpression(DSLExpression other);
DSLExpression assignExpression(DSLExpression other);
void swap(DSLVarBase& other);

View File

@ -1948,7 +1948,7 @@ DSLExpression DSLParser::swizzle(Position pos, DSLExpression base,
}
dsl::DSLExpression DSLParser::call(Position pos, dsl::DSLExpression base, ExpressionArray args) {
return DSLExpression(base(std::move(args), pos), pos);
return base(std::move(args), pos);
}
/* LBRACKET expression? RBRACKET | DOT IDENTIFIER | LPAREN arguments RPAREN |

View File

@ -139,14 +139,14 @@ public:
}
template <typename... Args>
static DSLPossibleExpression Call(const char* name, Args... args) {
static DSLExpression Call(const char* name, Position pos, Args... args) {
SkSL::ExpressionArray argArray;
argArray.reserve_back(sizeof...(args));
((void)argArray.push_back(args.release()), ...);
return SkSL::FunctionCall::Convert(ThreadContext::Context(), Position(),
return DSLExpression(SkSL::FunctionCall::Convert(ThreadContext::Context(), pos,
ThreadContext::Compiler().convertIdentifier(Position(), name),
std::move(argArray));
std::move(argArray)));
}
static DSLStatement Break(Position pos) {
@ -504,183 +504,180 @@ DSLStatement While(DSLExpression test, DSLStatement stmt, Position pos) {
}
DSLExpression Abs(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("abs", std::move(x)), pos);
return DSLCore::Call("abs", pos, std::move(x));
}
DSLExpression All(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("all", std::move(x)), pos);
return DSLCore::Call("all", pos, std::move(x));
}
DSLExpression Any(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("any", std::move(x)), pos);
return DSLCore::Call("any", pos, std::move(x));
}
DSLExpression Atan(DSLExpression y_over_x, Position pos) {
return DSLExpression(DSLCore::Call("atan", std::move(y_over_x)), pos);
return DSLCore::Call("atan", pos, std::move(y_over_x));
}
DSLExpression Atan(DSLExpression y, DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("atan", std::move(y), std::move(x)), pos);
return DSLCore::Call("atan", pos, std::move(y), std::move(x));
}
DSLExpression Ceil(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("ceil", std::move(x)), pos);
return DSLCore::Call("ceil", pos, std::move(x));
}
DSLExpression Clamp(DSLExpression x, DSLExpression min, DSLExpression max, Position pos) {
return DSLExpression(DSLCore::Call("clamp", std::move(x), std::move(min), std::move(max)), pos);
return DSLCore::Call("clamp", pos, std::move(x), std::move(min), std::move(max));
}
DSLExpression Cos(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("cos", std::move(x)), pos);
return DSLCore::Call("cos", pos, std::move(x));
}
DSLExpression Cross(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("cross", std::move(x), std::move(y)), pos);
return DSLCore::Call("cross", pos, std::move(x), std::move(y));
}
DSLExpression Degrees(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("degrees", std::move(x)), pos);
return DSLCore::Call("degrees", pos, std::move(x));
}
DSLExpression Distance(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("distance", std::move(x), std::move(y)), pos);
return DSLCore::Call("distance", pos, std::move(x), std::move(y));
}
DSLExpression Dot(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("dot", std::move(x), std::move(y)), pos);
return DSLCore::Call("dot", pos, std::move(x), std::move(y));
}
DSLExpression Equal(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("equal", std::move(x), std::move(y)), pos);
return DSLCore::Call("equal", pos, std::move(x), std::move(y));
}
DSLExpression Exp(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("exp", std::move(x)), pos);
return DSLCore::Call("exp", pos, std::move(x));
}
DSLExpression Exp2(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("exp2", std::move(x)), pos);
return DSLCore::Call("exp2", pos, std::move(x));
}
DSLExpression Faceforward(DSLExpression n, DSLExpression i, DSLExpression nref, Position pos) {
return DSLExpression(DSLCore::Call("faceforward", std::move(n), std::move(i), std::move(nref)),
pos);
return DSLCore::Call("faceforward", pos, std::move(n), std::move(i), std::move(nref));
}
DSLExpression Fract(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("fract", std::move(x)), pos);
return DSLCore::Call("fract", pos, std::move(x));
}
DSLExpression Floor(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("floor", std::move(x)), pos);
return DSLCore::Call("floor", pos, std::move(x));
}
DSLExpression GreaterThan(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("greaterThan", std::move(x), std::move(y)), pos);
return DSLCore::Call("greaterThan", pos, std::move(x), std::move(y));
}
DSLExpression GreaterThanEqual(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("greaterThanEqual", std::move(x), std::move(y)), pos);
return DSLCore::Call("greaterThanEqual", pos, std::move(x), std::move(y));
}
DSLExpression Inverse(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("inverse", std::move(x)), pos);
return DSLCore::Call("inverse", pos, std::move(x));
}
DSLExpression Inversesqrt(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("inversesqrt", std::move(x)), pos);
return DSLCore::Call("inversesqrt", pos, std::move(x));
}
DSLExpression Length(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("length", std::move(x)), pos);
return DSLCore::Call("length", pos, std::move(x));
}
DSLExpression LessThan(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("lessThan", std::move(x), std::move(y)), pos);
return DSLCore::Call("lessThan", pos, std::move(x), std::move(y));
}
DSLExpression LessThanEqual(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("lessThanEqual", std::move(x), std::move(y)), pos);
return DSLCore::Call("lessThanEqual", pos, std::move(x), std::move(y));
}
DSLExpression Log(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("log", std::move(x)), pos);
return DSLCore::Call("log", pos, std::move(x));
}
DSLExpression Log2(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("log2", std::move(x)), pos);
return DSLCore::Call("log2", pos, std::move(x));
}
DSLExpression Max(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("max", std::move(x), std::move(y)), pos);
return DSLCore::Call("max", pos, std::move(x), std::move(y));
}
DSLExpression Min(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("min", std::move(x), std::move(y)), pos);
return DSLCore::Call("min", pos, std::move(x), std::move(y));
}
DSLExpression Mix(DSLExpression x, DSLExpression y, DSLExpression a, Position pos) {
return DSLExpression(DSLCore::Call("mix", std::move(x), std::move(y), std::move(a)), pos);
return DSLCore::Call("mix", pos, std::move(x), std::move(y), std::move(a));
}
DSLExpression Mod(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("mod", std::move(x), std::move(y)), pos);
return DSLCore::Call("mod", pos, std::move(x), std::move(y));
}
DSLExpression Normalize(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("normalize", std::move(x)), pos);
return DSLCore::Call("normalize", pos, std::move(x));
}
DSLExpression NotEqual(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("notEqual", std::move(x), std::move(y)), pos);
return DSLCore::Call("notEqual", pos, std::move(x), std::move(y));
}
DSLExpression Pow(DSLExpression x, DSLExpression y, Position pos) {
return DSLExpression(DSLCore::Call("pow", std::move(x), std::move(y)), pos);
return DSLCore::Call("pow", pos, std::move(x), std::move(y));
}
DSLExpression Radians(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("radians", std::move(x)), pos);
return DSLCore::Call("radians", pos, std::move(x));
}
DSLExpression Reflect(DSLExpression i, DSLExpression n, Position pos) {
return DSLExpression(DSLCore::Call("reflect", std::move(i), std::move(n)), pos);
return DSLCore::Call("reflect", pos, std::move(i), std::move(n));
}
DSLExpression Refract(DSLExpression i, DSLExpression n, DSLExpression eta, Position pos) {
return DSLExpression(DSLCore::Call("refract", std::move(i), std::move(n), std::move(eta)), pos);
return DSLCore::Call("refract", pos, std::move(i), std::move(n), std::move(eta));
}
DSLExpression Round(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("round", std::move(x)), pos);
return DSLCore::Call("round", pos, std::move(x));
}
DSLExpression Saturate(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("saturate", std::move(x)), pos);
return DSLCore::Call("saturate", pos, std::move(x));
}
DSLExpression Sign(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("sign", std::move(x)), pos);
return DSLCore::Call("sign", pos, std::move(x));
}
DSLExpression Sin(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("sin", std::move(x)), pos);
return DSLCore::Call("sin", pos, std::move(x));
}
DSLExpression Smoothstep(DSLExpression edge1, DSLExpression edge2, DSLExpression x,
Position pos) {
return DSLExpression(DSLCore::Call("smoothstep", std::move(edge1), std::move(edge2),
std::move(x)),
pos);
return DSLCore::Call("smoothstep", pos, std::move(edge1), std::move(edge2), std::move(x));
}
DSLExpression Sqrt(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("sqrt", std::move(x)), pos);
return DSLCore::Call("sqrt", pos, std::move(x));
}
DSLExpression Step(DSLExpression edge, DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("step", std::move(edge), std::move(x)), pos);
return DSLCore::Call("step", pos, std::move(edge), std::move(x));
}
DSLExpression Swizzle(DSLExpression base, SkSL::SwizzleComponent::Type a,
@ -716,11 +713,11 @@ DSLExpression Swizzle(DSLExpression base,
}
DSLExpression Tan(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("tan", std::move(x)), pos);
return DSLCore::Call("tan", pos, std::move(x));
}
DSLExpression Unpremul(DSLExpression x, Position pos) {
return DSLExpression(DSLCore::Call("unpremul", std::move(x)), pos);
return DSLCore::Call("unpremul", pos, std::move(x));
}
} // namespace dsl

View File

@ -38,18 +38,16 @@ DSLExpression::DSLExpression() {}
DSLExpression::DSLExpression(DSLExpression&& other)
: fExpression(std::move(other.fExpression)) {}
DSLExpression::DSLExpression(std::unique_ptr<SkSL::Expression> expression)
: fExpression(std::move(expression)) {
SkASSERT(this->hasValue());
}
DSLExpression::DSLExpression(std::unique_ptr<SkSL::Expression> expression, Position pos)
: fExpression(expression ? std::move(expression)
: SkSL::Poison::Make(pos, ThreadContext::Context())) {
ThreadContext::ReportErrors(pos);
SkASSERTF(this->position() == pos, "expected expression position (%d-%d), but received (%d-%d)",
pos.startOffset(), pos.endOffset(), this->position().startOffset(),
this->position().endOffset());
// If a position was passed in, it must match the expression's position.
SkASSERTF(!pos.valid() || this->position() == pos,
"expected expression position (%d-%d), but received (%d-%d)",
pos.startOffset(), pos.endOffset(),
this->position().startOffset(), this->position().endOffset());
}
DSLExpression::DSLExpression(float value, Position pos)
@ -85,32 +83,19 @@ DSLExpression::DSLExpression(bool value, Position pos)
pos,
value)) {}
DSLExpression::DSLExpression(DSLVarBase& var, Position pos) {
fExpression = std::make_unique<SkSL::VariableReference>(pos, DSLWriter::Var(var),
SkSL::VariableReference::RefKind::kRead);
}
DSLExpression::DSLExpression(DSLVarBase& var, Position pos)
: fExpression(std::make_unique<SkSL::VariableReference>(
pos, DSLWriter::Var(var), SkSL::VariableReference::RefKind::kRead)) {}
DSLExpression::DSLExpression(DSLVarBase&& var, Position pos)
: DSLExpression(var) {}
DSLExpression::DSLExpression(DSLPossibleExpression expr, Position pos) {
ThreadContext::ReportErrors(pos);
if (expr.valid()) {
fExpression = std::move(expr.fExpression);
if (!this->position().valid()) {
fExpression->fPosition = pos;
}
} else {
fExpression = SkSL::Poison::Make(pos, ThreadContext::Context());
}
}
DSLExpression::~DSLExpression() {}
DSLExpression DSLExpression::Poison(Position pos) {
return DSLExpression(SkSL::Poison::Make(pos, ThreadContext::Context()));
}
DSLExpression::~DSLExpression() {}
bool DSLExpression::isValid() const {
return this->hasValue() && !fExpression->is<SkSL::Poison>();
}
@ -187,16 +172,17 @@ DSLExpression DSLExpression::field(std::string_view name, Position pos) {
*ThreadContext::SymbolTable(), this->release(), name), pos);
}
DSLPossibleExpression DSLExpression::assign(DSLExpression right) {
DSLExpression DSLExpression::assign(DSLExpression right) {
Position pos = this->position().rangeThrough(right.position());
return BinaryExpression::Convert(ThreadContext::Context(), pos, this->release(),
SkSL::Operator::Kind::EQ, right.release());
return DSLExpression(BinaryExpression::Convert(ThreadContext::Context(), pos, this->release(),
SkSL::Operator::Kind::EQ, right.release()));
}
DSLPossibleExpression DSLExpression::operator[](DSLExpression right) {
DSLExpression DSLExpression::operator[](DSLExpression right) {
Position pos = this->position().rangeThrough(right.position());
return IndexExpression::Convert(ThreadContext::Context(), *ThreadContext::SymbolTable(), pos,
this->release(), right.release());
return DSLExpression(IndexExpression::Convert(ThreadContext::Context(),
*ThreadContext::SymbolTable(), pos,
this->release(), right.release()));
}
DSLExpression DSLExpression::index(DSLExpression index, Position pos) {
@ -205,7 +191,7 @@ DSLExpression DSLExpression::index(DSLExpression index, Position pos) {
return DSLExpression(std::move(result), pos);
}
DSLPossibleExpression DSLExpression::operator()(SkTArray<DSLExpression> args, Position pos) {
DSLExpression DSLExpression::operator()(SkTArray<DSLExpression> args, Position pos) {
ExpressionArray converted;
converted.reserve_back(args.count());
for (DSLExpression& arg : args) {
@ -214,20 +200,20 @@ DSLPossibleExpression DSLExpression::operator()(SkTArray<DSLExpression> args, Po
return (*this)(std::move(converted), pos);
}
DSLPossibleExpression DSLExpression::operator()(ExpressionArray args, Position pos) {
return SkSL::FunctionCall::Convert(ThreadContext::Context(), pos, this->release(),
std::move(args));
DSLExpression DSLExpression::operator()(ExpressionArray args, Position pos) {
return DSLExpression(SkSL::FunctionCall::Convert(ThreadContext::Context(), pos, this->release(),
std::move(args)), pos);
}
DSLExpression DSLExpression::prefix(Operator::Kind op, Position pos) {
std::unique_ptr<SkSL::Expression> result = PrefixExpression::Convert(ThreadContext::Context(),
pos, op, this->release());
pos, op, this->release());
return DSLExpression(std::move(result), pos);
}
DSLExpression DSLExpression::postfix(Operator::Kind op, Position pos) {
std::unique_ptr<SkSL::Expression> result = PostfixExpression::Convert(ThreadContext::Context(),
pos, this->release(), op);
pos, this->release(), op);
return DSLExpression(std::move(result), pos);
}
@ -237,22 +223,29 @@ DSLExpression DSLExpression::binary(Operator::Kind op, DSLExpression right, Posi
return DSLExpression(std::move(result), pos);
}
#define OP(op, token) \
DSLPossibleExpression operator op(DSLExpression left, DSLExpression right) { \
return BinaryExpression::Convert(ThreadContext::Context(), Position(), left.release(), \
Operator::Kind::token, right.release()); \
#define OP(op, token) \
DSLExpression operator op(DSLExpression left, DSLExpression right) { \
return DSLExpression(BinaryExpression::Convert(ThreadContext::Context(), \
Position(), \
left.release(), \
Operator::Kind::token, \
right.release())); \
}
#define PREFIXOP(op, token) \
DSLPossibleExpression operator op(DSLExpression expr) { \
return PrefixExpression::Convert(ThreadContext::Context(), Position(), Operator::Kind::token, \
expr.release()); \
#define PREFIXOP(op, token) \
DSLExpression operator op(DSLExpression expr) { \
return DSLExpression(PrefixExpression::Convert(ThreadContext::Context(), \
Position(), \
Operator::Kind::token, \
expr.release())); \
}
#define POSTFIXOP(op, token) \
DSLPossibleExpression operator op(DSLExpression expr, int) { \
return PostfixExpression::Convert(ThreadContext::Context(), Position(), expr.release(), \
Operator::Kind::token); \
#define POSTFIXOP(op, token) \
DSLExpression operator op(DSLExpression expr, int) { \
return DSLExpression(PostfixExpression::Convert(ThreadContext::Context(), \
Position(), \
expr.release(), \
Operator::Kind::token)); \
}
OP(+, PLUS)
@ -277,9 +270,12 @@ OP(|, BITWISEOR)
OP(|=, BITWISEOREQ)
OP(^, BITWISEXOR)
OP(^=, BITWISEXOREQ)
DSLPossibleExpression LogicalXor(DSLExpression left, DSLExpression right) {
return BinaryExpression::Convert(ThreadContext::Context(), Position(), left.release(),
SkSL::Operator::Kind::LOGICALXOR, right.release());
DSLExpression LogicalXor(DSLExpression left, DSLExpression right) {
return DSLExpression(BinaryExpression::Convert(ThreadContext::Context(),
Position(),
left.release(),
SkSL::Operator::Kind::LOGICALXOR,
right.release()));
}
OP(==, EQEQ)
OP(!=, NEQ)
@ -297,140 +293,12 @@ POSTFIXOP(++, PLUSPLUS)
PREFIXOP(--, MINUSMINUS)
POSTFIXOP(--, MINUSMINUS)
DSLPossibleExpression operator,(DSLExpression left, DSLExpression right) {
return BinaryExpression::Convert(ThreadContext::Context(), Position(), left.release(),
SkSL::Operator::Kind::COMMA, right.release());
}
DSLPossibleExpression operator,(DSLPossibleExpression left, DSLExpression right) {
return BinaryExpression::Convert(ThreadContext::Context(), Position(),
DSLExpression(std::move(left)).release(), SkSL::Operator::Kind::COMMA, right.release());
}
DSLPossibleExpression operator,(DSLExpression left, DSLPossibleExpression right) {
return BinaryExpression::Convert(ThreadContext::Context(), Position(), left.release(),
SkSL::Operator::Kind::COMMA, DSLExpression(std::move(right)).release());
}
DSLPossibleExpression operator,(DSLPossibleExpression left, DSLPossibleExpression right) {
return BinaryExpression::Convert(ThreadContext::Context(), Position(),
DSLExpression(std::move(left)).release(), SkSL::Operator::Kind::COMMA,
DSLExpression(std::move(right)).release());
}
DSLPossibleExpression::DSLPossibleExpression(std::unique_ptr<SkSL::Expression> expr)
: fExpression(std::move(expr)) {}
DSLPossibleExpression::DSLPossibleExpression(DSLPossibleExpression&& other)
: fExpression(std::move(other.fExpression)) {}
DSLPossibleExpression::~DSLPossibleExpression() {}
void DSLPossibleExpression::reportErrors(Position pos) {
SkASSERT(!this->valid());
ThreadContext::ReportErrors(pos);
}
DSLType DSLPossibleExpression::type() const {
if (!this->valid()) {
return kVoid_Type;
}
return &fExpression->type();
}
std::string DSLPossibleExpression::description() const {
SkASSERT(this->valid());
return fExpression->description();
}
Position DSLPossibleExpression::position() const {
SkASSERT(this->valid());
return fExpression->fPosition;
}
DSLExpression DSLPossibleExpression::x(Position pos) {
return DSLExpression(this->release()).x(pos);
}
DSLExpression DSLPossibleExpression::y(Position pos) {
return DSLExpression(this->release()).y(pos);
}
DSLExpression DSLPossibleExpression::z(Position pos) {
return DSLExpression(this->release()).z(pos);
}
DSLExpression DSLPossibleExpression::w(Position pos) {
return DSLExpression(this->release()).w(pos);
}
DSLExpression DSLPossibleExpression::r(Position pos) {
return DSLExpression(this->release()).r(pos);
}
DSLExpression DSLPossibleExpression::g(Position pos) {
return DSLExpression(this->release()).g(pos);
}
DSLExpression DSLPossibleExpression::b(Position pos) {
return DSLExpression(this->release()).b(pos);
}
DSLExpression DSLPossibleExpression::a(Position pos) {
return DSLExpression(this->release()).a(pos);
}
DSLExpression DSLPossibleExpression::field(std::string_view name, Position pos) {
return DSLExpression(this->release()).field(name, pos);
}
DSLPossibleExpression DSLPossibleExpression::assign(DSLExpression expr) {
return DSLExpression(this->release()).assign(std::move(expr));
}
DSLPossibleExpression DSLPossibleExpression::assign(int expr) {
return this->assign(DSLExpression(expr));
}
DSLPossibleExpression DSLPossibleExpression::assign(float expr) {
return this->assign(DSLExpression(expr));
}
DSLPossibleExpression DSLPossibleExpression::assign(double expr) {
return this->assign(DSLExpression(expr));
}
DSLPossibleExpression DSLPossibleExpression::operator[](DSLExpression index) {
return DSLExpression(this->release())[std::move(index)];
}
DSLPossibleExpression DSLPossibleExpression::operator()(SkTArray<DSLExpression> args,
Position pos) {
return DSLExpression(this->release())(std::move(args), pos);
}
DSLPossibleExpression DSLPossibleExpression::operator()(ExpressionArray args, Position pos) {
return DSLExpression(this->release())(std::move(args), pos);
}
DSLPossibleExpression DSLPossibleExpression::operator++() {
return ++DSLExpression(this->release());
}
DSLPossibleExpression DSLPossibleExpression::operator++(int) {
return DSLExpression(this->release())++;
}
DSLPossibleExpression DSLPossibleExpression::operator--() {
return --DSLExpression(this->release());
}
DSLPossibleExpression DSLPossibleExpression::operator--(int) {
return DSLExpression(this->release())--;
}
std::unique_ptr<SkSL::Expression> DSLPossibleExpression::release(Position pos) {
return DSLExpression(std::move(*this), pos).release();
DSLExpression operator,(DSLExpression left, DSLExpression right) {
return DSLExpression(BinaryExpression::Convert(ThreadContext::Context(),
Position(),
left.release(),
SkSL::Operator::Kind::COMMA,
right.release()));
}
} // namespace dsl

View File

@ -44,9 +44,6 @@ DSLStatement::DSLStatement(std::unique_ptr<SkSL::Statement> stmt)
SkASSERT(this->hasValue());
}
DSLStatement::DSLStatement(DSLPossibleExpression expr, Position pos)
: DSLStatement(DSLExpression(std::move(expr), pos)) {}
DSLStatement::DSLStatement(DSLPossibleStatement stmt, Position pos) {
ThreadContext::ReportErrors(pos);
if (stmt.hasValue()) {

View File

@ -259,18 +259,18 @@ const SkSL::Type& DSLType::skslType() const {
Position());
}
DSLPossibleExpression DSLType::Construct(DSLType type, SkSpan<DSLExpression> argArray) {
DSLExpression DSLType::Construct(DSLType type, SkSpan<DSLExpression> argArray) {
SkSL::ExpressionArray skslArgs;
skslArgs.reserve_back(argArray.size());
for (DSLExpression& arg : argArray) {
if (!arg.hasValue()) {
return DSLPossibleExpression(nullptr);
return DSLExpression();
}
skslArgs.push_back(arg.release());
}
return SkSL::Constructor::Convert(ThreadContext::Context(), Position(), type.skslType(),
std::move(skslArgs));
return DSLExpression(SkSL::Constructor::Convert(ThreadContext::Context(), Position(),
type.skslType(), std::move(skslArgs)));
}
DSLType Array(const DSLType& base, int count, Position pos) {

View File

@ -61,14 +61,14 @@ void DSLVarBase::swap(DSLVarBase& other) {
std::swap(fPosition, other.fPosition);
}
DSLPossibleExpression DSLVarBase::operator[](DSLExpression&& index) {
return DSLExpression(*this, Position())[std::move(index)];
DSLExpression DSLVarBase::operator[](DSLExpression&& index) {
return DSLExpression(*this)[std::move(index)];
}
DSLPossibleExpression DSLVarBase::assignExpression(DSLExpression expr) {
return BinaryExpression::Convert(ThreadContext::Context(), Position(),
DSLExpression DSLVarBase::assignExpression(DSLExpression expr) {
return DSLExpression(BinaryExpression::Convert(ThreadContext::Context(), Position(),
DSLExpression(*this, Position()).release(), SkSL::Operator::Kind::EQ,
expr.release());
expr.release()));
}
/**

View File

@ -149,7 +149,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(DSLPossibleExpression& 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(); }
static std::string stringize(SkSL::Program& program) { return program.description(); }