Skip to content

Commit 4d885a8

Browse files
authored
Merge pull request #21921 from github/yoff/python-add-new-cfg-library
Python: add new shared-CFG-backed control flow graph (additive)
2 parents 0751408 + 3ad4861 commit 4d885a8

54 files changed

Lines changed: 3664 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import semmle.python.controlflow.internal.AstNodeImpl
2+
import ControlFlow::Consistency
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @name Print CFG
3+
* @description Produces a representation of a file's Control Flow Graph.
4+
* This query is used by the VS Code extension.
5+
* @id py/print-cfg
6+
* @kind graph
7+
* @tags ide-contextual-queries/print-cfg
8+
*/
9+
10+
import semmle.python.Files as Files
11+
import semmle.python.controlflow.internal.AstNodeImpl
12+
13+
external string selectedSourceFile();
14+
15+
private predicate selectedSourceFileAlias = selectedSourceFile/0;
16+
17+
external int selectedSourceLine();
18+
19+
private predicate selectedSourceLineAlias = selectedSourceLine/0;
20+
21+
external int selectedSourceColumn();
22+
23+
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;
24+
25+
module ViewCfgQueryInput implements ControlFlow::ViewCfgQueryInputSig<Files::File> {
26+
predicate selectedSourceFile = selectedSourceFileAlias/0;
27+
28+
predicate selectedSourceLine = selectedSourceLineAlias/0;
29+
30+
predicate selectedSourceColumn = selectedSourceColumnAlias/0;
31+
32+
predicate cfgScopeSpan(
33+
Ast::Callable scope, Files::File file, int startLine, int startColumn, int endLine,
34+
int endColumn
35+
) {
36+
file = scope.getLocation().getFile() and
37+
scope.getLocation().hasLocationInfo(_, startLine, startColumn, endLine, endColumn)
38+
}
39+
}
40+
41+
import ControlFlow::ViewCfgQuery<Files::File, ViewCfgQueryInput>

0 commit comments

Comments
 (0)