Skip to content

Commit

Permalink
Add interface
Browse files Browse the repository at this point in the history
  • Loading branch information
KuechA authored and oxisto committed Nov 24, 2023
1 parent a14211a commit 59d0ef1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2023, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $$$$$$\ $$$$$$$\ $$$$$$\
* $$ __$$\ $$ __$$\ $$ __$$\
* $$ / \__|$$ | $$ |$$ / \__|
* $$ | $$$$$$$ |$$ |$$$$\
* $$ | $$ ____/ $$ |\_$$ |
* $$ | $$\ $$ | $$ | $$ |
* \$$$$$ |$$ | \$$$$$ |
* \______/ \__| \______/
*
*/
package de.fraunhofer.aisec.cpg.graph

/**
* Some nodes have aliases, i.e., it potentially references another variable. This means that
* writing to this node, also writes to its [aliases] and vice-versa.
*/
interface HasAliases {
/** The aliases which this node has. */
var aliases: MutableSet<HasAliases>
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder
import org.neo4j.ogm.annotation.Relationship

/** A declaration who has a type. */
abstract class ValueDeclaration : Declaration(), HasType {
abstract class ValueDeclaration : Declaration(), HasType, HasAliases {
override val typeObservers: MutableSet<HasType.TypeObserver> = identitySetOf()

/** The type of this declaration. */
Expand All @@ -61,7 +61,7 @@ abstract class ValueDeclaration : Declaration(), HasType {
}
}

var aliases = mutableSetOf<Node>()
override var aliases = mutableSetOf<Declaration>()

override var assignedTypes: Set<Type> = mutableSetOf()
set(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package de.fraunhofer.aisec.cpg.graph.statements.expressions

import de.fraunhofer.aisec.cpg.PopulatedByPass
import de.fraunhofer.aisec.cpg.graph.AccessValues
import de.fraunhofer.aisec.cpg.graph.HasAliases
import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.declarations.Declaration
import de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration
Expand All @@ -45,7 +46,7 @@ import org.neo4j.ogm.annotation.Relationship
* expression `a = b`, which itself is an [AssignExpression], contains two [Reference]s, one for the
* variable `a` and one for variable `b`, which have been previously been declared.
*/
open class Reference : Expression(), HasType.TypeObserver {
open class Reference : Expression(), HasType.TypeObserver, HasAliases {
/**
* The [Declaration]s this expression might refer to. This will influence the [declaredType] of
* this expression.
Expand Down Expand Up @@ -73,7 +74,7 @@ open class Reference : Expression(), HasType.TypeObserver {
}
}

var aliases = mutableSetOf<Node>()
override var aliases = mutableSetOf<HasAliases>()

/**
* Is this reference used for writing data instead of just reading it? Determines dataflow
Expand Down

0 comments on commit 59d0ef1

Please sign in to comment.