@@ -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,19 @@ 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 """
585- /**
586- * {@snippet lang = Swift:
587- * \(decl.displayName)
588- * }
589- */
590- public static final MemorySegment ADDR = \( swiftModuleName) .findOrThrow( " \( decl. swiftMangledName) " );
592+ public static final MemorySegment \( accessorKind. renderAddrFieldName) = \( swiftModuleName) .findOrThrow( " \( decl. swiftMangledName) " );
591593 """
592594 ) ;
593595 }
594596
595- func printMethodDowncallHandleForAddrDesc( _ printer: inout CodePrinter ) {
597+ func printMethodDowncallHandleForAddrDesc( _ printer: inout CodePrinter , accessorKind : VariableAccessorKind ? = nil ) {
596598 printer. print (
597599 """
598- public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC );
600+ public static final MethodHandle \( accessorKind . renderHandleFieldName ) = Linker.nativeLinker().downcallHandle( \( accessorKind . renderAddrFieldName ) , \( accessorKind . renderDescFieldName ) );
599601 """
600602 )
601603 }
@@ -781,7 +783,8 @@ extension Swift2JavaTranslator {
781783 public func printFunctionDescriptorValue(
782784 _ printer: inout CodePrinter ,
783785 _ decl: ImportedFunc ,
784- fieldName: String = " DESC " ) {
786+ accessorKind: VariableAccessorKind ? = nil ) {
787+ let fieldName = accessorKind. renderDescFieldName
785788 printer. start ( " public static final FunctionDescriptor \( fieldName) = " )
786789
787790 let parameterLayoutDescriptors = javaMemoryLayoutDescriptors (
@@ -818,14 +821,4 @@ extension Swift2JavaTranslator {
818821 printer. print ( " ); " ) ;
819822 }
820823
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- }
831824}
0 commit comments