@@ -15,7 +15,7 @@ import Definition
1515
1616predicate is_increment ( Stmt s ) {
1717 /* x += n */
18- s .( AugAssign ) .getValue ( ) instanceof IntegerLiteral
18+ s .( AugAssign ) .getValue ( ) instanceof IntegerLiteral
1919 or
2020 /* x = x + n */
2121 exists ( Name t , BinaryExpr add |
@@ -36,7 +36,7 @@ predicate empty_loop(For f) {
3636
3737predicate one_item_only ( For f ) {
3838 not exists ( Continue c | f .contains ( c ) ) and
39- exists ( Stmt s |
39+ exists ( Stmt s |
4040 s = f .getBody ( ) .getLastItem ( ) |
4141 s instanceof Return
4242 or
@@ -45,13 +45,13 @@ predicate one_item_only(For f) {
4545}
4646
4747predicate 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" )
5252 |
53- f .refersTo ( call ) and
54- call .( CallNode ) .getFunction ( ) .refersTo ( range )
53+ f .pointsTo ( call ) and
54+ call .getACall ( ) .getFunction ( ) .pointsTo ( range )
5555 )
5656 or
5757 /* 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) {
6060 range = "range" or range = "xrange"
6161 )
6262 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 ) )
6867 )
6968}
7069
@@ -100,7 +99,7 @@ predicate implicit_repeat(For f) {
10099 * E.g. gets `x` from `{ y for y in x }`.
101100 */
102101ControlFlowNode get_comp_iterable ( For f ) {
103- exists ( Comp c |
102+ exists ( Comp c |
104103 c .getFunction ( ) .getStmt ( 0 ) = f |
105104 c .getAFlowNode ( ) .getAPredecessor ( ) = result
106105 )
0 commit comments