Skip to content

Commit

Permalink
ast children works again
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Jul 31, 2024
1 parent 158a37a commit d80c204
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class AstProperty<PropertyType : Node?, NodeType : Node>(
var post: ((PropertyType) -> Unit)? = null
) {

private var storage: PropertyType = initializer
internal var storage: PropertyType = initializer

operator fun getValue(thisRef: NodeType, property: KProperty<*>): PropertyType {
return storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder
open class BinaryOperator :
Expression(), HasBase, HasOperatorCode, ArgumentHolder, HasType.TypeObserver {
/** The left-hand expression. */
@delegate:AST
var lhs: Expression by
AstProperty(
initializer = ProblemExpression("could not parse lhs"),
Expand All @@ -49,6 +50,7 @@ open class BinaryOperator :
)

/** The right-hand expression. */
@delegate:AST
var rhs: Expression by
AstProperty(
initializer = ProblemExpression("could not parse rhs"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package de.fraunhofer.aisec.cpg.helpers
import de.fraunhofer.aisec.cpg.ScopeManager
import de.fraunhofer.aisec.cpg.frontends.LanguageFrontend
import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.AstProperty
import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.declarations.RecordDeclaration
import de.fraunhofer.aisec.cpg.graph.edge.PropertyEdge
Expand Down Expand Up @@ -174,6 +175,9 @@ object SubgraphWalker {
is Collection<*> -> {
children.addAll(obj.filterIsInstance<Node>())
}
is AstProperty<*, *> -> {
children.add((obj as AstProperty<Node, *>).storage)
}
else -> {
throw AnnotationFormatError(
"Found @field:SubGraph(\"AST\") on field of type " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class ExpressionBuilderTest {

assertEquals(binOp, lit1.astParent)
assertEquals(binOp, lit2.astParent)

var children = binOp.astChildren
assertEquals(2, children.size)
}
}

Expand Down

0 comments on commit d80c204

Please sign in to comment.