2021-01-07 15:57:27 +00:00
|
|
|
/*
|
|
|
|
* 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/core/SkTypes.h"
|
|
|
|
#include "src/sksl/ir/SkSLIRNode.h"
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
class Expression;
|
|
|
|
|
|
|
|
namespace dsl {
|
|
|
|
|
|
|
|
class DSLExpression;
|
2021-01-11 20:42:44 +00:00
|
|
|
class DSLVar;
|
2021-01-07 15:57:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents an expression such as 'cos(x)' or 'a + b'.
|
|
|
|
*/
|
|
|
|
class DSLExpression {
|
|
|
|
public:
|
|
|
|
DSLExpression(const DSLExpression&) = delete;
|
|
|
|
|
|
|
|
DSLExpression(DSLExpression&&) = default;
|
|
|
|
|
|
|
|
DSLExpression();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an expression representing a literal float.
|
|
|
|
*/
|
|
|
|
DSLExpression(float value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an expression representing a literal float.
|
|
|
|
*/
|
|
|
|
DSLExpression(double value)
|
|
|
|
: DSLExpression((float) value) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an expression representing a literal int.
|
|
|
|
*/
|
|
|
|
DSLExpression(int value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an expression representing a literal bool.
|
|
|
|
*/
|
|
|
|
DSLExpression(bool value);
|
|
|
|
|
2021-01-11 20:42:44 +00:00
|
|
|
/**
|
|
|
|
* Creates an expression representing a variable reference.
|
|
|
|
*/
|
|
|
|
DSLExpression(const DSLVar& var);
|
|
|
|
|
2021-01-07 15:57:27 +00:00
|
|
|
~DSLExpression();
|
|
|
|
|
2021-01-13 15:38:59 +00:00
|
|
|
/**
|
|
|
|
* Overloads the '=' operator to create an SkSL assignment statement.
|
|
|
|
*/
|
|
|
|
DSLExpression operator=(DSLExpression other);
|
|
|
|
|
2021-01-07 15:57:27 +00:00
|
|
|
/**
|
|
|
|
* Invalidates this object and returns the SkSL expression it represents.
|
|
|
|
*/
|
|
|
|
std::unique_ptr<SkSL::Expression> release();
|
|
|
|
|
|
|
|
private:
|
|
|
|
DSLExpression(std::unique_ptr<SkSL::Expression> expression);
|
|
|
|
|
2021-01-13 15:38:59 +00:00
|
|
|
/**
|
|
|
|
* Invalidates this object and returns the SkSL expression it represents coerced to the
|
|
|
|
* specified type. If the expression cannot be coerced, reports an error and returns null.
|
|
|
|
*/
|
|
|
|
std::unique_ptr<SkSL::Expression> coerceAndRelease(const SkSL::Type& type);
|
|
|
|
|
2021-01-07 15:57:27 +00:00
|
|
|
std::unique_ptr<SkSL::Expression> fExpression;
|
|
|
|
|
2021-01-22 20:18:25 +00:00
|
|
|
friend class DSLCore;
|
2021-01-13 15:38:59 +00:00
|
|
|
friend class DSLVar;
|
2021-01-07 15:57:27 +00:00
|
|
|
friend class DSLWriter;
|
|
|
|
};
|
|
|
|
|
2021-01-13 15:38:59 +00:00
|
|
|
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 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 expr);
|
|
|
|
DSLExpression operator~(DSLExpression expr);
|
|
|
|
DSLExpression operator++(DSLExpression expr);
|
|
|
|
DSLExpression operator++(DSLExpression expr, int);
|
|
|
|
DSLExpression operator--(DSLExpression expr);
|
|
|
|
DSLExpression operator--(DSLExpression expr, int);
|
|
|
|
|
2021-01-07 15:57:27 +00:00
|
|
|
} // namespace dsl
|
|
|
|
|
|
|
|
} // namespace SkSL
|
|
|
|
|
|
|
|
#endif
|