From a25a96f006c1c16c0ae8e7100c2b351788ad2348 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Mon, 9 Oct 2023 15:15:45 +0200 Subject: [PATCH] Renamed ResolutionStartHolder to EOGStartHolder --- .../{ResolutionStartHolder.kt => EOGStartHolder.kt} | 12 ++++++------ .../cpg/graph/declarations/FunctionDeclaration.kt | 4 ++-- .../cpg/graph/declarations/NamespaceDeclaration.kt | 5 ++--- .../cpg/graph/declarations/RecordDeclaration.kt | 5 ++--- .../graph/declarations/TranslationUnitDeclaration.kt | 4 ++-- .../aisec/cpg/graph/statements/CatchClause.kt | 6 +++--- .../aisec/cpg/passes/EvaluationOrderGraphPass.kt | 4 ++-- .../de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt | 3 +-- 8 files changed, 20 insertions(+), 23 deletions(-) rename cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/{ResolutionStartHolder.kt => EOGStartHolder.kt} (80%) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/ResolutionStartHolder.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/EOGStartHolder.kt similarity index 80% rename from cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/ResolutionStartHolder.kt rename to cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/EOGStartHolder.kt index 822f36fe0e1..7d2cd21cddc 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/ResolutionStartHolder.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/EOGStartHolder.kt @@ -36,12 +36,12 @@ import de.fraunhofer.aisec.cpg.passes.SymbolResolver * * In some cases, the [Node] that implements this interface will add itself, for example in a * [FunctionDeclaration], so that we can use all functions as an entry-point to symbol resolution. - * In other cases, certain child nodes might be added to [resolutionStartNodes], for example to add - * all top-level declarations in a [TranslationUnitDeclaration]. + * In other cases, certain child nodes might be added to [eogStart], for example to add all + * top-level declarations in a [TranslationUnitDeclaration]. * - * The common denominator is that all the nodes contained in [resolutionStartNodes] **start** an EOG - * path, i.e,. they should have a valid [Node.nextEOG], but an empty [Node.prevEOG]. + * The common denominator is that all the nodes contained in [eogStart] *start* an EOG path, i.e., + * they should have a valid [Node.nextEOG], but an empty [Node.prevEOG]. */ -interface ResolutionStartHolder { - val resolutionStartNodes: List +interface EOGStartHolder { + val eogStart: List } diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/FunctionDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/FunctionDeclaration.kt index 709e89db775..debf649b9b3 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/FunctionDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/FunctionDeclaration.kt @@ -41,7 +41,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder import org.neo4j.ogm.annotation.Relationship /** Represents the declaration or definition of a function. */ -open class FunctionDeclaration : ValueDeclaration(), DeclarationHolder, ResolutionStartHolder { +open class FunctionDeclaration : ValueDeclaration(), DeclarationHolder, EOGStartHolder { /** The function body. Usually a [Block]. */ @AST var body: Statement? = null @@ -227,7 +227,7 @@ open class FunctionDeclaration : ValueDeclaration(), DeclarationHolder, Resoluti .toString() } - override val resolutionStartNodes: List + override val eogStart: List get() = listOfNotNull(this) override fun equals(other: Any?): Boolean { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/NamespaceDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/NamespaceDeclaration.kt index 8e4dc4805bb..a786ef2fdac 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/NamespaceDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/NamespaceDeclaration.kt @@ -43,8 +43,7 @@ import org.neo4j.ogm.annotation.Relationship * * The name property of this node need to be a FQN for property resolution. */ -class NamespaceDeclaration : - Declaration(), DeclarationHolder, StatementHolder, ResolutionStartHolder { +class NamespaceDeclaration : Declaration(), DeclarationHolder, StatementHolder, EOGStartHolder { /** * Edges to nested namespaces, records, functions, fields etc. contained in the current * namespace. @@ -93,7 +92,7 @@ class NamespaceDeclaration : override var statements: List by PropertyEdgeDelegate(NamespaceDeclaration::statementEdges) - override val resolutionStartNodes: List + override val eogStart: List get() { val list = mutableListOf() // Add all top-level declarations diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/RecordDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/RecordDeclaration.kt index 444e5174071..e464a5f7fba 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/RecordDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/RecordDeclaration.kt @@ -37,8 +37,7 @@ import org.neo4j.ogm.annotation.Relationship import org.neo4j.ogm.annotation.Transient /** Represents a C++ union/struct/class or Java class */ -open class RecordDeclaration : - Declaration(), DeclarationHolder, StatementHolder, ResolutionStartHolder { +open class RecordDeclaration : Declaration(), DeclarationHolder, StatementHolder, EOGStartHolder { /** The kind, i.e. struct, class, union or enum. */ var kind: String? = null @@ -173,7 +172,7 @@ open class RecordDeclaration : .toString() } - override val resolutionStartNodes: List + override val eogStart: List get() { val list = mutableListOf() diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TranslationUnitDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TranslationUnitDeclaration.kt index a8a85aee812..2d3235b2d29 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TranslationUnitDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TranslationUnitDeclaration.kt @@ -38,7 +38,7 @@ import org.neo4j.ogm.annotation.Relationship /** The top most declaration, representing a translation unit, for example a file. */ class TranslationUnitDeclaration : - Declaration(), DeclarationHolder, StatementHolder, PassTarget, ResolutionStartHolder { + Declaration(), DeclarationHolder, StatementHolder, PassTarget, EOGStartHolder { /** A list of declarations within this unit. */ @Relationship(value = "DECLARATIONS", direction = Relationship.Direction.OUTGOING) @AST @@ -126,7 +126,7 @@ class TranslationUnitDeclaration : .toString() } - override val resolutionStartNodes: List + override val eogStart: List get() { val list = mutableListOf() // Add all top-level declarations diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/CatchClause.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/CatchClause.kt index 8aafb79aec2..65a08f0b0d1 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/CatchClause.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/CatchClause.kt @@ -27,13 +27,13 @@ package de.fraunhofer.aisec.cpg.graph.statements import de.fraunhofer.aisec.cpg.graph.AST import de.fraunhofer.aisec.cpg.graph.BranchingNode +import de.fraunhofer.aisec.cpg.graph.EOGStartHolder import de.fraunhofer.aisec.cpg.graph.Node -import de.fraunhofer.aisec.cpg.graph.ResolutionStartHolder import de.fraunhofer.aisec.cpg.graph.declarations.VariableDeclaration import de.fraunhofer.aisec.cpg.graph.statements.expressions.Block import java.util.Objects -class CatchClause : Statement(), BranchingNode, ResolutionStartHolder { +class CatchClause : Statement(), BranchingNode, EOGStartHolder { @AST var parameter: VariableDeclaration? = null @AST var body: Block? = null @@ -41,7 +41,7 @@ class CatchClause : Statement(), BranchingNode, ResolutionStartHolder { override val branchedBy: Node? get() = parameter - override val resolutionStartNodes: List + override val eogStart: List get() = listOf(this) override fun equals(other: Any?): Boolean { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/EvaluationOrderGraphPass.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/EvaluationOrderGraphPass.kt index bae0b05bd47..71052a237ae 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/EvaluationOrderGraphPass.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/EvaluationOrderGraphPass.kt @@ -28,8 +28,8 @@ package de.fraunhofer.aisec.cpg.passes import de.fraunhofer.aisec.cpg.TranslationContext import de.fraunhofer.aisec.cpg.frontends.HasShortCircuitOperators import de.fraunhofer.aisec.cpg.frontends.ProcessedListener +import de.fraunhofer.aisec.cpg.graph.EOGStartHolder import de.fraunhofer.aisec.cpg.graph.Node -import de.fraunhofer.aisec.cpg.graph.ResolutionStartHolder import de.fraunhofer.aisec.cpg.graph.StatementHolder import de.fraunhofer.aisec.cpg.graph.declarations.* import de.fraunhofer.aisec.cpg.graph.edge.Properties @@ -187,7 +187,7 @@ open class EvaluationOrderGraphPass(ctx: TranslationContext) : TranslationUnitPa ) // only eog entry points var validStarts = - eogNodes.filter { it is ResolutionStartHolder || it is VariableDeclaration }.toSet() + eogNodes.filter { it is EOGStartHolder || it is VariableDeclaration }.toSet() // Remove all nodes from eogNodes which are reachable from validStarts and transitively. val alreadySeen = IdentitySet() while (validStarts.isNotEmpty()) { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt index 5e3ec966b7b..5100ad6d426 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt @@ -118,8 +118,7 @@ open class SymbolResolver(ctx: TranslationContext) : ComponentPass(ctx) { for (tu in component.translationUnits) { currentTU = tu // gather all resolution start holders and their start nodes - val nodes = - tu.allChildren().flatMap { it.resolutionStartNodes }.toSet() + val nodes = tu.allChildren().flatMap { it.eogStart }.toSet() for (node in nodes) { walker.iterate(node)