Skip to content

Commit

Permalink
[Wasm] Improve Decimal class.
Browse files Browse the repository at this point in the history
- Remove superfluous methods.  The once inherited from `Expr<T>` are
  already what we need.
- *Delete* (with `require false`) certain operators and methods that are
  not supported by `Decimal`, e.g. `rotl` or `neg`.
  • Loading branch information
ImmanuelHaffner committed Jul 17, 2023
1 parent 8176c1a commit 599b673
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions src/backend/WasmUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,17 @@ struct Decimal : Expr<Base>
Expr<To> to() { return val().template to<To>() / powi(To(10), To(scale_)); }

Decimal clone() const { return Decimal(expr_type::clone(), scale_); }
bool can_be_null() const { return expr_type::can_be_null(); }
Bool is_null() {
if (can_be_null()) {
return expr_type::is_null();
} else {
expr_type::discard();
return Bool(false);
}
}
Bool not_null() {
if (can_be_null()) {
return expr_type::not_null();
} else {
expr_type::discard();
return Bool(true);
}
}


/*------------------------------------------------------------------------------------------------------------------
* Unary operations
*----------------------------------------------------------------------------------------------------------------*/

/** Bitwise negation is not supported by `Decimal` type. */
Decimal operator~()
requires false
{ M_unreachable("modulo division on decimals is not defined"); }


/*------------------------------------------------------------------------------------------------------------------
* Binary operations
Expand Down Expand Up @@ -210,6 +198,42 @@ struct Decimal : Expr<Base>
requires false
Decimal operator%(T&&) { M_unreachable("modulo division on decimals is not defined"); }

/** Bitwise and is not supported by `Decimal` type. */
template<typename T>
requires false
Decimal operator bitand(T&&) { M_unreachable("bitwise and on decimals is not defined"); }

/** Bitwise or is not supported by `Decimal` type. */
template<typename T>
requires false
Decimal operator bitor(T&&) { M_unreachable("bitwise or on decimals is not defined"); }

/** Bitwise xor (exclusive or) is not supported by `Decimal` type. */
template<typename T>
requires false
Decimal operator xor(T&&) { M_unreachable("exclusive or on decimals is not defined"); }

/** Shift left is not supported by `Decimal` type. */
template<typename T>
requires false
Decimal operator<<(T&&) { M_unreachable("shift left on decimals is not defined"); }

/** Shift right is not supported by `Decimal` type. */
template<typename T>
requires false
Decimal operator>>(T&&) { M_unreachable("shift right on decimals is not defined"); }

/** Shift right is not supported by `Decimal` type. */
template<typename T>
requires false
Decimal rotl(T&&) { M_unreachable("rotate left on decimals is not defined"); }

/** Shift right is not supported by `Decimal` type. */
template<typename T>
requires false
Decimal rotr(T&&) { M_unreachable("rotate right on decimals is not defined"); }


friend std::ostream & operator<<(std::ostream &out, const Decimal &d) {
return out << "Decimal: " << static_cast<const expr_type&>(d) << ", scale = " << d.scale_;
}
Expand Down

0 comments on commit 599b673

Please sign in to comment.