Skip to content

Commit 3d5d270

Browse files
committed
Dataflow: Reduce duplication, define PathGraphSig only once.
1 parent 4a5c9f0 commit 3d5d270

File tree

3 files changed

+29
-34
lines changed

3 files changed

+29
-34
lines changed

shared/dataflow/codeql/dataflow/DataFlow.qll

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,30 @@ module Configs<LocationSig Location, InputSig<Location> Lang> {
562562
}
563563
}
564564

565+
/** A type with `toString`. */
566+
private signature class TypeWithToString {
567+
string toString();
568+
}
569+
570+
import PathGraphSigMod
571+
572+
private module PathGraphSigMod {
573+
signature module PathGraphSig<TypeWithToString PathNode> {
574+
/** Holds if `(a,b)` is an edge in the graph of data flow path explanations. */
575+
predicate edges(PathNode a, PathNode b, string key, string val);
576+
577+
/** Holds if `n` is a node in the graph of data flow path explanations. */
578+
predicate nodes(PathNode n, string key, string val);
579+
580+
/**
581+
* Holds if `(arg, par, ret, out)` forms a subpath-tuple, that is, flow through
582+
* a subpath between `par` and `ret` with the connecting edges `arg -> par` and
583+
* `ret -> out` is summarized as the edge `arg -> out`.
584+
*/
585+
predicate subpaths(PathNode arg, PathNode par, PathNode ret, PathNode out);
586+
}
587+
}
588+
565589
module DataFlowMake<LocationSig Location, InputSig<Location> Lang> {
566590
private import Lang
567591
private import internal.DataFlowImpl::MakeImpl<Location, Lang>
@@ -663,20 +687,7 @@ module DataFlowMake<LocationSig Location, InputSig<Location> Lang> {
663687
Location getLocation();
664688
}
665689

666-
signature module PathGraphSig<PathNodeSig PathNode> {
667-
/** Holds if `(a,b)` is an edge in the graph of data flow path explanations. */
668-
predicate edges(PathNode a, PathNode b, string key, string val);
669-
670-
/** Holds if `n` is a node in the graph of data flow path explanations. */
671-
predicate nodes(PathNode n, string key, string val);
672-
673-
/**
674-
* Holds if `(arg, par, ret, out)` forms a subpath-tuple, that is, flow through
675-
* a subpath between `par` and `ret` with the connecting edges `arg -> par` and
676-
* `ret -> out` is summarized as the edge `arg -> out`.
677-
*/
678-
predicate subpaths(PathNode arg, PathNode par, PathNode ret, PathNode out);
679-
}
690+
import PathGraphSigMod
680691

681692
/**
682693
* Constructs a `PathGraph` from two `PathGraph`s by disjoint union.

shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4291,12 +4291,10 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
42914291
final predicate isSinkGroup(string group) { this = TPathNodeSinkGroup(group) }
42924292
}
42934293

4294-
private import codeql.dataflow.test.ProvenancePathGraph as ProvenancePathGraph
4295-
42964294
/**
42974295
* Provides the query predicates needed to include a graph in a path-problem query.
42984296
*/
4299-
module PathGraph implements PathGraphSig<PathNode>, ProvenancePathGraph::PathGraphSig<PathNode> {
4297+
module PathGraph implements PathGraphSig<PathNode> {
43004298
/** Holds if `(a,b)` is an edge in the graph of data flow path explanations. */
43014299
query predicate edges(PathNode a, PathNode b, string key, string val) {
43024300
a.(PathNodeImpl).getANonHiddenSuccessor(val) = b and

shared/dataflow/codeql/dataflow/test/ProvenancePathGraph.qll

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* In addition to the `PathGraph`, a `query predicate models` is provided to
66
* list the contents of the referenced MaD rows.
77
*/
8-
module;
8+
9+
private import codeql.dataflow.DataFlow as DF
910

1011
signature predicate interpretModelForTestSig(QlBuiltins::ExtensionId madId, string model);
1112

@@ -15,21 +16,6 @@ signature class PathNodeSig {
1516
string toString();
1617
}
1718

18-
signature module PathGraphSig<PathNodeSig PathNode> {
19-
/** Holds if `(a,b)` is an edge in the graph of data flow path explanations. */
20-
predicate edges(PathNode a, PathNode b, string key, string val);
21-
22-
/** Holds if `n` is a node in the graph of data flow path explanations. */
23-
predicate nodes(PathNode n, string key, string val);
24-
25-
/**
26-
* Holds if `(arg, par, ret, out)` forms a subpath-tuple, that is, flow through
27-
* a subpath between `par` and `ret` with the connecting edges `arg -> par` and
28-
* `ret -> out` is summarized as the edge `arg -> out`.
29-
*/
30-
predicate subpaths(PathNode arg, PathNode par, PathNode ret, PathNode out);
31-
}
32-
3319
private signature predicate provenanceSig(string model);
3420

3521
private module TranslateModels<
@@ -79,7 +65,7 @@ private module TranslateModels<
7965
/** Transforms a `PathGraph` by printing the provenance information. */
8066
module ShowProvenance<
8167
interpretModelForTestSig/2 interpretModelForTest, PathNodeSig PathNode,
82-
PathGraphSig<PathNode> PathGraph>
68+
DF::PathGraphSig<PathNode> PathGraph>
8369
{
8470
private predicate provenance(string model) { PathGraph::edges(_, _, _, model) }
8571

0 commit comments

Comments
 (0)