Interop/Indexer: update prebuilts with new interop versions

also port Interop/Runtime/libcallbacks to new interop
This commit is contained in:
Svyatoslav Scherbina
2016-11-22 12:54:25 +07:00
parent c5f00c3301
commit 183f6a6d2f
3 changed files with 2037 additions and 1490 deletions
File diff suppressed because it is too large Load Diff
@@ -3,7 +3,7 @@ package org.jetbrains.kotlin.native.interop.indexer
import clang.* import clang.*
import clang.CXIdxEntityKind.* import clang.CXIdxEntityKind.*
import clang.CXTypeKind.* import clang.CXTypeKind.*
import kotlin_native.interop.* import kotlin_.cinterop.*
import java.io.File import java.io.File
private class StructDeclImpl(spelling: String) : StructDecl(spelling) { private class StructDeclImpl(spelling: String) : StructDecl(spelling) {
@@ -135,11 +135,12 @@ private class NativeIndexImpl : NativeIndex() {
CXCursorKind.CXCursor_UnionDecl -> return false CXCursorKind.CXCursor_UnionDecl -> return false
CXCursorKind.CXCursor_StructDecl -> { CXCursorKind.CXCursor_StructDecl -> {
val hasAttributes = arena.alloc(Int32Box) val hasAttributes = arena.alloc<CInt32Var>()
hasAttributes.value = 0 hasAttributes.value = 0
clang_visitChildren(structDefCursor, { cursor, parent, clientData -> clang_visitChildren(structDefCursor, staticCFunction { cursor, parent, clientData ->
if (clang_isAttribute(cursor.kind.value) != 0) { if (clang_isAttribute(cursor.kind.value) != 0) {
clientData.asRef(Int32Box)!!.value = 1 val hasAttributes = clientData!!.reinterpret<CInt32Var>().pointed
hasAttributes.value = 1
} }
CXChildVisitResult.CXChildVisit_Continue CXChildVisitResult.CXChildVisit_Continue
}, hasAttributes.ptr) }, hasAttributes.ptr)
@@ -220,7 +221,7 @@ private class NativeIndexImpl : NativeIndex() {
fun indexDeclaration(info: CXIdxDeclInfo) { fun indexDeclaration(info: CXIdxDeclInfo) {
val cursor = info.cursor val cursor = info.cursor
val entityInfo = info.entityInfo.value!! val entityInfo = info.entityInfo.pointed!!
val entityName = entityInfo.name.value?.asCString()?.toString() val entityName = entityInfo.name.value?.asCString()?.toString()
val kind = entityInfo.kind.value val kind = entityInfo.kind.value
@@ -230,7 +231,7 @@ private class NativeIndexImpl : NativeIndex() {
val type = convertType(clang_getCursorType(cursor, arena)) val type = convertType(clang_getCursorType(cursor, arena))
val offset = clang_Cursor_getOffsetOfField(cursor) val offset = clang_Cursor_getOffsetOfField(cursor)
val container = info.semanticContainer.value!! val container = info.semanticContainer.pointed!!
val structDef = getStructDeclAt(container.cursor).def!! val structDef = getStructDeclAt(container.cursor).def!!
structDef.fields.add(Field(name, type, offset)) structDef.fields.add(Field(name, type, offset))
} }
@@ -265,7 +266,7 @@ private class NativeIndexImpl : NativeIndex() {
} }
CXIdxEntity_EnumConstant -> { CXIdxEntity_EnumConstant -> {
val container = info.semanticContainer.value!! val container = info.semanticContainer.pointed!!
val name = entityName!! val name = entityName!!
val value = clang_getEnumConstantDeclValue(info.cursor) val value = clang_getEnumConstantDeclValue(info.cursor)
@@ -294,11 +295,11 @@ fun CXString.convertAndDispose(): String {
fun buildNativeIndexImpl(headerFile: File, args: List<String>): NativeIndex { fun buildNativeIndexImpl(headerFile: File, args: List<String>): NativeIndex {
// TODO: dispose all allocated memory and resources // TODO: dispose all allocated memory and resources
val args1 = args.map { CString.fromString(it)!!.asCharPtr() }.toTypedArray() val args1 = args.map { CString.fromString(it, nativeHeap)!!.asCharPtr() }.toTypedArray()
val index = clang_createIndex(0, 0) val index = clang_createIndex(0, 0)
val indexAction = clang_IndexAction_create(index) val indexAction = clang_IndexAction_create(index)
val callbacks = malloc(IndexerCallbacks.Companion) val callbacks = nativeHeap.alloc<IndexerCallbacks>()
val res = NativeIndexImpl() val res = NativeIndexImpl()
try { try {
@@ -307,23 +308,23 @@ fun buildNativeIndexImpl(headerFile: File, args: List<String>): NativeIndex {
try { try {
with(callbacks) { with(callbacks) {
abortQuery.setStatic(null) abortQuery.value = null
diagnostic.setStatic(null) diagnostic.value = null
enteredMainFile.setStatic(null) enteredMainFile.value = null
ppIncludedFile.setStatic(null) ppIncludedFile.value = null
importedASTFile.setStatic(null) importedASTFile.value = null
startedTranslationUnit.setStatic(null) startedTranslationUnit.value = null
indexDeclaration.setStatic { clientData, info -> indexDeclaration.value = staticCFunction { clientData, info ->
val index = StableObjPtr.fromValue(clientData!!).get() as NativeIndexImpl val index = StableObjPtr.fromValue(clientData!!).get() as NativeIndexImpl
index.indexDeclaration(info!!) index.indexDeclaration(info!!.pointed)
} }
indexEntityReference.setStatic(null) indexEntityReference.value = null
} }
val commandLineArgs = if (args1.size != 0) mallocNativeArrayOf(Int8Box.Companion, *args1)[0] else null val commandLineArgs = if (args1.size != 0) nativeHeap.allocArrayOfPointersTo(*args1)[0].ptr else null
clang_indexSourceFile(indexAction, clientData, callbacks, IndexerCallbacks.size, 0, headerFile.path, clang_indexSourceFile(indexAction, clientData, callbacks.ptr, IndexerCallbacks.size.toInt(),
commandLineArgs, args1.size, null, 0, null, 0) 0, headerFile.path, commandLineArgs, args1.size, null, 0, null, 0)
return res return res
+33 -33
View File
@@ -4,101 +4,101 @@
#include <ffi.h> #include <ffi.h>
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiTypeVoid * Method: ffiTypeVoid
* Signature: ()J * Signature: ()J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiTypeVoid(JNIEnv *env, jclass cls) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiTypeVoid(JNIEnv *env, jclass cls) {
return (jlong) &ffi_type_void; return (jlong) &ffi_type_void;
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiTypeUInt8 * Method: ffiTypeUInt8
* Signature: ()J * Signature: ()J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiTypeUInt8(JNIEnv *env, jclass cls) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiTypeUInt8(JNIEnv *env, jclass cls) {
return (jlong) &ffi_type_uint8; return (jlong) &ffi_type_uint8;
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiTypeSInt8 * Method: ffiTypeSInt8
* Signature: ()J * Signature: ()J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiTypeSInt8(JNIEnv *env, jclass cls) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiTypeSInt8(JNIEnv *env, jclass cls) {
return (jlong) &ffi_type_sint8; return (jlong) &ffi_type_sint8;
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiTypeUInt16 * Method: ffiTypeUInt16
* Signature: ()J * Signature: ()J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiTypeUInt16(JNIEnv *env, jclass cls) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiTypeUInt16(JNIEnv *env, jclass cls) {
return (jlong) &ffi_type_uint16; return (jlong) &ffi_type_uint16;
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiTypeSInt16 * Method: ffiTypeSInt16
* Signature: ()J * Signature: ()J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiTypeSInt16(JNIEnv *env, jclass cls) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiTypeSInt16(JNIEnv *env, jclass cls) {
return (jlong) &ffi_type_sint16; return (jlong) &ffi_type_sint16;
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiTypeUInt32 * Method: ffiTypeUInt32
* Signature: ()J * Signature: ()J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiTypeUInt32(JNIEnv *env, jclass cls) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiTypeUInt32(JNIEnv *env, jclass cls) {
return (jlong) &ffi_type_uint32; return (jlong) &ffi_type_uint32;
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiTypeSInt32 * Method: ffiTypeSInt32
* Signature: ()J * Signature: ()J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiTypeSInt32(JNIEnv *env, jclass cls) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiTypeSInt32(JNIEnv *env, jclass cls) {
return (jlong) &ffi_type_sint32; return (jlong) &ffi_type_sint32;
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiTypeUInt64 * Method: ffiTypeUInt64
* Signature: ()J * Signature: ()J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiTypeUInt64(JNIEnv *env, jclass cls) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiTypeUInt64(JNIEnv *env, jclass cls) {
return (jlong) &ffi_type_uint64; return (jlong) &ffi_type_uint64;
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiTypeSInt64 * Method: ffiTypeSInt64
* Signature: ()J * Signature: ()J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiTypeSInt64(JNIEnv *env, jclass cls) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiTypeSInt64(JNIEnv *env, jclass cls) {
return (jlong) &ffi_type_sint64; return (jlong) &ffi_type_sint64;
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiTypePointer * Method: ffiTypePointer
* Signature: ()J * Signature: ()J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiTypePointer(JNIEnv *env, jclass cls) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiTypePointer(JNIEnv *env, jclass cls) {
return (jlong) &ffi_type_pointer; return (jlong) &ffi_type_pointer;
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiTypeStruct0 * Method: ffiTypeStruct0
* Signature: (J)J * Signature: (J)J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiTypeStruct0(JNIEnv *env, jclass cls, jlong elements) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiTypeStruct0(JNIEnv *env, jclass cls, jlong elements) {
ffi_type* res = malloc(sizeof(ffi_type)); ffi_type* res = malloc(sizeof(ffi_type));
if (res != NULL) { if (res != NULL) {
res->size = 0; res->size = 0;
@@ -110,11 +110,11 @@ JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiTypeStruct0(J
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiCreateCif0 * Method: ffiCreateCif0
* Signature: (IJJ)J * Signature: (IJJ)J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiCreateCif0(JNIEnv *env, jclass cls, jint nArgs, jlong rType, jlong argTypes) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiCreateCif0(JNIEnv *env, jclass cls, jint nArgs, jlong rType, jlong argTypes) {
ffi_cif* res = malloc(sizeof(ffi_cif)); ffi_cif* res = malloc(sizeof(ffi_cif));
if (res != NULL) { if (res != NULL) {
ffi_status status = ffi_prep_cif(res, FFI_DEFAULT_ABI, nArgs, (ffi_type*)rType, (ffi_type**)argTypes); ffi_status status = ffi_prep_cif(res, FFI_DEFAULT_ABI, nArgs, (ffi_type*)rType, (ffi_type**)argTypes);
@@ -166,7 +166,7 @@ static void ffi_fun(ffi_cif *cif, void *ret, void **args, void *user_data) {
static jmethodID ffiFunImpl0 = NULL; static jmethodID ffiFunImpl0 = NULL;
static jclass cls = NULL; static jclass cls = NULL;
if (ffiFunImpl0 == NULL) { if (ffiFunImpl0 == NULL) {
jclass clsLocal = (*env)->FindClass(env, "kotlin_native/interop/CallbacksKt"); jclass clsLocal = (*env)->FindClass(env, "kotlin_/cinterop/JvmCallbacksKt");
checkException(env); checkException(env);
assert(clsLocal != NULL); assert(clsLocal != NULL);
@@ -184,11 +184,11 @@ static void ffi_fun(ffi_cif *cif, void *ret, void **args, void *user_data) {
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: ffiCreateClosure0 * Method: ffiCreateClosure0
* Signature: (JLjava/lang/Object;)J * Signature: (JLjava/lang/Object;)J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiCreateClosure0(JNIEnv *env, jclass cls, jlong ffiCif, jobject userData) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_ffiCreateClosure0(JNIEnv *env, jclass cls, jlong ffiCif, jobject userData) {
jobject userDataGlobalRef = (*env)->NewGlobalRef(env, userData); jobject userDataGlobalRef = (*env)->NewGlobalRef(env, userData);
if (userDataGlobalRef == NULL) { if (userDataGlobalRef == NULL) {
return (jlong)0; return (jlong)0;
@@ -211,29 +211,29 @@ JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_ffiCreateClosure
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: newGlobalRef * Method: newGlobalRef
* Signature: (Ljava/lang/Object;)J * Signature: (Ljava/lang/Object;)J
*/ */
JNIEXPORT jlong JNICALL Java_kotlin_1native_interop_CallbacksKt_newGlobalRef(JNIEnv *env, jclass cls, jobject obj) { JNIEXPORT jlong JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_newGlobalRef(JNIEnv *env, jclass cls, jobject obj) {
jobject res = (*env)->NewGlobalRef(env, obj); jobject res = (*env)->NewGlobalRef(env, obj);
return (jlong) res; return (jlong) res;
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: derefGlobalRef * Method: derefGlobalRef
* Signature: (J)Ljava/lang/Object; * Signature: (J)Ljava/lang/Object;
*/ */
JNIEXPORT jobject JNICALL Java_kotlin_1native_interop_CallbacksKt_derefGlobalRef(JNIEnv *env, jclass cls, jlong ref) { JNIEXPORT jobject JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_derefGlobalRef(JNIEnv *env, jclass cls, jlong ref) {
return (jobject) ref; return (jobject) ref;
} }
/* /*
* Class: kotlin_native_interop_CallbacksKt * Class: kotlin__cinterop_JvmCallbacksKt
* Method: deleteGlobalRef * Method: deleteGlobalRef
* Signature: (J)V * Signature: (J)V
*/ */
JNIEXPORT void JNICALL Java_kotlin_1native_interop_CallbacksKt_deleteGlobalRef(JNIEnv *env, jclass cls, jlong ref) { JNIEXPORT void JNICALL Java_kotlin_1_cinterop_JvmCallbacksKt_deleteGlobalRef(JNIEnv *env, jclass cls, jlong ref) {
(*env)->DeleteGlobalRef(env, (jobject) ref); (*env)->DeleteGlobalRef(env, (jobject) ref);
} }