Skip to content

Commit 31d5a4d

Browse files
committed
generic-cfg-builder: the end of a function is now mapped to the last statement, for purposes of CFG node mapping
1 parent 8ca7ccb commit 31d5a4d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/control-flow/generic-cfg-builder.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,17 @@ export class GenericCFGBuilder {
4040
// `entry` will be non-null for any valid code
4141
if (entry) this.builder.addEdge(startNode, entry);
4242
if (exit) this.builder.addEdge(exit, endNode);
43+
44+
45+
// Make sure the end of the function is linked to the last piece of code, not to the top of the function.
46+
const lastStatement = bodySyntax.namedChildren[bodySyntax.namedChildren.length - 1];
47+
if (lastStatement) {
48+
this.nodeMapper.linkGap(lastStatement, functionNode, { includeTo: true, reverse: true });
49+
console.log(lastStatement.text)
50+
}
4351
}
4452

53+
4554
return {
4655
graph: this.builder.getGraph(),
4756
entry: startNode,

0 commit comments

Comments
 (0)