-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathcpp_id.cpp
118 lines (94 loc) · 2.97 KB
/
cpp_id.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*******************************************************************\
Module: C++ Language Type Checking
Author: Daniel Kroening, [email protected]
\*******************************************************************/
/// \file
/// C++ Language Type Checking
#include "cpp_id.h"
#include <ostream>
#include <util/invariant.h>
cpp_idt::cpp_idt():
is_member(false),
is_method(false),
is_static_member(false),
is_scope(false),
is_constructor(false),
id_class(id_classt::UNKNOWN),
this_expr(static_cast<const exprt &>(get_nil_irep())),
compound_counter(0),
parent(nullptr)
{
}
void cpp_idt::print(std::ostream &out, unsigned indent) const
{
print_fields(out, indent);
if(!sub.empty())
{
for(const auto &s : sub)
s.second.print(out, indent + 2);
out << '\n';
}
}
void cpp_idt::print_fields(std::ostream &out, unsigned indent) const
{
out << std::string(indent, ' ');
out << "**identifier=" << identifier << '\n';
out << std::string(indent, ' ');
out << " prefix=" << prefix << '\n';
out << std::string(indent, ' ');
out << " suffix=" << suffix << '\n';
out << std::string(indent, ' ');
out << " base_name=" << base_name << '\n';
out << std::string(indent, ' ');
out << " method=" << is_method << '\n';
out << std::string(indent, ' ');
out << " class_identifier=" << class_identifier << '\n';
for(const auto &s : secondary_scopes)
{
out << std::string(indent, ' ');
out << " secondary_scope=" << s->identifier << '\n';
}
for(const auto &s : using_scopes)
{
out << std::string(indent, ' ');
out << " using_scope=" << s->identifier << '\n';
}
out << std::string(indent, ' ');
out << " flags:";
if(is_constructor)
out << " constructor";
if(is_scope)
out << " scope";
if(is_member)
out << " member";
if(is_static_member)
out << " static_member";
out << '\n';
out << std::string(indent, ' ');
out << " id_class=" << id_class << '\n';
}
std::ostream &operator<<(std::ostream &out, const cpp_idt &cpp_id)
{
cpp_id.print(out, 0);
return out;
}
std::ostream &operator<<(std::ostream &out, const cpp_idt::id_classt &id_class)
{
// clang-format off
switch(id_class)
{
case cpp_idt::id_classt::UNKNOWN: return out<<"UNKNOWN";
case cpp_idt::id_classt::SYMBOL: return out<<"SYMBOL";
case cpp_idt::id_classt::TYPEDEF: return out<<"TYPEDEF";
case cpp_idt::id_classt::CLASS: return out<<"CLASS";
case cpp_idt::id_classt::TEMPLATE: return out<<"TEMPLATE";
case cpp_idt::id_classt::TEMPLATE_PARAMETER:return out<<"TEMPLATE_PARAMETER";
case cpp_idt::id_classt::ROOT_SCOPE: return out<<"ROOT_SCOPE";
case cpp_idt::id_classt::BLOCK_SCOPE: return out<<"BLOCK_SCOPE";
case cpp_idt::id_classt::TEMPLATE_SCOPE: return out<<"TEMPLATE_SCOPE";
case cpp_idt::id_classt::NAMESPACE: return out<<"NAMESPACE";
case cpp_idt::id_classt::ENUM: return out<<"ENUM";
}
// clang-format on
UNREACHABLE;
}