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