Skip to content

Commit d6c10ca

Browse files
authored
feat(cfg): generics for normalized ast deco (#1635)
1 parent 8796e40 commit d6c10ca

File tree

2 files changed

+110
-59
lines changed

2 files changed

+110
-59
lines changed

src/control-flow/semantic-cfg-guided-visitor.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import type { DataflowInformation } from '../dataflow/info';
55

66
import type { DataflowCfgGuidedVisitorConfiguration } from './dfg-cfg-guided-visitor';
77
import { DataflowAwareCfgGuidedVisitor } from './dfg-cfg-guided-visitor';
8-
import type { NormalizedAst, RNodeWithParent } from '../r-bridge/lang-4.x/ast/model/processing/decorate';
8+
import type {
9+
NormalizedAst,
10+
ParentInformation
11+
} from '../r-bridge/lang-4.x/ast/model/processing/decorate';
912
import type { SyntaxCfgGuidedVisitorConfiguration } from './syntax-cfg-guided-visitor';
1013
import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
1114
import type { Origin } from '../dataflow/origin/dfg-get-origin';
@@ -24,14 +27,16 @@ import type { RLogical } from '../r-bridge/lang-4.x/ast/model/nodes/r-logical';
2427
import type { FunctionArgument } from '../dataflow/graph/graph';
2528
import { edgeIncludesType, EdgeType } from '../dataflow/graph/edge';
2629
import { guard } from '../util/assert';
30+
import type { NoInfo, RNode } from '../r-bridge/lang-4.x/ast/model/model';
2731

2832

2933

3034
export interface SemanticCfgGuidedVisitorConfiguration<
31-
Cfg extends ControlFlowInformation = ControlFlowInformation,
32-
Ast extends NormalizedAst = NormalizedAst,
33-
Dfg extends DataflowInformation = DataflowInformation
34-
> extends DataflowCfgGuidedVisitorConfiguration<Cfg, Dfg>, SyntaxCfgGuidedVisitorConfiguration<Cfg, Ast> {
35+
OtherInfo = NoInfo,
36+
Cfg extends ControlFlowInformation = ControlFlowInformation,
37+
Ast extends NormalizedAst<OtherInfo> = NormalizedAst<OtherInfo>,
38+
Dfg extends DataflowInformation = DataflowInformation
39+
> extends DataflowCfgGuidedVisitorConfiguration<Cfg, Dfg>, SyntaxCfgGuidedVisitorConfiguration<OtherInfo, Cfg, Ast> {
3540
}
3641

3742
/**
@@ -58,16 +63,17 @@ export interface SemanticCfgGuidedVisitorConfiguration<
5863
* Use {@link BasicCfgGuidedVisitor#start} to start the traversal.
5964
*/
6065
export class SemanticCfgGuidedVisitor<
61-
Cfg extends ControlFlowInformation = ControlFlowInformation,
62-
Ast extends NormalizedAst = NormalizedAst,
63-
Dfg extends DataflowInformation = DataflowInformation,
64-
Config extends SemanticCfgGuidedVisitorConfiguration<Cfg, Ast, Dfg> = SemanticCfgGuidedVisitorConfiguration<Cfg, Ast, Dfg>
66+
OtherInfo = NoInfo,
67+
Cfg extends ControlFlowInformation = ControlFlowInformation,
68+
Ast extends NormalizedAst<OtherInfo> = NormalizedAst<OtherInfo>,
69+
Dfg extends DataflowInformation = DataflowInformation,
70+
Config extends SemanticCfgGuidedVisitorConfiguration<OtherInfo, Cfg, Ast, Dfg> = SemanticCfgGuidedVisitorConfiguration<OtherInfo, Cfg, Ast, Dfg>
6571
> extends DataflowAwareCfgGuidedVisitor<Cfg, Dfg, Config> {
6672

6773
/**
6874
* Get the normalized AST node for the given id or fail if it does not exist.
6975
*/
70-
protected getNormalizedAst(id: NodeId): RNodeWithParent | undefined {
76+
protected getNormalizedAst(id: NodeId): RNode<OtherInfo & ParentInformation> | undefined {
7177
return this.config.normalizedAst.idMap.get(id);
7278
}
7379

src/control-flow/syntax-cfg-guided-visitor.ts

+94-49
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import type {
66
import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
77
import type {
88
NormalizedAst,
9-
ParentInformation,
10-
RNodeWithParent
9+
ParentInformation
1110
} from '../r-bridge/lang-4.x/ast/model/processing/decorate';
1211
import type { BasicCfgGuidedVisitorConfiguration } from './basic-cfg-guided-visitor';
1312
import { BasicCfgGuidedVisitor } from './basic-cfg-guided-visitor';
@@ -34,10 +33,12 @@ import type { RString } from '../r-bridge/lang-4.x/ast/model/nodes/r-string';
3433
import type { RNext } from '../r-bridge/lang-4.x/ast/model/nodes/r-next';
3534
import type { RNumber } from '../r-bridge/lang-4.x/ast/model/nodes/r-number';
3635
import type { RSymbol } from '../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
36+
import type { NoInfo, RNode } from '../r-bridge/lang-4.x/ast/model/model';
3737

3838
export interface SyntaxCfgGuidedVisitorConfiguration<
39-
Cfg extends ControlFlowInformation = ControlFlowInformation,
40-
Ast extends NormalizedAst = NormalizedAst
39+
OtherInfo = NoInfo,
40+
Cfg extends ControlFlowInformation = ControlFlowInformation,
41+
Ast extends NormalizedAst<OtherInfo> = NormalizedAst<OtherInfo>
4142
> extends BasicCfgGuidedVisitorConfiguration<Cfg> {
4243
readonly normalizedAst: Ast;
4344
}
@@ -48,15 +49,16 @@ export interface SyntaxCfgGuidedVisitorConfiguration<
4849
* Use {@link BasicCfgGuidedVisitor#start} to start the traversal.
4950
*/
5051
export class SyntaxAwareCfgGuidedVisitor<
52+
OtherInfo = NoInfo,
5153
Cfg extends ControlFlowInformation = ControlFlowInformation,
52-
Ast extends NormalizedAst = NormalizedAst,
53-
Config extends SyntaxCfgGuidedVisitorConfiguration<Cfg, Ast> = SyntaxCfgGuidedVisitorConfiguration<Cfg, Ast>
54+
Ast extends NormalizedAst<OtherInfo> = NormalizedAst<OtherInfo>,
55+
Config extends SyntaxCfgGuidedVisitorConfiguration<OtherInfo, Cfg, Ast> = SyntaxCfgGuidedVisitorConfiguration<OtherInfo, Cfg, Ast>,
5456
> extends BasicCfgGuidedVisitor<Cfg, Config> {
5557

5658
/**
5759
* Get the normalized AST node for the given id or fail if it does not exist.
5860
*/
59-
protected getNormalizedAst(id: NodeId): RNodeWithParent | undefined {
61+
protected getNormalizedAst(id: NodeId): RNode<OtherInfo & ParentInformation> | undefined {
6062
return this.config.normalizedAst.idMap.get(id);
6163
}
6264

@@ -125,46 +127,89 @@ export class SyntaxAwareCfgGuidedVisitor<
125127
}
126128
}
127129

128-
protected visitRAccess(_node: RAccess<ParentInformation>): void {
129-
}
130-
protected visitRArgument(_node: RArgument<ParentInformation>): void {
131-
}
132-
protected visitRBinaryOp(_node: RBinaryOp<ParentInformation>): void {
133-
}
134-
protected visitRExpressionList(_node: RExpressionList<ParentInformation>): void {
135-
}
136-
protected visitRForLoop(_node: RForLoop<ParentInformation>): void {
137-
}
138-
protected visitRFunctionCall(_node: RFunctionCall<ParentInformation>): void {
139-
}
140-
protected visitRFunctionDefinition(_node: RFunctionDefinition<ParentInformation>): void {
141-
}
142-
protected visitRIfThenElse(_node: RIfThenElse<ParentInformation>): void {
143-
}
144-
protected visitRParameter(_node: RParameter<ParentInformation>): void {
145-
}
146-
protected visitRPipe(_node: RPipe<ParentInformation>): void {
147-
}
148-
protected visitRRepeatLoop(_node: RRepeatLoop<ParentInformation>): void {
149-
}
150-
protected visitRUnaryOp(_node: RUnaryOp<ParentInformation>): void {
151-
}
152-
protected visitRWhileLoop(_node: RWhileLoop<ParentInformation>): void {
153-
}
154-
protected visitRBreak(_node: RBreak<ParentInformation>): void {
155-
}
156-
protected visitRComment(_node: RComment<ParentInformation>): void {
157-
}
158-
protected visitRLineDirective(_node: RLineDirective<ParentInformation>): void {
159-
}
160-
protected visitRLogical(_node: RLogical<ParentInformation>): void {
161-
}
162-
protected visitRNext(_node: RNext<ParentInformation>): void {
163-
}
164-
protected visitRNumber(_node: RNumber<ParentInformation>): void {
165-
}
166-
protected visitRString(_node: RString<ParentInformation>): void {
167-
}
168-
protected visitRSymbol(_node: RSymbol<ParentInformation>): void {
169-
}
130+
131+
/**
132+
* {@link RAccess}
133+
*/
134+
protected visitRAccess(_node: RAccess<OtherInfo & ParentInformation>): void {}
135+
/**
136+
* {@link RArgument}
137+
*/
138+
protected visitRArgument(_node: RArgument<OtherInfo & ParentInformation>): void {}
139+
/**
140+
* {@link RBinaryOp}
141+
*/
142+
protected visitRBinaryOp(_node: RBinaryOp<OtherInfo & ParentInformation>): void {}
143+
/**
144+
* {@link RExpressionList}
145+
*/
146+
protected visitRExpressionList(_node: RExpressionList<OtherInfo & ParentInformation>): void {}
147+
/**
148+
* {@link RForLoop}
149+
*/
150+
protected visitRForLoop(_node: RForLoop<OtherInfo & ParentInformation>): void {}
151+
/**
152+
* {@link RFunctionCall}
153+
*/
154+
protected visitRFunctionCall(_node: RFunctionCall<OtherInfo & ParentInformation>): void {}
155+
/**
156+
* {@link RFunctionDefinition}
157+
*/
158+
protected visitRFunctionDefinition(_node: RFunctionDefinition<OtherInfo & ParentInformation>): void {}
159+
/**
160+
* {@link RIfThenElse}
161+
*/
162+
protected visitRIfThenElse(_node: RIfThenElse<OtherInfo & ParentInformation>): void {}
163+
/**
164+
* {@link RParameter}
165+
*/
166+
protected visitRParameter(_node: RParameter<OtherInfo & ParentInformation>): void {}
167+
/**
168+
* {@link RPipe}
169+
*/
170+
protected visitRPipe(_node: RPipe<OtherInfo & ParentInformation>): void {}
171+
/**
172+
* {@link RRepeatLoop}
173+
*/
174+
protected visitRRepeatLoop(_node: RRepeatLoop<OtherInfo & ParentInformation>): void {}
175+
/**
176+
* {@link RUnaryOp}
177+
*/
178+
protected visitRUnaryOp(_node: RUnaryOp<OtherInfo & ParentInformation>): void {}
179+
/**
180+
* {@link RWhileLoop}
181+
*/
182+
protected visitRWhileLoop(_node: RWhileLoop<OtherInfo & ParentInformation>): void {}
183+
/**
184+
* {@link RBreak}
185+
*/
186+
protected visitRBreak(_node: RBreak<OtherInfo & ParentInformation>): void {}
187+
/**
188+
* {@link RComment}
189+
*/
190+
protected visitRComment(_node: RComment<OtherInfo & ParentInformation>): void {}
191+
/**
192+
* {@link RLineDirective}
193+
*/
194+
protected visitRLineDirective(_node: RLineDirective<OtherInfo & ParentInformation>): void {}
195+
/**
196+
* {@link RLogical}
197+
*/
198+
protected visitRLogical(_node: RLogical<OtherInfo & ParentInformation>): void {}
199+
/**
200+
* {@link RNext}
201+
*/
202+
protected visitRNext(_node: RNext<OtherInfo & ParentInformation>): void {}
203+
/**
204+
* {@link RNumber}
205+
*/
206+
protected visitRNumber(_node: RNumber<OtherInfo & ParentInformation>): void {}
207+
/**
208+
* {@link RString}
209+
*/
210+
protected visitRString(_node: RString<OtherInfo & ParentInformation>): void {}
211+
/**
212+
* {@link RSymbol}
213+
*/
214+
protected visitRSymbol(_node: RSymbol<OtherInfo & ParentInformation>): void {}
170215
}

0 commit comments

Comments
 (0)