Skip to content

Commit

Permalink
C#/Java: Invert api filtering logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnebel committed May 8, 2024
1 parent 5a14ebe commit 98aa749
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ private import CaptureModelsSpecific
private import CaptureModelsPrinting

class DataFlowTargetApi extends TargetApiSpecific {
DataFlowTargetApi() { isRelevantForDataFlowModels(this) }
DataFlowTargetApi() { not isUninterestingForDataFlowModels(this) }
}

private module Printing implements PrintingSig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,18 @@ private predicate isRelevantForModels(CS::Callable api) {
}

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

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

/**
* A class of callables that are relevant generating summary, source and sinks models for.
Expand All @@ -71,7 +73,8 @@ predicate isRelevantForTypeBasedFlowModels = isRelevantForModels/1;
class TargetApiSpecific extends CS::Callable {
TargetApiSpecific() {
this.fromSource() and
this.isUnboundDeclaration()
this.isUnboundDeclaration() and
isRelevantForModels(this)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private module ModelPrinting = PrintingImpl<Printing>;
* on the Theorems for Free approach.
*/
class TypeBasedFlowTargetApi extends Specific::TargetApiSpecific {
TypeBasedFlowTargetApi() { Specific::isRelevantForTypeBasedFlowModels(this) }
TypeBasedFlowTargetApi() { not Specific::isUninterestingForTypeBasedFlowModels(this) }

/**
* Gets the string representation of all type based summaries for `this`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ private import CaptureModelsSpecific
private import CaptureModelsPrinting

class DataFlowTargetApi extends TargetApiSpecific {
DataFlowTargetApi() { isRelevantForDataFlowModels(this) }
DataFlowTargetApi() { not isUninterestingForDataFlowModels(this) }
}

private module Printing implements PrintingSig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,20 @@ private predicate hasManualModel(Callable api) {
}

/**
* Holds if it is relevant to generate models for `api` based on data flow analysis.
* Holds if it is irrelevant to generate models for `api` based on data flow analysis.
*
* This serves as an extra filter for the `relevant` predicate.
*/
predicate isRelevantForDataFlowModels(Callable api) {
(not api.getDeclaringType() instanceof J::Interface or exists(api.getBody()))
predicate isUninterestingForDataFlowModels(Callable api) {
api.getDeclaringType() instanceof J::Interface and not exists(api.getBody())
}

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

/**
* A class of Callables that are relevant for generating summary, source and sinks models for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private module ModelPrinting = PrintingImpl<Printing>;
* on the Theorems for Free approach.
*/
class TypeBasedFlowTargetApi extends Specific::TargetApiSpecific {
TypeBasedFlowTargetApi() { Specific::isRelevantForTypeBasedFlowModels(this) }
TypeBasedFlowTargetApi() { not Specific::isUninterestingForTypeBasedFlowModels(this) }

/**
* Gets the string representation of all type based summaries for `this`
Expand Down

0 comments on commit 98aa749

Please sign in to comment.