1
+ class Element extends @element {
2
+ string toString ( ) { none ( ) }
3
+ }
4
+
5
+ class ForEachStmt extends Element , @for_each_stmt {
6
+ Element getPattern ( ) { for_each_stmts ( this , result , _) }
7
+
8
+ Element getIteratorVar ( ) { for_each_stmt_iterator_vars ( this , result ) }
9
+
10
+ Element getIteratorVarPattern ( ) {
11
+ pattern_binding_decl_patterns ( this .getIteratorVar ( ) , _, result )
12
+ }
13
+
14
+ Element getIteratorVarConcreteDecl ( ) {
15
+ decl_ref_exprs ( this .getNextCallVarRef ( ) , result )
16
+ }
17
+
18
+ Element getNextCall ( ) { for_each_stmt_next_calls ( this , result ) }
19
+
20
+ Element getNextCallMethodLookup ( ) { apply_exprs ( this .getNextCall ( ) , result ) }
21
+
22
+ Element getNextCallFuncRef ( ) { apply_exprs ( this .getNextCallMethodLookup ( ) , result ) }
23
+
24
+ Element getNextCallInOutConversion ( ) { self_apply_exprs ( this .getNextCallMethodLookup ( ) , result ) }
25
+
26
+ Element getNextCallVarRef ( ) { in_out_exprs ( this .getNextCallInOutConversion ( ) , result ) }
27
+ }
28
+
29
+ query predicate new_for_each_stmts (
30
+ ForEachStmt stmt , @pattern_or_none pattern , @brace_stmt_or_none body , @expr_or_none sequence ,
31
+ @pattern_binding_decl_or_none iteratorVar
32
+ ) {
33
+ for_each_stmt ( stmt , pattern , body ) and
34
+ for_each_stmt_iterator_vars ( stmt , iteratorVar ) and
35
+ (
36
+ iteratorVar instanceof @pattern_binding_decl and
37
+ pattern_binding_decl_inits ( iteratorVar , 0 , sequence )
38
+ )
39
+ }
40
+
41
+ query predicate new_pattern_binding_decls ( Element id ) {
42
+ pattern_binding_decls ( id ) and
43
+ not for_each_stmt_iterator_vars ( id )
44
+ }
45
+
46
+ query predicate new_pattern_binding_decl_patterns ( Element id , int index , Element pattern ) {
47
+ pattern_binding_decl_patterns ( id , index , pattern ) and
48
+ not for_each_stmt_iterator_vars ( _, id )
49
+ }
50
+
51
+ query predicate new_named_patterns ( Element pattern , string name ) {
52
+ named_patterns ( pattern , name ) and
53
+ not exists ( Element decl |
54
+ pattern_binding_decl_patterns ( decl , _, pattern ) and
55
+ for_each_stmt_iterator_vars ( _, decl )
56
+ )
57
+ }
58
+
59
+ query predicate new_pattern_binding_decl_inits ( Element id , int index , Element init ) {
60
+ pattern_binding_decl_inits ( id , index , init ) and
61
+ not for_each_stmt_iterator_vars ( _, id )
62
+ }
63
+
64
+ query predicate new_dot_syntax_call_exprs ( Element id ) {
65
+ dot_syntax_call_exprs ( id ) and
66
+ not exists ( ForEachStmt stmt | id = stmt .getNextCallMethodLookup ( ) )
67
+ }
68
+
69
+ query predicate new_self_apply_exprs ( Element id , Element base ) {
70
+ self_apply_exprs ( id , base ) and
71
+ not exists ( ForEachStmt stmt | id = stmt .getNextCallMethodLookup ( ) )
72
+ }
73
+
74
+ query predicate new_in_out_exprs ( Element inOutExpr , Element subExpr ) {
75
+ in_out_exprs ( inOutExpr , subExpr ) and
76
+ not exists ( ForEachStmt stmt | inOutExpr = stmt .getNextCallInOutConversion ( ) )
77
+ }
78
+
79
+ query predicate new_apply_exprs ( Element id , Element func ) {
80
+ apply_exprs ( id , func ) and
81
+ not exists ( ForEachStmt stmt | id = stmt .getNextCall ( ) or id = stmt .getNextCallMethodLookup ( ) )
82
+ }
83
+
84
+ query predicate new_decl_ref_exprs ( Element id , Element decl ) {
85
+ decl_ref_exprs ( id , decl ) and
86
+ not exists ( ForEachStmt stmt | stmt .getNextCallVarRef ( ) = id or stmt .getNextCallFuncRef ( ) = id )
87
+ }
88
+
89
+ query predicate new_lookup_exprs ( Element id , Element base ) {
90
+ lookup_exprs ( id , base ) and
91
+ not exists ( ForEachStmt stmt | stmt .getNextCallMethodLookup ( ) = id )
92
+ }
93
+
94
+ query predicate new_call_exprs ( Element id ) {
95
+ call_exprs ( id ) and
96
+ not exists ( ForEachStmt stmt | stmt .getNextCall ( ) = id )
97
+ }
98
+
99
+ query predicate new_locatable_locations ( Element locatable , Element location ) {
100
+ locatable_locations ( locatable , location ) and
101
+ not exists ( ForEachStmt stmt |
102
+ locatable = stmt .getIteratorVarPattern ( ) or
103
+ locatable = stmt .getIteratorVarConcreteDecl ( ) or
104
+ locatable = stmt .getNextCall ( ) or
105
+ locatable = stmt .getNextCallMethodLookup ( ) or
106
+ locatable = stmt .getNextCallInOutConversion ( ) or
107
+ locatable = stmt .getNextCallVarRef ( )
108
+ )
109
+ }
110
+
111
+ query predicate new_concrete_var_decls ( Element decl , int introducer_int ) {
112
+ concrete_var_decls ( decl , introducer_int ) and
113
+ not exists ( ForEachStmt stmt | stmt .getIteratorVarConcreteDecl ( ) = decl )
114
+ }
115
+
116
+ query predicate new_var_decls ( NewElement decl , string name , Element type ) {
117
+ var_decls ( decl , name , type ) and
118
+ not exists ( ForEachStmt stmt | stmt .getIteratorVarConcreteDecl ( ) = decl )
119
+ }
120
+
121
+ query predicate new_expr_types ( NewElement expr , NewElement type ) {
122
+ expr_types ( expr , type ) and
123
+ not exists ( ForEachStmt stmt |
124
+ expr = stmt .getNextCall ( ) or
125
+ expr = stmt .getNextCallMethodLookup ( ) or
126
+ expr = stmt .getNextCallVarRef ( ) or
127
+ expr = stmt .getNextCallFuncRef ( ) or
128
+ expr = stmt .getNextCallInOutConversion ( )
129
+ )
130
+ }
0 commit comments