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,20 @@ 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 class_typet::basest &bases=lhs_class.bases ();
38
- for (const exprt &base : bases)
38
+ if (type_eq (lhs, rhs, ns))
39
39
{
40
- const typet &type=base.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 class_typet::basest &bases=lhs_class.bases ();
45
+ return std::any_of (
46
+ std::begin (bases),
47
+ std::end (bases),
48
+ [&](const exprt &base)
49
+ {
50
+ return instanceof (ns.follow (base.type ()), rhs, ns);
51
+ });
44
52
}
45
53
}
46
54
@@ -49,22 +57,32 @@ bool instanceof(const symbol_tablet &st, const typet &lhs, const typet &rhs)
49
57
const namespacet ns (st);
50
58
const typet &resolved_lhs=ns.follow (lhs);
51
59
const typet &resolved_rhs=ns.follow (rhs);
52
- if (ID_class != resolved_lhs.id () || ID_class != resolved_rhs.id ())
60
+ if (ID_class!=resolved_lhs.id () || ID_class!=resolved_rhs.id ())
61
+ {
53
62
return type_eq (resolved_lhs, resolved_rhs, ns);
63
+ }
54
64
return instanceof (resolved_lhs, resolved_rhs, ns);
55
65
}
56
66
57
- instanceof_anyt::instanceof_anyt (const symbol_tablet &st,
58
- const std::set<typet> &types) :
59
- st(st), types(types)
67
+ instanceof_anyt::instanceof_anyt (
68
+ const symbol_tablet &st,
69
+ const std::set<typet> &types):
70
+ st(st),
71
+ types(types)
60
72
{
61
73
}
62
74
63
- bool instanceof_anyt::operator ()(const typet &type) const
75
+ bool instanceof_anyt::operator ()(const typet &type) const
64
76
{
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);});
77
+ if (types.empty ())
78
+ {
79
+ return true ;
80
+ }
81
+ return types.end ()!=std::find_if (
82
+ types.begin (),
83
+ types.end (),
84
+ [this , &type](const typet &rhs)
85
+ {
86
+ return instanceof (st, type, rhs);
87
+ });
70
88
}
0 commit comments