@@ -76,23 +76,10 @@ predicate succExit(CfgScope scope, Ast last, Completion c) { scope.exit(last, c)
76
76
77
77
/** Defines the CFG by dispatch on the various AST types. */
78
78
module Trees {
79
- class NonDefaultParameterTree extends LeafTree instanceof Parameter {
80
- NonDefaultParameterTree ( ) { not exists ( super .getDefaultValue ( ) ) }
81
- }
82
-
83
- class DefaultParameterTree extends StandardPostOrderTree instanceof Parameter {
84
- DefaultParameterTree ( ) { exists ( super .getDefaultValue ( ) ) }
85
-
79
+ class ParameterBlockTree extends StandardPostOrderTree instanceof ParamBlock {
86
80
override AstNode getChildNode ( int i ) {
87
- i = 0 and
88
- result = super .getDefaultValue ( )
81
+ exists ( Parameter p | p = super .getParameter ( i ) | result = p .getDefaultValue ( ) )
89
82
}
90
-
91
- final override predicate propagatesAbnormal ( AstNode child ) { child = super .getDefaultValue ( ) }
92
- }
93
-
94
- class ParameterBlockTree extends StandardPostOrderTree instanceof ParamBlock {
95
- override AstNode getChildNode ( int i ) { result = super .getParameter ( i ) }
96
83
}
97
84
98
85
abstract class ScriptBlockTree extends ControlFlowTree instanceof ScriptBlock {
@@ -185,21 +172,31 @@ module Trees {
185
172
186
173
FunctionScriptBlockTree ( ) { func .getBody ( ) = this }
187
174
188
- AstNode getParameter ( int i ) { result = func .getFunctionParameter ( i ) }
175
+ Expr getDefaultValue ( int i ) {
176
+ exists ( Parameter p |
177
+ p =
178
+ rank [ i + 1 ] ( Parameter cand , int j |
179
+ cand .hasDefaultValue ( ) and j = cand .getIndex ( )
180
+ |
181
+ cand order by j
182
+ ) and
183
+ result = p .getDefaultValue ( )
184
+ )
185
+ }
189
186
190
- int getNumberOfParameters ( ) { result = func . getNumberOfFunctionParameters ( ) }
187
+ int getNumberOfDefaultValues ( ) { result = count ( int i | exists ( this . getDefaultValue ( i ) ) ) }
191
188
192
189
override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
193
190
// Step to the first parameter
194
191
pred = this and
195
- first ( this .getParameter ( 0 ) , succ ) and
192
+ first ( this .getDefaultValue ( 0 ) , succ ) and
196
193
completionIsSimple ( c )
197
194
or
198
195
// Step to the next parameter
199
196
exists ( int i |
200
- last ( this .getParameter ( i ) , pred , c ) and
197
+ last ( this .getDefaultValue ( i ) , pred , c ) and
201
198
completionIsNormal ( c ) and
202
- first ( this .getParameter ( i + 1 ) , succ )
199
+ first ( this .getDefaultValue ( i + 1 ) , succ )
203
200
)
204
201
or
205
202
// Body steps
@@ -208,12 +205,12 @@ module Trees {
208
205
209
206
final override predicate succEntry ( AstNode n , Completion c ) {
210
207
// If there are no paramters we enter the body directly
211
- not exists ( this .getParameter ( 0 ) ) and
208
+ not exists ( this .getDefaultValue ( _ ) ) and
212
209
n = this and
213
210
completionIsSimple ( c )
214
211
or
215
212
// Once we are done with the last parameter we enter the body
216
- last ( this .getParameter ( this .getNumberOfParameters ( ) - 1 ) , n , c ) and
213
+ last ( this .getDefaultValue ( this .getNumberOfDefaultValues ( ) - 1 ) , n , c ) and
217
214
completionIsNormal ( c )
218
215
}
219
216
}
@@ -380,11 +377,11 @@ module Trees {
380
377
or
381
378
// Emptiness test to variable declaration
382
379
pred = this and
383
- first ( super .getVariable ( ) , succ ) and
380
+ first ( super .getVarAccess ( ) , succ ) and
384
381
completionIsSimple ( c )
385
382
or
386
383
// Variable declaration to body
387
- last ( super .getVariable ( ) , succ , c ) and
384
+ last ( super .getVarAccess ( ) , succ , c ) and
388
385
completionIsNormal ( c ) and
389
386
first ( this .getBody ( ) , succ )
390
387
or
0 commit comments