Skip to content

Commit

Permalink
Adding mission relationship annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Aug 29, 2024
1 parent 535a5c4 commit 31e0b65
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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
import de.fraunhofer.aisec.cpg.passes.SymbolResolver
import org.neo4j.ogm.annotation.Relationship

/**
* A method declaration is a [FunctionDeclaration] that is part of to a specific [RecordDeclaration]
Expand All @@ -42,7 +43,7 @@ open class MethodDeclaration : FunctionDeclaration() {
*/
open var recordDeclaration: RecordDeclaration? = null

var receiverEdge = astOptionalEdgeOf<VariableDeclaration>()
@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 @@ -32,16 +32,17 @@ import de.fraunhofer.aisec.cpg.graph.statements.expressions.Block
import de.fraunhofer.aisec.cpg.graph.statements.expressions.Expression
import java.util.*
import org.apache.commons.lang3.builder.ToStringBuilder
import org.neo4j.ogm.annotation.Relationship

/** Represents a conditional loop statement of the form: `do{...}while(...)`. */
class DoStatement : Statement(), ArgumentHolder {
var conditionEdge = astOptionalEdgeOf<Expression>()
@Relationship("CONDITION") var conditionEdge = astOptionalEdgeOf<Expression>()
/**
* The loop condition that is evaluated after the loop statement and may trigger reevaluation.
*/
var condition by unwrappingOptional(DoStatement::conditionEdge)

var statementEdge = astOptionalEdgeOf<Statement>()
@Relationship("STATEMENT") var statementEdge = astOptionalEdgeOf<Statement>()

/**
* The statement that is going to be executed and re-executed, until the condition evaluates to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ import de.fraunhofer.aisec.cpg.graph.edges.unwrappingOptional
import de.fraunhofer.aisec.cpg.graph.statements.expressions.Block
import de.fraunhofer.aisec.cpg.graph.statements.expressions.Reference
import java.util.Objects
import org.neo4j.ogm.annotation.Relationship

class ForEachStatement : Statement(), BranchingNode, StatementHolder {

@Relationship("VARIABLE")
var variableEdge =
astOptionalEdgeOf<Statement>(
onChanged = { _, new ->
var end = new?.end
val end = new?.end
if (end is Reference) {
end.access = AccessValues.WRITE
}
Expand All @@ -54,11 +56,11 @@ class ForEachStatement : Statement(), BranchingNode, StatementHolder {
*/
var variable by unwrappingOptional(ForEachStatement::variableEdge)

var iterableEdge = astOptionalEdgeOf<Statement>()
@Relationship("ITERABLE") var iterableEdge = astOptionalEdgeOf<Statement>()
/** This field contains the iteration subject of the loop. */
var iterable by unwrappingOptional(ForEachStatement::iterableEdge)

var statementEdge = astOptionalEdgeOf<Statement>()
@Relationship("STATEMENT") var statementEdge = astOptionalEdgeOf<Statement>()
/** This field contains the body of the loop. */
var statement by unwrappingOptional(ForEachStatement::statementEdge)

Expand Down Expand Up @@ -91,7 +93,7 @@ class ForEachStatement : Statement(), BranchingNode, StatementHolder {
block.statements += s
statement = block
}
else -> (statement as? Block)?.statements += s
else -> (statement as? Block)?.statements?.plusAssign(s)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@ 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.Expression
import java.util.*
import org.neo4j.ogm.annotation.Relationship

class ForStatement : Statement(), BranchingNode {
var statementEdge = astOptionalEdgeOf<Statement>()
@Relationship("STATEMENT") var statementEdge = astOptionalEdgeOf<Statement>()
var statement by unwrappingOptional(ForStatement::statementEdge)

@Relationship("INITIALIZER_STATEMENT")
var initializerStatementEdge = astOptionalEdgeOf<Statement>()
var initializerStatement by unwrappingOptional(ForStatement::initializerStatementEdge)

@Relationship("CONDITION_DECLARATION")
var conditionDeclarationEdge = astOptionalEdgeOf<Declaration>()
var conditionDeclaration by unwrappingOptional(ForStatement::conditionDeclarationEdge)

var conditionEdge = astOptionalEdgeOf<Expression>()
@Relationship("CONDITION") var conditionEdge = astOptionalEdgeOf<Expression>()
var condition by unwrappingOptional(ForStatement::conditionEdge)

var iterationStatementEdge = astOptionalEdgeOf<Statement>()
@Relationship("ITERATION_STATEMENT") var iterationStatementEdge = astOptionalEdgeOf<Statement>()
var iterationStatement by unwrappingOptional(ForStatement::iterationStatementEdge)

override val branchedBy: Node?
Expand Down

0 comments on commit 31e0b65

Please sign in to comment.