cprover
Loading...
Searching...
No Matches
cpp_name.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: C++ Language Type Checking
4
5Author: 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
43void cpp_namet::convert(
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
75std::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}
virtual void clear()
Reset the abstract state.
Definition ai.h:267
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:564
irep_idt get_base_name() const
Definition cpp_name.cpp:16
std::string to_string() const
Definition cpp_name.cpp:75
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:37
subt & get_sub()
Definition irep.h:456
dstringt irep_idt
Definition irep.h:37