@@ -4,12 +4,15 @@ import python
44abstract class Comp extends Expr {
55 abstract Function getFunction ( ) ;
66
7+ /** Gets the iterable of this set comprehension. */
8+ abstract Expr getIterable ( ) ;
9+
710 /** Gets the iteration variable for the nth innermost generator of this list comprehension */
811 Variable getIterationVariable ( int n ) {
912 result .getAnAccess ( ) = this .getNthInnerLoop ( n ) .getTarget ( )
1013 }
1114
12- private For getNthInnerLoop ( int n ) {
15+ For getNthInnerLoop ( int n ) {
1316 n = 0 and result = this .getFunction ( ) .getStmt ( 0 )
1417 or
1518 result = this .getNthInnerLoop ( n - 1 ) .getStmt ( 0 )
@@ -62,6 +65,8 @@ class ListComp extends ListComp_, Comp {
6265
6366 override Function getFunction ( ) { result = ListComp_ .super .getFunction ( ) }
6467
68+ override Expr getIterable ( ) { result = ListComp_ .super .getIterable ( ) }
69+
6570 override string toString ( ) { result = ListComp_ .super .toString ( ) }
6671
6772 override Expr getElt ( ) { result = Comp .super .getElt ( ) }
@@ -79,6 +84,8 @@ class SetComp extends SetComp_, Comp {
7984 override predicate hasSideEffects ( ) { any ( ) }
8085
8186 override Function getFunction ( ) { result = SetComp_ .super .getFunction ( ) }
87+
88+ override Expr getIterable ( ) { result = SetComp_ .super .getIterable ( ) }
8289}
8390
8491/** A dictionary comprehension, such as `{ k:v for k, v in enumerate("0123456789") }` */
@@ -93,6 +100,8 @@ class DictComp extends DictComp_, Comp {
93100 override predicate hasSideEffects ( ) { any ( ) }
94101
95102 override Function getFunction ( ) { result = DictComp_ .super .getFunction ( ) }
103+
104+ override Expr getIterable ( ) { result = DictComp_ .super .getIterable ( ) }
96105}
97106
98107/** A generator expression, such as `(var for var in iterable)` */
@@ -107,4 +116,6 @@ class GeneratorExp extends GeneratorExp_, Comp {
107116 override predicate hasSideEffects ( ) { any ( ) }
108117
109118 override Function getFunction ( ) { result = GeneratorExp_ .super .getFunction ( ) }
119+
120+ override Expr getIterable ( ) { result = GeneratorExp_ .super .getIterable ( ) }
110121}
0 commit comments