@@ -17,36 +17,33 @@ import {
1717export class CFGBuilder {
1818 private graph : MultiDirectedGraph < GraphNode , GraphEdge > =
1919 new MultiDirectedGraph ( ) ;
20- private entry : string ;
2120 private nodeId : number = 0 ;
2221 private clusterId : ClusterId = 0 ;
2322 private readonly flatSwitch : boolean ;
2423 private readonly markerPattern : RegExp | null ;
2524 private activeClusters : Cluster [ ] = [ ] ;
2625
2726 constructor ( options ?: BuilderOptions ) {
28- this . entry = null ;
2927
3028 this . flatSwitch = options ?. flatSwitch ?? false ;
3129 this . markerPattern = options ?. markerPattern ?? null ;
3230 }
3331
3432 public buildCFG ( functionNode : Parser . SyntaxNode ) : CFG {
33+ const startNode = this . addNode ( "START" , "START" ) ;
3534 const bodyNode = functionNode . childForFieldName ( "body" ) ;
3635 if ( bodyNode ) {
3736 const blockHandler = new BlockHandler ( ) ;
3837 const { entry, exit } = blockHandler . update (
3938 this . processStatements ( bodyNode . namedChildren ) ,
4039 ) ;
4140
42- const startNode = this . addNode ( "START" , "START" ) ;
4341 const endNode = this . addNode ( "RETURN" , "implicit return" ) ;
4442 // `entry` will be non-null for any valid code
4543 if ( entry ) this . addEdge ( startNode , entry ) ;
4644 if ( exit ) this . addEdge ( exit , endNode ) ;
47- this . entry = startNode ;
4845 }
49- return { graph : this . graph , entry : this . entry } ;
46+ return { graph : this . graph , entry : startNode } ;
5047 }
5148
5249 private startCluster ( type : ClusterType ) : Cluster {
0 commit comments