diff --git a/cpg-core/src/main/java/de/fraunhofer/aisec/cpg/graph/ArgumentHolder.kt b/cpg-core/src/main/java/de/fraunhofer/aisec/cpg/graph/ArgumentHolder.kt index b2d512e70e..49001da796 100644 --- a/cpg-core/src/main/java/de/fraunhofer/aisec/cpg/graph/ArgumentHolder.kt +++ b/cpg-core/src/main/java/de/fraunhofer/aisec/cpg/graph/ArgumentHolder.kt @@ -44,8 +44,14 @@ interface ArgumentHolder : Holder { /** Adds the [expression] to the list of arguments. */ fun addArgument(expression: Expression) - /** Removes the [expression] from the list of arguments. */ - fun removeArgument(expression: Expression) {} + /** + * Removes the [expression] from the list of arguments. + * + * An indication whether this operation was successful needs to be returned. + */ + fun removeArgument(expression: Expression): Boolean { + return false + } /** * Replaces the existing argument specified in [old] with the one in [new]. Implementation how diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/HasInitializer.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/HasInitializer.kt index c878c9777c..1bcd1ef01b 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/HasInitializer.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/HasInitializer.kt @@ -31,7 +31,7 @@ import de.fraunhofer.aisec.cpg.graph.statements.expressions.Expression * Specifies that a certain node has an initializer. It is a special case of [ArgumentHolder], in * which the initializer is treated as the first (and only) argument. */ -interface HasInitializer : ArgumentHolder { +interface HasInitializer : HasType, ArgumentHolder, AssignmentHolder { var initializer: Expression? @@ -39,9 +39,12 @@ interface HasInitializer : ArgumentHolder { this.initializer = expression } - override fun removeArgument(expression: Expression) { - if (this.initializer == expression) { + override fun removeArgument(expression: Expression): Boolean { + return if (this.initializer == expression) { this.initializer = null + true + } else { + false } } @@ -49,4 +52,9 @@ interface HasInitializer : ArgumentHolder { this.initializer = new return true } + + override val assignments: List + get() { + return initializer?.let { listOf(Assignment(it, this, this)) } ?: listOf() + } } diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/VariableDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/VariableDeclaration.kt index 2be35cb30f..5a7b0a0734 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/VariableDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/VariableDeclaration.kt @@ -33,8 +33,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder import org.neo4j.ogm.annotation.Relationship /** Represents the declaration of a variable. */ -class VariableDeclaration : - ValueDeclaration(), HasType.TypeListener, HasInitializer, AssignmentHolder { +class VariableDeclaration : ValueDeclaration(), HasType.TypeListener, HasInitializer { /** * We need a way to store the templateParameters that a VariableDeclaration might have before @@ -129,11 +128,6 @@ class VariableDeclaration : .toString() } - override val assignments: List - get() { - return initializer?.let { listOf(Assignment(it, this, this)) } ?: listOf() - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ReturnStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ReturnStatement.kt index c74a845c10..26dfb191f7 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ReturnStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ReturnStatement.kt @@ -60,8 +60,9 @@ class ReturnStatement : Statement(), ArgumentHolder { this.returnValues += expression } - override fun removeArgument(expression: Expression) { + override fun removeArgument(expression: Expression): Boolean { this.returnValues -= expression + return true } override fun replaceArgument(old: Expression, new: Expression): Boolean { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/CallExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/CallExpression.kt index cb2d5ec97e..3f00e23cae 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/CallExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/CallExpression.kt @@ -148,8 +148,9 @@ open class CallExpression : Expression(), HasType.TypeListener, SecondaryTypeEdg return true } - override fun removeArgument(expression: Expression) { + override fun removeArgument(expression: Expression): Boolean { arguments -= expression + return true } /** Returns the function signature as list of types of the call arguments. */