| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#ifndef SKSL_EXPRESSION |
| 9 |
#define SKSL_EXPRESSION |
| 10 |
|
| 11 |
#include "include/core/SkTypes.h" |
| 12 |
#include "src/sksl/SkSLPosition.h" |
| 13 |
#include "src/sksl/ir/SkSLIRNode.h" |
| 14 |
#include "src/sksl/ir/SkSLType.h" |
| 15 |
|
| 16 |
#include <cstdint> |
| 17 |
#include <memory> |
| 18 |
#include <optional> |
| 19 |
#include <string> |
| 20 |
|
| 21 |
namespace SkSL { |
| 22 |
|
| 23 |
class AnyConstructor; |
| 24 |
class Context; |
| 25 |
enum class OperatorPrecedence : uint8_t; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
class Expression : public IRNode { |
| 31 |
public: |
| 32 |
using Kind = ExpressionKind; |
| 33 |
|
| 34 |
Expression(Position pos, Kind kind, const Type* type) |
| 35 |
: INHERITED(pos, (int) kind) |
| 36 |
, fType(type) { |
| 37 |
SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); |
| 38 |
} |
| 39 |
|
| 40 |
Kind kind() const { |
| 41 |
return (Kind)fKind; |
| 42 |
} |
| 43 |
|
| 44 |
const Type& type() const { |
| 45 |
return *fType; |
| 46 |
} |
| 47 |
|
| 48 |
bool isAnyConstructor() const { |
| 49 |
static_assert((int)Kind::kConstructorArray - 1 == (int)Kind::kChildCall); |
| 50 |
static_assert((int)Kind::kConstructorStruct + 1 == (int)Kind::kEmpty); |
| 51 |
return this->kind() >= Kind::kConstructorArray && this->kind() <= Kind::kConstructorStruct; |
| 52 |
} |
| 53 |
|
| 54 |
bool isIntLiteral() const { |
| 55 |
return this->kind() == Kind::kLiteral && this->type().isInteger(); |
| 56 |
} |
| 57 |
|
| 58 |
bool isFloatLiteral() const { |
| 59 |
return this->kind() == Kind::kLiteral && this->type().isFloat(); |
| 60 |
} |
| 61 |
|
| 62 |
bool isBoolLiteral() const { |
| 63 |
return this->kind() == Kind::kLiteral && this->type().isBoolean(); |
| 64 |
} |
| 65 |
|
| 66 |
AnyConstructor& asAnyConstructor(); |
| 67 |
const AnyConstructor& asAnyConstructor() const; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
bool isIncomplete(const Context& context) const; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
enum class ComparisonResult { |
| 82 |
kUnknown = -1, |
| 83 |
kNotEqual, |
| 84 |
kEqual |
| 85 |
}; |
| 86 |
virtual ComparisonResult compareConstant(const Expression& other) const { |
| 87 |
return ComparisonResult::kUnknown; |
| 88 |
} |
| 89 |
|
| 90 |
CoercionCost coercionCost(const Type& target) const { |
| 91 |
return this->type().coercionCost(target); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
virtual bool supportsConstantValues() const { |
| 104 |
return false; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
virtual std::optional<double> getConstantValue(int n) const { |
| 117 |
SkASSERT(!this->supportsConstantValues()); |
| 118 |
return std::nullopt; |
| 119 |
} |
| 120 |
|
| 121 |
virtual std::unique_ptr<Expression> clone(Position pos) const = 0; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
std::unique_ptr<Expression> clone() const { return this->clone(fPosition); } |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
std::string description() const final; |
| 132 |
virtual std::string description(OperatorPrecedence parentPrecedence) const = 0; |
| 133 |
|
| 134 |
|
| 135 |
private: |
| 136 |
const Type* fType; |
| 137 |
|
| 138 |
using INHERITED = IRNode; |
| 139 |
}; |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
#endif |