Provide default implementation of NetExpr::enumeration()

The current NetExpr::enumeration() always returns a nullptr.
The NetExpr class has a ivl_type_t member that represents
the type of the expression.

Provide a default implementation of NetExpr::enumeration() that
casts this type to the netenum_t type. This will allow
to share this implementation between subclasses and remove
a bit of duplicated code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-03-26 11:45:51 +01:00
parent 0ac3997142
commit 05d5c9b35f
2 changed files with 3 additions and 11 deletions

View File

@ -72,7 +72,7 @@ ivl_variable_type_t NetExpr::expr_type() const
const netenum_t*NetExpr::enumeration() const
{
return 0;
return dynamic_cast<const netenum_t*>(net_type_);
}
NetEArrayPattern::NetEArrayPattern(ivl_type_t lv_type, vector<NetExpr*>&items)
@ -464,15 +464,14 @@ const netenum_t* NetESelect::enumeration() const
NetESFunc::NetESFunc(const char*n, ivl_variable_type_t t,
unsigned width, unsigned np, bool is_overridden)
: name_(0), type_(t), enum_type_(0), parms_(np), is_overridden_(is_overridden)
: name_(0), type_(t), parms_(np), is_overridden_(is_overridden)
{
name_ = lex_strings.add(n);
expr_width(width);
}
NetESFunc::NetESFunc(const char*n, ivl_type_t rtype, unsigned np)
: NetExpr(rtype), name_(0), type_(rtype->base_type()),
enum_type_(dynamic_cast<const netenum_t*>(rtype)), parms_(np),
: NetExpr(rtype), name_(0), type_(rtype->base_type()), parms_(np),
is_overridden_(false)
{
name_ = lex_strings.add(n);
@ -523,11 +522,6 @@ ivl_variable_type_t NetESFunc::expr_type() const
return type_;
}
const netenum_t* NetESFunc::enumeration() const
{
return enum_type_;
}
NetEShallowCopy::NetEShallowCopy(NetExpr*arg1, NetExpr*arg2)
: arg1_(arg1), arg2_(arg2)
{

View File

@ -4663,7 +4663,6 @@ class NetESFunc : public NetExpr {
virtual ivl_variable_type_t expr_type() const;
virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
bool nested_func = false) const;
virtual const netenum_t* enumeration() const;
virtual void dump(std::ostream&) const;
virtual void expr_scan(struct expr_scan_t*) const;
@ -4739,7 +4738,6 @@ class NetESFunc : public NetExpr {
const char* name_;
ivl_variable_type_t type_;
const netenum_t*enum_type_;
std::vector<NetExpr*>parms_;
bool is_overridden_;