An enumeration cannot have duplicate values.
Add code to check that an enumeration does not have duplicate values.
This commit is contained in:
parent
be1be31deb
commit
3b6e26aa90
|
|
@ -213,6 +213,16 @@ static void elaborate_scope_enumeration(Design*des, NetScope*scope,
|
|||
des->errors += 1;
|
||||
}
|
||||
|
||||
// The enumeration value must be unique.
|
||||
perm_string dup_name = use_enum->find_value(cur_value);
|
||||
if (dup_name) {
|
||||
cerr << use_enum->get_fileline()
|
||||
<< ": error: Enumeration name "
|
||||
<< cur->name << " and " << dup_name
|
||||
<< " have the same value: " << cur_value << endl;
|
||||
des->errors += 1;
|
||||
}
|
||||
|
||||
// The values are explicitly sized to the width of the
|
||||
// base type of the enumeration.
|
||||
verinum tmp_val (0);
|
||||
|
|
|
|||
16
netenum.cc
16
netenum.cc
|
|
@ -55,6 +55,22 @@ netenum_t::iterator netenum_t::find_name(perm_string name) const
|
|||
return names_map_.find(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to see if the given value is already in the enumeration mapping.
|
||||
*/
|
||||
perm_string netenum_t::find_value(const verinum&val) const
|
||||
{
|
||||
perm_string res;
|
||||
for(netenum_t::iterator cur = names_map_.begin();
|
||||
cur != names_map_.end(); cur++) {
|
||||
if (cur->second == val) {
|
||||
res = cur->first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
netenum_t::iterator netenum_t::end_name() const
|
||||
{
|
||||
return names_map_.end();
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ class netenum_t : public LineInfo {
|
|||
typedef std::map<perm_string,verinum>::const_iterator iterator;
|
||||
iterator find_name(perm_string name) const;
|
||||
iterator end_name() const;
|
||||
perm_string find_value(const verinum&val) const;
|
||||
|
||||
// These methods roughly match the .first() and .last() methods.
|
||||
iterator first_name() const;
|
||||
|
|
|
|||
Loading…
Reference in New Issue