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 
16  const typet &src,
17  const namespacet &ns,
18  const std::string &suffix,
19  std::vector<irep_idt> &dest)
20 {
21  if(src.id()==ID_symbol)
22  {
23  cpp_exception_list_rec(ns.follow(src), ns, suffix, dest);
24  }
25  else if(src.id()==ID_pointer)
26  {
27  if(src.get_bool(ID_C_reference))
28  {
29  // do not change
30  cpp_exception_list_rec(src.subtype(), ns, suffix, dest);
31  }
32  else
33  {
34  // append suffix _ptr
35  cpp_exception_list_rec(src.subtype(), ns, "_ptr"+suffix, dest);
36  }
37  }
38  else if(src.id()==ID_union)
39  {
40  // just get tag
41  dest.push_back("union_"+src.get_string(ID_tag));
42  }
43  else if(src.id()==ID_struct)
44  {
45  // just get tag
46  dest.push_back("struct_"+src.get_string(ID_tag));
47 
48  // now do any bases, recursively
49  const irept::subt &bases=src.find(ID_bases).get_sub();
50 
51  forall_irep(it, bases)
52  {
53  const typet &type=static_cast<const typet &>(it->find(ID_type));
54  cpp_exception_list_rec(type, ns, suffix, dest);
55  }
56  }
57  else
58  {
59  // grab C/C++ type
60  irep_idt c_type=src.get(ID_C_c_type);
61 
62  if(!c_type.empty())
63  {
64  dest.push_back(id2string(c_type)+suffix);
65  return;
66  }
67  }
68 }
69 
72  const typet &src,
73  const namespacet &ns)
74 {
75  std::vector<irep_idt> ids;
76  irept result(ID_exception_list);
77 
78  cpp_exception_list_rec(src, ns, "", ids);
79  result.get_sub().resize(ids.size());
80 
81  for(unsigned i=0; i<ids.size(); i++)
82  result.get_sub()[i].id(ids[i]);
83 
84  return result;
85 }
86 
89  const typet &src,
90  const namespacet &ns)
91 {
92  std::vector<irep_idt> ids;
93  cpp_exception_list_rec(src, ns, "", ids);
94  assert(!ids.empty());
95  return ids.front();
96 }
The type of an expression.
Definition: type.h:20
const typet & follow(const typet &src) const
Definition: namespace.cpp:66
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
std::vector< irept > subt
Definition: irep.h:91
irept cpp_exception_list(const typet &src, const namespacet &ns)
turns a type into a list of relevant exception IDs
bool get_bool(const irep_namet &name) const
Definition: irep.cpp:240
subt & get_sub()
Definition: irep.h:245
const irep_idt & id() const
Definition: irep.h:189
C++ Language Type Checking.
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
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:213
TO_BE_DOCUMENTED.
Definition: namespace.h:62
Base class for tree-like data structures with sharing.
Definition: irep.h:87
irep_idt cpp_exception_id(const typet &src, const namespacet &ns)
turns a type into an exception ID
const std::string & get_string(const irep_namet &name) const
Definition: irep.h:202
const typet & subtype() const
Definition: type.h:31
bool empty() const
Definition: dstring.h:61
const irept & find(const irep_namet &name) const
Definition: irep.cpp:285
#define forall_irep(it, irep)
Definition: irep.h:62