diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt index d608c7d3ed2..a50f6b7ad4b 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt @@ -430,7 +430,7 @@ class AstProperty( 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 diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/BinaryOperator.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/BinaryOperator.kt index 4f12c1ac75d..9274743e8c0 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/BinaryOperator.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/BinaryOperator.kt @@ -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"), @@ -49,6 +50,7 @@ open class BinaryOperator : ) /** The right-hand expression. */ + @delegate:AST var rhs: Expression by AstProperty( initializer = ProblemExpression("could not parse rhs"), diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/SubgraphWalker.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/SubgraphWalker.kt index 1dcbec6ac22..e3ab541afdf 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/SubgraphWalker.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/SubgraphWalker.kt @@ -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 @@ -174,6 +175,9 @@ object SubgraphWalker { is Collection<*> -> { children.addAll(obj.filterIsInstance()) } + is AstProperty<*, *> -> { + children.add((obj as AstProperty).storage) + } else -> { throw AnnotationFormatError( "Found @field:SubGraph(\"AST\") on field of type " + diff --git a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/graph/ExpressionBuilderTest.kt b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/graph/ExpressionBuilderTest.kt index d499096afb1..86ecb422b80 100644 --- a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/graph/ExpressionBuilderTest.kt +++ b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/graph/ExpressionBuilderTest.kt @@ -91,6 +91,9 @@ class ExpressionBuilderTest { assertEquals(binOp, lit1.astParent) assertEquals(binOp, lit2.astParent) + + var children = binOp.astChildren + assertEquals(2, children.size) } }