Skip to content

Commit f738959

Browse files
committed
Rust: Hide internal implementation details from DataFlow::Node
1 parent 180782d commit f738959

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

rust/ql/lib/codeql/rust/dataflow/DataFlow.qll

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
private import rust
7+
private import codeql.rust.controlflow.CfgNodes
78
private import codeql.dataflow.DataFlow
89
private import internal.DataFlowImpl as DataFlowImpl
910
private import DataFlowImpl::Node as Node
@@ -13,7 +14,24 @@ private import DataFlowImpl::Node as Node
1314
* (inter-procedural) data flow analyses.
1415
*/
1516
module DataFlow {
16-
final class Node = Node::Node;
17+
/** An element, viewed as a node in a data flow graph. */
18+
final class Node instanceof Node::Node {
19+
/** Gets the location of this node. */
20+
Location getLocation() { result = super.getLocation() }
21+
22+
/** Gets a textual representation of this node. */
23+
string toString() { result = super.toString() }
24+
25+
/**
26+
* Gets the expression that corresponds to this node, if any.
27+
*/
28+
ExprCfgNode asExpr() { result = super.asExpr() }
29+
30+
/**
31+
* Gets the pattern that corresponds to this node, if any.
32+
*/
33+
PatCfgNode asPat() { result = super.asPat() }
34+
}
1735

1836
/**
1937
* The value of a parameter at function entry, viewed as a node in a data
@@ -24,7 +42,18 @@ module DataFlow {
2442
ParamBase getParameter() { result = super.getParameter().getParamBase() }
2543
}
2644

27-
final class PostUpdateNode = Node::PostUpdateNode;
45+
/**
46+
* A node associated with an object after an operation that might have
47+
* changed its state.
48+
*
49+
* This can be either the argument to a callable after the callable returns
50+
* (which might have mutated the argument), or the qualifier of a field after
51+
* an update to the field.
52+
*/
53+
final class PostUpdateNode extends Node instanceof Node::PostUpdateNode {
54+
/** Gets the node before the state update. */
55+
Node getPreUpdateNode() { result = super.getPreUpdateNode() }
56+
}
2857

2958
final class Content = DataFlowImpl::Content;
3059

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ private predicate isArgumentForCall(ExprCfgNode arg, CallExprBaseCfgNode call, P
129129
}
130130

131131
module Node {
132-
/**
133-
* An element, viewed as a node in a data flow graph. Either an expression
134-
* (`ExprNode`) or a parameter (`ParameterNode`).
135-
*/
132+
/** An element, viewed as a node in a data flow graph. */
136133
abstract class Node extends TNode {
137134
/** Gets the location of this node. */
138135
abstract Location getLocation();
@@ -150,6 +147,11 @@ module Node {
150147
*/
151148
PatCfgNode asPat() { none() }
152149

150+
/**
151+
* Gets the SSA definition that corresponds to this node, if any.
152+
*/
153+
Ssa::Definition asDefinition() { none() }
154+
153155
/** Gets the enclosing callable. */
154156
DataFlowCallable getEnclosingCallable() { result = TCfgScope(this.getCfgScope()) }
155157

@@ -160,11 +162,6 @@ module Node {
160162
* Gets the control flow node that corresponds to this data flow node.
161163
*/
162164
CfgNode getCfgNode() { none() }
163-
164-
/**
165-
* Gets this node's underlying SSA definition, if any.
166-
*/
167-
Ssa::Definition asDefinition() { none() }
168165
}
169166

170167
/** A node type that is not implemented. */

rust/ql/lib/utils/test/InlineFlowTest.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ private predicate callTargetName(CallExprCfgNode call, string name) {
2222
}
2323

2424
private module FlowTestImpl implements InputSig<Location, RustDataFlow> {
25-
predicate defaultSource(DataFlow::Node source) { callTargetName(source.asExpr(), "source") }
25+
predicate defaultSource(RustDataFlow::Node source) { callTargetName(source.asExpr(), "source") }
2626

27-
predicate defaultSink(DataFlow::Node sink) {
27+
predicate defaultSink(RustDataFlow::Node sink) {
2828
any(CallExprCfgNode call | callTargetName(call, "sink")).getArgument(_) = sink.asExpr()
2929
}
3030

@@ -40,7 +40,7 @@ private module FlowTestImpl implements InputSig<Location, RustDataFlow> {
4040
}
4141

4242
bindingset[src, sink]
43-
string getArgString(DataFlow::Node src, DataFlow::Node sink) {
43+
string getArgString(RustDataFlow::Node src, RustDataFlow::Node sink) {
4444
(
4545
result = getSourceArgString(src)
4646
or

0 commit comments

Comments
 (0)