From 6f0d3ae3323f6bf9c8f67462402db7e743a0f9d5 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 19 Mar 2022 14:46:18 +0100 Subject: [PATCH] ivl_type_s: Add get_scalar() method Currently only the netvector_t type implements the get_scalar() method. To check whether a type is scalar it is first cast to netvector_t and then the method is called. But there are other types, such as areal that can also be scalar. To support indicating that a real type is scalar add a virtual get_scalar() method to ivl_type_s, which is the base class for all types. Signed-off-by: Lars-Peter Clausen --- netlist.cc | 6 ++---- nettypes.cc | 5 +++++ nettypes.h | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/netlist.cc b/netlist.cc index a4b05c413..a96728765 100644 --- a/netlist.cc +++ b/netlist.cc @@ -715,10 +715,8 @@ bool NetNet::get_signed() const bool NetNet::get_scalar() const { - if (const netvector_t*vec = dynamic_cast (net_type_)) - return vec->get_scalar(); - else - return false; + ivl_assert(*this, net_type_); + return net_type_->get_scalar(); } const netenum_t*NetNet::enumeration(void) const diff --git a/nettypes.cc b/nettypes.cc index 23360fcee..d669bd9fe 100644 --- a/nettypes.cc +++ b/nettypes.cc @@ -56,6 +56,11 @@ bool ivl_type_s::get_signed() const return false; } +bool ivl_type_s::get_scalar() const +{ + return false; +} + bool ivl_type_s::type_compatible(ivl_type_t that) const { if (this == that) diff --git a/nettypes.h b/nettypes.h index 48ce48fd2..0c26678dc 100644 --- a/nettypes.h +++ b/nettypes.h @@ -45,6 +45,7 @@ class ivl_type_s { // those specific types. virtual ivl_variable_type_t base_type() const; virtual bool get_signed() const; + virtual bool get_scalar() const; // Return true if "that" type is compatible with this // type. Compatible means the types are essentially the same.