lambda-graphs 0.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lambda_graphs/__init__.py +18 -0
- lambda_graphs/__main__.py +7 -0
- lambda_graphs/cli.py +183 -0
- lambda_graphs/codeviews/AST/AST.py +120 -0
- lambda_graphs/codeviews/AST/AST_driver.py +37 -0
- lambda_graphs/codeviews/AST/__init__.py +0 -0
- lambda_graphs/codeviews/CFG/CFG.py +42 -0
- lambda_graphs/codeviews/CFG/CFG_c.py +1182 -0
- lambda_graphs/codeviews/CFG/CFG_cpp.py +5604 -0
- lambda_graphs/codeviews/CFG/CFG_driver.py +45 -0
- lambda_graphs/codeviews/CFG/CFG_java.py +1722 -0
- lambda_graphs/codeviews/CFG/__init__.py +0 -0
- lambda_graphs/codeviews/CST/CST_driver.py +70 -0
- lambda_graphs/codeviews/CST/__init__.py +0 -0
- lambda_graphs/codeviews/DFG/DFG_driver.py +42 -0
- lambda_graphs/codeviews/DFG/__init__.py +0 -0
- lambda_graphs/codeviews/SDFG/SDFG.py +135 -0
- lambda_graphs/codeviews/SDFG/SDFG_c.py +2041 -0
- lambda_graphs/codeviews/SDFG/SDFG_cpp.py +4030 -0
- lambda_graphs/codeviews/SDFG/SDFG_java.py +1618 -0
- lambda_graphs/codeviews/SDFG/__init__.py +0 -0
- lambda_graphs/codeviews/__init__.py +0 -0
- lambda_graphs/codeviews/combined_graph/__init__.py +0 -0
- lambda_graphs/codeviews/combined_graph/combined_driver.py +163 -0
- lambda_graphs/tree_parser/__init__.py +0 -0
- lambda_graphs/tree_parser/c_parser.py +565 -0
- lambda_graphs/tree_parser/cpp_parser.py +424 -0
- lambda_graphs/tree_parser/custom_parser.py +66 -0
- lambda_graphs/tree_parser/java_parser.py +254 -0
- lambda_graphs/tree_parser/parser_driver.py +54 -0
- lambda_graphs/utils/DFG_utils.py +44 -0
- lambda_graphs/utils/__init__.py +0 -0
- lambda_graphs/utils/c_nodes.py +431 -0
- lambda_graphs/utils/cpp_nodes.py +1331 -0
- lambda_graphs/utils/java_nodes.py +756 -0
- lambda_graphs/utils/multi_file_merger.py +444 -0
- lambda_graphs/utils/postprocessor.py +83 -0
- lambda_graphs/utils/preprocessor.py +68 -0
- lambda_graphs/utils/src_parser.py +23 -0
- lambda_graphs-0.1.4.dist-info/METADATA +380 -0
- lambda_graphs-0.1.4.dist-info/RECORD +45 -0
- lambda_graphs-0.1.4.dist-info/WHEEL +5 -0
- lambda_graphs-0.1.4.dist-info/entry_points.txt +2 -0
- lambda_graphs-0.1.4.dist-info/licenses/LICENSE +21 -0
- lambda_graphs-0.1.4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,756 @@
|
|
|
1
|
+
statement_types = {
|
|
2
|
+
"node_list_type": [
|
|
3
|
+
"declaration",
|
|
4
|
+
"expression_statement",
|
|
5
|
+
"labeled_statement",
|
|
6
|
+
"if_statement",
|
|
7
|
+
"while_statement",
|
|
8
|
+
"for_statement",
|
|
9
|
+
"enhanced_for_statement",
|
|
10
|
+
"assert_statement",
|
|
11
|
+
"do_statement",
|
|
12
|
+
"break_statement",
|
|
13
|
+
"continue_statement",
|
|
14
|
+
"return_statement",
|
|
15
|
+
"yield_statement",
|
|
16
|
+
"switch_expression",
|
|
17
|
+
"synchronized_statement",
|
|
18
|
+
"local_variable_declaration",
|
|
19
|
+
"throw_statement",
|
|
20
|
+
"try_statement",
|
|
21
|
+
"try_with_resources_statement",
|
|
22
|
+
"method_declaration",
|
|
23
|
+
"constructor_declaration",
|
|
24
|
+
"switch_block_statement_group",
|
|
25
|
+
"switch_rule",
|
|
26
|
+
"throw_statement",
|
|
27
|
+
"explicit_constructor_invocation",
|
|
28
|
+
"class_declaration",
|
|
29
|
+
"field_declaration",
|
|
30
|
+
"import_declaration",
|
|
31
|
+
"lambda_expression",
|
|
32
|
+
"interface_declaration",
|
|
33
|
+
],
|
|
34
|
+
"non_control_statement": [
|
|
35
|
+
"declaration",
|
|
36
|
+
"expression_statement",
|
|
37
|
+
"local_variable_declaration",
|
|
38
|
+
"explicit_constructor_invocation",
|
|
39
|
+
"assert_statement",
|
|
40
|
+
"field_declaration",
|
|
41
|
+
"import_declaration",
|
|
42
|
+
], # ON extending support fo files, explicit constructor invocation needs to be handled
|
|
43
|
+
"control_statement": [
|
|
44
|
+
"if_statement",
|
|
45
|
+
"while_statement",
|
|
46
|
+
"for_statement",
|
|
47
|
+
"enhanced_for_statement",
|
|
48
|
+
"do_statement",
|
|
49
|
+
"break_statement",
|
|
50
|
+
"continue_statement",
|
|
51
|
+
"return_statement",
|
|
52
|
+
"yield_statement",
|
|
53
|
+
"switch_expression",
|
|
54
|
+
"synchronized_statement",
|
|
55
|
+
"try_statement",
|
|
56
|
+
"try_with_resources_statement",
|
|
57
|
+
"yield_statement",
|
|
58
|
+
],
|
|
59
|
+
"loop_control_statement": [
|
|
60
|
+
"while_statement",
|
|
61
|
+
"for_statement",
|
|
62
|
+
"enhanced_for_statement",
|
|
63
|
+
],
|
|
64
|
+
"not_implemented": [],
|
|
65
|
+
"inner_node_type": [
|
|
66
|
+
"declaration",
|
|
67
|
+
"expression_statement",
|
|
68
|
+
"local_variable_declaration",
|
|
69
|
+
],
|
|
70
|
+
"outer_node_type": ["for_statement"],
|
|
71
|
+
"statement_holders": [
|
|
72
|
+
"block",
|
|
73
|
+
"switch_block_statement_group",
|
|
74
|
+
"switch_block",
|
|
75
|
+
"constructor_body",
|
|
76
|
+
"class_body",
|
|
77
|
+
"module_body",
|
|
78
|
+
"program",
|
|
79
|
+
],
|
|
80
|
+
"definition_types": [
|
|
81
|
+
"method_declaration",
|
|
82
|
+
"constructor_declaration",
|
|
83
|
+
"class_declaration",
|
|
84
|
+
"field_declaration",
|
|
85
|
+
"interface_declaration",
|
|
86
|
+
],
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
method_return_types = [
|
|
90
|
+
"integral_type",
|
|
91
|
+
"void_type",
|
|
92
|
+
"type_identifier",
|
|
93
|
+
"generic_type",
|
|
94
|
+
"scoped_type_identifier",
|
|
95
|
+
"floating_point_type",
|
|
96
|
+
"boolean_type",
|
|
97
|
+
"array_type",
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def get_child_of_type(node, type_list):
|
|
102
|
+
out = list(filter(lambda x: x.type in type_list, node.children))
|
|
103
|
+
if len(out) > 0:
|
|
104
|
+
return out[0]
|
|
105
|
+
else:
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def return_switch_child(node):
|
|
110
|
+
# Make it breadthfirst search, and return if you hit a node_list_type
|
|
111
|
+
bfs_queue = []
|
|
112
|
+
for child in node.children:
|
|
113
|
+
bfs_queue.append(child)
|
|
114
|
+
while bfs_queue != []:
|
|
115
|
+
top = bfs_queue.pop(0)
|
|
116
|
+
if top.type == "switch_expression":
|
|
117
|
+
return top
|
|
118
|
+
if top.type in statement_types["node_list_type"]:
|
|
119
|
+
return None
|
|
120
|
+
for child in top.children:
|
|
121
|
+
bfs_queue.append(child)
|
|
122
|
+
return None
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def return_switch_parent(node, non_control_statement):
|
|
126
|
+
"""Searches for a switch expression while going up the tree and returns it"""
|
|
127
|
+
|
|
128
|
+
while node.parent is not None and (
|
|
129
|
+
node.parent.type != "class_body" and node.parent.type != "method_body"
|
|
130
|
+
):
|
|
131
|
+
if node.parent.type == "block" and node.type == "switch_expression":
|
|
132
|
+
return node
|
|
133
|
+
if node.parent.type in non_control_statement:
|
|
134
|
+
return node.parent
|
|
135
|
+
node = node.parent
|
|
136
|
+
return None
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def return_switch_parent_statement(node, non_control_statement):
|
|
140
|
+
"""Searches for a switch expression while going up the tree and returns it"""
|
|
141
|
+
|
|
142
|
+
while node.parent is not None and (
|
|
143
|
+
node.parent.type != "class_body" and node.parent.type != "method_body"
|
|
144
|
+
):
|
|
145
|
+
if node.parent.type in non_control_statement:
|
|
146
|
+
return node.parent
|
|
147
|
+
node = node.parent
|
|
148
|
+
return None
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def has_inner_definition(node):
|
|
152
|
+
"""Checks if a node has a definition inside it"""
|
|
153
|
+
if node.type in statement_types["definition_types"]:
|
|
154
|
+
return True
|
|
155
|
+
for child in node.children:
|
|
156
|
+
if has_inner_definition(child):
|
|
157
|
+
return True
|
|
158
|
+
return False
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def find_method_declaration(node):
|
|
162
|
+
"""Searches for a method declaration while going up the tree and returns it"""
|
|
163
|
+
while node.parent is not None:
|
|
164
|
+
if node.parent.type == "method_declaration":
|
|
165
|
+
return node.parent
|
|
166
|
+
node = node.parent
|
|
167
|
+
return None
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
# def get_last_node(node):
|
|
171
|
+
# """Returns the last statement in the method block"""
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def get_signature(node):
|
|
175
|
+
signature = []
|
|
176
|
+
formal_parameters = node.child_by_field_name("parameters")
|
|
177
|
+
formal_parameters = list(
|
|
178
|
+
filter(lambda x: x.type == "formal_parameter", formal_parameters.children)
|
|
179
|
+
)
|
|
180
|
+
for formal_parameter in formal_parameters:
|
|
181
|
+
for child in formal_parameter.children:
|
|
182
|
+
if child.type != "identifier":
|
|
183
|
+
signature.append(child.text.decode("utf-8"))
|
|
184
|
+
return tuple(signature)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def get_anonymous_class(node):
|
|
188
|
+
"""Checks if a node contains an anonymous class and returns it breadthfirst"""
|
|
189
|
+
bfs_queue = []
|
|
190
|
+
bfs_queue.append(node)
|
|
191
|
+
while bfs_queue != []:
|
|
192
|
+
top = bfs_queue.pop(0)
|
|
193
|
+
if top.type == "class_body" and top.parent.type == "object_creation_expression":
|
|
194
|
+
return top
|
|
195
|
+
for child in top.children:
|
|
196
|
+
bfs_queue.append(child)
|
|
197
|
+
return None
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def check_anonymous_class(node):
|
|
201
|
+
"""Checks if a node contains a lambda expression"""
|
|
202
|
+
if get_anonymous_class(node) is None:
|
|
203
|
+
return False
|
|
204
|
+
else:
|
|
205
|
+
initial_node = node
|
|
206
|
+
class_node = get_anonymous_class(node)
|
|
207
|
+
parent_node = class_node.parent
|
|
208
|
+
while parent_node is not None:
|
|
209
|
+
if parent_node.type in statement_types["node_list_type"]:
|
|
210
|
+
if parent_node == initial_node:
|
|
211
|
+
return True
|
|
212
|
+
else:
|
|
213
|
+
return False
|
|
214
|
+
parent_node = parent_node.parent
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def get_lambda_body_depth(node):
|
|
218
|
+
"""Returns the body of a lambda expression"""
|
|
219
|
+
for child in node.children:
|
|
220
|
+
if get_lambda_body(child) is not None:
|
|
221
|
+
return get_lambda_body(child)
|
|
222
|
+
elif child.type == "lambda_expression":
|
|
223
|
+
return child
|
|
224
|
+
return None
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def get_lambda_body(node):
|
|
228
|
+
"""Returns the body of a lambda expression, breadthfirst"""
|
|
229
|
+
bfs_queue = []
|
|
230
|
+
|
|
231
|
+
bfs_queue.append(node)
|
|
232
|
+
while bfs_queue != []:
|
|
233
|
+
top = bfs_queue.pop(0)
|
|
234
|
+
if top.type == "lambda_expression":
|
|
235
|
+
return top
|
|
236
|
+
for child in top.children:
|
|
237
|
+
bfs_queue.append(child)
|
|
238
|
+
return None
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def get_all_lambda_body(node):
|
|
242
|
+
"""Returns the body of a lambda expression, breadthfirst"""
|
|
243
|
+
bfs_queue = []
|
|
244
|
+
output = []
|
|
245
|
+
bfs_queue.append(node)
|
|
246
|
+
while bfs_queue != []:
|
|
247
|
+
top = bfs_queue.pop(0)
|
|
248
|
+
if top.type == "lambda_expression":
|
|
249
|
+
output.append(top)
|
|
250
|
+
for child in top.children:
|
|
251
|
+
if (
|
|
252
|
+
child.type == "lambda_expression"
|
|
253
|
+
or child.type not in statement_types["node_list_type"]
|
|
254
|
+
):
|
|
255
|
+
bfs_queue.append(child)
|
|
256
|
+
|
|
257
|
+
return output
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def check_lambda(node):
|
|
261
|
+
"""Checks if a node contains a lambda expression"""
|
|
262
|
+
if get_lambda_body(node) is None:
|
|
263
|
+
return False
|
|
264
|
+
else:
|
|
265
|
+
initial_node = node
|
|
266
|
+
lambda_node = get_lambda_body(node)
|
|
267
|
+
parent_node = lambda_node.parent
|
|
268
|
+
while parent_node is not None:
|
|
269
|
+
if parent_node.type in statement_types["node_list_type"]:
|
|
270
|
+
|
|
271
|
+
if parent_node == initial_node:
|
|
272
|
+
return True
|
|
273
|
+
else:
|
|
274
|
+
return False
|
|
275
|
+
parent_node = parent_node.parent
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def abstract_method(node):
|
|
279
|
+
method_body = get_child_of_type(node, ["block"])
|
|
280
|
+
while node is not None:
|
|
281
|
+
if node.type == "class_body" and node.parent.type == "class_declaration":
|
|
282
|
+
node = node.parent
|
|
283
|
+
|
|
284
|
+
modifiers = get_child_of_type(node, ["modifiers"])
|
|
285
|
+
if (
|
|
286
|
+
modifiers is not None
|
|
287
|
+
and "abstract" in modifiers.text.decode("utf-8")
|
|
288
|
+
and method_body is None
|
|
289
|
+
):
|
|
290
|
+
return True
|
|
291
|
+
node = node.parent
|
|
292
|
+
return False
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def get_class_name(node, index):
|
|
296
|
+
"Returns the class name when a method declaration or constructor declaration is passed to it"
|
|
297
|
+
type_identifiers = ["type_identifier", "generic_type", "scoped_type_identifier"]
|
|
298
|
+
while node is not None:
|
|
299
|
+
if node.type == "class_body" and node.parent.type == "class_declaration":
|
|
300
|
+
node = node.parent
|
|
301
|
+
|
|
302
|
+
class_index = index[(node.start_point, node.end_point, node.type)]
|
|
303
|
+
class_name = [
|
|
304
|
+
(
|
|
305
|
+
list(
|
|
306
|
+
filter(lambda child: child.type == "identifier", node.children)
|
|
307
|
+
)[0]
|
|
308
|
+
).text.decode("UTF-8")
|
|
309
|
+
]
|
|
310
|
+
|
|
311
|
+
interface_node = get_child_of_type(node, ["super_interfaces"])
|
|
312
|
+
if interface_node is not None:
|
|
313
|
+
class_name.append(
|
|
314
|
+
get_child_of_type(interface_node, ["type_list"]).text.decode(
|
|
315
|
+
"UTF-8"
|
|
316
|
+
)
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
superclass_node = get_child_of_type(node, ["superclass"])
|
|
320
|
+
if superclass_node is not None:
|
|
321
|
+
class_name.append(
|
|
322
|
+
get_child_of_type(superclass_node, ["type_identifier"]).text.decode(
|
|
323
|
+
"UTF-8"
|
|
324
|
+
)
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
return class_index, class_name
|
|
328
|
+
|
|
329
|
+
elif (
|
|
330
|
+
node.type == "class_body"
|
|
331
|
+
and node.parent.type == "object_creation_expression"
|
|
332
|
+
):
|
|
333
|
+
node = node.parent
|
|
334
|
+
class_index = index[(node.start_point, node.end_point, node.type)]
|
|
335
|
+
class_name = [
|
|
336
|
+
list(
|
|
337
|
+
filter(lambda child: child.type in type_identifiers, node.children)
|
|
338
|
+
)[0].text.decode("UTF-8")
|
|
339
|
+
]
|
|
340
|
+
return class_index, class_name
|
|
341
|
+
elif (
|
|
342
|
+
node.type == "interface_body"
|
|
343
|
+
and node.parent.type == "interface_declaration"
|
|
344
|
+
):
|
|
345
|
+
return None
|
|
346
|
+
node = node.parent
|
|
347
|
+
class_index = index[(node.start_point, node.end_point, node.type)]
|
|
348
|
+
class_name = list(
|
|
349
|
+
filter(lambda child: child.type == "identifier", node.children)
|
|
350
|
+
)[0]
|
|
351
|
+
return class_index, class_name.text.decode("UTF-8")
|
|
352
|
+
node = node.parent
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def get_nodes(root_node=None, node_list={}, graph_node_list=[], index={}, records={}):
|
|
356
|
+
"""
|
|
357
|
+
Returns statement level nodes recursively from the concrete syntax tree passed to it. Uses records to maintain required supplementary information.
|
|
358
|
+
noe_list maintains an intermediate representation and graph_node_list returns the final list.
|
|
359
|
+
"""
|
|
360
|
+
|
|
361
|
+
if (
|
|
362
|
+
root_node.type == "parenthesized_expression"
|
|
363
|
+
and root_node.parent is not None
|
|
364
|
+
and root_node.parent.type == "do_statement"
|
|
365
|
+
):
|
|
366
|
+
label = "while" + root_node.text.decode("UTF-8")
|
|
367
|
+
type_label = "while"
|
|
368
|
+
node_list[(root_node.start_point, root_node.end_point, root_node.type)] = (
|
|
369
|
+
root_node
|
|
370
|
+
)
|
|
371
|
+
graph_node_list.append(
|
|
372
|
+
(
|
|
373
|
+
index[(root_node.start_point, root_node.end_point, root_node.type)],
|
|
374
|
+
root_node.start_point[0],
|
|
375
|
+
label,
|
|
376
|
+
type_label,
|
|
377
|
+
)
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
elif root_node.type == "catch_clause":
|
|
381
|
+
node_list[(root_node.start_point, root_node.end_point, root_node.type)] = (
|
|
382
|
+
root_node
|
|
383
|
+
)
|
|
384
|
+
catch_parameter = list(
|
|
385
|
+
filter(
|
|
386
|
+
lambda child: child.type == "catch_formal_parameter", root_node.children
|
|
387
|
+
)
|
|
388
|
+
)
|
|
389
|
+
label = "catch (" + catch_parameter[0].text.decode("UTF-8") + ")"
|
|
390
|
+
type_label = "catch"
|
|
391
|
+
graph_node_list.append(
|
|
392
|
+
(
|
|
393
|
+
index[(root_node.start_point, root_node.end_point, root_node.type)],
|
|
394
|
+
root_node.start_point[0],
|
|
395
|
+
label,
|
|
396
|
+
type_label,
|
|
397
|
+
)
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
elif root_node.type == "finally_clause":
|
|
401
|
+
node_list[(root_node.start_point, root_node.end_point, root_node.type)] = (
|
|
402
|
+
root_node
|
|
403
|
+
)
|
|
404
|
+
label = "finally"
|
|
405
|
+
type_label = "finally"
|
|
406
|
+
graph_node_list.append(
|
|
407
|
+
(
|
|
408
|
+
index[(root_node.start_point, root_node.end_point, root_node.type)],
|
|
409
|
+
root_node.start_point[0],
|
|
410
|
+
label,
|
|
411
|
+
type_label,
|
|
412
|
+
)
|
|
413
|
+
)
|
|
414
|
+
|
|
415
|
+
elif root_node.type in statement_types["node_list_type"]:
|
|
416
|
+
if (
|
|
417
|
+
root_node.type in statement_types["inner_node_type"]
|
|
418
|
+
and root_node.parent is not None
|
|
419
|
+
and root_node.parent.type in statement_types["outer_node_type"]
|
|
420
|
+
and root_node.parent.child_by_field_name("body") != root_node
|
|
421
|
+
):
|
|
422
|
+
pass
|
|
423
|
+
# If it has a parent and the parent is a for loop type and it is an initialization or update statement, omit it
|
|
424
|
+
elif (
|
|
425
|
+
root_node.type in statement_types["inner_node_type"]
|
|
426
|
+
and return_switch_child(root_node) is not None
|
|
427
|
+
):
|
|
428
|
+
# There is a switch expression in the subtree starting from this statement_node
|
|
429
|
+
switch_child = return_switch_child(root_node)
|
|
430
|
+
child_index = index[
|
|
431
|
+
(switch_child.start_point, switch_child.end_point, switch_child.type)
|
|
432
|
+
]
|
|
433
|
+
current_index = index[
|
|
434
|
+
(root_node.start_point, root_node.end_point, root_node.type)
|
|
435
|
+
]
|
|
436
|
+
records["switch_child_map"][current_index] = child_index
|
|
437
|
+
else:
|
|
438
|
+
node_list[(root_node.start_point, root_node.end_point, root_node.type)] = (
|
|
439
|
+
root_node
|
|
440
|
+
)
|
|
441
|
+
# Set default label values for the node and then modify based on node type if required in the following if-else ladder
|
|
442
|
+
label = root_node.text.decode("UTF-8")
|
|
443
|
+
type_label = "expression_statement"
|
|
444
|
+
if (
|
|
445
|
+
check_anonymous_class(root_node)
|
|
446
|
+
and root_node.type not in statement_types["definition_types"]
|
|
447
|
+
):
|
|
448
|
+
try:
|
|
449
|
+
label = label.split("{")[0] + label.split("}")[-1]
|
|
450
|
+
except:
|
|
451
|
+
# print("INCORRECT anonymous class label", label)
|
|
452
|
+
pass
|
|
453
|
+
# elif check_lambda(root_node) and root_node.type not in statement_types["definition_types"]:
|
|
454
|
+
elif (
|
|
455
|
+
check_lambda(root_node)
|
|
456
|
+
and root_node.type not in statement_types["definition_types"]
|
|
457
|
+
):
|
|
458
|
+
raw_label = root_node.text.decode("utf-8")
|
|
459
|
+
|
|
460
|
+
label = ""
|
|
461
|
+
for lambda_expression in get_all_lambda_body(root_node):
|
|
462
|
+
split_label = raw_label.split(
|
|
463
|
+
lambda_expression.text.decode("utf-8"), 2
|
|
464
|
+
)
|
|
465
|
+
raw_label = split_label[0]
|
|
466
|
+
if len(split_label) > 1:
|
|
467
|
+
label = split_label[1] + label
|
|
468
|
+
lambda_node = (
|
|
469
|
+
lambda_expression.start_point,
|
|
470
|
+
lambda_expression.end_point,
|
|
471
|
+
lambda_expression.type,
|
|
472
|
+
)
|
|
473
|
+
records["lambda_map"][lambda_node] = root_node
|
|
474
|
+
label = raw_label + label
|
|
475
|
+
|
|
476
|
+
elif root_node.type == "lambda_expression":
|
|
477
|
+
try:
|
|
478
|
+
if "{" in label:
|
|
479
|
+
label = label.split("{")[0] + label.split("}")[-1]
|
|
480
|
+
else:
|
|
481
|
+
label = root_node.text.decode("utf-8")
|
|
482
|
+
except:
|
|
483
|
+
raise Exception("INCORRECT lambda expression label", label)
|
|
484
|
+
# print("INCORRECT lambda expression label", label)
|
|
485
|
+
|
|
486
|
+
elif (
|
|
487
|
+
root_node.type == "method_declaration"
|
|
488
|
+
or root_node.type == "constructor_declaration"
|
|
489
|
+
):
|
|
490
|
+
label = ""
|
|
491
|
+
for child in root_node.children:
|
|
492
|
+
if child.type != "block" and child.type != "constructor_body":
|
|
493
|
+
label = label + " " + child.text.decode("utf-8")
|
|
494
|
+
method_name = list(
|
|
495
|
+
filter(lambda child: child.type == "identifier", root_node.children)
|
|
496
|
+
)
|
|
497
|
+
method_name = method_name[0].text.decode("UTF-8")
|
|
498
|
+
method_index = index[
|
|
499
|
+
(root_node.start_point, root_node.end_point, root_node.type)
|
|
500
|
+
]
|
|
501
|
+
type_label = root_node.type
|
|
502
|
+
try:
|
|
503
|
+
signature = get_signature(root_node)
|
|
504
|
+
class_index, class_name_list = get_class_name(root_node, index)
|
|
505
|
+
if method_name == "main":
|
|
506
|
+
records["main_method"] = method_index
|
|
507
|
+
records["main_class"] = class_index
|
|
508
|
+
if abstract_method(root_node) == False:
|
|
509
|
+
for class_name in class_name_list:
|
|
510
|
+
if root_node.type == "constructor_declaration":
|
|
511
|
+
if class_name == method_name:
|
|
512
|
+
records["constructor_list"][
|
|
513
|
+
((class_name, method_name), signature)
|
|
514
|
+
] = method_index
|
|
515
|
+
return_type = None
|
|
516
|
+
else:
|
|
517
|
+
records["method_list"][
|
|
518
|
+
((class_name, method_name), signature)
|
|
519
|
+
] = method_index
|
|
520
|
+
try:
|
|
521
|
+
return_type = list(
|
|
522
|
+
filter(
|
|
523
|
+
lambda child: child.type
|
|
524
|
+
in method_return_types,
|
|
525
|
+
root_node.children,
|
|
526
|
+
)
|
|
527
|
+
)
|
|
528
|
+
return_type = return_type[0].text.decode("UTF-8")
|
|
529
|
+
except:
|
|
530
|
+
raise Exception(
|
|
531
|
+
"No return type found for method, update method_return_types",
|
|
532
|
+
method_name,
|
|
533
|
+
)
|
|
534
|
+
|
|
535
|
+
records["return_type"][
|
|
536
|
+
((class_name, method_name), signature)
|
|
537
|
+
] = return_type
|
|
538
|
+
|
|
539
|
+
except:
|
|
540
|
+
pass
|
|
541
|
+
graph_node_list.append(
|
|
542
|
+
(method_index, root_node.start_point[0], label, type_label)
|
|
543
|
+
)
|
|
544
|
+
elif (
|
|
545
|
+
root_node.type
|
|
546
|
+
== "class_declaration"
|
|
547
|
+
# or root_node.type == "constructor_declaration"
|
|
548
|
+
):
|
|
549
|
+
modifiers = list(
|
|
550
|
+
filter(lambda child: child.type != "class_body", root_node.children)
|
|
551
|
+
)
|
|
552
|
+
class_name = list(
|
|
553
|
+
filter(lambda child: child.type == "identifier", root_node.children)
|
|
554
|
+
)[0].text.decode("UTF-8")
|
|
555
|
+
label = ""
|
|
556
|
+
for modifier in modifiers:
|
|
557
|
+
label = label + modifier.text.decode("UTF-8") + " "
|
|
558
|
+
type_label = root_node.type
|
|
559
|
+
class_index = index[
|
|
560
|
+
(root_node.start_point, root_node.end_point, root_node.type)
|
|
561
|
+
]
|
|
562
|
+
records["class_list"][class_name] = class_index
|
|
563
|
+
|
|
564
|
+
superclass_node = get_child_of_type(root_node, ["superclass"])
|
|
565
|
+
if superclass_node is not None:
|
|
566
|
+
parent_name = get_child_of_type(
|
|
567
|
+
superclass_node,
|
|
568
|
+
["type_identifier", "generic_type", "scoped_type_identifier"],
|
|
569
|
+
).text.decode("UTF-8")
|
|
570
|
+
try:
|
|
571
|
+
records["extends"][class_name].append(parent_name)
|
|
572
|
+
except:
|
|
573
|
+
records["extends"][class_name] = [parent_name]
|
|
574
|
+
|
|
575
|
+
elif root_node.type == "interface_declaration":
|
|
576
|
+
definition = list(
|
|
577
|
+
filter(
|
|
578
|
+
lambda child: child.type != "interface_body",
|
|
579
|
+
root_node.children,
|
|
580
|
+
)
|
|
581
|
+
)
|
|
582
|
+
label = ""
|
|
583
|
+
for x in definition:
|
|
584
|
+
label = label + x.text.decode("UTF-8") + " "
|
|
585
|
+
|
|
586
|
+
type_label = "interface_declaration"
|
|
587
|
+
|
|
588
|
+
elif root_node.type == "if_statement":
|
|
589
|
+
condition = list(
|
|
590
|
+
filter(
|
|
591
|
+
lambda child: child.type == "parenthesized_expression",
|
|
592
|
+
root_node.children,
|
|
593
|
+
)
|
|
594
|
+
)
|
|
595
|
+
label = "if" + condition[0].text.decode("UTF-8")
|
|
596
|
+
type_label = "if"
|
|
597
|
+
|
|
598
|
+
elif root_node.type == "for_statement":
|
|
599
|
+
try:
|
|
600
|
+
init = root_node.child_by_field_name("init").text.decode("UTF-8")
|
|
601
|
+
if init[-1] != ";":
|
|
602
|
+
init = init + ";"
|
|
603
|
+
except:
|
|
604
|
+
init = ""
|
|
605
|
+
try:
|
|
606
|
+
condition = root_node.child_by_field_name("condition").text.decode(
|
|
607
|
+
"UTF-8"
|
|
608
|
+
)
|
|
609
|
+
except:
|
|
610
|
+
condition = ""
|
|
611
|
+
try:
|
|
612
|
+
update = root_node.child_by_field_name("update").text.decode(
|
|
613
|
+
"UTF-8"
|
|
614
|
+
)
|
|
615
|
+
except:
|
|
616
|
+
update = ""
|
|
617
|
+
label = "for(" + init + condition + ";" + update + ")"
|
|
618
|
+
type_label = "for"
|
|
619
|
+
|
|
620
|
+
elif root_node.type == "enhanced_for_statement":
|
|
621
|
+
try:
|
|
622
|
+
modifiers = str(
|
|
623
|
+
list(
|
|
624
|
+
filter(
|
|
625
|
+
lambda child: child.type == "modifiers",
|
|
626
|
+
root_node.children,
|
|
627
|
+
)
|
|
628
|
+
)
|
|
629
|
+
)
|
|
630
|
+
modifier = modifiers[0].text.decode("UTF-8")
|
|
631
|
+
except:
|
|
632
|
+
modifier = ""
|
|
633
|
+
try:
|
|
634
|
+
types = root_node.child_by_field_name("type").text.decode("UTF-8")
|
|
635
|
+
except:
|
|
636
|
+
types = ""
|
|
637
|
+
|
|
638
|
+
try:
|
|
639
|
+
variables = list(
|
|
640
|
+
filter(
|
|
641
|
+
lambda child: child.type == "identifier", root_node.children
|
|
642
|
+
)
|
|
643
|
+
)
|
|
644
|
+
variable = variables[0].text.decode("UTF-8")
|
|
645
|
+
except:
|
|
646
|
+
variable = ""
|
|
647
|
+
try:
|
|
648
|
+
value = root_node.child_by_field_name("value").text.decode("UTF-8")
|
|
649
|
+
except:
|
|
650
|
+
value = ""
|
|
651
|
+
label = (
|
|
652
|
+
"for(" + modifier + " " + types + " " + variable + ":" + value + ")"
|
|
653
|
+
)
|
|
654
|
+
type_label = "for"
|
|
655
|
+
|
|
656
|
+
elif root_node.type == "while_statement":
|
|
657
|
+
condition = list(
|
|
658
|
+
filter(
|
|
659
|
+
lambda child: child.type == "parenthesized_expression",
|
|
660
|
+
root_node.children,
|
|
661
|
+
)
|
|
662
|
+
)
|
|
663
|
+
label = "while" + condition[0].text.decode("UTF-8")
|
|
664
|
+
type_label = "while"
|
|
665
|
+
|
|
666
|
+
elif root_node.type == "do_statement":
|
|
667
|
+
label = "do"
|
|
668
|
+
type_label = "do"
|
|
669
|
+
|
|
670
|
+
elif root_node.type == "switch_expression":
|
|
671
|
+
parent_statement = return_switch_parent(
|
|
672
|
+
root_node, statement_types["non_control_statement"]
|
|
673
|
+
)
|
|
674
|
+
if parent_statement is not None:
|
|
675
|
+
label = parent_statement.text.decode("UTF-8").split("{")[0]
|
|
676
|
+
else:
|
|
677
|
+
condition = list(
|
|
678
|
+
filter(
|
|
679
|
+
lambda child: child.type == "parenthesized_expression",
|
|
680
|
+
root_node.children,
|
|
681
|
+
)
|
|
682
|
+
)
|
|
683
|
+
label = "switch" + condition[0].text.decode("UTF-8")
|
|
684
|
+
type_label = "switch"
|
|
685
|
+
|
|
686
|
+
elif (
|
|
687
|
+
root_node.type == "switch_block_statement_group"
|
|
688
|
+
or root_node.type == "switch_rule"
|
|
689
|
+
):
|
|
690
|
+
case_label = list(
|
|
691
|
+
filter(
|
|
692
|
+
lambda child: child.type == "switch_label", root_node.children
|
|
693
|
+
)
|
|
694
|
+
)
|
|
695
|
+
label = case_label[0].text.decode("UTF-8") + ":"
|
|
696
|
+
type_label = "case"
|
|
697
|
+
|
|
698
|
+
elif (
|
|
699
|
+
root_node.type == "try_statement"
|
|
700
|
+
or root_node.type == "try_with_resources_statement"
|
|
701
|
+
):
|
|
702
|
+
label = "try"
|
|
703
|
+
type_label = "try"
|
|
704
|
+
|
|
705
|
+
elif root_node.type == "synchronized_statement":
|
|
706
|
+
condition = list(
|
|
707
|
+
filter(
|
|
708
|
+
lambda child: child.type == "parenthesized_expression",
|
|
709
|
+
root_node.children,
|
|
710
|
+
)
|
|
711
|
+
)
|
|
712
|
+
label = "synchronized " + condition[0].text.decode("UTF-8")
|
|
713
|
+
type_label = "synchronized"
|
|
714
|
+
elif root_node.type == "labeled_statement":
|
|
715
|
+
name = list(
|
|
716
|
+
filter(lambda child: child.type == "identifier", root_node.children)
|
|
717
|
+
)
|
|
718
|
+
label = name[0].text.decode("UTF-8") + ":"
|
|
719
|
+
records["label_statement_map"][label] = (
|
|
720
|
+
root_node.start_point,
|
|
721
|
+
root_node.end_point,
|
|
722
|
+
root_node.type,
|
|
723
|
+
)
|
|
724
|
+
type_label = "label"
|
|
725
|
+
elif root_node.type == "return_statement":
|
|
726
|
+
if has_inner_definition(root_node):
|
|
727
|
+
label = "return"
|
|
728
|
+
else:
|
|
729
|
+
label = root_node.text.decode("UTF-8")
|
|
730
|
+
type_label = "return"
|
|
731
|
+
|
|
732
|
+
if (
|
|
733
|
+
root_node.type != "method_declaration"
|
|
734
|
+
and root_node.type != "constructor_declaration"
|
|
735
|
+
):
|
|
736
|
+
graph_node_list.append(
|
|
737
|
+
(
|
|
738
|
+
index[
|
|
739
|
+
(root_node.start_point, root_node.end_point, root_node.type)
|
|
740
|
+
],
|
|
741
|
+
root_node.start_point[0],
|
|
742
|
+
label,
|
|
743
|
+
type_label,
|
|
744
|
+
)
|
|
745
|
+
)
|
|
746
|
+
|
|
747
|
+
for child in root_node.children:
|
|
748
|
+
root_node, node_list, graph_node_list, records = get_nodes(
|
|
749
|
+
root_node=child,
|
|
750
|
+
node_list=node_list,
|
|
751
|
+
graph_node_list=graph_node_list,
|
|
752
|
+
index=index,
|
|
753
|
+
records=records,
|
|
754
|
+
)
|
|
755
|
+
|
|
756
|
+
return root_node, node_list, graph_node_list, records
|