mirror of
https://github.com/github/codeql.git
synced 2026-04-20 14:34:04 +02:00
Merge pull request #17887 from hvitved/dataflow/provenance-order
Data flow: Order provenance output by textual representation
This commit is contained in:
@@ -17,7 +17,7 @@ signature class PathNodeSig {
|
||||
private signature predicate provenanceSig(string model);
|
||||
|
||||
private module TranslateModels<
|
||||
interpretModelForTestSig/2 interpretModelForTest, provenanceSig/1 provenance>
|
||||
interpretModelForTestSig/2 interpretModelForTest0, provenanceSig/1 provenance>
|
||||
{
|
||||
private predicate madIds(string madId) {
|
||||
exists(string model |
|
||||
@@ -26,15 +26,42 @@ private module TranslateModels<
|
||||
)
|
||||
}
|
||||
|
||||
private predicate rankedMadIds(string madId, int r) {
|
||||
madId = rank[r](string madId0 | madIds(madId0) | madId0 order by madId0.toInt())
|
||||
// Be robust against MaD IDs with multiple textual representations; simply
|
||||
// concatenate them all
|
||||
private predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
|
||||
model = strictconcat(string mod | interpretModelForTest0(madId, mod) | mod, ", ")
|
||||
}
|
||||
|
||||
private QlBuiltins::ExtensionId getModelId(string model) {
|
||||
madIds(result.toString()) and
|
||||
interpretModelForTest(result, model)
|
||||
}
|
||||
|
||||
// collapse models with the same textual representation, in order to not rely
|
||||
// on the order of `ExtensionId`s
|
||||
private module ExtensionIdSets =
|
||||
QlBuiltins::InternSets<string, QlBuiltins::ExtensionId, getModelId/1>;
|
||||
|
||||
private predicate rankedMadIds(ExtensionIdSets::Set extIdSet, int r) {
|
||||
extIdSet =
|
||||
rank[r](ExtensionIdSets::Set extIdSet0, string model |
|
||||
extIdSet0 = ExtensionIdSets::getSet(model)
|
||||
|
|
||||
extIdSet0 order by model
|
||||
)
|
||||
}
|
||||
|
||||
private predicate translateModel(string id, int r) {
|
||||
exists(QlBuiltins::ExtensionId madId, ExtensionIdSets::Set extIdSet |
|
||||
id = madId.toString() and
|
||||
extIdSet.contains(madId) and
|
||||
rankedMadIds(extIdSet, r)
|
||||
)
|
||||
}
|
||||
|
||||
/** Lists the renumbered and pretty-printed models used in the edges relation. */
|
||||
predicate models(int r, string model) {
|
||||
exists(QlBuiltins::ExtensionId madId |
|
||||
rankedMadIds(madId.toString(), r) and interpretModelForTest(madId, model)
|
||||
)
|
||||
exists(string madId | translateModel(madId, r) and getModelId(model).toString() = madId)
|
||||
}
|
||||
|
||||
private predicate translateModelsPart(string model1, string model2, int i) {
|
||||
@@ -46,7 +73,7 @@ private module TranslateModels<
|
||||
translateModelsPart(model1, part, i - 1) and
|
||||
madId = s.regexpCapture("([0-9]*)(.*)", 1) and
|
||||
rest = s.regexpCapture("([0-9]*)(.*)", 2) and
|
||||
rankedMadIds(madId, r) and
|
||||
translateModel(madId, r) and
|
||||
model2 = part + "MaD:" + r + rest
|
||||
)
|
||||
)
|
||||
@@ -102,17 +129,6 @@ module TestPostProcessing {
|
||||
|
||||
private module Models = TranslateModels<interpretModelForTest/2, provenance/1>;
|
||||
|
||||
private newtype TModelRow = TMkModelRow(int r, string model) { Models::models(r, model) }
|
||||
|
||||
private predicate rankedModels(int i, int r, string model) {
|
||||
TMkModelRow(r, model) =
|
||||
rank[i](TModelRow row, int r0, string model0 |
|
||||
row = TMkModelRow(r0, model0)
|
||||
|
|
||||
row order by r0, model0
|
||||
)
|
||||
}
|
||||
|
||||
query predicate results(string relation, int row, int column, string data) {
|
||||
queryResults(relation, row, column, data) and
|
||||
(relation != "edges" or column != provenanceColumn())
|
||||
@@ -124,11 +140,11 @@ module TestPostProcessing {
|
||||
Models::translateModels(model, data)
|
||||
)
|
||||
or
|
||||
exists(int r, string model |
|
||||
exists(string model |
|
||||
relation = "models" and
|
||||
rankedModels(row, r, model)
|
||||
Models::models(row, model)
|
||||
|
|
||||
column = 0 and data = r.toString()
|
||||
column = 0 and data = row.toString()
|
||||
or
|
||||
column = 1 and data = model
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user