@@ -5,78 +5,13 @@ Module: Over-approximating uncaught exceptions analysis
5
5
Author: Cristina David
6
6
7
7
\*******************************************************************/
8
-
9
8
#ifdef DEBUG
10
9
#include < iostream>
11
10
#endif
12
11
#include " uncaught_exceptions_analysis.h"
13
12
14
13
/* ******************************************************************\
15
14
16
- Function: get_subtypes
17
-
18
- Inputs:
19
-
20
- Outputs:
21
-
22
- Purpose: computes the set of subtypes of "type" by iterating over
23
- the symbol table
24
- \*******************************************************************/
25
-
26
- static void get_subtypes (
27
- const irep_idt &type,
28
- std::set<irep_idt> &subtypes,
29
- const namespacet &ns)
30
- {
31
- irep_idt candidate;
32
- bool new_subtype=true ;
33
- const symbol_tablet &symbol_table=ns.get_symbol_table ();
34
-
35
- // as we don't know the order types have been recorded,
36
- // we need to iterate over the symbol table until there are no more
37
- // new subtypes found
38
- while (new_subtype)
39
- {
40
- new_subtype=false ;
41
- // iterate over the symbol_table in order to find subtypes of type
42
- forall_symbols (it, symbol_table.symbols )
43
- {
44
- // we only look at type entries
45
- if (it->second .is_type )
46
- {
47
- // every type is a potential candidate
48
- candidate=it->second .name ;
49
- // current candidate is already in subtypes
50
- if (find (subtypes.begin (),
51
- subtypes.end (),
52
- candidate)!=subtypes.end ())
53
- continue ;
54
- // get its base class
55
- const class_typet::basest &bases=
56
- to_class_type ((it->second ).type ).bases ();
57
- if (bases.size ()>0 )
58
- {
59
- const class_typet::baset &base = bases[0 ];
60
- const irept &base_type=base.find (ID_type);
61
- assert (base_type.id ()==ID_symbol);
62
-
63
- // is it derived from type?
64
- // i.e. does it have type or one of its subtypes as a base?
65
- if (base_type.get (ID_identifier)==type ||
66
- find (subtypes.begin (), subtypes.end (),
67
- base_type.get (ID_identifier))!=subtypes.end ())
68
- {
69
- subtypes.insert (candidate);
70
- new_subtype=true ;
71
- }
72
- }
73
- }
74
- }
75
- }
76
- }
77
-
78
- /* ******************************************************************\
79
-
80
15
Function: get_static_type
81
16
82
17
Inputs:
@@ -144,6 +79,12 @@ void uncaught_exceptions_domaint::join(
144
79
thrown.insert (elements.begin (), elements.end ());
145
80
}
146
81
82
+ void uncaught_exceptions_domaint::join (
83
+ const std::vector<irep_idt> &elements)
84
+ {
85
+ thrown.insert (elements.begin (), elements.end ());
86
+ }
87
+
147
88
148
89
/* ******************************************************************\
149
90
@@ -178,8 +119,8 @@ void uncaught_exceptions_domaint::transform(
178
119
join (type_id);
179
120
// we must consider all the subtypes given that
180
121
// the runtime type is a subtype of the static type
181
- std::set <irep_idt> subtypes;
182
- get_subtypes (type_id, subtypes, ns );
122
+ std::vector <irep_idt> subtypes=
123
+ class_hierarchy. get_children_trans (type_id );
183
124
join (subtypes);
184
125
}
185
126
break ;
@@ -199,8 +140,8 @@ void uncaught_exceptions_domaint::transform(
199
140
for (const auto &exc : exception_list)
200
141
{
201
142
last_caught.insert (exc.id ());
202
- std::set <irep_idt> subtypes;
203
- get_subtypes (exc.id (), subtypes, ns );
143
+ std::vector <irep_idt> subtypes=
144
+ class_hierarchy. get_children_trans (exc.id ());
204
145
last_caught.insert (subtypes.begin (), subtypes.end ());
205
146
}
206
147
}
@@ -260,6 +201,24 @@ void uncaught_exceptions_domaint::get_elements(
260
201
261
202
/* ******************************************************************\
262
203
204
+ Function: uncaught_exceptions_domaint::operator()
205
+
206
+ Inputs:
207
+
208
+ Outputs:
209
+
210
+ Purpose:
211
+
212
+ \*******************************************************************/
213
+
214
+ void uncaught_exceptions_domaint::operator ()(
215
+ const namespacet &ns)
216
+ {
217
+ class_hierarchy (ns.get_symbol_table ());
218
+ }
219
+
220
+ /* ******************************************************************\
221
+
263
222
Function: uncaught_exceptions_analysist::collect_uncaught_exceptions
264
223
265
224
Inputs:
@@ -350,6 +309,7 @@ void uncaught_exceptions_analysist::operator()(
350
309
const namespacet &ns,
351
310
exceptions_mapt &exceptions)
352
311
{
312
+ domain (ns);
353
313
collect_uncaught_exceptions (goto_functions, ns);
354
314
exceptions=exceptions_map;
355
315
output (goto_functions);
0 commit comments