KE2: Start extracting declaration parents

This commit is contained in:
Ian Lynagh
2024-08-29 18:14:46 +01:00
parent 75e78965f0
commit c98415631f
4 changed files with 27 additions and 22 deletions

View File

@@ -285,9 +285,6 @@ OLD: KE1
*/
}
is KtFunction -> {
println("=== Dec is fun")
println(declaration)
println(declaration.parent)
val parentId = useDeclarationParentOf(declaration, false)?.cast<DbReftype>()
/*
OLD: KE1

View File

@@ -56,11 +56,11 @@ OLD: KE1
val javaLangObject by lazy { referenceExternalClass("java.lang.Object") }
val javaLangObjectType by lazy { javaLangObject?.typeWith() }
*/
private fun usePackage(pkg: String): Label<out DbPackage> {
return extractPackage(pkg)
}
*/
fun extractPackage(pkg: String): Label<out DbPackage> {
val pkgLabel = "@\"package;$pkg\""
@@ -84,24 +84,28 @@ OLD: KE1
TypeResult(extractFileClass(pkg, jvmName), "", ""),
TypeResult(fakeKotlinType(), "", "")
)
*/
fun extractFileClass(f: IrFile): Label<out DbClassorinterface> {
fun extractFileClass(f: KtFile): Label<out DbClassorinterface> {
val pkg = f.packageFqName.asString()
val jvmName = getFileClassName(f)
val id = extractFileClass(pkg, jvmName)
if (tw.lm.fileClassLocationsExtracted.add(f)) {
val fileId = tw.mkFileId(f.path, false)
val fileId = tw.mkFileId(f.virtualFilePath, false)
val locId = tw.getWholeFileLocation(fileId)
tw.writeHasLocation(id, locId)
}
return id
}
/*
OLD: KE1
private fun extractFileClass(fqName: FqName): Label<out DbClassorinterface> {
val pkg = if (fqName.isRoot()) "" else fqName.parent().asString()
val jvmName = fqName.shortName().asString()
return extractFileClass(pkg, jvmName)
}
*/
private fun extractFileClass(pkg: String, jvmName: String): Label<out DbClassorinterface> {
val qualClassName = if (pkg.isEmpty()) jvmName else "$pkg.$jvmName"
@@ -112,11 +116,16 @@ OLD: KE1
tw.writeClasses_or_interfaces(it, jvmName, pkgId, it)
tw.writeFile_class(it)
/*
OLD: KE1
addModifiers(it, "public", "final")
*/
}
return id
}
/*
OLD: KE1
data class UseClassInstanceResult(
val typeResult: TypeResult<DbClassorinterface>,
val javaClass: IrClass
@@ -1016,14 +1025,14 @@ OLD: KE1
*/
): Label<out DbElement>? =
when (dp) {
/*
OLD: KE1
is IrFile ->
is KtFile ->
if (canBeTopLevel) {
usePackage(dp.packageFqName.asString())
} else {
extractFileClass(dp)
}
/*
OLD: KE1
is IrClass ->
if (classTypeArguments != null) {
useClassInstance(dp, classTypeArguments, inReceiverContext).typeResult.id

View File

@@ -51,15 +51,15 @@ OLD: KE1
* labels, so we just accept this duplication.
*/
val genericSpecialisationsExtracted = HashSet<String>()
*/
/**
* Sometimes, when we extract a file class we don't have the IrFile for it, so we are not able
* Sometimes, when we extract a file class we don't have the KtFile for it, so we are not able
* to give it a location. This means that the location is written outside of the label creation.
* This allows us to keep track of whether we've written the location already in this TRAP file,
* to avoid duplication.
*/
val fileClassLocationsExtracted = HashSet<IrFile>()
*/
val fileClassLocationsExtracted = HashSet<KtFile>()
}
/**
@@ -67,15 +67,9 @@ OLD: KE1
* `TrapWriter`s for the same file, as different instances will have different additional state, but
* they must all share the same `TrapLabelManager` and `BufferedWriter`.
*/
/*
OLD: KE1:
// TODO lm was `protected` before anonymousTypeMapping and locallyVisibleFunctionLabelMapping moved
// into it. Should we re-protect it and provide accessors?
Protected again for now in KE2.
*/
abstract class TrapWriter(
protected val loggerBase: LoggerBase,
protected val lm: TrapLabelManager,
val lm: TrapLabelManager,
private val bw: BufferedWriter
) {
abstract fun getDiagnosticTrapWriter(): DiagnosticTrapWriter

View File

@@ -1,5 +1,7 @@
package com.github.codeql
import org.jetbrains.kotlin.psi.*
/*
OLD: KE1
import com.github.codeql.utils.getJvmName
@@ -25,14 +27,17 @@ import org.jetbrains.kotlin.load.kotlin.VirtualFileKotlinClass
// for `that`.
private fun getName(d: IrDeclarationWithName) =
(d as? IrAnnotationContainer)?.let { getJvmName(it) } ?: d.name.asString()
*/
fun getFileClassName(f: IrFile) =
getJvmName(f)
?: ((f.fileEntry.name
fun getFileClassName(f: KtFile): String =
null /* OLD: KE1: getJvmName(f) */
?: ((f.virtualFilePath
.replaceFirst(Regex(""".*[/\\]"""), "")
.replaceFirst(Regex("""\.kt$"""), "")
.replaceFirstChar { it.uppercase() }) + "Kt")
/*
OLD: KE1
fun getIrElementBinaryName(that: IrElement): String {
if (that is IrFile) {
val shortName = getFileClassName(that)