committed by
Nikolay Igotti
parent
e36b5d3476
commit
c1d9dc1cbb
@@ -1,3 +1,4 @@
|
||||
@file:Suppress("UNUSED_EXPRESSION")
|
||||
package clang
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
@@ -2845,8 +2846,8 @@ class __mbstate_t(override val rawPtr: NativePtr) : CStructVar() {
|
||||
|
||||
companion object : Type(128, 8)
|
||||
|
||||
val __mbstate8: CArray<CInt8Var>
|
||||
get() = memberAt(0)
|
||||
val __mbstate8: CArrayPointer<CInt8Var>
|
||||
get() = arrayMemberAt(0)
|
||||
|
||||
val _mbstateL: CInt64Var
|
||||
get() = memberAt(0)
|
||||
@@ -2875,8 +2876,8 @@ class _opaque_pthread_attr_t(override val rawPtr: NativePtr) : CStructVar() {
|
||||
val __sig: CInt64Var
|
||||
get() = memberAt(0)
|
||||
|
||||
val __opaque: CArray<CInt8Var>
|
||||
get() = memberAt(8)
|
||||
val __opaque: CArrayPointer<CInt8Var>
|
||||
get() = arrayMemberAt(8)
|
||||
|
||||
}
|
||||
|
||||
@@ -2887,8 +2888,8 @@ class _opaque_pthread_cond_t(override val rawPtr: NativePtr) : CStructVar() {
|
||||
val __sig: CInt64Var
|
||||
get() = memberAt(0)
|
||||
|
||||
val __opaque: CArray<CInt8Var>
|
||||
get() = memberAt(8)
|
||||
val __opaque: CArrayPointer<CInt8Var>
|
||||
get() = arrayMemberAt(8)
|
||||
|
||||
}
|
||||
|
||||
@@ -2899,8 +2900,8 @@ class _opaque_pthread_condattr_t(override val rawPtr: NativePtr) : CStructVar()
|
||||
val __sig: CInt64Var
|
||||
get() = memberAt(0)
|
||||
|
||||
val __opaque: CArray<CInt8Var>
|
||||
get() = memberAt(8)
|
||||
val __opaque: CArrayPointer<CInt8Var>
|
||||
get() = arrayMemberAt(8)
|
||||
|
||||
}
|
||||
|
||||
@@ -2911,8 +2912,8 @@ class _opaque_pthread_mutex_t(override val rawPtr: NativePtr) : CStructVar() {
|
||||
val __sig: CInt64Var
|
||||
get() = memberAt(0)
|
||||
|
||||
val __opaque: CArray<CInt8Var>
|
||||
get() = memberAt(8)
|
||||
val __opaque: CArrayPointer<CInt8Var>
|
||||
get() = arrayMemberAt(8)
|
||||
|
||||
}
|
||||
|
||||
@@ -2923,8 +2924,8 @@ class _opaque_pthread_mutexattr_t(override val rawPtr: NativePtr) : CStructVar()
|
||||
val __sig: CInt64Var
|
||||
get() = memberAt(0)
|
||||
|
||||
val __opaque: CArray<CInt8Var>
|
||||
get() = memberAt(8)
|
||||
val __opaque: CArrayPointer<CInt8Var>
|
||||
get() = arrayMemberAt(8)
|
||||
|
||||
}
|
||||
|
||||
@@ -2935,8 +2936,8 @@ class _opaque_pthread_once_t(override val rawPtr: NativePtr) : CStructVar() {
|
||||
val __sig: CInt64Var
|
||||
get() = memberAt(0)
|
||||
|
||||
val __opaque: CArray<CInt8Var>
|
||||
get() = memberAt(8)
|
||||
val __opaque: CArrayPointer<CInt8Var>
|
||||
get() = arrayMemberAt(8)
|
||||
|
||||
}
|
||||
|
||||
@@ -2947,8 +2948,8 @@ class _opaque_pthread_rwlock_t(override val rawPtr: NativePtr) : CStructVar() {
|
||||
val __sig: CInt64Var
|
||||
get() = memberAt(0)
|
||||
|
||||
val __opaque: CArray<CInt8Var>
|
||||
get() = memberAt(8)
|
||||
val __opaque: CArrayPointer<CInt8Var>
|
||||
get() = arrayMemberAt(8)
|
||||
|
||||
}
|
||||
|
||||
@@ -2959,8 +2960,8 @@ class _opaque_pthread_rwlockattr_t(override val rawPtr: NativePtr) : CStructVar(
|
||||
val __sig: CInt64Var
|
||||
get() = memberAt(0)
|
||||
|
||||
val __opaque: CArray<CInt8Var>
|
||||
get() = memberAt(8)
|
||||
val __opaque: CArrayPointer<CInt8Var>
|
||||
get() = arrayMemberAt(8)
|
||||
|
||||
}
|
||||
|
||||
@@ -2974,8 +2975,8 @@ class _opaque_pthread_t(override val rawPtr: NativePtr) : CStructVar() {
|
||||
val __cleanup_stack: CPointerVar<__darwin_pthread_handler_rec>
|
||||
get() = memberAt(8)
|
||||
|
||||
val __opaque: CArray<CInt8Var>
|
||||
get() = memberAt(16)
|
||||
val __opaque: CArrayPointer<CInt8Var>
|
||||
get() = arrayMemberAt(16)
|
||||
|
||||
}
|
||||
|
||||
@@ -3092,8 +3093,8 @@ class CXFileUniqueID(override val rawPtr: NativePtr) : CStructVar() {
|
||||
|
||||
companion object : Type(24, 8)
|
||||
|
||||
val data: CArray<CInt64Var>
|
||||
get() = memberAt(0)
|
||||
val data: CArrayPointer<CInt64Var>
|
||||
get() = arrayMemberAt(0)
|
||||
|
||||
}
|
||||
|
||||
@@ -3103,8 +3104,8 @@ class CXSourceLocation(override val rawPtr: NativePtr) : CStructVar() {
|
||||
|
||||
companion object : Type(24, 8)
|
||||
|
||||
val ptr_data: CArray<COpaquePointerVar>
|
||||
get() = memberAt(0)
|
||||
val ptr_data: CArrayPointer<COpaquePointerVar>
|
||||
get() = arrayMemberAt(0)
|
||||
|
||||
val int_data: CInt32Var
|
||||
get() = memberAt(16)
|
||||
@@ -3115,8 +3116,8 @@ class CXSourceRange(override val rawPtr: NativePtr) : CStructVar() {
|
||||
|
||||
companion object : Type(24, 8)
|
||||
|
||||
val ptr_data: CArray<COpaquePointerVar>
|
||||
get() = memberAt(0)
|
||||
val ptr_data: CArrayPointer<COpaquePointerVar>
|
||||
get() = arrayMemberAt(0)
|
||||
|
||||
val begin_int_data: CInt32Var
|
||||
get() = memberAt(16)
|
||||
@@ -3175,8 +3176,8 @@ class CXCursor(override val rawPtr: NativePtr) : CStructVar() {
|
||||
val xdata: CInt32Var
|
||||
get() = memberAt(4)
|
||||
|
||||
val data: CArray<COpaquePointerVar>
|
||||
get() = memberAt(8)
|
||||
val data: CArrayPointer<COpaquePointerVar>
|
||||
get() = arrayMemberAt(8)
|
||||
|
||||
}
|
||||
|
||||
@@ -3213,8 +3214,8 @@ class CXType(override val rawPtr: NativePtr) : CStructVar() {
|
||||
val kind: CXTypeKind.Var
|
||||
get() = memberAt(0)
|
||||
|
||||
val data: CArray<COpaquePointerVar>
|
||||
get() = memberAt(8)
|
||||
val data: CArrayPointer<COpaquePointerVar>
|
||||
get() = arrayMemberAt(8)
|
||||
|
||||
}
|
||||
|
||||
@@ -3222,8 +3223,8 @@ class CXToken(override val rawPtr: NativePtr) : CStructVar() {
|
||||
|
||||
companion object : Type(24, 8)
|
||||
|
||||
val int_data: CArray<CInt32Var>
|
||||
get() = memberAt(0)
|
||||
val int_data: CArrayPointer<CInt32Var>
|
||||
get() = arrayMemberAt(0)
|
||||
|
||||
val ptr_data: COpaquePointerVar
|
||||
get() = memberAt(16)
|
||||
@@ -3270,8 +3271,8 @@ class CXIdxLoc(override val rawPtr: NativePtr) : CStructVar() {
|
||||
|
||||
companion object : Type(24, 8)
|
||||
|
||||
val ptr_data: CArray<COpaquePointerVar>
|
||||
get() = memberAt(0)
|
||||
val ptr_data: CArrayPointer<COpaquePointerVar>
|
||||
get() = arrayMemberAt(0)
|
||||
|
||||
val int_data: CInt32Var
|
||||
get() = memberAt(16)
|
||||
@@ -3623,7 +3624,7 @@ val _CLOCK_UPTIME_RAW_APPROX: clockid_t = 9
|
||||
val _CLOCK_PROCESS_CPUTIME_ID: clockid_t = 12
|
||||
val _CLOCK_THREAD_CPUTIME_ID: clockid_t = 16
|
||||
|
||||
enum class CXErrorCode(val value: Int) {
|
||||
enum class CXErrorCode(override val value: Int) : CEnum {
|
||||
CXError_Success(0),
|
||||
CXError_Failure(1),
|
||||
CXError_Crashed(2),
|
||||
@@ -3643,7 +3644,7 @@ enum class CXErrorCode(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXAvailabilityKind(val value: Int) {
|
||||
enum class CXAvailabilityKind(override val value: Int) : CEnum {
|
||||
CXAvailability_Available(0),
|
||||
CXAvailability_Deprecated(1),
|
||||
CXAvailability_NotAvailable(2),
|
||||
@@ -3670,7 +3671,7 @@ val CXGlobalOpt_ThreadBackgroundPriorityForIndexing: CXGlobalOptFlags = 1
|
||||
val CXGlobalOpt_ThreadBackgroundPriorityForEditing: CXGlobalOptFlags = 2
|
||||
val CXGlobalOpt_ThreadBackgroundPriorityForAll: CXGlobalOptFlags = 3
|
||||
|
||||
enum class CXDiagnosticSeverity(val value: Int) {
|
||||
enum class CXDiagnosticSeverity(override val value: Int) : CEnum {
|
||||
CXDiagnostic_Ignored(0),
|
||||
CXDiagnostic_Note(1),
|
||||
CXDiagnostic_Warning(2),
|
||||
@@ -3690,7 +3691,7 @@ enum class CXDiagnosticSeverity(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXLoadDiag_Error(val value: Int) {
|
||||
enum class CXLoadDiag_Error(override val value: Int) : CEnum {
|
||||
CXLoadDiag_None(0),
|
||||
CXLoadDiag_Unknown(1),
|
||||
CXLoadDiag_CannotLoad(2),
|
||||
@@ -3739,7 +3740,7 @@ typealias CXSaveTranslationUnit_Flags = Int
|
||||
|
||||
val CXSaveTranslationUnit_None: CXSaveTranslationUnit_Flags = 0
|
||||
|
||||
enum class CXSaveError(val value: Int) {
|
||||
enum class CXSaveError(override val value: Int) : CEnum {
|
||||
CXSaveError_None(0),
|
||||
CXSaveError_Unknown(1),
|
||||
CXSaveError_TranslationErrors(2),
|
||||
@@ -3763,7 +3764,7 @@ typealias CXReparse_Flags = Int
|
||||
|
||||
val CXReparse_None: CXReparse_Flags = 0
|
||||
|
||||
enum class CXTUResourceUsageKind(val value: Int) {
|
||||
enum class CXTUResourceUsageKind(override val value: Int) : CEnum {
|
||||
CXTUResourceUsage_AST(1),
|
||||
CXTUResourceUsage_Identifiers(2),
|
||||
CXTUResourceUsage_Selectors(3),
|
||||
@@ -3796,7 +3797,7 @@ enum class CXTUResourceUsageKind(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXCursorKind(val value: Int) {
|
||||
enum class CXCursorKind(override val value: Int) : CEnum {
|
||||
CXCursor_UnexposedDecl(1),
|
||||
CXCursor_StructDecl(2),
|
||||
CXCursor_UnionDecl(3),
|
||||
@@ -4031,7 +4032,7 @@ enum class CXCursorKind(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXLinkageKind(val value: Int) {
|
||||
enum class CXLinkageKind(override val value: Int) : CEnum {
|
||||
CXLinkage_Invalid(0),
|
||||
CXLinkage_NoLinkage(1),
|
||||
CXLinkage_Internal(2),
|
||||
@@ -4051,7 +4052,7 @@ enum class CXLinkageKind(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXVisibilityKind(val value: Int) {
|
||||
enum class CXVisibilityKind(override val value: Int) : CEnum {
|
||||
CXVisibility_Invalid(0),
|
||||
CXVisibility_Hidden(1),
|
||||
CXVisibility_Protected(2),
|
||||
@@ -4070,7 +4071,7 @@ enum class CXVisibilityKind(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXLanguageKind(val value: Int) {
|
||||
enum class CXLanguageKind(override val value: Int) : CEnum {
|
||||
CXLanguage_Invalid(0),
|
||||
CXLanguage_C(1),
|
||||
CXLanguage_ObjC(2),
|
||||
@@ -4089,7 +4090,7 @@ enum class CXLanguageKind(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXTypeKind(val value: Int) {
|
||||
enum class CXTypeKind(override val value: Int) : CEnum {
|
||||
CXType_Invalid(0),
|
||||
CXType_Unexposed(1),
|
||||
CXType_Void(2),
|
||||
@@ -4157,7 +4158,7 @@ enum class CXTypeKind(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXCallingConv(val value: Int) {
|
||||
enum class CXCallingConv(override val value: Int) : CEnum {
|
||||
CXCallingConv_Default(0),
|
||||
CXCallingConv_C(1),
|
||||
CXCallingConv_X86StdCall(2),
|
||||
@@ -4189,7 +4190,7 @@ enum class CXCallingConv(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXTemplateArgumentKind(val value: Int) {
|
||||
enum class CXTemplateArgumentKind(override val value: Int) : CEnum {
|
||||
CXTemplateArgumentKind_Null(0),
|
||||
CXTemplateArgumentKind_Type(1),
|
||||
CXTemplateArgumentKind_Declaration(2),
|
||||
@@ -4230,7 +4231,7 @@ val CXRefQualifier_None: CXRefQualifierKind = 0
|
||||
val CXRefQualifier_LValue: CXRefQualifierKind = 1
|
||||
val CXRefQualifier_RValue: CXRefQualifierKind = 2
|
||||
|
||||
enum class CX_CXXAccessSpecifier(val value: Int) {
|
||||
enum class CX_CXXAccessSpecifier(override val value: Int) : CEnum {
|
||||
CX_CXXInvalidAccessSpecifier(0),
|
||||
CX_CXXPublic(1),
|
||||
CX_CXXProtected(2),
|
||||
@@ -4249,7 +4250,7 @@ enum class CX_CXXAccessSpecifier(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CX_StorageClass(val value: Int) {
|
||||
enum class CX_StorageClass(override val value: Int) : CEnum {
|
||||
CX_SC_Invalid(0),
|
||||
CX_SC_None(1),
|
||||
CX_SC_Extern(2),
|
||||
@@ -4272,7 +4273,7 @@ enum class CX_StorageClass(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXChildVisitResult(val value: Int) {
|
||||
enum class CXChildVisitResult(override val value: Int) : CEnum {
|
||||
CXChildVisit_Break(0),
|
||||
CXChildVisit_Continue(1),
|
||||
CXChildVisit_Recurse(2),
|
||||
@@ -4326,7 +4327,7 @@ val CXNameRange_WantQualifier: CXNameRefFlags = 1
|
||||
val CXNameRange_WantTemplateArgs: CXNameRefFlags = 2
|
||||
val CXNameRange_WantSinglePiece: CXNameRefFlags = 4
|
||||
|
||||
enum class CXTokenKind(val value: Int) {
|
||||
enum class CXTokenKind(override val value: Int) : CEnum {
|
||||
CXToken_Punctuation(0),
|
||||
CXToken_Keyword(1),
|
||||
CXToken_Identifier(2),
|
||||
@@ -4346,7 +4347,7 @@ enum class CXTokenKind(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXCompletionChunkKind(val value: Int) {
|
||||
enum class CXCompletionChunkKind(override val value: Int) : CEnum {
|
||||
CXCompletionChunk_Optional(0),
|
||||
CXCompletionChunk_TypedText(1),
|
||||
CXCompletionChunk_Text(2),
|
||||
@@ -4417,7 +4418,7 @@ val CXCompletionContext_MacroName: CXCompletionContext = 1048576
|
||||
val CXCompletionContext_NaturalLanguage: CXCompletionContext = 2097152
|
||||
val CXCompletionContext_Unknown: CXCompletionContext = 4194303
|
||||
|
||||
enum class CXEvalResultKind(val value: Int) {
|
||||
enum class CXEvalResultKind(override val value: Int) : CEnum {
|
||||
CXEval_Int(1),
|
||||
CXEval_Float(2),
|
||||
CXEval_ObjCStrLiteral(3),
|
||||
@@ -4439,7 +4440,7 @@ enum class CXEvalResultKind(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXVisitorResult(val value: Int) {
|
||||
enum class CXVisitorResult(override val value: Int) : CEnum {
|
||||
CXVisit_Break(0),
|
||||
CXVisit_Continue(1),
|
||||
;
|
||||
@@ -4456,7 +4457,7 @@ enum class CXVisitorResult(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXResult(val value: Int) {
|
||||
enum class CXResult(override val value: Int) : CEnum {
|
||||
CXResult_Success(0),
|
||||
CXResult_Invalid(1),
|
||||
CXResult_VisitBreak(2),
|
||||
@@ -4474,7 +4475,7 @@ enum class CXResult(val value: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class CXIdxEntityKind(val value: Int) {
|
||||
enum class CXIdxEntityKind(override val value: Int) : CEnum {
|
||||
CXIdxEntity_Unexposed(0),
|
||||
CXIdxEntity_Typedef(1),
|
||||
CXIdxEntity_Function(2),
|
||||
@@ -4653,87 +4654,87 @@ typealias __darwin_wint_tVar = CInt32VarWithValueMappedTo<__darwin_wint_t>
|
||||
typealias __darwin_wint_t = Int
|
||||
|
||||
object CFunctionType1 : CAdaptedFunctionTypeImpl<(CXCursor, CXCursor, COpaquePointer?) -> CXChildVisitResult>(UInt32, Struct(UInt32, SInt32, Struct(Pointer, Pointer, Pointer)), Struct(UInt32, SInt32, Struct(Pointer, Pointer, Pointer)), Pointer) {
|
||||
override fun invoke(function: (CXCursor, CXCursor, COpaquePointer?) -> CXChildVisitResult, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (CXCursor, CXCursor, COpaquePointer?) -> CXChildVisitResult, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<CXCursor>().pointed, args[1].value!!.reinterpret<CXCursor>().pointed, args[2].value!!.reinterpret<COpaquePointerVar>().pointed.value)
|
||||
ret.reinterpret<CXChildVisitResult.Var>().pointed.value = res
|
||||
}
|
||||
}
|
||||
|
||||
object CFunctionType2 : CAdaptedFunctionTypeImpl<(COpaquePointer?) -> Unit>(Void, Pointer) {
|
||||
override fun invoke(function: (COpaquePointer?) -> Unit, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (COpaquePointer?) -> Unit, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<COpaquePointerVar>().pointed.value)
|
||||
}
|
||||
}
|
||||
|
||||
object CFunctionType3 : CAdaptedFunctionTypeImpl<(COpaquePointer?, CPointer<CXSourceLocation>?, Int, COpaquePointer?) -> Unit>(Void, Pointer, Pointer, UInt32, Pointer) {
|
||||
override fun invoke(function: (COpaquePointer?, CPointer<CXSourceLocation>?, Int, COpaquePointer?) -> Unit, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (COpaquePointer?, CPointer<CXSourceLocation>?, Int, COpaquePointer?) -> Unit, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<COpaquePointerVar>().pointed.value, args[1].value!!.reinterpret<CPointerVar<CXSourceLocation>>().pointed.value, args[2].value!!.reinterpret<CInt32Var>().pointed.value, args[3].value!!.reinterpret<COpaquePointerVar>().pointed.value)
|
||||
}
|
||||
}
|
||||
|
||||
object CFunctionType4 : CAdaptedFunctionTypeImpl<(CXCursor, COpaquePointer?) -> CXVisitorResult>(UInt32, Struct(UInt32, SInt32, Struct(Pointer, Pointer, Pointer)), Pointer) {
|
||||
override fun invoke(function: (CXCursor, COpaquePointer?) -> CXVisitorResult, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (CXCursor, COpaquePointer?) -> CXVisitorResult, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<CXCursor>().pointed, args[1].value!!.reinterpret<COpaquePointerVar>().pointed.value)
|
||||
ret.reinterpret<CXVisitorResult.Var>().pointed.value = res
|
||||
}
|
||||
}
|
||||
|
||||
object CFunctionType5 : CAdaptedFunctionTypeImpl<(COpaquePointer?, CXCursor, CXSourceRange) -> CXVisitorResult>(UInt32, Pointer, Struct(UInt32, SInt32, Struct(Pointer, Pointer, Pointer)), Struct(Struct(Pointer, Pointer), UInt32, UInt32)) {
|
||||
override fun invoke(function: (COpaquePointer?, CXCursor, CXSourceRange) -> CXVisitorResult, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (COpaquePointer?, CXCursor, CXSourceRange) -> CXVisitorResult, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<COpaquePointerVar>().pointed.value, args[1].value!!.reinterpret<CXCursor>().pointed, args[2].value!!.reinterpret<CXSourceRange>().pointed)
|
||||
ret.reinterpret<CXVisitorResult.Var>().pointed.value = res
|
||||
}
|
||||
}
|
||||
|
||||
object CFunctionType6 : CAdaptedFunctionTypeImpl<(COpaquePointer?, COpaquePointer?) -> Int>(SInt32, Pointer, Pointer) {
|
||||
override fun invoke(function: (COpaquePointer?, COpaquePointer?) -> Int, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (COpaquePointer?, COpaquePointer?) -> Int, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<COpaquePointerVar>().pointed.value, args[1].value!!.reinterpret<COpaquePointerVar>().pointed.value)
|
||||
ret.reinterpret<CInt32Var>().pointed.value = res
|
||||
}
|
||||
}
|
||||
|
||||
object CFunctionType7 : CAdaptedFunctionTypeImpl<(COpaquePointer?, COpaquePointer?, COpaquePointer?) -> Unit>(Void, Pointer, Pointer, Pointer) {
|
||||
override fun invoke(function: (COpaquePointer?, COpaquePointer?, COpaquePointer?) -> Unit, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (COpaquePointer?, COpaquePointer?, COpaquePointer?) -> Unit, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<COpaquePointerVar>().pointed.value, args[1].value!!.reinterpret<COpaquePointerVar>().pointed.value, args[2].value!!.reinterpret<COpaquePointerVar>().pointed.value)
|
||||
}
|
||||
}
|
||||
|
||||
object CFunctionType8 : CAdaptedFunctionTypeImpl<(COpaquePointer?, COpaquePointer?, COpaquePointer?) -> COpaquePointer?>(Pointer, Pointer, Pointer, Pointer) {
|
||||
override fun invoke(function: (COpaquePointer?, COpaquePointer?, COpaquePointer?) -> COpaquePointer?, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (COpaquePointer?, COpaquePointer?, COpaquePointer?) -> COpaquePointer?, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<COpaquePointerVar>().pointed.value, args[1].value!!.reinterpret<COpaquePointerVar>().pointed.value, args[2].value!!.reinterpret<COpaquePointerVar>().pointed.value)
|
||||
ret.reinterpret<COpaquePointerVar>().pointed.value = res
|
||||
}
|
||||
}
|
||||
|
||||
object CFunctionType9 : CAdaptedFunctionTypeImpl<(COpaquePointer?, CPointer<CXIdxIncludedFileInfo>?) -> COpaquePointer?>(Pointer, Pointer, Pointer) {
|
||||
override fun invoke(function: (COpaquePointer?, CPointer<CXIdxIncludedFileInfo>?) -> COpaquePointer?, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (COpaquePointer?, CPointer<CXIdxIncludedFileInfo>?) -> COpaquePointer?, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<COpaquePointerVar>().pointed.value, args[1].value!!.reinterpret<CPointerVar<CXIdxIncludedFileInfo>>().pointed.value)
|
||||
ret.reinterpret<COpaquePointerVar>().pointed.value = res
|
||||
}
|
||||
}
|
||||
|
||||
object CFunctionType10 : CAdaptedFunctionTypeImpl<(COpaquePointer?, CPointer<CXIdxImportedASTFileInfo>?) -> COpaquePointer?>(Pointer, Pointer, Pointer) {
|
||||
override fun invoke(function: (COpaquePointer?, CPointer<CXIdxImportedASTFileInfo>?) -> COpaquePointer?, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (COpaquePointer?, CPointer<CXIdxImportedASTFileInfo>?) -> COpaquePointer?, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<COpaquePointerVar>().pointed.value, args[1].value!!.reinterpret<CPointerVar<CXIdxImportedASTFileInfo>>().pointed.value)
|
||||
ret.reinterpret<COpaquePointerVar>().pointed.value = res
|
||||
}
|
||||
}
|
||||
|
||||
object CFunctionType11 : CAdaptedFunctionTypeImpl<(COpaquePointer?, COpaquePointer?) -> COpaquePointer?>(Pointer, Pointer, Pointer) {
|
||||
override fun invoke(function: (COpaquePointer?, COpaquePointer?) -> COpaquePointer?, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (COpaquePointer?, COpaquePointer?) -> COpaquePointer?, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<COpaquePointerVar>().pointed.value, args[1].value!!.reinterpret<COpaquePointerVar>().pointed.value)
|
||||
ret.reinterpret<COpaquePointerVar>().pointed.value = res
|
||||
}
|
||||
}
|
||||
|
||||
object CFunctionType12 : CAdaptedFunctionTypeImpl<(COpaquePointer?, CPointer<CXIdxDeclInfo>?) -> Unit>(Void, Pointer, Pointer) {
|
||||
override fun invoke(function: (COpaquePointer?, CPointer<CXIdxDeclInfo>?) -> Unit, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (COpaquePointer?, CPointer<CXIdxDeclInfo>?) -> Unit, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<COpaquePointerVar>().pointed.value, args[1].value!!.reinterpret<CPointerVar<CXIdxDeclInfo>>().pointed.value)
|
||||
}
|
||||
}
|
||||
|
||||
object CFunctionType13 : CAdaptedFunctionTypeImpl<(COpaquePointer?, CPointer<CXIdxEntityRefInfo>?) -> Unit>(Void, Pointer, Pointer) {
|
||||
override fun invoke(function: (COpaquePointer?, CPointer<CXIdxEntityRefInfo>?) -> Unit, args: CArray<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
override fun invoke(function: (COpaquePointer?, CPointer<CXIdxEntityRefInfo>?) -> Unit, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer) {
|
||||
val res = function(args[0].value!!.reinterpret<COpaquePointerVar>().pointed.value, args[1].value!!.reinterpret<CPointerVar<CXIdxEntityRefInfo>>().pointed.value)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -65,7 +65,7 @@ internal fun parseTranslationUnit(
|
||||
val result = clang_parseTranslationUnit(
|
||||
index,
|
||||
sourceFile.absolutePath,
|
||||
compilerArgs.toNativeStringArray(memScope)[0].ptr, compilerArgs.size,
|
||||
compilerArgs.toNativeStringArray(memScope), compilerArgs.size,
|
||||
null, 0,
|
||||
options
|
||||
)!!
|
||||
@@ -120,7 +120,7 @@ internal fun CValue<CXCursor>.isLeaf(): Boolean {
|
||||
return !hasChildren
|
||||
}
|
||||
|
||||
internal fun List<String>.toNativeStringArray(placement: NativePlacement): CArray<CPointerVar<CInt8Var>> {
|
||||
internal fun List<String>.toNativeStringArray(placement: NativePlacement): CArrayPointer<CPointerVar<CInt8Var>> {
|
||||
return placement.allocArray(this.size) { index ->
|
||||
this.value = this@toNativeStringArray[index].cstr.getPointer(placement)
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ abstract class CAdaptedFunctionTypeImpl<F : Function<*>>
|
||||
* @param args array of pointers to arguments to be passed to [function]
|
||||
* @param ret pointer to memory to be filled with return value of [function]
|
||||
*/
|
||||
protected abstract fun invoke(function: F, args: CArray<COpaquePointerVar>, ret: COpaquePointer)
|
||||
protected abstract fun invoke(function: F, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer)
|
||||
|
||||
companion object {
|
||||
init {
|
||||
@@ -118,7 +118,7 @@ abstract class CAdaptedFunctionTypeImpl<F : Function<*>>
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
val impl: UserData = { ret: COpaquePointer, args: CArray<COpaquePointerVar> ->
|
||||
val impl: UserData = { ret: COpaquePointer, args: CArrayPointer<COpaquePointerVar> ->
|
||||
invoke(function, args, ret)
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ abstract class CAdaptedFunctionTypeImpl<F : Function<*>>
|
||||
private val cache = mutableMapOf<F, NativePtr>()
|
||||
}
|
||||
|
||||
private typealias UserData = (ret: COpaquePointer, args: CArray<COpaquePointerVar>)->Unit
|
||||
private typealias UserData = (ret: COpaquePointer, args: CArrayPointer<COpaquePointerVar>)->Unit
|
||||
|
||||
private fun loadCallbacksLibrary() {
|
||||
System.loadLibrary("callbacks")
|
||||
@@ -185,7 +185,7 @@ private external fun ffiTypeStruct0(elements: Long): Long
|
||||
*/
|
||||
private fun ffiTypeStruct(elementTypes: List<ffi_type>): ffi_type {
|
||||
val elements = nativeHeap.allocArrayOfPointersTo(*elementTypes.toTypedArray(), null)
|
||||
val res = ffiTypeStruct0(elements.rawPtr)
|
||||
val res = ffiTypeStruct0(elements.rawValue)
|
||||
if (res == 0L) {
|
||||
throw OutOfMemoryError()
|
||||
}
|
||||
@@ -205,7 +205,7 @@ private external fun ffiCreateCif0(nArgs: Int, rType: Long, argTypes: Long): Lon
|
||||
private fun ffiCreateCif(returnType: ffi_type, paramTypes: List<ffi_type>): ffi_cif {
|
||||
val nArgs = paramTypes.size
|
||||
val argTypes = nativeHeap.allocArrayOfPointersTo(*paramTypes.toTypedArray(), null)
|
||||
val res = ffiCreateCif0(nArgs, returnType.rawPtr, argTypes.rawPtr)
|
||||
val res = ffiCreateCif0(nArgs, returnType.rawPtr, argTypes.rawValue)
|
||||
|
||||
when (res) {
|
||||
0L -> throw OutOfMemoryError()
|
||||
@@ -220,7 +220,7 @@ private fun ffiCreateCif(returnType: ffi_type, paramTypes: List<ffi_type>): ffi_
|
||||
private fun ffiFunImpl0(ffiCif: Long, ret: Long, args: Long, userData: Any) {
|
||||
ffiFunImpl(interpretPointed(ffiCif),
|
||||
interpretCPointer(ret)!!,
|
||||
interpretPointed(args),
|
||||
interpretCPointer(args)!!,
|
||||
userData as UserData)
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ private fun ffiFunImpl0(ffiCif: Long, ret: Long, args: Long, userData: Any) {
|
||||
* @param ret pointer to memory to be filled with return value of the invoked native function
|
||||
* @param args pointer to array of pointers to arguments passed to the invoked native function
|
||||
*/
|
||||
private fun ffiFunImpl(ffiCif: ffi_cif, ret: COpaquePointer, args: CArray<COpaquePointerVar>,
|
||||
private fun ffiFunImpl(ffiCif: ffi_cif, ret: COpaquePointer, args: CArrayPointer<COpaquePointerVar>,
|
||||
userData: UserData) {
|
||||
|
||||
userData.invoke(ret, args)
|
||||
|
||||
@@ -188,21 +188,20 @@ inline fun <reified T : CVariable> sizeOf() = typeOf<T>().size
|
||||
inline fun <reified T : CVariable> alignOf() = typeOf<T>().align
|
||||
|
||||
/**
|
||||
* The C data which is composed from several members.
|
||||
* Returns the member of this [CStructVar] which is located by given offset in bytes.
|
||||
*/
|
||||
interface CAggregate : CPointed
|
||||
|
||||
/**
|
||||
* Returns the member of this [CAggregate] which is located by given offset in bytes.
|
||||
*/
|
||||
inline fun <reified T : CPointed> CAggregate.memberAt(offset: Long): T {
|
||||
inline fun <reified T : CPointed> CStructVar.memberAt(offset: Long): T {
|
||||
return interpretPointed<T>(this.rawPtr + offset)
|
||||
}
|
||||
|
||||
inline fun <reified T : CVariable> CStructVar.arrayMemberAt(offset: Long): CArrayPointer<T> {
|
||||
return interpretCPointer<T>(this.rawPtr + offset)!!
|
||||
}
|
||||
|
||||
/**
|
||||
* The C struct-typed variable located in memory.
|
||||
*/
|
||||
abstract class CStructVar : CVariable, CAggregate {
|
||||
abstract class CStructVar : CVariable {
|
||||
open class Type(size: Long, align: Int) : CVariable.Type(size, align)
|
||||
}
|
||||
|
||||
@@ -307,16 +306,19 @@ inline var <reified T : CPointed, reified P : CPointer<T>> CPointerVarWithValueM
|
||||
this.value = value?.ptr as P?
|
||||
}
|
||||
|
||||
class CArray<T : CVariable>(override val rawPtr: NativePtr) : CAggregate
|
||||
|
||||
inline fun <reified T : CVariable> CArray<T>.elementOffset(index: Long) = if (index == 0L) {
|
||||
0L // optimization for JVM impl which uses reflection for now.
|
||||
} else {
|
||||
index * sizeOf<T>()
|
||||
inline operator fun <reified T : CVariable> CPointer<T>.get(index: Long): T {
|
||||
val offset = if (index == 0L) {
|
||||
0L // optimization for JVM impl which uses reflection for now.
|
||||
} else {
|
||||
index * sizeOf<T>()
|
||||
}
|
||||
return interpretPointed(this.rawValue + offset)
|
||||
}
|
||||
|
||||
inline operator fun <reified T : CVariable> CArray<T>.get(index: Long): T = memberAt(elementOffset(index))
|
||||
inline operator fun <reified T : CVariable> CArray<T>.get(index: Int) = this.get(index.toLong())
|
||||
inline operator fun <reified T : CVariable> CPointer<T>.get(index: Int): T = this.get(index.toLong())
|
||||
|
||||
typealias CArrayPointer<T> = CPointer<T>
|
||||
typealias CArrayPointerVar<T> = CPointerVar<T>
|
||||
|
||||
/**
|
||||
* The type of C function.
|
||||
|
||||
@@ -56,15 +56,15 @@ inline fun <reified T : CVariable> NativePlacement.alloc(): T =
|
||||
*
|
||||
* @param T must not be abstract
|
||||
*/
|
||||
inline fun <reified T : CVariable> NativePlacement.allocArray(length: Long): CArray<T> =
|
||||
alloc(sizeOf<T>() * length, alignOf<T>()).reinterpret()
|
||||
inline fun <reified T : CVariable> NativePlacement.allocArray(length: Long): CArrayPointer<T> =
|
||||
alloc(sizeOf<T>() * length, alignOf<T>()).reinterpret<T>().ptr
|
||||
|
||||
/**
|
||||
* Allocates C array of given elements type and length.
|
||||
*
|
||||
* @param T must not be abstract
|
||||
*/
|
||||
inline fun <reified T : CVariable> NativePlacement.allocArray(length: Int): CArray<T> =
|
||||
inline fun <reified T : CVariable> NativePlacement.allocArray(length: Int): CArrayPointer<T> =
|
||||
allocArray(length.toLong())
|
||||
|
||||
/**
|
||||
@@ -73,7 +73,7 @@ inline fun <reified T : CVariable> NativePlacement.allocArray(length: Int): CArr
|
||||
* @param T must not be abstract
|
||||
*/
|
||||
inline fun <reified T : CVariable> NativePlacement.allocArray(length: Long,
|
||||
initializer: T.(index: Long)->Unit): CArray<T> {
|
||||
initializer: T.(index: Long)->Unit): CArrayPointer<T> {
|
||||
val res = allocArray<T>(length)
|
||||
|
||||
(0 .. length - 1).forEach { index ->
|
||||
@@ -89,7 +89,7 @@ inline fun <reified T : CVariable> NativePlacement.allocArray(length: Long,
|
||||
* @param T must not be abstract
|
||||
*/
|
||||
inline fun <reified T : CVariable> NativePlacement.allocArray(length: Int,
|
||||
initializer: T.(index: Int)->Unit): CArray<T> =
|
||||
initializer: T.(index: Int)->Unit): CArrayPointer<T> =
|
||||
allocArray(length.toLong()) { index ->
|
||||
this.initializer(index.toInt())
|
||||
}
|
||||
@@ -98,7 +98,7 @@ inline fun <reified T : CVariable> NativePlacement.allocArray(length: Int,
|
||||
/**
|
||||
* Allocates C array of pointers to given elements.
|
||||
*/
|
||||
fun <T : CPointed> NativePlacement.allocArrayOfPointersTo(elements: List<T?>): CArray<CPointerVar<T>> {
|
||||
fun <T : CPointed> NativePlacement.allocArrayOfPointersTo(elements: List<T?>): CArrayPointer<CPointerVar<T>> {
|
||||
val res = allocArray<CPointerVar<T>>(elements.size)
|
||||
elements.forEachIndexed { index, value ->
|
||||
res[index].value = value?.ptr
|
||||
@@ -116,7 +116,7 @@ fun <T : CPointed> NativePlacement.allocArrayOfPointersTo(vararg elements: T?) =
|
||||
* Allocates C array of given values.
|
||||
*/
|
||||
inline fun <reified T : CPointer<*>>
|
||||
NativePlacement.allocArrayOf(vararg elements: T?): CArray<CPointerVarWithValueMappedTo<T>> {
|
||||
NativePlacement.allocArrayOf(vararg elements: T?): CArrayPointer<CPointerVarWithValueMappedTo<T>> {
|
||||
|
||||
return allocArrayOf(listOf(*elements))
|
||||
}
|
||||
@@ -125,7 +125,7 @@ inline fun <reified T : CPointer<*>>
|
||||
* Allocates C array of given values.
|
||||
*/
|
||||
inline fun <reified T : CPointer<*>>
|
||||
NativePlacement.allocArrayOf(elements: List<T?>): CArray<CPointerVarWithValueMappedTo<T>> {
|
||||
NativePlacement.allocArrayOf(elements: List<T?>): CArrayPointer<CPointerVarWithValueMappedTo<T>> {
|
||||
|
||||
val res = allocArray<CPointerVarWithValueMappedTo<T>>(elements.size)
|
||||
elements.forEachIndexed { index, value ->
|
||||
@@ -135,13 +135,13 @@ inline fun <reified T : CPointer<*>>
|
||||
return res
|
||||
}
|
||||
|
||||
fun NativePlacement.allocArrayOf(elements: ByteArray): CArray<CInt8Var> {
|
||||
fun NativePlacement.allocArrayOf(elements: ByteArray): CArrayPointer<CInt8Var> {
|
||||
val result = allocArray<CInt8Var>(elements.size)
|
||||
nativeMemUtils.putByteArray(elements, result, elements.size)
|
||||
nativeMemUtils.putByteArray(elements, result.pointed, elements.size)
|
||||
return result
|
||||
}
|
||||
|
||||
fun NativePlacement.allocArrayOf(vararg elements: Float): CArray<CFloat32Var> {
|
||||
fun NativePlacement.allocArrayOf(vararg elements: Float): CArrayPointer<CFloat32Var> {
|
||||
val res = allocArray<CFloat32Var>(elements.size)
|
||||
var index = 0
|
||||
for (element in elements) {
|
||||
@@ -231,7 +231,7 @@ inline fun <reified T : CVariable> createValues(count: Int, initializer: T.(inde
|
||||
}
|
||||
|
||||
fun cValuesOf(vararg elements: Byte): CValues<CInt8Var> = object : CValues<CInt8Var>() {
|
||||
override fun getPointer(placement: NativePlacement) = placement.allocArrayOf(elements)[0].ptr
|
||||
override fun getPointer(placement: NativePlacement) = placement.allocArrayOf(elements)
|
||||
override val size get() = 1 * elements.size
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ fun cValuesOf(vararg elements: Long): CValues<CInt64Var> =
|
||||
createValues(elements.size) { index -> this.value = elements[index] }
|
||||
|
||||
fun cValuesOf(vararg elements: Float): CValues<CFloat32Var> = object : CValues<CFloat32Var>() {
|
||||
override fun getPointer(placement: NativePlacement) = placement.allocArrayOf(*elements)[0].ptr
|
||||
override fun getPointer(placement: NativePlacement) = placement.allocArrayOf(*elements)
|
||||
override val size get() = 4 * elements.size
|
||||
}
|
||||
|
||||
@@ -281,9 +281,9 @@ val String.cstr: CValues<CInt8Var>
|
||||
|
||||
override fun getPointer(placement: NativePlacement): CPointer<CInt8Var> {
|
||||
val result = placement.allocArray<CInt8Var>(bytes.size + 1)
|
||||
nativeMemUtils.putByteArray(bytes, result, bytes.size)
|
||||
nativeMemUtils.putByteArray(bytes, result.pointed, bytes.size)
|
||||
result[bytes.size].value = 0.toByte()
|
||||
return result[0].ptr
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -294,7 +294,7 @@ val String.cstr: CValues<CInt8Var>
|
||||
* @return the [kotlin.String] decoded from given zero-terminated UTF-8-encoded C string.
|
||||
*/
|
||||
fun CPointer<CInt8Var>.toKString(): String {
|
||||
val nativeBytes = this.reinterpret<CArray<CInt8Var>>().pointed
|
||||
val nativeBytes = this
|
||||
|
||||
var length = 0
|
||||
while (nativeBytes[length].value != 0.toByte()) {
|
||||
@@ -302,7 +302,7 @@ fun CPointer<CInt8Var>.toKString(): String {
|
||||
}
|
||||
|
||||
val bytes = ByteArray(length)
|
||||
nativeMemUtils.getByteArray(nativeBytes, bytes, length)
|
||||
nativeMemUtils.getByteArray(nativeBytes.pointed, bytes, length)
|
||||
return decodeFromUtf8(bytes)
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ object nativeMemUtils {
|
||||
|
||||
// TODO: optimize
|
||||
fun getByteArray(source: NativePointed, dest: ByteArray, length: Int) {
|
||||
val sourceArray: CArray<CInt8Var> = source.reinterpret()
|
||||
val sourceArray = source.reinterpret<CInt8Var>().ptr
|
||||
for (index in 0 .. length - 1) {
|
||||
dest[index] = sourceArray[index].value
|
||||
}
|
||||
@@ -40,7 +40,7 @@ object nativeMemUtils {
|
||||
|
||||
// TODO: optimize
|
||||
fun putByteArray(source: ByteArray, dest: NativePointed, length: Int) {
|
||||
val destArray: CArray<CInt8Var> = dest.reinterpret()
|
||||
val destArray = dest.reinterpret<CInt8Var>().ptr
|
||||
for (index in 0 .. length - 1) {
|
||||
destArray[index].value = source[index]
|
||||
}
|
||||
@@ -48,7 +48,7 @@ object nativeMemUtils {
|
||||
|
||||
// TODO: optimize
|
||||
fun zeroMemory(dest: NativePointed, length: Int): Unit {
|
||||
val destArray: CArray<CInt8Var> = dest.reinterpret()
|
||||
val destArray = dest.reinterpret<CInt8Var>().ptr
|
||||
for (index in 0 .. length - 1) {
|
||||
destArray[index].value = 0
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ fun callWithVarargs(codePtr: NativePtr, returnValuePtr: NativePtr, returnTypeKin
|
||||
|
||||
assert (index == totalArgumentsNumber)
|
||||
|
||||
callWithVarargs(codePtr, returnValuePtr, returnTypeKind, arguments.rawPtr, types.rawPtr,
|
||||
callWithVarargs(codePtr, returnValuePtr, returnTypeKind, arguments.rawValue, types.rawValue,
|
||||
fixedArguments.size, totalArgumentsNumber)
|
||||
}
|
||||
|
||||
|
||||
+18
-5
@@ -390,8 +390,11 @@ class StubGenerator(
|
||||
}
|
||||
|
||||
is ArrayType -> {
|
||||
val elemMirror = mirror(type.elemType)
|
||||
byRefTypeMirror("CArray<${elemMirror.pointedTypeName}>")
|
||||
// TODO: array type doesn't exactly correspond neither to pointer nor to value.
|
||||
val elemTypeMirror = mirror(type.elemType)
|
||||
val info = TypeInfo.Pointer(elemTypeMirror.pointedTypeName)
|
||||
TypeMirror.ByValue("CArrayPointerVar<${elemTypeMirror.pointedTypeName}>", info,
|
||||
"CArrayPointer<${elemTypeMirror.pointedTypeName}>")
|
||||
}
|
||||
|
||||
is FunctionType -> byRefTypeMirror("CFunction<${type.kotlinName}>")
|
||||
@@ -584,8 +587,18 @@ class StubGenerator(
|
||||
assert(field.offset % 8 == 0L)
|
||||
val offset = field.offset / 8
|
||||
val fieldRefType = mirror(field.type)
|
||||
out("val ${field.name.asSimpleName()}: ${fieldRefType.pointedTypeName}")
|
||||
out(" get() = memberAt($offset)")
|
||||
if (field.type.unwrapTypedefs() is ArrayType) {
|
||||
// FIXME:
|
||||
val nullableType = fieldRefType.argType
|
||||
assert (nullableType.endsWith('?'))
|
||||
val type = nullableType.substring(0, nullableType.length - 1)
|
||||
|
||||
out("val ${field.name.asSimpleName()}: $type")
|
||||
out(" get() = arrayMemberAt($offset)")
|
||||
} else {
|
||||
out("val ${field.name.asSimpleName()}: ${fieldRefType.pointedTypeName}")
|
||||
out(" get() = memberAt($offset)")
|
||||
}
|
||||
out("")
|
||||
} catch (e: Throwable) {
|
||||
println("Warning: cannot generate definition for field ${decl.kotlinName}.${field.name}")
|
||||
@@ -1004,7 +1017,7 @@ class StubGenerator(
|
||||
val constructorArgsStr = constructorArgs.joinToString(", ")
|
||||
|
||||
block("object $name : CAdaptedFunctionTypeImpl<$kotlinFunctionType>($constructorArgsStr)") {
|
||||
block("override fun invoke(function: $kotlinFunctionType, args: CArray<COpaquePointerVar>, ret: COpaquePointer)") {
|
||||
block("override fun invoke(function: $kotlinFunctionType, args: CArrayPointer<COpaquePointerVar>, ret: COpaquePointer)") {
|
||||
val args = type.parameterTypes.mapIndexed { i, paramType ->
|
||||
val pointedTypeName = mirror(paramType).pointedTypeName
|
||||
val ref = "args[$i].value!!.reinterpret<$pointedTypeName>().pointed"
|
||||
|
||||
+5
-5
@@ -7,7 +7,7 @@ internal fun localHash(data: ByteArray): Long {
|
||||
memScoped {
|
||||
val res = alloc<LocalHashVar>()
|
||||
val bytes = allocArrayOf(data)
|
||||
MakeLocalHash(bytes[0].ptr, data.size, res.ptr)
|
||||
MakeLocalHash(bytes, data.size, res.ptr)
|
||||
return res.value
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ internal fun globalHash(data: ByteArray, retValPlacement: NativePlacement): Glob
|
||||
val res = retValPlacement.alloc<GlobalHash>()
|
||||
memScoped {
|
||||
val bytes = allocArrayOf(data)
|
||||
MakeGlobalHash(bytes[0].ptr, data.size, res.ptr)
|
||||
MakeGlobalHash(bytes, data.size, res.ptr)
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -26,9 +26,9 @@ public fun base64Encode(data: ByteArray): String {
|
||||
val resultSize = 4 * data.size / 3 + 3 + 1
|
||||
val result = allocArray<CInt8Var>(resultSize)
|
||||
val bytes = allocArrayOf(data)
|
||||
EncodeBase64(bytes.ptr, data.size, result.ptr, resultSize)
|
||||
EncodeBase64(bytes, data.size, result, resultSize)
|
||||
// TODO: any better way to do that without two copies?
|
||||
return result[0].ptr.toKString()
|
||||
return result.toKString()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public fun base64Decode(encoded: String): ByteArray {
|
||||
val result = allocArray<CInt8Var>(bufferSize)
|
||||
val resultSize = allocArray<uint32_tVar>(1)
|
||||
resultSize[0].value = bufferSize
|
||||
val errorCode = DecodeBase64(encoded, encoded.length, result[0].ptr, resultSize[0].ptr)
|
||||
val errorCode = DecodeBase64(encoded, encoded.length, result, resultSize)
|
||||
if (errorCode != 0) throw Error("Non-zero exit code of DecodeBase64: ${errorCode}")
|
||||
val realSize = resultSize[0].value!!
|
||||
val bytes = ByteArray(realSize)
|
||||
|
||||
+1
-1
@@ -155,7 +155,7 @@ internal fun RuntimeAware.isObjectType(type: LLVMTypeRef): Boolean {
|
||||
/**
|
||||
* Reads [size] bytes contained in this array.
|
||||
*/
|
||||
internal fun CArray<CInt8Var>.getBytes(size: Long) =
|
||||
internal fun CArrayPointer<CInt8Var>.getBytes(size: Long) =
|
||||
(0 .. size-1).map { this[it].value }.toByteArray()
|
||||
|
||||
internal fun getFunctionType(ptrToFunction: LLVMValueRef): LLVMTypeRef {
|
||||
|
||||
+3
-3
@@ -90,7 +90,7 @@ class MetadataReader(file: File) : Closeable {
|
||||
val nodeCount = LLVMGetNamedMetadataNumOperands(llvmModule, name)
|
||||
val nodeArray = allocArray<LLVMValueRefVar>(nodeCount)
|
||||
|
||||
LLVMGetNamedMetadataOperands(llvmModule, name, nodeArray[0].ptr)
|
||||
LLVMGetNamedMetadataOperands(llvmModule, name, nodeArray)
|
||||
|
||||
//return Pair(nodeCount, nodeArray[0].value!!)
|
||||
for (index in 0..nodeCount-1) {
|
||||
@@ -105,7 +105,7 @@ class MetadataReader(file: File) : Closeable {
|
||||
val nodeCount = LLVMGetNamedMetadataNumOperands(llvmModule, name)
|
||||
val nodeArray = allocArray<LLVMValueRefVar>(nodeCount)
|
||||
|
||||
LLVMGetNamedMetadataOperands(llvmModule, name, nodeArray[0].ptr)
|
||||
LLVMGetNamedMetadataOperands(llvmModule, name, nodeArray)
|
||||
|
||||
return Pair(nodeCount, nodeArray[0].value!!)
|
||||
}
|
||||
@@ -116,7 +116,7 @@ class MetadataReader(file: File) : Closeable {
|
||||
val operandCount = LLVMGetMDNodeNumOperands(metadataNode)
|
||||
val operandArray = allocArray<LLVMValueRefVar>(operandCount)
|
||||
|
||||
LLVMGetMDNodeOperands(metadataNode, operandArray[0].ptr)
|
||||
LLVMGetMDNodeOperands(metadataNode, operandArray)
|
||||
|
||||
return Array(operandCount, {index -> operandArray[index].value!!})
|
||||
}
|
||||
|
||||
+24
-7
@@ -90,15 +90,23 @@ private class InteropTransformer(val context: Context, val irFile: IrFile) : IrB
|
||||
return alignOf(typeObject)
|
||||
}
|
||||
|
||||
private fun IrBuilderWithScope.interpretPointed(expression: IrCall, type: KotlinType): IrExpression =
|
||||
irCall(interop.interpretNullablePointed).apply {
|
||||
putValueArgument(0, expression)
|
||||
}
|
||||
// TODO: make the result type more correct.
|
||||
|
||||
private fun IrBuilderWithScope.arrayGet(array: IrExpression, index: IrExpression): IrExpression? {
|
||||
val elementSize = sizeOf(array.type.arguments.single().type) ?: return null
|
||||
val elementType = array.type.arguments.single().type
|
||||
val elementSize = sizeOf(elementType) ?: return null
|
||||
|
||||
val offset = times(elementSize, index)
|
||||
|
||||
return irCall(interop.memberAt).apply {
|
||||
extensionReceiver = array
|
||||
putValueArgument(0, offset)
|
||||
val resultRawPtr = irCall(interop.nativePtrPlusLong).apply {
|
||||
dispatchReceiver = irCall(interop.cPointerGetRawValue).apply {
|
||||
extensionReceiver = array
|
||||
}
|
||||
putValueArgument(0, times(elementSize, index))
|
||||
}
|
||||
return interpretPointed(resultRawPtr, elementType)
|
||||
}
|
||||
|
||||
private fun IrBuilderWithScope.times(left: IrExpression, right: IrExpression): IrCall {
|
||||
@@ -125,6 +133,15 @@ private class InteropTransformer(val context: Context, val irFile: IrFile) : IrB
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrBuilderWithScope.nativePointedToCPointer(
|
||||
expression: IrExpression, pointeeType: KotlinType
|
||||
): IrExpression = irCall(interop.interpretCPointer).apply {
|
||||
putValueArgument(0, irCall(interop.nativePointedGetRawPointer).apply {
|
||||
extensionReceiver = expression
|
||||
})
|
||||
}
|
||||
// TODO: make the result type more correct.
|
||||
|
||||
private fun IrBuilderWithScope.allocArray(placement: IrExpression,
|
||||
elementType: KotlinType,
|
||||
length: IrExpression
|
||||
@@ -134,7 +151,7 @@ private class InteropTransformer(val context: Context, val irFile: IrFile) : IrB
|
||||
val size = times(elementSize, length)
|
||||
val align = alignOf(elementType) ?: return null
|
||||
|
||||
return alloc(placement, size, align)
|
||||
return nativePointedToCPointer(alloc(placement, size, align), elementType)
|
||||
}
|
||||
|
||||
private fun IrBuilderWithScope.alloc(placement: IrExpression, type: KotlinType): IrExpression? {
|
||||
|
||||
@@ -11,7 +11,7 @@ fun main(args: Array<String>) {
|
||||
values[3].value = 13
|
||||
values[4].value = 8
|
||||
|
||||
cstdlib.qsort(values[0].ptr, count.toLong(), CInt32Var.size, staticCFunction(::comparator))
|
||||
cstdlib.qsort(values, count.toLong(), CInt32Var.size, staticCFunction(::comparator))
|
||||
|
||||
for (i in 0 .. count - 1) {
|
||||
print(values[i].value)
|
||||
|
||||
@@ -35,14 +35,14 @@ fun main(args: Array<String>) {
|
||||
.ensureUnixCallResult { it >= 0 }
|
||||
|
||||
while (true) {
|
||||
val length = read(commFd, buffer.ptr, bufferLength)
|
||||
val length = read(commFd, buffer, bufferLength)
|
||||
.ensureUnixCallResult { it >= 0 }
|
||||
|
||||
if (length == 0L) {
|
||||
break
|
||||
}
|
||||
|
||||
write(commFd, buffer.ptr, length)
|
||||
write(commFd, buffer, length)
|
||||
.ensureUnixCallResult { it >= 0 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ fun main(args: Array<String>) {
|
||||
val buffer = allocArray<CInt8Var>(bufferLength)
|
||||
|
||||
for (i in 1..count) {
|
||||
val nextLine = fgets(buffer[0].ptr, bufferLength, file)?.toKString()
|
||||
val nextLine = fgets(buffer, bufferLength, file)?.toKString()
|
||||
if (nextLine == null || nextLine.isEmpty()) break
|
||||
|
||||
val records = parseLine(nextLine, ',')
|
||||
|
||||
@@ -22,7 +22,7 @@ class GitRepository(val location: String) {
|
||||
val size = remoteList.count.value.toInt()
|
||||
val list = ArrayList<GitRemote>(size)
|
||||
for (index in 0..size - 1) {
|
||||
val array = remoteList.strings.value!!.reinterpret<CArray<CPointerVar<CInt8Var>>>().pointed
|
||||
val array = remoteList.strings.value!!
|
||||
val name = array[index].value!!.toKString()
|
||||
val remotePtr = allocPointerTo<git_remote>()
|
||||
git_remote_lookup(remotePtr.ptr, handle, name).errorCheck()
|
||||
|
||||
@@ -35,14 +35,14 @@ fun main(args: Array<String>) {
|
||||
.ensureUnixCallResult { it >= 0 }
|
||||
|
||||
while (true) {
|
||||
val length = read(commFd, buffer.ptr, bufferLength)
|
||||
val length = read(commFd, buffer, bufferLength)
|
||||
.ensureUnixCallResult { it >= 0 }
|
||||
|
||||
if (length == 0L) {
|
||||
break
|
||||
}
|
||||
|
||||
write(commFd, buffer.ptr, length)
|
||||
write(commFd, buffer, length)
|
||||
.ensureUnixCallResult { it >= 0 }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user