Skip to content

Commit

Permalink
Almost all Go test works
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Sep 25, 2023
1 parent 9af1de6 commit 22bb061
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -93,4 +96,15 @@ class NamespaceDeclaration : Declaration(), DeclarationHolder, StatementHolder {

override var statements: List<Statement> by
PropertyEdgeDelegate(NamespaceDeclaration::statementEdges)

override val resolutionStartNodes: List<Node>
get() {
val list = mutableListOf<Node>()
// Add all top-level declarations
list += declarations
// Add all top-level statements
list += statements

return list
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 22bb061

Please sign in to comment.