Skip to content

Commit 1ac9d2e

Browse files
committed
CFG: Compute splitsToString using concat, and exclude partial split sets
1 parent 3343b78 commit 1ac9d2e

File tree

1 file changed

+27
-16
lines changed
  • shared/controlflow/codeql/controlflow

1 file changed

+27
-16
lines changed

shared/controlflow/codeql/controlflow/Cfg.qll

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,20 @@ module Make<LocationSig Location, InputSig<Location> Input> {
399399
}
400400
}
401401

402+
private predicate isFullyConstructedSplits(Splits splits) { exists(TAstNode(_, _, splits)) }
403+
402404
/**
403405
* A set of control flow node splits. The set is represented by a list of splits,
404406
* ordered by ascending rank.
405407
*/
406408
class Splits extends TSplits {
407409
/** Gets a textual representation of this set of splits. */
408-
string toString() { result = splitsToString(this) }
410+
string toString() {
411+
result = splitsToString(this)
412+
or
413+
not isFullyConstructedSplits(this) and
414+
result = "<partial split set>"
415+
}
409416

410417
/** Gets a split belonging to this set of splits. */
411418
SplitImpl getASplit() {
@@ -857,23 +864,27 @@ module Make<LocationSig Location, InputSig<Location> Input> {
857864
succEntrySplitsCons(_, _, head, tail, _)
858865
}
859866

867+
private string getSplitStringAt(Splits split, int index) {
868+
exists(SplitImpl head, Splits tail | split = TSplitsCons(head, tail) |
869+
index = 0 and result = head.toString() and result != ""
870+
or
871+
index > 0 and result = getSplitStringAt(tail, index - 1)
872+
)
873+
}
874+
875+
private string getSplitsStringPart(Splits splits, int index) {
876+
isFullyConstructedSplits(splits) and
877+
result = getSplitStringAt(splits, index)
878+
}
879+
860880
cached
861881
string splitsToString(Splits splits) {
862-
splits = TSplitsNil() and
863-
result = ""
864-
or
865-
exists(SplitImpl head, Splits tail, string headString, string tailString |
866-
splits = TSplitsCons(head, tail)
867-
|
868-
headString = head.toString() and
869-
tailString = tail.toString() and
870-
if tailString = ""
871-
then result = headString
872-
else
873-
if headString = ""
874-
then result = tailString
875-
else result = headString + ", " + tailString
876-
)
882+
result =
883+
concat(string child, int index |
884+
child = getSplitsStringPart(splits, index)
885+
|
886+
child, ", " order by index
887+
)
877888
}
878889

879890
/**

0 commit comments

Comments
 (0)