Kotlin: Populate diagnostic_for

This commit is contained in:
Ian Lynagh
2022-03-10 19:31:07 +00:00
parent ac3c635fe3
commit 62ce28eb68
3 changed files with 12 additions and 10 deletions

View File

@@ -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())

View File

@@ -25,15 +25,6 @@ class StringLabel<T>(val name: String): Label<T> {
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<T>: Label<T> {
override fun toString(): String = "*"
}
// TODO: Remove this and all of its uses
fun <T> fakeLabel(): Label<T> {
if (false) {

View File

@@ -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<DbLocation> = { tw.unknownLocation }) {
val diagnosticLoc = getDiagnosticLocation()
val diagnosticLocStr = if(diagnosticLoc == null) "<unknown location>" 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<DbDiagnostic>()
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")