cprover
cpp_name.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_name.h"
13 
14 #include <cassert>
15 #include <sstream>
16 
18 {
19  const subt &sub=get_sub();
20 
21  // find last "::"
22  std::size_t base=0;
23 
24  for(std::size_t i=0; i<sub.size(); i++)
25  {
26  if(sub[i].id()=="::")
27  base=i+1;
28  }
29 
30  if(base>=sub.size())
31  return irep_idt();
32 
33  if(sub[base].id()==ID_name)
34  return sub[base].get(ID_identifier);
35  else if(base+1<sub.size() && sub[base].id()==ID_operator)
36  return "operator"+sub[base+1].id_string();
37  else if(base+1<sub.size() && sub[base].id()=="~" && sub[base+1].id()==ID_name)
38  return "~"+sub[base+1].get_string(ID_identifier);
39 
40  return irep_idt();
41 }
42 
43 #if 0
45  std::string &identifier,
46  std::string &base_name) const
47 {
48  forall_irep(it, get_sub())
49  {
50  const irep_idt id=it->id();
51 
52  std::string name_component;
53 
54  if(id==ID_name)
55  name_component=it->get_string(ID_identifier);
56  else if(id==ID_template_args)
57  {
58  std::stringstream ss;
59  ss << location() << '\n';
60  ss << "no template arguments allowed here";
61  throw ss.str();
62  }
63  else
64  name_component=it->id_string();
65 
66  identifier+=name_component;
67 
68  if(id=="::")
69  base_name.clear();
70  else
71  base_name+=name_component;
72  }
73 }
74 #endif
75 
76 std::string cpp_namet::to_string() const
77 {
78  std::string str;
79 
80  forall_irep(it, get_sub())
81  {
82  if(it->id()=="::")
83  str += it->id_string();
84  else if(it->id()==ID_template_args)
85  str += "<...>";
86  else
87  str+=it->get_string(ID_identifier);
88  }
89 
90  return str;
91 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
irep_idt
dstringt irep_idt
Definition: irep.h:32
convert
static bool convert(const irep_idt &identifier, const std::ostringstream &s, symbol_tablet &symbol_table, message_handlert &message_handler)
Definition: builtin_factory.cpp:42
dstringt::clear
void clear()
Definition: dstring.h:142
sharing_treet< irept, std::map< irep_namet, irept > >::subt
typename dt::subt subt
Definition: irep.h:182
forall_irep
#define forall_irep(it, irep)
Definition: irep.h:62
irept::get_sub
subt & get_sub()
Definition: irep.h:477
cpp_namet::get_base_name
irep_idt get_base_name() const
Definition: cpp_name.cpp:17
cpp_namet::to_string
std::string to_string() const
Definition: cpp_name.cpp:76
cpp_name.h