From 6c627a0b55e84b0ff67a4bb06c469d83d09557f3 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Wed, 1 Mar 2017 11:14:09 +0700 Subject: [PATCH] backend: add trivial utils for reporting compile errors --- .../kotlin/backend/konan/Reporting.kt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Reporting.kt diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Reporting.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Reporting.kt new file mode 100644 index 00000000000..96b33676548 --- /dev/null +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Reporting.kt @@ -0,0 +1,27 @@ +package org.jetbrains.kotlin.backend.konan + +import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.common.messages.MessageCollector +import org.jetbrains.kotlin.ir.IrElement +import org.jetbrains.kotlin.ir.declarations.IrFile + +internal val Context.messageCollector: MessageCollector + get() = this.config.configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) + +internal fun getCompilerMessageLocation(irFile: IrFile, irElement: IrElement): CompilerMessageLocation { + val sourceRangeInfo = irFile.fileEntry.getSourceRangeInfo(irElement.startOffset, irElement.endOffset) + return CompilerMessageLocation.create( + path = sourceRangeInfo.filePath, + line = sourceRangeInfo.startLineNumber, + column = sourceRangeInfo.startColumnNumber, + lineContent = null // TODO: retrieve the line content. + ) +} + +internal fun Context.reportCompilationError(message: String, irFile: IrFile, irElement: IrElement): Nothing { + val location = getCompilerMessageLocation(irFile, irElement) + this.messageCollector.report(CompilerMessageSeverity.ERROR, message, location) + throw KonanCompilationException() +} \ No newline at end of file