File tree Expand file tree Collapse file tree 6 files changed +39
-36
lines changed
Expand file tree Collapse file tree 6 files changed +39
-36
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,11 @@ import {
55 type CFGBuilder ,
66} from "./cfg-defs" ;
77import { Match } from "./block-matcher.ts" ;
8- import type { Context , StatementHandlers } from "./statement-handlers.ts" ;
9- import { GenericCFGBuilder } from "./generic-cfg-builder.ts" ;
8+ import {
9+ GenericCFGBuilder ,
10+ type Context ,
11+ type StatementHandlers ,
12+ } from "./generic-cfg-builder.ts" ;
1013import { pairwise , zip } from "./zip.ts" ;
1114import { buildSwitch , collectCases } from "./switch-utils.ts" ;
1215
Original file line number Diff line number Diff line change @@ -4,8 +4,11 @@ import {
44 type BuilderOptions ,
55 type CFGBuilder ,
66} from "./cfg-defs" ;
7- import type { Context , StatementHandlers } from "./statement-handlers" ;
8- import { GenericCFGBuilder } from "./generic-cfg-builder" ;
7+ import {
8+ GenericCFGBuilder ,
9+ type Context ,
10+ type StatementHandlers ,
11+ } from "./generic-cfg-builder" ;
912import { buildSwitch , collectCases , type SwitchOptions } from "./switch-utils" ;
1013
1114function getChildFieldText ( node : Parser . SyntaxNode , fieldName : string ) : string {
Original file line number Diff line number Diff line change @@ -4,8 +4,11 @@ import {
44 type BuilderOptions ,
55 type CFGBuilder ,
66} from "./cfg-defs" ;
7- import type { Context , StatementHandlers } from "./statement-handlers.ts" ;
8- import { GenericCFGBuilder } from "./generic-cfg-builder.ts" ;
7+ import {
8+ GenericCFGBuilder ,
9+ type Context ,
10+ type StatementHandlers ,
11+ } from "./generic-cfg-builder.ts" ;
912import { matchExistsIn } from "./block-matcher.ts" ;
1013import { maybe , zip } from "./zip.ts" ;
1114
Original file line number Diff line number Diff line change @@ -6,11 +6,33 @@ import {
66 type BuilderOptions ,
77 type CFG ,
88} from "./cfg-defs" ;
9- import type { StatementHandlers } from "./statement-handlers" ;
109import { BlockMatcher } from "./block-matcher" ;
1110import { NodeMapper } from "./node-mapper" ;
1211import { pairwise } from "./zip" ;
1312
13+ interface Dispatch {
14+ single ( syntax : Parser . SyntaxNode | null ) : BasicBlock ;
15+ many ( statements : Parser . SyntaxNode [ ] ) : BasicBlock ;
16+ }
17+ interface Link {
18+ syntaxToNode : InstanceType < typeof NodeMapper > [ "linkSytaxToNode" ] ;
19+ offsetToSyntax : InstanceType < typeof NodeMapper > [ "linkOffsetToSyntax" ] ;
20+ }
21+ export interface Context {
22+ builder : Builder ;
23+ options : BuilderOptions ;
24+ matcher : BlockMatcher ;
25+ dispatch : Dispatch ;
26+ state : BlockHandler ;
27+ link : Link ;
28+ }
29+
30+ type StatementHandler = ( syntax : Parser . SyntaxNode , ctx : Context ) => BasicBlock ;
31+ export type StatementHandlers = {
32+ named : { [ key : string ] : StatementHandler } ;
33+ default : StatementHandler ;
34+ } ;
35+
1436export class GenericCFGBuilder {
1537 private builder : Builder = new Builder ( ) ;
1638 private readonly options : BuilderOptions ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import type Parser from "web-tree-sitter" ;
22import type { Case , EdgeType } from "./cfg-defs" ;
3- import type { Context } from "./statement-handlers" ;
43import { pairwise } from "./zip" ;
4+ import type { Context } from "./generic-cfg-builder" ;
55export interface SwitchOptions {
66 /// A Go `select` blocks until one of the branches matches.
77 /// This means that we never add an alternative edge from the
You can’t perform that action at this time.
0 commit comments