-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Propagate uncertainty information to Evaluators (#886)
Co-authored-by: Wendland, Florian <[email protected]>
- Loading branch information
1 parent
5587864
commit 0f468e4
Showing
20 changed files
with
604 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...e-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/dsl/Result.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.fraunhofer.aisec.codyze.backends.cpg.coko.dsl | ||
|
||
import de.fraunhofer.aisec.codyze.backends.cpg.coko.dsl.Result.* | ||
|
||
/** | ||
* A data class that serves as a ternary value for the analysis result. | ||
* | ||
* OPEN is used where we cannot deduce either VALID or INVALID results because of lack of information. | ||
*/ | ||
enum class Result { | ||
VALID, | ||
INVALID, | ||
OPEN; | ||
|
||
companion object { | ||
fun convert(from: Any?): Result { | ||
return when (from) { | ||
is Result -> from | ||
is Boolean -> if (from) VALID else INVALID | ||
else -> OPEN | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** returns VALID if all Results are VALID, otherwise returns OPEN if any result is OPEN, otherwise returns INVALID */ | ||
fun <T> Iterable<T>.allResult(predicate: (T) -> Result?): Result { | ||
var invalidFlag = false | ||
for (element in this) { | ||
if (predicate(element) == OPEN) { | ||
return OPEN | ||
} else if (predicate(element) == INVALID) { | ||
invalidFlag = true | ||
} | ||
} | ||
return if (invalidFlag) INVALID else VALID | ||
} | ||
|
||
/** returns VALID if any Result is VALID, otherwise returns OPEN if any result is OPEN, otherwise returns INVALID */ | ||
fun <T> Iterable<T>.anyResult(predicate: (T) -> Result?): Result { | ||
var openFlag = false | ||
for (element in this) { | ||
if (predicate(element) == VALID) { | ||
return VALID | ||
} else if (predicate(element) == OPEN) { | ||
openFlag = true | ||
} | ||
} | ||
return if (openFlag) OPEN else INVALID | ||
} | ||
|
||
/** returns VALID if all Results are VALID, otherwise returns OPEN if any result is OPEN, otherwise returns INVALID */ | ||
fun <T> Array<T>.allResult(predicate: (T) -> Result?): Result { | ||
return this.asIterable().allResult(predicate) | ||
} | ||
|
||
/** returns VALID if any Result is VALID, otherwise returns OPEN if any result is OPEN, otherwise returns INVALID */ | ||
fun <T> Array<T>.anyResult(predicate: (T) -> Result?): Result { | ||
return this.asIterable().anyResult(predicate) | ||
} | ||
|
||
/** precedence order for ternary and: OPEN > INVALID > VALID */ | ||
fun Result.and(other: Result): Result { | ||
return if (this == OPEN || other == OPEN) { | ||
OPEN | ||
} else if (this == INVALID || other == INVALID) { | ||
INVALID | ||
} else { | ||
VALID | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.