Skip to content

Commit f00ad7c

Browse files
committed
C#/Java: Invert api filtering logic.
1 parent 5e2e224 commit f00ad7c

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

csharp/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ private import CaptureModelsSpecific
77
private import CaptureModelsPrinting
88

99
class DataFlowTargetApi extends TargetApiSpecific {
10-
DataFlowTargetApi() { isRelevantForDataFlowModels(this) }
10+
DataFlowTargetApi() { not isUninterestingForDataFlowModels(this) }
1111
}
1212

1313
private module Printing implements PrintingSig {

csharp/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,18 @@ private predicate isRelevantForModels(CS::Callable api) {
5151
}
5252

5353
/**
54-
* Holds if it is relevant to generate models for `api` based on data flow analysis.
54+
* Holds if it is irrelevant to generate models for `api` based on data flow analysis.
55+
*
56+
* This serves as an extra filter for the `relevant` predicate.
5557
*/
56-
predicate isRelevantForDataFlowModels(CS::Callable api) {
57-
isRelevantForModels(api) and not isHigherOrder(api)
58-
}
58+
predicate isUninterestingForDataFlowModels(CS::Callable api) { isHigherOrder(api) }
5959

6060
/**
61-
* Holds if it is relevant to generate models for `api` based on its type.
61+
* Holds if it is irrelevant to generate models for `api` based on type-based analysis.
62+
*
63+
* This serves as an extra filter for the `relevant` predicate.
6264
*/
63-
predicate isRelevantForTypeBasedFlowModels = isRelevantForModels/1;
65+
predicate isUninterestingForTypeBasedFlowModels(CS::Callable api) { none() }
6466

6567
/**
6668
* A class of callables that are relevant generating summary, source and sinks models for.
@@ -71,7 +73,8 @@ predicate isRelevantForTypeBasedFlowModels = isRelevantForModels/1;
7173
class TargetApiSpecific extends CS::Callable {
7274
TargetApiSpecific() {
7375
this.fromSource() and
74-
this.isUnboundDeclaration()
76+
this.isUnboundDeclaration() and
77+
isRelevantForModels(this)
7578
}
7679
}
7780

csharp/ql/src/utils/modelgenerator/internal/CaptureTypeBasedSummaryModels.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private module ModelPrinting = PrintingImpl<Printing>;
190190
* on the Theorems for Free approach.
191191
*/
192192
class TypeBasedFlowTargetApi extends Specific::TargetApiSpecific {
193-
TypeBasedFlowTargetApi() { Specific::isRelevantForTypeBasedFlowModels(this) }
193+
TypeBasedFlowTargetApi() { not Specific::isUninterestingForTypeBasedFlowModels(this) }
194194

195195
/**
196196
* Gets the string representation of all type based summaries for `this`

java/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ private import CaptureModelsSpecific
77
private import CaptureModelsPrinting
88

99
class DataFlowTargetApi extends TargetApiSpecific {
10-
DataFlowTargetApi() { isRelevantForDataFlowModels(this) }
10+
DataFlowTargetApi() { not isUninterestingForDataFlowModels(this) }
1111
}
1212

1313
private module Printing implements PrintingSig {

java/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,20 @@ private predicate hasManualModel(Callable api) {
6363
}
6464

6565
/**
66-
* Holds if it is relevant to generate models for `api` based on data flow analysis.
66+
* Holds if it is irrelevant to generate models for `api` based on data flow analysis.
67+
*
68+
* This serves as an extra filter for the `relevant` predicate.
6769
*/
68-
predicate isRelevantForDataFlowModels(Callable api) {
69-
(not api.getDeclaringType() instanceof J::Interface or exists(api.getBody()))
70+
predicate isUninterestingForDataFlowModels(Callable api) {
71+
api.getDeclaringType() instanceof J::Interface and not exists(api.getBody())
7072
}
7173

72-
predicate isRelevantForTypeBasedFlowModels(Callable api) { any() }
74+
/**
75+
* Holds if it is irrelevant to generate models for `api` based on type-based analysis.
76+
*
77+
* This serves as an extra filter for the `relevant` predicate.
78+
*/
79+
predicate isUninterestingForTypeBasedFlowModels(Callable api) { none() }
7380

7481
/**
7582
* A class of Callables that are relevant for generating summary, source and sinks models for.

java/ql/src/utils/modelgenerator/internal/CaptureTypeBasedSummaryModels.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ private module ModelPrinting = PrintingImpl<Printing>;
296296
* on the Theorems for Free approach.
297297
*/
298298
class TypeBasedFlowTargetApi extends Specific::TargetApiSpecific {
299-
TypeBasedFlowTargetApi() { Specific::isRelevantForTypeBasedFlowModels(this) }
299+
TypeBasedFlowTargetApi() { not Specific::isUninterestingForTypeBasedFlowModels(this) }
300300

301301
/**
302302
* Gets the string representation of all type based summaries for `this`

0 commit comments

Comments
 (0)