mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Merge pull request #17363 from michaelnebel/modelgen/fieldbasedimprovements
C#/Java: Content based model generation improvements.
This commit is contained in:
@@ -271,6 +271,38 @@ module MakeImplContentDataFlow<LocationSig Location, InputSig<Location> Lang> {
|
||||
result = head + "." + tail
|
||||
)
|
||||
}
|
||||
|
||||
private ContentSet getAtIndex(int i) {
|
||||
i = 0 and
|
||||
result = this.getHead()
|
||||
or
|
||||
i > 0 and
|
||||
result = this.getTail().getAtIndex(i - 1)
|
||||
}
|
||||
|
||||
private AccessPath reverse0(int i) {
|
||||
i = -1 and result = TAccessPathNil()
|
||||
or
|
||||
i >= 0 and
|
||||
result = TAccessPathCons(this.getAtIndex(i), this.reverse0(i - 1))
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the length of this access path.
|
||||
*/
|
||||
private int length() {
|
||||
result = 0 and this = TAccessPathNil()
|
||||
or
|
||||
result = 1 + this.getTail().length()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the reversed access path, if any.
|
||||
*
|
||||
* Note that not all access paths have a reverse as these are not
|
||||
* included by default in the IPA type.
|
||||
*/
|
||||
AccessPath reverse() { result = this.reverse0(this.length() - 1) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,14 +64,23 @@ module ModelPrintingImpl<ModelPrintingLangSig Lang> {
|
||||
|
||||
/**
|
||||
* Gets the summary model for `api` with `input`, `output` and `kind`.
|
||||
* The model is lifted in case `lift` is true.
|
||||
*/
|
||||
bindingset[input, output, kind]
|
||||
private string asSummaryModel(Printing::SummaryApi api, string input, string output, string kind) {
|
||||
result =
|
||||
asPartialModel(api.lift()) + input + ";" //
|
||||
+ output + ";" //
|
||||
+ kind + ";" //
|
||||
+ Printing::getProvenance()
|
||||
private string asSummaryModel(
|
||||
Printing::SummaryApi api, string input, string output, string kind, boolean lift
|
||||
) {
|
||||
exists(Lang::Callable c |
|
||||
lift = true and c = api.lift()
|
||||
or
|
||||
lift = false and c = api
|
||||
|
|
||||
result =
|
||||
asPartialModel(c) + input + ";" //
|
||||
+ output + ";" //
|
||||
+ kind + ";" //
|
||||
+ Printing::getProvenance()
|
||||
)
|
||||
}
|
||||
|
||||
string asNeutralSummaryModel(Printing::SummaryApi api) {
|
||||
@@ -82,31 +91,35 @@ module ModelPrintingImpl<ModelPrintingLangSig Lang> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value summary model for `api` with `input` and `output`.
|
||||
* Gets the lifted value summary model for `api` with `input` and `output`.
|
||||
*/
|
||||
bindingset[input, output]
|
||||
string asValueModel(Printing::SummaryApi api, string input, string output) {
|
||||
result = asSummaryModel(api, input, output, "value")
|
||||
string asLiftedValueModel(Printing::SummaryApi api, string input, string output) {
|
||||
result = asModel(api, input, output, true, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the taint summary model for `api` with `input` and `output`.
|
||||
* Gets the lifted taint summary model for `api` with `input` and `output`.
|
||||
*/
|
||||
bindingset[input, output]
|
||||
string asTaintModel(Printing::SummaryApi api, string input, string output) {
|
||||
result = asSummaryModel(api, input, output, "taint")
|
||||
string asLiftedTaintModel(Printing::SummaryApi api, string input, string output) {
|
||||
result = asModel(api, input, output, false, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the summary model for `api` with `input` and `output`.
|
||||
* (1) If `preservesValue` is true a "value" model is created.
|
||||
* (2) If `lift` is true the model is lifted to the best possible type.
|
||||
*/
|
||||
bindingset[input, output, preservesValue]
|
||||
string asModel(Printing::SummaryApi api, string input, string output, boolean preservesValue) {
|
||||
string asModel(
|
||||
Printing::SummaryApi api, string input, string output, boolean preservesValue, boolean lift
|
||||
) {
|
||||
preservesValue = true and
|
||||
result = asValueModel(api, input, output)
|
||||
result = asSummaryModel(api, input, output, "value", lift)
|
||||
or
|
||||
preservesValue = false and
|
||||
result = asTaintModel(api, input, output)
|
||||
result = asSummaryModel(api, input, output, "taint", lift)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user