Skip to content

Commit

Permalink
first draft problem nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
maximiliankaul committed Sep 5, 2024
1 parent e36b64d commit d0782fc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,27 @@ fun MetadataProvider.newProblemDeclaration(
return node
}

/**
* Creates a new [Problem]. The [MetadataProvider] receiver will be used to fill different meta-data
* using [Node.applyMetadata]. Calling this extension function outside of Kotlin requires an
* appropriate [MetadataProvider], such as a [LanguageFrontend] as an additional prepended argument.
*/
@JvmOverloads
fun MetadataProvider.newProblem(
problem: String = "",
problemType: ProblemNode.ProblemType = ProblemNode.ProblemType.PARSING,
rawNode: Any? = null
): Problem {
val node = Problem()
node.applyMetadata(this, EMPTY_NAME, rawNode, true)

node.problem = problem
node.problemType = problemType

log(node)
return node
}

/**
* Creates a new [IncludeDeclaration]. The [MetadataProvider] receiver will be used to fill
* different meta-data using [Node.applyMetadata]. Calling this extension function outside of Kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ abstract class Node :
@Relationship("ANNOTATIONS") var annotationEdges = astEdgesOf<Annotation>()
var annotations by unwrapping(Node::annotationEdges)

/**
* Additional problem nodes. These nodes represent problems which occurred during processing of
* a node (i.e. only partially processed).
*/
val additionalProblems: MutableSet<ProblemNode> = mutableSetOf()

/**
* If a node should be removed from the graph, just removing it from the AST is not enough (see
* issue #60). It will most probably be referenced somewhere via DFG or EOG edges. Thus, if it
Expand Down
32 changes: 32 additions & 0 deletions cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Problem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $$$$$$\ $$$$$$$\ $$$$$$\
* $$ __$$\ $$ __$$\ $$ __$$\
* $$ / \__|$$ | $$ |$$ / \__|
* $$ | $$$$$$$ |$$ |$$$$\
* $$ | $$ ____/ $$ |\_$$ |
* $$ | $$\ $$ | $$ | $$ |
* \$$$$$ |$$ | \$$$$$ |
* \______/ \__| \______/
*
*/
package de.fraunhofer.aisec.cpg.graph

/** A problem node documenting that something failed. */
data class Problem(
override var problem: String = "",
override var problemType: ProblemNode.ProblemType = ProblemNode.ProblemType.TRANSLATION
) : ProblemNode, MetadataProvider, Node()

0 comments on commit d0782fc

Please sign in to comment.