Skip to content

Commit

Permalink
Renamed ResolutionStartHolder to EOGStartHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Oct 9, 2023
1 parent 2a38903 commit a25a96f
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ import de.fraunhofer.aisec.cpg.passes.SymbolResolver
*
* In some cases, the [Node] that implements this interface will add itself, for example in a
* [FunctionDeclaration], so that we can use all functions as an entry-point to symbol resolution.
* In other cases, certain child nodes might be added to [resolutionStartNodes], for example to add
* all top-level declarations in a [TranslationUnitDeclaration].
* In other cases, certain child nodes might be added to [eogStart], for example to add all
* top-level declarations in a [TranslationUnitDeclaration].
*
* The common denominator is that all the nodes contained in [resolutionStartNodes] **start** an EOG
* path, i.e,. they should have a valid [Node.nextEOG], but an empty [Node.prevEOG].
* The common denominator is that all the nodes contained in [eogStart] *start* an EOG path, i.e.,
* they should have a valid [Node.nextEOG], but an empty [Node.prevEOG].
*/
interface ResolutionStartHolder {
val resolutionStartNodes: List<Node>
interface EOGStartHolder {
val eogStart: List<Node>
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder
import org.neo4j.ogm.annotation.Relationship

/** Represents the declaration or definition of a function. */
open class FunctionDeclaration : ValueDeclaration(), DeclarationHolder, ResolutionStartHolder {
open class FunctionDeclaration : ValueDeclaration(), DeclarationHolder, EOGStartHolder {
/** The function body. Usually a [Block]. */
@AST var body: Statement? = null

Expand Down Expand Up @@ -227,7 +227,7 @@ open class FunctionDeclaration : ValueDeclaration(), DeclarationHolder, Resoluti
.toString()
}

override val resolutionStartNodes: List<Node>
override val eogStart: List<Node>
get() = listOfNotNull(this)

override fun equals(other: Any?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ import org.neo4j.ogm.annotation.Relationship
*
* The name property of this node need to be a FQN for property resolution.
*/
class NamespaceDeclaration :
Declaration(), DeclarationHolder, StatementHolder, ResolutionStartHolder {
class NamespaceDeclaration : Declaration(), DeclarationHolder, StatementHolder, EOGStartHolder {
/**
* Edges to nested namespaces, records, functions, fields etc. contained in the current
* namespace.
Expand Down Expand Up @@ -93,7 +92,7 @@ class NamespaceDeclaration :
override var statements: List<Statement> by
PropertyEdgeDelegate(NamespaceDeclaration::statementEdges)

override val resolutionStartNodes: List<Node>
override val eogStart: List<Node>
get() {
val list = mutableListOf<Node>()
// Add all top-level declarations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ import org.neo4j.ogm.annotation.Relationship
import org.neo4j.ogm.annotation.Transient

/** Represents a C++ union/struct/class or Java class */
open class RecordDeclaration :
Declaration(), DeclarationHolder, StatementHolder, ResolutionStartHolder {
open class RecordDeclaration : Declaration(), DeclarationHolder, StatementHolder, EOGStartHolder {
/** The kind, i.e. struct, class, union or enum. */
var kind: String? = null

Expand Down Expand Up @@ -173,7 +172,7 @@ open class RecordDeclaration :
.toString()
}

override val resolutionStartNodes: List<Node>
override val eogStart: List<Node>
get() {
val list = mutableListOf<Node>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import org.neo4j.ogm.annotation.Relationship

/** The top most declaration, representing a translation unit, for example a file. */
class TranslationUnitDeclaration :
Declaration(), DeclarationHolder, StatementHolder, PassTarget, ResolutionStartHolder {
Declaration(), DeclarationHolder, StatementHolder, PassTarget, EOGStartHolder {
/** A list of declarations within this unit. */
@Relationship(value = "DECLARATIONS", direction = Relationship.Direction.OUTGOING)
@AST
Expand Down Expand Up @@ -126,7 +126,7 @@ class TranslationUnitDeclaration :
.toString()
}

override val resolutionStartNodes: List<Node>
override val eogStart: List<Node>
get() {
val list = mutableListOf<Node>()
// Add all top-level declarations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ package de.fraunhofer.aisec.cpg.graph.statements

import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.BranchingNode
import de.fraunhofer.aisec.cpg.graph.EOGStartHolder
import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.ResolutionStartHolder
import de.fraunhofer.aisec.cpg.graph.declarations.VariableDeclaration
import de.fraunhofer.aisec.cpg.graph.statements.expressions.Block
import java.util.Objects

class CatchClause : Statement(), BranchingNode, ResolutionStartHolder {
class CatchClause : Statement(), BranchingNode, EOGStartHolder {
@AST var parameter: VariableDeclaration? = null

@AST var body: Block? = null

override val branchedBy: Node?
get() = parameter

override val resolutionStartNodes: List<Node>
override val eogStart: List<Node>
get() = listOf(this)

override fun equals(other: Any?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ package de.fraunhofer.aisec.cpg.passes
import de.fraunhofer.aisec.cpg.TranslationContext
import de.fraunhofer.aisec.cpg.frontends.HasShortCircuitOperators
import de.fraunhofer.aisec.cpg.frontends.ProcessedListener
import de.fraunhofer.aisec.cpg.graph.EOGStartHolder
import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.ResolutionStartHolder
import de.fraunhofer.aisec.cpg.graph.StatementHolder
import de.fraunhofer.aisec.cpg.graph.declarations.*
import de.fraunhofer.aisec.cpg.graph.edge.Properties
Expand Down Expand Up @@ -187,7 +187,7 @@ open class EvaluationOrderGraphPass(ctx: TranslationContext) : TranslationUnitPa
)
// only eog entry points
var validStarts =
eogNodes.filter { it is ResolutionStartHolder || it is VariableDeclaration }.toSet()
eogNodes.filter { it is EOGStartHolder || it is VariableDeclaration }.toSet()
// Remove all nodes from eogNodes which are reachable from validStarts and transitively.
val alreadySeen = IdentitySet<Node>()
while (validStarts.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ open class SymbolResolver(ctx: TranslationContext) : ComponentPass(ctx) {
for (tu in component.translationUnits) {
currentTU = tu
// gather all resolution start holders and their start nodes
val nodes =
tu.allChildren<ResolutionStartHolder>().flatMap { it.resolutionStartNodes }.toSet()
val nodes = tu.allChildren<EOGStartHolder>().flatMap { it.eogStart }.toSet()

for (node in nodes) {
walker.iterate(node)
Expand Down

0 comments on commit a25a96f

Please sign in to comment.