/
ExecutionContext.ts
60 lines (53 loc) · 1.55 KB
/
ExecutionContext.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import type { Entity } from './Entity';
import type { ExpressionEntity } from './nodes/shared/Expression';
import { DiscriminatedPathTracker, PathTracker } from './utils/PathTracker';
import type ThisVariable from './variables/ThisVariable';
interface ExecutionContextIgnore {
breaks: boolean;
continues: boolean;
labels: Set<string>;
returnYield: boolean;
}
export const BROKEN_FLOW_NONE = 0;
export const BROKEN_FLOW_BREAK_CONTINUE = 1;
export const BROKEN_FLOW_ERROR_RETURN_LABEL = 2;
interface ControlFlowContext {
brokenFlow: number;
includedLabels: Set<string>;
}
export interface InclusionContext extends ControlFlowContext {
includedCallArguments: Set<Entity>;
}
export interface HasEffectsContext extends ControlFlowContext {
accessed: PathTracker;
assigned: PathTracker;
brokenFlow: number;
called: DiscriminatedPathTracker;
ignore: ExecutionContextIgnore;
instantiated: DiscriminatedPathTracker;
replacedVariableInits: Map<ThisVariable, ExpressionEntity>;
}
export function createInclusionContext(): InclusionContext {
return {
brokenFlow: BROKEN_FLOW_NONE,
includedCallArguments: new Set(),
includedLabels: new Set()
};
}
export function createHasEffectsContext(): HasEffectsContext {
return {
accessed: new PathTracker(),
assigned: new PathTracker(),
brokenFlow: BROKEN_FLOW_NONE,
called: new DiscriminatedPathTracker(),
ignore: {
breaks: false,
continues: false,
labels: new Set(),
returnYield: false
},
includedLabels: new Set(),
instantiated: new DiscriminatedPathTracker(),
replacedVariableInits: new Map()
};
}