16
16
17
17
#include < cegis/cegis-util/type_helper.h>
18
18
19
- const typet &replace_struct_by_symbol_type (const symbol_tablet &st,
20
- const typet &type)
19
+ const typet &replace_struct_by_symbol_type (
20
+ const symbol_tablet &st,
21
+ const typet &type)
21
22
{
22
23
const irep_idt &type_id=type.id ();
23
- if (ID_struct != type_id && ID_incomplete_struct != type_id
24
- && ID_union != type_id && ID_incomplete_union != type_id) return type;
24
+ if (type_id!=ID_struct && type_id!=ID_incomplete_struct &&
25
+ type_id!=ID_union && type_id!=ID_incomplete_union)
26
+ {
27
+ return type;
28
+ }
25
29
std::string tag (TAG_PREFIX);
26
30
tag+=id2string (to_struct_union_type (type).get_tag ());
27
31
return st.lookup (tag).type ;
@@ -31,16 +35,21 @@ namespace
31
35
{
32
36
bool instanceof (const typet &lhs, const typet &rhs, const namespacet &ns)
33
37
{
34
- if (type_eq (lhs, rhs, ns)) return true ;
35
- assert (ID_class == lhs.id ());
36
- const class_typet &lhs_class=to_class_type (lhs);
37
- const irept::subt &bases=lhs_class.bases ();
38
- for (const irept &base : bases)
38
+ if (type_eq (lhs, rhs, ns))
39
39
{
40
- const typet &type=static_cast <const typet &>(base.find (ID_type));
41
- if (instanceof (ns.follow (type), rhs, ns)) return true ;
40
+ return true ;
42
41
}
43
- return false ;
42
+ assert (ID_class==lhs.id ());
43
+ const class_typet &lhs_class=to_class_type (lhs);
44
+ const irept::subt &bases=lhs_class.bases ();
45
+ return std::any_of (
46
+ std::begin (bases),
47
+ std::end (bases),
48
+ [&](const irept &base)
49
+ {
50
+ const typet &type=static_cast <const typet &>(base.find (ID_type));
51
+ return instanceof (ns.follow (type), rhs, ns);
52
+ });
44
53
}
45
54
}
46
55
@@ -49,22 +58,32 @@ bool instanceof(const symbol_tablet &st, const typet &lhs, const typet &rhs)
49
58
const namespacet ns (st);
50
59
const typet &resolved_lhs=ns.follow (lhs);
51
60
const typet &resolved_rhs=ns.follow (rhs);
52
- if (ID_class != resolved_lhs.id () || ID_class != resolved_rhs.id ())
61
+ if (ID_class!=resolved_lhs.id () || ID_class!=resolved_rhs.id ())
62
+ {
53
63
return type_eq (resolved_lhs, resolved_rhs, ns);
64
+ }
54
65
return instanceof (resolved_lhs, resolved_rhs, ns);
55
66
}
56
67
57
- instanceof_anyt::instanceof_anyt (const symbol_tablet &st,
58
- const std::set<typet> &types) :
59
- st(st), types(types)
68
+ instanceof_anyt::instanceof_anyt (
69
+ const symbol_tablet &st,
70
+ const std::set<typet> &types) :
71
+ st(st),
72
+ types(types)
60
73
{
61
74
}
62
75
63
- bool instanceof_anyt::operator ()(const typet &type) const
76
+ bool instanceof_anyt::operator ()(const typet &type) const
64
77
{
65
- if (types.empty ()) return true ;
66
- return types.end ()
67
- != std::find_if (types.begin (), types.end (),
68
- [this , &type](const typet &rhs)
69
- { return instanceof (st, type, rhs);});
78
+ if (types.empty ())
79
+ {
80
+ return true ;
81
+ }
82
+ return types.end ()!=std::find_if (
83
+ types.begin (),
84
+ types.end (),
85
+ [this , &type](const typet &rhs)
86
+ {
87
+ return instanceof (st, type, rhs);
88
+ });
70
89
}
0 commit comments