From 79ef63ebe5503acb7b687f60eee70f138b470172 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Tue, 23 Jul 2024 14:33:48 +0200 Subject: [PATCH] Using ValueEvaluator instead of ValueResolver --- .../java/io/clouditor/graph/ValueResolver.kt | 3 +++ .../graph/passes/GormDatabasePass.kt | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cloudpg/src/main/java/io/clouditor/graph/ValueResolver.kt b/cloudpg/src/main/java/io/clouditor/graph/ValueResolver.kt index 00a87e9..084386e 100644 --- a/cloudpg/src/main/java/io/clouditor/graph/ValueResolver.kt +++ b/cloudpg/src/main/java/io/clouditor/graph/ValueResolver.kt @@ -152,6 +152,9 @@ open class ValueResolver( return cannotResolve(expr, this) } + is Reference -> { + return expr.refersTo + } } return cannotResolve(expr, this) diff --git a/cloudpg/src/main/java/io/clouditor/graph/passes/GormDatabasePass.kt b/cloudpg/src/main/java/io/clouditor/graph/passes/GormDatabasePass.kt index f28444d..b45215a 100644 --- a/cloudpg/src/main/java/io/clouditor/graph/passes/GormDatabasePass.kt +++ b/cloudpg/src/main/java/io/clouditor/graph/passes/GormDatabasePass.kt @@ -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 @@ -293,16 +294,16 @@ 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() ) } @@ -310,17 +311,17 @@ class GormDatabasePass(ctx: TranslationContext) : DatabaseOperationPass(ctx) { // 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) } }