(code)
| 1308 | return uval >> 1 |
| 1309 | |
| 1310 | def parse_location_table(code): |
| 1311 | line = code.co_firstlineno |
| 1312 | it = iter(code.co_linetable) |
| 1313 | while True: |
| 1314 | try: |
| 1315 | first_byte = read(it) |
| 1316 | except StopIteration: |
| 1317 | return |
| 1318 | code = (first_byte >> 3) & 15 |
| 1319 | length = (first_byte & 7) + 1 |
| 1320 | if code == 15: |
| 1321 | yield (code, length, None, None, None, None) |
| 1322 | elif code == 14: |
| 1323 | line_delta = read_signed_varint(it) |
| 1324 | line += line_delta |
| 1325 | end_line = line + read_varint(it) |
| 1326 | col = read_varint(it) |
| 1327 | if col == 0: |
| 1328 | col = None |
| 1329 | else: |
| 1330 | col -= 1 |
| 1331 | end_col = read_varint(it) |
| 1332 | if end_col == 0: |
| 1333 | end_col = None |
| 1334 | else: |
| 1335 | end_col -= 1 |
| 1336 | yield (code, length, line, end_line, col, end_col) |
| 1337 | elif code == 13: # No column |
| 1338 | line_delta = read_signed_varint(it) |
| 1339 | line += line_delta |
| 1340 | yield (code, length, line, line, None, None) |
| 1341 | elif code in (10, 11, 12): # new line |
| 1342 | line_delta = code - 10 |
| 1343 | line += line_delta |
| 1344 | column = read(it) |
| 1345 | end_column = read(it) |
| 1346 | yield (code, length, line, line, column, end_column) |
| 1347 | else: |
| 1348 | assert (0 <= code < 10) |
| 1349 | second_byte = read(it) |
| 1350 | column = code << 3 | (second_byte >> 4) |
| 1351 | yield (code, length, line, line, column, column + (second_byte & 15)) |
| 1352 | |
| 1353 | def positions_from_location_table(code): |
| 1354 | for _, length, line, end_line, col, end_col in parse_location_table(code): |
no test coverage detected