Skip to content

Commit

Permalink
Revert labels
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Dec 13, 2024
1 parent ac482aa commit a7bd3df
Show file tree
Hide file tree
Showing 59 changed files with 136 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TranslationResult(
var finalCtx: TranslationContext,
) : Node(), StatisticsHolder {

@Relationship("COMPONENTS") val componentEdges = astEdgesOf<Component>(label = "COMPONENTS")
@Relationship("COMPONENTS") val componentEdges = astEdgesOf<Component>()
/**
* Entry points to the CPG: "SoftwareComponent" refer to programs, application, other "bundles"
* of software.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ abstract class Language<T : LanguageFrontend<*, *>> : 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import org.neo4j.ogm.annotation.Transient
*/
open class Component : Node() {
@Relationship("TRANSLATION_UNITS")
val translationUnitEdges = astEdgesOf<TranslationUnitDeclaration>(label = "TRANSLATION_UNITS")
val translationUnitEdges = astEdgesOf<TranslationUnitDeclaration>()
/** All translation units belonging to this application. */
val translationUnits by unwrapping(Component::translationUnitEdges)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ abstract class Node :
var argumentIndex = 0

/** List of annotations associated with that node. */
@Relationship("ANNOTATIONS") var annotationEdges = astEdgesOf<Annotation>(label = "ANNOTATIONS")
@Relationship("ANNOTATIONS") var annotationEdges = astEdgesOf<Annotation>()
var annotations by unwrapping(Node::annotationEdges)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import org.neo4j.ogm.annotation.Relationship
* explicit initializer value.
*/
class EnumConstantDeclaration : ValueDeclaration(), HasInitializer {
@Relationship("INITIALIZER")
var initializerEdge = astOptionalEdgeOf<Expression>(label = "INITIALIZER")
@Relationship("INITIALIZER") var initializerEdge = astOptionalEdgeOf<Expression>()
override var initializer by unwrapping(EnumConstantDeclaration::initializerEdge)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.neo4j.ogm.annotation.Relationship

class EnumDeclaration : RecordDeclaration() {
@Relationship(value = "ENTRIES", direction = Relationship.Direction.OUTGOING)
var entryEdges = astEdgesOf<EnumConstantDeclaration>(label = "ENTRIES")
var entryEdges = astEdgesOf<EnumConstantDeclaration>()
var entries by unwrapping(EnumDeclaration::entryEdges)

override fun toString(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Statement>(label = "BODY")
@Relationship("BODY") var bodyEdge = astOptionalEdgeOf<Statement>()
/** 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<ParameterDeclaration>(label = "PARAMETERS")
var parameterEdges = astEdgesOf<ParameterDeclaration>()
/** Virtual property for accessing [parameterEdges] without property edges. */
var parameters by unwrapping(FunctionDeclaration::parameterEdges)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FunctionDeclaration>(label = "REALIZATION")
val realizationEdges = astEdgesOf<FunctionDeclaration>()
val realization by unwrapping(FunctionTemplateDeclaration::realizationEdges)

override val realizations: List<Declaration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IncludeDeclaration>(label = "INCLUDES")
val includeEdges = astEdgesOf<IncludeDeclaration>()
val includes by unwrapping(IncludeDeclaration::includeEdges)

@Relationship(value = "PROBLEMS", direction = Relationship.Direction.OUTGOING)
val problemEdges = astEdgesOf<ProblemDeclaration>(label = "PROBLEMS")
val problemEdges = astEdgesOf<ProblemDeclaration>()
val problems by unwrapping(IncludeDeclaration::problemEdges)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ open class MethodDeclaration : FunctionDeclaration() {
*/
open var recordDeclaration: RecordDeclaration? = null

@Relationship("RECEIVER")
var receiverEdge = astOptionalEdgeOf<VariableDeclaration>(label = "RECEIVER")
@Relationship("RECEIVER") var receiverEdge = astOptionalEdgeOf<VariableDeclaration>()
/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Declaration>(label = "DECLARATIONS")
val declarationEdges = astEdgesOf<Declaration>()
override val declarations by unwrapping(NamespaceDeclaration::declarationEdges)

/** The list of statements. */
@Relationship(value = "STATEMENTS", direction = Relationship.Direction.OUTGOING)
override var statementEdges = astEdgesOf<Statement>(label = "STATEMENTS")
override var statementEdges = astEdgesOf<Statement>()

/**
* In some languages, there is a relationship between paths / directories and the package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ParameterDeclaration : ValueDeclaration(), HasDefault<Expression?> {
var isVariadic = false

@Relationship(value = "DEFAULT", direction = Relationship.Direction.OUTGOING)
var defaultValueEdge = astOptionalEdgeOf<Expression>(label = "DEFAULT")
var defaultValueEdge = astOptionalEdgeOf<Expression>()
private var defaultValue by unwrapping(ParameterDeclaration::defaultValueEdge)

var modifiers: List<String> = mutableListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,28 @@ open class RecordDeclaration :
var kind: String? = null

@Relationship(value = "FIELDS", direction = Relationship.Direction.OUTGOING)
var fieldEdges = astEdgesOf<FieldDeclaration>(label = "FIELDS")
var fieldEdges = astEdgesOf<FieldDeclaration>()
var fields by unwrapping(RecordDeclaration::fieldEdges)

@Relationship(value = "METHODS", direction = Relationship.Direction.OUTGOING)
var methodEdges = astEdgesOf<MethodDeclaration>(label = "METHODS")
var methodEdges = astEdgesOf<MethodDeclaration>()
var methods by unwrapping(RecordDeclaration::methodEdges)

@Relationship(value = "CONSTRUCTORS", direction = Relationship.Direction.OUTGOING)
var constructorEdges = astEdgesOf<ConstructorDeclaration>(label = "CONSTRUCTORS")
var constructorEdges = astEdgesOf<ConstructorDeclaration>()
var constructors by unwrapping(RecordDeclaration::constructorEdges)

@Relationship(value = "RECORDS", direction = Relationship.Direction.OUTGOING)
var recordEdges = astEdgesOf<RecordDeclaration>(label = "RECORDS")
var recordEdges = astEdgesOf<RecordDeclaration>()
var records by unwrapping(RecordDeclaration::recordEdges)

@Relationship(value = "TEMPLATES", direction = Relationship.Direction.OUTGOING)
var templateEdges = astEdgesOf<TemplateDeclaration>(label = "TEMPLATES")
var templateEdges = astEdgesOf<TemplateDeclaration>()
var templates by unwrapping(RecordDeclaration::templateEdges)

/** The list of statements. */
@Relationship(value = "STATEMENTS", direction = Relationship.Direction.OUTGOING)
override var statementEdges = astEdgesOf<Statement>(label = "STATEMENTS")
override var statementEdges = astEdgesOf<Statement>()
override var statements by unwrapping(RecordDeclaration::statementEdges)

@Transient var superClasses: MutableList<Type> = ArrayList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RecordDeclaration>(label = "REALIZATION")
val realizationEdges = astEdgesOf<RecordDeclaration>()
override val realizations by unwrapping(RecordTemplateDeclaration::realizationEdges)

override fun addDeclaration(declaration: Declaration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Declaration>(label = "PARAMETERS")
var parameterEdges = astEdgesOf<Declaration>()
val parameters by unwrapping(TemplateDeclaration::parameterEdges)

val parametersWithDefaults: List<Declaration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Declaration>(label = "DECLARATIONS")
val declarationEdges = astEdgesOf<Declaration>()
override val declarations by unwrapping(TranslationUnitDeclaration::declarationEdges)

/** A list of includes within this unit. */
@Relationship(value = "INCLUDES", direction = Relationship.Direction.OUTGOING)
val includeEdges = astEdgesOf<IncludeDeclaration>(label = "INCLUDES")
val includeEdges = astEdgesOf<IncludeDeclaration>()
val includes by unwrapping(TranslationUnitDeclaration::includeEdges)

/** A list of namespaces within this unit. */
@Relationship(value = "NAMESPACES", direction = Relationship.Direction.OUTGOING)
val namespaceEdges = astEdgesOf<NamespaceDeclaration>(label = "NAMESPACES")
val namespaceEdges = astEdgesOf<NamespaceDeclaration>()
val namespaces by unwrapping(TranslationUnitDeclaration::namespaceEdges)

/** The list of statements. */
@Relationship(value = "STATEMENTS", direction = Relationship.Direction.OUTGOING)
override var statementEdges = astEdgesOf<Statement>(label = "STATEMENTS")
override var statementEdges = astEdgesOf<Statement>()
override var statements by unwrapping(TranslationUnitDeclaration::statementEdges)

override fun addDeclaration(declaration: Declaration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<VariableDeclaration>(
label = "ELEMENTS",
onAdd = { registerTypeObserver(it.end) },
onRemove = { unregisterTypeObserver(it.end) }
)
astEdgesOf<VariableDeclaration>(onAdd = { registerTypeObserver(it.end) }) {
unregisterTypeObserver(it.end)

Check warning on line 68 in cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TupleDeclaration.kt

View check run for this annotation

Codecov / codecov/patch

cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/declarations/TupleDeclaration.kt#L68

Added line #L68 was not covered by tests
}
var elements by unwrapping(TupleDeclaration::elementEdges)

override var name: Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import org.neo4j.ogm.annotation.Relationship
/** A declaration of a type template parameter */
class TypeParameterDeclaration : ValueDeclaration(), HasDefault<Type?> {
@Relationship(value = "DEFAULT", direction = Relationship.Direction.OUTGOING)
var defaultEdge = astOptionalEdgeOf<Type>(label = "DEFAULT")
var defaultEdge = astOptionalEdgeOf<Type>()
/** TemplateParameters can define a default for the type parameter. */
override var default by unwrapping(TypeParameterDeclaration::defaultEdge)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node>(label = "TEMPLATE_PARAMETERS")
var templateParameterEdges = astEdgesOf<Node>()
var templateParameters by unwrapping(VariableDeclaration::templateParameterEdges)

/** Determines if this is a global variable. */
Expand All @@ -69,7 +69,6 @@ open class VariableDeclaration : ValueDeclaration(), HasInitializer, HasType.Typ
@Relationship("INITIALIZER")
var initializerEdge =
astOptionalEdgeOf<Expression>(
label = "INITIALIZER",
onChanged = { old, new ->
val value = new?.end
exchangeTypeObserver(old, new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,22 @@ open class AstEdge<T : Node>(start: Node, end: T, override var labels: Set<Strin

/** Creates an [AstEdges] container starting from this node. */
fun <NodeType : Node> Node.astEdgesOf(
label: String? = null,
onAdd: ((AstEdge<NodeType>) -> Unit)? = null,
onRemove: ((AstEdge<NodeType>) -> Unit)? = null,
): AstEdges<NodeType, AstEdge<NodeType>> {
return AstEdges(thisRef = this, label = label, onAdd = onAdd, onRemove = onRemove)
return AstEdges(thisRef = this, onAdd = onAdd, onRemove = onRemove)
}

/**
* Creates a single optional [AstEdge] starting from this node (wrapped in a [EdgeSingletonList]
* container).
*/
fun <NodeType : Node> Node.astOptionalEdgeOf(
label: String? = null,
onChanged: ((old: AstEdge<NodeType>?, new: AstEdge<NodeType>?) -> Unit)? = null
): EdgeSingletonList<NodeType, NodeType?, AstEdge<NodeType>> {
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
Expand All @@ -71,12 +69,11 @@ fun <NodeType : Node> Node.astOptionalEdgeOf(
*/
fun <NodeType : Node> Node.astEdgeOf(
of: NodeType,
label: String? = null,
onChanged: ((old: AstEdge<NodeType>?, new: AstEdge<NodeType>?) -> Unit)? = null,
): EdgeSingletonList<NodeType, NodeType, AstEdge<NodeType>> {
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
Expand All @@ -86,12 +83,11 @@ fun <NodeType : Node> Node.astEdgeOf(
/** This property edge list describes elements that are AST children of a node. */
open class AstEdges<NodeType : Node, PropertyEdgeType : AstEdge<NodeType>>(
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<NodeType, PropertyEdgeType>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ import de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression
class TemplateArgument<NodeType : Node>(
start: Node,
end: NodeType,
label: String,
var instantiation: TemplateInitialization? = TemplateInitialization.EXPLICIT,
) : AstEdge<NodeType>(start, end, setOf(label, "AST"))
) : AstEdge<NodeType>(start, end)

/** A container for [TemplateArgument] edges. */
class TemplateArguments<NodeType : Node>(thisRef: Node, label: String) :
class TemplateArguments<NodeType : Node>(thisRef: Node) :
AstEdges<NodeType, TemplateArgument<NodeType>>(
thisRef,
label,
init = { start, end -> TemplateArgument(start, end, label = label) }
init = { start, end -> TemplateArgument(start, end) }
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ import org.neo4j.ogm.annotation.Relationship

/** Represents an assert statement */
class AssertStatement : Statement() {
@Relationship(value = "CONDITION")
var conditionEdge = astOptionalEdgeOf<Expression>(label = "CONDITION")
@Relationship(value = "CONDITION") var conditionEdge = astOptionalEdgeOf<Expression>()
/** The condition to be evaluated. */
var condition by unwrapping(AssertStatement::conditionEdge)

@Relationship(value = "MESSAGE")
var messageEdge = astOptionalEdgeOf<Statement>(label = "MESSAGE")
@Relationship(value = "MESSAGE") var messageEdge = astOptionalEdgeOf<Statement>()
/** The *optional* message that is shown, if the assert is evaluated as true */
var message by unwrapping(AssertStatement::messageEdge)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import org.neo4j.ogm.annotation.Relationship
*/
class CaseStatement : Statement() {
@Relationship(value = "CASE_EXPRESSION")
var caseExpressionEdge = astOptionalEdgeOf<Expression>(label = "CASE_EXPRESSION")
var caseExpressionEdge = astOptionalEdgeOf<Expression>()

/**
* Primitive side effect free statement that has to match with the evaluated selector in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<VariableDeclaration>(label = "PARAMETER")
@Relationship(value = "PARAMETER") var parameterEdge = astOptionalEdgeOf<VariableDeclaration>()

var parameter by unwrapping(CatchClause::parameterEdge)

@Relationship(value = "BODY") var bodyEdge = astOptionalEdgeOf<Block>(label = "BODY")
@Relationship(value = "BODY") var bodyEdge = astOptionalEdgeOf<Block>()
var body by unwrapping(CatchClause::bodyEdge)

@DoNotPersist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class DeclarationStatement : Statement() {
* it only contains a single [Declaration].
*/
@Relationship(value = "DECLARATIONS", direction = Relationship.Direction.OUTGOING)
var declarationEdges = astEdgesOf<Declaration>(label = "DECLARATIONS")
var declarationEdges = astEdgesOf<Declaration>()
override var declarations by unwrapping(DeclarationStatement::declarationEdges)

var singleDeclaration: Declaration?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Expression>(label = "CONDITION")
@Relationship("CONDITION") var conditionEdge = astOptionalEdgeOf<Expression>()
/**
* The loop condition that is evaluated after the loop statement and may trigger reevaluation.
*/
Expand Down
Loading

0 comments on commit a7bd3df

Please sign in to comment.