Skip to content

Commit 5524d1e

Browse files
SvyatoslavScherbinaprojedi
authored andcommitted
[K/N] Support list-typed binary options
This commit adds support for declaring semicolon-separated list-typed binary options. I.e. `-Xbinary=foo=bar;baz` parsed to `[bar, baz]` with the nested parser. `-Xbinary=foo=` is parsed as an empty list.
1 parent 693c44e commit 5524d1e

File tree

1 file changed

+27
-1
lines changed
  • kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan

1 file changed

+27
-1
lines changed

kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BinaryOptions.kt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ open class BinaryOptionRegistry {
164164
}
165165
}
166166

167+
protected fun <T : Any> listOption(
168+
elementValueParser: BinaryOption.ValueParser<T>
169+
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, CompilerConfigurationKey<List<T>>>> = PropertyDelegateProvider { _, property ->
170+
val option = BinaryOption(property.name, ListValueParser(elementValueParser))
171+
register(option)
172+
ReadOnlyProperty { _, _ ->
173+
option.compilerConfigurationKey
174+
}
175+
}
176+
167177
protected inline fun <reified T : Enum<T>> option(noinline shortcut : (T) -> String? = { null }, noinline hideValue: (T) -> Boolean = { false }): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, CompilerConfigurationKey<T>>> =
168178
PropertyDelegateProvider { _, property ->
169179
val option = BinaryOption(property.name, EnumValueParser(enumValues<T>().toList(), shortcut, hideValue))
@@ -191,7 +201,23 @@ private object UIntValueParser : BinaryOption.ValueParser<UInt> {
191201
private object StringValueParser : BinaryOption.ValueParser<String> {
192202
override fun parse(value: String) = value
193203
override val validValuesHint: String?
194-
get() = null
204+
get() = "string"
205+
}
206+
207+
private class ListValueParser<T : Any>(
208+
val elementValueParser: BinaryOption.ValueParser<T>
209+
) : BinaryOption.ValueParser<List<T>> {
210+
override fun parse(value: String): List<T>? {
211+
if (value == "") return emptyList()
212+
213+
return value.split(";").map {
214+
elementValueParser.parse(it) ?: return null
215+
}
216+
}
217+
218+
override val validValuesHint: String?
219+
get() = "semicolon-separated list of ${elementValueParser.validValuesHint}"
220+
195221
}
196222

197223
@PublishedApi

0 commit comments

Comments
 (0)