@@ -7,21 +7,23 @@ import type { LocalQueries } from "../../local-queries";
77import { QuickEvalType } from "../../local-queries" ;
88import type {
99 TemplatePrintAstProvider ,
10- TemplatePrintCfgProvider ,
10+ TemplatePrintGraphProvider ,
1111} from "../contextual/template-provider" ;
1212
1313type AstCfgOptions = {
1414 localQueries : LocalQueries ;
1515 astViewer : AstViewer ;
1616 astTemplateProvider : TemplatePrintAstProvider ;
17- cfgTemplateProvider : TemplatePrintCfgProvider ;
17+ cfgTemplateProvider : TemplatePrintGraphProvider ;
18+ dfgTemplateProvider : TemplatePrintGraphProvider ;
1819} ;
1920
2021export function getAstCfgCommands ( {
2122 localQueries,
2223 astViewer,
2324 astTemplateProvider,
2425 cfgTemplateProvider,
26+ dfgTemplateProvider,
2527} : AstCfgOptions ) : AstCfgCommands {
2628 const viewAst = async ( selectedFile : Uri ) =>
2729 withProgress (
@@ -41,35 +43,49 @@ export function getAstCfgCommands({
4143 } ,
4244 ) ;
4345
44- const viewCfg = async ( ) =>
45- withProgress (
46- async ( progress , token ) => {
47- const editor = window . activeTextEditor ;
48- const res = ! editor
49- ? undefined
50- : await cfgTemplateProvider . provideCfgUri (
51- editor . document ,
52- editor . selection . active . line + 1 ,
53- editor . selection . active . character + 1 ,
46+ const viewGraph = (
47+ provider : TemplatePrintGraphProvider ,
48+ title : string ,
49+ ) => {
50+ return async ( ) =>
51+ withProgress (
52+ async ( progress , token ) => {
53+ const editor = window . activeTextEditor ;
54+ const res = ! editor
55+ ? undefined
56+ : await provider . provideGraphUri (
57+ editor . document ,
58+ editor . selection . active . line + 1 ,
59+ editor . selection . active . character + 1 ,
60+ ) ;
61+ if ( res ) {
62+ await localQueries . compileAndRunQuery (
63+ QuickEvalType . None ,
64+ res [ 0 ] ,
65+ progress ,
66+ token ,
67+ undefined ,
68+ false ,
69+ undefined ,
70+ res [ 1 ] ,
5471 ) ;
55- if ( res ) {
56- await localQueries . compileAndRunQuery (
57- QuickEvalType . None ,
58- res [ 0 ] ,
59- progress ,
60- token ,
61- undefined ,
62- false ,
63- undefined ,
64- res [ 1 ] ,
65- ) ;
66- }
67- } ,
68- {
69- title : "Calculating Control Flow Graph" ,
70- cancellable : true ,
71- } ,
72- ) ;
72+ }
73+ } ,
74+ {
75+ title,
76+ cancellable : true ,
77+ } ,
78+ ) ;
79+ } ;
80+
81+ const viewCfg = viewGraph (
82+ cfgTemplateProvider ,
83+ "Calculating Control Flow Graph" ,
84+ ) ;
85+ const viewDfg = viewGraph (
86+ dfgTemplateProvider ,
87+ "Calculating Data Flow Graph" ,
88+ ) ;
7389
7490 return {
7591 "codeQL.viewAst" : viewAst ,
@@ -78,5 +94,8 @@ export function getAstCfgCommands({
7894 "codeQL.viewCfg" : viewCfg ,
7995 "codeQL.viewCfgContextExplorer" : viewCfg ,
8096 "codeQL.viewCfgContextEditor" : viewCfg ,
97+ "codeQL.viewDfg" : viewDfg ,
98+ "codeQL.viewDfgContextExplorer" : viewDfg ,
99+ "codeQL.viewDfgContextEditor" : viewDfg ,
81100 } ;
82101}
0 commit comments