Skip to content

Commit

Permalink
Made additionalNodes a mutable set on public interface (#1176)
Browse files Browse the repository at this point in the history
* Made `additionalNodes` a mutable list on public interface

Fixes #1175

* Apply suggestions from code review

Co-authored-by: KuechA <[email protected]>

* Address review comments

---------

Co-authored-by: KuechA <[email protected]>
  • Loading branch information
oxisto and KuechA committed May 22, 2023
1 parent 1080568 commit 6dd63d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ object SubgraphWalker {

/**
* Function returns two lists in a list. The first list contains all eog nodes with no
* predecesor in the subgraph with root 'n'. The second list contains eog edges that have no
* predecessor in the subgraph with root 'n'. The second list contains eog edges that have no
* successor in the subgraph with root 'n'. The first List marks the entry and the second marks
* the exit nodes of the cfg in this subgraph.
*
Expand All @@ -236,19 +236,18 @@ object SubgraphWalker {
val border = Border()
val flattedASTTree = flattenAST(n)
val eogNodes =
flattedASTTree
.stream()
.filter { node: Node -> node.prevEOG.isNotEmpty() || node.nextEOG.isNotEmpty() }
.collect(Collectors.toList())
flattedASTTree.filter { node: Node ->
node.prevEOG.isNotEmpty() || node.nextEOG.isNotEmpty()
}
// Nodes that are incoming edges, no other node
border.entries =
eogNodes.filter { node: Node ->
node.prevEOG.any { prev: Node -> !eogNodes.contains(prev) }
}
eogNodes
.filter { node: Node -> node.prevEOG.any { prev -> prev !in eogNodes } }
.toMutableList()
border.exits =
eogNodes.filter { node: Node ->
node.nextEOG.any { next: Node -> !eogNodes.contains(next) }
}
eogNodes
.filter { node: Node -> node.nextEOG.any { next -> next !in eogNodes } }
.toMutableList()
return border
}

Expand All @@ -272,8 +271,8 @@ object SubgraphWalker {
* EOG subgraph, EOG entries and exits in a CFG subgraph.
*/
class Border {
var entries: List<Node> = ArrayList()
var exits: List<Node> = ArrayList()
var entries = mutableListOf<Node>()
var exits = mutableListOf<Node>()
}

class IterativeGraphWalker {
Expand Down Expand Up @@ -381,10 +380,10 @@ object SubgraphWalker {
* Handles declaration scope monitoring for iterative traversals. If this is not required, use
* [IterativeGraphWalker] for less overhead.
*
* Declaration scopes are similar to [de.fraunhofer.aisec.cpg.passes.scopes.ScopeManager]
* scopes: [ValueDeclaration]s located inside a scope (i.e. are children of the scope root) are
* visible to any children of the scope root. Scopes can be layered, where declarations from
* parent scopes are visible to the children but not the other way around.
* Declaration scopes are similar to [de.fraunhofer.aisec.cpg.ScopeManager] scopes:
* [ValueDeclaration]s located inside a scope (i.e. are children of the scope root) are visible
* to any children of the scope root. Scopes can be layered, where declarations from parent
* scopes are visible to the children but not the other way around.
*/
class ScopedWalker {
// declarationScope -> (parentScope, declarations)
Expand Down Expand Up @@ -465,10 +464,10 @@ object SubgraphWalker {
if (
node is RecordDeclaration ||
node is CompoundStatement ||
node is FunctionDeclaration // can also be a translationunit for global (c)
// functions
||
node is TranslationUnitDeclaration
node is FunctionDeclaration ||
node is
TranslationUnitDeclaration // can also be a translation unit for global
// (C) functions
) {
parentBlock = node
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class TranslationResult(
/**
* A free-for-use collection of unique nodes. Nodes stored here will be exported to Neo4j, too.
*/
val additionalNodes: Set<Node> = HashSet()
val additionalNodes = mutableSetOf<Node>()
override val benchmarks: MutableSet<MeasurementHolder> = LinkedHashSet()

val isCancelled: Boolean
Expand Down

0 comments on commit 6dd63d2

Please sign in to comment.