@@ -17,36 +17,33 @@ import {
17
17
export class CFGBuilder {
18
18
private graph : MultiDirectedGraph < GraphNode , GraphEdge > =
19
19
new MultiDirectedGraph ( ) ;
20
- private entry : string ;
21
20
private nodeId : number = 0 ;
22
21
private clusterId : ClusterId = 0 ;
23
22
private readonly flatSwitch : boolean ;
24
23
private readonly markerPattern : RegExp | null ;
25
24
private activeClusters : Cluster [ ] = [ ] ;
26
25
27
26
constructor ( options ?: BuilderOptions ) {
28
- this . entry = null ;
29
27
30
28
this . flatSwitch = options ?. flatSwitch ?? false ;
31
29
this . markerPattern = options ?. markerPattern ?? null ;
32
30
}
33
31
34
32
public buildCFG ( functionNode : Parser . SyntaxNode ) : CFG {
33
+ const startNode = this . addNode ( "START" , "START" ) ;
35
34
const bodyNode = functionNode . childForFieldName ( "body" ) ;
36
35
if ( bodyNode ) {
37
36
const blockHandler = new BlockHandler ( ) ;
38
37
const { entry, exit } = blockHandler . update (
39
38
this . processStatements ( bodyNode . namedChildren ) ,
40
39
) ;
41
40
42
- const startNode = this . addNode ( "START" , "START" ) ;
43
41
const endNode = this . addNode ( "RETURN" , "implicit return" ) ;
44
42
// `entry` will be non-null for any valid code
45
43
if ( entry ) this . addEdge ( startNode , entry ) ;
46
44
if ( exit ) this . addEdge ( exit , endNode ) ;
47
- this . entry = startNode ;
48
45
}
49
- return { graph : this . graph , entry : this . entry } ;
46
+ return { graph : this . graph , entry : startNode } ;
50
47
}
51
48
52
49
private startCluster ( type : ClusterType ) : Cluster {
0 commit comments