Added StringTrimLowering to pipeline (#4647)

This commit is contained in:
LepilkinaElena
2021-01-21 19:53:08 +03:00
committed by Nikolay Krasko
parent 73297a4ef3
commit 71f44dce0f
4 changed files with 41 additions and 0 deletions
@@ -380,3 +380,9 @@ internal val foldConstantLoweringPhase = makeKonanFileOpPhase(
description = "Constant Folding", description = "Constant Folding",
prerequisite = setOf(flattenStringConcatenationPhase) prerequisite = setOf(flattenStringConcatenationPhase)
) )
internal val computeStringTrimPhase = makeKonanFileLoweringPhase(
::StringTrimLowering,
name = "StringTrimLowering",
description = "Compute trimIndent and trimMargin operations on constant strings"
)
@@ -221,6 +221,7 @@ internal val allLoweringsPhase = NamedCompilerPhase(
forLoopsPhase, forLoopsPhase,
flattenStringConcatenationPhase, flattenStringConcatenationPhase,
foldConstantLoweringPhase, foldConstantLoweringPhase,
computeStringTrimPhase,
stringConcatenationPhase, stringConcatenationPhase,
enumConstructorsPhase, enumConstructorsPhase,
initializersPhase, initializersPhase,
@@ -813,6 +813,10 @@ task hello0(type: KonanLocalTest) {
source = "runtime/basic/hello0.kt" source = "runtime/basic/hello0.kt"
} }
task stringTrim(type: KonanLocalTest) {
source = "codegen/stringTrim/stringTrim.kt"
}
standaloneTest("hello1") { standaloneTest("hello1") {
goldValue = "Hello World" goldValue = "Hello World"
testData = "Hello World\n" testData = "Hello World\n"
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package codegen.stringTrim.stringTrim
import kotlin.test.*
// TODO: check IR
fun constantIndent(): String {
return """
Hello,
World
""".trimIndent()
}
fun constantMargin(): String {
return """
|Hello,
|World
""".trimMargin()
}
@Test
fun runTest() {
assertTrue(constantIndent() === constantIndent())
assertTrue(constantMargin() === constantMargin())
}