| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ import Definition | |||
| 15 | 15 | ||
| 16 | 16 | predicate is_increment(Stmt s) { | |
| 17 | 17 | /* x += n */ | |
| 18 | - s.(AugAssign).getValue() instanceof IntegerLiteral | ||
| 18 | + s.(AugAssign).getValue() instanceof IntegerLiteral | ||
| 19 | 19 | or | |
| 20 | 20 | /* x = x + n */ | |
| 21 | 21 | exists(Name t, BinaryExpr add | | |
@@ -36,7 +36,7 @@ predicate empty_loop(For f) { | |||
| 36 | 36 | ||
| 37 | 37 | predicate one_item_only(For f) { | |
| 38 | 38 | not exists(Continue c | f.contains(c)) and | |
| 39 | - exists(Stmt s | | ||
| 39 | + exists(Stmt s | | ||
| 40 | 40 | s = f.getBody().getLastItem() | | |
| 41 | 41 | s instanceof Return | |
| 42 | 42 | or | |
@@ -45,13 +45,13 @@ predicate one_item_only(For f) { | |||
| 45 | 45 | } | |
| 46 | 46 | ||
| 47 | 47 | predicate points_to_call_to_range(ControlFlowNode f) { | |
| 48 | - /* (x)range is a function in Py2 and a class in Py3, so we must treat it as a plain object */ | ||
| 49 | - exists(Object range, Object call | | ||
| 50 | - range = Object::builtin("range") or | ||
| 51 | - range = Object::builtin("xrange") | ||
| 48 | + /* (x)range is a function in Py2 and a class in Py3, so we must treat it as a plain object */ | ||
| 49 | + exists(Value range, Value call | | ||
| 50 | + range = Value::named("range") or | ||
| 51 | + range = Value::named("xrange") | ||
| 52 | 52 | | | |
| 53 | - f.refersTo(call) and | ||
| 54 | - call.(CallNode).getFunction().refersTo(range) | ||
| 53 | + f.pointsTo(call) and | ||
| 54 | + call.getACall().getFunction().pointsTo(range) | ||
| 55 | 55 | ) | |
| 56 | 56 | or | |
| 57 | 57 | /* In case points-to fails due to 'from six.moves import range' or similar. */ | |
@@ -60,11 +60,10 @@ predicate points_to_call_to_range(ControlFlowNode f) { | |||
| 60 | 60 | range = "range" or range = "xrange" | |
| 61 | 61 | ) | |
| 62 | 62 | or | |
| 63 | - /* If range is wrapped in a list it is still a range */ | ||
| 64 | - exists(CallNode call | | ||
| 65 | - f.refersTo(call) and | ||
| 66 | - call = theListType().getACall() and | ||
| 67 | - points_to_call_to_range(call.getArg(0)) | ||
| 63 | + /* Handle list(range(...)) and list(list(range(...))) */ | ||
| 64 | + ( | ||
| 65 | + f.(CallNode).pointsTo().getClass() = ClassValue::list() and | ||
| 66 | + points_to_call_to_range(f.(CallNode).getArg(0)) | ||
| 68 | 67 | ) | |
| 69 | 68 | } | |
| 70 | 69 | ||
@@ -100,7 +99,7 @@ predicate implicit_repeat(For f) { | |||
| 100 | 99 | * E.g. gets `x` from `{ y for y in x }`. | |
| 101 | 100 | */ | |
| 102 | 101 | ControlFlowNode get_comp_iterable(For f) { | |
| 103 | - exists(Comp c | | ||
| 102 | + exists(Comp c | | ||
| 104 | 103 | c.getFunction().getStmt(0) = f | | |
| 105 | 104 | c.getAFlowNode().getAPredecessor() = result | |
| 106 | 105 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -211,7 +211,7 @@ module Value { | |||
| 211 | 211 | } | |
| 212 | 212 | ||
| 213 | 213 | /** Gets the `Value` for the integer constant `i`, if it exists. | |
| 214 | - * There will be no `Value` for most integers, but the following are | ||
| 214 | + * There will be no `Value` for most integers, but the following are | ||
| 215 | 215 | * guaranteed to exist: | |
| 216 | 216 | * * From zero to 511 inclusive. | |
| 217 | 217 | * * All powers of 2 (up to 2**30) | |
@@ -634,6 +634,11 @@ module ClassValue { | |||
| 634 | 634 | result = TBuiltinClassObject(Builtin::special("float")) | |
| 635 | 635 | } | |
| 636 | 636 | ||
| 637 | + /** Get the `ClassValue` for the `list` class. */ | ||
| 638 | + ClassValue list() { | ||
| 639 | + result = TBuiltinClassObject(Builtin::special("list")) | ||
| 640 | + } | ||
| 641 | + | ||
| 637 | 642 | /** Get the `ClassValue` for the `bytes` class (also called `str` in Python 2). */ | |
| 638 | 643 | ClassValue bytes() { | |
| 639 | 644 | result = TBuiltinClassObject(Builtin::special("bytes")) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ def OK1(seq): | |||
| 10 | 10 | for _ in seq: | |
| 11 | 11 | do_something() | |
| 12 | 12 | print("Hi") | |
| 13 | - | ||
| 13 | + | ||
| 14 | 14 | #OK counting | |
| 15 | 15 | def OK2(seq): | |
| 16 | 16 | i = 3 | |
@@ -29,7 +29,7 @@ def OK4(n): | |||
| 29 | 29 | r = range(n) | |
| 30 | 30 | for i in r: | |
| 31 | 31 | print("x") | |
| 32 | - | ||
| 32 | + | ||
| 33 | 33 | #OK named as unused | |
| 34 | 34 | def OK5(seq): | |
| 35 | 35 | for unused_x in seq: | |
@@ -77,7 +77,7 @@ def fail4(coll, sequence): | |||
| 77 | 77 | x = coll.pop() | |
| 78 | 78 | for s in sequence: | |
| 79 | 79 | do_something(x+1) | |
| 80 | - | ||
| 80 | + | ||
| 81 | 81 | #OK See ODASA-4153 and ODASA-4533 | |
| 82 | 82 | def fail5(t): | |
| 83 | 83 | x, y = t | |
@@ -106,3 +106,12 @@ def cleanup(sessions): | |||
| 106 | 106 | for sess in sessions: | |
| 107 | 107 | # Original code had some comment about deleting sessions | |
| 108 | 108 | del sess | |
| 109 | + | ||
| 110 | + # For SuspiciousUnusedLoopIterationVariable.ql | ||
| 111 | + # ok | ||
| 112 | + for x in list(range(100)): | ||
| 113 | + print('hi') | ||
| 114 | + | ||
| 115 | + # ok | ||
| 116 | + for y in list(list(range(100))): | ||
| 117 | + print('hi') | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments