-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathast-cfg-commands.ts
More file actions
95 lines (90 loc) · 2.68 KB
/
ast-cfg-commands.ts
File metadata and controls
95 lines (90 loc) · 2.68 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import type { Uri } from "vscode";
import { window } from "vscode";
import { withProgress } from "../../common/vscode/progress";
import type { AstViewer } from "./ast-viewer";
import type { AstCfgCommands } from "../../common/commands";
import type { LocalQueries } from "../../local-queries";
import { QuickEvalType } from "../../local-queries";
import type {
TemplatePrintAstProvider,
TemplatePrintGraphProvider,
} from "../contextual/template-provider";
type AstCfgOptions = {
localQueries: LocalQueries;
astViewer: AstViewer;
astTemplateProvider: TemplatePrintAstProvider;
cfgTemplateProvider: TemplatePrintGraphProvider;
dfgTemplateProvider: TemplatePrintGraphProvider;
};
export function getAstCfgCommands({
localQueries,
astViewer,
astTemplateProvider,
cfgTemplateProvider,
dfgTemplateProvider,
}: AstCfgOptions): AstCfgCommands {
const viewAst = async (selectedFile: Uri) =>
withProgress(
async (progress, token) => {
const ast = await astTemplateProvider.provideAst(
progress,
token,
selectedFile ?? window.activeTextEditor?.document.uri,
);
if (ast) {
astViewer.updateRoots(await ast.getRoots(), ast.db, ast.fileName);
}
},
{
cancellable: true,
title: "Calculate AST",
},
);
const viewGraph = (provider: TemplatePrintGraphProvider, title: string) => {
return async () =>
withProgress(
async (progress, token) => {
const editor = window.activeTextEditor;
const res = !editor
? undefined
: await provider.provideGraphUri(
editor.document,
editor.selection.active.line + 1,
editor.selection.active.character + 1,
);
if (res) {
await localQueries.compileAndRunQuery(
QuickEvalType.None,
res[0],
progress,
token,
undefined,
false,
undefined,
res[1],
);
}
},
{
title,
cancellable: true,
},
);
};
const viewCfg = viewGraph(
cfgTemplateProvider,
"Calculating Control Flow Graph",
);
const viewDfg = viewGraph(dfgTemplateProvider, "Calculating Data Flow Graph");
return {
"codeQL.viewAst": viewAst,
"codeQL.viewAstContextExplorer": viewAst,
"codeQL.viewAstContextEditor": viewAst,
"codeQL.viewCfg": viewCfg,
"codeQL.viewCfgContextExplorer": viewCfg,
"codeQL.viewCfgContextEditor": viewCfg,
"codeQL.viewDfg": viewDfg,
"codeQL.viewDfgContextExplorer": viewDfg,
"codeQL.viewDfgContextEditor": viewDfg,
};
}