Skip to content

Commit b1be123

Browse files
committed
C#/C++/Java: Prettier AccessPath.toString
The `ppReprType` predicate should now be `none()` instead of `result=""` to signal that there is nothing to print. That seems clearer to me.
1 parent dbe8034 commit b1be123

File tree

24 files changed

+509
-415
lines changed

24 files changed

+509
-415
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,15 @@ private class AccessPath extends TAccessPath {
12531253
abstract AccessPathFront getFront();
12541254

12551255
/**
1256-
* Holds if `this` has `head` at the front and may be followed by `tail`.
1256+
* Holds if this access path has `head` at the front and may be followed by `tail`.
12571257
*/
12581258
abstract predicate pop(Content head, AccessPath tail);
12591259
}
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
1262-
override string toString() { exists(DataFlowType t | this = TNil(t) | result = ppReprType(t)) }
1262+
override string toString() {
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1264+
}
12631265

12641266
override AccessPathFront getFront() {
12651267
exists(DataFlowType t | this = TNil(t) | result = TFrontNil(t))
@@ -1273,7 +1275,8 @@ abstract private class AccessPathCons extends AccessPath { }
12731275
private class AccessPathConsNil extends AccessPathCons, TConsNil {
12741276
override string toString() {
12751277
exists(Content f, DataFlowType t | this = TConsNil(f, t) |
1276-
result = f.toString() + " : " + ppReprType(t)
1278+
// The `concat` becomes "" if `ppReprType` has no result.
1279+
result = f.toString() + concat(" : " + ppReprType(t))
12771280
)
12781281
}
12791282

@@ -1289,7 +1292,9 @@ private class AccessPathConsNil extends AccessPathCons, TConsNil {
12891292
private class AccessPathConsCons extends AccessPathCons, TConsCons {
12901293
override string toString() {
12911294
exists(Content f1, Content f2, int len | this = TConsCons(f1, f2, len) |
1292-
result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
1295+
if len = 2
1296+
then result = f1.toString() + ", " + f2.toString()
1297+
else result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
12931298
)
12941299
}
12951300

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl2.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,15 @@ private class AccessPath extends TAccessPath {
12531253
abstract AccessPathFront getFront();
12541254

12551255
/**
1256-
* Holds if `this` has `head` at the front and may be followed by `tail`.
1256+
* Holds if this access path has `head` at the front and may be followed by `tail`.
12571257
*/
12581258
abstract predicate pop(Content head, AccessPath tail);
12591259
}
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
1262-
override string toString() { exists(DataFlowType t | this = TNil(t) | result = ppReprType(t)) }
1262+
override string toString() {
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1264+
}
12631265

12641266
override AccessPathFront getFront() {
12651267
exists(DataFlowType t | this = TNil(t) | result = TFrontNil(t))
@@ -1273,7 +1275,8 @@ abstract private class AccessPathCons extends AccessPath { }
12731275
private class AccessPathConsNil extends AccessPathCons, TConsNil {
12741276
override string toString() {
12751277
exists(Content f, DataFlowType t | this = TConsNil(f, t) |
1276-
result = f.toString() + " : " + ppReprType(t)
1278+
// The `concat` becomes "" if `ppReprType` has no result.
1279+
result = f.toString() + concat(" : " + ppReprType(t))
12771280
)
12781281
}
12791282

@@ -1289,7 +1292,9 @@ private class AccessPathConsNil extends AccessPathCons, TConsNil {
12891292
private class AccessPathConsCons extends AccessPathCons, TConsCons {
12901293
override string toString() {
12911294
exists(Content f1, Content f2, int len | this = TConsCons(f1, f2, len) |
1292-
result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
1295+
if len = 2
1296+
then result = f1.toString() + ", " + f2.toString()
1297+
else result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
12931298
)
12941299
}
12951300

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl3.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,15 @@ private class AccessPath extends TAccessPath {
12531253
abstract AccessPathFront getFront();
12541254

12551255
/**
1256-
* Holds if `this` has `head` at the front and may be followed by `tail`.
1256+
* Holds if this access path has `head` at the front and may be followed by `tail`.
12571257
*/
12581258
abstract predicate pop(Content head, AccessPath tail);
12591259
}
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
1262-
override string toString() { exists(DataFlowType t | this = TNil(t) | result = ppReprType(t)) }
1262+
override string toString() {
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1264+
}
12631265

12641266
override AccessPathFront getFront() {
12651267
exists(DataFlowType t | this = TNil(t) | result = TFrontNil(t))
@@ -1273,7 +1275,8 @@ abstract private class AccessPathCons extends AccessPath { }
12731275
private class AccessPathConsNil extends AccessPathCons, TConsNil {
12741276
override string toString() {
12751277
exists(Content f, DataFlowType t | this = TConsNil(f, t) |
1276-
result = f.toString() + " : " + ppReprType(t)
1278+
// The `concat` becomes "" if `ppReprType` has no result.
1279+
result = f.toString() + concat(" : " + ppReprType(t))
12771280
)
12781281
}
12791282

@@ -1289,7 +1292,9 @@ private class AccessPathConsNil extends AccessPathCons, TConsNil {
12891292
private class AccessPathConsCons extends AccessPathCons, TConsCons {
12901293
override string toString() {
12911294
exists(Content f1, Content f2, int len | this = TConsCons(f1, f2, len) |
1292-
result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
1295+
if len = 2
1296+
then result = f1.toString() + ", " + f2.toString()
1297+
else result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
12931298
)
12941299
}
12951300

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl4.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,15 @@ private class AccessPath extends TAccessPath {
12531253
abstract AccessPathFront getFront();
12541254

12551255
/**
1256-
* Holds if `this` has `head` at the front and may be followed by `tail`.
1256+
* Holds if this access path has `head` at the front and may be followed by `tail`.
12571257
*/
12581258
abstract predicate pop(Content head, AccessPath tail);
12591259
}
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
1262-
override string toString() { exists(DataFlowType t | this = TNil(t) | result = ppReprType(t)) }
1262+
override string toString() {
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1264+
}
12631265

12641266
override AccessPathFront getFront() {
12651267
exists(DataFlowType t | this = TNil(t) | result = TFrontNil(t))
@@ -1273,7 +1275,8 @@ abstract private class AccessPathCons extends AccessPath { }
12731275
private class AccessPathConsNil extends AccessPathCons, TConsNil {
12741276
override string toString() {
12751277
exists(Content f, DataFlowType t | this = TConsNil(f, t) |
1276-
result = f.toString() + " : " + ppReprType(t)
1278+
// The `concat` becomes "" if `ppReprType` has no result.
1279+
result = f.toString() + concat(" : " + ppReprType(t))
12771280
)
12781281
}
12791282

@@ -1289,7 +1292,9 @@ private class AccessPathConsNil extends AccessPathCons, TConsNil {
12891292
private class AccessPathConsCons extends AccessPathCons, TConsCons {
12901293
override string toString() {
12911294
exists(Content f1, Content f2, int len | this = TConsCons(f1, f2, len) |
1292-
result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
1295+
if len = 2
1296+
then result = f1.toString() + ", " + f2.toString()
1297+
else result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
12931298
)
12941299
}
12951300

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImplLocal.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,15 @@ private class AccessPath extends TAccessPath {
12531253
abstract AccessPathFront getFront();
12541254

12551255
/**
1256-
* Holds if `this` has `head` at the front and may be followed by `tail`.
1256+
* Holds if this access path has `head` at the front and may be followed by `tail`.
12571257
*/
12581258
abstract predicate pop(Content head, AccessPath tail);
12591259
}
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
1262-
override string toString() { exists(DataFlowType t | this = TNil(t) | result = ppReprType(t)) }
1262+
override string toString() {
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1264+
}
12631265

12641266
override AccessPathFront getFront() {
12651267
exists(DataFlowType t | this = TNil(t) | result = TFrontNil(t))
@@ -1273,7 +1275,8 @@ abstract private class AccessPathCons extends AccessPath { }
12731275
private class AccessPathConsNil extends AccessPathCons, TConsNil {
12741276
override string toString() {
12751277
exists(Content f, DataFlowType t | this = TConsNil(f, t) |
1276-
result = f.toString() + " : " + ppReprType(t)
1278+
// The `concat` becomes "" if `ppReprType` has no result.
1279+
result = f.toString() + concat(" : " + ppReprType(t))
12771280
)
12781281
}
12791282

@@ -1289,7 +1292,9 @@ private class AccessPathConsNil extends AccessPathCons, TConsNil {
12891292
private class AccessPathConsCons extends AccessPathCons, TConsCons {
12901293
override string toString() {
12911294
exists(Content f1, Content f2, int len | this = TConsCons(f1, f2, len) |
1292-
result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
1295+
if len = 2
1296+
then result = f1.toString() + ", " + f2.toString()
1297+
else result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
12931298
)
12941299
}
12951300

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Type getErasedRepr(Type t) {
219219
}
220220

221221
/** Gets a string representation of a type returned by `getErasedRepr`. */
222-
string ppReprType(Type t) { result = t.toString() }
222+
string ppReprType(Type t) { none() } // stub implementation
223223

224224
/**
225225
* Holds if `t1` and `t2` are compatible, that is, whether data can flow from

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,15 @@ private class AccessPath extends TAccessPath {
12531253
abstract AccessPathFront getFront();
12541254

12551255
/**
1256-
* Holds if `this` has `head` at the front and may be followed by `tail`.
1256+
* Holds if this access path has `head` at the front and may be followed by `tail`.
12571257
*/
12581258
abstract predicate pop(Content head, AccessPath tail);
12591259
}
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
1262-
override string toString() { exists(DataFlowType t | this = TNil(t) | result = ppReprType(t)) }
1262+
override string toString() {
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1264+
}
12631265

12641266
override AccessPathFront getFront() {
12651267
exists(DataFlowType t | this = TNil(t) | result = TFrontNil(t))
@@ -1273,7 +1275,8 @@ abstract private class AccessPathCons extends AccessPath { }
12731275
private class AccessPathConsNil extends AccessPathCons, TConsNil {
12741276
override string toString() {
12751277
exists(Content f, DataFlowType t | this = TConsNil(f, t) |
1276-
result = f.toString() + " : " + ppReprType(t)
1278+
// The `concat` becomes "" if `ppReprType` has no result.
1279+
result = f.toString() + concat(" : " + ppReprType(t))
12771280
)
12781281
}
12791282

@@ -1289,7 +1292,9 @@ private class AccessPathConsNil extends AccessPathCons, TConsNil {
12891292
private class AccessPathConsCons extends AccessPathCons, TConsCons {
12901293
override string toString() {
12911294
exists(Content f1, Content f2, int len | this = TConsCons(f1, f2, len) |
1292-
result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
1295+
if len = 2
1296+
then result = f1.toString() + ", " + f2.toString()
1297+
else result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
12931298
)
12941299
}
12951300

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl2.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,15 @@ private class AccessPath extends TAccessPath {
12531253
abstract AccessPathFront getFront();
12541254

12551255
/**
1256-
* Holds if `this` has `head` at the front and may be followed by `tail`.
1256+
* Holds if this access path has `head` at the front and may be followed by `tail`.
12571257
*/
12581258
abstract predicate pop(Content head, AccessPath tail);
12591259
}
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
1262-
override string toString() { exists(DataFlowType t | this = TNil(t) | result = ppReprType(t)) }
1262+
override string toString() {
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1264+
}
12631265

12641266
override AccessPathFront getFront() {
12651267
exists(DataFlowType t | this = TNil(t) | result = TFrontNil(t))
@@ -1273,7 +1275,8 @@ abstract private class AccessPathCons extends AccessPath { }
12731275
private class AccessPathConsNil extends AccessPathCons, TConsNil {
12741276
override string toString() {
12751277
exists(Content f, DataFlowType t | this = TConsNil(f, t) |
1276-
result = f.toString() + " : " + ppReprType(t)
1278+
// The `concat` becomes "" if `ppReprType` has no result.
1279+
result = f.toString() + concat(" : " + ppReprType(t))
12771280
)
12781281
}
12791282

@@ -1289,7 +1292,9 @@ private class AccessPathConsNil extends AccessPathCons, TConsNil {
12891292
private class AccessPathConsCons extends AccessPathCons, TConsCons {
12901293
override string toString() {
12911294
exists(Content f1, Content f2, int len | this = TConsCons(f1, f2, len) |
1292-
result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
1295+
if len = 2
1296+
then result = f1.toString() + ", " + f2.toString()
1297+
else result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
12931298
)
12941299
}
12951300

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl3.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,15 @@ private class AccessPath extends TAccessPath {
12531253
abstract AccessPathFront getFront();
12541254

12551255
/**
1256-
* Holds if `this` has `head` at the front and may be followed by `tail`.
1256+
* Holds if this access path has `head` at the front and may be followed by `tail`.
12571257
*/
12581258
abstract predicate pop(Content head, AccessPath tail);
12591259
}
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
1262-
override string toString() { exists(DataFlowType t | this = TNil(t) | result = ppReprType(t)) }
1262+
override string toString() {
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1264+
}
12631265

12641266
override AccessPathFront getFront() {
12651267
exists(DataFlowType t | this = TNil(t) | result = TFrontNil(t))
@@ -1273,7 +1275,8 @@ abstract private class AccessPathCons extends AccessPath { }
12731275
private class AccessPathConsNil extends AccessPathCons, TConsNil {
12741276
override string toString() {
12751277
exists(Content f, DataFlowType t | this = TConsNil(f, t) |
1276-
result = f.toString() + " : " + ppReprType(t)
1278+
// The `concat` becomes "" if `ppReprType` has no result.
1279+
result = f.toString() + concat(" : " + ppReprType(t))
12771280
)
12781281
}
12791282

@@ -1289,7 +1292,9 @@ private class AccessPathConsNil extends AccessPathCons, TConsNil {
12891292
private class AccessPathConsCons extends AccessPathCons, TConsCons {
12901293
override string toString() {
12911294
exists(Content f1, Content f2, int len | this = TConsCons(f1, f2, len) |
1292-
result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
1295+
if len = 2
1296+
then result = f1.toString() + ", " + f2.toString()
1297+
else result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
12931298
)
12941299
}
12951300

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl4.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,15 @@ private class AccessPath extends TAccessPath {
12531253
abstract AccessPathFront getFront();
12541254

12551255
/**
1256-
* Holds if `this` has `head` at the front and may be followed by `tail`.
1256+
* Holds if this access path has `head` at the front and may be followed by `tail`.
12571257
*/
12581258
abstract predicate pop(Content head, AccessPath tail);
12591259
}
12601260

12611261
private class AccessPathNil extends AccessPath, TNil {
1262-
override string toString() { exists(DataFlowType t | this = TNil(t) | result = ppReprType(t)) }
1262+
override string toString() {
1263+
exists(DataFlowType t | this = TNil(t) | result = concat(ppReprType(t)))
1264+
}
12631265

12641266
override AccessPathFront getFront() {
12651267
exists(DataFlowType t | this = TNil(t) | result = TFrontNil(t))
@@ -1273,7 +1275,8 @@ abstract private class AccessPathCons extends AccessPath { }
12731275
private class AccessPathConsNil extends AccessPathCons, TConsNil {
12741276
override string toString() {
12751277
exists(Content f, DataFlowType t | this = TConsNil(f, t) |
1276-
result = f.toString() + " : " + ppReprType(t)
1278+
// The `concat` becomes "" if `ppReprType` has no result.
1279+
result = f.toString() + concat(" : " + ppReprType(t))
12771280
)
12781281
}
12791282

@@ -1289,7 +1292,9 @@ private class AccessPathConsNil extends AccessPathCons, TConsNil {
12891292
private class AccessPathConsCons extends AccessPathCons, TConsCons {
12901293
override string toString() {
12911294
exists(Content f1, Content f2, int len | this = TConsCons(f1, f2, len) |
1292-
result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
1295+
if len = 2
1296+
then result = f1.toString() + ", " + f2.toString()
1297+
else result = f1.toString() + ", " + f2.toString() + ", ... (" + len.toString() + ")"
12931298
)
12941299
}
12951300

0 commit comments

Comments
 (0)