CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
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
41void cpp_namet::convert(
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
73std::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}
virtual void clear()
Reset the abstract state.
Definition ai.h:265
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
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
subt & get_sub()
Definition irep.h:448
dstringt irep_idt