1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/internal_tests/branches.py Tue Aug 30 16:51:10 2016 +0200
1.3 @@ -0,0 +1,627 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +import branching
1.7 +
1.8 +names = []
1.9 +
1.10 +# Equivalent to...
1.11 +#
1.12 +# a = ...
1.13 +# a.p
1.14 +# if ...:
1.15 +# a = ...
1.16 +# a.x
1.17 +# else:
1.18 +# ...
1.19 +# a.q
1.20 +
1.21 +bt = branching.BranchTracker()
1.22 +a1 = bt.assign_names(["a"])
1.23 +bt.use_attribute("a", "p")
1.24 +bt.new_branchpoint() # begin
1.25 +bt.new_branch() # if ...
1.26 +a2 = bt.assign_names(["a"]) # a = ...
1.27 +ax = bt.use_attribute("a", "x")
1.28 +bt.shelve_branch()
1.29 +bt.new_branch() # else
1.30 +bt.shelve_branch()
1.31 +bt.merge_branches() # end
1.32 +aq = bt.use_attribute("a", "q")
1.33 +
1.34 +print a1.get_usage() == \
1.35 + {'a' : set([('p',), ('p', 'q')])}, \
1.36 + a1.get_usage()
1.37 +print a2.get_usage() == \
1.38 + {'a' : set([('q', 'x')])}, \
1.39 + a2.get_usage()
1.40 +print bt.get_assignment_positions_for_branches("a", ax) == [1], \
1.41 + bt.get_assignment_positions_for_branches("a", ax)
1.42 +print bt.get_assignment_positions_for_branches("a", aq) == [0, 1], \
1.43 + bt.get_assignment_positions_for_branches("a", aq)
1.44 +names.append(bt.assignments["a"])
1.45 +
1.46 +# Equivalent to...
1.47 +#
1.48 +# a = ...
1.49 +# a.p
1.50 +# if ...:
1.51 +# a.x
1.52 +# elif ...:
1.53 +# a.y; a.z
1.54 +# else:
1.55 +# ...
1.56 +# a.q
1.57 +
1.58 +bt = branching.BranchTracker()
1.59 +a = bt.assign_names(["a"])
1.60 +bt.use_attribute("a", "p")
1.61 +bt.new_branchpoint() # begin
1.62 +bt.new_branch() # if ...
1.63 +ax = bt.use_attribute("a", "x")
1.64 +bt.shelve_branch()
1.65 +bt.new_branch() # elif ...
1.66 +ay = bt.use_attribute("a", "y")
1.67 +az = bt.use_attribute("a", "z")
1.68 +bt.shelve_branch()
1.69 +bt.new_branch() # else
1.70 +bt.shelve_branch()
1.71 +bt.merge_branches() # end
1.72 +bt.use_attribute("a", "q")
1.73 +
1.74 +print a.get_usage() == \
1.75 + {'a' : set([('p', 'q'), ('p', 'q', 'x'), ('p', 'q', 'y', 'z')])}, \
1.76 + a.get_usage()
1.77 +print bt.get_assignment_positions_for_branches("a", ax) == [0], \
1.78 + bt.get_assignment_positions_for_branches("a", ax)
1.79 +print bt.get_assignment_positions_for_branches("a", ay) == [0], \
1.80 + bt.get_assignment_positions_for_branches("a", ay)
1.81 +print bt.get_assignment_positions_for_branches("a", az) == [0], \
1.82 + bt.get_assignment_positions_for_branches("a", az)
1.83 +names.append(bt.assignments["a"])
1.84 +
1.85 +# Equivalent to...
1.86 +#
1.87 +# a = ...
1.88 +# a.p
1.89 +# while ...:
1.90 +# a.x
1.91 +# a.q
1.92 +
1.93 +bt = branching.BranchTracker()
1.94 +a = bt.assign_names(["a"])
1.95 +bt.use_attribute("a", "p")
1.96 +bt.new_branchpoint(True) # begin
1.97 +bt.new_branch(True) # while ...
1.98 +ax = bt.use_attribute("a", "x")
1.99 +bt.resume_continuing_branches()
1.100 +bt.shelve_branch(True)
1.101 +bt.new_branch() # (null)
1.102 +bt.shelve_branch()
1.103 +bt.merge_branches() # end
1.104 +bt.resume_broken_branches()
1.105 +bt.use_attribute("a", "q")
1.106 +
1.107 +print a.get_usage() == \
1.108 + {'a' : set([('p', 'q'), ('p', 'q', 'x')])}, a.get_usage()
1.109 +print bt.get_assignment_positions_for_branches("a", ax) == [0], \
1.110 + bt.get_assignment_positions_for_branches("a", ax)
1.111 +names.append(bt.assignments["a"])
1.112 +
1.113 +# Equivalent to...
1.114 +#
1.115 +# a = ...
1.116 +# a.p
1.117 +# while ...:
1.118 +# if ...:
1.119 +# a.x
1.120 +# else ...:
1.121 +# a.y
1.122 +# a.q
1.123 +
1.124 +bt = branching.BranchTracker()
1.125 +a = bt.assign_names(["a"])
1.126 +bt.use_attribute("a", "p")
1.127 +bt.new_branchpoint(True) # begin
1.128 +bt.new_branch(True) # while ...
1.129 +bt.new_branchpoint() # begin
1.130 +bt.new_branch() # if ...
1.131 +ax = bt.use_attribute("a", "x")
1.132 +bt.shelve_branch()
1.133 +bt.new_branch()
1.134 +ay = bt.use_attribute("a", "y")
1.135 +bt.shelve_branch()
1.136 +bt.merge_branches() # end
1.137 +bt.resume_continuing_branches()
1.138 +bt.shelve_branch(True)
1.139 +bt.new_branch() # (null)
1.140 +bt.shelve_branch()
1.141 +bt.merge_branches() # end
1.142 +bt.resume_broken_branches()
1.143 +bt.use_attribute("a", "q")
1.144 +
1.145 +print a.get_usage() == \
1.146 + {'a' : set([('p', 'q'), ('p', 'q', 'x'), ('p', 'q', 'y')])}, \
1.147 + a.get_usage()
1.148 +print bt.get_assignment_positions_for_branches("a", ax) == [0], \
1.149 + bt.get_assignment_positions_for_branches("a", ax)
1.150 +print bt.get_assignment_positions_for_branches("a", ay) == [0], \
1.151 + bt.get_assignment_positions_for_branches("a", ay)
1.152 +names.append(bt.assignments["a"])
1.153 +
1.154 +# Equivalent to...
1.155 +#
1.156 +# a = ...
1.157 +# a.p
1.158 +# while ...:
1.159 +# if ...:
1.160 +# a = ...
1.161 +# a.x
1.162 +# else ...:
1.163 +# a.y
1.164 +# a.q
1.165 +
1.166 +bt = branching.BranchTracker()
1.167 +a1 = bt.assign_names(["a"])
1.168 +bt.use_attribute("a", "p")
1.169 +bt.new_branchpoint(True) # begin
1.170 +bt.new_branch(True) # while ...
1.171 +bt.new_branchpoint() # begin
1.172 +bt.new_branch() # if ...
1.173 +a2 = bt.assign_names(["a"]) # a = ...
1.174 +ax = bt.use_attribute("a", "x")
1.175 +bt.shelve_branch()
1.176 +bt.new_branch()
1.177 +ay = bt.use_attribute("a", "y")
1.178 +bt.shelve_branch()
1.179 +bt.merge_branches() # end
1.180 +bt.resume_continuing_branches()
1.181 +bt.shelve_branch(True)
1.182 +bt.new_branch() # (null)
1.183 +bt.shelve_branch()
1.184 +bt.merge_branches() # end
1.185 +bt.resume_broken_branches()
1.186 +bt.use_attribute("a", "q")
1.187 +
1.188 +print a1.get_usage() == \
1.189 + {'a' : set([('p', 'q'), ('p', 'q', 'y'), ('p',)])}, a1.get_usage()
1.190 +print a2.get_usage() == \
1.191 + {'a' : set([('q', 'x')])}, a2.get_usage()
1.192 +print bt.get_assignment_positions_for_branches("a", ax) == [1], \
1.193 + bt.get_assignment_positions_for_branches("a", ax)
1.194 +print bt.get_assignment_positions_for_branches("a", ay) == [0, 1], \
1.195 + bt.get_assignment_positions_for_branches("a", ay)
1.196 +names.append(bt.assignments["a"])
1.197 +
1.198 +# Equivalent to...
1.199 +#
1.200 +# a = ...
1.201 +# a.p
1.202 +# while ...:
1.203 +# if ...:
1.204 +# a.y
1.205 +# else ...:
1.206 +# a = ...
1.207 +# a.x
1.208 +# a.q
1.209 +
1.210 +bt = branching.BranchTracker()
1.211 +a1 = bt.assign_names(["a"])
1.212 +bt.use_attribute("a", "p")
1.213 +bt.new_branchpoint(True) # begin
1.214 +bt.new_branch(True) # while ...
1.215 +bt.new_branchpoint() # begin
1.216 +bt.new_branch() # if ...
1.217 +ay = bt.use_attribute("a", "y")
1.218 +bt.shelve_branch()
1.219 +bt.new_branch()
1.220 +a2 = bt.assign_names(["a"]) # a = ...
1.221 +ax = bt.use_attribute("a", "x")
1.222 +bt.shelve_branch()
1.223 +bt.merge_branches() # end
1.224 +bt.resume_continuing_branches()
1.225 +bt.shelve_branch(True)
1.226 +bt.new_branch() # (null)
1.227 +bt.shelve_branch()
1.228 +bt.merge_branches() # end
1.229 +bt.resume_broken_branches()
1.230 +bt.use_attribute("a", "q")
1.231 +
1.232 +print a1.get_usage() == \
1.233 + {'a' : set([('p', 'q'), ('p', 'q', 'y'), ('p',)])}, a1.get_usage()
1.234 +print a2.get_usage() == \
1.235 + {'a' : set([('q', 'x')])}, a2.get_usage()
1.236 +print bt.get_assignment_positions_for_branches("a", ax) == [1], \
1.237 + bt.get_assignment_positions_for_branches("a", ax)
1.238 +print bt.get_assignment_positions_for_branches("a", ay) == [0, 1], \
1.239 + bt.get_assignment_positions_for_branches("a", ay)
1.240 +names.append(bt.assignments["a"])
1.241 +
1.242 +# Equivalent to...
1.243 +#
1.244 +# a = ...
1.245 +# a.p
1.246 +# while ...:
1.247 +# a = ...
1.248 +# a.x
1.249 +# a.q
1.250 +
1.251 +bt = branching.BranchTracker()
1.252 +a1 = bt.assign_names(["a"])
1.253 +ap = bt.use_attribute("a", "p")
1.254 +bt.new_branchpoint(True) # begin
1.255 +bt.new_branch(True) # while ...
1.256 +a2 = bt.assign_names(["a"]) # a = ...
1.257 +ax = bt.use_attribute("a", "x")
1.258 +bt.resume_continuing_branches()
1.259 +bt.shelve_branch(True)
1.260 +bt.new_branch() # (null)
1.261 +bt.shelve_branch()
1.262 +bt.merge_branches() # end
1.263 +bt.resume_broken_branches()
1.264 +aq = bt.use_attribute("a", "q")
1.265 +
1.266 +print a1.get_usage() == \
1.267 + {'a' : set([('p', 'q'), ('p',)])}, a1.get_usage()
1.268 +print a2.get_usage() == \
1.269 + {'a' : set([('q', 'x')])}, a2.get_usage()
1.270 +print bt.get_assignment_positions_for_branches("a", ax) == [1], \
1.271 + bt.get_assignment_positions_for_branches("a", ax)
1.272 +print bt.get_assignment_positions_for_branches("a", ap) == [0], \
1.273 + bt.get_assignment_positions_for_branches("a", ap)
1.274 +print bt.get_assignment_positions_for_branches("a", aq) == [0, 1], \
1.275 + bt.get_assignment_positions_for_branches("a", aq)
1.276 +names.append(bt.assignments["a"])
1.277 +
1.278 +# Equivalent to...
1.279 +#
1.280 +# a = ...
1.281 +# a.p
1.282 +# while ...:
1.283 +# if ...:
1.284 +# break
1.285 +# a.q
1.286 +# a.r
1.287 +
1.288 +bt = branching.BranchTracker()
1.289 +a1 = bt.assign_names(["a"])
1.290 +bt.use_attribute("a", "p")
1.291 +bt.new_branchpoint(True) # begin
1.292 +bt.new_branch(True) # while ...
1.293 +bt.new_branchpoint() # begin
1.294 +bt.new_branch() # if ...
1.295 +bt.suspend_broken_branch() # break
1.296 +bt.shelve_branch()
1.297 +bt.new_branch() # (null)
1.298 +bt.shelve_branch()
1.299 +bt.merge_branches() # end
1.300 +bt.use_attribute("a", "q")
1.301 +bt.resume_continuing_branches()
1.302 +bt.shelve_branch(True)
1.303 +bt.merge_branches() # end
1.304 +bt.resume_broken_branches()
1.305 +bt.use_attribute("a", "r")
1.306 +
1.307 +print a1.get_usage() == \
1.308 + {'a' : set([('p', 'q', 'r'), ('p', 'r')])}, a1.get_usage()
1.309 +names.append(bt.assignments["a"])
1.310 +
1.311 +# Equivalent to...
1.312 +#
1.313 +# a = ...
1.314 +# a.p and a.q and a.r
1.315 +
1.316 +bt = branching.BranchTracker()
1.317 +a1 = bt.assign_names(["a"])
1.318 +bt.new_branchpoint() # begin
1.319 +bt.new_branch()
1.320 +bt.use_attribute("a", "p")
1.321 +bt.new_branchpoint() # begin
1.322 +bt.new_branch()
1.323 +bt.use_attribute("a", "q")
1.324 +bt.new_branchpoint() # begin
1.325 +bt.new_branch()
1.326 +bt.use_attribute("a", "r")
1.327 +bt.shelve_branch()
1.328 +bt.new_branch() # (null)
1.329 +bt.shelve_branch()
1.330 +bt.merge_branches() # end
1.331 +bt.shelve_branch()
1.332 +bt.new_branch() # (null)
1.333 +bt.shelve_branch()
1.334 +bt.merge_branches() # end
1.335 +bt.shelve_branch()
1.336 +bt.merge_branches() # end
1.337 +
1.338 +print a1.get_usage() == \
1.339 + {'a' : set([('p', 'q', 'r'), ('p', 'q'), ('p',)])}, a1.get_usage()
1.340 +names.append(bt.assignments["a"])
1.341 +
1.342 +# Equivalent to...
1.343 +#
1.344 +# a = ...
1.345 +# if ...:
1.346 +# a.p
1.347 +# return
1.348 +# a.q
1.349 +
1.350 +bt = branching.BranchTracker()
1.351 +a1 = bt.assign_names(["a"])
1.352 +bt.new_branchpoint() # begin
1.353 +bt.new_branch() # if ...
1.354 +bt.use_attribute("a", "p")
1.355 +bt.abandon_returning_branch()
1.356 +bt.shelve_branch()
1.357 +bt.new_branch() # (null)
1.358 +bt.shelve_branch()
1.359 +bt.merge_branches() # end
1.360 +bt.use_attribute("a", "q")
1.361 +
1.362 +print a1.get_usage() == \
1.363 + {'a' : set([('p',), ('q',)])}, a1.get_usage()
1.364 +names.append(bt.assignments["a"])
1.365 +
1.366 +# Equivalent to...
1.367 +#
1.368 +# a = ...
1.369 +# try:
1.370 +# if ...:
1.371 +# a.p
1.372 +# return
1.373 +# a.q
1.374 +# except:
1.375 +# a.r
1.376 +
1.377 +bt = branching.BranchTracker()
1.378 +a1 = bt.assign_names(["a"])
1.379 +bt.new_branchpoint() # begin (try)
1.380 +bt.new_branchpoint() # begin
1.381 +bt.new_branch() # if ...
1.382 +bt.use_attribute("a", "p")
1.383 +bt.abandon_returning_branch()
1.384 +bt.shelve_branch() # ... if
1.385 +bt.new_branch() # (null)
1.386 +bt.shelve_branch()
1.387 +bt.merge_branches() # end
1.388 +bt.use_attribute("a", "q")
1.389 +bt.resume_abandoned_branches() # except
1.390 +bt.use_attribute("a", "r")
1.391 +bt.shelve_branch()
1.392 +bt.merge_branches() # end
1.393 +
1.394 +print a1.get_usage() == \
1.395 + {'a' : set([('p',), ('q', 'r')])}, a1.get_usage()
1.396 +names.append(bt.assignments["a"])
1.397 +
1.398 +# Equivalent to...
1.399 +#
1.400 +# a = ...
1.401 +# if ...:
1.402 +# a.p
1.403 +# a = ...
1.404 +# if ...:
1.405 +# a.q
1.406 +
1.407 +bt = branching.BranchTracker()
1.408 +a1 = bt.assign_names(["a"])
1.409 +bt.new_branchpoint() # begin
1.410 +bt.new_branch() # if ...
1.411 +ap = bt.use_attribute("a", "p")
1.412 +bt.abandon_branch()
1.413 +bt.shelve_branch() # ... if
1.414 +bt.new_branch() # (null)
1.415 +bt.shelve_branch()
1.416 +bt.merge_branches() # end
1.417 +a2 = bt.assign_names(["a"])
1.418 +bt.new_branchpoint() # begin
1.419 +bt.new_branch() # if ...
1.420 +aq = bt.use_attribute("a", "q")
1.421 +bt.abandon_branch()
1.422 +bt.shelve_branch() # ... if
1.423 +bt.new_branch() # (null)
1.424 +bt.shelve_branch()
1.425 +bt.merge_branches() # end
1.426 +
1.427 +print a1.get_usage() == \
1.428 + {'a' : set([('p',), ()])}, a1.get_usage()
1.429 +print a2.get_usage() == \
1.430 + {'a' : set([('q',), ()])}, a2.get_usage()
1.431 +print bt.get_assignment_positions_for_branches("a", ap) == [0], \
1.432 + bt.get_assignment_positions_for_branches("a", ap)
1.433 +print bt.get_assignment_positions_for_branches("a", aq) == [1], \
1.434 + bt.get_assignment_positions_for_branches("a", aq)
1.435 +names.append(bt.assignments["a"])
1.436 +
1.437 +# Equivalent to...
1.438 +#
1.439 +# a = {}
1.440 +# a.p
1.441 +# if ...:
1.442 +# a = ...
1.443 +# a.x
1.444 +# else:
1.445 +# ...
1.446 +# a.q
1.447 +
1.448 +bt = branching.BranchTracker()
1.449 +a1 = bt.assign_names(["a"], ["<instance>:__builtins__.dict.dict"])
1.450 +ap = bt.use_attribute("a", "p")
1.451 +bt.new_branchpoint() # begin
1.452 +bt.new_branch() # if ...
1.453 +a2 = bt.assign_names(["a"]) # a = ...
1.454 +ax = bt.use_attribute("a", "x")
1.455 +bt.shelve_branch()
1.456 +bt.new_branch() # else
1.457 +bt.shelve_branch()
1.458 +bt.merge_branches() # end
1.459 +aq = bt.use_attribute("a", "q")
1.460 +
1.461 +print a1.get_usage() == \
1.462 + {'a' : set([('p',), ('p', 'q')])}, \
1.463 + a1.get_usage()
1.464 +print a2.get_usage() == \
1.465 + {'a' : set([('q', 'x')])}, \
1.466 + a2.get_usage()
1.467 +print bt.get_assignment_positions_for_branches("a", ap) == [0], \
1.468 + bt.get_assignment_positions_for_branches("a", ap)
1.469 +print bt.get_assignment_positions_for_branches("a", ax) == [1], \
1.470 + bt.get_assignment_positions_for_branches("a", ax)
1.471 +print bt.get_assignment_positions_for_branches("a", aq) == [0, 1], \
1.472 + bt.get_assignment_positions_for_branches("a", aq)
1.473 +names.append(bt.assignments["a"])
1.474 +
1.475 +# Equivalent to...
1.476 +#
1.477 +# if ...:
1.478 +# a = ...
1.479 +# a.x
1.480 +# else:
1.481 +# ...
1.482 +# a.q
1.483 +
1.484 +bt = branching.BranchTracker()
1.485 +bt.new_branchpoint() # begin
1.486 +bt.new_branch() # if ...
1.487 +a1 = bt.assign_names(["a"]) # a = ...
1.488 +ax = bt.use_attribute("a", "x")
1.489 +bt.shelve_branch()
1.490 +bt.new_branch() # else
1.491 +bt.shelve_branch()
1.492 +bt.merge_branches() # end
1.493 +aq = bt.use_attribute("a", "q")
1.494 +
1.495 +print a1.get_usage() == \
1.496 + {'a' : set([('q', 'x')])}, \
1.497 + a1.get_usage()
1.498 +print bt.get_assignment_positions_for_branches("a", aq) == [None, 0], \
1.499 + bt.get_assignment_positions_for_branches("a", aq)
1.500 +names.append(bt.assignments["a"])
1.501 +
1.502 +# Equivalent to...
1.503 +#
1.504 +# if ...:
1.505 +# a = ...
1.506 +# return
1.507 +# a.q
1.508 +
1.509 +bt = branching.BranchTracker()
1.510 +bt.new_branchpoint() # begin
1.511 +bt.new_branch() # if ...
1.512 +a1 = bt.assign_names(["a"])
1.513 +bt.abandon_returning_branch()
1.514 +bt.shelve_branch()
1.515 +bt.new_branch() # (null)
1.516 +bt.shelve_branch()
1.517 +bt.merge_branches() # end
1.518 +aq = bt.use_attribute("a", "q")
1.519 +
1.520 +print a1.get_usage() == \
1.521 + {'a' : set([()])}, a1.get_usage()
1.522 +print bt.get_assignment_positions_for_branches("a", aq) == [None], \
1.523 + bt.get_assignment_positions_for_branches("a", aq)
1.524 +names.append(bt.assignments["a"])
1.525 +
1.526 +# Equivalent to...
1.527 +#
1.528 +# a = ...
1.529 +# try:
1.530 +# if ...:
1.531 +# a.p
1.532 +# return
1.533 +# a.q
1.534 +# finally:
1.535 +# a.r
1.536 +
1.537 +bt = branching.BranchTracker()
1.538 +a1 = bt.assign_names(["a"])
1.539 +bt.new_branchpoint() # begin
1.540 +bt.new_branch() # if ...
1.541 +bt.use_attribute("a", "p")
1.542 +bt.abandon_returning_branch()
1.543 +bt.shelve_branch() # ... if
1.544 +bt.new_branch() # (null)
1.545 +bt.shelve_branch()
1.546 +bt.merge_branches() # end
1.547 +bt.use_attribute("a", "q")
1.548 +branches = bt.resume_all_abandoned_branches()
1.549 +bt.use_attribute("a", "r")
1.550 +bt.restore_active_branches(branches)
1.551 +
1.552 +print a1.get_usage() == \
1.553 + {'a' : set([('p', 'r'), ('q', 'r')])}, a1.get_usage()
1.554 +names.append(bt.assignments["a"])
1.555 +
1.556 +# Equivalent to...
1.557 +#
1.558 +# a = ...
1.559 +# try:
1.560 +# if ...:
1.561 +# a = ...
1.562 +# a.p
1.563 +# return
1.564 +# a.q
1.565 +# finally:
1.566 +# a.r
1.567 +
1.568 +bt = branching.BranchTracker()
1.569 +a1 = bt.assign_names(["a"])
1.570 +bt.new_branchpoint() # begin
1.571 +bt.new_branch() # if ...
1.572 +a2 = bt.assign_names(["a"])
1.573 +bt.use_attribute("a", "p")
1.574 +bt.abandon_returning_branch()
1.575 +bt.shelve_branch() # ... if
1.576 +bt.new_branch() # (null)
1.577 +bt.shelve_branch()
1.578 +bt.merge_branches() # end
1.579 +aq = bt.use_attribute("a", "q")
1.580 +branches = bt.resume_all_abandoned_branches()
1.581 +ar = bt.use_attribute("a", "r")
1.582 +bt.restore_active_branches(branches)
1.583 +
1.584 +print a1.get_usage() == \
1.585 + {'a' : set([(), ('q', 'r')])}, a1.get_usage()
1.586 +print a2.get_usage() == \
1.587 + {'a' : set([('p', 'r')])}, a2.get_usage()
1.588 +print bt.get_assignment_positions_for_branches("a", ar) == [0, 1], \
1.589 + bt.get_assignment_positions_for_branches("a", ar)
1.590 +names.append(bt.assignments["a"])
1.591 +
1.592 +# Equivalent to...
1.593 +#
1.594 +# a = ...
1.595 +# try:
1.596 +# if ...:
1.597 +# a = ...
1.598 +# a.p
1.599 +# return
1.600 +# a.q
1.601 +# except:
1.602 +# a.r
1.603 +
1.604 +bt = branching.BranchTracker()
1.605 +a1 = bt.assign_names(["a"])
1.606 +bt.new_branchpoint() # begin (try)
1.607 +bt.new_branchpoint() # begin
1.608 +bt.new_branch() # if ...
1.609 +a2 = bt.assign_names(["a"])
1.610 +bt.use_attribute("a", "p")
1.611 +bt.abandon_returning_branch()
1.612 +bt.shelve_branch() # ... if
1.613 +bt.new_branch() # (null)
1.614 +bt.shelve_branch()
1.615 +bt.merge_branches() # end
1.616 +bt.use_attribute("a", "q")
1.617 +bt.resume_abandoned_branches() # except
1.618 +ar = bt.use_attribute("a", "r")
1.619 +bt.shelve_branch()
1.620 +bt.merge_branches() # end
1.621 +
1.622 +print a1.get_usage() == \
1.623 + {'a' : set([(), ('q', 'r')])}, a1.get_usage()
1.624 +print a2.get_usage() == \
1.625 + {'a' : set([('p',)])}, a2.get_usage()
1.626 +print bt.get_assignment_positions_for_branches("a", ar) == [0, 1], \
1.627 + bt.get_assignment_positions_for_branches("a", ar)
1.628 +names.append(bt.assignments["a"])
1.629 +
1.630 +# vim: tabstop=4 expandtab shiftwidth=4