From 40b46d346876b5e8ac48560c5c436bb5d1b93da9 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Fri, 6 Sep 2024 01:10:06 +0200 Subject: [PATCH] Some code review comments --- .../aisec/cpg/frontends/LanguageTraits.kt | 17 +++++++++-------- .../cpg/graph/edges/collections/EdgeList.kt | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/LanguageTraits.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/LanguageTraits.kt index 2e33473dd0c..d4dc45b7ee9 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/LanguageTraits.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/LanguageTraits.kt @@ -245,13 +245,6 @@ inline infix fun KClass.of( return Pair(T::class, operatorCode) } -/** Checks whether the [Name] for a function is a known operator name. */ -context(LanguageProvider) -val Name.isKnownOperatorName: Boolean - get() { - return this.localName.isKnownOperatorName - } - /** Checks whether the name for a function (as [CharSequence]) is a known operator name. */ context(LanguageProvider) val CharSequence.isKnownOperatorName: Boolean @@ -261,5 +254,13 @@ val CharSequence.isKnownOperatorName: Boolean return false } - return language.overloadedOperatorNames.containsValue(this) + // If this is a parsed name, we only are interested in the local name + val name = + if (this is Name) { + this.localName + } else { + this + } + + return language.overloadedOperatorNames.containsValue(name) } diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/collections/EdgeList.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/collections/EdgeList.kt index ce3dcb69e4b..cfbf9a8c030 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/collections/EdgeList.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/collections/EdgeList.kt @@ -82,6 +82,7 @@ abstract class EdgeList>( return ok } + /** Replaces the first occurrence of an edge with [old] with a new edge to [new]. */ fun replace(old: NodeType, new: NodeType): Boolean { val idx = this.indexOfFirst { it.end == old } if (idx != -1) {