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