cprover
cpp_exception_id.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: C++ Language Type Checking
4 
5 Author: Daniel Kroening, kroening@cs.cmu.edu
6 
7 \*******************************************************************/
8 
11 
12 #include "cpp_exception_id.h"
13 
14 #include <util/c_types.h>
15 #include <util/invariant.h>
16 #include <util/namespace.h>
17 #include <util/std_types.h>
18 
21  const typet &src,
22  const namespacet &ns,
23  const std::string &suffix,
24  std::vector<irep_idt> &dest)
25 {
26  if(src.id() == ID_pointer)
27  {
28  if(src.get_bool(ID_C_reference))
29  {
30  // do not change
31  cpp_exception_list_rec(src.subtype(), ns, suffix, dest);
32  }
33  else
34  {
35  // append suffix _ptr
36  cpp_exception_list_rec(src.subtype(), ns, "_ptr"+suffix, dest);
37  }
38  }
39  else if(src.id() == ID_union_tag)
40  {
41  cpp_exception_list_rec(ns.follow_tag(to_union_tag_type(src)), ns, suffix, dest);
42  }
43  else if(src.id()==ID_union)
44  {
45  // just get tag
46  dest.push_back("union_"+src.get_string(ID_tag));
47  }
48  else if(src.id() == ID_struct_tag)
49  {
50  cpp_exception_list_rec(ns.follow_tag(to_struct_tag_type(src)), ns, suffix, dest);
51  }
52  else if(src.id()==ID_struct)
53  {
54  // just get tag
55  dest.push_back("struct_"+src.get_string(ID_tag));
56 
57  // now do any bases, recursively
58  for(const auto &b : to_struct_type(src).bases())
59  cpp_exception_list_rec(b.type(), ns, suffix, dest);
60  }
61  else
62  {
63  // grab C/C++ type
64  irep_idt c_type=src.get(ID_C_c_type);
65 
66  if(!c_type.empty())
67  {
68  dest.push_back(id2string(c_type)+suffix);
69  return;
70  }
71  }
72 }
73 
76  const typet &src,
77  const namespacet &ns)
78 {
79  std::vector<irep_idt> ids;
80  irept result(ID_exception_list);
81 
82  cpp_exception_list_rec(src, ns, "", ids);
83  result.get_sub().resize(ids.size());
84 
85  for(std::size_t i=0; i<ids.size(); i++)
86  result.get_sub()[i].id(ids[i]);
87 
88  return result;
89 }
90 
93  const typet &src,
94  const namespacet &ns)
95 {
96  std::vector<irep_idt> ids;
97  cpp_exception_list_rec(src, ns, "", ids);
98  CHECK_RETURN(!ids.empty());
99  return ids.front();
100 }
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
Definition: c_types.h:189
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
bool empty() const
Definition: dstring.h:88
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition: irep.h:383
subt & get_sub()
Definition: irep.h:467
const std::string & get_string(const irep_namet &name) const
Definition: irep.h:420
bool get_bool(const irep_namet &name) const
Definition: irep.cpp:58
const irep_idt & id() const
Definition: irep.h:407
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:45
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
Definition: namespace.cpp:63
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:91
The type of an expression, extends irept.
Definition: type.h:28
const typet & subtype() const
Definition: type.h:47
irep_idt cpp_exception_id(const typet &src, const namespacet &ns)
turns a type into an exception ID
void cpp_exception_list_rec(const typet &src, const namespacet &ns, const std::string &suffix, std::vector< irep_idt > &dest)
turns a type into a list of relevant exception IDs
irept cpp_exception_list(const typet &src, const namespacet &ns)
turns a type into a list of relevant exception IDs
C++ Language Type Checking.
const std::string & id2string(const irep_idt &d)
Definition: irep.h:49
#define CHECK_RETURN(CONDITION)
Definition: invariant.h:495
Pre-defined types.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
Definition: std_types.h:308
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition: std_types.h:474