From 599b673f7f7262c9588ca89d4408499aa9834796 Mon Sep 17 00:00:00 2001 From: Immanuel Haffner Date: Mon, 17 Jul 2023 20:35:08 +0200 Subject: [PATCH] [Wasm] Improve `Decimal` class. - Remove superfluous methods. The once inherited from `Expr` are already what we need. - *Delete* (with `require false`) certain operators and methods that are not supported by `Decimal`, e.g. `rotl` or `neg`. --- src/backend/WasmUtil.hpp | 58 ++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/backend/WasmUtil.hpp b/src/backend/WasmUtil.hpp index 35a36e06..8c039d45 100644 --- a/src/backend/WasmUtil.hpp +++ b/src/backend/WasmUtil.hpp @@ -119,29 +119,17 @@ struct Decimal : Expr Expr to() { return val().template 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 @@ -210,6 +198,42 @@ struct Decimal : Expr requires false Decimal operator%(T&&) { M_unreachable("modulo division on decimals is not defined"); } + /** Bitwise and is not supported by `Decimal` type. */ + template + requires false + Decimal operator bitand(T&&) { M_unreachable("bitwise and on decimals is not defined"); } + + /** Bitwise or is not supported by `Decimal` type. */ + template + 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 + requires false + Decimal operator xor(T&&) { M_unreachable("exclusive or on decimals is not defined"); } + + /** Shift left is not supported by `Decimal` type. */ + template + requires false + Decimal operator<<(T&&) { M_unreachable("shift left on decimals is not defined"); } + + /** Shift right is not supported by `Decimal` type. */ + template + requires false + Decimal operator>>(T&&) { M_unreachable("shift right on decimals is not defined"); } + + /** Shift right is not supported by `Decimal` type. */ + template + requires false + Decimal rotl(T&&) { M_unreachable("rotate left on decimals is not defined"); } + + /** Shift right is not supported by `Decimal` type. */ + template + 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(d) << ", scale = " << d.scale_; }