@@ -23,7 +23,6 @@ private import AutomaticVariable
23
23
newtype VarKind =
24
24
ThisVarKind ( ) or
25
25
ParamVarRealKind ( ) or
26
- ParamVarPipelineKind ( ) or
27
26
PipelineIteratorKind ( ) or
28
27
PipelineByPropertyNameIteratorKind ( string name ) {
29
28
exists ( Raw:: ProcessBlock pb |
@@ -78,9 +77,7 @@ class Synthesis extends TSynthesis {
78
77
79
78
predicate parameterStaticType ( Parameter p , string type ) { none ( ) }
80
79
81
- predicate isPipelineParameter ( Parameter p ) { none ( ) }
82
-
83
- predicate pipelineParameterHasIndex ( ScriptBlock s , int i ) { none ( ) }
80
+ predicate pipelineParameterHasIndex ( Raw:: ScriptBlock s , int i ) { none ( ) }
84
81
85
82
predicate functionName ( FunctionBase f , string name ) { none ( ) }
86
83
@@ -167,33 +164,28 @@ private module SetVariableAssignment {
167
164
}
168
165
}
169
166
167
+ /** Gets the pipeline parameter associated with `s`. */
168
+ TVariable getPipelineParameter ( Raw:: ScriptBlock s ) {
169
+ exists ( ChildIndex i |
170
+ any ( ParameterSynth:: ParameterSynth ps ) .isPipelineParameterChild ( s , _, i , _, _) and
171
+ result = TVariableSynth ( s , i )
172
+ )
173
+ }
174
+
170
175
/**
171
176
* Syntesize parameters from parameter blocks and function definitions
172
177
* so that they have a uniform API.
173
178
*/
174
179
private module ParameterSynth {
175
- private class ParameterSynth extends Synthesis {
180
+ class ParameterSynth extends Synthesis {
176
181
final override predicate isRelevant ( Raw:: Ast a ) { a = any ( Scope:: Range r ) .getAParameter ( ) }
177
182
178
- private predicate parameter (
179
- Raw:: Ast parent , ChildIndex i , Raw:: Parameter p , Child child , boolean isPipelineParameter
180
- ) {
183
+ private predicate parameter ( Raw:: Ast parent , ChildIndex i , Raw:: Parameter p , Child child ) {
181
184
exists ( Scope:: Range r , int index |
182
185
p = r .getParameter ( index ) and
183
186
parent = r and
184
187
i = funParam ( index ) and
185
- child = SynthChild ( VarSynthKind ( ParamVarRealKind ( ) ) ) and
186
- if p instanceof Raw:: PipelineParameter
187
- then isPipelineParameter = true
188
- else isPipelineParameter = false
189
- )
190
- }
191
-
192
- final override predicate isPipelineParameter ( Parameter p ) {
193
- exists ( Raw:: Ast parent , ChildIndex i |
194
- parent = getRawAst ( p .getFunction ( ) .getBody ( ) ) and
195
- this .isPipelineParameterChild ( parent , _, i ) and
196
- p = TVariableSynth ( parent , i )
188
+ child = SynthChild ( VarSynthKind ( ParamVarRealKind ( ) ) )
197
189
)
198
190
}
199
191
@@ -205,47 +197,49 @@ private module ParameterSynth {
205
197
}
206
198
207
199
final override predicate variableSynthName ( VariableSynth v , string name ) {
208
- exists ( Raw:: Ast parent , int i , Raw:: Parameter p |
209
- this .parameter ( parent , FunParam ( i ) , p , _, false ) and
210
- v = TVariableSynth ( parent , FunParam ( i ) ) and
211
- name = p .getName ( )
212
- )
213
- or
214
- exists ( Raw:: Ast parent |
215
- this .child ( parent , PipelineParamVar ( ) , _) and
216
- v = TVariableSynth ( parent , PipelineParamVar ( ) ) and
200
+ exists ( Raw:: Ast parent , ChildIndex i | v = TVariableSynth ( parent , i ) |
201
+ exists ( Raw:: Parameter p |
202
+ this .parameter ( parent , i , p , _) and
203
+ name = p .getName ( )
204
+ )
205
+ or
206
+ this .isPipelineParameterChild ( parent , _, i , _, true ) and
217
207
name = "[synth] pipeline"
218
208
)
219
209
}
220
210
221
- private predicate isPipelineParameterChild ( Raw:: Ast parent , int index , ChildIndex i ) {
222
- exists ( Scope:: Range r | parent = r and i = PipelineParamVar ( ) |
223
- r .getParameter ( index ) instanceof Raw:: PipelineParameter
211
+ predicate isPipelineParameterChild (
212
+ Raw:: Ast parent , int index , ChildIndex i , Child child , boolean synthesized
213
+ ) {
214
+ exists ( Scope:: Range r |
215
+ parent = r and
216
+ i = funParam ( index ) and
217
+ child = SynthChild ( VarSynthKind ( ParamVarRealKind ( ) ) )
218
+ |
219
+ r .getParameter ( index ) instanceof Raw:: PipelineParameter and
220
+ synthesized = false
224
221
or
225
222
not r .getAParameter ( ) instanceof Raw:: PipelineParameter and
226
- index = synthPipelineParameterChildIndex ( r )
223
+ index = synthPipelineParameterChildIndex ( r ) and
224
+ synthesized = true
227
225
)
228
226
}
229
227
230
- final override predicate pipelineParameterHasIndex ( ScriptBlock s , int i ) {
231
- exists ( Raw:: ScriptBlock scriptBlock |
232
- s = TScriptBlock ( scriptBlock ) and
233
- this .isPipelineParameterChild ( scriptBlock , i , _)
234
- )
228
+ final override predicate pipelineParameterHasIndex ( Raw:: ScriptBlock s , int i ) {
229
+ this .isPipelineParameterChild ( s , i , _, _, _)
235
230
}
236
231
237
232
final override predicate child ( Raw:: Ast parent , ChildIndex i , Child child ) {
238
233
// Synthesize parameters
239
- this .parameter ( parent , i , _, child , false )
234
+ this .parameter ( parent , i , _, child )
240
235
or
241
- // Synthesize pipeline parameter
242
- child = SynthChild ( VarSynthKind ( ParamVarPipelineKind ( ) ) ) and
243
- this .isPipelineParameterChild ( parent , _, i )
236
+ // Synthesize implicit pipeline parameter, if necessary
237
+ this .isPipelineParameterChild ( parent , _, i , child , true )
244
238
or
245
239
// Synthesize default values
246
240
exists ( Raw:: Parameter q |
247
241
parent = q and
248
- this .parameter ( _, _, q , _, _ )
242
+ this .parameter ( _, _, q , _)
249
243
|
250
244
i = paramDefaultVal ( ) and
251
245
child = childRef ( getResultAst ( q .getDefaultValue ( ) ) )
@@ -258,30 +252,30 @@ private module ParameterSynth {
258
252
}
259
253
260
254
final override Parameter getResultAstImpl ( Raw:: Ast r ) {
261
- exists ( Raw:: Ast parent , int i |
262
- this .parameter ( parent , FunParam ( i ) , r , _, false ) and
263
- result = TVariableSynth ( parent , FunParam ( i ) )
264
- )
265
- or
266
- exists ( Scope:: Range scope , int i , ChildIndex index |
267
- scope .getParameter ( i ) = r and
268
- this .isPipelineParameterChild ( scope , i , index ) and
269
- result = TVariableSynth ( scope , index )
255
+ exists ( Raw:: Ast parent , ChildIndex i |
256
+ this .parameter ( parent , i , r , _) and
257
+ result = TVariableSynth ( parent , i )
270
258
)
271
259
}
272
260
273
261
final override Location getLocation ( Ast n ) {
274
- exists ( Raw:: Ast parent , Raw:: Parameter p , int i |
275
- this .parameter ( parent , _, p , _, _) and
276
- n = TVariableSynth ( parent , FunParam ( i ) ) and
277
- result = p .getLocation ( )
262
+ exists ( Raw:: Ast parent , ChildIndex i | n = TVariableSynth ( parent , i ) |
263
+ exists ( Raw:: Parameter p |
264
+ this .parameter ( parent , i , p , _) and
265
+ result = p .getLocation ( )
266
+ )
267
+ or
268
+ this .isPipelineParameterChild ( parent , _, i , _, true ) and
269
+ result = parent .getLocation ( )
278
270
)
279
271
}
280
272
281
273
final override predicate parameterStaticType ( Parameter n , string type ) {
282
- exists ( Raw:: Ast parent , int i , Raw:: Parameter p |
283
- this .parameter ( parent , FunParam ( i ) , p , _, false ) and
284
- n = TVariableSynth ( parent , FunParam ( i ) ) and
274
+ exists ( Raw:: Ast parent , Raw:: Parameter p , ChildIndex i |
275
+ // No need to consider the synthesized pipeline parameter as it never
276
+ // has a static type.
277
+ this .parameter ( parent , i , p , _) and
278
+ n = TVariableSynth ( parent , i ) and
285
279
type = p .getStaticType ( )
286
280
)
287
281
}
@@ -440,6 +434,11 @@ private module FunctionSynth {
440
434
n = TFunctionSynth ( fundefStmt , _) and
441
435
result = fundefStmt .getLocation ( )
442
436
)
437
+ or
438
+ exists ( Raw:: TopLevelScriptBlock topLevelScriptBlock |
439
+ n = TTopLevelFunction ( topLevelScriptBlock ) and
440
+ result = topLevelScriptBlock .getLocation ( )
441
+ )
443
442
}
444
443
}
445
444
}
@@ -857,8 +856,10 @@ private module IteratorAccessSynth {
857
856
result = cmdExpr .getLocation ( )
858
857
)
859
858
or
860
- exists ( Raw:: Ast parent |
861
- n = TVariableSynth ( parent , _) and
859
+ exists ( Raw:: Ast parent , ChildIndex i |
860
+ i instanceof PipelineIteratorVar or i instanceof PipelineByPropertyNameIteratorVar
861
+ |
862
+ n = TVariableSynth ( parent , i ) and
862
863
result = parent .getLocation ( )
863
864
)
864
865
}
@@ -870,12 +871,12 @@ private module PipelineAccess {
870
871
final override predicate child ( Raw:: Ast parent , ChildIndex i , Child child ) {
871
872
exists ( Raw:: ProcessBlock pb | parent = pb |
872
873
i = processBlockPipelineVarReadAccess ( ) and
873
- exists ( PipelineVariable pipelineVar |
874
- pipelineVar = TVariableSynth ( pb .getScriptBlock ( ) , PipelineParamVar ( ) ) and
874
+ exists ( PipelineParameter pipelineVar |
875
+ pipelineVar = getPipelineParameter ( pb .getScriptBlock ( ) ) and
875
876
child = SynthChild ( VarAccessSynthKind ( pipelineVar ) )
876
877
)
877
878
or
878
- exists ( PipelineByPropertyNameVariable pipelineVar , Raw:: PipelineByPropertyNameParameter p |
879
+ exists ( PipelineByPropertyNameParameter pipelineVar , Raw:: PipelineByPropertyNameParameter p |
879
880
i = processBlockPipelineByPropertyNameVarReadAccess ( p .getName ( ) ) and
880
881
getResultAst ( p ) = pipelineVar and
881
882
child = SynthChild ( VarAccessSynthKind ( pipelineVar ) )
0 commit comments