Kotlin: Keep our own stack of extractor contexts

For now we only use its length, but in the future we might use this to
give more informatino about the cause of warnings.
This commit is contained in:
Ian Lynagh
2022-03-08 12:01:29 +00:00
parent 9c2df20117
commit aad9e5601a
2 changed files with 12 additions and 2 deletions

View File

@@ -43,14 +43,19 @@ open class KotlinFileExtractor(
inline fun <T> with(kind: String, element: IrElement, f: () -> T): T {
val loc = tw.getLocationString(element)
globalExtensionState.context.push(ExtractorContext(kind, element))
try {
val depth = globalExtensionState.context.size
val depthDescription = "${"-".repeat(depth)} (${depth.toString()})"
val name = (element as? IrDeclarationWithName)?.name?.asString() ?: "<no name>"
logger.trace("Starting a $kind ($name) at $loc")
logger.trace("$depthDescription: Starting a $kind ($name) at $loc")
val result = f()
logger.trace("Finished a $kind ($name) at $loc")
logger.trace("$depthDescription: Finished a $kind ($name) at $loc")
return result
} catch(exception: Exception) {
throw Exception("While extracting a $kind at $loc", exception)
} finally {
globalExtensionState.context.pop()
}
}