-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeSystem.cpp
More file actions
153 lines (142 loc) · 4.36 KB
/
TypeSystem.cpp
File metadata and controls
153 lines (142 loc) · 4.36 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// TypeSystem.cpp --- CodeReverse type system
// Copyright (C) 2017 Katayama Hirofumi MZ. License: MIT License
#include "TypeSystem.hpp"
/////////////////////////////////////////////////////////////////////////
namespace CodeReverse
{
/*static*/ TypeFlagsType
LogType::normalize_flags(TypeFlagsType flags)
{
if (flags & T_INT)
{
// remove "int" if wordy
if (flags & (T_SHORT | T_LONG | T_LONGLONG | T_INT128))
{
if (!(flags & T_POINTER))
{
flags &= ~T_INT;
}
}
}
if (flags & T_UNSIGNED)
{
if (!(flags & (T_CHAR | T_SHORT | T_LONG | T_LONGLONG |
T_INT128 | T_INT)))
{
// add "int" for single "unsigned"
flags |= T_INT;
}
}
if ((flags & T_SIGNED) && !(flags & T_CHAR))
{
// delete signed for non-char
flags &= ~T_SIGNED;
}
if (!(flags & (T_VOID | T_BOOL | T_FLOATING | T_COMPLEX | T_IMAGINARY |
T_ARRAY | T_POINTER | T_ALIAS | T_TAG | T_FUNC)))
{
flags |= T_INT;
}
return flags;
}
/*static*/ bool LogType::is_integer(TypeFlagsType flags)
{
flags = normalize_flags(flags);
if (is_floating(flags))
return false;
return (flags & (T_BOOL | T_CHAR | T_INT | T_INT128));
}
/*static*/ bool LogType::is_floating(TypeFlagsType flags)
{
flags = normalize_flags(flags);
return (flags & T_FLOATING);
}
/////////////////////////////////////////////////////////////////////////
// adding types
LogScope::LogScope(ScopeID parent_scope_id)
{
m_scope_id = all().size();
m_parent_id = parent_scope_id;
if (parent_scope_id == invalid_id())
{
init_default_scope();
}
else
{
all()[m_parent_id].m_child_scope_ids.insert(m_scope_id);
}
}
TypeID LogScope::name_to_type_id(const string_type& name) const
{
auto it = m_type_map.find(name);
if (it == m_type_map.end())
{
for (auto scope_id : m_child_scope_ids)
{
auto& scope = all()[scope_id];
auto id = scope.name_to_type_id(name);
if (id != invalid_id())
{
return id;
}
}
return invalid_id();
}
return it->second;
}
EntryID LogScope::name_to_entry_id(const string_type& name) const
{
auto it = m_entry_map.find(name);
if (it == m_entry_map.end())
{
for (auto scope_id : m_child_scope_ids)
{
auto& scope = all()[scope_id];
auto id = scope.name_to_entry_id(name);
if (id != invalid_id())
{
return id;
}
}
return invalid_id();
}
return it->second;
}
TagID LogScope::name_to_tag_id(const string_type& tag_name) const
{
auto it = m_tag_map.find(name);
if (it == m_tag_map.end())
{
for (auto scope_id : m_child_scope_ids)
{
auto& scope = all()[scope_id];
auto id = scope.name_to_tag_id(name);
if (id != invalid_id())
{
return id;
}
}
return invalid_id();
}
return it->second;
}
LabelID LogScope::name_to_label_id(const string_type& name) const
{
auto it = m_label_map.find(name);
if (it == m_label_map.end())
{
for (auto scope_id : m_child_scope_ids)
{
auto& scope = all()[scope_id];
auto id = scope.name_to_label_id(name);
if (id != invalid_id())
{
return id;
}
}
return invalid_id();
}
return it->second;
}
/////////////////////////////////////////////////////////////////////////
} // namespace CodeReverse