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