Skip to content

Commit

Permalink
Converting ME to static reference
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Nov 21, 2024
1 parent 077d7ec commit faaa036
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ class ExpressionHandler(lang: JavaLanguageFrontend) :
// our own.
try {
val symbol = fieldAccessExpr.resolve()
baseType = frontend.typeOf(symbol.type)
fieldType = frontend.typeOf(symbol.type)

if (symbol.isField) {
fieldType = objectType(symbol.asField().declaringType().qualifiedName)
baseType = objectType(symbol.asField().declaringType().qualifiedName)
}
} catch (_: UnsolvedSymbolException) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ open class JavaLanguageFrontend(language: Language<JavaLanguageFrontend>, ctx: T

// We create an implicit import for "java.lang.*"
val decl =
newImportDeclaration(Name("java.lang"), wildcardImport = true)
newImportDeclaration(parseName("java.lang"), wildcardImport = true)
.implicit("import java.lang.*")
scopeManager.addDeclaration(decl)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ package de.fraunhofer.aisec.cpg.passes

import de.fraunhofer.aisec.cpg.TranslationContext
import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.codeAndLocationFrom
import de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration
import de.fraunhofer.aisec.cpg.graph.fqn
import de.fraunhofer.aisec.cpg.graph.newReference
import de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression
import de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberExpression
import de.fraunhofer.aisec.cpg.graph.statements.expressions.Reference
import de.fraunhofer.aisec.cpg.helpers.SubgraphWalker
import de.fraunhofer.aisec.cpg.helpers.replace
import de.fraunhofer.aisec.cpg.nameIsType
import de.fraunhofer.aisec.cpg.passes.configuration.DependsOn
import de.fraunhofer.aisec.cpg.passes.configuration.ExecuteBefore
Expand Down Expand Up @@ -67,8 +69,11 @@ class JavaExtraPass(ctx: TranslationContext) : TranslationUnitPass(ctx) {
// Our base refers to a type, so this is actually a static reference, which we
// model not as a member expression, but as a reference with an FQN. Let's build that
// and exchange the node
val ref = newReference(type.name.fqn(me.name.localName)).apply { isStaticAccess = true }
println("hello")
val ref =
newReference(type.name.fqn(me.name.localName), type = me.type)
.codeAndLocationFrom(me)
.apply { isStaticAccess = true }
walker.replace(parent, me, ref)
}
}

Expand Down

0 comments on commit faaa036

Please sign in to comment.