@@ -8,6 +8,7 @@ import java.nio.file.Files
88import java.nio.file.Paths
99import java.text.SimpleDateFormat
1010import java.util.Date
11+ import java.util.Optional
1112import kotlin.system.exitProcess
1213import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
1314import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
@@ -167,8 +168,8 @@ fun doFile(logger: Logger, trapDir: File, srcDir: File, declaration: IrFile) {
167168 val tw = TrapWriter (fileLabel, trapFileBW, declaration.fileEntry)
168169 val id: Label <DbFile > = tw.getLabelFor(fileLabel)
169170 tw.writeFiles(id, filePath, basename, extension, 0 )
170- val fileExtractor = KotlinFileExtractor (logger, tw)
171- fileExtractor.extractFile(id, declaration )
171+ val fileExtractor = KotlinFileExtractor (logger, tw, declaration )
172+ fileExtractor.extractFile(id)
172173 }
173174}
174175
@@ -179,14 +180,16 @@ fun <T> fakeLabel(): Label<T> {
179180 return Label (0 )
180181}
181182
182- class KotlinFileExtractor (val logger : Logger , val tw : TrapWriter ) {
183- fun extractFile (id : Label <DbFile >, f : IrFile ) {
184- val pkg = f.fqName.asString()
183+ class KotlinFileExtractor (val logger : Logger , val tw : TrapWriter , val file : IrFile ) {
184+ val fileClass by lazy {
185+ extractFileClass(file)
186+ }
187+
188+ fun extractFile (id : Label <DbFile >) {
189+ val pkg = file.fqName.asString()
185190 val pkgId = extractPackage(pkg)
186191 tw.writeCupackage(id, pkgId)
187- // TODO: This shouldn't really exist if there is nothing to go on it
188- val fileClass = extractFileClass(f)
189- f.declarations.map { extractDeclaration(it, fileClass) }
192+ file.declarations.map { extractDeclaration(it, Optional .empty()) }
190193 }
191194
192195 fun extractFileClass (f : IrFile ): Label <out DbClass > {
@@ -233,11 +236,11 @@ class KotlinFileExtractor(val logger: Logger, val tw: TrapWriter) {
233236 return id
234237 }
235238
236- fun extractDeclaration (declaration : IrDeclaration , parentid : Label <out DbReftype >) {
239+ fun extractDeclaration (declaration : IrDeclaration , optParentid : Optional < Label <out DbReftype > >) {
237240 when (declaration) {
238241 is IrClass -> extractClass(declaration)
239- is IrFunction -> extractFunction(declaration, parentid )
240- is IrProperty -> extractProperty(declaration, parentid )
242+ is IrFunction -> extractFunction(declaration, if (optParentid.isPresent()) optParentid.get() else fileClass )
243+ is IrProperty -> extractProperty(declaration, if (optParentid.isPresent()) optParentid.get() else fileClass )
241244 else -> logger.warn(" Unrecognised IrDeclaration: " + declaration.javaClass)
242245 }
243246 }
@@ -309,7 +312,7 @@ class KotlinFileExtractor(val logger: Logger, val tw: TrapWriter) {
309312 val pkgId = extractPackage(pkg)
310313 tw.writeClasses(id, cls, pkgId, id)
311314 tw.writeHasLocation(id, locId)
312- c.declarations.map { extractDeclaration(it, id ) }
315+ c.declarations.map { extractDeclaration(it, Optional .of(id) ) }
313316 return id
314317 }
315318
0 commit comments