mirror of
https://github.com/Z3Prover/z3
synced 2025-06-19 04:13:38 +00:00
generate error on duplicated data-type accessors. Issue 85
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
e27b7e3038
commit
a00a9fbdfd
3 changed files with 28 additions and 0 deletions
|
@ -515,6 +515,25 @@ bool pdatatype_decl::has_missing_refs(symbol & missing) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool pdatatype_decl::has_duplicate_accessors(symbol & duplicated) const {
|
||||||
|
hashtable<symbol, symbol_hash_proc, symbol_eq_proc> names;
|
||||||
|
ptr_vector<pconstructor_decl>::const_iterator it = m_constructors.begin();
|
||||||
|
ptr_vector<pconstructor_decl>::const_iterator end = m_constructors.end();
|
||||||
|
for (; it != end; ++it) {
|
||||||
|
ptr_vector<paccessor_decl> const& acc = (*it)->m_accessors;
|
||||||
|
for (unsigned i = 0; i < acc.size(); ++i) {
|
||||||
|
symbol const& name = acc[i]->get_name();
|
||||||
|
if (names.contains(name)) {
|
||||||
|
duplicated = name;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
names.insert(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool pdatatype_decl::fix_missing_refs(dictionary<int> const & symbol2idx, symbol & missing) {
|
bool pdatatype_decl::fix_missing_refs(dictionary<int> const & symbol2idx, symbol & missing) {
|
||||||
ptr_vector<pconstructor_decl>::iterator it = m_constructors.begin();
|
ptr_vector<pconstructor_decl>::iterator it = m_constructors.begin();
|
||||||
ptr_vector<pconstructor_decl>::iterator end = m_constructors.end();
|
ptr_vector<pconstructor_decl>::iterator end = m_constructors.end();
|
||||||
|
|
|
@ -169,6 +169,7 @@ public:
|
||||||
class paccessor_decl : public pdecl {
|
class paccessor_decl : public pdecl {
|
||||||
friend class pdecl_manager;
|
friend class pdecl_manager;
|
||||||
friend class pconstructor_decl;
|
friend class pconstructor_decl;
|
||||||
|
friend class pdatatype_decl;
|
||||||
symbol m_name;
|
symbol m_name;
|
||||||
ptype m_type;
|
ptype m_type;
|
||||||
paccessor_decl(unsigned id, unsigned num_params, pdecl_manager & m, symbol const & n, ptype const & r);
|
paccessor_decl(unsigned id, unsigned num_params, pdecl_manager & m, symbol const & n, ptype const & r);
|
||||||
|
@ -222,6 +223,7 @@ public:
|
||||||
sort * instantiate(pdecl_manager & m, unsigned n, sort * const * s);
|
sort * instantiate(pdecl_manager & m, unsigned n, sort * const * s);
|
||||||
virtual void display(std::ostream & out) const;
|
virtual void display(std::ostream & out) const;
|
||||||
bool has_missing_refs(symbol & missing) const;
|
bool has_missing_refs(symbol & missing) const;
|
||||||
|
bool has_duplicate_accessors(symbol & repeated) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -850,6 +850,13 @@ namespace smt2 {
|
||||||
for (unsigned i = 0; i < sz; i++) {
|
for (unsigned i = 0; i < sz; i++) {
|
||||||
pdatatype_decl * d = new_dt_decls[i];
|
pdatatype_decl * d = new_dt_decls[i];
|
||||||
SASSERT(d != 0);
|
SASSERT(d != 0);
|
||||||
|
symbol duplicated;
|
||||||
|
if (d->has_duplicate_accessors(duplicated)) {
|
||||||
|
std::string err_msg = "invalid datatype declaration, repeated accessor identifier '";
|
||||||
|
err_msg += duplicated.str();
|
||||||
|
err_msg += "'";
|
||||||
|
throw parser_exception(err_msg, line, pos);
|
||||||
|
}
|
||||||
m_ctx.insert(d);
|
m_ctx.insert(d);
|
||||||
if (d->get_num_params() == 0) {
|
if (d->get_num_params() == 0) {
|
||||||
// if datatype is not parametric... then force instantiation to register accessor, recognizers and constructors...
|
// if datatype is not parametric... then force instantiation to register accessor, recognizers and constructors...
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue