Skip to content

Commit

Permalink
Using ValueEvaluator instead of ValueResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Jul 23, 2024
1 parent e1637fe commit 79ef63e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions cloudpg/src/main/java/io/clouditor/graph/ValueResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ open class ValueResolver(

return cannotResolve(expr, this)
}
is Reference -> {
return expr.refersTo
}
}

return cannotResolve(expr, this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.clouditor.graph.passes

import de.fraunhofer.aisec.cpg.TranslationContext
import de.fraunhofer.aisec.cpg.TranslationResult
import de.fraunhofer.aisec.cpg.analysis.ValueEvaluator
import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration
import de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression
Expand Down Expand Up @@ -293,34 +294,34 @@ class GormDatabasePass(ctx: TranslationContext) : DatabaseOperationPass(ctx) {
}
?: mutableMapOf()

return ValueResolver { node, resolver ->
return ValueEvaluator { node, resolver ->
when (node) {
is CallExpression -> {
// support for some special calls, i.e. format
if (node.name.localName == "Sprintf") {
val str = resolver.resolve(node.arguments.firstOrNull()) as String
val str = resolver.evaluate(node.arguments.firstOrNull()) as String
val arguments = node.arguments.drop(1)

return@ValueResolver str.format(
*arguments.map { resolver.resolve(it) }.toTypedArray()
return@ValueEvaluator str.format(
*arguments.map { resolver.evaluate(it) }.toTypedArray()
)
}

// a little bit of a hack, this is specific to our use case, since the
// stdlib doesnt have that built-in
if (node.name.localName == "EnvOrDefault") {
// environment lookup on python
val key = resolver.resolve(node.arguments.firstOrNull())
val key = resolver.evaluate(node.arguments.firstOrNull())

return@ValueResolver env[key] ?: resolver.resolve(node.arguments[1])
return@ValueEvaluator env[key] ?: resolver.evaluate(node.arguments[1])
}

// return placeholder
return@ValueResolver "{${node.name}()}"
return@ValueEvaluator "{${node.name}()}"
}
else -> return@ValueResolver "{${node?.name}}"
else -> return@ValueEvaluator "{${node?.name}}"
}
}
.resolve(expr)
.evaluate(expr)
}
}

0 comments on commit 79ef63e

Please sign in to comment.