@@ -23,7 +23,6 @@ private import AutomaticVariable
2323newtype VarKind =
2424 ThisVarKind ( ) or
2525 ParamVarRealKind ( ) or
26- ParamVarPipelineKind ( ) or
2726 PipelineIteratorKind ( ) or
2827 PipelineByPropertyNameIteratorKind ( string name ) {
2928 exists ( Raw:: ProcessBlock pb |
@@ -78,9 +77,7 @@ class Synthesis extends TSynthesis {
7877
7978 predicate parameterStaticType ( Parameter p , string type ) { none ( ) }
8079
81- predicate isPipelineParameter ( Parameter p ) { none ( ) }
82-
83- predicate pipelineParameterHasIndex ( ScriptBlock s , int i ) { none ( ) }
80+ predicate pipelineParameterHasIndex ( Raw:: ScriptBlock s , int i ) { none ( ) }
8481
8582 predicate functionName ( FunctionBase f , string name ) { none ( ) }
8683
@@ -167,33 +164,28 @@ private module SetVariableAssignment {
167164 }
168165}
169166
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+
170175/**
171176 * Syntesize parameters from parameter blocks and function definitions
172177 * so that they have a uniform API.
173178 */
174179private module ParameterSynth {
175- private class ParameterSynth extends Synthesis {
180+ class ParameterSynth extends Synthesis {
176181 final override predicate isRelevant ( Raw:: Ast a ) { a = any ( Scope:: Range r ) .getAParameter ( ) }
177182
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 ) {
181184 exists ( Scope:: Range r , int index |
182185 p = r .getParameter ( index ) and
183186 parent = r and
184187 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 ( ) ) )
197189 )
198190 }
199191
@@ -205,47 +197,49 @@ private module ParameterSynth {
205197 }
206198
207199 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
217207 name = "[synth] pipeline"
218208 )
219209 }
220210
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
224221 or
225222 not r .getAParameter ( ) instanceof Raw:: PipelineParameter and
226- index = synthPipelineParameterChildIndex ( r )
223+ index = synthPipelineParameterChildIndex ( r ) and
224+ synthesized = true
227225 )
228226 }
229227
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 , _, _, _)
235230 }
236231
237232 final override predicate child ( Raw:: Ast parent , ChildIndex i , Child child ) {
238233 // Synthesize parameters
239- this .parameter ( parent , i , _, child , false )
234+ this .parameter ( parent , i , _, child )
240235 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 )
244238 or
245239 // Synthesize default values
246240 exists ( Raw:: Parameter q |
247241 parent = q and
248- this .parameter ( _, _, q , _, _ )
242+ this .parameter ( _, _, q , _)
249243 |
250244 i = paramDefaultVal ( ) and
251245 child = childRef ( getResultAst ( q .getDefaultValue ( ) ) )
@@ -258,30 +252,30 @@ private module ParameterSynth {
258252 }
259253
260254 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 )
270258 )
271259 }
272260
273261 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 ( )
278270 )
279271 }
280272
281273 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
285279 type = p .getStaticType ( )
286280 )
287281 }
@@ -440,6 +434,11 @@ private module FunctionSynth {
440434 n = TFunctionSynth ( fundefStmt , _) and
441435 result = fundefStmt .getLocation ( )
442436 )
437+ or
438+ exists ( Raw:: TopLevelScriptBlock topLevelScriptBlock |
439+ n = TTopLevelFunction ( topLevelScriptBlock ) and
440+ result = topLevelScriptBlock .getLocation ( )
441+ )
443442 }
444443 }
445444}
@@ -857,8 +856,10 @@ private module IteratorAccessSynth {
857856 result = cmdExpr .getLocation ( )
858857 )
859858 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
862863 result = parent .getLocation ( )
863864 )
864865 }
@@ -870,12 +871,12 @@ private module PipelineAccess {
870871 final override predicate child ( Raw:: Ast parent , ChildIndex i , Child child ) {
871872 exists ( Raw:: ProcessBlock pb | parent = pb |
872873 i = processBlockPipelineVarReadAccess ( ) and
873- exists ( PipelineVariable pipelineVar |
874- pipelineVar = TVariableSynth ( pb .getScriptBlock ( ) , PipelineParamVar ( ) ) and
874+ exists ( PipelineParameter pipelineVar |
875+ pipelineVar = getPipelineParameter ( pb .getScriptBlock ( ) ) and
875876 child = SynthChild ( VarAccessSynthKind ( pipelineVar ) )
876877 )
877878 or
878- exists ( PipelineByPropertyNameVariable pipelineVar , Raw:: PipelineByPropertyNameParameter p |
879+ exists ( PipelineByPropertyNameParameter pipelineVar , Raw:: PipelineByPropertyNameParameter p |
879880 i = processBlockPipelineByPropertyNameVarReadAccess ( p .getName ( ) ) and
880881 getResultAst ( p ) = pipelineVar and
881882 child = SynthChild ( VarAccessSynthKind ( pipelineVar ) )
0 commit comments