-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonkType.py
266 lines (241 loc) · 9.34 KB
/
monkType.py
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/python
import monkDebug as debug
import monkType as Type
import monkNode as node
import monkModule as module
import re
global_basic_type = ['void', 'bool', \
'char', 'char8_t', 'char16_t', 'char32_t', \
'float', 'double', \
'int', 'unsigned int', 'short', 'unsigned short', 'long', 'unsigned long', \
'int8_t', 'int16_t', 'int32_t', 'int64_t', 'int128_t', \
'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'uint128_t', \
'T', 'CLASS_TYPE']
global_class_link = {
"etk::String" : "http://www.cplusplus.com/reference/string/string/",
"std::u16string" : "http://www.cplusplus.com/reference/string/u16string/",
"std11::u16string" : "http://www.cplusplus.com/reference/string/u16string/",
"etk::UString" : "http://www.cplusplus.com/reference/string/u32string/",
"std11::u32string" : "http://www.cplusplus.com/reference/string/u32string/",
"std::wstring" : "http://www.cplusplus.com/reference/string/wstring/",
"etk::Vector" : "http://www.cplusplus.com/reference/vector/vector/",
"std::list" : "http://www.cplusplus.com/reference/list/list/",
"etk::Pair" : "http://www.cplusplus.com/reference/utility/pair/",
"std::tuple" : "http://www.cplusplus.com/reference/tuple/tuple/",
"std::shared_ptr" : "http://www.cplusplus.com/reference/memory/shared_ptr/",
"std11::shared_ptr": "http://www.cplusplus.com/reference/memory/shared_ptr/",
"std::weak_ptr" : "http://www.cplusplus.com/reference/memory/weak_ptr/",
"std11::weak_ptr" : "http://www.cplusplus.com/reference/memory/weak_ptr/",
"std::enable_shared_from_this" : "http://www.cplusplus.com/reference/memory/enable_shared_from_this/",
"std11::enable_shared_from_this" : "http://www.cplusplus.com/reference/memory/enable_shared_from_this/",
"ethread::Mutex" : "http://www.cplusplus.com/reference/mutex/mutex/",
"std11::mutex": "http://www.cplusplus.com/reference/mutex/mutex/",
"std::unique_lock" : "http://www.cplusplus.com/reference/mutex/unique_lock/",
"std11::unique_lock": "http://www.cplusplus.com/reference/mutex/unique_lock/",
"std::chrono::" : "http://www.cplusplus.com/reference/chrono/time_point/",
"std11::chrono::": "http://www.cplusplus.com/reference/chrono/time_point/",
"std::chrono::system_clock::time_point" : "http://www.cplusplus.com/reference/chrono/time_point/",
"std11::chrono::system_clock::time_point" : "http://www.cplusplus.com/reference/chrono/time_point/",
"std::chrono::steady_clock::time_point" : "http://www.cplusplus.com/reference/chrono/time_point/",
"std11::chrono::steady_clock::time_point" : "http://www.cplusplus.com/reference/chrono/time_point/",
"std::chrono::time_point" : "http://www.cplusplus.com/reference/chrono/time_point/",
"std11::chrono::time_point" : "http://www.cplusplus.com/reference/chrono/time_point/",
"std::chrono::system_clock":"http://www.cplusplus.com/reference/chrono/system_clock/",
"std11::chrono::system_clock":"http://www.cplusplus.com/reference/chrono/system_clock/",
"std::chrono::steady_clock":"http://www.cplusplus.com/reference/chrono/steady_clock/",
"std11::chrono::steady_clock":"http://www.cplusplus.com/reference/chrono/steady_clock/",
"std::chrono::duration":"http://www.cplusplus.com/reference/chrono/duration/",
"std11::chrono::duration":"http://www.cplusplus.com/reference/chrono/duration/",
"std::chrono::hours":"http://www.cplusplus.com/reference/chrono/duration/",
"std11::chrono::hours":"http://www.cplusplus.com/reference/chrono/duration/",
"std::chrono::minutes":"http://www.cplusplus.com/reference/chrono/duration/",
"std11::chrono::minutes":"http://www.cplusplus.com/reference/chrono/duration/",
"std::chrono::seconds":"http://www.cplusplus.com/reference/chrono/duration/",
"std11::chrono::seconds":"http://www.cplusplus.com/reference/chrono/duration/",
"std::chrono::milliseconds":"http://www.cplusplus.com/reference/chrono/duration/",
"std11::chrono::milliseconds":"http://www.cplusplus.com/reference/chrono/duration/",
"std::chrono::microseconds":"http://www.cplusplus.com/reference/chrono/duration/",
"std11::chrono::microseconds":"http://www.cplusplus.com/reference/chrono/duration/",
"std::chrono::nanoseconds":"http://www.cplusplus.com/reference/chrono/duration/",
"std11::chrono::nanoseconds":"http://www.cplusplus.com/reference/chrono/duration/",
}
class Type():
def __init__(self, stack=[]):
self.name_before = ""
self.name = ""
self.name_after = ""
self.const = False # the const xxxxx
self.reference = False
self.const_var = False # the char* const VarName
self.enum = False
self.struct = False
self.mutable = False
self.template_parameter = None
if len(stack) == 0:
# None type
return
if len(stack) == 1:
self.name = stack[0]
return;
# check end const
if stack[len(stack)-1] == 'const':
self.const_var = True
stack = stack[:len(stack)-1]
# check if element is a reference ...
if stack[len(stack)-1] == '&':
self.reference = True
stack = stack[:len(stack)-1]
# check if it start with const ...
if stack[0] == 'const':
self.const = True
stack = stack[1:]
# check if it start with enum & struct ...
if stack[0] == 'enum':
self.enum = True
stack = stack[1:]
if stack[0] == 'struct':
self.struct = True
stack = stack[1:]
if stack[0] == 'mutable':
self.mutable = True
stack = stack[1:]
debug.info("get type : " + str(stack))
self.name_before = ""
self.name = ""
self.name_after = ""
template_level = 0
template_new_elem = False
for element in stack:
if template_level == 0:
if self.name_after != "":
self.name_after += element
continue
if element[0] in ['*', '&']:
if self.name == "":
self.name_before += element
continue
else:
self.name_after += element
continue
else:
if element[0] in [',']:
#Template separator ...
template_new_elem = True
continue
if element[0] == '<':
debug.info(" Start template")
if self.template_parameter == None:
self.template_parameter = []
template_level += 1
continue
if element[0] == '>':
template_level -= 1
debug.info(" Stop template")
continue
if template_level != 0:
if element != "":
if template_new_elem == True \
or len(self.template_parameter) == 0:
self.template_parameter.append(element)
else:
self.template_parameter[-1] += " " + element
else:
self.name += element
if self.template_parameter == None:
debug.info(" ==> '" + self.name + "'")
else:
debug.info(" ==> '" + self.name + "' : " + str(self.template_parameter))
debug.info(" self.name_before='" + str(self.name_before) + "'")
debug.info(" self.name_after='" + self.name_after + "'")
def to_str(self) :
ret = ""
if self.const == True:
ret += "const "
if self.mutable == True:
ret += "mutable "
if self.enum == True:
ret += "enum "
if self.struct == True:
ret += "struct "
ret += self.name_before
ret += self.name
if self.template_parameter != None:
ret += "<"
first_elem = True
for elem in self.template_parameter:
if first_elem == True:
first_elem = False
else:
ret += ", "
ret += elem
ret += ">"
ret += self.name_after
if self.reference == True:
ret += " &"
if self.const_var == True:
ret += " const"
return ret
def to_str_decorated(self) :
global global_basic_type
global global_class_link
ret = ""
retDecorated = ""
if self.const == True:
ret += "const "
retDecorated += module.display_color("const") + " "
if self.mutable == True:
ret += "mutable "
retDecorated += module.display_color("mutable") + " "
if self.enum == True:
ret += "enum "
retDecorated += module.display_color("enum") + " "
if self.struct == True:
ret += "struct "
retDecorated += module.display_color("struct") + " "
ret += self.name_before
ret += self.name
ret += self.name_after
retDecorated += self.name_before
element = module.get_element_with_name(self.name)
if element == None:
if self.name in global_basic_type:
retDecorated += '<span class="code-type" >' + self.name + '</span>'
elif self.name in global_class_link.keys():
retDecorated += '<a class="code-type" href="' + global_class_link[self.name] + '">' + self.name + '</a>'
else:
retDecorated += self.name
else:
currentPageSite = element.get_doc_website_page()
link = element.get_doc_website_page()
link = node.get_doc_website_page_relative(currentPageSite, link)
retDecorated += '<a class="code-type" href="' + link + '">'
retDecorated += self.name
retDecorated += '</a>'
if self.template_parameter != None:
retDecorated += "<"
ret += "<"
first_elem = True
for elem in self.template_parameter:
if first_elem == True:
first_elem = False
else:
ret += ", "
retDecorated += ", "
ret += elem
retDecorated += elem
ret += ">"
retDecorated += ">"
retDecorated += self.name_after
if self.reference == True:
ret += " &"
retDecorated += " &"
if self.const_var == True:
ret += " const"
retDecorated += " " + module.display_color("const")
return [ret, retDecorated]
class TypeVoid(Type):
def __init__(self):
Type.__init__(self, ['void'])
class TypeNone(Type):
def __init__(self):
Type.__init__(self)