Properly parse smap information

#KT-23369 Fixed
This commit is contained in:
Mikhael Bogdanov
2018-09-13 13:22:29 +02:00
parent 86ba5ebf29
commit a789fd92fe
10 changed files with 338 additions and 15 deletions
@@ -42,25 +42,24 @@ object SMAPParser {
fun parse(mappingInfo: String): SMAP {
val fileMappings = linkedMapOf<Int, FileMapping>()
val fileSectionStart = mappingInfo.indexOf(SMAP.FILE_SECTION) + SMAP.FILE_SECTION.length
val lineSectionAnchor = mappingInfo.indexOf(SMAP.LINE_SECTION)
val files = mappingInfo.substring(fileSectionStart, lineSectionAnchor)
val iterator = mappingInfo.lineSequence().dropWhile { it.trim() != SMAP.FILE_SECTION }.drop(1).iterator()
while (iterator.hasNext()) {
val fileDeclaration = iterator.next().trim()
if (fileDeclaration == SMAP.LINE_SECTION) break
val fileEntries = files.trim().split('+')
if (!fileDeclaration.startsWith('+')) {
throw AssertionError("File declaration should be in extended form, but: $fileDeclaration in $mappingInfo")
}
for (fileDeclaration in fileEntries) {
if (fileDeclaration == "") continue
val fileInternalName = fileDeclaration.trim()
val indexEnd = fileInternalName.indexOf(' ')
val fileIndex = fileInternalName.substring(0, indexEnd).toInt()
val newLine = fileInternalName.indexOf('\n')
val fileName = fileInternalName.substring(indexEnd + 1, newLine)
fileMappings[fileIndex] = FileMapping(fileName, fileInternalName.substring(newLine + 1).trim())
val indexAndFileInternalName = fileDeclaration.substringAfter("+ ").trim()
val fileIndex = indexAndFileInternalName.substringBefore(' ').toInt()
val fileName = indexAndFileInternalName.substringAfter(' ')
val path = iterator.next().trim()
fileMappings[fileIndex] = FileMapping(fileName, path)
}
val lines = mappingInfo.substring(lineSectionAnchor + SMAP.LINE_SECTION.length, mappingInfo.indexOf(SMAP.END)).trim().split('\n')
for (lineMapping in lines) {
for (lineMapping in iterator) {
if (lineMapping.trim() == SMAP.END) break
/*only simple mapping now*/
val targetSplit = lineMapping.indexOf(':')
val originalPart = lineMapping.substring(0, targetSplit)
+39
View File
@@ -0,0 +1,39 @@
// FILE: 1+a.kt
package test
inline fun inlineFun(lambda: () -> String): String {
return lambda()
}
// FILE: 2.kt
import test.*
fun box(): String {
return inlineFun { "OK" }
}
// FILE: 1+a.smap
// FILE: 2.smap
SMAP
2.kt
Kotlin
*S Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 1+a.kt
test/_1_aKt
*L
1#1,8:1
6#2:9
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
5#1:9
*E
+39
View File
@@ -0,0 +1,39 @@
// FILE: 1+ a.kt
package test
inline fun inlineFun(lambda: () -> String): String {
return lambda()
}
// FILE: 2.kt
import test.*
fun box(): String {
return inlineFun { "OK" }
}
// FILE: 1+ a.smap
// FILE: 2.smap
SMAP
2.kt
Kotlin
*S Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 1+ a.kt
test/_1__aKt
*L
1#1,8:1
6#2:9
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
5#1:9
*E
+39
View File
@@ -0,0 +1,39 @@
// FILE: + a.kt
package test
inline fun inlineFun(lambda: () -> String): String {
return lambda()
}
// FILE: 2.kt
import test.*
fun box(): String {
return inlineFun { "OK" }
}
// FILE: + a.smap
// FILE: 2.smap
SMAP
2.kt
Kotlin
*S Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 + a.kt
test/__aKt
*L
1#1,8:1
6#2:9
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
5#1:9
*E
+39
View File
@@ -0,0 +1,39 @@
// FILE: 1*E.kt
package test
inline fun inlineFun(lambda: () -> String): String {
return lambda()
}
// FILE: 2.kt
import test.*
fun box(): String {
return inlineFun { "OK" }
}
// FILE: 1+a.smap
// FILE: 2.smap
SMAP
2.kt
Kotlin
*S Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 1*E.kt
test/_1_EKt
*L
1#1,8:1
6#2:9
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
5#1:9
*E
+39
View File
@@ -0,0 +1,39 @@
// FILE: 1*F.kt
package test
inline fun inlineFun(lambda: () -> String): String {
return lambda()
}
// FILE: 2.kt
import test.*
fun box(): String {
return inlineFun { "OK" }
}
// FILE: 1+a.smap
// FILE: 2.smap
SMAP
2.kt
Kotlin
*S Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 1*F.kt
test/_1_FKt
*L
1#1,8:1
6#2:9
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
5#1:9
*E
+39
View File
@@ -0,0 +1,39 @@
// FILE: 1*L.kt
package test
inline fun inlineFun(lambda: () -> String): String {
return lambda()
}
// FILE: 2.kt
import test.*
fun box(): String {
return inlineFun { "OK" }
}
// FILE: 1+a.smap
// FILE: 2.smap
SMAP
2.kt
Kotlin
*S Kotlin
*F
+ 1 2.kt
_2Kt
+ 2 1*L.kt
test/_1_LKt
*L
1#1,8:1
6#2:9
*E
*S KotlinDebug
*F
+ 1 2.kt
_2Kt
*L
5#1:9
*E
@@ -2841,6 +2841,36 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
runTest("compiler/testData/codegen/boxInline/smap/defaultFunction.kt");
}
@TestMetadata("kt23369.kt")
public void testKt23369() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369.kt");
}
@TestMetadata("kt23369_2.kt")
public void testKt23369_2() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_2.kt");
}
@TestMetadata("kt23369_3.kt")
public void testKt23369_3() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_3.kt");
}
@TestMetadata("kt23369_E.kt")
public void testKt23369_E() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_E.kt");
}
@TestMetadata("kt23369_F.kt")
public void testKt23369_F() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_F.kt");
}
@TestMetadata("kt23369_L.kt")
public void testKt23369_L() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_L.kt");
}
@TestMetadata("oneFile.kt")
public void testOneFile() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/oneFile.kt");
@@ -2841,6 +2841,36 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
runTest("compiler/testData/codegen/boxInline/smap/defaultFunction.kt");
}
@TestMetadata("kt23369.kt")
public void testKt23369() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369.kt");
}
@TestMetadata("kt23369_2.kt")
public void testKt23369_2() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_2.kt");
}
@TestMetadata("kt23369_3.kt")
public void testKt23369_3() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_3.kt");
}
@TestMetadata("kt23369_E.kt")
public void testKt23369_E() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_E.kt");
}
@TestMetadata("kt23369_F.kt")
public void testKt23369_F() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_F.kt");
}
@TestMetadata("kt23369_L.kt")
public void testKt23369_L() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_L.kt");
}
@TestMetadata("oneFile.kt")
public void testOneFile() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/oneFile.kt");
@@ -2841,6 +2841,36 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
runTest("compiler/testData/codegen/boxInline/smap/defaultFunction.kt");
}
@TestMetadata("kt23369.kt")
public void testKt23369() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369.kt");
}
@TestMetadata("kt23369_2.kt")
public void testKt23369_2() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_2.kt");
}
@TestMetadata("kt23369_3.kt")
public void testKt23369_3() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_3.kt");
}
@TestMetadata("kt23369_E.kt")
public void testKt23369_E() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_E.kt");
}
@TestMetadata("kt23369_F.kt")
public void testKt23369_F() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_F.kt");
}
@TestMetadata("kt23369_L.kt")
public void testKt23369_L() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/kt23369_L.kt");
}
@TestMetadata("oneFile.kt")
public void testOneFile() throws Exception {
runTest("compiler/testData/codegen/boxInline/smap/oneFile.kt");