Skip to content

Commit

Permalink
Addressed first batch of review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Mar 8, 2023
1 parent 83f3b65 commit 99aac98
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ interface ArgumentHolder : Holder<Expression> {
/** 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,30 @@ 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?

override fun addArgument(expression: Expression) {
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
}
}

override fun replaceArgument(old: Expression, new: Expression): Boolean {
this.initializer = new
return true
}

override val assignments: List<Assignment>
get() {
return initializer?.let { listOf(Assignment(it, this, this)) } ?: listOf()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -129,11 +128,6 @@ class VariableDeclaration :
.toString()
}

override val assignments: List<Assignment>
get() {
return initializer?.let { listOf(Assignment(it, this, this)) } ?: listOf()
}

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 99aac98

Please sign in to comment.