Dataflow: Replace ppReprType with DataFlowType.toString. · github/codeql@7a48fe1 · GitHub
Skip to content

Commit 7a48fe1

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

11 files changed

Lines changed: 36 additions & 46 deletions

File tree

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

Lines changed: 7 additions & 6 deletions

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

0 commit comments

Comments
 (0)