Added StringTrimLowering to pipeline (#4647)
This commit is contained in:
committed by
Nikolay Krasko
parent
73297a4ef3
commit
71f44dce0f
+6
@@ -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"
|
||||||
|
)
|
||||||
+1
@@ -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())
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user