From 62ce28eb6824732d967fcdeb4a7ec50af0275ff1 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Thu, 10 Mar 2022 19:31:07 +0000 Subject: [PATCH] Kotlin: Populate diagnostic_for --- .../src/main/kotlin/KotlinExtractorExtension.kt | 1 + java/kotlin-extractor/src/main/kotlin/Label.kt | 9 --------- .../kotlin-extractor/src/main/kotlin/utils/Logger.kt | 12 +++++++++++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt b/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt index 4bd402d7e6c..806e5dd44a9 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt @@ -121,6 +121,7 @@ class KotlinExtractorExtension( moduleFragment.files.mapIndexed { index: Int, file: IrFile -> val fileExtractionProblems = FileExtractionProblems(invocationExtractionProblems) val fileTrapWriter = tw.makeSourceFileTrapWriter(file, true) + loggerBase.setFileNumber(index) fileTrapWriter.writeCompilation_compiling_files(compilation, index, fileTrapWriter.fileId) doFile(fileExtractionProblems, invocationTrapFile, fileTrapWriter, checkTrapIdentical, loggerBase, trapDir, srcDir, file, primitiveTypeMapping, pluginContext, globalExtensionState) fileTrapWriter.writeCompilation_compiling_files_completed(compilation, index, fileExtractionProblems.extractionResult()) diff --git a/java/kotlin-extractor/src/main/kotlin/Label.kt b/java/kotlin-extractor/src/main/kotlin/Label.kt index cdc9292e7da..5fb2acf12bb 100644 --- a/java/kotlin-extractor/src/main/kotlin/Label.kt +++ b/java/kotlin-extractor/src/main/kotlin/Label.kt @@ -25,15 +25,6 @@ class StringLabel(val name: String): Label { override fun toString(): String = "#$name" } -/** - * This is not really a label, but just a `*`. Used in the rare cases - * when we only need to refer to something once, to save adding - * unnecessary labels. - */ -class StarLabel: Label { - override fun toString(): String = "*" -} - // TODO: Remove this and all of its uses fun fakeLabel(): Label { if (false) { diff --git a/java/kotlin-extractor/src/main/kotlin/utils/Logger.kt b/java/kotlin-extractor/src/main/kotlin/utils/Logger.kt index 19b3c342cd0..c4bdd997cd6 100644 --- a/java/kotlin-extractor/src/main/kotlin/utils/Logger.kt +++ b/java/kotlin-extractor/src/main/kotlin/utils/Logger.kt @@ -73,6 +73,14 @@ open class LoggerBase(val logCounter: LogCounter) { return null } + private var file_number = -1 + private var file_number_diagnostic_number = 0 + + fun setFileNumber(index: Int) { + file_number = index + file_number_diagnostic_number = 0 + } + fun diagnostic(tw: TrapWriter, severity: Severity, msg: String, extraInfo: String?, locationString: String? = null, mkLocationId: () -> Label = { tw.unknownLocation }) { val diagnosticLoc = getDiagnosticLocation() val diagnosticLocStr = if(diagnosticLoc == null) "" else diagnosticLoc @@ -106,7 +114,9 @@ open class LoggerBase(val logCounter: LogCounter) { val ts = timestamp() // We don't actually make the location until after the `return` above val locationId = mkLocationId() - tw.writeDiagnostics(StarLabel(), "CodeQL Kotlin extractor", severity.sev, "", msg, "$ts $fullMsg", locationId) + val diagLabel = tw.getFreshIdLabel() + tw.writeDiagnostics(diagLabel, "CodeQL Kotlin extractor", severity.sev, "", msg, "$ts $fullMsg", locationId) + tw.writeDiagnostic_for(diagLabel, StringLabel("compilation"), file_number, file_number_diagnostic_number++) val locStr = if (locationString == null) "" else "At " + locationString + ": " val kind = if (severity <= Severity.WarnHigh) "WARN" else "ERROR" logStream.write("$ts [$kind] Diagnostic($diagnosticLocStr): $locStr$fullMsg")