Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingDepot committed Jul 10, 2024
1 parent 3804986 commit 1d8267b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import de.fraunhofer.aisec.cpg.TranslationResult
import de.fraunhofer.aisec.cpg.graph.*
import de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration
import de.fraunhofer.aisec.cpg.graph.statements.expressions.*
import de.fraunhofer.aisec.cpg.query.dataFlow
import de.fraunhofer.aisec.cpg.query.executionPath
import de.fraunhofer.aisec.cpg.query.*

//
// all functions/properties defined here must use CokoBackend
Expand Down Expand Up @@ -177,7 +176,7 @@ infix fun Any.cpgFlowsTo(that: Collection<Node>): Boolean =
is Length -> checkLength(that)
else -> this in that.map { (it as Expression).evaluate() }
}
)
}

private fun Any.checkRange(that: Collection<Node>): Boolean {
when (this) {
Expand All @@ -201,17 +200,14 @@ private fun Any.checkRange(that: Collection<Node>): Boolean {
}
}

private fun Length.checkLength(that: Collection<Node>): Result {
return Result.convert(
that.all {
val size = sizeof(it).value
if (size == -1) {
// Handle case where size could not be determined -> OPEN Finding
return OPEN
}
size in this.value
private fun Length.checkLength(that: Collection<Node>): Boolean {
return that.all {
val size = sizeof(it).value

Check warning on line 205 in codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/dsl/ImplementationDsl.kt

View check run for this annotation

Codecov / codecov/patch

codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/dsl/ImplementationDsl.kt#L204-L205

Added lines #L204 - L205 were not covered by tests
if (size == -1) {
// TODO: Handle case where size could not be determined -> OPEN Finding
}
)
size in this.value
}
}

context(CokoBackend)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,13 @@ class ImplementationDslTest {
for (i in 0..3) {
with(lengthBackend) {
val nodes = opX[i].cpgGetNodes()
val validNodes = nodes.filter { it.value == Result.VALID }
// TODO: filter out false positives
assertEquals(
results[i],
validNodes.size,
"cpgGetNodes returned ${validNodes.size} node(s) instead of ${results[i]} nodes " +
nodes.size,
"cpgGetNodes returned ${nodes.size} node(s) instead of ${results[i]} nodes " +
"for the Op: ${opX[i]}."
)
assertEquals(
1,
nodes.filter { it.value == Result.OPEN }.size,
"cpgGetNodes did not return exactly one OPEN result as expected."
)
}
}
}
Expand All @@ -133,18 +128,13 @@ class ImplementationDslTest {
for (i in 0..3) {
with(lengthBackend) {
val nodes = opX[i].cpgGetNodes()
val validNodes = nodes.filter { it.value == Result.VALID }
// TODO: filter out false positives
assertEquals(
results[i],
validNodes.size,
"cpgGetNodes returned ${validNodes.size} node(s) instead of ${results[i]} nodes " +
nodes.size,
"cpgGetNodes returned ${nodes.size} node(s) instead of ${results[i]} nodes " +
"for the Op: ${opX[i]}."
)
assertEquals(
1,
nodes.filter { it.value == Result.OPEN }.size,
"cpgGetNodes did not return exactly one OPEN result as expected."
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fraunhofer.aisec.codyze.backends.cpg
package de.fraunhofer.aisec.codyze.backends.cpg.coko.evaluators

import de.fraunhofer.aisec.codyze.backends.cpg.coko.CokoCpgBackend
import de.fraunhofer.aisec.codyze.backends.cpg.coko.CpgFinding
import de.fraunhofer.aisec.codyze.backends.cpg.createCpgConfiguration
import de.fraunhofer.aisec.codyze.backends.cpg.dummyRule
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.EvaluationContext
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.Finding
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.dsl.definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fraunhofer.aisec.codyze.backends.cpg
package de.fraunhofer.aisec.codyze.backends.cpg.coko.evaluators

import de.fraunhofer.aisec.codyze.backends.cpg.coko.CokoCpgBackend
import de.fraunhofer.aisec.codyze.backends.cpg.createCpgConfiguration
import de.fraunhofer.aisec.codyze.backends.cpg.dummyRule
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.EvaluationContext
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.Finding
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.dsl.definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fraunhofer.aisec.codyze.backends.cpg
package de.fraunhofer.aisec.codyze.backends.cpg.coko.evaluators

import de.fraunhofer.aisec.codyze.backends.cpg.coko.CokoCpgBackend
import de.fraunhofer.aisec.codyze.backends.cpg.createCpgConfiguration
import de.fraunhofer.aisec.codyze.backends.cpg.dummyRule
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.EvaluationContext
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.Finding
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.dsl.definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fraunhofer.aisec.codyze.backends.cpg
package de.fraunhofer.aisec.codyze.backends.cpg.coko.evaluators

import de.fraunhofer.aisec.codyze.backends.cpg.coko.CokoCpgBackend
import de.fraunhofer.aisec.codyze.backends.cpg.coko.CpgFinding
import de.fraunhofer.aisec.codyze.backends.cpg.createCpgConfiguration
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.CokoBackend
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.EvaluationContext
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.Evaluator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fraunhofer.aisec.codyze.backends.cpg
package de.fraunhofer.aisec.codyze.backends.cpg.coko.ordering

import de.fraunhofer.aisec.codyze.backends.cpg.coko.CokoCpgBackend
import de.fraunhofer.aisec.codyze.backends.cpg.coko.ordering.toNfa
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.dsl.*
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.ordering.*
import de.fraunhofer.aisec.cpg.analysis.fsm.DFA
Expand Down

0 comments on commit 1d8267b

Please sign in to comment.