Skip to content

Commit

Permalink
Pass ordering, but broken until cpg 8.2.0 is released
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Apr 19, 2024
1 parent a5b1191 commit 5ec4eeb
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 30 deletions.
15 changes: 6 additions & 9 deletions cloudpg/src/main/java/io/clouditor/graph/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import io.clouditor.graph.nodes.Builder
import io.clouditor.graph.passes.*
import io.clouditor.graph.passes.golang.*
import io.clouditor.graph.passes.java.JaxRsClientPass
import io.clouditor.graph.passes.java.JaxRsPass
import io.clouditor.graph.passes.java.SpringBootPass
import io.clouditor.graph.passes.js.FetchPass
import io.clouditor.graph.passes.js.JSHttpPass
import io.clouditor.graph.passes.python.*
import io.clouditor.graph.testing.LocalTestingPass
import java.nio.file.Path
Expand Down Expand Up @@ -119,7 +116,7 @@ object App : Callable<Int> {
val builder =
TranslationConfiguration.builder()
.topLevel(rootPath.toFile())
.sourceLocations(paths.map { rootPath.resolve(it).toFile() })
.sourceLocations(paths.map { rootPath.resolve(it).toFile().normalize() })
.registerLanguage(JavaLanguage())
.registerLanguage(CPPLanguage())
.registerLanguage(CLanguage())
Expand All @@ -129,13 +126,13 @@ object App : Callable<Int> {
.debugParser(true)
.defaultPasses()
.registerPass(GitHubWorkflowPass::class)
.registerPass(SpringBootPass::class)
.registerPass(JaxRsPass::class)
// .registerPass(SpringBootPass::class)
// .registerPass(JaxRsPass::class)
.registerPass(GolangHttpPass::class)
.registerPass(GinGonicPass::class)
// .registerPass(WebBrickPass::class)
.registerPass(JSHttpPass::class)
.registerPass(FlaskPass::class)
// .registerPass(JSHttpPass::class)
// .registerPass(FlaskPass::class)
.apply {
if (localMode) {
// register the localTestingPass after the HTTP Passes since it needs HTTP
Expand Down Expand Up @@ -194,7 +191,7 @@ val TranslationResult.computes: MutableList<Compute>
MutableList<Compute>

fun TranslationResult.findApplicationByTU(tu: TranslationUnitDeclaration): Application? {
return this.additionalNodes.filterIsInstance(Application::class.java).firstOrNull {
return this.additionalNodes.filterIsInstance<Application>().firstOrNull {
it.translationUnits.contains(tu)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,14 @@ class LabelExtractionPass(ctx: TranslationContext) : TranslationResultPass(ctx)
node.declarations
.filterIsInstance<VariableDeclaration>()
.flatMap { it.usageEdges.map { edge -> edge.end.refersTo } }
.filterNotNull()
.toSet()
usages.forEach { addLabelToDFGBorderEdges(it as Node, label) }
usages.forEach { addLabelToDFGBorderEdges(it, label) }
}
is AssignExpression -> {
val variableDeclarations =
node.lhs.filterIsInstance<Reference>().map { it.refersTo }
variableDeclarations.forEach { addLabelToDFGBorderEdges(it as Node, label) }
node.lhs.filterIsInstance<Reference>().mapNotNull { it.refersTo }
variableDeclarations.forEach { addLabelToDFGBorderEdges(it, label) }
}
else -> {
addLabelToDFGBorderEdges(node, label)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.declarations.FunctionDeclaration
import de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration
import de.fraunhofer.aisec.cpg.graph.declarations.VariableDeclaration
import de.fraunhofer.aisec.cpg.graph.firstAssignment
import de.fraunhofer.aisec.cpg.graph.parseName
import de.fraunhofer.aisec.cpg.graph.statements.expressions.*
import de.fraunhofer.aisec.cpg.graph.types.PointerType
import de.fraunhofer.aisec.cpg.passes.*
import de.fraunhofer.aisec.cpg.passes.order.DependsOn
import de.fraunhofer.aisec.cpg.passes.order.ExecuteBefore
import de.fraunhofer.aisec.cpg.processing.IVisitor
import de.fraunhofer.aisec.cpg.processing.strategy.Strategy
import io.clouditor.graph.*
import io.clouditor.graph.passes.KubernetesPass
import io.clouditor.graph.testing.LocalTestingPass

@DependsOn(GoExtraPass::class)
@DependsOn(SymbolResolver::class)
@ExecuteBefore(LocalTestingPass::class)
@ExecuteBefore(KubernetesPass::class)
@DependsOn(
LocalTestingPass::class /*, softDependency = true*/
) // should be "soft", but broken until #1532 is released
// @DependsOn(KubernetesPass::class /*, softDependency = true*/)
class GinGonicPass(ctx: TranslationContext) : TranslationResultPass(ctx) {
private val clients = mutableMapOf<VariableDeclaration, HttpRequestHandler>()

Expand Down Expand Up @@ -257,9 +257,10 @@ class GinGonicPass(ctx: TranslationContext) : TranslationResultPass(ctx) {
tu: TranslationUnitDeclaration,
r: VariableDeclaration
) {
if (r.initializer is CallExpression &&
((r.initializer as CallExpression).name.toString() == "gin.Default" ||
(r.initializer as CallExpression).name.toString() == "gin.New")
val initializer = r.firstAssignment
if (initializer is CallExpression &&
(initializer.name.toString() == "gin.Default" ||
initializer.name.toString() == "gin.New")
) {
val app = result.findApplicationByTU(tu)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ import de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration
import de.fraunhofer.aisec.cpg.graph.declarations.VariableDeclaration
import de.fraunhofer.aisec.cpg.graph.statements.expressions.*
import de.fraunhofer.aisec.cpg.graph.types.PointerType
import de.fraunhofer.aisec.cpg.passes.GoExtraPass
import de.fraunhofer.aisec.cpg.passes.SymbolResolver
import de.fraunhofer.aisec.cpg.passes.order.DependsOn
import de.fraunhofer.aisec.cpg.processing.IVisitor
import de.fraunhofer.aisec.cpg.processing.strategy.Strategy
import io.clouditor.graph.*
import io.clouditor.graph.passes.HttpClientPass
import io.clouditor.graph.testing.LocalTestingPass
import kotlin.streams.toList

@Suppress("UNUSED_PARAMETER")
@DependsOn(GoExtraPass::class)
@DependsOn(SymbolResolver::class)
@DependsOn(LocalTestingPass::class, softDependency = true)
// @DependsOn(KubernetesPass::class, softDependency = true)
class GolangHttpPass(ctx: TranslationContext) : HttpClientPass(ctx) {
private val clients = mutableMapOf<VariableDeclaration, HttpRequestHandler>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import de.fraunhofer.aisec.cpg.TranslationResult
import de.fraunhofer.aisec.cpg.graph.Name
import de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration
import de.fraunhofer.aisec.cpg.passes.TranslationResultPass
import de.fraunhofer.aisec.cpg.passes.order.DependsOn
import io.clouditor.graph.*
import io.clouditor.graph.passes.golang.GinGonicPass
import io.clouditor.graph.passes.golang.appendPath
import java.nio.file.Files

@DependsOn(GinGonicPass::class)
class LocalTestingPass(ctx: TranslationContext) : TranslationResultPass(ctx) {

override fun accept(t: TranslationResult) {
Expand Down
3 changes: 1 addition & 2 deletions cloudpg/src/test/java/io/clouditor/graph/PerformanceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.clouditor.graph

import kotlin.io.path.*
import kotlinx.benchmark.Scope
import kotlinx.benchmark.readFile
import org.junit.Test
import org.openjdk.jmh.annotations.*

Expand Down Expand Up @@ -70,7 +69,7 @@ open class PerformanceTest {

// create ONE large file
val tmp = createTempFile(dir, "detectability", ".py")
tmp.appendText(serverSrc.readFile())
tmp.appendText(Path(serverSrc).readText())
// append the function i times to the temporary file
for (i in 1..range.toInt()) {
val sampleFunction =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (

func main() {
//@PseudoIdentifier
name := "firstname lastname"
var name = "firstname lastname"
//name := "firstname lastname"
data := url.Values{
"Name": {name},
"Name": {name},
"Message": {"hello world"},
}

Expand Down

0 comments on commit 5ec4eeb

Please sign in to comment.