mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-09 21:47:47 +00:00
Validate binary operations
This change validates that the operand types and result type of every binary operation is valid. * Added two unit tests which test all valid and invalid param combos. I also removed the old tests, many of which failed once I added this validation, and the rest are obviated by the new tests. * Fixed VertexPulling transform, as well as many tests, that were using invalid operand types for binary operations. Fixed: tint:354 Change-Id: Ia3f48384256993da61b341f17ba5583741011819 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44341 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
1691401179
commit
be0fc4e929
@@ -23,11 +23,11 @@ namespace ast {
|
||||
/// The operator type
|
||||
enum class BinaryOp {
|
||||
kNone = 0,
|
||||
kAnd,
|
||||
kOr,
|
||||
kAnd, // &
|
||||
kOr, // |
|
||||
kXor,
|
||||
kLogicalAnd,
|
||||
kLogicalOr,
|
||||
kLogicalAnd, // &&
|
||||
kLogicalOr, // ||
|
||||
kEqual,
|
||||
kNotEqual,
|
||||
kLessThan,
|
||||
@@ -98,6 +98,14 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
|
||||
bool IsDivide() const { return op_ == BinaryOp::kDivide; }
|
||||
/// @returns true if the op is modulo
|
||||
bool IsModulo() const { return op_ == BinaryOp::kModulo; }
|
||||
/// @returns true if the op is an arithmetic operation
|
||||
bool IsArithmetic() const;
|
||||
/// @returns true if the op is a comparison operation
|
||||
bool IsComparison() const;
|
||||
/// @returns true if the op is a bitwise operation
|
||||
bool IsBitwise() const;
|
||||
/// @returns true if the op is a bit shift operation
|
||||
bool IsBitshift() const;
|
||||
|
||||
/// @returns the left side expression
|
||||
Expression* lhs() const { return lhs_; }
|
||||
@@ -126,6 +134,54 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
|
||||
Expression* const rhs_;
|
||||
};
|
||||
|
||||
inline bool BinaryExpression::IsArithmetic() const {
|
||||
switch (op_) {
|
||||
case ast::BinaryOp::kAdd:
|
||||
case ast::BinaryOp::kSubtract:
|
||||
case ast::BinaryOp::kMultiply:
|
||||
case ast::BinaryOp::kDivide:
|
||||
case ast::BinaryOp::kModulo:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool BinaryExpression::IsComparison() const {
|
||||
switch (op_) {
|
||||
case ast::BinaryOp::kEqual:
|
||||
case ast::BinaryOp::kNotEqual:
|
||||
case ast::BinaryOp::kLessThan:
|
||||
case ast::BinaryOp::kLessThanEqual:
|
||||
case ast::BinaryOp::kGreaterThan:
|
||||
case ast::BinaryOp::kGreaterThanEqual:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool BinaryExpression::IsBitwise() const {
|
||||
switch (op_) {
|
||||
case ast::BinaryOp::kAnd:
|
||||
case ast::BinaryOp::kOr:
|
||||
case ast::BinaryOp::kXor:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool BinaryExpression::IsBitshift() const {
|
||||
switch (op_) {
|
||||
case ast::BinaryOp::kShiftLeft:
|
||||
case ast::BinaryOp::kShiftRight:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, BinaryOp op) {
|
||||
switch (op) {
|
||||
case BinaryOp::kNone:
|
||||
|
||||
Reference in New Issue
Block a user