From a7bd3df4fca77fcf32346f18be1060d923a7084b Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Fri, 13 Dec 2024 23:21:35 +0100 Subject: [PATCH] Revert labels --- .../fraunhofer/aisec/cpg/TranslationResult.kt | 2 +- .../aisec/cpg/frontends/Language.kt | 2 +- .../fraunhofer/aisec/cpg/graph/Component.kt | 2 +- .../de/fraunhofer/aisec/cpg/graph/Node.kt | 2 +- .../declarations/EnumConstantDeclaration.kt | 3 +- .../cpg/graph/declarations/EnumDeclaration.kt | 2 +- .../graph/declarations/FunctionDeclaration.kt | 4 +-- .../FunctionTemplateDeclaration.kt | 2 +- .../graph/declarations/IncludeDeclaration.kt | 4 +-- .../graph/declarations/MethodDeclaration.kt | 3 +- .../declarations/NamespaceDeclaration.kt | 4 +-- .../declarations/ParameterDeclaration.kt | 2 +- .../graph/declarations/RecordDeclaration.kt | 12 ++++---- .../declarations/RecordTemplateDeclaration.kt | 2 +- .../graph/declarations/TemplateDeclaration.kt | 2 +- .../TranslationUnitDeclaration.kt | 8 ++--- .../graph/declarations/TupleDeclaration.kt | 8 ++--- .../declarations/TypeParameterDeclaration.kt | 2 +- .../graph/declarations/VariableDeclaration.kt | 3 +- .../aisec/cpg/graph/edges/ast/AstEdge.kt | 12 +++----- .../cpg/graph/edges/ast/TemplateArgument.kt | 8 ++--- .../cpg/graph/statements/AssertStatement.kt | 6 ++-- .../cpg/graph/statements/CaseStatement.kt | 2 +- .../aisec/cpg/graph/statements/CatchClause.kt | 5 ++-- .../graph/statements/DeclarationStatement.kt | 2 +- .../aisec/cpg/graph/statements/DoStatement.kt | 3 +- .../cpg/graph/statements/ForEachStatement.kt | 5 ++-- .../cpg/graph/statements/ForStatement.kt | 10 +++---- .../aisec/cpg/graph/statements/IfStatement.kt | 13 ++++---- .../cpg/graph/statements/LabelStatement.kt | 5 ++-- .../cpg/graph/statements/LoopStatement.kt | 5 ++-- .../cpg/graph/statements/ReturnStatement.kt | 3 +- .../aisec/cpg/graph/statements/Statement.kt | 2 +- .../cpg/graph/statements/SwitchStatement.kt | 10 +++---- .../graph/statements/SynchronizedStatement.kt | 5 ++-- .../cpg/graph/statements/ThrowExpression.kt | 5 ++-- .../cpg/graph/statements/TryStatement.kt | 13 ++++---- .../cpg/graph/statements/WhileStatement.kt | 5 ++-- .../expressions/AssignExpression.kt | 12 +++----- .../statements/expressions/BinaryOperator.kt | 2 -- .../cpg/graph/statements/expressions/Block.kt | 2 +- .../statements/expressions/CallExpression.kt | 9 +++--- .../statements/expressions/CastExpression.kt | 1 - .../expressions/CollectionComprehension.kt | 4 +-- .../expressions/ComprehensionExpression.kt | 8 ++--- .../expressions/ConditionalExpression.kt | 7 +---- .../expressions/ConstructExpression.kt | 3 +- .../expressions/DeleteExpression.kt | 2 +- .../statements/expressions/ExpressionList.kt | 2 +- .../expressions/InitializerListExpression.kt | 6 ++-- .../expressions/KeyValueExpression.kt | 6 ++-- .../expressions/LambdaExpression.kt | 6 +--- .../expressions/MemberExpression.kt | 1 - .../expressions/NewArrayExpression.kt | 5 ++-- .../statements/expressions/NewExpression.kt | 5 ++-- .../statements/expressions/RangeExpression.kt | 6 ++-- .../expressions/SubscriptExpression.kt | 6 +--- .../statements/expressions/UnaryOperator.kt | 1 - .../fraunhofer/aisec/cpg/persistence/Neo4J.kt | 30 +++++++++++++++++-- 59 files changed, 136 insertions(+), 176 deletions(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationResult.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationResult.kt index fb0e3907cf..05ace1a4dc 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationResult.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationResult.kt @@ -54,7 +54,7 @@ class TranslationResult( var finalCtx: TranslationContext, ) : Node(), StatisticsHolder { - @Relationship("COMPONENTS") val componentEdges = astEdgesOf(label = "COMPONENTS") + @Relationship("COMPONENTS") val componentEdges = astEdgesOf() /** * Entry points to the CPG: "SoftwareComponent" refer to programs, application, other "bundles" * of software. diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/Language.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/Language.kt index 9503ba8bc8..6192a7f130 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/Language.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/Language.kt @@ -323,7 +323,7 @@ abstract class Language> : Node() { // matches val source = result.source if (this is HasTemplates && source is CallExpression) { - source.templateArgumentEdges = TemplateArguments(source, label = "TEMPLATE_ARGUMENTS") + source.templateArgumentEdges = TemplateArguments(source) val (ok, candidates) = this.handleTemplateFunctionCalls( null, diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Component.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Component.kt index 73c9d1c47d..10f4edaf7d 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Component.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Component.kt @@ -43,7 +43,7 @@ import org.neo4j.ogm.annotation.Transient */ open class Component : Node() { @Relationship("TRANSLATION_UNITS") - val translationUnitEdges = astEdgesOf(label = "TRANSLATION_UNITS") + val translationUnitEdges = astEdgesOf() /** All translation units belonging to this application. */ val translationUnits by unwrapping(Component::translationUnitEdges) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Node.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Node.kt index d71400fbef..de06b9d2be 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Node.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Node.kt @@ -265,7 +265,7 @@ abstract class Node : var argumentIndex = 0 /** List of annotations associated with that node. */ - @Relationship("ANNOTATIONS") var annotationEdges = astEdgesOf(label = "ANNOTATIONS") + @Relationship("ANNOTATIONS") var annotationEdges = astEdgesOf() var annotations by unwrapping(Node::annotationEdges) /** diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/EnumConstantDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/EnumConstantDeclaration.kt index 7786e8fe23..4ef95234bc 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/EnumConstantDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/EnumConstantDeclaration.kt @@ -36,7 +36,6 @@ import org.neo4j.ogm.annotation.Relationship * explicit initializer value. */ class EnumConstantDeclaration : ValueDeclaration(), HasInitializer { - @Relationship("INITIALIZER") - var initializerEdge = astOptionalEdgeOf(label = "INITIALIZER") + @Relationship("INITIALIZER") var initializerEdge = astOptionalEdgeOf() override var initializer by unwrapping(EnumConstantDeclaration::initializerEdge) } diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/EnumDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/EnumDeclaration.kt index b881521531..c0e912c32f 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/EnumDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/EnumDeclaration.kt @@ -32,7 +32,7 @@ import org.neo4j.ogm.annotation.Relationship class EnumDeclaration : RecordDeclaration() { @Relationship(value = "ENTRIES", direction = Relationship.Direction.OUTGOING) - var entryEdges = astEdgesOf(label = "ENTRIES") + var entryEdges = astEdgesOf() var entries by unwrapping(EnumDeclaration::entryEdges) override fun toString(): String { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/FunctionDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/FunctionDeclaration.kt index 553b4f541f..d489bd4c8a 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/FunctionDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/FunctionDeclaration.kt @@ -41,13 +41,13 @@ import org.neo4j.ogm.annotation.Relationship /** Represents the declaration or definition of a function. */ open class FunctionDeclaration : ValueDeclaration(), DeclarationHolder, EOGStarterHolder { - @Relationship("BODY") var bodyEdge = astOptionalEdgeOf(label = "BODY") + @Relationship("BODY") var bodyEdge = astOptionalEdgeOf() /** The function body. Usualfly a [Block]. */ var body by unwrapping(FunctionDeclaration::bodyEdge) /** The list of function parameters. */ @Relationship(value = "PARAMETERS", direction = Relationship.Direction.OUTGOING) - var parameterEdges = astEdgesOf(label = "PARAMETERS") + var parameterEdges = astEdgesOf() /** Virtual property for accessing [parameterEdges] without property edges. */ var parameters by unwrapping(FunctionDeclaration::parameterEdges) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/FunctionTemplateDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/FunctionTemplateDeclaration.kt index 5c393d18fe..9b9bcdca32 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/FunctionTemplateDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/FunctionTemplateDeclaration.kt @@ -39,7 +39,7 @@ class FunctionTemplateDeclaration : TemplateDeclaration() { * expansion pass for each instantiation of the FunctionTemplate there will be a realization */ @Relationship(value = "REALIZATION", direction = Relationship.Direction.OUTGOING) - val realizationEdges = astEdgesOf(label = "REALIZATION") + val realizationEdges = astEdgesOf() val realization by unwrapping(FunctionTemplateDeclaration::realizationEdges) override val realizations: List diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/IncludeDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/IncludeDeclaration.kt index 994b51cbd8..da8e3edb14 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/IncludeDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/IncludeDeclaration.kt @@ -35,11 +35,11 @@ import org.neo4j.ogm.annotation.Relationship /** This declaration represents either an include or an import, depending on the language. */ class IncludeDeclaration : Declaration() { @Relationship(value = "INCLUDES", direction = Relationship.Direction.OUTGOING) - val includeEdges = astEdgesOf(label = "INCLUDES") + val includeEdges = astEdgesOf() val includes by unwrapping(IncludeDeclaration::includeEdges) @Relationship(value = "PROBLEMS", direction = Relationship.Direction.OUTGOING) - val problemEdges = astEdgesOf(label = "PROBLEMS") + val problemEdges = astEdgesOf() val problems by unwrapping(IncludeDeclaration::problemEdges) /** diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/MethodDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/MethodDeclaration.kt index 45525f33c1..422e69fcef 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/MethodDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/MethodDeclaration.kt @@ -43,8 +43,7 @@ open class MethodDeclaration : FunctionDeclaration() { */ open var recordDeclaration: RecordDeclaration? = null - @Relationship("RECEIVER") - var receiverEdge = astOptionalEdgeOf(label = "RECEIVER") + @Relationship("RECEIVER") var receiverEdge = astOptionalEdgeOf() /** * The receiver variable of this method. In most cases, this variable is called `this`, but in * some languages, it is `self` (e.g. in Rust or Python) or can be freely named (e.g. in diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/NamespaceDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/NamespaceDeclaration.kt index f90d845ed2..20bebae19d 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/NamespaceDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/NamespaceDeclaration.kt @@ -49,12 +49,12 @@ class NamespaceDeclaration : Declaration(), DeclarationHolder, StatementHolder, * Edges to nested namespaces, records, functions, fields etc. contained in the current * namespace. */ - val declarationEdges = astEdgesOf(label = "DECLARATIONS") + val declarationEdges = astEdgesOf() override val declarations by unwrapping(NamespaceDeclaration::declarationEdges) /** The list of statements. */ @Relationship(value = "STATEMENTS", direction = Relationship.Direction.OUTGOING) - override var statementEdges = astEdgesOf(label = "STATEMENTS") + override var statementEdges = astEdgesOf() /** * In some languages, there is a relationship between paths / directories and the package diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/ParameterDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/ParameterDeclaration.kt index 9b0fb81753..cd820498d0 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/ParameterDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/ParameterDeclaration.kt @@ -37,7 +37,7 @@ class ParameterDeclaration : ValueDeclaration(), HasDefault { var isVariadic = false @Relationship(value = "DEFAULT", direction = Relationship.Direction.OUTGOING) - var defaultValueEdge = astOptionalEdgeOf(label = "DEFAULT") + var defaultValueEdge = astOptionalEdgeOf() private var defaultValue by unwrapping(ParameterDeclaration::defaultValueEdge) var modifiers: List = mutableListOf() diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/RecordDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/RecordDeclaration.kt index b7cdeeb583..23440b37c2 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/RecordDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/RecordDeclaration.kt @@ -45,28 +45,28 @@ open class RecordDeclaration : var kind: String? = null @Relationship(value = "FIELDS", direction = Relationship.Direction.OUTGOING) - var fieldEdges = astEdgesOf(label = "FIELDS") + var fieldEdges = astEdgesOf() var fields by unwrapping(RecordDeclaration::fieldEdges) @Relationship(value = "METHODS", direction = Relationship.Direction.OUTGOING) - var methodEdges = astEdgesOf(label = "METHODS") + var methodEdges = astEdgesOf() var methods by unwrapping(RecordDeclaration::methodEdges) @Relationship(value = "CONSTRUCTORS", direction = Relationship.Direction.OUTGOING) - var constructorEdges = astEdgesOf(label = "CONSTRUCTORS") + var constructorEdges = astEdgesOf() var constructors by unwrapping(RecordDeclaration::constructorEdges) @Relationship(value = "RECORDS", direction = Relationship.Direction.OUTGOING) - var recordEdges = astEdgesOf(label = "RECORDS") + var recordEdges = astEdgesOf() var records by unwrapping(RecordDeclaration::recordEdges) @Relationship(value = "TEMPLATES", direction = Relationship.Direction.OUTGOING) - var templateEdges = astEdgesOf(label = "TEMPLATES") + var templateEdges = astEdgesOf() var templates by unwrapping(RecordDeclaration::templateEdges) /** The list of statements. */ @Relationship(value = "STATEMENTS", direction = Relationship.Direction.OUTGOING) - override var statementEdges = astEdgesOf(label = "STATEMENTS") + override var statementEdges = astEdgesOf() override var statements by unwrapping(RecordDeclaration::statementEdges) @Transient var superClasses: MutableList = ArrayList() diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/RecordTemplateDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/RecordTemplateDeclaration.kt index 028ef222e2..56e4b31645 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/RecordTemplateDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/RecordTemplateDeclaration.kt @@ -39,7 +39,7 @@ class RecordTemplateDeclaration : TemplateDeclaration() { * expansion pass for each instantiation of the ClassTemplate there will be a realization */ @Relationship(value = "REALIZATION", direction = Relationship.Direction.OUTGOING) - val realizationEdges = astEdgesOf(label = "REALIZATION") + val realizationEdges = astEdgesOf() override val realizations by unwrapping(RecordTemplateDeclaration::realizationEdges) override fun addDeclaration(declaration: Declaration) { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TemplateDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TemplateDeclaration.kt index d960b6e02c..f49c43fda3 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TemplateDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TemplateDeclaration.kt @@ -52,7 +52,7 @@ abstract class TemplateDeclaration : Declaration(), DeclarationHolder { /** Parameters the Template requires for instantiation */ @Relationship(value = "PARAMETERS", direction = Relationship.Direction.OUTGOING) - var parameterEdges = astEdgesOf(label = "PARAMETERS") + var parameterEdges = astEdgesOf() val parameters by unwrapping(TemplateDeclaration::parameterEdges) val parametersWithDefaults: List diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TranslationUnitDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TranslationUnitDeclaration.kt index df2611f2f8..4b479bcd36 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TranslationUnitDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TranslationUnitDeclaration.kt @@ -40,22 +40,22 @@ class TranslationUnitDeclaration : Declaration(), DeclarationHolder, StatementHolder, EOGStarterHolder { /** A list of declarations within this unit. */ @Relationship(value = "DECLARATIONS", direction = Relationship.Direction.OUTGOING) - val declarationEdges = astEdgesOf(label = "DECLARATIONS") + val declarationEdges = astEdgesOf() override val declarations by unwrapping(TranslationUnitDeclaration::declarationEdges) /** A list of includes within this unit. */ @Relationship(value = "INCLUDES", direction = Relationship.Direction.OUTGOING) - val includeEdges = astEdgesOf(label = "INCLUDES") + val includeEdges = astEdgesOf() val includes by unwrapping(TranslationUnitDeclaration::includeEdges) /** A list of namespaces within this unit. */ @Relationship(value = "NAMESPACES", direction = Relationship.Direction.OUTGOING) - val namespaceEdges = astEdgesOf(label = "NAMESPACES") + val namespaceEdges = astEdgesOf() val namespaces by unwrapping(TranslationUnitDeclaration::namespaceEdges) /** The list of statements. */ @Relationship(value = "STATEMENTS", direction = Relationship.Direction.OUTGOING) - override var statementEdges = astEdgesOf(label = "STATEMENTS") + override var statementEdges = astEdgesOf() override var statements by unwrapping(TranslationUnitDeclaration::statementEdges) override fun addDeclaration(declaration: Declaration) { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TupleDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TupleDeclaration.kt index 4f70b631e3..2755ad7a83 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TupleDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TupleDeclaration.kt @@ -64,11 +64,9 @@ import de.fraunhofer.aisec.cpg.graph.types.TupleType class TupleDeclaration : VariableDeclaration() { /** The list of elements in this tuple. */ var elementEdges = - astEdgesOf( - label = "ELEMENTS", - onAdd = { registerTypeObserver(it.end) }, - onRemove = { unregisterTypeObserver(it.end) } - ) + astEdgesOf(onAdd = { registerTypeObserver(it.end) }) { + unregisterTypeObserver(it.end) + } var elements by unwrapping(TupleDeclaration::elementEdges) override var name: Name diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TypeParameterDeclaration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TypeParameterDeclaration.kt index cd558339e9..2f061836a2 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TypeParameterDeclaration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TypeParameterDeclaration.kt @@ -35,7 +35,7 @@ import org.neo4j.ogm.annotation.Relationship /** A declaration of a type template parameter */ class TypeParameterDeclaration : ValueDeclaration(), HasDefault { @Relationship(value = "DEFAULT", direction = Relationship.Direction.OUTGOING) - var defaultEdge = astOptionalEdgeOf(label = "DEFAULT") + var defaultEdge = astOptionalEdgeOf() /** TemplateParameters can define a default for the type parameter. */ override var default by unwrapping(TypeParameterDeclaration::defaultEdge) 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 cbaa05e56d..ebf498fc1b 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 @@ -48,7 +48,7 @@ open class VariableDeclaration : ValueDeclaration(), HasInitializer, HasType.Typ * the [ConstructExpression] is created. */ @Relationship(value = "TEMPLATE_PARAMETERS", direction = Relationship.Direction.OUTGOING) - var templateParameterEdges = astEdgesOf(label = "TEMPLATE_PARAMETERS") + var templateParameterEdges = astEdgesOf() var templateParameters by unwrapping(VariableDeclaration::templateParameterEdges) /** Determines if this is a global variable. */ @@ -69,7 +69,6 @@ open class VariableDeclaration : ValueDeclaration(), HasInitializer, HasType.Typ @Relationship("INITIALIZER") var initializerEdge = astOptionalEdgeOf( - label = "INITIALIZER", onChanged = { old, new -> val value = new?.end exchangeTypeObserver(old, new) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/ast/AstEdge.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/ast/AstEdge.kt index 5e7d09dce9..5fba6f689a 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/ast/AstEdge.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/ast/AstEdge.kt @@ -42,11 +42,10 @@ open class AstEdge(start: Node, end: T, override var labels: Set Node.astEdgesOf( - label: String? = null, onAdd: ((AstEdge) -> Unit)? = null, onRemove: ((AstEdge) -> Unit)? = null, ): AstEdges> { - return AstEdges(thisRef = this, label = label, onAdd = onAdd, onRemove = onRemove) + return AstEdges(thisRef = this, onAdd = onAdd, onRemove = onRemove) } /** @@ -54,12 +53,11 @@ fun Node.astEdgesOf( * container). */ fun Node.astOptionalEdgeOf( - label: String? = null, onChanged: ((old: AstEdge?, new: AstEdge?) -> Unit)? = null ): EdgeSingletonList> { return EdgeSingletonList( thisRef = this, - init = { start, end -> AstEdge(start, end, labels = setOfNotNull(label, "AST")) }, + init = { start, end -> AstEdge(start, end) }, outgoing = true, onChanged = onChanged, of = null @@ -71,12 +69,11 @@ fun Node.astOptionalEdgeOf( */ fun Node.astEdgeOf( of: NodeType, - label: String? = null, onChanged: ((old: AstEdge?, new: AstEdge?) -> Unit)? = null, ): EdgeSingletonList> { return EdgeSingletonList( thisRef = this, - init = { start, end -> AstEdge(start, end, labels = setOfNotNull(label, "AST")) }, + init = { start, end -> AstEdge(start, end) }, outgoing = true, onChanged = onChanged, of = of @@ -86,12 +83,11 @@ fun Node.astEdgeOf( /** This property edge list describes elements that are AST children of a node. */ open class AstEdges>( thisRef: Node, - label: String? = null, onAdd: ((PropertyEdgeType) -> Unit)? = null, onRemove: ((PropertyEdgeType) -> Unit)? = null, @Suppress("UNCHECKED_CAST") init: (start: Node, end: NodeType) -> PropertyEdgeType = { start, end -> - AstEdge(start, end, labels = setOfNotNull(label, "AST")) as PropertyEdgeType + AstEdge(start, end) as PropertyEdgeType }, ) : EdgeList( diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/ast/TemplateArgument.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/ast/TemplateArgument.kt index 46374d959c..9e4518158a 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/ast/TemplateArgument.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/ast/TemplateArgument.kt @@ -33,14 +33,12 @@ import de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression class TemplateArgument( start: Node, end: NodeType, - label: String, var instantiation: TemplateInitialization? = TemplateInitialization.EXPLICIT, -) : AstEdge(start, end, setOf(label, "AST")) +) : AstEdge(start, end) /** A container for [TemplateArgument] edges. */ -class TemplateArguments(thisRef: Node, label: String) : +class TemplateArguments(thisRef: Node) : AstEdges>( thisRef, - label, - init = { start, end -> TemplateArgument(start, end, label = label) } + init = { start, end -> TemplateArgument(start, end) } ) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/AssertStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/AssertStatement.kt index 2974aa0617..bc9910b429 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/AssertStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/AssertStatement.kt @@ -33,13 +33,11 @@ import org.neo4j.ogm.annotation.Relationship /** Represents an assert statement */ class AssertStatement : Statement() { - @Relationship(value = "CONDITION") - var conditionEdge = astOptionalEdgeOf(label = "CONDITION") + @Relationship(value = "CONDITION") var conditionEdge = astOptionalEdgeOf() /** The condition to be evaluated. */ var condition by unwrapping(AssertStatement::conditionEdge) - @Relationship(value = "MESSAGE") - var messageEdge = astOptionalEdgeOf(label = "MESSAGE") + @Relationship(value = "MESSAGE") var messageEdge = astOptionalEdgeOf() /** The *optional* message that is shown, if the assert is evaluated as true */ var message by unwrapping(AssertStatement::messageEdge) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/CaseStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/CaseStatement.kt index 1c65983ddb..e0dfe6f36f 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/CaseStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/CaseStatement.kt @@ -39,7 +39,7 @@ import org.neo4j.ogm.annotation.Relationship */ class CaseStatement : Statement() { @Relationship(value = "CASE_EXPRESSION") - var caseExpressionEdge = astOptionalEdgeOf(label = "CASE_EXPRESSION") + var caseExpressionEdge = astOptionalEdgeOf() /** * Primitive side effect free statement that has to match with the evaluated selector in diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/CatchClause.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/CatchClause.kt index ba52c16d69..7e93010f70 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/CatchClause.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/CatchClause.kt @@ -37,12 +37,11 @@ import java.util.Objects import org.neo4j.ogm.annotation.Relationship class CatchClause : Statement(), BranchingNode, EOGStarterHolder { - @Relationship(value = "PARAMETER") - var parameterEdge = astOptionalEdgeOf(label = "PARAMETER") + @Relationship(value = "PARAMETER") var parameterEdge = astOptionalEdgeOf() var parameter by unwrapping(CatchClause::parameterEdge) - @Relationship(value = "BODY") var bodyEdge = astOptionalEdgeOf(label = "BODY") + @Relationship(value = "BODY") var bodyEdge = astOptionalEdgeOf() var body by unwrapping(CatchClause::bodyEdge) @DoNotPersist diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/DeclarationStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/DeclarationStatement.kt index dd16600207..31285ccc59 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/DeclarationStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/DeclarationStatement.kt @@ -45,7 +45,7 @@ open class DeclarationStatement : Statement() { * it only contains a single [Declaration]. */ @Relationship(value = "DECLARATIONS", direction = Relationship.Direction.OUTGOING) - var declarationEdges = astEdgesOf(label = "DECLARATIONS") + var declarationEdges = astEdgesOf() override var declarations by unwrapping(DeclarationStatement::declarationEdges) var singleDeclaration: Declaration? diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/DoStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/DoStatement.kt index 24711e2e2e..256546f551 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/DoStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/DoStatement.kt @@ -39,8 +39,7 @@ import org.neo4j.ogm.annotation.Relationship * a [Block], is executed and re-executed if the [condition] evaluates to true. */ class DoStatement : LoopStatement(), ArgumentHolder { - @Relationship("CONDITION") - var conditionEdge = astOptionalEdgeOf(label = "CONDITION") + @Relationship("CONDITION") var conditionEdge = astOptionalEdgeOf() /** * The loop condition that is evaluated after the loop statement and may trigger reevaluation. */ diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ForEachStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ForEachStatement.kt index 2f6b9d3f6f..ed47af14a6 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ForEachStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ForEachStatement.kt @@ -45,7 +45,6 @@ class ForEachStatement : LoopStatement(), BranchingNode, StatementHolder { @Relationship("VARIABLE") var variableEdge = astOptionalEdgeOf( - label = "VARIABLE", onChanged = { _, new -> val end = new?.end if (end is Reference) { @@ -60,7 +59,7 @@ class ForEachStatement : LoopStatement(), BranchingNode, StatementHolder { */ var variable by unwrapping(ForEachStatement::variableEdge) - @Relationship("ITERABLE") var iterableEdge = astOptionalEdgeOf(label = "ITERABLE") + @Relationship("ITERABLE") var iterableEdge = astOptionalEdgeOf() /** This field contains the iteration subject of the loop. */ var iterable by unwrapping(ForEachStatement::iterableEdge) @@ -69,7 +68,7 @@ class ForEachStatement : LoopStatement(), BranchingNode, StatementHolder { override var statementEdges: AstEdges> get() { - val statements = astEdgesOf(label = "STATEMENTS") + val statements = astEdgesOf() statements += variableEdge statements += iterableEdge statements += statementEdge diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ForStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ForStatement.kt index 4e59de9266..482c7a32c7 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ForStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ForStatement.kt @@ -42,19 +42,17 @@ import org.neo4j.ogm.annotation.Relationship class ForStatement : LoopStatement(), BranchingNode { @Relationship("INITIALIZER_STATEMENT") - var initializerStatementEdge = astOptionalEdgeOf(label = "INITIALIZER_STATEMENT") + var initializerStatementEdge = astOptionalEdgeOf() var initializerStatement by unwrapping(ForStatement::initializerStatementEdge) @Relationship("CONDITION_DECLARATION") - var conditionDeclarationEdge = astOptionalEdgeOf(label = "CONDITION_DECLARATION") + var conditionDeclarationEdge = astOptionalEdgeOf() var conditionDeclaration by unwrapping(ForStatement::conditionDeclarationEdge) - @Relationship("CONDITION") - var conditionEdge = astOptionalEdgeOf(label = "CONDITION") + @Relationship("CONDITION") var conditionEdge = astOptionalEdgeOf() var condition by unwrapping(ForStatement::conditionEdge) - @Relationship("ITERATION_STATEMENT") - var iterationStatementEdge = astOptionalEdgeOf(label = "ITERATION_STATEMENT") + @Relationship("ITERATION_STATEMENT") var iterationStatementEdge = astOptionalEdgeOf() var iterationStatement by unwrapping(ForStatement::iterationStatementEdge) override val branchedBy: Node? diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/IfStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/IfStatement.kt index dfdc2f9d05..346d78b533 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/IfStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/IfStatement.kt @@ -40,17 +40,16 @@ import org.neo4j.ogm.annotation.Relationship /** Represents a condition control flow statement, usually indicating by `If`. */ class IfStatement : Statement(), BranchingNode, ArgumentHolder { @Relationship(value = "INITIALIZER_STATEMENT") - var initializerStatementEdge = astOptionalEdgeOf(label = "INITIALIZER_STATEMENT") + var initializerStatementEdge = astOptionalEdgeOf() /** C++ initializer statement. */ var initializerStatement by unwrapping(IfStatement::initializerStatementEdge) @Relationship(value = "CONDITION_DECLARATION") - var conditionDeclarationEdge = astOptionalEdgeOf(label = "CONDITION_DECLARATION") + var conditionDeclarationEdge = astOptionalEdgeOf() /** C++ alternative to the condition. */ var conditionDeclaration by unwrapping(IfStatement::conditionDeclarationEdge) - @Relationship(value = "CONDITION") - var conditionEdge = astOptionalEdgeOf(label = "CONDITION") + @Relationship(value = "CONDITION") var conditionEdge = astOptionalEdgeOf() /** The condition to be evaluated. */ var condition by unwrapping(IfStatement::conditionEdge) @@ -60,13 +59,11 @@ class IfStatement : Statement(), BranchingNode, ArgumentHolder { /** C++ constexpr construct. */ var isConstExpression = false - @Relationship(value = "THEN_STATEMENT") - var thenStatementEdge = astOptionalEdgeOf(label = "THEN_STATEMENT") + @Relationship(value = "THEN_STATEMENT") var thenStatementEdge = astOptionalEdgeOf() /** The statement that is executed, if the condition is evaluated as true. Usually a [Block]. */ var thenStatement by unwrapping(IfStatement::thenStatementEdge) - @Relationship(value = "ELSE_STATEMENT") - var elseStatementEdge = astOptionalEdgeOf(label = "ELSE_STATEMENT") + @Relationship(value = "ELSE_STATEMENT") var elseStatementEdge = astOptionalEdgeOf() /** * The statement that is executed, if the condition is evaluated as false. Usually a [Block]. */ diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/LabelStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/LabelStatement.kt index 0eff2e9b7a..88eddde61c 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/LabelStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/LabelStatement.kt @@ -40,8 +40,7 @@ import org.neo4j.ogm.annotation.Relationship * breaks (Java) or goto(C++). */ class LabelStatement : Statement(), StatementHolder { - @Relationship(value = "SUB_STATEMENT") - var subStatementEdge = astOptionalEdgeOf(label = "SUB_STATEMENT") + @Relationship(value = "SUB_STATEMENT") var subStatementEdge = astOptionalEdgeOf() /** Statement that the label is attached to. Can be a simple or compound statement. */ var subStatement by unwrapping(LabelStatement::subStatementEdge) @@ -59,7 +58,7 @@ class LabelStatement : Statement(), StatementHolder { override var statementEdges: AstEdges> get() { - var list = astEdgesOf(label = "STATEMENTS") + var list = astEdgesOf() subStatement?.let { list.resetTo(listOf(it)) } return list } diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/LoopStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/LoopStatement.kt index 13b551faeb..5db8239930 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/LoopStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/LoopStatement.kt @@ -43,7 +43,7 @@ import org.neo4j.ogm.annotation.Relationship */ abstract class LoopStatement : Statement() { - @Relationship("STATEMENT") var statementEdge = astOptionalEdgeOf(label = "STATEMENT") + @Relationship("STATEMENT") var statementEdge = astOptionalEdgeOf() /** This field contains the body of the loop, e.g. a [Block] or single [Statement]. */ var statement by unwrapping(LoopStatement::statementEdge) @@ -54,8 +54,7 @@ abstract class LoopStatement : Statement() { * `else`-Statement at loop level. E.g. in Python the [elseStatement] is executed when the loop * was not left through a break. */ - @Relationship(value = "ELSE_STATEMENT") - var elseStatementEdge = astOptionalEdgeOf(label = "ELSE_STATEMENT") + @Relationship(value = "ELSE_STATEMENT") var elseStatementEdge = astOptionalEdgeOf() var elseStatement by unwrapping(LoopStatement::elseStatementEdge) override fun toString() = 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 f5ba10c00e..420db4def0 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 @@ -35,8 +35,7 @@ import org.neo4j.ogm.annotation.Relationship /** Represents a statement that returns out of the current function. */ class ReturnStatement : Statement(), ArgumentHolder { - @Relationship(value = "RETURN_VALUES") - var returnValueEdges = astEdgesOf(label = "RETURN_VALUES") + @Relationship(value = "RETURN_VALUES") var returnValueEdges = astEdgesOf() /** The expression whose value will be returned. */ var returnValues by unwrapping(ReturnStatement::returnValueEdges) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/Statement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/Statement.kt index 129c3ddb2d..f006d9c132 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/Statement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/Statement.kt @@ -52,7 +52,7 @@ abstract class Statement : Node(), DeclarationHolder { * TODO: This is actually an AST node just for a subset of nodes, i.e. initializers in for-loops */ @Relationship(value = "LOCALS", direction = Relationship.Direction.OUTGOING) - var localEdges = astEdgesOf(label = "LOCALS") + var localEdges = astEdgesOf() /** Virtual property to access [localEdges] without property edges. */ var locals by unwrapping(Statement::localEdges) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/SwitchStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/SwitchStatement.kt index 3277d36cb1..9d955a5057 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/SwitchStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/SwitchStatement.kt @@ -40,23 +40,21 @@ import org.neo4j.ogm.annotation.Relationship * handled properly. */ class SwitchStatement : Statement(), BranchingNode { - @Relationship(value = "SELECTOR") - var selectorEdge = astOptionalEdgeOf(label = "SELECTOR") + @Relationship(value = "SELECTOR") var selectorEdge = astOptionalEdgeOf() /** Selector that determines the case/default statement of the subsequent execution */ var selector by unwrapping(SwitchStatement::selectorEdge) @Relationship(value = "INITIALIZER_STATEMENT") - var initializerStatementEdge = astOptionalEdgeOf(label = "INITIALIZER_STATEMENT") + var initializerStatementEdge = astOptionalEdgeOf() /** C++ can have an initializer statement in a switch */ var initializerStatement by unwrapping(SwitchStatement::initializerStatementEdge) @Relationship(value = "SELECTOR_DECLARATION") - var selectorDeclarationEdge = astOptionalEdgeOf(label = "SELECTOR_DECLARATION") + var selectorDeclarationEdge = astOptionalEdgeOf() /** C++ allows to use a declaration instead of an expression as selector */ var selectorDeclaration by unwrapping(SwitchStatement::selectorDeclarationEdge) - @Relationship(value = "STATEMENT") - var statementEdge = astOptionalEdgeOf(label = "STATEMENT") + @Relationship(value = "STATEMENT") var statementEdge = astOptionalEdgeOf() /** * The compound statement that contains break/default statements with regular statements on the * same hierarchy diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/SynchronizedStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/SynchronizedStatement.kt index 0608e51155..ac955b24ce 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/SynchronizedStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/SynchronizedStatement.kt @@ -33,11 +33,10 @@ import java.util.Objects import org.neo4j.ogm.annotation.Relationship class SynchronizedStatement : Statement() { - @Relationship(value = "EXPRESSION") - var expressionEdge = astOptionalEdgeOf(label = "EXPRESSION") + @Relationship(value = "EXPRESSION") var expressionEdge = astOptionalEdgeOf() var expression by unwrapping(SynchronizedStatement::expressionEdge) - @Relationship(value = "BLOCK") var blockEdge = astOptionalEdgeOf(label = "BLOCK") + @Relationship(value = "BLOCK") var blockEdge = astOptionalEdgeOf() var block by unwrapping(SynchronizedStatement::blockEdge) override fun equals(other: Any?): Boolean { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ThrowExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ThrowExpression.kt index 59d245f79b..0f8b86cb32 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ThrowExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/ThrowExpression.kt @@ -37,8 +37,7 @@ import org.neo4j.ogm.annotation.Relationship class ThrowExpression : Expression(), ArgumentHolder { /** The exception object to be raised. */ - @Relationship(value = "EXCEPTION") - var exceptionEdge = astOptionalEdgeOf(label = "EXCEPTION") + @Relationship(value = "EXCEPTION") var exceptionEdge = astOptionalEdgeOf() var exception by unwrapping(ThrowExpression::exceptionEdge) /** @@ -46,7 +45,7 @@ class ThrowExpression : Expression(), ArgumentHolder { * was raised while handling another exception. */ @Relationship(value = "PARENT_EXCEPTION") - var parentExceptionEdge = astOptionalEdgeOf(label = "PARENT_EXCEPTION") + var parentExceptionEdge = astOptionalEdgeOf() var parentException by unwrapping(ThrowExpression::parentExceptionEdge) override fun addArgument(expression: Expression) { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/TryStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/TryStatement.kt index cd96ca44d3..1f887fa207 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/TryStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/TryStatement.kt @@ -42,15 +42,14 @@ class TryStatement : Statement() { * enter the [tryBlock]. */ @Relationship(value = "RESOURCES", direction = Relationship.Direction.OUTGOING) - var resourceEdges = astEdgesOf(label = "RESOURCES") + var resourceEdges = astEdgesOf() var resources by unwrapping(TryStatement::resourceEdges) /** * This represents a block whose statements can throw exceptions which are handled by the * [catchClauses]. */ - @Relationship(value = "TRY_BLOCK") - var tryBlockEdge = astOptionalEdgeOf(label = "TRY_BLOCK") + @Relationship(value = "TRY_BLOCK") var tryBlockEdge = astOptionalEdgeOf() var tryBlock by unwrapping(TryStatement::tryBlockEdge) /** @@ -58,8 +57,7 @@ class TryStatement : Statement() { * exceptions. Note that any exception thrown in this block is no longer caught by the * [catchClauses]. */ - @Relationship(value = "ELSE_BLOCK") - var elseBlockEdge = astOptionalEdgeOf(label = "ELSE_BLOCK") + @Relationship(value = "ELSE_BLOCK") var elseBlockEdge = astOptionalEdgeOf() var elseBlock by unwrapping(TryStatement::elseBlockEdge) /** @@ -67,8 +65,7 @@ class TryStatement : Statement() { * or one of the [catchClauses]. Note that any exception thrown in this block is no longer * caught by the [catchClauses]. */ - @Relationship(value = "FINALLY_BLOCK") - var finallyBlockEdge = astOptionalEdgeOf(label = "FINALLY_BLOCK") + @Relationship(value = "FINALLY_BLOCK") var finallyBlockEdge = astOptionalEdgeOf() var finallyBlock by unwrapping(TryStatement::finallyBlockEdge) /** @@ -77,7 +74,7 @@ class TryStatement : Statement() { * exists. */ @Relationship(value = "CATCH_CLAUSES", direction = Relationship.Direction.OUTGOING) - var catchClauseEdges = astEdgesOf(label = "CATCH_CLAUSES") + var catchClauseEdges = astEdgesOf() var catchClauses by unwrapping(TryStatement::catchClauseEdges) override fun equals(other: Any?): Boolean { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/WhileStatement.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/WhileStatement.kt index ffb9d38cc6..5c3bfb69b4 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/WhileStatement.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/WhileStatement.kt @@ -42,12 +42,11 @@ import org.neo4j.ogm.annotation.Relationship */ class WhileStatement : LoopStatement(), BranchingNode, ArgumentHolder { @Relationship(value = "CONDITION_DECLARATION") - var conditionDeclarationEdge = astOptionalEdgeOf(label = "CONDITION_DECLARATION") + var conditionDeclarationEdge = astOptionalEdgeOf() /** C++ allows defining a declaration instead of a pure logical expression as condition */ var conditionDeclaration by unwrapping(WhileStatement::conditionDeclarationEdge) - @Relationship(value = "CONDITION") - var conditionEdge = astOptionalEdgeOf(label = "CONDITION") + @Relationship(value = "CONDITION") var conditionEdge = astOptionalEdgeOf() /** The condition that decides if the block is executed. */ var condition by unwrapping(WhileStatement::conditionEdge) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/AssignExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/AssignExpression.kt index c1f335c565..89ae115c2a 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/AssignExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/AssignExpression.kt @@ -63,7 +63,6 @@ class AssignExpression : @Relationship("LHS") var lhsEdges = astEdgesOf( - label = "LHS", onAdd = { var end = it.end var base = (end as? MemberExpression)?.base as? MemberExpression @@ -84,11 +83,9 @@ class AssignExpression : @Relationship("RHS") /** The expressions on the right-hand side. */ var rhsEdges = - astEdgesOf( - label = "RHS", - onAdd = { it.end.registerTypeObserver(this) }, - onRemove = { it.end.unregisterTypeObserver(this) } - ) + astEdgesOf(onAdd = { it.end.registerTypeObserver(this) }) { + it.end.unregisterTypeObserver(this) + } var rhs by unwrapping(AssignExpression::rhsEdges) /** @@ -126,8 +123,7 @@ class AssignExpression : return operatorCode in (language?.simpleAssignmentOperators ?: setOf()) } - @Relationship("DECLARATIONS") - var declarationEdges = astEdgesOf(label = "DECLARATIONS") + @Relationship("DECLARATIONS") var declarationEdges = astEdgesOf() /** * Some languages, such as Go explicitly allow the definition / declaration of variables in the * assignment (known as a "short assignment"). Some languages, such as Python even implicitly diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/BinaryOperator.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/BinaryOperator.kt index 63e1ccec0d..06cce9f422 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/BinaryOperator.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/BinaryOperator.kt @@ -50,7 +50,6 @@ open class BinaryOperator : var lhsEdge = astEdgeOf( of = ProblemExpression("could not parse lhs"), - label = "LHS", onChanged = ::exchangeTypeObserver ) var lhs by unwrapping(BinaryOperator::lhsEdge) @@ -60,7 +59,6 @@ open class BinaryOperator : var rhsEdge = astEdgeOf( of = ProblemExpression("could not parse rhs"), - label = "RHS", onChanged = ::exchangeTypeObserver ) var rhs by unwrapping(BinaryOperator::rhsEdge) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Block.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Block.kt index 16ad6ad0f3..0677c75087 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Block.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Block.kt @@ -42,7 +42,7 @@ import org.neo4j.ogm.annotation.Relationship open class Block : Expression(), StatementHolder { /** The list of statements. */ @Relationship(value = "STATEMENTS", direction = Relationship.Direction.OUTGOING) - override var statementEdges = astEdgesOf(label = "STATEMENTS") + override var statementEdges = astEdgesOf() override var statements by unwrapping(Block::statementEdges) /** * This variable helps to differentiate between static and non-static initializer blocks. Static 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 e33affe188..221d686432 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 @@ -65,7 +65,7 @@ open class CallExpression : /** The list of arguments of this call expression, backed by a list of [Edge] objects. */ @Relationship(value = "ARGUMENTS", direction = Relationship.Direction.OUTGOING) - var argumentEdges = astEdgesOf(label = "ARGUMENTS") + var argumentEdges = astEdgesOf() /** * The list of arguments as a simple list. This is a delegated property delegated to @@ -85,8 +85,7 @@ open class CallExpression : * is intentionally left empty. It is not filled by the [SymbolResolver]. */ @Relationship(value = "CALLEE", direction = Relationship.Direction.OUTGOING) - private var calleeEdge = - astEdgeOf(ProblemExpression("could not parse callee"), label = "CALLEE") + private var calleeEdge = astEdgeOf(ProblemExpression("could not parse callee")) var callee by unwrapping(CallExpression::calleeEdge) @@ -186,7 +185,7 @@ open class CallExpression : ) { if (templateParam is Expression || templateParam is Type) { if (templateArgumentEdges == null) { - templateArgumentEdges = TemplateArguments(this, label = "TEMPLATE_ARGUMENTS") + templateArgumentEdges = TemplateArguments(this) } templateArgumentEdges?.add(templateParam) { instantiation = templateInitialization } @@ -199,7 +198,7 @@ open class CallExpression : orderedInitializationSignature: List ) { if (templateArgumentEdges == null) { - templateArgumentEdges = TemplateArguments(this, label = "TEMPLATE_ARGUMENTS") + templateArgumentEdges = TemplateArguments(this) } for (edge in templateArgumentEdges ?: listOf()) { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/CastExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/CastExpression.kt index 19f9f54ece..541cf38a25 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/CastExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/CastExpression.kt @@ -48,7 +48,6 @@ class CastExpression : Expression(), ArgumentHolder, HasType.TypeObserver { var expressionEdge = astEdgeOf( of = ProblemExpression("could not parse inner expression"), - label = "EXPRESSION", onChanged = ::exchangeTypeObserver ) var expression by unwrapping(CastExpression::expressionEdge) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/CollectionComprehension.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/CollectionComprehension.kt index d75a716c2f..2e99cb4dea 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/CollectionComprehension.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/CollectionComprehension.kt @@ -46,8 +46,7 @@ import org.neo4j.ogm.annotation.Relationship class CollectionComprehension : Expression(), ArgumentHolder { @Relationship("COMPREHENSION_EXPRESSIONS") - var comprehensionExpressionEdges = - astEdgesOf(label = "COMPREHENSION_EXPRESSIONS") + var comprehensionExpressionEdges = astEdgesOf() /** * This field contains one or multiple [ComprehensionExpression]s. * @@ -62,7 +61,6 @@ class CollectionComprehension : Expression(), ArgumentHolder { var statementEdge = astEdgeOf( ProblemExpression("No statement provided but is required in ${this::class}"), - label = "STATEMENT", ) /** * This field contains the statement which is applied to each element of the input for which the diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ComprehensionExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ComprehensionExpression.kt index 4b8f87158d..aeb24c0bf2 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ComprehensionExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ComprehensionExpression.kt @@ -41,7 +41,6 @@ class ComprehensionExpression : Expression(), ArgumentHolder { var variableEdge = astEdgeOf( of = ProblemExpression("Missing variableEdge in ${this::class}"), - label = "VARIABLE", onChanged = { _, new -> val end = new?.end if (end is Reference) { @@ -58,15 +57,12 @@ class ComprehensionExpression : Expression(), ArgumentHolder { @Relationship("ITERABLE") var iterableEdge = - astEdgeOf( - ProblemExpression("Missing iterable in ${this::class}"), - label = "ITERABLE" - ) + astEdgeOf(ProblemExpression("Missing iterable in ${this::class}")) /** This field contains the iteration subject of the loop. */ var iterable by unwrapping(ComprehensionExpression::iterableEdge) - @Relationship("PREDICATE") var predicateEdge = astOptionalEdgeOf(label = "PREDICATE") + @Relationship("PREDICATE") var predicateEdge = astOptionalEdgeOf() /** * This field contains the predicate which has to hold to evaluate `statement(variable)` and diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ConditionalExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ConditionalExpression.kt index bc8b0a85e8..977c85d8ed 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ConditionalExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ConditionalExpression.kt @@ -43,16 +43,12 @@ import org.neo4j.ogm.annotation.Relationship class ConditionalExpression : Expression(), ArgumentHolder, BranchingNode, HasType.TypeObserver { @Relationship("CONDITION") var conditionEdge = - astEdgeOf( - ProblemExpression("could not parse condition expression"), - label = "CONDITION" - ) + astEdgeOf(ProblemExpression("could not parse condition expression")) var condition by unwrapping(ConditionalExpression::conditionEdge) @Relationship("THEN_EXPRESSION") var thenExpressionEdge = astOptionalEdgeOf( - label = "THEN_EXPRESSION", onChanged = { old, new -> old?.end?.unregisterTypeObserver(this) new?.end?.registerTypeObserver(this) @@ -63,7 +59,6 @@ class ConditionalExpression : Expression(), ArgumentHolder, BranchingNode, HasTy @Relationship("ELSE_EXPRESSION") var elseExpressionEdge = astOptionalEdgeOf( - label = "ELSE_EXPRESSION", onChanged = { old, new -> old?.end?.unregisterTypeObserver(this) new?.end?.registerTypeObserver(this) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ConstructExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ConstructExpression.kt index c9f3d3535a..c6c81d51ae 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ConstructExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ConstructExpression.kt @@ -65,8 +65,7 @@ class ConstructExpression : CallExpression() { } } - @Relationship("ANONYMOUS_CLASS") - var anonymousClassEdge = astOptionalEdgeOf(label = "ANONYMOUS_CLASS") + @Relationship("ANONYMOUS_CLASS") var anonymousClassEdge = astOptionalEdgeOf() var anonymousClass by unwrapping(ConstructExpression::anonymousClassEdge) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/DeleteExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/DeleteExpression.kt index 2e96939395..dfa39b08f2 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/DeleteExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/DeleteExpression.kt @@ -31,7 +31,7 @@ import java.util.Objects import org.neo4j.ogm.annotation.Relationship class DeleteExpression : Expression() { - @Relationship("OPERANDS") var operandEdges = astEdgesOf(label = "OPERANDS") + @Relationship("OPERANDS") var operandEdges = astEdgesOf() var operands by unwrapping(DeleteExpression::operandEdges) override fun equals(other: Any?): Boolean { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ExpressionList.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ExpressionList.kt index be7e87711d..f349cc7a33 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ExpressionList.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/ExpressionList.kt @@ -34,7 +34,7 @@ import org.neo4j.ogm.annotation.Relationship class ExpressionList : Expression() { @Relationship(value = "SUBEXPR", direction = Relationship.Direction.OUTGOING) - var expressionEdges = astEdgesOf(label = "SUBEXPR") + var expressionEdges = astEdgesOf() var expressions by unwrapping(ExpressionList::expressionEdges) override fun equals(other: Any?): Boolean { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/InitializerListExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/InitializerListExpression.kt index bf04043718..2f70d1026f 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/InitializerListExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/InitializerListExpression.kt @@ -49,9 +49,9 @@ class InitializerListExpression : Expression(), ArgumentHolder, HasType.TypeObse var initializerEdges = astEdgesOf( onAdd = { it.end.registerTypeObserver(this) }, - onRemove = { it.end.unregisterTypeObserver(this) }, - label = "INITIALIZERS", - ) + ) { + it.end.unregisterTypeObserver(this) + } /** Virtual property to access [initializerEdges] without property edges. */ var initializers by unwrapping(InitializerListExpression::initializerEdges) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/KeyValueExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/KeyValueExpression.kt index 04325a7d81..d6b2eaff81 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/KeyValueExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/KeyValueExpression.kt @@ -40,16 +40,14 @@ import org.neo4j.ogm.annotation.Relationship */ class KeyValueExpression : Expression(), ArgumentHolder { - @Relationship("KEY") - var keyEdge = astEdgeOf(ProblemExpression("missing key"), label = "KEY") + @Relationship("KEY") var keyEdge = astEdgeOf(ProblemExpression("missing key")) /** * The key of this pair. It is usually a literal, but some languages even allow references to * variables as a key. */ var key by unwrapping(KeyValueExpression::keyEdge) - @Relationship("VALUE") - var valueEdge = astEdgeOf(ProblemExpression("missing value"), label = "VALUE") + @Relationship("VALUE") var valueEdge = astEdgeOf(ProblemExpression("missing value")) /** The value of this pair. It can be any expression */ var value by unwrapping(KeyValueExpression::valueEdge) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/LambdaExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/LambdaExpression.kt index 5827f3ebe1..2b8823be97 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/LambdaExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/LambdaExpression.kt @@ -51,11 +51,7 @@ class LambdaExpression : Expression(), HasType.TypeObserver { var areVariablesMutable: Boolean = true @Relationship("FUNCTION") - var functionEdge = - astOptionalEdgeOf( - label = "FUNCTION", - onChanged = ::exchangeTypeObserver - ) + var functionEdge = astOptionalEdgeOf(onChanged = ::exchangeTypeObserver) var function by unwrapping(LambdaExpression::functionEdge) override fun typeChanged(newType: Type, src: HasType) { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/MemberExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/MemberExpression.kt index bee94e37e5..21c0e2cb85 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/MemberExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/MemberExpression.kt @@ -48,7 +48,6 @@ class MemberExpression : Reference(), HasOverloadedOperation, ArgumentHolder, Ha var baseEdge = astEdgeOf( ProblemExpression("could not parse base expression"), - label = "BASE", onChanged = { old, new -> exchangeTypeObserver(old, new) updateName() diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/NewArrayExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/NewArrayExpression.kt index 4f4ad5d0fd..d0bfa683f2 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/NewArrayExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/NewArrayExpression.kt @@ -39,8 +39,7 @@ import org.neo4j.ogm.annotation.Relationship */ // TODO Merge and/or refactor with new Expression class NewArrayExpression : Expression() { - @Relationship("INITIALIZER") - var initializerEdge = astOptionalEdgeOf(label = "INITIALIZER") + @Relationship("INITIALIZER") var initializerEdge = astOptionalEdgeOf() /** * The initializer of the expression, if present. Many languages, such as Java, either specify @@ -54,7 +53,7 @@ class NewArrayExpression : Expression() { * dimensions. In the graph, this will NOT be done. */ @Relationship(value = "DIMENSIONS", direction = Relationship.Direction.OUTGOING) - var dimensionEdges = astEdgesOf(label = "DIMENSIONS") + var dimensionEdges = astEdgesOf() /** Virtual property to access [dimensionEdges] without property edges. */ var dimensions by unwrapping(NewArrayExpression::dimensionEdges) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/NewExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/NewExpression.kt index 9132992c40..807dbcdf29 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/NewExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/NewExpression.kt @@ -36,8 +36,7 @@ import org.neo4j.ogm.annotation.Relationship /** Represents the creation of a new object through the `new` keyword. */ class NewExpression : Expression(), HasInitializer { - @Relationship("INITIALIZER") - var initializerEdge = astOptionalEdgeOf(label = "INITIALIZER") + @Relationship("INITIALIZER") var initializerEdge = astOptionalEdgeOf() /** The initializer expression. */ override var initializer by unwrapping(NewExpression::initializerEdge) @@ -47,7 +46,7 @@ class NewExpression : Expression(), HasInitializer { * ConstructExpression is created */ @Relationship(value = "TEMPLATE_PARAMETERS", direction = Relationship.Direction.OUTGOING) - var templateParameterEdges = astEdgesOf(label = "TEMPLATE_PARAMETERS") + var templateParameterEdges = astEdgesOf() var templateParameters by unwrapping(NewExpression::templateParameterEdges) override fun toString(): String { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/RangeExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/RangeExpression.kt index 180bdc8480..0140852024 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/RangeExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/RangeExpression.kt @@ -55,15 +55,15 @@ import org.neo4j.ogm.annotation.Relationship * Individual meaning of the range indices might differ per language. */ class RangeExpression : Expression() { - @Relationship("FLOOR") var floorEdge = astOptionalEdgeOf(label = "FLOOR") + @Relationship("FLOOR") var floorEdge = astOptionalEdgeOf() /** The lower bound ("floor") of the range. This index is usually *inclusive*. */ var floor by unwrapping(RangeExpression::floorEdge) - @Relationship("CEILING") var ceilingEdge = astOptionalEdgeOf(label = "CEILING") + @Relationship("CEILING") var ceilingEdge = astOptionalEdgeOf() /** The upper bound ("ceiling") of the range. This index is usually *exclusive*. */ var ceiling by unwrapping(RangeExpression::ceilingEdge) - @Relationship("THIRD") var thirdEdge = astOptionalEdgeOf(label = "THIRD") + @Relationship("THIRD") var thirdEdge = astOptionalEdgeOf() /** * Some languages offer a third value. The meaning depends completely on the language. For * example, Python allows specifying a step, while Go allows to control the underlying array's diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/SubscriptExpression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/SubscriptExpression.kt index b4b3a70d55..8254241a74 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/SubscriptExpression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/SubscriptExpression.kt @@ -43,7 +43,6 @@ class SubscriptExpression : Expression(), HasBase, HasType.TypeObserver, Argumen var arrayExpressionEdge = astEdgeOf( of = ProblemExpression("could not parse array expression"), - label = "ARRAY_EXPRESSION", onChanged = ::exchangeTypeObserver ) /** The array on which the access is happening. This is most likely a [Reference]. */ @@ -51,10 +50,7 @@ class SubscriptExpression : Expression(), HasBase, HasType.TypeObserver, Argumen @Relationship("SUBSCRIPT_EXPRESSION") var subscriptExpressionEdge = - astEdgeOf( - ProblemExpression("could not parse index expression"), - label = "SUBSCRIPT_EXPRESSION" - ) + astEdgeOf(ProblemExpression("could not parse index expression")) /** * The expression which represents the "subscription" or index on which the array is accessed. * This can for example be a reference to another variable ([Reference]), a [Literal] or a diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/UnaryOperator.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/UnaryOperator.kt index cfab59fc84..3bb1931a57 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/UnaryOperator.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/UnaryOperator.kt @@ -42,7 +42,6 @@ class UnaryOperator : Expression(), HasOverloadedOperation, ArgumentHolder, HasT var inputEdge = astEdgeOf( of = ProblemExpression("could not parse input"), - label = "INPUT", onChanged = { old, new -> exchangeTypeObserver(old, new) changeExpressionAccess() diff --git a/cpg-neo4j/src/main/kotlin/de/fraunhofer/aisec/cpg/persistence/Neo4J.kt b/cpg-neo4j/src/main/kotlin/de/fraunhofer/aisec/cpg/persistence/Neo4J.kt index 09f6c2fb67..2e25a93e9f 100644 --- a/cpg-neo4j/src/main/kotlin/de/fraunhofer/aisec/cpg/persistence/Neo4J.kt +++ b/cpg-neo4j/src/main/kotlin/de/fraunhofer/aisec/cpg/persistence/Neo4J.kt @@ -28,6 +28,7 @@ package de.fraunhofer.aisec.cpg.persistence import de.fraunhofer.aisec.cpg.TranslationResult import de.fraunhofer.aisec.cpg.graph.Node import de.fraunhofer.aisec.cpg.graph.Persistable +import de.fraunhofer.aisec.cpg.graph.edges.Edge import de.fraunhofer.aisec.cpg.graph.edges.collections.EdgeCollection import de.fraunhofer.aisec.cpg.graph.nodes import de.fraunhofer.aisec.cpg.helpers.Benchmark @@ -84,8 +85,8 @@ fun TranslationResult.persist() { val b = Benchmark(Persistable::class.java, "Persisting translation result") val astNodes = this@persist.nodes - val connected = astNodes.flatMap { it.connectedNodes } - val nodes = astNodes + connected + val connected = astNodes.flatMap { it.connectedNodes }.toSet() + val nodes = (astNodes + connected).distinct() log.info( "Persisting {} nodes: AST nodes ({}), other nodes ({})", @@ -168,6 +169,31 @@ private fun Collection.persist() { this.chunked(edgeChunkSize).map { chunk -> createRelationships(chunk) } } +context(Session) +private fun Collection>.persistEdgesOld() { + // Create an index for the "id" field of node, because we are "MATCH"ing on it in the edge + // creation. We need to wait for this to be finished + this@Session.executeWrite { tx -> + tx.run("CREATE INDEX IF NOT EXISTS FOR (n:Node) ON (n.id)").consume() + } + + this.chunked(edgeChunkSize).map { chunk -> + createRelationships( + chunk.flatMap { edge -> + // Since Neo4J does not support multiple labels on edges, but we do internally, we + // duplicate the edge for each label + edge.labels.map { label -> + mapOf( + "startId" to edge.start.id.toString(), + "endId" to edge.end.id.toString(), + "type" to label + ) + edge.properties() + } + } + ) + } +} + /** * Creates relationships in a graph database based on provided properties. *