Skip to content

Commit

Permalink
Refactor some nodes to remove redundant nodes (#1352)
Browse files Browse the repository at this point in the history
  • Loading branch information
konradweiss authored Nov 30, 2023
1 parent 36f072b commit 6592ce4
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,27 +294,6 @@ fun MetadataProvider.newCallExpression(
return node
}

/**
* Creates a new [CallExpression]. 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.newConstructorCallExpression(
containingClass: String?,
code: String? = null,
rawNode: Any? = null
): ConstructorCallExpression {
val node = ConstructorCallExpression()
node.applyMetadata(this, EMPTY_NAME, rawNode, code, true)

node.containingClass = containingClass

log(node)
return node
}

/**
* Creates a new [CallExpression]. The [MetadataProvider] receiver will be used to fill different
* meta-data using [Node.applyMetadata]. Calling this extension function outside of Kotlin requires
Expand Down Expand Up @@ -550,24 +529,6 @@ fun MetadataProvider.newInitializerListExpression(
return node
}

/**
* Creates a new [DesignatedInitializerExpression]. 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.newDesignatedInitializerExpression(
code: String? = null,
rawNode: Any? = null
): DesignatedInitializerExpression {
val node = DesignatedInitializerExpression()
node.applyMetadata(this, EMPTY_NAME, rawNode, code, true)

log(node)
return node
}

/**
* Creates a new [TypeExpression]. The [MetadataProvider] receiver will be used to fill different
* meta-data using [Node.applyMetadata]. Calling this extension function outside of Kotlin requires
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ fun MetadataProvider.newAssertStatement(
}

/**
* Creates a new [ASMDeclarationStatement]. The [MetadataProvider] receiver will be used to fill
* Creates a new [DistinctLanguageBlock]. 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.newASMDeclarationStatement(
fun MetadataProvider.newDistinctLanguageBlock(
code: String? = null,
rawNode: Any? = null
): ASMDeclarationStatement {
val node = ASMDeclarationStatement()
): DistinctLanguageBlock {
val node = DistinctLanguageBlock()
node.applyMetadata(this, EMPTY_NAME, rawNode, code, true)

log(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@
*
*/
package de.fraunhofer.aisec.cpg.graph.statements
// TODO Merge and/or refactor
class ASMDeclarationStatement : DeclarationStatement()

import de.fraunhofer.aisec.cpg.graph.statements.expressions.Block

/**
* A Block of code containing code in a different language that is not parsable with the same
* frontend as the enclosing language.
*/
class DistinctLanguageBlock : Block()
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import org.neo4j.ogm.annotation.Relationship
* A statement which contains a list of statements. A common example is a function body within a
* [FunctionDeclaration].
*/
class Block : Expression(), StatementHolder {
open class Block : Expression(), StatementHolder {
/** The list of statements. */
@Relationship(value = "STATEMENTS", direction = Relationship.Direction.OUTGOING)
@AST
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ open class SymbolResolver(ctx: TranslationContext) : ComponentPass(ctx) {
when (node) {
is MemberExpression -> handleMemberExpression(currClass, node)
is Reference -> handleReference(currClass, node)
is ConstructorCallExpression -> handleConstructorCallExpression(node)
is ConstructExpression -> handleConstructExpression(node)
is CallExpression -> handleCallExpression(scopeManager.currentRecord, node)
}
Expand Down Expand Up @@ -741,23 +740,6 @@ open class SymbolResolver(ctx: TranslationContext) : ComponentPass(ctx) {
}
}

protected fun handleConstructorCallExpression(
constructorCallExpression: ConstructorCallExpression
) {
constructorCallExpression.containingClass?.let { containingClass ->
val recordDeclaration =
constructorCallExpression.objectType(containingClass).recordDeclaration
val signature = constructorCallExpression.arguments.map { it.type }
if (recordDeclaration != null) {
val constructor =
getConstructorDeclarationForExplicitInvocation(signature, recordDeclaration)
val invokes = mutableListOf<FunctionDeclaration>()
invokes.add(constructor)
constructorCallExpression.invokes = invokes
}
}
}

protected fun getPossibleContainingTypes(node: Node?): Set<Type> {
val possibleTypes = mutableSetOf<Type>()
if (node is MemberCallExpression) {
Expand Down
Loading

0 comments on commit 6592ce4

Please sign in to comment.