Skip to content

Commit 229817d

Browse files
Remove duplicate version of class_hierarchyt::get_children_trans_rec
1 parent 47cd927 commit 229817d

File tree

2 files changed

+34
-69
lines changed

2 files changed

+34
-69
lines changed

src/analyses/uncaught_exceptions_analysis.cpp

+29-69
Original file line numberDiff line numberDiff line change
@@ -5,78 +5,13 @@ Module: Over-approximating uncaught exceptions analysis
55
Author: Cristina David
66
77
\*******************************************************************/
8-
98
#ifdef DEBUG
109
#include <iostream>
1110
#endif
1211
#include "uncaught_exceptions_analysis.h"
1312

1413
/*******************************************************************\
1514
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-
8015
Function: get_static_type
8116
8217
Inputs:
@@ -144,6 +79,12 @@ void uncaught_exceptions_domaint::join(
14479
thrown.insert(elements.begin(), elements.end());
14580
}
14681

82+
void uncaught_exceptions_domaint::join(
83+
const std::vector<irep_idt> &elements)
84+
{
85+
thrown.insert(elements.begin(), elements.end());
86+
}
87+
14788

14889
/*******************************************************************\
14990
@@ -178,8 +119,8 @@ void uncaught_exceptions_domaint::transform(
178119
join(type_id);
179120
// we must consider all the subtypes given that
180121
// 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);
183124
join(subtypes);
184125
}
185126
break;
@@ -199,8 +140,8 @@ void uncaught_exceptions_domaint::transform(
199140
for(const auto &exc : exception_list)
200141
{
201142
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());
204145
last_caught.insert(subtypes.begin(), subtypes.end());
205146
}
206147
}
@@ -260,6 +201,24 @@ void uncaught_exceptions_domaint::get_elements(
260201

261202
/*******************************************************************\
262203
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+
263222
Function: uncaught_exceptions_analysist::collect_uncaught_exceptions
264223
265224
Inputs:
@@ -350,6 +309,7 @@ void uncaught_exceptions_analysist::operator()(
350309
const namespacet &ns,
351310
exceptions_mapt &exceptions)
352311
{
312+
domain(ns);
353313
collect_uncaught_exceptions(goto_functions, ns);
354314
exceptions=exceptions_map;
355315
output(goto_functions);

src/analyses/uncaught_exceptions_analysis.h

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Cristina David
1313
#include <map>
1414
#include <set>
1515
#include <goto-programs/goto_functions.h>
16+
#include <goto-programs/class_hierarchy.h>
1617

1718
/*******************************************************************\
1819
@@ -34,6 +35,7 @@ class uncaught_exceptions_domaint
3435

3536
void join(const irep_idt &);
3637
void join(const std::set<irep_idt> &);
38+
void join(const std::vector<irep_idt> &);
3739

3840
void make_top()
3941
{
@@ -47,10 +49,13 @@ class uncaught_exceptions_domaint
4749

4850
void get_elements(std::set<irep_idt> &elements);
4951

52+
void operator()(const namespacet &ns);
53+
5054
private:
5155
typedef std::vector<std::set<irep_idt>> stack_caughtt;
5256
stack_caughtt stack_caught;
5357
std::set<irep_idt> thrown;
58+
class_hierarchyt class_hierarchy;
5459
};
5560

5661
/*******************************************************************\

0 commit comments

Comments
 (0)