-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathast-cfg-commands.ts
More file actions
82 lines (78 loc) · 2.22 KB
/
ast-cfg-commands.ts
File metadata and controls
82 lines (78 loc) · 2.22 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
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,
TemplatePrintCfgProvider,
} from "../contextual/template-provider";
type AstCfgOptions = {
localQueries: LocalQueries;
astViewer: AstViewer;
astTemplateProvider: TemplatePrintAstProvider;
cfgTemplateProvider: TemplatePrintCfgProvider;
};
export function getAstCfgCommands({
localQueries,
astViewer,
astTemplateProvider,
cfgTemplateProvider,
}: 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 viewCfg = async () =>
withProgress(
async (progress, token) => {
const editor = window.activeTextEditor;
const res = !editor
? undefined
: await cfgTemplateProvider.provideCfgUri(
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: "Calculating Control Flow Graph",
cancellable: true,
},
);
return {
"codeQL.viewAst": viewAst,
"codeQL.viewAstContextExplorer": viewAst,
"codeQL.viewAstContextEditor": viewAst,
"codeQL.viewCfg": viewCfg,
"codeQL.viewCfgContextExplorer": viewCfg,
"codeQL.viewCfgContextEditor": viewCfg,
};
}