Get rid of explicit value case manipulations.

This commit is contained in:
Alexander Gorshenev
2017-12-15 17:26:35 +03:00
committed by alexander-gorshenev
parent d237afdea5
commit ff49153e79
7 changed files with 47 additions and 25 deletions
@@ -69,7 +69,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
internal val produce get() = configuration.get(KonanConfigKeys.PRODUCE)!!
private val prefix = produce.prefix(target)
private val suffix = produce.suffix(target)
val outputName = configuration.get(KonanConfigKeys.OUTPUT)?.removeSuffixIfPresent(suffix) ?: produce.name.toLowerCase()
val outputName = configuration.get(KonanConfigKeys.OUTPUT)?.removeSuffixIfPresent(suffix) ?: produce.userName
val outputFile = outputName
.prefixBaseNameIfNot(prefix)
.suffixIfNot(suffix)
@@ -17,12 +17,13 @@
package org.jetbrains.kotlin.backend.konan
import org.jetbrains.kotlin.backend.konan.util.*
import org.jetbrains.kotlin.konan.util.UserNamed
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
enum class KonanPhase(val description: String,
vararg prerequisite: KonanPhase,
var enabled: Boolean = true, var verbose: Boolean = false) {
var enabled: Boolean = true,
var verbose: Boolean = false) : UserNamed {
/* */ FRONTEND("Frontend builds AST"),
/* */ PSI_TO_IR("Psi to IR conversion"),
/* */ SERIALIZER("Serialize descriptor tree and inline IR bodies"),
@@ -73,7 +74,7 @@ enum class KonanPhase(val description: String,
}
object KonanPhases {
val phases = KonanPhase.values().associate { it.name.toLowerCase() to it }
val phases = KonanPhase.values().associate { it.userName to it }
fun known(name: String): String {
if (phases[name] == null) {
@@ -32,7 +32,7 @@ interface KonanLibraryLayout {
val targetsDir
get() = File(libDir, "targets")
val targetDir
get() = File(targetsDir, target!!.name.toLowerCase())
get() = File(targetsDir, target!!.userName)
val kotlinDir
get() = File(targetDir, "kotlin")
val nativeDir
+2 -2
View File
@@ -337,11 +337,11 @@ private ArrayList<DefFile> targetDefFiles(String target) {
}
private String targetToPlatform(String target) {
new TargetManager(target).target.family.name().toLowerCase()
new TargetManager(target).target.family.userName
}
private String targetToOs(String target) {
new TargetManager(target).target.detailedName.toLowerCase()
new TargetManager(target).target.detailedName
}
private String defFileToTaskName(String target, String name) {
@@ -16,28 +16,27 @@
package org.jetbrains.kotlin.konan.target
enum class Family(name:String, val exeSuffix:String, val dynamicPrefix: String, val dynamicSuffix: String) {
OSX( "osx" , "kexe", "lib", "dylib"),
IOS( "ios" , "kexe", "lib", "dylib"),
LINUX( "linux" , "kexe", "lib", "so" ),
WINDOWS("windows", "exe" , "" , "dll" ),
ANDROID("android", "so" , "lib", "so" ),
WASM( "wasm" , "wasm", "" , "wasm" )
import org.jetbrains.kotlin.konan.util.UserNamed
enum class Family(val exeSuffix:String, val dynamicPrefix: String, val dynamicSuffix: String) : UserNamed {
OSX ("kexe", "lib", "dylib"),
IOS ("kexe", "lib", "dylib"),
LINUX ("kexe", "lib", "so" ),
WINDOWS ("exe" , "" , "dll" ),
ANDROID ("so" , "lib", "so" ),
WASM ("wasm", "" , "wasm" )
}
enum class Architecture(val bitness: Int) {
enum class Architecture(val bitness: Int) : UserNamed {
X64(64),
ARM64(64),
ARM32(32),
MIPS32(32),
MIPSEL32(32),
WASM32(32);
val userName: String
get() = this.name.toLowerCase()
}
enum class KonanTarget(val family: Family, val architecture: Architecture, val detailedName: String, var enabled: Boolean = false) {
enum class KonanTarget(val family: Family, val architecture: Architecture, val detailedName: String, var enabled: Boolean = false) : UserNamed {
ANDROID_ARM32( Family.ANDROID, Architecture.ARM32, "android_arm32"),
ANDROID_ARM64( Family.ANDROID, Architecture.ARM64, "android_arm64"),
IPHONE( Family.IOS, Architecture.ARM64, "ios"),
@@ -49,14 +48,12 @@ enum class KonanTarget(val family: Family, val architecture: Architecture, val d
LINUX_MIPS32( Family.LINUX, Architecture.MIPS32, "linux_mips32"),
LINUX_MIPSEL32( Family.LINUX, Architecture.MIPSEL32, "linux_mipsel32"),
WASM32( Family.WASM, Architecture.WASM32, "wasm32");
val userName get() = name.toLowerCase()
}
fun hostTargetSuffix(host: KonanTarget, target: KonanTarget) =
if (target == host) host.detailedName else "${host.detailedName}-${target.detailedName}"
enum class CompilerOutputKind {
enum class CompilerOutputKind: UserNamed {
PROGRAM {
override fun suffix(target: KonanTarget?) = ".${target!!.family.exeSuffix}"
},
@@ -82,7 +79,7 @@ class TargetManager(val userRequest: String? = null) {
val targets = KonanTarget.values().associate{ it.userName to it }
val target = determineCurrent()
val targetName
get() = target.name.toLowerCase()
get() = target.userName
fun known(name: String): String {
@@ -165,7 +162,7 @@ class TargetManager(val userRequest: String? = null) {
val hostSuffix get() = host.detailedName
@JvmStatic
val hostName get() = host.name.toLowerCase()
val hostName get() = host.userName
init {
when (host) {
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.konan.util
// This interface is good for Enums to make enum members available to users
// as low case words.
interface UserNamed {
val name: String
val userName get() = name.toLowerCase()
}
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.konan.target.TargetManager
import java.io.File
internal val Project.host
get() = TargetManager.host.name.toLowerCase()
get() = TargetManager.host.userName
internal val Project.simpleOsName
get() = TargetManager.simpleOsName()