Skip to content

Commit ad95225

Browse files
committed
python: improve code
according to alert and reviewer's suggestion
1 parent bb26c31 commit ad95225

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

python/downgrades/503c0516fba2e5da9570f00eb34ef43025ecb8fb/py_exprs.ql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ class ExprParent_ extends @py_expr_parent {
2323
* New kinds have been inserted such that
2424
* `@py_Name` which used to have index 18 now has index 19.
2525
* Entries with lower indices are unchanged.
26+
*
27+
* Note that if `18 <= new_index < 19`, it does not correspond
28+
* to an old index.
2629
*/
2730
bindingset[new_index]
2831
int old_index(int new_index) {
29-
if new_index < 18
30-
then result = new_index
31-
else
32-
if new_index >= 19
33-
then result + (19 - 18) = new_index
34-
else none()
32+
// before inserted range
33+
new_index < 18 and result = new_index
34+
or
35+
// after inserted range
36+
new_index >= 19 and result + (19 - 18) = new_index
3537
}
3638

3739
// The schema for py_exprs is:

python/downgrades/503c0516fba2e5da9570f00eb34ef43025ecb8fb/py_stmts.ql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ class StmtList_ extends @py_stmt_list {
2323
* New kinds have been inserted such that
2424
* `@py_Nonlocal` which used to have index 14 now has index 16.
2525
* Entries with lower indices are unchanged.
26+
*
27+
* Note that if `14 <= new_index < 16`, it does not correspond
28+
* to an old index.
2629
*/
2730
bindingset[new_index]
2831
int old_index(int new_index) {
29-
if new_index < 14
30-
then result = new_index
31-
else
32-
if new_index >= 16
33-
then result + (16 - 14) = new_index
34-
else none()
32+
// before inserted range
33+
new_index < 14 and result = new_index
34+
or
35+
// after inserted range
36+
new_index >= 16 and result + (16 - 14) = new_index
3537
}
3638

3739
// The schema for py_stmts is:

0 commit comments

Comments
 (0)