@@ -190,8 +190,10 @@ function cfgIfThenElse(ifNode: RNodeWithParent, condition: ControlFlowInformatio
190190 graph . addEdge ( entryPoint , ifId , { label : CfgEdgeType . Fd } ) ;
191191 }
192192
193- for ( const exit of [ ...then . exitPoints , ...otherwise ?. exitPoints ?? [ ] ] ) {
194- graph . addEdge ( ifId + '-exit' , exit , { label : CfgEdgeType . Fd } ) ;
193+ for ( const exits of [ then . exitPoints , otherwise ?. exitPoints ?? [ ] ] ) {
194+ for ( const exit of exits ) {
195+ graph . addEdge ( ifId + '-exit' , exit , { label : CfgEdgeType . Fd } ) ;
196+ }
195197 }
196198 if ( ! otherwise ) {
197199 for ( const e of condition . exitPoints ) {
@@ -219,8 +221,10 @@ function cfgRepeat(repeat: RRepeatLoop<ParentInformation>, body: ControlFlowInfo
219221 }
220222
221223 // loops automatically
222- for ( const next of [ ...body . nexts , ...body . exitPoints ] ) {
223- graph . addEdge ( repeat . info . id , next , { label : CfgEdgeType . Fd } ) ;
224+ for ( const nexts of [ body . nexts , body . exitPoints ] ) {
225+ for ( const next of nexts ) {
226+ graph . addEdge ( repeat . info . id , next , { label : CfgEdgeType . Fd } ) ;
227+ }
224228 }
225229
226230 for ( const breakPoint of body . breaks ) {
@@ -248,8 +252,10 @@ function cfgWhile(whileLoop: RWhileLoop<ParentInformation>, condition: ControlFl
248252 }
249253 }
250254
251- for ( const next of [ ...body . nexts , ...body . exitPoints ] ) {
252- graph . addEdge ( whileId , next , { label : CfgEdgeType . Fd } ) ;
255+ for ( const nexts of [ body . nexts , body . exitPoints ] ) {
256+ for ( const next of nexts ) {
257+ graph . addEdge ( whileId , next , { label : CfgEdgeType . Fd } ) ;
258+ }
253259 }
254260
255261 for ( const breakPoint of body . breaks ) {
@@ -292,8 +298,10 @@ function cfgFor(forLoop: RForLoop<ParentInformation>, variable: ControlFlowInfor
292298 }
293299 }
294300
295- for ( const next of [ ...body . nexts , ...body . exitPoints ] ) {
296- graph . addEdge ( forLoopId , next , { label : CfgEdgeType . Fd } ) ;
301+ for ( const points of [ body . nexts , body . exitPoints ] ) {
302+ for ( const next of points ) {
303+ graph . addEdge ( forLoopId , next , { label : CfgEdgeType . Fd } ) ;
304+ }
297305 }
298306
299307 for ( const breakPoint of body . breaks ) {
@@ -324,11 +332,15 @@ function cfgFunctionDefinition(fn: RFunctionDefinition<ParentInformation>, param
324332 graph . addVertex ( { id : fnId , children, type : identifyMayStatementType ( fn ) , mid : paramExits , end : [ fnId + '-exit' ] } ) ;
325333
326334 graph . mergeWith ( body . graph , true ) ;
327- children . push ( ...body . graph . rootIds ( ) ) ;
335+ for ( const r of body . graph . rootIds ( ) ) {
336+ children . push ( r ) ;
337+ }
328338
329339 for ( const param of params ) {
330340 graph . mergeWith ( param . graph , true ) ;
331- children . push ( ...param . graph . rootIds ( ) ) ;
341+ for ( const r of param . graph . rootIds ( ) ) {
342+ children . push ( r ) ;
343+ }
332344 for ( const entry of param . entryPoints ) {
333345 graph . addEdge ( entry , fnId , { label : CfgEdgeType . Fd } ) ;
334346 }
@@ -354,7 +366,14 @@ function cfgFunctionDefinition(fn: RFunctionDefinition<ParentInformation>, param
354366function cfgFunctionCall ( call : RFunctionCall < ParentInformation > , name : ControlFlowInformation , args : ( ControlFlowInformation | typeof EmptyArgument ) [ ] , exit = 'exit' ) : ControlFlowInformation {
355367 const callId = call . info . id ;
356368 const graph = name . graph ;
357- const info = { graph, breaks : [ ...name . breaks ] , nexts : [ ...name . nexts ] , returns : [ ...name . returns ] , exitPoints : [ callId + '-' + exit ] , entryPoints : [ callId ] } ;
369+ const info = {
370+ graph,
371+ breaks : Array . from ( name . breaks ) ,
372+ nexts : Array . from ( name . nexts ) ,
373+ returns : Array . from ( name . returns ) ,
374+ exitPoints : [ callId + '-' + exit ] ,
375+ entryPoints : [ callId ]
376+ } ;
358377
359378 graph . addVertex ( { id : callId , type : identifyMayStatementType ( call ) , mid : name . exitPoints , end : [ callId + '-' + exit ] } ) ;
360379
@@ -420,8 +439,10 @@ function cfgFunctionCallWithDataflow(graph: DataflowGraph): typeof cfgFunctionCa
420439 root : call . info . id
421440 } ) ;
422441
423- for ( const exit of [ ...baseCfg . exitPoints , ...exits ] ) {
424- baseCfg . graph . addEdge ( call . info . id + ResolvedCallSuffix , exit , { label : CfgEdgeType . Fd } ) ;
442+ for ( const col of [ baseCfg . exitPoints , exits ] ) {
443+ for ( const exit of col ) {
444+ baseCfg . graph . addEdge ( call . info . id + ResolvedCallSuffix , exit , { label : CfgEdgeType . Fd } ) ;
445+ }
425446 }
426447
427448 return {
@@ -452,7 +473,6 @@ function cfgArgumentOrParameter(node: RNodeWithParent, name: ControlFlowInformat
452473 }
453474 }
454475
455-
456476 if ( value ) {
457477 graph . mergeWith ( value . graph ) ;
458478 info . breaks = info . breaks . concat ( value . breaks ) ;
@@ -473,12 +493,11 @@ function cfgArgumentOrParameter(node: RNodeWithParent, name: ControlFlowInformat
473493 }
474494
475495 return info ;
476-
477496}
478497
479498function cfgBinaryOp ( binOp : RBinaryOp < ParentInformation > | RPipe < ParentInformation > , lhs : ControlFlowInformation , rhs : ControlFlowInformation ) : ControlFlowInformation {
480499 const graph = new ControlFlowGraph ( ) . mergeWith ( lhs . graph ) . mergeWith ( rhs . graph ) ;
481- const result : ControlFlowInformation = { graph, breaks : [ ... lhs . breaks , ... rhs . breaks ] , nexts : [ ... lhs . nexts , ... rhs . nexts ] , returns : [ ... lhs . returns , ... rhs . returns ] , entryPoints : [ binOp . info . id ] , exitPoints : [ binOp . info . id + '-exit' ] } ;
500+ const result : ControlFlowInformation = { graph, breaks : lhs . breaks . concat ( rhs . breaks ) , nexts : lhs . nexts . concat ( rhs . nexts ) , returns : lhs . returns . concat ( rhs . returns ) , entryPoints : [ binOp . info . id ] , exitPoints : [ binOp . info . id + '-exit' ] } ;
482501
483502 graph . addVertex ( { id : binOp . info . id , type : binOp . flavor === 'assignment' ? CfgVertexType . Statement : CfgVertexType . Expression , end : [ binOp . info . id + '-exit' ] } ) ;
484503 graph . addVertex ( { id : binOp . info . id + '-exit' , type : CfgVertexType . EndMarker , root : binOp . info . id } ) ;
0 commit comments