@@ -136,6 +136,17 @@ Element getParent(Element type) {
136136 )
137137}
138138
139+ Element getNextMethod ( ForEachStmt foreach ) {
140+ exists ( @element sequence , @element exprType , @element parentType , @element typeDecl |
141+ sequence = foreach .getSequence ( ) and
142+ expr_types ( sequence , exprType ) and
143+ parentType = getParent * ( exprType ) and
144+ any_generic_types ( parentType , typeDecl ) and
145+ decl_members ( typeDecl , _, result ) and
146+ callable_names ( result , "next()" )
147+ )
148+ }
149+
139150// TODO: do we need a new_apply_expr_arguments
140151query predicate new_decl_ref_exprs ( NewElement id , NewElement decl ) {
141152 decl_ref_exprs ( id , decl )
@@ -145,18 +156,9 @@ query predicate new_decl_ref_exprs(NewElement id, NewElement decl) {
145156 Fresh:: map ( TIteratorVarConcreteDecl ( foreach ) ) = decl
146157 )
147158 or
148- exists (
149- ForEachStmt foreach , @element sequence , @element exprType , @element parentType ,
150- @element typeDecl
151- |
159+ exists ( ForEachStmt foreach |
152160 Fresh:: map ( TNextCallFuncRef ( foreach ) ) = id and
153- // ForEachStmt.getSequence().getType().getMember(next)
154- sequence = foreach .getSequence ( ) and
155- expr_types ( sequence , exprType ) and
156- parentType = getParent * ( exprType ) and
157- any_generic_types ( parentType , typeDecl ) and
158- decl_members ( typeDecl , _, decl ) and
159- callable_names ( decl , "next()" )
161+ decl = getNextMethod ( foreach )
160162 )
161163}
162164
@@ -217,4 +219,25 @@ query predicate new_expr_types(NewElement expr, NewElement type) {
217219 var_decl_parent_patterns ( var_decl , pattern ) and
218220 var_decls ( var_decl , _, type )
219221 )
222+ or
223+ exists ( ForEachStmt stmt |
224+ expr = Fresh:: map ( TNextCallMethodLookup ( stmt ) ) and
225+ value_decls ( getNextMethod ( stmt ) , type )
226+ )
227+ or
228+ exists ( ForEachStmt stmt |
229+ expr = Fresh:: map ( TNextCallVarRef ( stmt ) ) and
230+ expr_types ( stmt .getSequence ( ) , type )
231+ )
232+ or
233+ exists ( ForEachStmt stmt |
234+ expr = Fresh:: map ( TNextCallFuncRef ( stmt ) ) and
235+ value_decls ( getNextMethod ( stmt ) , type )
236+ )
237+ or
238+ exists ( ForEachStmt stmt , NewElement plainType |
239+ expr = Fresh:: map ( TNextCallInOutConversion ( stmt ) ) and
240+ expr_types ( stmt .getSequence ( ) , plainType ) and
241+ in_out_types ( type , plainType )
242+ )
220243}
0 commit comments