diff --git a/Sources/JExtractSwiftLib/FFM/CDeclLowering/FFMSwift2JavaGenerator+FunctionLowering.swift b/Sources/JExtractSwiftLib/FFM/CDeclLowering/FFMSwift2JavaGenerator+FunctionLowering.swift index 9d53b8b5..21fb23bd 100644 --- a/Sources/JExtractSwiftLib/FFM/CDeclLowering/FFMSwift2JavaGenerator+FunctionLowering.swift +++ b/Sources/JExtractSwiftLib/FFM/CDeclLowering/FFMSwift2JavaGenerator+FunctionLowering.swift @@ -95,11 +95,11 @@ struct CdeclLowering { // Lower the self parameter. let loweredSelf: LoweredParameter? = switch signature.selfParameter { - case .instance(let selfParameter): + case .instance(let convention, let swiftType): try lowerParameter( - selfParameter.type, - convention: selfParameter.convention, - parameterName: selfParameter.parameterName ?? "self", + swiftType, + convention: convention, + parameterName: "self", genericParameters: signature.genericParameters, genericRequirements: signature.genericRequirements ) @@ -949,10 +949,10 @@ extension LoweredFunctionSignature { let selfExpr: ExprSyntax? switch original.selfParameter { - case .instance(let swiftSelf): + case .instance: // Raise the 'self' from cdecl parameters. selfExpr = self.selfParameter!.conversion.asExprSyntax( - placeholder: swiftSelf.parameterName ?? "self", + placeholder: "self", bodyItems: &bodyItems ) case .staticMethod(let selfType), .initializer(let selfType): diff --git a/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaTranslation.swift b/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaTranslation.swift index a066fa40..4aab23fc 100644 --- a/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaTranslation.swift +++ b/Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+JavaTranslation.swift @@ -281,11 +281,11 @@ extension FFMSwift2JavaGenerator { // 'self' let selfParameter: TranslatedParameter? - if case .instance(let swiftSelf) = swiftSignature.selfParameter { + if case .instance(let convention, let swiftType) = swiftSignature.selfParameter { selfParameter = try self.translateParameter( - type: swiftSelf.type, - convention: swiftSelf.convention, - parameterName: swiftSelf.parameterName ?? "self", + type: swiftType, + convention: convention, + parameterName: "self", loweredParam: loweredFunctionSignature.selfParameter!, methodName: methodName, genericParameters: swiftSignature.genericParameters, diff --git a/Sources/JExtractSwiftLib/ImportedDecls.swift b/Sources/JExtractSwiftLib/ImportedDecls.swift index 1879bc76..136647b4 100644 --- a/Sources/JExtractSwiftLib/ImportedDecls.swift +++ b/Sources/JExtractSwiftLib/ImportedDecls.swift @@ -138,17 +138,7 @@ public final class ImportedFunc: ImportedDecl, CustomStringConvertible { } var parentType: SwiftType? { - guard let selfParameter = functionSignature.selfParameter else { - return nil - } - switch selfParameter { - case .instance(let parameter): - return parameter.type - case .staticMethod(let type): - return type - case .initializer(let type): - return type - } + functionSignature.selfParameter?.selfType } /// If this function type uses types that require any additional `import` statements, diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift index 06bd9740..660ae2ee 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift @@ -399,12 +399,12 @@ extension JNISwift2JavaGenerator { printer.printBraceBlock("public Discriminator getDiscriminator()") { printer in printer.print("return Discriminator.values()[$getDiscriminator(this.$memoryAddress(), this.$typeMetadataAddress())];") } - printer.print("private static native int $getDiscriminator(long self, long selfType);") + printer.print("private static native int $getDiscriminator(long selfPointer, long selfTypePointer);") } else { printer.printBraceBlock("public Discriminator getDiscriminator()") { printer in printer.print("return Discriminator.values()[$getDiscriminator(this.$memoryAddress())];") } - printer.print("private static native int $getDiscriminator(long self);") + printer.print("private static native int $getDiscriminator(long selfPointer);") } } @@ -740,7 +740,7 @@ extension JNISwift2JavaGenerator { private func printDestroyFunction(_ printer: inout CodePrinter, _ type: ImportedNominalType) { let isGeneric = type.swiftNominal.isGeneric if isGeneric { - printer.print("private static native void $destroy(long selfPointer, long selfType);") + printer.print("private static native void $destroy(long selfPointer, long selfTypePointer);") } else { printer.print("private static native void $destroy(long selfPointer);") } diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift index 0ff525ae..99826ea0 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaTranslation.swift @@ -150,7 +150,7 @@ extension JNISwift2JavaGenerator { functionTypes: [], translatedFunctionSignature: TranslatedFunctionSignature( selfParameter: TranslatedParameter( - parameter: JavaParameter(name: "self", type: .long), + parameter: JavaParameter(name: "selfPointer", type: .long), conversion: .aggregate( [ .ifStatement( @@ -164,7 +164,7 @@ extension JNISwift2JavaGenerator { selfTypeParameter: !isGenericParent ? nil : .init( - parameter: JavaParameter(name: "selfType", type: .long), + parameter: JavaParameter(name: "selfTypePointer", type: .long), conversion: .typeMetadataAddress(.placeholder) ), parameters: [], @@ -179,7 +179,7 @@ extension JNISwift2JavaGenerator { ), nativeFunctionSignature: NativeFunctionSignature( selfParameter: NativeParameter( - parameters: [JavaParameter(name: "self", type: .long)], + parameters: [JavaParameter(name: "selfPointer", type: .long)], conversion: .extractSwiftValue(.placeholder, swiftType: .nominal(enumCase.enumType), allowNil: false), indirectConversion: nil, conversionCheck: nil @@ -187,7 +187,7 @@ extension JNISwift2JavaGenerator { selfTypeParameter: !isGenericParent ? nil : .init( - parameters: [JavaParameter(name: "selfType", type: .long)], + parameters: [JavaParameter(name: "selfTypePointer", type: .long)], conversion: .extractMetatypeValue(.placeholder), indirectConversion: nil, conversionCheck: nil @@ -396,10 +396,10 @@ extension JNISwift2JavaGenerator { genericRequirements: [SwiftGenericRequirement] ) throws -> TranslatedParameter? { // 'self' - if case .instance(let swiftSelf) = selfParameter { + if case .instance(_, let swiftType) = selfParameter { return try self.translateParameter( - swiftType: swiftSelf.type, - parameterName: swiftSelf.parameterName ?? "self", + swiftType: swiftType, + parameterName: "selfPointer", methodName: methodName, parentName: parentName, genericParameters: genericParameters, @@ -422,17 +422,11 @@ extension JNISwift2JavaGenerator { return nil } - let isGeneric = - switch selfParameter { - case .instance(let selfParameter): - selfParameter.type.asNominalTypeDeclaration?.isGeneric == true - case .initializer(let swiftType), .staticMethod(let swiftType): - swiftType.asNominalTypeDeclaration?.isGeneric == true - } + let isGeneric = selfParameter.selfType.asNominalTypeDeclaration?.isGeneric == true if isGeneric { return try self.translateParameter( swiftType: .metatype(selfParameter.selfType), - parameterName: "selfType", + parameterName: "selfTypePointer", methodName: methodName, parentName: parentName, genericParameters: genericParameters, diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+NativeTranslation.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+NativeTranslation.swift index 1a023ae0..b9a28003 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+NativeTranslation.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+NativeTranslation.swift @@ -49,10 +49,10 @@ extension JNISwift2JavaGenerator { // Lower the self parameter. let nativeSelf: NativeParameter? = switch functionSignature.selfParameter { - case .instance(let selfParameter): + case .instance(_, let swiftType): try translateParameter( - type: selfParameter.type, - parameterName: selfParameter.parameterName ?? "self", + type: swiftType, + parameterName: "selfPointer", methodName: methodName, parentName: parentName, genericParameters: functionSignature.genericParameters, @@ -68,7 +68,7 @@ extension JNISwift2JavaGenerator { { try translateParameter( type: .metatype(selfType), - parameterName: "selfType", + parameterName: "selfTypePointer", methodName: methodName, parentName: parentName, genericParameters: functionSignature.genericParameters, diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift index 713c8141..0870f584 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift @@ -302,7 +302,7 @@ extension JNISwift2JavaGenerator { let selfPointerParam = JavaParameter(name: "selfPointer", type: .long) var parameters = [selfPointerParam] if type.swiftNominal.isGeneric { - parameters.append(JavaParameter(name: "selfType", type: .long)) + parameters.append(JavaParameter(name: "selfTypePointer", type: .long)) } printCDecl( @@ -315,7 +315,7 @@ extension JNISwift2JavaGenerator { if type.swiftNominal.isGeneric { let knownTypes = SwiftKnownTypes(symbolTable: lookupContext.symbolTable) let discriminatorFunctionSignature = SwiftFunctionSignature( - selfParameter: .instance(SwiftParameter(convention: .byValue, parameterName: "selfPointer", type: type.swiftType)), + selfParameter: .instance(convention: .byValue, swiftType: type.swiftType), parameters: [], result: .init(convention: .direct, type: knownTypes.int), effectSpecifiers: [], @@ -391,7 +391,7 @@ extension JNISwift2JavaGenerator { ) { printer in let selfPointer = enumCase.getAsCaseFunction.nativeFunctionSignature.selfParameter!.conversion.render( &printer, - "self" + "selfPointer" ) let caseNames = enumCase.original.parameters.enumerated().map { idx, parameter in parameter.name ?? "_\(idx)" @@ -598,10 +598,10 @@ extension JNISwift2JavaGenerator { // Callee let callee: String = switch decl.functionSignature.selfParameter { - case .instance(let swiftSelf): + case .instance: nativeSignature.selfParameter!.conversion.render( &printer, - swiftSelf.parameterName ?? "self" + "selfPointer" ) case .staticMethod(let selfType), .initializer(let selfType): "\(selfType)" @@ -819,7 +819,7 @@ extension JNISwift2JavaGenerator { let selfPointerParam = JavaParameter(name: "selfPointer", type: .long) var parameters = [selfPointerParam] if type.swiftNominal.isGeneric { - parameters.append(JavaParameter(name: "selfType", type: .long)) + parameters.append(JavaParameter(name: "selfTypePointer", type: .long)) } printCDecl( @@ -831,7 +831,7 @@ extension JNISwift2JavaGenerator { ) { printer in if type.swiftNominal.isGeneric { let destroyFunctionSignature = SwiftFunctionSignature( - selfParameter: .instance(SwiftParameter(convention: .byValue, parameterName: "selfPointer", type: type.swiftType)), + selfParameter: .instance(convention: .byValue, swiftType: type.swiftType), parameters: [], result: .void, effectSpecifiers: [], @@ -933,7 +933,7 @@ extension JNISwift2JavaGenerator { } let nativeSignature = translatedDecl.nativeFunctionSignature - let selfType = nativeSignature.selfTypeParameter!.conversion.render(&printer, "selfType") + let selfType = nativeSignature.selfTypeParameter!.conversion.render(&printer, "selfTypePointer") let openerName = openerProtocolName(for: parentNominalType.nominalTypeDecl) printer.print("let openerType = \(selfType) as! (any \(openerName).Type)") @@ -1043,14 +1043,14 @@ extension JNISwift2JavaGenerator { } printer.printBraceBlock("static func _destroy(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong)") { printer in - printer.print(#"assert(selfPointer != 0, "self memory address was null")"#) - printer.print("let selfBits$ = Int(Int64(fromJNI: selfPointer, in: environment))") - printer.print("let self$ = UnsafeMutablePointer(bitPattern: selfBits$)") - printer.printBraceBlock("guard let self$ else") { printer in - printer.print("fatalError(\"self memory address was null in call to \\(#function)!\")") + printer.print(#"assert(selfPointer != 0, "selfPointer memory address was null")"#) + printer.print("let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment))") + printer.print("let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$)") + printer.printBraceBlock("guard let selfPointer$ else") { printer in + printer.print("fatalError(\"selfPointer memory address was null in call to \\(#function)!\")") } - printer.print("self$.deinitialize(count: 1)") - printer.print("self$.deallocate()") + printer.print("selfPointer$.deinitialize(count: 1)") + printer.print("selfPointer$.deallocate()") } } } @@ -1063,16 +1063,16 @@ extension JNISwift2JavaGenerator { swiftParentName: String, _ selfPointerParam: JavaParameter ) -> String { - let newSelfParamName = "self$" + let newSelfParamName = "selfPointer$" printer.print( """ guard let env$ = environment else { fatalError("Missing JNIEnv in downcall to \\(#function)") } assert(\(selfPointerParam.name) != 0, "\(selfPointerParam.name) memory address was null") - let selfBits$ = Int(Int64(fromJNI: \(selfPointerParam.name), in: env$)) - guard let \(newSelfParamName) = UnsafeMutablePointer<\(swiftParentName)>(bitPattern: selfBits$) else { - fatalError("self memory address was null in call to \\(#function)!") + let selfPointerBits$ = Int(Int64(fromJNI: \(selfPointerParam.name), in: env$)) + guard let \(newSelfParamName) = UnsafeMutablePointer<\(swiftParentName)>(bitPattern: selfPointerBits$) else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } """ ) diff --git a/Sources/JExtractSwiftLib/Swift2JavaVisitor.swift b/Sources/JExtractSwiftLib/Swift2JavaVisitor.swift index ebfb25c6..b96e50f5 100644 --- a/Sources/JExtractSwiftLib/Swift2JavaVisitor.swift +++ b/Sources/JExtractSwiftLib/Swift2JavaVisitor.swift @@ -433,7 +433,7 @@ final class Swift2JavaVisitor { let knownTypes = SwiftKnownTypes(symbolTable: translator.symbolTable) let toStringFunctionSignature = SwiftFunctionSignature( - selfParameter: .instance(SwiftParameter(convention: .byValue, parameterName: "selfPointer", type: imported.swiftType)), + selfParameter: .instance(convention: .byValue, swiftType: imported.swiftType), parameters: [], result: SwiftResult(convention: .direct, type: knownTypes.string), effectSpecifiers: [], diff --git a/Sources/JExtractSwiftLib/SwiftTypes/SwiftFunctionSignature.swift b/Sources/JExtractSwiftLib/SwiftTypes/SwiftFunctionSignature.swift index f4be77f8..5e92f9ea 100644 --- a/Sources/JExtractSwiftLib/SwiftTypes/SwiftFunctionSignature.swift +++ b/Sources/JExtractSwiftLib/SwiftTypes/SwiftFunctionSignature.swift @@ -58,7 +58,7 @@ public struct SwiftFunctionSignature: Equatable { /// Describes the "self" parameter of a Swift function signature. enum SwiftSelfParameter: Equatable { /// 'self' is an instance parameter. - case instance(SwiftParameter) + case instance(convention: SwiftParameterConvention, swiftType: SwiftType) /// 'self' is a metatype for a static method. We only need the type to /// form the call. @@ -70,9 +70,7 @@ enum SwiftSelfParameter: Equatable { var selfType: SwiftType { switch self { - case .instance(let swiftParameter): - return swiftParameter.type - case .staticMethod(let swiftType), .initializer(let swiftType): + case .instance(_, let swiftType), .staticMethod(let swiftType), .initializer(let swiftType): return swiftType } } @@ -161,10 +159,8 @@ extension SwiftFunctionSignature { selfParameter = .staticMethod(enclosingType) } else { selfParameter = .instance( - SwiftParameter( - convention: isMutating ? .inout : isConsuming ? .consuming : .byValue, - type: enclosingType - ) + convention: isMutating ? .inout : isConsuming ? .consuming : .byValue, + swiftType: enclosingType ) } } else { @@ -414,10 +410,8 @@ extension SwiftFunctionSignature { return .staticMethod(enclosingType) } else { return .instance( - SwiftParameter( - convention: isSet && !enclosingType.isReferenceType ? .inout : .byValue, - type: enclosingType - ) + convention: isSet && !enclosingType.isReferenceType ? .inout : .byValue, + swiftType: enclosingType ) } } else { diff --git a/Sources/JExtractSwiftLib/SwiftTypes/SwiftParameter.swift b/Sources/JExtractSwiftLib/SwiftTypes/SwiftParameter.swift index 63f7d75b..56fe3cb9 100644 --- a/Sources/JExtractSwiftLib/SwiftTypes/SwiftParameter.swift +++ b/Sources/JExtractSwiftLib/SwiftTypes/SwiftParameter.swift @@ -19,7 +19,6 @@ struct SwiftParameter: Equatable { var argumentLabel: String? var parameterName: String? var type: SwiftType - var canBeDirectReturn = false } extension SwiftParameter: CustomStringConvertible { diff --git a/Tests/JExtractSwiftTests/DateTests.swift b/Tests/JExtractSwiftTests/DateTests.swift index b2a7be08..a9046106 100644 --- a/Tests/JExtractSwiftTests/DateTests.swift +++ b/Tests/JExtractSwiftTests/DateTests.swift @@ -147,7 +147,7 @@ struct DateTests { """, """ @_cdecl("Java_com_example_swift_Date__00024getTimeIntervalSince1970__J") - public func Java_com_example_swift_Date__00024getTimeIntervalSince1970__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jdouble { + public func Java_com_example_swift_Date__00024getTimeIntervalSince1970__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jdouble { """, ] ) diff --git a/Tests/JExtractSwiftTests/JNI/JNIClassTests.swift b/Tests/JExtractSwiftTests/JNI/JNIClassTests.swift index 3fba9755..aad33973 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIClassTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIClassTests.swift @@ -261,12 +261,12 @@ struct JNIClassTests { fatalError("Missing JNIEnv in downcall to \\(#function)") } assert(selfPointer != 0, "selfPointer memory address was null") - let selfBits$ = Int(Int64(fromJNI: selfPointer, in: env$)) - guard let self$ = UnsafeMutablePointer(bitPattern: selfBits$) else { - fatalError("self memory address was null in call to \\(#function)!") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: env$)) + guard let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - self$.deinitialize(count: 1) - self$.deallocate() + selfPointer$.deinitialize(count: 1) + selfPointer$.deallocate() } """ ] @@ -292,7 +292,7 @@ struct JNIClassTests { } """, """ - private static native void $doSomething(long x, long self); + private static native void $doSomething(long x, long selfPointer); """, ] ) @@ -308,14 +308,14 @@ struct JNIClassTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyClass__00024doSomething__JJ") - public func Java_com_example_swift_MyClass__00024doSomething__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, self: jlong) { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + public func Java_com_example_swift_MyClass__00024doSomething__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, selfPointer: jlong) { + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - self$.pointee.doSomething(x: Int64(fromJNI: x, in: environment)) + selfPointer$.pointee.doSomething(x: Int64(fromJNI: x, in: environment)) } """ ] @@ -341,7 +341,7 @@ struct JNIClassTests { } """, """ - private static native long $copy(long self); + private static native long $copy(long selfPointer); """, ] ) @@ -357,15 +357,15 @@ struct JNIClassTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyClass__00024copy__J") - public func Java_com_example_swift_MyClass__00024copy__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jlong { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + public func Java_com_example_swift_MyClass__00024copy__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } let result$ = UnsafeMutablePointer.allocate(capacity: 1) - result$.initialize(to: self$.pointee.copy()) + result$.initialize(to: selfPointer$.pointee.copy()) let resultBits$ = Int64(Int(bitPattern: result$)) return resultBits$.getJNIValue(in: environment) } @@ -393,7 +393,7 @@ struct JNIClassTests { } """, """ - private static native boolean $isEqual(long other, long self); + private static native boolean $isEqual(long other, long selfPointer); """, ] ) @@ -409,20 +409,20 @@ struct JNIClassTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyClass__00024isEqual__JJ") - public func Java_com_example_swift_MyClass__00024isEqual__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, other: jlong, self: jlong) -> jboolean { + public func Java_com_example_swift_MyClass__00024isEqual__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, other: jlong, selfPointer: jlong) -> jboolean { assert(other != 0, "other memory address was null") let otherBits$ = Int(Int64(fromJNI: other, in: environment)) let other$ = UnsafeMutablePointer(bitPattern: otherBits$) guard let other$ else { fatalError("other memory address was null in call to \\(#function)!") } - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - return self$.pointee.isEqual(to: other$.pointee).getJNIValue(in: environment) + return selfPointer$.pointee.isEqual(to: other$.pointee).getJNIValue(in: environment) } """ ] diff --git a/Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift b/Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift index a211227b..1583ed08 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIEnumTests.swift @@ -125,7 +125,7 @@ struct JNIEnumTests { } """, """ - private static native int $getDiscriminator(long self); + private static native int $getDiscriminator(long selfPointer); """, ] ) @@ -143,7 +143,7 @@ struct JNIEnumTests { @_cdecl("Java_com_example_swift_MyEnum__00024getDiscriminator__J") public func Java_com_example_swift_MyEnum__00024getDiscriminator__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jint { ... - switch (self$.pointee) { + switch (selfPointer$.pointee) { case .first: return 0 case .second: return 1 case .third: return 2 @@ -309,10 +309,10 @@ struct JNIEnumTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyEnum__00024getAsSecond__J") - public func Java_com_example_swift_MyEnum__00024getAsSecond__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jobject? { + public func Java_com_example_swift_MyEnum__00024getAsSecond__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jobject? { ... - guard case .second(let _0) = self$.pointee else { - fatalError("Expected enum case 'second', but was '\\(self$.pointee)'!") + guard case .second(let _0) = selfPointer$.pointee else { + fatalError("Expected enum case 'second', but was '\\(selfPointer$.pointee)'!") } let cache$ = _JNI_MyEnum.myEnumSecondCache let class$ = cache$.javaClass @@ -324,10 +324,10 @@ struct JNIEnumTests { """, """ @_cdecl("Java_com_example_swift_MyEnum__00024getAsThird__J") - public func Java_com_example_swift_MyEnum__00024getAsThird__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jobject? { + public func Java_com_example_swift_MyEnum__00024getAsThird__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jobject? { ... - guard case .third(let x, let y) = self$.pointee else { - fatalError("Expected enum case 'third', but was '\\(self$.pointee)'!") + guard case .third(let x, let y) = selfPointer$.pointee else { + fatalError("Expected enum case 'third', but was '\\(selfPointer$.pointee)'!") } let cache$ = _JNI_MyEnum.myEnumThirdCache let class$ = cache$.javaClass diff --git a/Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift b/Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift index cc9bdbdb..26d13c77 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIGenericTypeTests.swift @@ -64,7 +64,7 @@ struct JNIGenericTypeTests { public java.lang.String getDescription() { return MyID.$getDescription(this.$memoryAddress(), this.$typeMetadataAddress()); } - private static native java.lang.String $getDescription(long self, long selfType); + private static native java.lang.String $getDescription(long selfPointer, long selfTypePointer); """, """ @Override @@ -73,7 +73,7 @@ struct JNIGenericTypeTests { } """, """ - private static native void $destroy(long selfPointer, long selfType); + private static native void $destroy(long selfPointer, long selfTypePointer); @Override public Runnable $createDestroyFunction() { long self$ = this.$memoryAddress(); @@ -109,33 +109,33 @@ struct JNIGenericTypeTests { expectedChunks: [ """ protocol _SwiftModule_MyID_opener { - static func _get_description(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jstring? + static func _get_description(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jstring? ... } """, #""" extension MyID: _SwiftModule_MyID_opener { - static func _get_description(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jstring? { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \(#function)!") + static func _get_description(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jstring? { + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \(#function)!") } - return self$.pointee.description.getJNIValue(in: environment) + return selfPointer$.pointee.description.getJNIValue(in: environment) } ... } """#, """ @_cdecl("Java_com_example_swift_MyID__00024getDescription__JJ") - public func Java_com_example_swift_MyID__00024getDescription__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong, selfType: jlong) -> jstring? { - let selfTypeBits$ = Int(Int64(fromJNI: selfType, in: environment)) - guard let selfType$ = UnsafeRawPointer(bitPattern: selfTypeBits$) else { - fatalError("selfType metadata address was null") + public func Java_com_example_swift_MyID__00024getDescription__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong, selfTypePointer: jlong) -> jstring? { + let selfTypePointerBits$ = Int(Int64(fromJNI: selfTypePointer, in: environment)) + guard let selfTypePointer$ = UnsafeRawPointer(bitPattern: selfTypePointerBits$) else { + fatalError("selfTypePointer metadata address was null") } - let openerType = unsafeBitCast(selfType$, to: Any.Type.self) as! (any _SwiftModule_MyID_opener.Type) - return openerType._get_description(environment: environment, thisClass: thisClass, self: self) + let openerType = unsafeBitCast(selfTypePointer$, to: Any.Type.self) as! (any _SwiftModule_MyID_opener.Type) + return openerType._get_description(environment: environment, thisClass: thisClass, selfPointer: selfPointer) } """, ] diff --git a/Tests/JExtractSwiftTests/JNI/JNIIntConversionChecksTests.swift b/Tests/JExtractSwiftTests/JNI/JNIIntConversionChecksTests.swift index ad00f350..0cb10a91 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIIntConversionChecksTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIIntConversionChecksTests.swift @@ -116,7 +116,7 @@ struct JNIIntConversionChecksTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyStruct__00024setUnsignedInt__JJ") - public func Java_com_example_swift_MyStruct__00024setUnsignedInt__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, self: jlong) { + public func Java_com_example_swift_MyStruct__00024setUnsignedInt__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, selfPointer: jlong) { let newValue$indirect = UInt64(fromJNI: newValue, in: environment) #if _pointerBitWidth(_32) guard newValue$indirect >= UInt32.min && newValue$indirect <= UInt32.max else { @@ -125,13 +125,13 @@ struct JNIIntConversionChecksTests { """, """ #endif - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - self$.pointee.unsignedInt = UInt(newValue$indirect) + selfPointer$.pointee.unsignedInt = UInt(newValue$indirect) """, ] ) @@ -145,14 +145,14 @@ struct JNIIntConversionChecksTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyStruct__00024getUnsignedInt__J") - public func Java_com_example_swift_MyStruct__00024getUnsignedInt__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jlong { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + public func Java_com_example_swift_MyStruct__00024getUnsignedInt__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - return UInt64(self$.pointee.unsignedInt).getJNIValue(in: environment) + return UInt64(selfPointer$.pointee.unsignedInt).getJNIValue(in: environment) """ ] ) @@ -166,7 +166,7 @@ struct JNIIntConversionChecksTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyStruct__00024setNormalInt__JJ") - public func Java_com_example_swift_MyStruct__00024setNormalInt__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, self: jlong) { + public func Java_com_example_swift_MyStruct__00024setNormalInt__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, selfPointer: jlong) { let newValue$indirect = Int64(fromJNI: newValue, in: environment) #if _pointerBitWidth(_32) guard newValue$indirect >= Int32.min && newValue$indirect <= Int32.max else { @@ -175,13 +175,13 @@ struct JNIIntConversionChecksTests { """, """ #endif - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - self$.pointee.normalInt = Int(newValue$indirect) + selfPointer$.pointee.normalInt = Int(newValue$indirect) """, ] ) @@ -195,7 +195,7 @@ struct JNIIntConversionChecksTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyStruct__00024dummyFunc__JJ") - public func Java_com_example_swift_MyStruct__00024dummyFunc__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, arg: jlong, self: jlong) -> jlong { + public func Java_com_example_swift_MyStruct__00024dummyFunc__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, arg: jlong, selfPointer: jlong) -> jlong { let arg$indirect = Int64(fromJNI: arg, in: environment) #if _pointerBitWidth(_32) guard arg$indirect >= Int32.min && arg$indirect <= Int32.max else { @@ -204,13 +204,13 @@ struct JNIIntConversionChecksTests { """, """ #endif - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - return Int64(self$.pointee.dummyFunc(arg: Int(arg$indirect))).getJNIValue(in: environment) + return Int64(selfPointer$.pointee.dummyFunc(arg: Int(arg$indirect))).getJNIValue(in: environment) """, ] ) @@ -224,7 +224,7 @@ struct JNIIntConversionChecksTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyStruct__00024dummyFunc__JJ") - public func Java_com_example_swift_MyStruct__00024dummyFunc__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, arg: jlong, self: jlong) -> jlong { + public func Java_com_example_swift_MyStruct__00024dummyFunc__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, arg: jlong, selfPointer: jlong) -> jlong { let arg$indirect = UInt64(fromJNI: arg, in: environment) #if _pointerBitWidth(_32) guard arg$indirect >= UInt32.min && arg$indirect <= UInt32.max else { @@ -232,13 +232,13 @@ struct JNIIntConversionChecksTests { return Int64.jniPlaceholderValue """, """ - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - return UInt64(self$.pointee.dummyFunc(arg: UInt(arg$indirect))).getJNIValue(in: environment) + return UInt64(selfPointer$.pointee.dummyFunc(arg: UInt(arg$indirect))).getJNIValue(in: environment) """, ] ) diff --git a/Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift b/Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift index 808fe99c..447ca4c1 100644 --- a/Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift @@ -94,7 +94,7 @@ struct JNINestedTypesTests { """, """ @_cdecl("Java_com_example_swift_A_00024B_00024C__00024h__JJ") - public func Java_com_example_swift_A_00024B_00024C__00024h__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, b: jlong, self: jlong) { + public func Java_com_example_swift_A_00024B_00024C__00024h__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, b: jlong, selfPointer: jlong) { ... } """, diff --git a/Tests/JExtractSwiftTests/JNI/JNIStructTests.swift b/Tests/JExtractSwiftTests/JNI/JNIStructTests.swift index e98d5fb2..e7f50b77 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIStructTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIStructTests.swift @@ -181,12 +181,12 @@ struct JNIStructTests { fatalError("Missing JNIEnv in downcall to \\(#function)") } assert(selfPointer != 0, "selfPointer memory address was null") - let selfBits$ = Int(Int64(fromJNI: selfPointer, in: env$)) - guard let self$ = UnsafeMutablePointer(bitPattern: selfBits$) else { - fatalError("self memory address was null in call to \\(#function)!") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: env$)) + guard let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - self$.deinitialize(count: 1) - self$.deallocate() + selfPointer$.deinitialize(count: 1) + selfPointer$.deallocate() } """ ] @@ -212,7 +212,7 @@ struct JNIStructTests { } """, """ - private static native void $doSomething(long x, long self); + private static native void $doSomething(long x, long selfPointer); """, ] ) @@ -228,14 +228,14 @@ struct JNIStructTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyStruct__00024doSomething__JJ") - public func Java_com_example_swift_MyStruct__00024doSomething__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, self: jlong) { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + public func Java_com_example_swift_MyStruct__00024doSomething__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, x: jlong, selfPointer: jlong) { + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - self$.pointee.doSomething(x: Int64(fromJNI: x, in: environment)) + selfPointer$.pointee.doSomething(x: Int64(fromJNI: x, in: environment)) } """ ] diff --git a/Tests/JExtractSwiftTests/JNI/JNISubscriptsTests.swift b/Tests/JExtractSwiftTests/JNI/JNISubscriptsTests.swift index 0d058bca..05ff7eab 100644 --- a/Tests/JExtractSwiftTests/JNI/JNISubscriptsTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNISubscriptsTests.swift @@ -51,14 +51,14 @@ struct JNISubscriptsTests { return MyStruct.$getSubscript(this.$memoryAddress()); """, """ - private static native double $getSubscript(long self); + private static native double $getSubscript(long selfPointer); """, """ public void setSubscript(double newValue) { MyStruct.$setSubscript(newValue, this.$memoryAddress()); """, """ - private static native void $setSubscript(double newValue, long self); + private static native void $setSubscript(double newValue, long selfPointer); """, ] ) @@ -87,14 +87,14 @@ struct JNISubscriptsTests { """, """ - private static native int $getSubscript(int index, long self); + private static native int $getSubscript(int index, long selfPointer); """, """ public void setSubscript(int index, int newValue) { MyStruct.$setSubscript(index, newValue, this.$memoryAddress()); """, """ - private static native void $setSubscript(int index, int newValue, long self); + private static native void $setSubscript(int index, int newValue, long selfPointer); """, ] ) @@ -109,25 +109,25 @@ struct JNISubscriptsTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyStruct__00024getSubscript__J") - public func Java_com_example_swift_MyStruct__00024getSubscript__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jdouble { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + public func Java_com_example_swift_MyStruct__00024getSubscript__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jdouble { + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - return self$.pointee[].getJNIValue(in: environment) + return selfPointer$.pointee[].getJNIValue(in: environment) """, """ @_cdecl("Java_com_example_swift_MyStruct__00024setSubscript__DJ") - public func Java_com_example_swift_MyStruct__00024setSubscript__DJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jdouble, self: jlong) { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + public func Java_com_example_swift_MyStruct__00024setSubscript__DJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jdouble, selfPointer: jlong) { + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - self$.pointee[] = Double(fromJNI: newValue, in: environment) + selfPointer$.pointee[] = Double(fromJNI: newValue, in: environment) """, ] ) @@ -142,25 +142,25 @@ struct JNISubscriptsTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyStruct__00024getSubscript__IJ") - public func Java_com_example_swift_MyStruct__00024getSubscript__IJ(environment: UnsafeMutablePointer!, thisClass: jclass, index: jint, self: jlong) -> jint { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + public func Java_com_example_swift_MyStruct__00024getSubscript__IJ(environment: UnsafeMutablePointer!, thisClass: jclass, index: jint, selfPointer: jlong) -> jint { + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - return self$.pointee[Int32(fromJNI: index, in: environment)].getJNIValue(in: environment) + return selfPointer$.pointee[Int32(fromJNI: index, in: environment)].getJNIValue(in: environment) """, """ @_cdecl("Java_com_example_swift_MyStruct__00024setSubscript__IIJ") - public func Java_com_example_swift_MyStruct__00024setSubscript__IIJ(environment: UnsafeMutablePointer!, thisClass: jclass, index: jint, newValue: jint, self: jlong) { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + public func Java_com_example_swift_MyStruct__00024setSubscript__IIJ(environment: UnsafeMutablePointer!, thisClass: jclass, index: jint, newValue: jint, selfPointer: jlong) { + assert(selfPointer != 0, "selfPointer memory address was null") + let selfPointerBits$ = Int(Int64(fromJNI: selfPointer, in: environment)) + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } - self$.pointee[Int32(fromJNI: index, in: environment)] = Int32(fromJNI: newValue, in: environment) + selfPointer$.pointee[Int32(fromJNI: index, in: environment)] = Int32(fromJNI: newValue, in: environment) """, ] ) diff --git a/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift b/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift index cb8e80f8..f812f62d 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift @@ -57,7 +57,7 @@ struct JNIVariablesTests { } """, """ - private static native long $getConstant(long self); + private static native long $getConstant(long selfPointer); """, ] ) @@ -73,9 +73,9 @@ struct JNIVariablesTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyClass__00024getConstant__J") - public func Java_com_example_swift_MyClass__00024getConstant__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jlong { + public func Java_com_example_swift_MyClass__00024getConstant__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { ... - return self$.pointee.constant.getJNIValue(in: environment) + return selfPointer$.pointee.constant.getJNIValue(in: environment) } """ ] @@ -113,10 +113,10 @@ struct JNIVariablesTests { } """, """ - private static native long $getMutable(long self); + private static native long $getMutable(long selfPointer); """, """ - private static native void $setMutable(long newValue, long self); + private static native void $setMutable(long newValue, long selfPointer); """, ] ) @@ -132,23 +132,23 @@ struct JNIVariablesTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyClass__00024getMutable__J") - public func Java_com_example_swift_MyClass__00024getMutable__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jlong { - assert(self != 0, "self memory address was null") + public func Java_com_example_swift_MyClass__00024getMutable__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { + assert(selfPointer != 0, "selfPointer memory address was null") ... - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") + let selfPointer$ = UnsafeMutablePointer(bitPattern: selfPointerBits$) + guard let selfPointer$ else { + fatalError("selfPointer memory address was null in call to \\(#function)!") } ... - return self$.pointee.mutable.getJNIValue(in: environment) + return selfPointer$.pointee.mutable.getJNIValue(in: environment) } """, """ @_cdecl("Java_com_example_swift_MyClass__00024setMutable__JJ") - public func Java_com_example_swift_MyClass__00024setMutable__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, self: jlong) { - assert(self != 0, "self memory address was null") + public func Java_com_example_swift_MyClass__00024setMutable__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, selfPointer: jlong) { + assert(selfPointer != 0, "selfPointer memory address was null") ... - self$.pointee.mutable = Int64(fromJNI: newValue, in: environment) + selfPointer$.pointee.mutable = Int64(fromJNI: newValue, in: environment) } """, ] @@ -175,7 +175,7 @@ struct JNIVariablesTests { } """, """ - private static native long $getComputed(long self); + private static native long $getComputed(long selfPointer); """, ] ) @@ -191,9 +191,9 @@ struct JNIVariablesTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyClass__00024getComputed__J") - public func Java_com_example_swift_MyClass__00024getComputed__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jlong { + public func Java_com_example_swift_MyClass__00024getComputed__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { ... - return self$.pointee.computed.getJNIValue(in: environment) + return selfPointer$.pointee.computed.getJNIValue(in: environment) } """ ] @@ -220,7 +220,7 @@ struct JNIVariablesTests { } """, """ - private static native long $getComputedThrowing(long self); + private static native long $getComputedThrowing(long selfPointer); """, ] ) @@ -236,10 +236,10 @@ struct JNIVariablesTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyClass__00024getComputedThrowing__J") - public func Java_com_example_swift_MyClass__00024getComputedThrowing__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jlong { + public func Java_com_example_swift_MyClass__00024getComputedThrowing__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { ... do { - return try self$.pointee.computedThrowing.getJNIValue(in: environment) + return try selfPointer$.pointee.computedThrowing.getJNIValue(in: environment) } catch { environment.throwAsException(error) return Int64.jniPlaceholderValue @@ -281,10 +281,10 @@ struct JNIVariablesTests { } """, """ - private static native long $getGetterAndSetter(long self); + private static native long $getGetterAndSetter(long selfPointer); """, """ - private static native void $setGetterAndSetter(long newValue, long self); + private static native void $setGetterAndSetter(long newValue, long selfPointer); """, ] ) @@ -300,16 +300,16 @@ struct JNIVariablesTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyClass__00024getGetterAndSetter__J") - public func Java_com_example_swift_MyClass__00024getGetterAndSetter__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jlong { + public func Java_com_example_swift_MyClass__00024getGetterAndSetter__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jlong { ... - return self$.pointee.getterAndSetter.getJNIValue(in: environment) + return selfPointer$.pointee.getterAndSetter.getJNIValue(in: environment) } """, """ @_cdecl("Java_com_example_swift_MyClass__00024setGetterAndSetter__JJ") - public func Java_com_example_swift_MyClass__00024setGetterAndSetter__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, self: jlong) { + public func Java_com_example_swift_MyClass__00024setGetterAndSetter__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, selfPointer: jlong) { ... - self$.pointee.getterAndSetter = Int64(fromJNI: newValue, in: environment) + selfPointer$.pointee.getterAndSetter = Int64(fromJNI: newValue, in: environment) } """, ] @@ -347,10 +347,10 @@ struct JNIVariablesTests { } """, """ - private static native boolean $isSomeBoolean(long self); + private static native boolean $isSomeBoolean(long selfPointer); """, """ - private static native void $setSomeBoolean(boolean newValue, long self); + private static native void $setSomeBoolean(boolean newValue, long selfPointer); """, ] ) @@ -366,16 +366,16 @@ struct JNIVariablesTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyClass__00024isSomeBoolean__J") - public func Java_com_example_swift_MyClass__00024isSomeBoolean__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jboolean { + public func Java_com_example_swift_MyClass__00024isSomeBoolean__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jboolean { ... - return self$.pointee.someBoolean.getJNIValue(in: environment) + return selfPointer$.pointee.someBoolean.getJNIValue(in: environment) } """, """ @_cdecl("Java_com_example_swift_MyClass__00024setSomeBoolean__ZJ") - public func Java_com_example_swift_MyClass__00024setSomeBoolean__ZJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jboolean, self: jlong) { + public func Java_com_example_swift_MyClass__00024setSomeBoolean__ZJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jboolean, selfPointer: jlong) { ... - self$.pointee.someBoolean = Bool(fromJNI: newValue, in: environment) + selfPointer$.pointee.someBoolean = Bool(fromJNI: newValue, in: environment) } """, ] @@ -413,10 +413,10 @@ struct JNIVariablesTests { } """, """ - private static native boolean $isBoolean(long self); + private static native boolean $isBoolean(long selfPointer); """, """ - private static native void $setBoolean(boolean newValue, long self); + private static native void $setBoolean(boolean newValue, long selfPointer); """, ] ) @@ -432,16 +432,16 @@ struct JNIVariablesTests { expectedChunks: [ """ @_cdecl("Java_com_example_swift_MyClass__00024isBoolean__J") - public func Java_com_example_swift_MyClass__00024isBoolean__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jboolean { + public func Java_com_example_swift_MyClass__00024isBoolean__J(environment: UnsafeMutablePointer!, thisClass: jclass, selfPointer: jlong) -> jboolean { ... - return self$.pointee.isBoolean.getJNIValue(in: environment) + return selfPointer$.pointee.isBoolean.getJNIValue(in: environment) } """, """ @_cdecl("Java_com_example_swift_MyClass__00024setBoolean__ZJ") - public func Java_com_example_swift_MyClass__00024setBoolean__ZJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jboolean, self: jlong) { + public func Java_com_example_swift_MyClass__00024setBoolean__ZJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jboolean, selfPointer: jlong) { ... - self$.pointee.isBoolean = Bool(fromJNI: newValue, in: environment) + selfPointer$.pointee.isBoolean = Bool(fromJNI: newValue, in: environment) } """, ]