diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/builder/Fluent.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/builder/Fluent.kt index d03de43f9cd..e4acd860930 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/builder/Fluent.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/builder/Fluent.kt @@ -752,6 +752,21 @@ fun LanguageFrontend<*, *>.loopBody(init: Block.() -> Unit): Block { return node } +/** + * Creates a new [Block] in the Fluent Node DSL and sets it to the [DoStatement.statement] of the + * nearest enclosing [WhileStatement]. The [init] block can be used to create further sub-nodes as + * well as configuring the created node itself. + */ +context(DoStatement) + +fun LanguageFrontend<*, *>.loopBody(init: Block.() -> Unit): Block { + val node = newBlock() + init(node) + statement = node + + return node +} + /** * Creates a new [Block] in the Fluent Node DSL and sets it to the [WhileStatement.statement] of the * nearest enclosing [WhileStatement]. The [init] block can be used to create further sub-nodes as 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 9fed1238d12..3c380e3a158 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 @@ -27,10 +27,12 @@ package de.fraunhofer.aisec.cpg.graph.declarations import de.fraunhofer.aisec.cpg.graph.AST import de.fraunhofer.aisec.cpg.graph.DeclarationHolder +import de.fraunhofer.aisec.cpg.graph.Node import de.fraunhofer.aisec.cpg.graph.StatementHolder import de.fraunhofer.aisec.cpg.graph.edge.PropertyEdge import de.fraunhofer.aisec.cpg.graph.edge.PropertyEdgeDelegate import de.fraunhofer.aisec.cpg.graph.statements.Statement +import de.fraunhofer.aisec.cpg.passes.ResolutionStartHolder import java.util.Objects import org.neo4j.ogm.annotation.Relationship @@ -45,7 +47,8 @@ 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 { +class NamespaceDeclaration : + Declaration(), DeclarationHolder, StatementHolder, ResolutionStartHolder { /** * Edges to nested namespaces, records, functions, fields etc. contained in the current * namespace. @@ -93,4 +96,15 @@ class NamespaceDeclaration : Declaration(), DeclarationHolder, StatementHolder { override var statements: List by PropertyEdgeDelegate(NamespaceDeclaration::statementEdges) + + override val resolutionStartNodes: List + get() { + val list = mutableListOf() + // Add all top-level declarations + list += declarations + // Add all top-level statements + list += statements + + return list + } } diff --git a/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/golang/ExpressionHandler.kt b/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/golang/ExpressionHandler.kt index 6055a14c7a6..488bedb528f 100644 --- a/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/golang/ExpressionHandler.kt +++ b/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/golang/ExpressionHandler.kt @@ -149,16 +149,7 @@ class ExpressionHandler(frontend: GoLanguageFrontend) : return literal } - val ref = newReference(ident.name, rawNode = ident) - - // Check, if this refers to a package import - val import = frontend.currentTU?.getIncludeByName(ident.name) - // Then set the refersTo, because our regular CPG passes will not resolve them - if (import != null) { - ref.refersTo = import - } - - return ref + return newReference(ident.name, rawNode = ident) } private fun handleIndexExpr(indexExpr: GoStandardLibrary.Ast.IndexExpr): SubscriptExpression {