Skip to content

Commit 318ab86

Browse files
committed
Improve class_typet's base description
This defines an exprt subclass representing a base class instead of using a bare exprt, and enforces proper types when returning the base list. It's the same shape as the existing exprt so old code doesn't need adjusting, it just makes client code neater.
1 parent 4bebee9 commit 318ab86

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/cegis/cegis-util/type_helper.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ bool instanceof(const typet &lhs, const typet &rhs, const namespacet &ns)
3434
if (type_eq(lhs, rhs, ns)) return true;
3535
assert(ID_class == lhs.id());
3636
const class_typet &lhs_class=to_class_type(lhs);
37-
const irept::subt &bases=lhs_class.bases();
38-
for (const irept &base : bases)
37+
const class_typet::basest &bases=lhs_class.bases();
38+
for(const exprt &base : bases)
3939
{
40-
const typet &type=static_cast<const typet &>(base.find(ID_type));
40+
const typet &type=base.type();
4141
if (instanceof(ns.follow(type), rhs, ns)) return true;
4242
}
4343
return false;

src/util/std_types.h

+21-12
Original file line numberDiff line numberDiff line change
@@ -361,31 +361,40 @@ class class_typet:public struct_typet
361361
return is_class()?ID_private:ID_public;
362362
}
363363

364-
const irept::subt &bases() const
364+
class baset:public exprt
365365
{
366-
return find(ID_bases).get_sub();
366+
public:
367+
baset():exprt(ID_base)
368+
{
369+
}
370+
371+
explicit baset(const typet &base):exprt(ID_base, base)
372+
{
373+
}
374+
};
375+
376+
typedef std::vector<baset> basest;
377+
378+
const basest &bases() const
379+
{
380+
return (const basest &)find(ID_bases).get_sub();
367381
}
368382

369-
irept::subt &bases()
383+
basest &bases()
370384
{
371-
return add(ID_bases).get_sub();
385+
return (basest &)add(ID_bases).get_sub();
372386
}
373387

374388
void add_base(const typet &base)
375389
{
376-
bases().push_back(exprt(ID_base, base));
390+
bases().push_back(baset(base));
377391
}
378392

379393
bool has_base(const irep_idt &id) const
380394
{
381-
const irept::subt &b=bases();
382-
383-
forall_irep(it, b)
395+
for(const auto &b : bases())
384396
{
385-
assert(it->id()==ID_base);
386-
const irept &type=it->find(ID_type);
387-
assert(type.id()==ID_symbol);
388-
if(type.get(ID_identifier)==id)
397+
if(to_symbol_type(b.type()).get(ID_identifier)==id)
389398
return true;
390399
}
391400

0 commit comments

Comments
 (0)