-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathcpp_exception_id.cpp
More file actions
102 lines (88 loc) · 2.32 KB
/
cpp_exception_id.cpp
File metadata and controls
102 lines (88 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*******************************************************************\
Module: C++ Language Type Checking
Author: Daniel Kroening, [email protected]
\*******************************************************************/
/// \file
/// C++ Language Type Checking
#include "cpp_exception_id.h"
#include <util/c_types.h>
#include <util/invariant.h>
#include <util/namespace.h>
#include <util/std_types.h>
/// turns a type into a list of relevant exception IDs
void cpp_exception_list_rec(
const typet &src,
const namespacet &ns,
const std::string &suffix,
std::vector<irep_idt> &dest)
{
if(src.id() == ID_pointer)
{
if(src.get_bool(ID_C_reference))
{
// do not change
cpp_exception_list_rec(
to_reference_type(src).base_type(), ns, suffix, dest);
}
else
{
// append suffix _ptr
cpp_exception_list_rec(
to_reference_type(src).base_type(), ns, "_ptr" + suffix, dest);
}
}
else if(src.id() == ID_union_tag)
{
cpp_exception_list_rec(ns.follow_tag(to_union_tag_type(src)), ns, suffix, dest);
}
else if(src.id()==ID_union)
{
// just get tag
dest.push_back("union_"+src.get_string(ID_tag));
}
else if(src.id() == ID_struct_tag)
{
cpp_exception_list_rec(ns.follow_tag(to_struct_tag_type(src)), ns, suffix, dest);
}
else if(src.id()==ID_struct)
{
// just get tag
dest.push_back("struct_"+src.get_string(ID_tag));
// now do any bases, recursively
for(const auto &b : to_struct_type(src).bases())
cpp_exception_list_rec(b.type(), ns, suffix, dest);
}
else
{
// grab C/C++ type
irep_idt c_type=src.get(ID_C_c_type);
if(!c_type.empty())
{
dest.push_back(id2string(c_type)+suffix);
return;
}
}
}
/// turns a type into a list of relevant exception IDs
irept cpp_exception_list(
const typet &src,
const namespacet &ns)
{
std::vector<irep_idt> ids;
irept result(ID_exception_list);
cpp_exception_list_rec(src, ns, "", ids);
result.get_sub().resize(ids.size());
for(std::size_t i=0; i<ids.size(); i++)
result.get_sub()[i].id(ids[i]);
return result;
}
/// turns a type into an exception ID
irep_idt cpp_exception_id(
const typet &src,
const namespacet &ns)
{
std::vector<irep_idt> ids;
cpp_exception_list_rec(src, ns, "", ids);
CHECK_RETURN(!ids.empty());
return ids.front();
}