mirror of https://github.com/m-labs/artiq.git
transforms/unroll_loops: count statements in try blocks
This commit is contained in:
parent
2b948ba267
commit
7289c18a42
|
@ -4,12 +4,19 @@ from artiq.transforms.tools import eval_ast, value_to_ast
|
|||
|
||||
|
||||
def _count_stmts(node):
|
||||
if isinstance(node, (ast.For, ast.While, ast.If)):
|
||||
return 1 + _count_stmts(node.body) + _count_stmts(node.orelse)
|
||||
if isinstance(node, list):
|
||||
return sum(map(_count_stmts, node))
|
||||
elif isinstance(node, ast.With):
|
||||
return 1 + _count_stmts(node.body)
|
||||
elif isinstance(node, list):
|
||||
return sum(map(_count_stmts, node))
|
||||
elif isinstance(node, (ast.For, ast.While, ast.If)):
|
||||
return 1 + _count_stmts(node.body) + _count_stmts(node.orelse)
|
||||
elif isinstance(node, ast.Try):
|
||||
r = 1 + _count_stmts(node.body) \
|
||||
+ _count_stmts(node.orelse) \
|
||||
+ _count_stmts(node.finalbody)
|
||||
for handler in node.handlers:
|
||||
r += 1 + _count_stmts(handler.body)
|
||||
return r
|
||||
else:
|
||||
return 1
|
||||
|
||||
|
|
Loading…
Reference in New Issue