@@ -129,7 +129,9 @@ extension Swift2JavaTranslator {
129129 }
130130
131131 // Properties
132- // TODO: property accessors
132+ for varDecl in decl. variables {
133+ printVariableDowncallMethods ( & printer, varDecl)
134+ }
133135
134136 // Methods
135137 for funcDecl in decl. methods {
@@ -482,8 +484,8 @@ extension Swift2JavaTranslator {
482484 decl: ImportedFunc ,
483485 accessorKind: VariableAccessorKind ? = nil ) {
484486
485- let addrName = accessorKind? . renderAddrFieldName ?? " ADDR "
486- let methodNameSegment = accessorKind? . renderMethodNameSegment ?? " "
487+ let addrName = accessorKind. renderAddrFieldName
488+ let methodNameSegment = accessorKind. renderMethodNameSegment
487489 let snippet = decl. renderCommentSnippet ?? " * "
488490
489491 printer. print (
@@ -502,8 +504,8 @@ extension Swift2JavaTranslator {
502504 private func printFunctionMethodHandleMethod( _ printer: inout CodePrinter ,
503505 decl: ImportedFunc ,
504506 accessorKind: VariableAccessorKind ? = nil ) {
505- let handleName = accessorKind? . renderHandleFieldName ?? " HANDLE "
506- let methodNameSegment = accessorKind? . renderMethodNameSegment ?? " "
507+ let handleName = accessorKind. renderHandleFieldName
508+ let methodNameSegment = accessorKind. renderMethodNameSegment
507509 let snippet = decl. renderCommentSnippet ?? " * "
508510
509511 printer. print (
@@ -522,8 +524,8 @@ extension Swift2JavaTranslator {
522524 private func printFunctionDescriptorMethod( _ printer: inout CodePrinter ,
523525 decl: ImportedFunc ,
524526 accessorKind: VariableAccessorKind ? = nil ) {
525- let descName = accessorKind? . renderDescFieldName ?? " DESC "
526- let methodNameSegment = accessorKind? . renderMethodNameSegment ?? " "
527+ let descName = accessorKind. renderDescFieldName
528+ let methodNameSegment = accessorKind. renderMethodNameSegment
527529 let snippet = decl. renderCommentSnippet ?? " * "
528530
529531 printer. print (
@@ -544,10 +546,14 @@ extension Swift2JavaTranslator {
544546
545547 printer. printTypeDecl ( " private static class \( decl. baseIdentifier) " ) { printer in
546548 for accessorKind in decl. supportedAccessorKinds {
547- printPropertyAccessorDescriptorValue ( & printer, decl, accessorKind)
548- // printFunctionDescriptorValue(&printer, decl);
549- // printFindMemorySegmentAddrByMangledName(&printer, decl)
550- // printMethodDowncallHandleForAddrDesc(&printer)
549+ guard let accessor = decl. accessorFunc ( kind: accessorKind) else {
550+ log. warning ( " Skip print for \( accessorKind) of \( decl. identifier) ! " )
551+ continue
552+ }
553+
554+ printFunctionDescriptorValue ( & printer, accessor, accessorKind: accessorKind) ;
555+ printFindMemorySegmentAddrByMangledName ( & printer, accessor, accessorKind: accessorKind)
556+ printMethodDowncallHandleForAddrDesc ( & printer, accessorKind: accessorKind)
551557 }
552558 }
553559
@@ -579,23 +585,24 @@ extension Swift2JavaTranslator {
579585 }
580586 }
581587
582- func printFindMemorySegmentAddrByMangledName( _ printer: inout CodePrinter , _ decl: ImportedFunc ) {
588+ func printFindMemorySegmentAddrByMangledName( _ printer: inout CodePrinter , _ decl: ImportedFunc ,
589+ accessorKind: VariableAccessorKind ? = nil ) {
583590 printer. print (
584591 """
585592 /**
586- * {@snippet lang = Swift:
587- * \(decl.displayName)
588- * }
593+ \(decl.renderCommentSnippet ?? "* ")
589594 */
590- public static final MemorySegment ADDR = \( swiftModuleName) .findOrThrow( " \( decl. swiftMangledName) " );
595+ public static final MemorySegment \( accessorKind. renderAddrFieldName) =
596+ \( swiftModuleName) .findOrThrow( " \( decl. swiftMangledName) " );
591597 """
592598 ) ;
593599 }
594600
595- func printMethodDowncallHandleForAddrDesc( _ printer: inout CodePrinter ) {
601+ func printMethodDowncallHandleForAddrDesc( _ printer: inout CodePrinter , accessorKind : VariableAccessorKind ? = nil ) {
596602 printer. print (
597603 """
598- public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);
604+ public static final MethodHandle \( accessorKind. renderHandleFieldName) =
605+ Linker.nativeLinker().downcallHandle( \( accessorKind. renderAddrFieldName) , \( accessorKind. renderDescFieldName) );
599606 """
600607 )
601608 }
@@ -781,7 +788,8 @@ extension Swift2JavaTranslator {
781788 public func printFunctionDescriptorValue(
782789 _ printer: inout CodePrinter ,
783790 _ decl: ImportedFunc ,
784- fieldName: String = " DESC " ) {
791+ accessorKind: VariableAccessorKind ? = nil ) {
792+ let fieldName = accessorKind. renderDescFieldName
785793 printer. start ( " public static final FunctionDescriptor \( fieldName) = " )
786794
787795 let parameterLayoutDescriptors = javaMemoryLayoutDescriptors (
@@ -818,14 +826,4 @@ extension Swift2JavaTranslator {
818826 printer. print ( " ); " ) ;
819827 }
820828
821- public func printPropertyAccessorDescriptorValue(
822- _ printer: inout CodePrinter ,
823- _ decl: ImportedVariable ,
824- _ kind: VariableAccessorKind ) {
825- guard let funcDecl = decl. accessorFunc ( kind: kind) else {
826- return
827- }
828-
829- printFunctionDescriptorValue ( & printer, funcDecl, fieldName: kind. renderDescFieldName)
830- }
831829}
0 commit comments