Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aad9e56

Browse files
committed
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.
1 parent 9c2df20 commit aad9e56

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
44
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
55
import org.jetbrains.kotlin.ir.declarations.*
66
import org.jetbrains.kotlin.ir.util.*
7+
import org.jetbrains.kotlin.ir.IrElement
78
import java.io.File
89
import java.io.FileOutputStream
910
import java.nio.file.Files
1011
import java.nio.file.Paths
12+
import java.util.Stack
1113
import com.semmle.util.files.FileUtil
1214
import kotlin.system.exitProcess
1315

@@ -116,6 +118,8 @@ class KotlinExtractorExtension(
116118
}
117119
}
118120

121+
data class ExtractorContext(val kind: String, val element: IrElement)
122+
119123
class KotlinExtractorGlobalState {
120124
val genericSpecialisationsExtracted = HashSet<String>()
121125
// These three record mappings of classes, functions and fields that should be replaced wherever they are found.
@@ -125,6 +129,7 @@ class KotlinExtractorGlobalState {
125129
val syntheticToRealClassMap = HashMap<IrClass, IrClass?>()
126130
val syntheticToRealFunctionMap = HashMap<IrSimpleFunction, IrSimpleFunction?>()
127131
val syntheticToRealFieldMap = HashMap<IrField, IrField?>()
132+
val context = Stack<ExtractorContext>()
128133
}
129134

130135
/*

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,19 @@ open class KotlinFileExtractor(
4343

4444
inline fun <T> with(kind: String, element: IrElement, f: () -> T): T {
4545
val loc = tw.getLocationString(element)
46+
globalExtensionState.context.push(ExtractorContext(kind, element))
4647
try {
48+
val depth = globalExtensionState.context.size
49+
val depthDescription = "${"-".repeat(depth)} (${depth.toString()})"
4750
val name = (element as? IrDeclarationWithName)?.name?.asString() ?: "<no name>"
48-
logger.trace("Starting a $kind ($name) at $loc")
51+
logger.trace("$depthDescription: Starting a $kind ($name) at $loc")
4952
val result = f()
50-
logger.trace("Finished a $kind ($name) at $loc")
53+
logger.trace("$depthDescription: Finished a $kind ($name) at $loc")
5154
return result
5255
} catch(exception: Exception) {
5356
throw Exception("While extracting a $kind at $loc", exception)
57+
} finally {
58+
globalExtensionState.context.pop()
5459
}
5560
}
5661

0 commit comments

Comments
 (0)