Skip to content

Commit 7289c18

Browse files
committedSep 27, 2014
transforms/unroll_loops: count statements in try blocks
1 parent 2b948ba commit 7289c18

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed
 

‎artiq/transforms/unroll_loops.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44

55

66
def _count_stmts(node):
7-
if isinstance(node, (ast.For, ast.While, ast.If)):
8-
return 1 + _count_stmts(node.body) + _count_stmts(node.orelse)
7+
if isinstance(node, list):
8+
return sum(map(_count_stmts, node))
99
elif isinstance(node, ast.With):
1010
return 1 + _count_stmts(node.body)
11-
elif isinstance(node, list):
12-
return sum(map(_count_stmts, node))
11+
elif isinstance(node, (ast.For, ast.While, ast.If)):
12+
return 1 + _count_stmts(node.body) + _count_stmts(node.orelse)
13+
elif isinstance(node, ast.Try):
14+
r = 1 + _count_stmts(node.body) \
15+
+ _count_stmts(node.orelse) \
16+
+ _count_stmts(node.finalbody)
17+
for handler in node.handlers:
18+
r += 1 + _count_stmts(handler.body)
19+
return r
1320
else:
1421
return 1
1522

0 commit comments

Comments
 (0)
Please sign in to comment.