c6218799a6
This reverts commit193c16380f
. Reason for revert: fixed google3 warning Original change's description: > Revert "Eliminate DSLPossibleExpression." > > This reverts commitf2d000328f
. > > 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>
238 lines
7.0 KiB
C++
238 lines
7.0 KiB
C++
/*
|
|
* Copyright 2020 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_EXPRESSION
|
|
#define SKSL_DSL_EXPRESSION
|
|
|
|
#include "include/private/SkTArray.h"
|
|
#include "include/sksl/SkSLOperator.h"
|
|
#include "include/sksl/SkSLPosition.h"
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
#if defined(__has_cpp_attribute) && __has_cpp_attribute(clang::reinitializes)
|
|
#define SK_CLANG_REINITIALIZES [[clang::reinitializes]]
|
|
#else
|
|
#define SK_CLANG_REINITIALIZES
|
|
#endif
|
|
|
|
namespace SkSL {
|
|
|
|
class Expression;
|
|
class ExpressionArray;
|
|
|
|
namespace dsl {
|
|
|
|
class DSLType;
|
|
class DSLVarBase;
|
|
|
|
/**
|
|
* Represents an expression such as 'cos(x)' or 'a + b'.
|
|
*/
|
|
class DSLExpression {
|
|
public:
|
|
DSLExpression(const DSLExpression&) = delete;
|
|
|
|
DSLExpression(DSLExpression&&);
|
|
|
|
DSLExpression();
|
|
|
|
/**
|
|
* Creates an expression representing a literal float.
|
|
*/
|
|
DSLExpression(float value, Position pos = {});
|
|
|
|
/**
|
|
* Creates an expression representing a literal float.
|
|
*/
|
|
DSLExpression(double value, Position pos = {})
|
|
: DSLExpression((float) value) {}
|
|
|
|
/**
|
|
* Creates an expression representing a literal int.
|
|
*/
|
|
DSLExpression(int value, Position pos = {});
|
|
|
|
/**
|
|
* Creates an expression representing a literal int.
|
|
*/
|
|
DSLExpression(int64_t value, Position pos = {});
|
|
|
|
/**
|
|
* Creates an expression representing a literal uint.
|
|
*/
|
|
DSLExpression(unsigned int value, Position pos = {});
|
|
|
|
/**
|
|
* Creates an expression representing a literal bool.
|
|
*/
|
|
DSLExpression(bool value, Position pos = {});
|
|
|
|
/**
|
|
* Creates an expression representing a variable reference.
|
|
*/
|
|
DSLExpression(DSLVarBase& var, Position pos = {});
|
|
|
|
DSLExpression(DSLVarBase&& var, Position pos = {});
|
|
|
|
// If expression is null, returns Poison
|
|
explicit DSLExpression(std::unique_ptr<SkSL::Expression> expression, Position pos = {});
|
|
|
|
static DSLExpression Poison(Position pos = {});
|
|
|
|
~DSLExpression();
|
|
|
|
DSLType type() const;
|
|
|
|
std::string description() const;
|
|
|
|
Position position() const;
|
|
|
|
void setPosition(Position pos);
|
|
|
|
/**
|
|
* Performs assignment, like the '=' operator.
|
|
*/
|
|
DSLExpression assign(DSLExpression other);
|
|
|
|
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 = {});
|
|
|
|
/**
|
|
* Creates an SkSL struct field access expression.
|
|
*/
|
|
DSLExpression field(std::string_view name, Position pos = {});
|
|
|
|
/**
|
|
* Creates an SkSL array index expression.
|
|
*/
|
|
DSLExpression operator[](DSLExpression index);
|
|
|
|
DSLExpression operator()(SkTArray<DSLExpression> args, Position pos = {});
|
|
|
|
DSLExpression operator()(ExpressionArray args, Position pos = {});
|
|
|
|
/**
|
|
* Invokes a prefix operator.
|
|
*/
|
|
DSLExpression prefix(Operator::Kind op, Position pos);
|
|
|
|
/**
|
|
* Invokes a postfix operator.
|
|
*/
|
|
DSLExpression postfix(Operator::Kind op, Position pos);
|
|
|
|
/**
|
|
* Invokes a binary operator.
|
|
*/
|
|
DSLExpression binary(Operator::Kind op, DSLExpression right, Position pos);
|
|
|
|
/**
|
|
* Equivalent to operator[].
|
|
*/
|
|
DSLExpression index(DSLExpression index, Position pos);
|
|
|
|
/**
|
|
* Returns true if this object contains an expression. DSLExpressions which were created with
|
|
* the empty constructor or which have already been release()ed do not have a value.
|
|
* DSLExpressions created with errors are still considered to have a value (but contain poison).
|
|
*/
|
|
bool hasValue() const {
|
|
return fExpression != nullptr;
|
|
}
|
|
|
|
/**
|
|
* Returns true if this object contains an expression which is not poison.
|
|
*/
|
|
bool isValid() const;
|
|
|
|
SK_CLANG_REINITIALIZES void swap(DSLExpression& other);
|
|
|
|
/**
|
|
* Invalidates this object and returns the SkSL expression it represents. It is an error to call
|
|
* this on an invalid DSLExpression.
|
|
*/
|
|
std::unique_ptr<SkSL::Expression> release();
|
|
|
|
private:
|
|
/**
|
|
* Calls release if this expression has a value, otherwise returns null.
|
|
*/
|
|
std::unique_ptr<SkSL::Expression> releaseIfPossible();
|
|
|
|
std::unique_ptr<SkSL::Expression> fExpression;
|
|
|
|
friend DSLExpression SampleChild(int index, DSLExpression coords);
|
|
|
|
friend class DSLCore;
|
|
friend class DSLFunction;
|
|
friend class DSLType;
|
|
friend class DSLVarBase;
|
|
friend class DSLWriter;
|
|
};
|
|
|
|
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
|
|
|
|
} // namespace SkSL
|
|
|
|
#endif
|