mcpp 1.3.2__tar.gz → 1.3.3__tar.gz
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.
- {mcpp-1.3.2/src/mcpp.egg-info → mcpp-1.3.3}/PKG-INFO +1 -1
- {mcpp-1.3.2 → mcpp-1.3.3}/pyproject.toml +1 -1
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/complexity.py +7 -3
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/parse.py +1 -1
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/vulnerability.py +16 -8
- {mcpp-1.3.2 → mcpp-1.3.3/src/mcpp.egg-info}/PKG-INFO +1 -1
- {mcpp-1.3.2 → mcpp-1.3.3}/LICENSE +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/README.md +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/requirements.txt +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/setup.cfg +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/__init__.py +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/__main__.py +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/additional.py +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/assets/__init__.py +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/assets/config.yaml +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/config.py +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/memory.py +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/queries.py +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/smell.py +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp/tree.py +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp.egg-info/SOURCES.txt +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp.egg-info/dependency_links.txt +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp.egg-info/entry_points.txt +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp.egg-info/requires.txt +0 -0
- {mcpp-1.3.2 → mcpp-1.3.3}/src/mcpp.egg-info/top_level.txt +0 -0
|
@@ -43,10 +43,12 @@ def c2(root, sitter, lang, calls=None):
|
|
|
43
43
|
"""number of for, while and do-while loops"""
|
|
44
44
|
loops = {
|
|
45
45
|
"Q_FOR_STMT": Q_FOR_STMT,
|
|
46
|
-
"Q_FOR_RANGE_STMT": Q_FOR_RANGE_STMT,
|
|
47
46
|
"Q_WHILE_STMT": Q_WHILE_STMT,
|
|
48
47
|
"Q_DO_STMT": Q_DO_STMT,
|
|
49
|
-
}
|
|
48
|
+
}
|
|
49
|
+
if lang == "cpp":
|
|
50
|
+
loops.update({"Q_FOR_RANGE_STMT": Q_FOR_RANGE_STMT})
|
|
51
|
+
|
|
50
52
|
sitter.add_queries(loops)
|
|
51
53
|
complexity = 0
|
|
52
54
|
for query in loops.keys():
|
|
@@ -66,10 +68,12 @@ def c3_c4(root, sitter, lang, calls=None):
|
|
|
66
68
|
"""
|
|
67
69
|
loops = {
|
|
68
70
|
"Q_FOR_STMT": Q_FOR_STMT,
|
|
69
|
-
"Q_FOR_RANGE_STMT": Q_FOR_RANGE_STMT,
|
|
70
71
|
"Q_DO_STMT": Q_DO_STMT,
|
|
71
72
|
"Q_WHILE_STMT": Q_WHILE_STMT
|
|
72
73
|
}
|
|
74
|
+
if lang == "cpp":
|
|
75
|
+
loops.update({"Q_FOR_RANGE_STMT": Q_FOR_RANGE_STMT})
|
|
76
|
+
|
|
73
77
|
sitter.add_queries(loops)
|
|
74
78
|
c3_val = 0
|
|
75
79
|
c4_val = 0
|
|
@@ -14,7 +14,7 @@ LANGS = {
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class Sitter(object):
|
|
17
|
-
def __init__(self,
|
|
17
|
+
def __init__(self, *languages):
|
|
18
18
|
self.langs = {k:v for k, v in LANGS.items() if k in languages}
|
|
19
19
|
self.parser = {lang: self._init_parser(lang) for lang in languages}
|
|
20
20
|
self.queries = {}
|
|
@@ -197,15 +197,17 @@ def v6_v7(root, sitter, lang, calls=None):
|
|
|
197
197
|
"Q_DO_STMT": Q_DO_STMT,
|
|
198
198
|
"Q_WHILE_STMT": Q_WHILE_STMT,
|
|
199
199
|
"Q_FOR_STMT": Q_FOR_STMT,
|
|
200
|
-
"Q_FOR_RANGE_STMT": Q_FOR_RANGE_STMT,
|
|
201
200
|
}
|
|
201
|
+
if lang == "cpp":
|
|
202
|
+
queries.update({"Q_FOR_RANGE_STMT": Q_FOR_RANGE_STMT})
|
|
203
|
+
|
|
202
204
|
sitter.add_queries(queries)
|
|
203
205
|
|
|
204
206
|
nested_controls = []
|
|
205
207
|
max_nesting_level = 0
|
|
206
208
|
for q in queries.keys():
|
|
207
209
|
for node in sitter.captures(q, root, lang).get("stmt", []):
|
|
208
|
-
nesting_level = _control_nesting_level(node)
|
|
210
|
+
nesting_level = _control_nesting_level(node, lang)
|
|
209
211
|
if nesting_level > 0:
|
|
210
212
|
nested_controls.append(node)
|
|
211
213
|
max_nesting_level = max(max_nesting_level, nesting_level)
|
|
@@ -216,15 +218,17 @@ def v6_v7(root, sitter, lang, calls=None):
|
|
|
216
218
|
}
|
|
217
219
|
|
|
218
220
|
|
|
219
|
-
def _control_nesting_level(node):
|
|
221
|
+
def _control_nesting_level(node, lang):
|
|
220
222
|
control_types = [
|
|
221
223
|
"if_statement",
|
|
222
224
|
"switch_statement",
|
|
223
225
|
"do_statement",
|
|
224
226
|
"while_statement",
|
|
225
227
|
"for_statement",
|
|
226
|
-
"for_range_loop",
|
|
227
228
|
]
|
|
229
|
+
if lang == "cpp":
|
|
230
|
+
control_types.append("for_range_loop")
|
|
231
|
+
|
|
228
232
|
parent = node.parent
|
|
229
233
|
num_control_ancestors = 0
|
|
230
234
|
while parent is not None:
|
|
@@ -244,9 +248,11 @@ def v8(root, sitter, lang, calls=None):
|
|
|
244
248
|
"Q_DO_STMT": Q_DO_STMT,
|
|
245
249
|
"Q_WHILE_STMT": Q_WHILE_STMT,
|
|
246
250
|
"Q_FOR_STMT": Q_FOR_STMT,
|
|
247
|
-
"Q_FOR_RANGE_STMT": Q_FOR_RANGE_STMT,
|
|
248
251
|
#"Q_CONDITION": Q_CONDITION,
|
|
249
252
|
}
|
|
253
|
+
if lang == "cpp":
|
|
254
|
+
queries.update({"Q_FOR_RANGE_STMT": Q_FOR_RANGE_STMT})
|
|
255
|
+
|
|
250
256
|
sitter.add_queries(queries)
|
|
251
257
|
|
|
252
258
|
# count dependent controls under another control: key = start_byte of parent in function
|
|
@@ -272,13 +278,13 @@ def v8(root, sitter, lang, calls=None):
|
|
|
272
278
|
def _v8_single_query(root, sitter, lang, calls, query, control_dependent_controls, thread_lock):
|
|
273
279
|
tag = "condition" if "Q_CONDITION" in query else "stmt"
|
|
274
280
|
for node in sitter.captures(query, root, lang).get(tag, []):
|
|
275
|
-
parents = _traverse_parent_controls(node)
|
|
281
|
+
parents = _traverse_parent_controls(node, lang)
|
|
276
282
|
if len(parents) > 0:
|
|
277
283
|
with thread_lock:
|
|
278
284
|
control_dependent_controls[parents[-1].start_byte] += 1
|
|
279
285
|
|
|
280
286
|
|
|
281
|
-
def _traverse_parent_controls(node):
|
|
287
|
+
def _traverse_parent_controls(node, lang):
|
|
282
288
|
""" Climb up the AST and emit all control nodes. """
|
|
283
289
|
control_types = [
|
|
284
290
|
"if_statement",
|
|
@@ -286,8 +292,10 @@ def _traverse_parent_controls(node):
|
|
|
286
292
|
"do_statement",
|
|
287
293
|
"while_statement",
|
|
288
294
|
"for_statement",
|
|
289
|
-
"for_range_loop",
|
|
290
295
|
]
|
|
296
|
+
if lang == "cpp":
|
|
297
|
+
control_types.append("for_range_loop")
|
|
298
|
+
|
|
291
299
|
parent_controls = []
|
|
292
300
|
parent = node.parent
|
|
293
301
|
while parent is not None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|