MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / _max_nesting_depth

Function _max_nesting_depth

scripts/code_verify_rules.py:1244–1273  ·  view source on GitHub ↗

Maximum control-flow nesting depth inside a compound_statement. Counts if/else/for/while/do/switch/try blocks. Lambdas reset the counter -- their body is a separate scope.

(body_node)

Source from the content-addressed store, hash-verified

1242
1243
1244def _max_nesting_depth(body_node) -> int:
1245 """Maximum control-flow nesting depth inside a compound_statement.
1246 Counts if/else/for/while/do/switch/try blocks. Lambdas reset the
1247 counter -- their body is a separate scope."""
1248 if body_node is None:
1249 return 0
1250
1251 NESTERS = {
1252 "if_statement",
1253 "for_statement",
1254 "for_range_loop",
1255 "while_statement",
1256 "do_statement",
1257 "switch_statement",
1258 "try_statement",
1259 }
1260 LAMBDA = "lambda_expression"
1261
1262 def walk(n, depth):
1263 best = depth
1264 for c in n.children:
1265 if c.type == LAMBDA:
1266 continue # lambda body is its own scope
1267 if c.type in NESTERS:
1268 best = max(best, walk(c, depth + 1))
1269 else:
1270 best = max(best, walk(c, depth))
1271 return best
1272
1273 return walk(body_node, 0)
1274
1275
1276def _previous_doxygen_brief(node, src: bytes) -> bool:

Callers 1

_cpp_rulesFunction · 0.85

Calls 1

walkFunction · 0.85

Tested by

no test coverage detected