Platform libs definitions for Android, small interop tweaks. (#804)

This commit is contained in:
Nikolay Igotti
2017-08-23 16:47:19 +03:00
committed by GitHub
parent 9667749b4e
commit 87a4fa9380
16 changed files with 152 additions and 33 deletions
@@ -64,6 +64,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
private sealed class DeclarationID {
data class USR(val usr: String) : DeclarationID()
object VaList : DeclarationID()
object VaListTag : DeclarationID()
object BuiltinVaList : DeclarationID()
}
@@ -105,6 +106,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
val spelling = getCursorSpelling(cursor)
return when (kind to spelling) {
CXCursorKind.CXCursor_StructDecl to "__va_list_tag" -> DeclarationID.VaListTag
CXCursorKind.CXCursor_StructDecl to "__va_list" -> DeclarationID.VaList
CXCursorKind.CXCursor_TypedefDecl to "__builtin_va_list" -> DeclarationID.BuiltinVaList
else -> error(spelling)
}
@@ -388,7 +390,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
if (canonicalType.kind != CXType_Unexposed) {
convertType(canonicalType)
} else {
throw NotImplementedError()
UnsupportedType
}
}
}
@@ -142,9 +142,10 @@ private fun processCodeSnippet(
val kind = cursor.kind
when {
state == VisitorState.EXPECT_VARIABLE && kind == CXCursorKind.CXCursor_VarDecl -> {
state = VisitorState.EXPECT_VARIABLE_VALUE
val evalResult = clang_Cursor_Evaluate(cursor)
if (evalResult != null) {
state = VisitorState.EXPECT_VARIABLE_VALUE
try {
evalResultKind = clang_EvalResult_getKind(evalResult)
if (evalResultKind == CXEvalResultKind.CXEval_Float) {
@@ -153,6 +154,8 @@ private fun processCodeSnippet(
} finally {
clang_EvalResult_dispose(evalResult)
}
} else {
state = VisitorState.INVALID
}
CXChildVisitResult.CXChildVisit_Recurse
}
@@ -17,7 +17,7 @@
package org.jetbrains.kotlin.native.interop.gen
val kotlinKeywords = setOf(
"as", "break", "class", "continue", "do", "else", "false", "for", "fun", "if", "in",
"as", "break", "class", "continue", "do", "dynamic", "else", "false", "for", "fun", "if", "in",
"interface", "is", "null", "object", "package", "return", "super", "this", "throw",
"true", "try", "typealias", "val", "var", "when", "while"
)
@@ -26,22 +26,22 @@ interface DeclarationMapper {
val PrimitiveType.kotlinType: String
get() = when (this) {
is CharType -> "Byte"
is CharType -> "kotlin.Byte"
is BoolType -> "Boolean"
is BoolType -> "kotlin.Boolean"
// TODO: C primitive types should probably be generated as type aliases for Kotlin types.
is IntegerType -> when (this.size) {
1 -> "Byte"
2 -> "Short"
4 -> "Int"
8 -> "Long"
1 -> "kotlin.Byte"
2 -> "kotlin.Short"
4 -> "kotlin.Int"
8 -> "kotlin.Long"
else -> TODO(this.toString())
}
is FloatingType -> when (this.size) {
4 -> "Float"
8 -> "Double"
4 -> "kotlin.Float"
8 -> "kotlin.Double"
else -> TODO(this.toString())
}
@@ -19,16 +19,16 @@ package org.jetbrains.kotlin.native.interop.gen
/**
* The type which has exact counterparts on both Kotlin and native side and can be directly passed through bridges.
*/
enum class BridgedType(val kotlinType: String) {
BYTE("Byte"),
SHORT("Short"),
INT("Int"),
LONG("Long"),
FLOAT("Float"),
DOUBLE("Double"),
enum class BridgedType(val kotlinType: String, val convertor: String? = null) {
BYTE("kotlin.Byte", "toByte"),
SHORT("kotlin.Short", "toShort"),
INT("kotlin.Int", "toInt"),
LONG("kotlin.Long", "toLong"),
FLOAT("kotlin.Float", "toFloat"),
DOUBLE("kotlin.Double", "toDouble"),
NATIVE_PTR("NativePtr"),
OBJC_POINTER("NativePtr"),
VOID("Unit")
VOID("kotlin.Unit")
}
data class BridgeTypedKotlinValue(val type: BridgedType, val value: KotlinExpression)
@@ -316,7 +316,7 @@ class StubGenerator(
val signed = field.type.getUnderlyingIntegerType().isSigned
val readBitsExpr =
"readBits(this.rawPtr, ${field.offset}, ${field.size}, $signed).to${rawType.kotlinType}()"
"readBits(this.rawPtr, ${field.offset}, ${field.size}, $signed).${rawType.convertor!!}()"
out(" get() = ${typeInfo.argFromBridged(readBitsExpr)}")
@@ -626,10 +626,10 @@ class StubGenerator(
}
val narrowedValue: Number = when (unwrappedType.kotlinType) {
"Byte" -> value.toByte()
"Short" -> value.toShort()
"Int" -> value.toInt()
"Long" -> value
"kotlin.Byte" -> value.toByte()
"kotlin.Short" -> value.toShort()
"kotlin.Int" -> value.toInt()
"kotlin.Long" -> value
else -> return null
}
@@ -199,7 +199,7 @@ private fun maybeExecuteHelper(dependenciesRoot: String, properties: Properties,
}
}
private fun Properties.getClangFlags(target: String, targetSysRoot: String) : List<String> {
private fun Properties.getClangFlags(target: String, targetSysRoot: String): List<String> {
val flags = getTargetSpecific("clangFlags", target)
if (flags == null) return emptyList()
return flags.replace("<sysrootDir>", targetSysRoot).split(' ')
@@ -263,8 +263,8 @@ private fun loadProperties(file: File?, substitutions: Map<String, String>): Pro
}
private fun Properties.storeProperties(file: File) {
file.outputStream().use {
this.store(it, null)
file.outputStream().use {
this.store(it, null)
}
}
@@ -303,7 +303,7 @@ private fun parseDefFile(file: File?, substitutions: Map<String, String>): Tripl
return Triple(properties, manifestAddendProperties, headerLines)
}
private fun Properties.duplicate() = Properties().apply{ putAll(this@duplicate) }
private fun Properties.duplicate() = Properties().apply { putAll(this@duplicate) }
private fun usage() {
println("""
@@ -355,8 +355,8 @@ private fun processLib(konanHome: String,
return
}
val (config, manifestAddendProperties, defHeaderLines)
= parseDefFile(defFile, substitutions)
val (config, manifestAddendProperties, defHeaderLines)
= parseDefFile(defFile, substitutions)
val konanFileName = args["-properties"]?.single() ?:
"${konanHome}/konan/konan.properties"
@@ -369,7 +369,7 @@ private fun processLib(konanHome: String,
val llvmHome = konanProperties.getHostSpecific("llvmHome")!!
val llvmInstallPath = "$dependencies/$llvmHome"
val additionalHeaders = args["-h"].orEmpty()
val additionalCompilerOpts = args["-copt"].orEmpty()+ args["-compilerOpts"].orEmpty()
val additionalCompilerOpts = args["-copt"].orEmpty() + args["-compilerOpts"].orEmpty()
val additionalLinkerOpts = args["-lopt"].orEmpty() + args["-linkerOpts"].orEmpty()
val generateShims = args["-shims"].isTrue()
val verbose = args["-verbose"].isTrue()
@@ -403,7 +403,7 @@ private fun processLib(konanHome: String,
val linker = args["-linker"]?.atMostOne() ?: config.getProperty("linker") ?: "clang"
val excludedFunctions = config.getSpaceSeparated("excludedFunctions").toSet()
val fqParts = args["-pkg"]?.atMostOne()?.let {
val fqParts = (args["-pkg"]?.atMostOne() ?: config.getProperty("package"))?.let {
it.split('.')
} ?: defFile!!.name.split('.').reversed().drop(1)
@@ -459,7 +459,7 @@ private fun processLib(konanHome: String,
}
manifestAddend?.parentFile?.mkdirs()
manifestAddend ?.let { manifestAddendProperties.storeProperties(it) }
manifestAddend?.let { manifestAddendProperties.storeProperties(it) }
val workDir = defFile?.absoluteFile?.parentFile ?: File(userDir)