@@ -18,7 +18,7 @@ import SwiftJavaJNICore
1818extension FFMSwift2JavaGenerator {
1919 package func printFunctionDowncallMethods(
2020 _ printer: inout CodePrinter ,
21- _ decl: ImportedFunc
21+ _ decl: ImportedFunc ,
2222 ) {
2323 guard let _ = translatedDecl ( for: decl) else {
2424 // Failed to translate. Skip.
@@ -38,7 +38,7 @@ extension FFMSwift2JavaGenerator {
3838 /// Print FFM Java binding descriptors for the imported Swift API.
3939 package func printJavaBindingDescriptorClass(
4040 _ printer: inout CodePrinter ,
41- _ decl: ImportedFunc
41+ _ decl: ImportedFunc ,
4242 ) {
4343 let thunkName = thunkNameRegistry. functionThunkName ( decl: decl)
4444 let translated = self . translatedDecl ( for: decl) !
@@ -58,7 +58,7 @@ extension FFMSwift2JavaGenerator {
5858 package func printJavaBindingDescriptorClass(
5959 _ printer: inout CodePrinter ,
6060 _ cFunc: CFunction ,
61- additionalContent: ( ( inout CodePrinter ) -> Void ) ? = nil
61+ additionalContent: ( ( inout CodePrinter ) -> Void ) ? = nil ,
6262 ) {
6363 printer. printBraceBlock (
6464 """
@@ -87,7 +87,7 @@ extension FFMSwift2JavaGenerator {
8787 func printFunctionDescriptorDefinition(
8888 _ printer: inout CodePrinter ,
8989 _ resultType: CType ,
90- _ parameters: [ CParameter ]
90+ _ parameters: [ CParameter ] ,
9191 ) {
9292 printer. start ( " private static final FunctionDescriptor DESC = " )
9393
@@ -113,7 +113,7 @@ extension FFMSwift2JavaGenerator {
113113
114114 func printJavaBindingDowncallMethod(
115115 _ printer: inout CodePrinter ,
116- _ cFunc: CFunction
116+ _ cFunc: CFunction ,
117117 ) {
118118 let returnTy = cFunc. resultType. javaType
119119 let maybeReturn = cFunc. resultType. isVoid ? " " : " return ( \( returnTy) ) "
@@ -157,7 +157,7 @@ extension FFMSwift2JavaGenerator {
157157 /// * Unnamed-struct parameter as a record. (unimplemented)
158158 func printParameterDescriptorClasses(
159159 _ printer: inout CodePrinter ,
160- _ cFunc: CFunction
160+ _ cFunc: CFunction ,
161161 ) {
162162 for param in cFunc. parameters {
163163 switch param. type {
@@ -172,7 +172,7 @@ extension FFMSwift2JavaGenerator {
172172
173173 func printUpcallParameterDescriptorClasses(
174174 _ printer: inout CodePrinter ,
175- _ outCallback: OutCallback
175+ _ outCallback: OutCallback ,
176176 ) {
177177 let name = outCallback. name
178178 printFunctionPointerParameterDescriptorClass ( & printer, name, outCallback. cFunc. functionType, impl: outCallback)
@@ -199,7 +199,7 @@ extension FFMSwift2JavaGenerator {
199199 _ printer: inout CodePrinter ,
200200 _ name: String ,
201201 _ cType: CType ,
202- impl: OutCallback ?
202+ impl: OutCallback ? ,
203203 ) {
204204 let cResultType : CType
205205 let cParameterTypes : [ CType ]
@@ -267,7 +267,7 @@ extension FFMSwift2JavaGenerator {
267267 /// * User-facing functional interfaces.
268268 func printJavaBindingWrapperHelperClass(
269269 _ printer: inout CodePrinter ,
270- _ decl: ImportedFunc
270+ _ decl: ImportedFunc ,
271271 ) {
272272 let translated = self . translatedDecl ( for: decl) !
273273 let bindingDescriptorName = self . thunkNameRegistry. functionThunkName ( decl: decl)
@@ -290,7 +290,7 @@ extension FFMSwift2JavaGenerator {
290290 func printJavaBindingWrapperFunctionTypeHelper(
291291 _ printer: inout CodePrinter ,
292292 _ functionType: TranslatedFunctionType ,
293- _ bindingDescriptorName: String
293+ _ bindingDescriptorName: String ,
294294 ) {
295295 let cdeclDescriptor = " \( bindingDescriptorName) .$ \( functionType. name) "
296296 if functionType. isCompatibleWithC {
@@ -356,7 +356,7 @@ extension FFMSwift2JavaGenerator {
356356 /// with adding `SwiftArena.ofAuto()` at the end.
357357 package func printJavaBindingWrapperMethod(
358358 _ printer: inout CodePrinter ,
359- _ decl: ImportedFunc
359+ _ decl: ImportedFunc ,
360360 ) {
361361 let translated = self . translatedDecl ( for: decl) !
362362 let methodName = translated. name
@@ -382,14 +382,13 @@ extension FFMSwift2JavaGenerator {
382382 paramDecls. append ( " AllocatingSwiftArena swiftArena " )
383383 }
384384
385- let needsThrows = translatedSignature. parameters. contains { $0. needs32BitIntOverflowCheck != . none } ||
386- translatedSignature. result. needs32BitIntOverflowCheck != . none
385+ let needsThrows = translatedSignature. parameters. contains { $0. needs32BitIntOverflowCheck != . none } || translatedSignature. result. needs32BitIntOverflowCheck != . none
387386 let throwsClause = needsThrows ? " throws SwiftIntegerOverflowException " : " "
388387
389388 TranslatedDocumentation . printDocumentation (
390389 importedFunc: decl,
391390 translatedDecl: translated,
392- in: & printer
391+ in: & printer,
393392 )
394393 printer. printBraceBlock (
395394 """
@@ -410,7 +409,7 @@ extension FFMSwift2JavaGenerator {
410409 /// This assumes that all the parameters are passed-in with appropriate names.
411410 package func printDowncall(
412411 _ printer: inout CodePrinter ,
413- _ decl: ImportedFunc
412+ _ decl: ImportedFunc ,
414413 ) {
415414 //=== Part 1: prepare temporary arena if needed.
416415 let translatedSignature = self . translatedDecl ( for: decl) !. translatedSignature
@@ -479,32 +478,26 @@ extension FFMSwift2JavaGenerator {
479478
480479 let hasOverflowChecks = translatedSignature. parameters. contains { $0. needs32BitIntOverflowCheck != . none }
481480 if hasOverflowChecks {
482- printer. print ( " if (SwiftValueLayout.has32bitSwiftInt) { " )
483- printer. indent ( )
484- for (i, parameter) in translatedSignature. parameters. enumerated ( ) {
485- switch parameter. needs32BitIntOverflowCheck {
486- case . none:
487- break
488- case . signedInt:
489- let original = decl. functionSignature. parameters [ i]
490- let parameterName = original. parameterName ?? " _ \( i) "
491- printer. print ( " if ( \( parameterName) < Integer.MIN_VALUE || \( parameterName) > Integer.MAX_VALUE) { " )
492- printer. indent ( )
493- printer. print ( " throw new SwiftIntegerOverflowException( \" Parameter ' \( parameterName) ' overflow: \" + \( parameterName) ); " )
494- printer. outdent ( )
495- printer. print ( " } " )
496- case . unsignedInt:
497- let original = decl. functionSignature. parameters [ i]
498- let parameterName = original. parameterName ?? " _ \( i) "
499- printer. print ( " if ( \( parameterName) < 0 || \( parameterName) > 0xFFFFFFFFL) { " )
500- printer. indent ( )
501- printer. print ( " throw new SwiftIntegerOverflowException( \" Parameter ' \( parameterName) ' overflow: \" + \( parameterName) ); " )
502- printer. outdent ( )
503- printer. print ( " } " )
481+ printer. printBraceBlock ( " if (SwiftValueLayout.has32bitSwiftInt) " ) { printer in
482+ for (i, parameter) in translatedSignature. parameters. enumerated ( ) {
483+ switch parameter. needs32BitIntOverflowCheck {
484+ case . none:
485+ break
486+ case . signedInt:
487+ let original = decl. functionSignature. parameters [ i]
488+ let parameterName = original. parameterName ?? " _ \( i) "
489+ printer. printBraceBlock ( " if ( \( parameterName) < Integer.MIN_VALUE || \( parameterName) > Integer.MAX_VALUE) " ) { printer in
490+ printer. print ( " throw new SwiftIntegerOverflowException( \" Parameter ' \( parameterName) ' overflow: \" + \( parameterName) ); " )
491+ }
492+ case . unsignedInt:
493+ let original = decl. functionSignature. parameters [ i]
494+ let parameterName = original. parameterName ?? " _ \( i) "
495+ printer. printBraceBlock ( " if ( \( parameterName) < 0 || \( parameterName) > 0xFFFFFFFFL) " ) { printer in
496+ printer. print ( " throw new SwiftIntegerOverflowException( \" Parameter ' \( parameterName) ' overflow: \" + \( parameterName) ); " )
497+ }
498+ }
504499 }
505500 }
506- printer. outdent ( )
507- printer. print ( " } " )
508501 }
509502
510503 //=== Part 3: Downcall.
@@ -533,7 +526,7 @@ extension FFMSwift2JavaGenerator {
533526 let result = translatedSignature. result. conversion. render (
534527 & printer,
535528 placeholder,
536- placeholderForDowncall: placeholderForDowncall
529+ placeholderForDowncall: placeholderForDowncall,
537530 )
538531
539532 if translatedSignature. result. javaResultType != . void {
@@ -560,36 +553,30 @@ extension FFMSwift2JavaGenerator {
560553 private func printReturnWithOverflowCheck(
561554 _ printer: inout CodePrinter ,
562555 value: String ,
563- overflowCheck: OverflowCheckType
556+ overflowCheck: OverflowCheckType ,
564557 ) {
565558 switch overflowCheck {
566559 case . none:
567560 printer. print ( " return \( value) ; " )
568561 case . signedInt:
569562 let resultVar = " _result$checked "
570563 printer. print ( " long \( resultVar) = \( value) ; " )
571- printer. print ( " if (SwiftValueLayout.has32bitSwiftInt) { " )
572- printer. indent ( )
573- printer. print ( " if ( \( resultVar) < Integer.MIN_VALUE || \( resultVar) > Integer.MAX_VALUE) { " )
574- printer. indent ( )
575- printer. print ( " throw new SwiftIntegerOverflowException( \" Return value overflow: \" + \( resultVar) ); " )
576- printer. outdent ( )
577- printer. print ( " } " )
578- printer. outdent ( )
579- printer. print ( " } " )
564+
565+ printer. printBraceBlock ( " if (SwiftValueLayout.has32bitSwiftInt) " ) { printer in
566+ printer. printBraceBlock ( " if ( \( resultVar) < Integer.MIN_VALUE || \( resultVar) > Integer.MAX_VALUE) " ) { printer in
567+ printer. print ( " throw new SwiftIntegerOverflowException( \" Return value overflow: \" + \( resultVar) ); " )
568+ }
569+ }
580570 printer. print ( " return \( resultVar) ; " )
581571 case . unsignedInt:
582572 let resultVar = " _result$checked "
583573 printer. print ( " long \( resultVar) = \( value) ; " )
584- printer. print ( " if (SwiftValueLayout.has32bitSwiftInt) { " )
585- printer. indent ( )
586- printer. print ( " if ( \( resultVar) < 0 || \( resultVar) > 0xFFFFFFFFL) { " )
587- printer. indent ( )
588- printer. print ( " throw new SwiftIntegerOverflowException( \" Return value overflow: \" + \( resultVar) ); " )
589- printer. outdent ( )
590- printer. print ( " } " )
591- printer. outdent ( )
592- printer. print ( " } " )
574+
575+ printer. printBraceBlock ( " if (SwiftValueLayout.has32bitSwiftInt) " ) { printer in
576+ printer. printBraceBlock ( " if ( \( resultVar) < 0 || \( resultVar) > 0xFFFFFFFFL) " ) { printer in
577+ printer. print ( " throw new SwiftIntegerOverflowException( \" Return value overflow: \" + \( resultVar) ); " )
578+ }
579+ }
593580 printer. print ( " return \( resultVar) ; " )
594581 }
595582 }
0 commit comments