Skip to content

Commit

Permalink
Removed AST annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Aug 14, 2024
1 parent 2b03e96 commit 676f48a
Show file tree
Hide file tree
Showing 55 changed files with 57 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package de.fraunhofer.aisec.cpg

import de.fraunhofer.aisec.cpg.frontends.LanguageFrontend
import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.Component
import de.fraunhofer.aisec.cpg.graph.Name
import de.fraunhofer.aisec.cpg.graph.Node
Expand Down Expand Up @@ -55,7 +54,7 @@ class TranslationResult(
var finalCtx: TranslationContext,
) : Node(), StatisticsHolder {

@Relationship("COMPONENTS") @AST val componentEdges = astEdgesOf<Component>()
@Relationship("COMPONENTS") val componentEdges = astEdgesOf<Component>()
/**
* Entry points to the CPG: "SoftwareComponent" refer to programs, application, other "bundles"
* of software.
Expand Down
35 changes: 0 additions & 35 deletions cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/AST.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import org.neo4j.ogm.annotation.Relationship
*/
open class Component : Node() {
@Relationship("TRANSLATION_UNITS")
@AST
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 @@ -254,7 +254,7 @@ abstract class Node :
var argumentIndex = 0

/** List of annotations associated with that node. */
@Relationship("ANNOTATIONS") @AST var annotationEdges = astEdgesOf<Annotation>()
@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 @@ -25,7 +25,6 @@
*/
package de.fraunhofer.aisec.cpg.graph.declarations

import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.HasInitializer
import de.fraunhofer.aisec.cpg.graph.edges.ast.astOptionalEdgeOf
import de.fraunhofer.aisec.cpg.graph.edges.unwrappingOptional
Expand All @@ -37,6 +36,6 @@ import org.neo4j.ogm.annotation.Relationship
* explicit initializer value.
*/
class EnumConstantDeclaration : ValueDeclaration(), HasInitializer {
@Relationship("INITIALIZER") @AST var initializerEdge = astOptionalEdgeOf<Expression>()
@Relationship("INITIALIZER") var initializerEdge = astOptionalEdgeOf<Expression>()
override var initializer by unwrappingOptional(EnumConstantDeclaration::initializerEdge)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
*/
package de.fraunhofer.aisec.cpg.graph.declarations

import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.edges.ast.astEdgesOf
import de.fraunhofer.aisec.cpg.graph.edges.unwrapping
import org.apache.commons.lang3.builder.ToStringBuilder
import org.neo4j.ogm.annotation.Relationship

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

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

/** Represents the declaration or definition of a function. */
open class FunctionDeclaration : ValueDeclaration(), DeclarationHolder, EOGStarterHolder {
@Relationship("BODY") @AST var bodyEdge = astOptionalEdgeOf<Statement>()
@Relationship("BODY") var bodyEdge = astOptionalEdgeOf<Statement>()
/** The function body. Usually a [Block]. */
var body by unwrappingOptional(FunctionDeclaration::bodyEdge)

/** The list of function parameters. */
@Relationship(value = "PARAMETERS", direction = Relationship.Direction.OUTGOING)
@AST
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 @@ -25,7 +25,6 @@
*/
package de.fraunhofer.aisec.cpg.graph.declarations

import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.edges.Edge.Companion.propertyEqualsList
import de.fraunhofer.aisec.cpg.graph.edges.ast.astEdgesOf
import de.fraunhofer.aisec.cpg.graph.edges.unwrapping
Expand All @@ -40,7 +39,6 @@ class FunctionTemplateDeclaration : TemplateDeclaration() {
* expansion pass for each instantiation of the FunctionTemplate there will be a realization
*/
@Relationship(value = "REALIZATION", direction = Relationship.Direction.OUTGOING)
@AST
val realizationEdges = astEdgesOf<FunctionDeclaration>()
val realization by unwrapping(FunctionTemplateDeclaration::realizationEdges)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
package de.fraunhofer.aisec.cpg.graph.declarations

import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.edges.Edge.Companion.propertyEqualsList
import de.fraunhofer.aisec.cpg.graph.edges.ast.astEdgesOf
import de.fraunhofer.aisec.cpg.graph.edges.unwrapping
Expand All @@ -36,12 +35,10 @@ 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)
@AST
val includeEdges = astEdgesOf<IncludeDeclaration>()
val includes by unwrapping(IncludeDeclaration::includeEdges)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
package de.fraunhofer.aisec.cpg.graph.declarations

import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.edges.ast.astOptionalEdgeOf
import de.fraunhofer.aisec.cpg.graph.edges.unwrappingOptional
import de.fraunhofer.aisec.cpg.graph.statements.expressions.Reference
Expand All @@ -43,7 +42,7 @@ open class MethodDeclaration : FunctionDeclaration() {
*/
open var recordDeclaration: RecordDeclaration? = null

@AST var receiverEdge = astOptionalEdgeOf<VariableDeclaration>()
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 @@ -48,12 +48,11 @@ class NamespaceDeclaration : Declaration(), DeclarationHolder, StatementHolder,
* Edges to nested namespaces, records, functions, fields etc. contained in the current
* namespace.
*/
@AST val declarationEdges = astEdgesOf<Declaration>()
val declarationEdges = astEdgesOf<Declaration>()
override val declarations by unwrapping(NamespaceDeclaration::declarationEdges)

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
package de.fraunhofer.aisec.cpg.graph.declarations

import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.HasDefault
import de.fraunhofer.aisec.cpg.graph.edges.ast.astOptionalEdgeOf
import de.fraunhofer.aisec.cpg.graph.edges.unwrappingOptional
Expand All @@ -38,7 +37,6 @@ class ParameterDeclaration : ValueDeclaration(), HasDefault<Expression?> {
var isVariadic = false

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,27 @@ open class RecordDeclaration :
var kind: String? = null

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

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
package de.fraunhofer.aisec.cpg.graph.declarations

import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.edges.Edge.Companion.propertyEqualsList
import de.fraunhofer.aisec.cpg.graph.edges.ast.astEdgesOf
import de.fraunhofer.aisec.cpg.graph.edges.unwrapping
Expand All @@ -40,7 +39,6 @@ class RecordTemplateDeclaration : TemplateDeclaration() {
* expansion pass for each instantiation of the ClassTemplate there will be a realization
*/
@Relationship(value = "REALIZATION", direction = Relationship.Direction.OUTGOING)
@AST
val realizationEdges = astEdgesOf<RecordDeclaration>()
override val realizations by unwrapping(RecordTemplateDeclaration::realizationEdges)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
package de.fraunhofer.aisec.cpg.graph.declarations

import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.DeclarationHolder
import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.edges.Edge.Companion.propertyEqualsList
Expand All @@ -52,7 +51,6 @@ abstract class TemplateDeclaration : Declaration(), DeclarationHolder {

/** Parameters the Template requires for instantiation */
@Relationship(value = "PARAMETERS", direction = Relationship.Direction.OUTGOING)
@AST
var parameterEdges = astEdgesOf<Declaration>()
val parameters by unwrapping(TemplateDeclaration::parameterEdges)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,21 @@ class TranslationUnitDeclaration :
Declaration(), DeclarationHolder, StatementHolder, EOGStarterHolder {
/** A list of declarations within this unit. */
@Relationship(value = "DECLARATIONS", direction = Relationship.Direction.OUTGOING)
@AST
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)
@AST
val includeEdges = astEdgesOf<IncludeDeclaration>()
val includes by unwrapping(TranslationUnitDeclaration::includeEdges)

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
package de.fraunhofer.aisec.cpg.graph.declarations

import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.Name
import de.fraunhofer.aisec.cpg.graph.edges.ast.astEdgesOf
import de.fraunhofer.aisec.cpg.graph.edges.unwrapping
Expand Down Expand Up @@ -64,7 +63,6 @@ import de.fraunhofer.aisec.cpg.graph.types.TupleType
*/
class TupleDeclaration : VariableDeclaration() {
/** The list of elements in this tuple. */
@AST
var elementEdges =
astEdgesOf<VariableDeclaration>(
onAdd = { registerTypeObserver(it.end) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
package de.fraunhofer.aisec.cpg.graph.declarations

import de.fraunhofer.aisec.cpg.graph.AST
import de.fraunhofer.aisec.cpg.graph.HasDefault
import de.fraunhofer.aisec.cpg.graph.edges.ast.astOptionalEdgeOf
import de.fraunhofer.aisec.cpg.graph.edges.unwrappingOptional
Expand All @@ -36,7 +35,6 @@ 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)
@AST
var defaultEdge = astOptionalEdgeOf<Type>()
/** TemplateParameters can define a default for the type parameter. */
override var default by unwrappingOptional(TypeParameterDeclaration::defaultEdge)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ open class VariableDeclaration : ValueDeclaration(), HasInitializer, HasType.Typ
* the [ConstructExpression] is created.
*/
@Relationship(value = "TEMPLATE_PARAMETERS", direction = Relationship.Direction.OUTGOING)
@AST
var templateParameterEdges = astEdgesOf<Node>()
var templateParameters by unwrapping(VariableDeclaration::templateParameterEdges)

Expand All @@ -69,7 +68,6 @@ open class VariableDeclaration : ValueDeclaration(), HasInitializer, HasType.Typ
var isArray = false

@Relationship("INITIALIZER")
@AST
var initializerEdge =
astOptionalEdgeOf<Expression>(
onChanged = { old, new ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
* \______/ \__| \______/
*
*/
@file:Suppress("UNCHECKED_CAST")

package de.fraunhofer.aisec.cpg.graph.edges

import de.fraunhofer.aisec.cpg.graph.Node
Expand All @@ -36,12 +34,12 @@ import de.fraunhofer.aisec.cpg.graph.edges.collections.UnwrappedEdgeSet
import kotlin.reflect.KProperty1
import kotlin.reflect.jvm.isAccessible

@Suppress("UNCHECKED_CAST")
fun <EdgeType : Edge<Node>> MutableList<Node>.add(
target: Node,
builder: EdgeType.() -> Unit
): Boolean {
if (this is UnwrappedEdgeList<*, *>) {
@Suppress("UNCHECKED_CAST")
return (this as UnwrappedEdgeList<Node, EdgeType>).add(target, builder)
}

Expand Down
Loading

0 comments on commit 676f48a

Please sign in to comment.