Skip to content

Commit 7a48fe1

Browse files
committed
Dataflow: Replace ppReprType with DataFlowType.toString.
1 parent 4cbc334 commit 7a48fe1

File tree

11 files changed

+36
-46
lines changed

11 files changed

+36
-46
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,19 +215,16 @@ predicate typeStrongerThan(DataFlowType t1, DataFlowType t2) { none() }
215215
predicate localMustFlowStep(Node node1, Node node2) { none() }
216216

217217
/** Gets the type of `n` used for type pruning. */
218-
Type getNodeType(Node n) {
218+
DataFlowType getNodeType(Node n) {
219219
exists(n) and
220220
result instanceof VoidType // stub implementation
221221
}
222222

223-
/** Gets a string representation of a type returned by `getNodeType`. */
224-
string ppReprType(Type t) { none() } // stub implementation
225-
226223
/**
227224
* Holds if `t1` and `t2` are compatible, that is, whether data can flow from
228225
* a node of type `t1` to a node of type `t2`.
229226
*/
230-
predicate compatibleTypes(Type t1, Type t2) {
227+
predicate compatibleTypes(DataFlowType t1, DataFlowType t2) {
231228
t1 instanceof VoidType and t2 instanceof VoidType // stub implementation
232229
}
233230

@@ -243,7 +240,11 @@ class DataFlowCallable extends Function { }
243240

244241
class DataFlowExpr = Expr;
245242

246-
class DataFlowType = Type;
243+
final private class TypeFinal = Type;
244+
245+
class DataFlowType extends TypeFinal {
246+
string toString() { result = "" }
247+
}
247248

248249
/** A function call relevant for data flow. */
249250
class DataFlowCall extends Expr instanceof Call {

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -994,9 +994,6 @@ DataFlowType getNodeType(Node n) {
994994
result instanceof VoidType // stub implementation
995995
}
996996

997-
/** Gets a string representation of a type returned by `getNodeType`. */
998-
string ppReprType(DataFlowType t) { none() } // stub implementation
999-
1000997
/**
1001998
* Holds if `t1` and `t2` are compatible, that is, whether data can flow from
1002999
* a node of type `t1` to a node of type `t2`.
@@ -1097,7 +1094,11 @@ class SummarizedCallable extends DataFlowCallable, TSummarizedCallable {
10971094

10981095
class DataFlowExpr = Expr;
10991096

1100-
class DataFlowType = Type;
1097+
final private class TypeFinal = Type;
1098+
1099+
class DataFlowType extends TypeFinal {
1100+
string toString() { result = "" }
1101+
}
11011102

11021103
cached
11031104
private newtype TDataFlowCall =

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,9 +2444,6 @@ DataFlowType getNodeType(Node n) {
24442444
] = result.getADelegateCreation()
24452445
}
24462446

2447-
/** Gets a string representation of a `DataFlowType`. */
2448-
string ppReprType(DataFlowType t) { result = t.toString() }
2449-
24502447
private class DataFlowNullType extends Gvn::GvnType {
24512448
DataFlowNullType() { this = Gvn::getGlobalValueNumber(any(NullType nt)) }
24522449

docs/ql-libraries/dataflow/dataflow.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,9 @@ DataFlowType getNodeType(Node n)
548548
```
549549
and every `Node` should have a type.
550550

551-
One also needs to define the string representation of a `DataFlowType`:
552-
```ql
553-
string ppReprType(DataFlowType t)
554-
```
555-
The `ppReprType` predicate is used for printing a type in the labels of
556-
`PathNode`s, this can be defined as `none()` if type pruning is not used.
551+
One also needs to define the string representation of a `DataFlowType`.
552+
The `DataFlowType.toString` predicate is used for printing a type in the labels of
553+
`PathNode`s, this should be defined as `result = ""` if type pruning is not used.
557554

558555
Finally, one must define `CastNode` as a subclass of `Node` as those nodes
559556
where types should be checked. Usually this will be things like explicit casts.

go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ predicate localMustFlowStep(Node node1, Node node2) { none() }
215215
/** Gets the type of `n` used for type pruning. */
216216
DataFlowType getNodeType(Node n) { result = TTodoDataFlowType() and exists(n) }
217217

218-
/** Gets a string representation of a type returned by `getNodeType()`. */
219-
string ppReprType(DataFlowType t) { none() }
220-
221218
/**
222219
* Holds if `t1` and `t2` are compatible, that is, whether data can flow from
223220
* a node of type `t1` to a node of type `t2`.

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowPrivate.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,12 @@ RefType getErasedRepr(Type t) {
356356
t instanceof NullType and result instanceof TypeObject
357357
}
358358

359-
class DataFlowType extends SrcRefType {
359+
final private class SrcRefTypeFinal = SrcRefType;
360+
361+
class DataFlowType extends SrcRefTypeFinal {
360362
DataFlowType() { this = getErasedRepr(_) }
363+
364+
string toString() { result = ppReprType(this) }
361365
}
362366

363367
pragma[nomagic]
@@ -371,7 +375,7 @@ DataFlowType getNodeType(Node n) {
371375
}
372376

373377
/** Gets a string representation of a type returned by `getErasedRepr`. */
374-
string ppReprType(DataFlowType t) {
378+
private string ppReprType(SrcRefType t) {
375379
if t.(BoxedType).getPrimitiveType().getName() = "double"
376380
then result = "Number"
377381
else result = t.toString()

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ newtype TDataFlowType = TAnyFlow()
534534

535535
class DataFlowType extends TDataFlowType {
536536
/** Gets a textual representation of this element. */
537-
string toString() { result = "DataFlowType" }
537+
string toString() { result = "" }
538538
}
539539

540540
/** A node that performs a type cast. */
@@ -578,9 +578,6 @@ DataFlowType getNodeType(Node node) {
578578
exists(node)
579579
}
580580

581-
/** Gets a string representation of a type returned by `getErasedRepr`. */
582-
string ppReprType(DataFlowType t) { none() }
583-
584581
//--------
585582
// Extra flow
586583
//--------

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,9 +2077,6 @@ DataFlowType getNodeType(Node n) {
20772077
result = TUnknownDataFlowType()
20782078
}
20792079

2080-
/** Gets a string representation of a `DataFlowType`. */
2081-
string ppReprType(DataFlowType t) { none() }
2082-
20832080
pragma[inline]
20842081
private predicate compatibleTypesNonSymRefl(DataFlowType t1, DataFlowType t2) {
20852082
t1 != TUnknownDataFlowType() and

shared/dataflow/codeql/dataflow/DataFlow.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ signature module InputSig<LocationSig Location> {
124124
string toString();
125125
}
126126

127-
string ppReprType(DataFlowType t);
128-
129127
/**
130128
* Holds if `t1` and `t2` are compatible types.
131129
*

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,9 +3445,11 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
34453445

34463446
AccessPathApproxConsNil() { this = TConsNil(c, t) }
34473447

3448+
private string ppTyp() { result = t.toString() and result != "" }
3449+
34483450
override string toString() {
3449-
// The `concat` becomes "" if `ppReprType` has no result.
3450-
result = "[" + c.toString() + "]" + concat(" : " + ppReprType(t))
3451+
// The `concat` becomes "" if `ppTyp` has no result.
3452+
result = "[" + c.toString() + "]" + concat(" : " + this.ppTyp())
34513453
}
34523454

34533455
override Content getHead() { result = c }
@@ -3668,7 +3670,9 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
36683670

36693671
ParamNodeEx getParamNode() { result = p }
36703672

3671-
override string toString() { result = p + concat(" : " + ppReprType(t)) + " " + ap }
3673+
private string ppTyp() { result = t.toString() and result != "" }
3674+
3675+
override string toString() { result = p + concat(" : " + this.ppTyp()) + " " + ap }
36723676

36733677
Location getLocation() { result = p.getLocation() }
36743678
}
@@ -3935,10 +3939,12 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
39353939

39363940
override int length() { result = 1 + tail_.length() }
39373941

3942+
private string ppTyp() { result = t.toString() and result != "" }
3943+
39383944
private string toStringImpl(boolean needsSuffix) {
39393945
tail_ = TAccessPathNil() and
39403946
needsSuffix = false and
3941-
result = head_.toString() + "]" + concat(" : " + ppReprType(t))
3947+
result = head_.toString() + "]" + concat(" : " + this.ppTyp())
39423948
or
39433949
result = head_ + ", " + tail_.(AccessPathCons).toStringImpl(needsSuffix)
39443950
or
@@ -4087,9 +4093,8 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
40874093
private string ppType() {
40884094
this instanceof PathNodeSink and result = ""
40894095
or
4090-
exists(DataFlowType t | t = this.(PathNodeMid).getType() |
4091-
// The `concat` becomes "" if `ppReprType` has no result.
4092-
result = concat(" : " + ppReprType(t))
4096+
exists(string t | t = this.(PathNodeMid).getType().toString() |
4097+
if t = "" then result = "" else result = " : " + t
40934098
)
40944099
}
40954100

@@ -5402,9 +5407,8 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
54025407
private string ppType() {
54035408
this instanceof PartialPathNodeRev and result = ""
54045409
or
5405-
exists(DataFlowType t | t = this.(PartialPathNodeFwd).getType() |
5406-
// The `concat` becomes "" if `ppReprType` has no result.
5407-
result = concat(" : " + ppReprType(t))
5410+
exists(string t | t = this.(PartialPathNodeFwd).getType().toString() |
5411+
if t = "" then result = "" else result = " : " + t
54085412
)
54095413
}
54105414

0 commit comments

Comments
 (0)