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 
18  const typet &src,
19  const namespacet &ns,
20  const std::string &suffix,
21  std::vector<irep_idt> &dest)
22 {
23  if(src.id()==ID_symbol)
24  {
25  cpp_exception_list_rec(ns.follow(src), ns, suffix, dest);
26  }
27  else if(src.id()==ID_pointer)
28  {
29  if(src.get_bool(ID_C_reference))
30  {
31  // do not change
32  cpp_exception_list_rec(src.subtype(), ns, suffix, dest);
33  }
34  else
35  {
36  // append suffix _ptr
37  cpp_exception_list_rec(src.subtype(), ns, "_ptr"+suffix, dest);
38  }
39  }
40  else if(src.id()==ID_union)
41  {
42  // just get tag
43  dest.push_back("union_"+src.get_string(ID_tag));
44  }
45  else if(src.id()==ID_struct)
46  {
47  // just get tag
48  dest.push_back("struct_"+src.get_string(ID_tag));
49 
50  // now do any bases, recursively
51  const irept::subt &bases=src.find(ID_bases).get_sub();
52 
53  forall_irep(it, bases)
54  {
55  const typet &type=static_cast<const typet &>(it->find(ID_type));
56  cpp_exception_list_rec(type, ns, suffix, dest);
57  }
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 }
The type of an expression.
Definition: type.h:22
const std::string & id2string(const irep_idt &d)
Definition: irep.h:43
std::vector< irept > subt
Definition: irep.h:90
irept cpp_exception_list(const typet &src, const namespacet &ns)
turns a type into a list of relevant exception IDs
#define CHECK_RETURN(CONDITION)
Definition: invariant.h:245
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:74
Base class for tree-like data structures with sharing.
Definition: irep.h:86
const typet & follow(const typet &) const
Definition: namespace.cpp:55
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:33
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:61