@@ -4,18 +4,22 @@ import python
44abstract class Comp extends Expr {
55 abstract Function getFunction ( ) ;
66
7- /** Gets the iteration variable for the nth innermost generator of this list comprehension */
7+ /** Gets the iterable of this set comprehension. */
8+ abstract Expr getIterable ( ) ;
9+
10+ /** Gets the iteration variable for the nth innermost generator of this comprehension. */
811 Variable getIterationVariable ( int n ) {
912 result .getAnAccess ( ) = this .getNthInnerLoop ( n ) .getTarget ( )
1013 }
1114
12- private For getNthInnerLoop ( int n ) {
15+ /** Gets the nth innermost For expression of this comprehension. */
16+ For getNthInnerLoop ( int n ) {
1317 n = 0 and result = this .getFunction ( ) .getStmt ( 0 )
1418 or
1519 result = this .getNthInnerLoop ( n - 1 ) .getStmt ( 0 )
1620 }
1721
18- /** Gets the iteration variable for a generator of this list comprehension */
22+ /** Gets the iteration variable for a generator of this list comprehension. */
1923 Variable getAnIterationVariable ( ) { result = this .getIterationVariable ( _) }
2024
2125 /** Gets the scope in which the body of this list comprehension evaluates. */
@@ -62,6 +66,8 @@ class ListComp extends ListComp_, Comp {
6266
6367 override Function getFunction ( ) { result = ListComp_ .super .getFunction ( ) }
6468
69+ override Expr getIterable ( ) { result = ListComp_ .super .getIterable ( ) }
70+
6571 override string toString ( ) { result = ListComp_ .super .toString ( ) }
6672
6773 override Expr getElt ( ) { result = Comp .super .getElt ( ) }
@@ -79,6 +85,8 @@ class SetComp extends SetComp_, Comp {
7985 override predicate hasSideEffects ( ) { any ( ) }
8086
8187 override Function getFunction ( ) { result = SetComp_ .super .getFunction ( ) }
88+
89+ override Expr getIterable ( ) { result = SetComp_ .super .getIterable ( ) }
8290}
8391
8492/** A dictionary comprehension, such as `{ k:v for k, v in enumerate("0123456789") }` */
@@ -93,6 +101,8 @@ class DictComp extends DictComp_, Comp {
93101 override predicate hasSideEffects ( ) { any ( ) }
94102
95103 override Function getFunction ( ) { result = DictComp_ .super .getFunction ( ) }
104+
105+ override Expr getIterable ( ) { result = DictComp_ .super .getIterable ( ) }
96106}
97107
98108/** A generator expression, such as `(var for var in iterable)` */
@@ -107,4 +117,6 @@ class GeneratorExp extends GeneratorExp_, Comp {
107117 override predicate hasSideEffects ( ) { any ( ) }
108118
109119 override Function getFunction ( ) { result = GeneratorExp_ .super .getFunction ( ) }
120+
121+ override Expr getIterable ( ) { result = GeneratorExp_ .super .getIterable ( ) }
110122}
0 commit comments