@@ -465,54 +465,108 @@ extension Swift2JavaTranslator {
465465 printMethodDowncallHandleForAddrDesc ( & printer)
466466 }
467467
468+ printFunctionDescriptorMethod ( & printer, decl: decl)
469+ printFunctionMethodHandleMethod ( & printer, decl: decl)
470+ printFunctionAddressMethod ( & printer, decl: decl)
471+
472+ // Render the basic "make the downcall" function
473+ if decl. hasParent {
474+ printFuncDowncallMethod ( & printer, decl: decl, selfVariant: . memorySegment)
475+ printFuncDowncallMethod ( & printer, decl: decl, selfVariant: . wrapper)
476+ } else {
477+ printFuncDowncallMethod ( & printer, decl: decl, selfVariant: nil )
478+ }
479+ }
480+
481+ private func printFunctionAddressMethod( _ printer: inout CodePrinter ,
482+ decl: ImportedFunc ,
483+ accessorKind: VariableAccessorKind ? = nil ) {
484+
485+ let addrName = accessorKind? . renderAddrFieldName ?? " ADDR "
486+ let methodNameSegment = accessorKind? . renderMethodNameSegment ?? " "
487+ let snippet = decl. renderCommentSnippet ?? " * "
488+
468489 printer. print (
469490 """
470491 /**
471- * Function descriptor for:
472- * {@snippet lang=swift :
473- * \(/*TODO: make a printSnippet func*/decl.syntax ?? "")
474- * }
492+ * Address for:
493+ \(snippet)
475494 */
476- public static FunctionDescriptor \( decl. baseIdentifier) $descriptor () {
477- return \( decl. baseIdentifier) .DESC ;
495+ public static MemorySegment \( decl. baseIdentifier) \( methodNameSegment ) $address () {
496+ return \( decl. baseIdentifier) . \( addrName ) ;
478497 }
479498 """
480499 )
500+ }
501+
502+ private func printFunctionMethodHandleMethod( _ printer: inout CodePrinter ,
503+ decl: ImportedFunc ,
504+ accessorKind: VariableAccessorKind ? = nil ) {
505+ let handleName = accessorKind? . renderHandleFieldName ?? " HANDLE "
506+ let methodNameSegment = accessorKind? . renderMethodNameSegment ?? " "
507+ let snippet = decl. renderCommentSnippet ?? " * "
481508
482509 printer. print (
483510 """
484511 /**
485512 * Downcall method handle for:
486- * {@snippet lang=swift :
487- * \(/*TODO: make a printSnippet func*/decl.syntax ?? "")
488- * }
513+ \(snippet)
489514 */
490- public static MethodHandle \( decl. baseIdentifier) $handle() {
491- return \( decl. baseIdentifier) .HANDLE ;
515+ public static MethodHandle \( decl. baseIdentifier) \( methodNameSegment ) $handle() {
516+ return \( decl. baseIdentifier) . \( handleName ) ;
492517 }
493518 """
494519 )
520+ }
521+
522+ private func printFunctionDescriptorMethod( _ printer: inout CodePrinter ,
523+ decl: ImportedFunc ,
524+ accessorKind: VariableAccessorKind ? = nil ) {
525+ let descName = accessorKind? . renderDescFieldName ?? " DESC "
526+ let methodNameSegment = accessorKind? . renderMethodNameSegment ?? " "
527+ let snippet = decl. renderCommentSnippet ?? " * "
495528
496529 printer. print (
497530 """
498531 /**
499- * Address for:
500- * {@snippet lang=swift :
501- * \(/*TODO: make a printSnippet func*/decl.syntax ?? "")
502- * }
532+ * Function descriptor for:
533+ \(snippet)
503534 */
504- public static MemorySegment \( decl. baseIdentifier) $address () {
505- return \( decl. baseIdentifier) .ADDR ;
535+ public static FunctionDescriptor \( decl. baseIdentifier) \( methodNameSegment ) $descriptor () {
536+ return \( decl. baseIdentifier) . \( descName ) ;
506537 }
507538 """
508539 )
540+ }
541+
542+ public func printVariableDowncallMethods( _ printer: inout CodePrinter , _ decl: ImportedVariable ) {
543+ printer. printSeparator ( decl. identifier)
544+
545+ printer. printTypeDecl ( " private static class \( decl. baseIdentifier) " ) { printer in
546+ for accessorKind in decl. supportedAccessorKinds {
547+ printPropertyAccessorDescriptorValue ( & printer, decl, accessorKind)
548+ // printFunctionDescriptorValue(&printer, decl);
549+ // printFindMemorySegmentAddrByMangledName(&printer, decl)
550+ // printMethodDowncallHandleForAddrDesc(&printer)
551+ }
552+ }
553+
554+ for accessorKind in decl. supportedAccessorKinds {
555+ guard let accessor = decl. accessorFunc ( kind: accessorKind) else {
556+ log. warning ( " Skip print for \( accessorKind) of \( decl. identifier) ! " )
557+ continue
558+ }
559+ printFunctionDescriptorMethod ( & printer, decl: accessor, accessorKind: accessorKind)
560+ printFunctionMethodHandleMethod ( & printer, decl: accessor, accessorKind: accessorKind)
561+ printFunctionAddressMethod ( & printer, decl: accessor, accessorKind: accessorKind)
562+ }
509563
510564 // Render the basic "make the downcall" function
511565 if decl. hasParent {
512- printFuncDowncallMethod ( & printer, decl: decl, selfVariant: . memorySegment)
513- printFuncDowncallMethod ( & printer, decl: decl, selfVariant: . wrapper)
566+ // printFuncDowncallMethod(&printer, decl: decl, selfVariant: .memorySegment)
567+ // printFuncDowncallMethod(&printer, decl: decl, selfVariant: .wrapper)
514568 } else {
515- printFuncDowncallMethod ( & printer, decl: decl, selfVariant: nil )
569+ // printFuncDowncallMethod(&printer, decl: decl, selfVariant: nil)
516570 }
517571 }
518572
0 commit comments