From ac7a8494cbcbb1807419352af324f9a52e7a4fbb Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Fri, 24 Mar 2023 19:52:34 +0100 Subject: [PATCH] Formatting and stuff --- .../de/fraunhofer/aisec/cpg/ScopeManager.kt | 48 +++++++++---------- .../aisec/cpg/passes/inference/Inference.kt | 1 - .../aisec/cpg/passes/GoExtraPass.kt | 4 +- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/ScopeManager.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/ScopeManager.kt index c843b3b10c..29da6fb328 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/ScopeManager.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/ScopeManager.kt @@ -462,7 +462,7 @@ class ScopeManager : ScopeProvider { if (scope == null) { LOGGER.error( "Break inside of unbreakable scope. The break will be ignored, but may lead " + - "to an incorrect graph. The source code is not valid or incomplete." + "to an incorrect graph. The source code is not valid or incomplete." ) return } @@ -487,7 +487,7 @@ class ScopeManager : ScopeProvider { if (scope == null) { LOGGER.error( "Continue inside of not continuable scope. The continue will be ignored, but may lead " + - "to an incorrect graph. The source code is not valid or incomplete." + "to an incorrect graph. The source code is not valid or incomplete." ) return } @@ -599,30 +599,30 @@ class ScopeManager : ScopeProvider { scope: Scope? = currentScope ): ValueDeclaration? { return resolve(scope) { - if ( - it.name.lastPartsMatch(ref.name) - ) { // TODO: This place is likely to make things fail - // If the reference seems to point to a function the entire signature is checked - // for equality - if (ref.type is FunctionPointerType && it is FunctionDeclaration) { - val fptrType = (ref as HasType).type as FunctionPointerType - // TODO(oxisto): This is the third place where function pointers are - // resolved. WHY? - // TODO(oxisto): Support multiple return values - val returnType = it.returnTypes.firstOrNull() ?: IncompleteType() - if ( - returnType == fptrType.returnType && - it.hasSignature(fptrType.parameters) - ) { - return@resolve true + if ( + it.name.lastPartsMatch(ref.name) + ) { // TODO: This place is likely to make things fail + // If the reference seems to point to a function the entire signature is checked + // for equality + if (ref.type is FunctionPointerType && it is FunctionDeclaration) { + val fptrType = (ref as HasType).type as FunctionPointerType + // TODO(oxisto): This is the third place where function pointers are + // resolved. WHY? + // TODO(oxisto): Support multiple return values + val returnType = it.returnTypes.firstOrNull() ?: IncompleteType() + if ( + returnType == fptrType.returnType && + it.hasSignature(fptrType.parameters) + ) { + return@resolve true + } + } else { + return@resolve it !is FunctionDeclaration } - } else { - return@resolve it !is FunctionDeclaration } - } - return@resolve false - } + return@resolve false + } .firstOrNull() } @@ -827,4 +827,4 @@ class ScopeManager : ScopeProvider { ) } } -} \ No newline at end of file +} diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/inference/Inference.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/inference/Inference.kt index 8a2c625955..19f9b33514 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/inference/Inference.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/inference/Inference.kt @@ -151,7 +151,6 @@ class Inference(val start: Node, val scopeManager: ScopeManager) : return scopeManager.withScope(scopeManager.lookupScope(start), init) } - private fun createInferredParameters(function: FunctionDeclaration, signature: List) { // To save some unnecessary scopes, we only want to "enter" the function if it is necessary, // e.g., if we need to create parameters diff --git a/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/GoExtraPass.kt b/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/GoExtraPass.kt index 0ee7a7acc9..62ae002773 100644 --- a/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/GoExtraPass.kt +++ b/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/GoExtraPass.kt @@ -120,7 +120,7 @@ class GoExtraPass : Pass(), ScopeProvider { when (node) { is CallExpression -> handleCall(node, parent) is IncludeDeclaration -> handleInclude(node) - is AssignExpression -> handleAssign(node, parent) + is AssignExpression -> handleAssign(node) is ForEachStatement -> handleForEachStatement(node) } } @@ -170,7 +170,7 @@ class GoExtraPass : Pass(), ScopeProvider { * This function gets called for every [AssignExpression], to check, whether we need to * implicitly define any variables assigned in the statement. */ - private fun handleAssign(assign: AssignExpression, parent: Node?) { + private fun handleAssign(assign: AssignExpression) { // Only filter nodes that could potentially declare if (assign.operatorCode != ":=") { return