Skip to content

Commit aa7e6d7

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: add negative numbers
1 parent b82f9b1 commit aa7e6d7

File tree

7 files changed

+179
-38
lines changed

7 files changed

+179
-38
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,28 @@ module Public {
261261
NegativeSummarizedCallable() { negativeSummaryElement(this, _) }
262262

263263
/**
264-
* Holds if the negative summary is auto generated.
264+
* Holds if the negative summary is auto generated and not manually generated.
265265
*/
266-
predicate isAutoGenerated() { negativeSummaryElement(this, true) }
266+
predicate isAutoGenerated() {
267+
negativeSummaryElement(this, true) and
268+
not negativeSummaryElement(this, false)
269+
} // ! okay to adjust this to "and not manually generated"? Will that mess up anything that currently uses this?
270+
271+
/**
272+
* Holds if the summary is manually generated and not auto generated.
273+
*/
274+
predicate isManuallyGenerated() {
275+
negativeSummaryElement(this, false) and
276+
not negativeSummaryElement(this, true)
277+
}
278+
279+
/**
280+
* Holds if the summary is both auto generated and manually generated.
281+
*/
282+
predicate isBothAutoAndManuallyGenerated() {
283+
negativeSummaryElement(this, true) and
284+
negativeSummaryElement(this, false)
285+
}
267286
}
268287
}
269288

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,28 @@ module Public {
261261
NegativeSummarizedCallable() { negativeSummaryElement(this, _) }
262262

263263
/**
264-
* Holds if the negative summary is auto generated.
264+
* Holds if the negative summary is auto generated and not manually generated.
265265
*/
266-
predicate isAutoGenerated() { negativeSummaryElement(this, true) }
266+
predicate isAutoGenerated() {
267+
negativeSummaryElement(this, true) and
268+
not negativeSummaryElement(this, false)
269+
} // ! okay to adjust this to "and not manually generated"? Will that mess up anything that currently uses this?
270+
271+
/**
272+
* Holds if the summary is manually generated and not auto generated.
273+
*/
274+
predicate isManuallyGenerated() {
275+
negativeSummaryElement(this, false) and
276+
not negativeSummaryElement(this, true)
277+
}
278+
279+
/**
280+
* Holds if the summary is both auto generated and manually generated.
281+
*/
282+
predicate isBothAutoAndManuallyGenerated() {
283+
negativeSummaryElement(this, true) and
284+
negativeSummaryElement(this, false)
285+
}
267286
}
268287
}
269288

java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,28 @@ module Public {
261261
NegativeSummarizedCallable() { negativeSummaryElement(this, _) }
262262

263263
/**
264-
* Holds if the negative summary is auto generated.
264+
* Holds if the negative summary is auto generated and not manually generated.
265265
*/
266-
predicate isAutoGenerated() { negativeSummaryElement(this, true) }
266+
predicate isAutoGenerated() {
267+
negativeSummaryElement(this, true) and
268+
not negativeSummaryElement(this, false)
269+
} // ! okay to adjust this to "and not manually generated"? Will that mess up anything that currently uses this?
270+
271+
/**
272+
* Holds if the summary is manually generated and not auto generated.
273+
*/
274+
predicate isManuallyGenerated() {
275+
negativeSummaryElement(this, false) and
276+
not negativeSummaryElement(this, true)
277+
}
278+
279+
/**
280+
* Holds if the summary is both auto generated and manually generated.
281+
*/
282+
predicate isBothAutoAndManuallyGenerated() {
283+
negativeSummaryElement(this, true) and
284+
negativeSummaryElement(this, false)
285+
}
267286
}
268287
}
269288

java/ql/src/Metrics/Summaries/GeneratedVsManualCoverage.ql

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//import java // not needed I guess
1010
import semmle.code.java.dataflow.FlowSummary // for SummarizedCallable
1111
import utils.modelgenerator.internal.CaptureModels // for DataFlowTargetApi
12+
import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl // for NegativeSummarizedCallable
1213

1314
// ! improve QLDoc?
1415
/**
@@ -19,7 +20,10 @@ import utils.modelgenerator.internal.CaptureModels // for DataFlowTargetApi
1920
class MadModeledCallable extends SummarizedCallableBase {
2021
// ! better name for this class?
2122
MadModeledCallable() {
22-
this instanceof SummarizedCallable and
23+
(
24+
this instanceof SummarizedCallable or
25+
this instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable
26+
) and
2327
exists(DataFlowTargetApi dataFlowTargApi |
2428
this.asCallable() = dataFlowTargApi and
2529
not exists(FunctionalExpr funcExpr | dataFlowTargApi = funcExpr.asMethod()) // ! remove this if DataFlowTargetApi itself is adjusted to exclude FunctionalExpr (see static-team slack thread)
@@ -28,29 +32,48 @@ class MadModeledCallable extends SummarizedCallableBase {
2832
}
2933

3034
// ! move to other file
35+
// ! separate this into pos and neg predicates instead of using `posOrNeg` flag?
3136
/**
3237
* Returns the number of APIs with MaD models
3338
* for a given package and provenance.
3439
*/
35-
float getNumMadModels(string package, string provenance) {
40+
float getNumMadModels(string package, string provenance, string posOrNeg) {
3641
exists(MadModeledCallable mc |
3742
package = mc.asCallable().getDeclaringType().getPackage().toString() and
38-
provenance in ["generated", "manual", "both"]
43+
provenance in ["generated", "manual", "both"] and
44+
posOrNeg in ["positive", "negative"]
3945
|
40-
result =
41-
count(MadModeledCallable c |
42-
package = c.asCallable().getDeclaringType().getPackage().toString() and
43-
(
44-
c.(SummarizedCallable).isAutoGenerated() and // generated and NOT manual = "auto-only"
45-
provenance = "generated"
46-
or
47-
c.(SummarizedCallable).isManuallyGenerated() and // manual and NOT generated = "manual-only"
48-
provenance = "manual"
49-
or
50-
c.(SummarizedCallable).isBothAutoAndManuallyGenerated() and // BOTH generated and manual = "both"
51-
provenance = "both"
46+
if posOrNeg = "positive"
47+
then
48+
result =
49+
count(MadModeledCallable c |
50+
package = c.asCallable().getDeclaringType().getPackage().toString() and
51+
(
52+
c.(SummarizedCallable).isAutoGenerated() and // generated and NOT manual = "auto-only"
53+
provenance = "generated"
54+
or
55+
c.(SummarizedCallable).isManuallyGenerated() and // manual and NOT generated = "manual-only"
56+
provenance = "manual"
57+
or
58+
c.(SummarizedCallable).isBothAutoAndManuallyGenerated() and // BOTH generated and manual = "both"
59+
provenance = "both"
60+
)
61+
)
62+
else
63+
result =
64+
count(MadModeledCallable c |
65+
package = c.asCallable().getDeclaringType().getPackage().toString() and
66+
(
67+
c.(FlowSummaryImpl::Public::NegativeSummarizedCallable).isAutoGenerated() and // generated and NOT manual = "auto-only"
68+
provenance = "generated"
69+
or
70+
c.(FlowSummaryImpl::Public::NegativeSummarizedCallable).isManuallyGenerated() and // manual and NOT generated = "manual-only"
71+
provenance = "manual"
72+
or
73+
c.(FlowSummaryImpl::Public::NegativeSummarizedCallable).isBothAutoAndManuallyGenerated() and // BOTH generated and manual = "both"
74+
provenance = "both"
75+
)
5276
)
53-
)
5477
)
5578
}
5679

@@ -87,14 +110,18 @@ float getNumApisWithoutMadModel(string package) {
87110
*/
88111

89112
from
90-
string package, float generated, float manual, float both, float notModeled, float all,
91-
float metric1, float metric2
113+
string package, float generatedPos, float manualPos, float bothPos, float generatedNeg,
114+
float manualNeg, float bothNeg, float notModeled, float all, float metric1, float metric2
92115
where
93-
generated = getNumMadModels(package, "generated") and
94-
manual = getNumMadModels(package, "manual") and
95-
both = getNumMadModels(package, "both") and
96-
notModeled = getNumApisWithoutMadModel(package) and // ! better name for this?, "none" is a reserved keyword :(
97-
all = generated + manual + both + notModeled and
98-
metric1 = (both / (both + manual)) and
99-
metric2 = (generated + both + manual) / all
100-
select package, generated, manual, both, notModeled, all, metric1, metric2 order by package
116+
generatedPos = getNumMadModels(package, "generated", "positive") and
117+
manualPos = getNumMadModels(package, "manual", "positive") and
118+
bothPos = getNumMadModels(package, "both", "positive") and
119+
generatedNeg = getNumMadModels(package, "generated", "negative") and
120+
manualNeg = getNumMadModels(package, "manual", "negative") and
121+
bothNeg = getNumMadModels(package, "both", "negative") and
122+
notModeled = getNumApisWithoutMadModel(package) and
123+
all = generatedPos + manualPos + bothPos + generatedNeg + manualNeg + bothNeg + notModeled and
124+
metric1 = (bothPos / (bothPos + manualPos)) and // ! I believe this metric was intended to be only on the positive ones?
125+
metric2 = (generatedPos + generatedNeg + bothPos + bothNeg + manualPos + manualNeg) / all
126+
select package, generatedPos, manualPos, bothPos, generatedNeg, manualNeg, bothNeg, notModeled, all,
127+
metric1, metric2 order by package

python/ql/lib/semmle/python/dataflow/new/internal/FlowSummaryImpl.qll

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,28 @@ module Public {
261261
NegativeSummarizedCallable() { negativeSummaryElement(this, _) }
262262

263263
/**
264-
* Holds if the negative summary is auto generated.
264+
* Holds if the negative summary is auto generated and not manually generated.
265265
*/
266-
predicate isAutoGenerated() { negativeSummaryElement(this, true) }
266+
predicate isAutoGenerated() {
267+
negativeSummaryElement(this, true) and
268+
not negativeSummaryElement(this, false)
269+
} // ! okay to adjust this to "and not manually generated"? Will that mess up anything that currently uses this?
270+
271+
/**
272+
* Holds if the summary is manually generated and not auto generated.
273+
*/
274+
predicate isManuallyGenerated() {
275+
negativeSummaryElement(this, false) and
276+
not negativeSummaryElement(this, true)
277+
}
278+
279+
/**
280+
* Holds if the summary is both auto generated and manually generated.
281+
*/
282+
predicate isBothAutoAndManuallyGenerated() {
283+
negativeSummaryElement(this, true) and
284+
negativeSummaryElement(this, false)
285+
}
267286
}
268287
}
269288

ruby/ql/lib/codeql/ruby/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,28 @@ module Public {
261261
NegativeSummarizedCallable() { negativeSummaryElement(this, _) }
262262

263263
/**
264-
* Holds if the negative summary is auto generated.
264+
* Holds if the negative summary is auto generated and not manually generated.
265265
*/
266-
predicate isAutoGenerated() { negativeSummaryElement(this, true) }
266+
predicate isAutoGenerated() {
267+
negativeSummaryElement(this, true) and
268+
not negativeSummaryElement(this, false)
269+
} // ! okay to adjust this to "and not manually generated"? Will that mess up anything that currently uses this?
270+
271+
/**
272+
* Holds if the summary is manually generated and not auto generated.
273+
*/
274+
predicate isManuallyGenerated() {
275+
negativeSummaryElement(this, false) and
276+
not negativeSummaryElement(this, true)
277+
}
278+
279+
/**
280+
* Holds if the summary is both auto generated and manually generated.
281+
*/
282+
predicate isBothAutoAndManuallyGenerated() {
283+
negativeSummaryElement(this, true) and
284+
negativeSummaryElement(this, false)
285+
}
267286
}
268287
}
269288

swift/ql/lib/codeql/swift/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,28 @@ module Public {
261261
NegativeSummarizedCallable() { negativeSummaryElement(this, _) }
262262

263263
/**
264-
* Holds if the negative summary is auto generated.
264+
* Holds if the negative summary is auto generated and not manually generated.
265265
*/
266-
predicate isAutoGenerated() { negativeSummaryElement(this, true) }
266+
predicate isAutoGenerated() {
267+
negativeSummaryElement(this, true) and
268+
not negativeSummaryElement(this, false)
269+
} // ! okay to adjust this to "and not manually generated"? Will that mess up anything that currently uses this?
270+
271+
/**
272+
* Holds if the summary is manually generated and not auto generated.
273+
*/
274+
predicate isManuallyGenerated() {
275+
negativeSummaryElement(this, false) and
276+
not negativeSummaryElement(this, true)
277+
}
278+
279+
/**
280+
* Holds if the summary is both auto generated and manually generated.
281+
*/
282+
predicate isBothAutoAndManuallyGenerated() {
283+
negativeSummaryElement(this, true) and
284+
negativeSummaryElement(this, false)
285+
}
267286
}
268287
}
269288

0 commit comments

Comments
 (0)