Skip to content

Commit dc2c8f3

Browse files
committed
Update PrintCfg queries to use new interface
1 parent 9a048c9 commit dc2c8f3

6 files changed

Lines changed: 35 additions & 17 deletions

File tree

java/ql/lib/printCfg.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import java
11+
import PrintCfg
1112

1213
external string selectedSourceFile();
1314

@@ -21,14 +22,14 @@ external int selectedSourceColumn();
2122

2223
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;
2324

24-
module ViewCfgQueryInput implements ViewCfgQueryInputSig<File> {
25+
module ViewCfgQueryInput implements ViewGraphQueryInputSig<File> {
2526
predicate selectedSourceFile = selectedSourceFileAlias/0;
2627

2728
predicate selectedSourceLine = selectedSourceLineAlias/0;
2829

2930
predicate selectedSourceColumn = selectedSourceColumnAlias/0;
3031

31-
predicate cfgScopeSpan(
32+
predicate callableSpan(
3233
Callable callable, File file, int startLine, int startColumn, int endLine, int endColumn
3334
) {
3435
file = callable.getFile() and
@@ -42,4 +43,4 @@ module ViewCfgQueryInput implements ViewCfgQueryInputSig<File> {
4243
}
4344
}
4445

45-
import ViewCfgQuery<File, ViewCfgQueryInput>
46+
import ViewGraphQuery<File, ViewCfgQueryInput>

java/ql/lib/semmle/code/java/ControlFlowGraph.qll

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,16 +1776,28 @@ class ConditionNode extends ControlFlow::Node {
17761776
ExprParent getCondition() { result = this.asExpr() or result = this.asStmt() }
17771777
}
17781778

1779-
private import codeql.controlflow.PrintGraph as PrintGraph
1779+
private import codeql.util.PrintGraph as PrintGraph
17801780

17811781
private module PrintGraphInput implements PrintGraph::InputSig<Location> {
17821782
private import java as J
17831783

17841784
class Callable = J::Callable;
17851785

1786-
class ControlFlowNode = J::ControlFlowNode;
1786+
final private class FinalControlFlowNode = J::ControlFlowNode;
17871787

1788-
ControlFlowNode getASuccessor(ControlFlowNode n, SuccessorType t) { result = n.getASuccessor(t) }
1788+
class Node extends FinalControlFlowNode {
1789+
string getOrderDisambiguation() { result = "" }
1790+
}
1791+
1792+
predicate edge(Node node1, string s, Node node2) {
1793+
exists(SuccessorType t |
1794+
node2 = node1.getASuccessor(t) and
1795+
if t instanceof DirectSuccessor then s = "" else s = t.toString()
1796+
)
1797+
}
17891798
}
17901799

1791-
import PrintGraph::PrintGraph<Location, PrintGraphInput>
1800+
/** Provides utilities for visualising the CFG. */
1801+
module PrintCfg {
1802+
import PrintGraph::PrintGraph<Location, PrintGraphInput>
1803+
}

ruby/ql/lib/ide-contextual-queries/printCfg.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
private import codeql.Locations
1111
private import codeql.ruby.controlflow.internal.ControlFlowGraphImpl
1212
private import codeql.ruby.controlflow.ControlFlowGraph
13+
private import PrintCfg
1314

1415
external string selectedSourceFile();
1516

@@ -23,19 +24,19 @@ external int selectedSourceColumn();
2324

2425
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;
2526

26-
module ViewCfgQueryInput implements ViewCfgQueryInputSig<File> {
27+
module ViewCfgQueryInput implements ViewGraphQueryInputSig<File> {
2728
predicate selectedSourceFile = selectedSourceFileAlias/0;
2829

2930
predicate selectedSourceLine = selectedSourceLineAlias/0;
3031

3132
predicate selectedSourceColumn = selectedSourceColumnAlias/0;
3233

33-
predicate cfgScopeSpan(
34+
predicate callableSpan(
3435
CfgScope scope, File file, int startLine, int startColumn, int endLine, int endColumn
3536
) {
3637
file = scope.getFile() and
3738
scope.getLocation().hasLocationInfo(_, startLine, startColumn, endLine, endColumn)
3839
}
3940
}
4041

41-
import ViewCfgQuery<File, ViewCfgQueryInput>
42+
import ViewGraphQuery<File, ViewCfgQueryInput>

rust/ql/lib/ide-contextual-queries/PrintCfg.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
private import codeql.files.FileSystem
1111
private import codeql.rust.controlflow.internal.ControlFlowGraphImpl
1212
private import codeql.rust.controlflow.ControlFlowGraph
13+
private import PrintCfg
1314

1415
/**
1516
* Gets the source file to generate a CFG from.
@@ -32,19 +33,19 @@ external int selectedSourceColumn();
3233

3334
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;
3435

35-
private module ViewCfgQueryInput implements ViewCfgQueryInputSig<File> {
36+
private module ViewCfgQueryInput implements ViewGraphQueryInputSig<File> {
3637
predicate selectedSourceFile = selectedSourceFileAlias/0;
3738

3839
predicate selectedSourceLine = selectedSourceLineAlias/0;
3940

4041
predicate selectedSourceColumn = selectedSourceColumnAlias/0;
4142

42-
predicate cfgScopeSpan(
43+
predicate callableSpan(
4344
CfgScope scope, File file, int startLine, int startColumn, int endLine, int endColumn
4445
) {
4546
file = scope.getFile() and
4647
scope.getLocation().hasLocationInfo(_, startLine, startColumn, endLine, endColumn)
4748
}
4849
}
4950

50-
import ViewCfgQuery<File, ViewCfgQueryInput>
51+
import ViewGraphQuery<File, ViewCfgQueryInput>

shared/controlflow/codeql/controlflow/Cfg.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,10 @@ module MakeWithSplitting<
13301330
}
13311331
}
13321332

1333-
import Pp::PrintGraph<Location, PrintGraphInput>
1333+
/** Provides utilities for visualising the CFG. */
1334+
module PrintCfg {
1335+
import Pp::PrintGraph<Location, PrintGraphInput>
1336+
}
13341337

13351338
/** Provides a set of consistency queries. */
13361339
module Consistency {

swift/ql/lib/codeql/swift/controlflow/internal/PrintCFG.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ external int selectedSourceColumn();
3333

3434
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;
3535

36-
module ViewCfgQueryInput implements Impl::ViewCfgQueryInputSig<File> {
36+
module ViewCfgQueryInput implements Impl::PrintCfg::ViewGraphQueryInputSig<File> {
3737
predicate selectedSourceFile = selectedSourceFileAlias/0;
3838

3939
predicate selectedSourceLine = selectedSourceLineAlias/0;
4040

4141
predicate selectedSourceColumn = selectedSourceColumnAlias/0;
4242

43-
predicate cfgScopeSpan(
43+
predicate callableSpan(
4444
CfgInput::CfgScope scope, File file, int startLine, int startColumn, int endLine, int endColumn
4545
) {
4646
file = scope.getFile() and
4747
scope.getLocation().hasLocationInfo(_, startLine, startColumn, endLine, endColumn)
4848
}
4949
}
5050

51-
import Impl::ViewCfgQuery<File, ViewCfgQueryInput>
51+
import Impl::PrintCfg::ViewGraphQuery<File, ViewCfgQueryInput>

0 commit comments

Comments
 (0)