Skip to content

Commit

Permalink
Addressing more code review
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Aug 7, 2024
1 parent 35fc17f commit 13be7de
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import de.fraunhofer.aisec.cpg.graph.edges.ast.astEdgesOf
import de.fraunhofer.aisec.cpg.graph.edges.unwrapping
import de.fraunhofer.aisec.cpg.graph.statements.*
import de.fraunhofer.aisec.cpg.graph.statements.expressions.Expression
import de.fraunhofer.aisec.cpg.graph.statements.expressions.Block
import de.fraunhofer.aisec.cpg.graph.types.Type
import java.util.*
import org.apache.commons.lang3.builder.ToStringBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,25 @@ open class AstEdge<T : Node> : Edge<T> {
}

/** Creates an [AstEdges] container starting from this node. */
context(Node)
fun <NodeType : Node> astEdgesOf(
fun <NodeType : Node> Node.astEdgesOf(
postAdd: ((AstEdge<NodeType>) -> Unit)? = null,
preRemove: ((AstEdge<NodeType>) -> Unit)? = null,
postRemove: ((AstEdge<NodeType>) -> Unit)? = null,
): AstEdges<NodeType, AstEdge<NodeType>> {
return AstEdges(this@Node, postAdd, preRemove)
return AstEdges(this, postAdd, postRemove)
}

/** This property edge list describes elements that are AST children of a node. */
@Suppress("UNCHECKED_CAST")
open class AstEdges<NodeType : Node, PropertyEdgeType : Edge<NodeType>>(
thisRef: Node,
postAdd: ((PropertyEdgeType) -> Unit)? = null,
preRemove: ((PropertyEdgeType) -> Unit)? = null,
init: (start: Node, end: NodeType) -> PropertyEdgeType = { start, end ->
postRemove: ((PropertyEdgeType) -> Unit)? = null,
@Suppress("UNCHECKED_CAST") init: (start: Node, end: NodeType) -> PropertyEdgeType = { start, end ->
AstEdge<NodeType>(start, end) as PropertyEdgeType
}
) :
EdgeList<NodeType, PropertyEdgeType>(
thisRef = thisRef,
init = init,
postAdd = postAdd,
postRemove = preRemove,
postRemove = postRemove,
)
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ class InitializerListExpression : Expression(), ArgumentHolder, HasType.TypeObse
/** The list of initializers. */
@Relationship(value = "INITIALIZERS", direction = Relationship.Direction.OUTGOING)
@AST
var initializerEdges = astEdgesOf<Expression>(postAdd = { it.end.registerTypeObserver(this) })
var initializerEdges =
astEdgesOf<Expression>(
postAdd = { it.end.registerTypeObserver(this) },
postRemove = { it.end.unregisterTypeObserver(this) },
)

/** Virtual property to access [initializerEdges] without property edges. */
var initializers by PropertyEdgeDelegate(InitializerListExpression::initializerEdges)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ open class ControlDependenceGraphPass(ctx: TranslationContext) : EOGStarterPass(
node.prevCDGEdges.add(k) {
branches =
when {
branchesSet.size == 1 -> {
branchesSet
}
branchesSet.isNotEmpty() -> {
branchesSet
}
Expand Down

0 comments on commit 13be7de

Please sign in to comment.