An enumeration cannot have duplicate values.

Add code to check that an enumeration does not have duplicate values.
This commit is contained in:
Cary R 2011-09-29 19:34:23 -07:00 committed by Stephen Williams
parent be1be31deb
commit 3b6e26aa90
4 changed files with 28 additions and 1 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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;

View File

@ -117,7 +117,7 @@ static list<PExpr*>* make_range_from_width(uint64_t wid)
}
/*
* Make a rqange vector from an existing pair of expressions.
* Make a range vector from an existing pair of expressions.
*/
static vector<PExpr*>* make_range_vector(list<PExpr*>*that)
{