-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathcpp_name.cpp
88 lines (69 loc) · 1.78 KB
/
cpp_name.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*******************************************************************\
Module: C++ Language Type Checking
Author: Daniel Kroening, [email protected]
\*******************************************************************/
/// \file
/// C++ Language Type Checking
#include "cpp_name.h"
irep_idt cpp_namet::get_base_name() const
{
const subt &sub=get_sub();
// find last "::"
std::size_t base=0;
for(std::size_t i=0; i<sub.size(); i++)
{
if(sub[i].id()=="::")
base=i+1;
}
if(base>=sub.size())
return irep_idt();
if(sub[base].id()==ID_name)
return sub[base].get(ID_identifier);
else if(base+1<sub.size() && sub[base].id()==ID_operator)
return "operator"+sub[base+1].id_string();
else if(base+1<sub.size() && sub[base].id()=="~" && sub[base+1].id()==ID_name)
return "~"+sub[base+1].get_string(ID_identifier);
return irep_idt();
}
#if 0
void cpp_namet::convert(
std::string &identifier,
std::string &base_name) const
{
for(const auto &irep : get_sub())
{
const irep_idt id = irep.id();
std::string name_component;
if(id==ID_name)
name_component = irep.get_string(ID_identifier);
else if(id==ID_template_args)
{
std::stringstream ss;
ss << location() << '\n';
ss << "no template arguments allowed here";
throw ss.str();
}
else
name_component = irep.id_string();
identifier+=name_component;
if(id=="::")
base_name.clear();
else
base_name+=name_component;
}
}
#endif
std::string cpp_namet::to_string() const
{
std::string str;
for(const auto &irep : get_sub())
{
if(irep.id() == "::")
str += irep.id_string();
else if(irep.id() == ID_template_args)
str += "<...>";
else
str += irep.get_string(ID_identifier);
}
return str;
}