From ab46995d4a2915d03254c6877c108e99f5b96132 Mon Sep 17 00:00:00 2001 From: jferreyra Date: Fri, 15 Dec 2023 13:33:59 -0800 Subject: [PATCH 01/68] Improving examples build configs and documentation. --- README.md | 6 +++--- bzl/android_configure.bzl | 2 +- examples/BUILD | 2 +- examples/ios/TextSort.xcodeproj/project.pbxproj | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 83290c6f..1f0695e8 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,9 @@ to build and run Objective-C and Java tests. ### Building and running the mobile example apps -The Android example app can be build with bazel: `bazel build -//examples:android-app`, and then install to a device with `adb install -bazel-bin/examples/android-app.apk` +You need to install the Android SDK 30.0.3 and the NDK 21.4.7075529. You need both `ANDROID_SDK_HOME` and `ANDROID_NDK_HOME` env variables set. +The Android example app can be build with bazel: `bazel build //examples:android-app`, +and then install to a device with `adb install bazel-bin/examples/android-app.apk` The iOS example app are built with Xcode. Simply open the project in Xcode and it should work. diff --git a/bzl/android_configure.bzl b/bzl/android_configure.bzl index 13550d9e..4f8ce7c2 100644 --- a/bzl/android_configure.bzl +++ b/bzl/android_configure.bzl @@ -24,7 +24,7 @@ def _android_autoconf_impl(repository_ctx): name="androidsdk", path="{}", api_level=30, - build_tools_version="30.0.2", + build_tools_version="30.0.3", ) """.format(sdk_home) diff --git a/examples/BUILD b/examples/BUILD index 74a1b99c..e1442ba8 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -53,7 +53,7 @@ android_library( srcs = glob(["handwritten-src/java/com/dropbox/textsort/*.java"]), custom_package = "com.dropbox.textsort", manifest = "android/app/src/main/AndroidManifest.xml", - resource_files = glob(["android/app/src/main/res/**"]), + resource_files = glob(["android/app/src/main/res/**"], exclude=["android/app/src/main/res/.DS_Store"]), deps = [":textsort-java",], ) diff --git a/examples/ios/TextSort.xcodeproj/project.pbxproj b/examples/ios/TextSort.xcodeproj/project.pbxproj index ed799f19..1dd7294e 100644 --- a/examples/ios/TextSort.xcodeproj/project.pbxproj +++ b/examples/ios/TextSort.xcodeproj/project.pbxproj @@ -428,6 +428,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TextSort/TextSort-Prefix.pch"; INFOPLIST_FILE = "TextSort/TextSort-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "Dropbox.${PRODUCT_NAME:rfc1034identifier}"; @@ -449,6 +450,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TextSort/TextSort-Prefix.pch"; INFOPLIST_FILE = "TextSort/TextSort-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "Dropbox.${PRODUCT_NAME:rfc1034identifier}"; From fb63bbc2424feb0b12af45a9c1563149b3acbf39 Mon Sep 17 00:00:00 2001 From: jferreyra Date: Fri, 15 Dec 2023 13:42:23 -0800 Subject: [PATCH 02/68] reverted to sdk 30.0.2 --- README.md | 2 +- bzl/android_configure.bzl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1f0695e8..a876f96c 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ to build and run Objective-C and Java tests. ### Building and running the mobile example apps -You need to install the Android SDK 30.0.3 and the NDK 21.4.7075529. You need both `ANDROID_SDK_HOME` and `ANDROID_NDK_HOME` env variables set. +You need to install the Android SDK 30.0.2 and the NDK 21.4.7075529. You need both `ANDROID_SDK_HOME` and `ANDROID_NDK_HOME` env variables set. The Android example app can be build with bazel: `bazel build //examples:android-app`, and then install to a device with `adb install bazel-bin/examples/android-app.apk` diff --git a/bzl/android_configure.bzl b/bzl/android_configure.bzl index 4f8ce7c2..13550d9e 100644 --- a/bzl/android_configure.bzl +++ b/bzl/android_configure.bzl @@ -24,7 +24,7 @@ def _android_autoconf_impl(repository_ctx): name="androidsdk", path="{}", api_level=30, - build_tools_version="30.0.3", + build_tools_version="30.0.2", ) """.format(sdk_home) From 0e5bd4850d83be3973cb326d7f074fc86501d51e Mon Sep 17 00:00:00 2001 From: jferreyra Date: Mon, 18 Dec 2023 19:12:04 -0800 Subject: [PATCH 03/68] Set min deployment target on iOS 11 for the example xcode project --- examples/ios/TextSort.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ios/TextSort.xcodeproj/project.pbxproj b/examples/ios/TextSort.xcodeproj/project.pbxproj index 1dd7294e..0c025a7e 100644 --- a/examples/ios/TextSort.xcodeproj/project.pbxproj +++ b/examples/ios/TextSort.xcodeproj/project.pbxproj @@ -428,7 +428,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TextSort/TextSort-Prefix.pch"; INFOPLIST_FILE = "TextSort/TextSort-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "Dropbox.${PRODUCT_NAME:rfc1034identifier}"; @@ -450,7 +450,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TextSort/TextSort-Prefix.pch"; INFOPLIST_FILE = "TextSort/TextSort-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "Dropbox.${PRODUCT_NAME:rfc1034identifier}"; From f2143f895f854f0bc0dbc1972660fbdaf60354c5 Mon Sep 17 00:00:00 2001 From: jferreyra Date: Mon, 18 Dec 2023 19:12:31 -0800 Subject: [PATCH 04/68] Added npm instructions and examples server instructions. --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a876f96c..663f915f 100644 --- a/README.md +++ b/README.md @@ -301,9 +301,11 @@ Notable differences when comparing to the Java/ObjC support: easily add extension methods (by add functions to prototype) without having to derive from a base class. -The command to run Wasm/TypeScript unit tests is `bazel run -//test-suite:server-ts`. You will need the `tsc` compiler and the `browserify` -tool to run these tests. +Use `bazel run //test-suite:server-ts` to run the Wasm/TypeScript unit tests. +You will need `npm` and run `npm install` in the `test-suite` folder. +You need as well the `tsc` compiler and the `browserify` tool to run these tests. + +To run the examples server: `bazel run //examples:server` ## Async interface support From fd1b31418662857fa5d50f070251c575d209c918 Mon Sep 17 00:00:00 2001 From: Jan Buenker Date: Thu, 14 Mar 2024 12:30:23 +0100 Subject: [PATCH 05/68] Use std::expected for outcome when available --- README.md | 3 ++- support-lib/cpp/expected.hpp | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 83290c6f..5026c22b 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,8 @@ outcome Where RESULT and ERROR can be any Djinni types (primitives or records). -In C++, the `outcome<>` type maps to the template class `djinni::expected<>`. +In C++, the `outcome<>` type maps to the template `djinni::expected<>`, +which is an alias of `std::expected<>` if supported or a drop-in replacement otherwise. In Java, it maps to the generic class `com.snapchat.djinni.Outcome<>`. In ObjC, it maps to the generic class `DJOutcome<>`. diff --git a/support-lib/cpp/expected.hpp b/support-lib/cpp/expected.hpp index d3143fc7..31877afb 100644 --- a/support-lib/cpp/expected.hpp +++ b/support-lib/cpp/expected.hpp @@ -1,5 +1,27 @@ #pragma once +#ifdef __has_include +#if __has_include() +#include +#endif +#endif + +#include +#include + +#ifdef __cpp_lib_expected + +#include + +namespace djinni { + +using ::std::expected; +using ::std::unexpected; + +} + +#else + #include "tl_expected.hpp" namespace djinni { @@ -7,9 +29,15 @@ namespace djinni { using ::tl::unexpected; using ::tl::expected; +} + +#endif + +namespace djinni { + template -unexpected::type> make_unexpected(E &&e) { - return tl::unexpected::type>(std::forward(e)); +djinni::unexpected::type> make_unexpected(E &&e) { + return djinni::unexpected::type>(std::forward(e)); } } From 5e03b1177088578e1cb74e987c1ea93b00fdc75c Mon Sep 17 00:00:00 2001 From: Li Feng Date: Tue, 16 Apr 2024 12:52:38 +1000 Subject: [PATCH 06/68] swift test --- WORKSPACE | 18 ++++++++++-------- test-suite/BUILD | 6 ++++++ .../handwritten-src/swift/AllTests.swift | 12 ++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 test-suite/handwritten-src/swift/AllTests.swift diff --git a/WORKSPACE b/WORKSPACE index 25a1a4fc..44ef08e0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -16,26 +16,26 @@ android_workspace() load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -build_bazel_rules_apple_version = "1.0.1" +build_bazel_rules_apple_version = "1.1.3" http_archive( name = "build_bazel_rules_apple", - sha256 = "36072d4f3614d309d6a703da0dfe48684ec4c65a89611aeb9590b45af7a3e592", + sha256 = "f94e6dddf74739ef5cb30f000e13a2a613f6ebfa5e63588305a71fce8a8a9911", url = "https://github.com/bazelbuild/rules_apple/releases/download/{0}/rules_apple.{0}.tar.gz" .format(build_bazel_rules_apple_version), ) -build_bazel_rules_swift_version = "1.0.0" +build_bazel_rules_swift_version = "1.14.0" http_archive( name = "build_bazel_rules_swift", - sha256 = "12057b7aa904467284eee640de5e33853e51d8e31aae50b3fb25d2823d51c6b8", + sha256 = "9b0064197e3b6c123cf7cbd377ad5071ac020cbd208fcc23dbc9f3928baf4fa2", url = "https://github.com/bazelbuild/rules_swift/releases/download/{0}/rules_swift.{0}.tar.gz" .format(build_bazel_rules_swift_version), ) -build_bazel_apple_support_version = "1.0.0" +build_bazel_apple_support_version = "1.15.1" http_archive( name = "build_bazel_apple_support", - sha256 = "df317473b5894dd8eb432240d209271ebc83c76bb30c55481374b36ddf1e4fd1", + sha256 = "c4bb2b7367c484382300aee75be598b92f847896fb31bbd22f3a2346adf66a80", url = "https://github.com/bazelbuild/apple_support/releases/download/{0}/apple_support.{0}.tar.gz" .format(build_bazel_apple_support_version), ) @@ -50,13 +50,15 @@ http_archive( ) load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies") -load("@build_bazel_rules_swift//swift:repositories.bzl", "swift_rules_dependencies") load("@build_bazel_apple_support//lib:repositories.bzl", "apple_support_dependencies") +load("@build_bazel_rules_swift//swift:repositories.bzl", "swift_rules_dependencies") +load("@build_bazel_rules_swift//swift:extras.bzl", "swift_rules_extra_dependencies",) load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") apple_rules_dependencies() -swift_rules_dependencies() apple_support_dependencies() +swift_rules_dependencies() +swift_rules_extra_dependencies() kotlin_repositories() kt_register_toolchains() diff --git a/test-suite/BUILD b/test-suite/BUILD index fa6cb8dd..9b3576b6 100644 --- a/test-suite/BUILD +++ b/test-suite/BUILD @@ -1,6 +1,7 @@ load("@rules_cc//cc:defs.bzl", "cc_library", "cc_binary", "objc_library") load("@rules_java//java:defs.bzl", "java_test") load("@build_bazel_rules_apple//apple:macos.bzl", "macos_unit_test") +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library", "swift_test") load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") cc_library( @@ -191,3 +192,8 @@ sh_binary( data = glob(["handwritten-src/js/*.html", "handwritten-src/js/*.js"]) + [":wasm"] ) + +swift_test( + name = "djinni-swift-tests", + srcs = ['handwritten-src/swift/AllTests.swift'] +) diff --git a/test-suite/handwritten-src/swift/AllTests.swift b/test-suite/handwritten-src/swift/AllTests.swift new file mode 100644 index 00000000..507bb461 --- /dev/null +++ b/test-suite/handwritten-src/swift/AllTests.swift @@ -0,0 +1,12 @@ +import XCTest +// @testable import swift + +final class AllTests: XCTestCase { + func testExample() throws { + // XCTest Documentation + // https://developer.apple.com/documentation/xctest + + // Defining Test Cases and Test Methods + // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods + } +} From 3f40e5abc43fe6a7751e1c5a850492fc3e359c44 Mon Sep 17 00:00:00 2001 From: Jan Buenker Date: Wed, 8 May 2024 17:42:16 +0200 Subject: [PATCH 07/68] Fix compilation for djinni::Future --- support-lib/cpp/Future.hpp | 3 ++- support-lib/objc/Future_objc.hpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/support-lib/cpp/Future.hpp b/support-lib/cpp/Future.hpp index fc2adffb..dede703d 100644 --- a/support-lib/cpp/Future.hpp +++ b/support-lib/cpp/Future.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef __cpp_coroutines #if __has_include() @@ -414,7 +415,7 @@ Future combine(U&& futures, size_t c) { return future; } for (auto& f: futures) { - f.then([context] (auto f) { + f.then([context] (auto) { if (--(context->counter) == 0) { context->promise.setValue(); } diff --git a/support-lib/objc/Future_objc.hpp b/support-lib/objc/Future_objc.hpp index 339b9780..0249156b 100644 --- a/support-lib/objc/Future_objc.hpp +++ b/support-lib/objc/Future_objc.hpp @@ -82,7 +82,7 @@ class FutureAdaptor __block auto p = std::make_unique(); auto f = p->getFuture(); - [o then: ^id(DJFuture* res) { + [o then: ^id(DJFuture*) { @try { p->setValue(); } @catch (NSException* e) { @@ -98,7 +98,7 @@ class FutureAdaptor DJPromise* promise = [[DJPromise alloc] init]; DJFuture* future = [promise getFuture]; - c.then([promise] (Future res) { + c.then([promise] (Future) { try { [promise setValue:[NSNull null]]; } catch (const std::exception& e) { From 2e8e23186e7d54839d91e9d1666c72f89aaf7ec7 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Thu, 16 May 2024 14:36:07 +1000 Subject: [PATCH 08/68] wip example --- WORKSPACE | 9 +- examples/BUILD | 68 ++++++++++++ .../swift/ItemList+Private.swift | 16 +++ examples/generated-src/swift/ItemList.swift | 7 ++ .../swift/SortItems+Private.swift | 43 +++++++ examples/generated-src/swift/SortItems.swift | 3 + .../swift/SortOrder+Private.swift | 4 + examples/generated-src/swift/SortOrder.swift | 5 + .../swift/TextboxListener+Private.swift | 44 ++++++++ .../generated-src/swift/TextboxListener.swift | 3 + .../generated-src/swiftxx/NativeSortItems.cpp | 84 ++++++++++++++ .../generated-src/swiftxx/NativeSortItems.hpp | 24 ++++ support-lib/BUILD | 41 +++++++ support-lib/swift/DjinniSupport.swift | 47 ++++++++ support-lib/swiftxx/djinni_support.cpp | 62 +++++++++++ support-lib/swiftxx/djinni_support.hpp | 105 ++++++++++++++++++ test-suite/BUILD | 9 +- .../handwritten-src/swift/AllTests.swift | 19 +++- 18 files changed, 580 insertions(+), 13 deletions(-) create mode 100644 examples/generated-src/swift/ItemList+Private.swift create mode 100644 examples/generated-src/swift/ItemList.swift create mode 100644 examples/generated-src/swift/SortItems+Private.swift create mode 100644 examples/generated-src/swift/SortItems.swift create mode 100644 examples/generated-src/swift/SortOrder+Private.swift create mode 100644 examples/generated-src/swift/SortOrder.swift create mode 100644 examples/generated-src/swift/TextboxListener+Private.swift create mode 100644 examples/generated-src/swift/TextboxListener.swift create mode 100644 examples/generated-src/swiftxx/NativeSortItems.cpp create mode 100644 examples/generated-src/swiftxx/NativeSortItems.hpp create mode 100644 support-lib/swift/DjinniSupport.swift create mode 100644 support-lib/swiftxx/djinni_support.cpp create mode 100644 support-lib/swiftxx/djinni_support.hpp diff --git a/WORKSPACE b/WORKSPACE index 44ef08e0..cb090799 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -20,24 +20,21 @@ build_bazel_rules_apple_version = "1.1.3" http_archive( name = "build_bazel_rules_apple", sha256 = "f94e6dddf74739ef5cb30f000e13a2a613f6ebfa5e63588305a71fce8a8a9911", - url = "https://github.com/bazelbuild/rules_apple/releases/download/{0}/rules_apple.{0}.tar.gz" - .format(build_bazel_rules_apple_version), + url = "https://github.com/bazelbuild/rules_apple/releases/download/{0}/rules_apple.{0}.tar.gz" .format(build_bazel_rules_apple_version), ) build_bazel_rules_swift_version = "1.14.0" http_archive( name = "build_bazel_rules_swift", sha256 = "9b0064197e3b6c123cf7cbd377ad5071ac020cbd208fcc23dbc9f3928baf4fa2", - url = "https://github.com/bazelbuild/rules_swift/releases/download/{0}/rules_swift.{0}.tar.gz" - .format(build_bazel_rules_swift_version), + url = "https://github.com/bazelbuild/rules_swift/releases/download/{0}/rules_swift.{0}.tar.gz" .format(build_bazel_rules_swift_version), ) build_bazel_apple_support_version = "1.15.1" http_archive( name = "build_bazel_apple_support", sha256 = "c4bb2b7367c484382300aee75be598b92f847896fb31bbd22f3a2346adf66a80", - url = "https://github.com/bazelbuild/apple_support/releases/download/{0}/apple_support.{0}.tar.gz" - .format(build_bazel_apple_support_version), + url = "https://github.com/bazelbuild/apple_support/releases/download/{0}/apple_support.{0}.tar.gz" .format(build_bazel_apple_support_version), ) rules_kotlin_version = "legacy-1.3.0" diff --git a/examples/BUILD b/examples/BUILD index 74a1b99c..3396df15 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -1,6 +1,7 @@ load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application") load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") cc_library( name = "textsort-common", @@ -19,7 +20,9 @@ cc_library( deps = [ "//support-lib:djinni-support-common", ], + tags = ["swift_module"], alwayslink = 1, + visibility = ["//visibility:public"], ) # ------------------------------------------------------------------ @@ -99,3 +102,68 @@ sh_binary( srcs = ["ts/run.sh"], data = glob(["ts/*.html", "ts/*.ts", "ts/*.json", "generated-src/ts/*.ts"]) + [":wasm"] ) + +# ------------------------------------------------------------------ + +swift_private_files = "generated-src/swift/*+Private.swift" + +swift_library( + name = "textsort-swift", + module_name = "TextSort", + generated_header_name = "Textsort-Swift.h", + generates_header = True, + srcs = glob([ + "generated-src/swift/*.swift", + ], exclude = [ swift_private_files ]), + copts = [ + "-cxx-interoperability-mode=default", + "-Xcc", "-std=c++17", + ], + deps = [ + "//support-lib:djinni-support-swift", + ], + visibility = ["//visibility:public"], +) + +swift_library( + name = "textsort-swiftimp", + module_name = "TextSortImp", + srcs = glob([swift_private_files,]), + copts = [ + "-cxx-interoperability-mode=default", + "-Xcc", "-std=c++17", + ], + deps = [ + ":textsort-common", + ":textsort-swift", + ":textsort-swiftxx", + "//support-lib:djinni-support-swift", + "//support-lib:djinni-support-swiftxx", + ], + visibility = ["//visibility:public"], +) + +cc_library( + name = "textsort-swiftxx", + srcs = glob([ + "generated-src/swiftxx/*.cpp", + ]), + hdrs = glob([ + "generated-src/swiftxx/*.hpp", + ]), + includes = [ + "generated-src/swiftxx", + ".", + ], + deps = [ + ":textsort-common", + ":textsort-swift", + "//support-lib:djinni-support-common", + "//support-lib:djinni-support-swiftxx", + ], + copts = [ + "-std=c++17", + ], + tags = ["swift_module"], + visibility = ["//visibility:public"], +) diff --git a/examples/generated-src/swift/ItemList+Private.swift b/examples/generated-src/swift/ItemList+Private.swift new file mode 100644 index 00000000..d6203ba1 --- /dev/null +++ b/examples/generated-src/swift/ItemList+Private.swift @@ -0,0 +1,16 @@ +import TextSort // Swift Djinni API +import DjinniSupport // Swift support library +import support_lib_djinni_support_swiftxx // C++ support library + +enum ItemListMarshaller: Marshaller { + typealias SwiftType = ItemList + static func fromCpp(_ v: djinni.AnyValue) -> SwiftType { + let items = DjinniSupport.ListMarshaller.fromCpp(djinni.getMember(v, 0)) + return ItemList(items: items) + } + static func toCpp(_ s: SwiftType) -> djinni.AnyValue { + let v = djinni.makeCompositeValue() + djinni.addMember(v, ListMarshaller.toCpp(s.items)) + return v + } +} diff --git a/examples/generated-src/swift/ItemList.swift b/examples/generated-src/swift/ItemList.swift new file mode 100644 index 00000000..ae413d4a --- /dev/null +++ b/examples/generated-src/swift/ItemList.swift @@ -0,0 +1,7 @@ +public struct ItemList { + public var items: [String] + + public init(items: [String]) { + self.items = items + } +}; diff --git a/examples/generated-src/swift/SortItems+Private.swift b/examples/generated-src/swift/SortItems+Private.swift new file mode 100644 index 00000000..38c5bdf4 --- /dev/null +++ b/examples/generated-src/swift/SortItems+Private.swift @@ -0,0 +1,43 @@ +import TextSort // Swift Djinni API +import DjinniSupport // Swift support library +import support_lib_djinni_support_swiftxx // C++ support library +import examples_textsort_swiftxx // C++ bridge code + +class SortItemsProxy: SortItems { + var inst: djinni.AnyValue + init(_ inst: djinni.AnyValue) { + self.inst = inst + } + func sort(order: SortOrder, items: ItemList) { + var params = djinni.ParameterList() + params.addValue(inst) + params.addValue(SortOrderMarshaller.toCpp(order)) + params.addValue(ItemListMarshaller.toCpp(items)) + djinni_generated.SortItems_sort(params) + } +} + +enum SortItemsMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = SortItems + static func fromCpp(_ v: djinni.AnyValue) -> SwiftType { + return SortItemsProxy(v) + } + static func toCpp(_ v: SwiftType) -> djinni.AnyValue { + return djinni.nilValue() // no +swift + } +} + +public class SortItems_statics { + static func createWithListener(listener: TextboxListener)-> SortItems { + var params = djinni.ParameterList() + params.addValue(TextboxListenerMarshaller.toCpp(listener)) + let ret = djinni_generated.SortItems_createWithListener(params) + return SortItemsMarshaller.fromCpp(ret) + } + static func runSort(items: ItemList)-> ItemList { + var params = djinni.ParameterList() + params.addValue(ItemListMarshaller.toCpp(items)) + let ret = djinni_generated.SortItems_runSort(params) + return ItemListMarshaller.fromCpp(ret) + } +} diff --git a/examples/generated-src/swift/SortItems.swift b/examples/generated-src/swift/SortItems.swift new file mode 100644 index 00000000..f919db64 --- /dev/null +++ b/examples/generated-src/swift/SortItems.swift @@ -0,0 +1,3 @@ +public protocol SortItems { + func sort(order: SortOrder, items: ItemList) +} diff --git a/examples/generated-src/swift/SortOrder+Private.swift b/examples/generated-src/swift/SortOrder+Private.swift new file mode 100644 index 00000000..d2ce68aa --- /dev/null +++ b/examples/generated-src/swift/SortOrder+Private.swift @@ -0,0 +1,4 @@ +import TextSort +import DjinniSupport + +typealias SortOrderMarshaller = EnumMarshaller diff --git a/examples/generated-src/swift/SortOrder.swift b/examples/generated-src/swift/SortOrder.swift new file mode 100644 index 00000000..66cf38eb --- /dev/null +++ b/examples/generated-src/swift/SortOrder.swift @@ -0,0 +1,5 @@ +public enum SortOrder: Int32 { + case ASCENDING = 0 + case DESCENDING = 1 + case RANDOM = 2 +} diff --git a/examples/generated-src/swift/TextboxListener+Private.swift b/examples/generated-src/swift/TextboxListener+Private.swift new file mode 100644 index 00000000..6458c9dc --- /dev/null +++ b/examples/generated-src/swift/TextboxListener+Private.swift @@ -0,0 +1,44 @@ +import examples_textsort_swiftxx +import TextSort +import DjinniSupport +import support_lib_djinni_support_swiftxx + +class TextboxListenerProxy: TextboxListener { + var inst: djinni.AnyValue + init(_ inst: djinni.AnyValue) { + self.inst = inst + } + func update(items: ItemList) { + var params = djinni.ParameterList() + params.addValue(inst) + params.addValue(ItemListMarshaller.toCpp(items)) + djinni_generated.TextboxListener_update(params) + } +} + +func textboxListenerDispatcher(_ instance: UnsafeMutableRawPointer?, + idx: Int32, + params: UnsafePointer?, + ret: UnsafeMutablePointer?) -> Void { + guard let ptr = instance else { return } + if (idx < 0) { + let _ = Unmanaged.fromOpaque(ptr).takeRetainedValue() + return + } + guard let listener = Unmanaged.fromOpaque(ptr).takeUnretainedValue() as? TextboxListener else { return } + if (idx == 0) { + let items = ItemListMarshaller.fromCpp(params.pointee.getValue(0)) + listener.update(items: items) + } +} + +enum TextboxListenerMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TextboxListener + static func fromCpp(_ v: djinni.AnyValue) -> SwiftType { + return TextboxListenerProxy(v) + } + static func toCpp(_ listener: TextboxListener) -> djinni.AnyValue { + let instance = Unmanaged.passRetained(listener as AnyObject).toOpaque() + return djinni_generated.TextboxListenerProtocolWrapper.make(instance, textboxListenerDispatcher) + } +} diff --git a/examples/generated-src/swift/TextboxListener.swift b/examples/generated-src/swift/TextboxListener.swift new file mode 100644 index 00000000..e5c354e6 --- /dev/null +++ b/examples/generated-src/swift/TextboxListener.swift @@ -0,0 +1,3 @@ +public protocol TextboxListener { + func update(items: ItemList) +} diff --git a/examples/generated-src/swiftxx/NativeSortItems.cpp b/examples/generated-src/swiftxx/NativeSortItems.cpp new file mode 100644 index 00000000..0eaf5eb5 --- /dev/null +++ b/examples/generated-src/swiftxx/NativeSortItems.cpp @@ -0,0 +1,84 @@ +#include +#include + +namespace djinni_generated { + +struct NativeItemList { + static djinni::AnyValue fromCpp(const textsort::ItemList& v) { + auto ret = std::make_shared(); + ret->addValue(djinni::List::fromCpp(v.items)); + return {ret}; + } + static textsort::ItemList toCpp(const djinni::AnyValue& v) { + auto c = std::get(v); + return textsort::ItemList(djinni::List::toCpp(c->getValue(0))); + } +}; + + +void TextboxListenerProtocolWrapper::update(const textsort::ItemList& items) { + djinni::ParameterList params; + params.addValue(NativeItemList::fromCpp(items)); + callProtocol(0, params); +} + + +struct NativeTextboxListener { + static std::shared_ptr toCpp(const djinni::AnyValue& v) { + auto p = std::get(v); + return std::reinterpret_pointer_cast(p); + } +}; + +struct NativeSortItems { + static djinni::AnyValue fromCpp(const std::shared_ptr& v) { + return {v}; + } + static std::shared_ptr toCpp(const djinni::AnyValue& v) { + auto p = std::get(v); + return std::reinterpret_pointer_cast(p); + } +}; + +struct NativeSortOrder { + static djinni::AnyValue fromCpp(textsort::sort_order v) { + return {static_cast(v)}; + } + static textsort::sort_order toCpp(const djinni::AnyValue& v) { + auto i = std::get(v); + return static_cast(i); + } +}; + +djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList& params) { + auto listener = NativeTextboxListener::toCpp(params.getValue(0)); + auto ret = textsort::SortItems::create_with_listener(listener); + return NativeSortItems::fromCpp(ret); +} + +djinni::AnyValue SortItems_runSort(const djinni::ParameterList& params) { + auto items = NativeItemList::toCpp(params.getValue(0)); + auto ret = textsort::SortItems::run_sort(items); + return NativeItemList::fromCpp(ret); +} + +djinni::AnyValue SortItems_sort(const djinni::ParameterList& params) { + auto inst = NativeSortItems::toCpp(params.getValue(0)); + auto order = NativeSortOrder::toCpp(params.getValue(1)); + auto items = NativeItemList::toCpp(params.getValue(2)); + inst->sort(order, items); + return djinni::nilValue(); +} + +djinni::AnyValue TextboxListener_update(const djinni::ParameterList& params) { + auto inst = NativeTextboxListener::toCpp(params.getValue(0)); + auto items = NativeItemList::toCpp(params.getValue(1)); + inst->update(items); + return djinni::nilValue(); +} + +djinni::AnyValue TextboxListenerProtocolWrapper::make(void* instance, djinni::DispatchFunc dispatcher) { + return {std::make_shared(instance, dispatcher)}; +} + +} diff --git a/examples/generated-src/swiftxx/NativeSortItems.hpp b/examples/generated-src/swiftxx/NativeSortItems.hpp new file mode 100644 index 00000000..0859bb1f --- /dev/null +++ b/examples/generated-src/swiftxx/NativeSortItems.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "sort_items.hpp" +#include "textbox_listener.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +class TextboxListenerProtocolWrapper: public textsort::TextboxListener, public djinni::ProtocolWrapper { +public: + TextboxListenerProtocolWrapper(void* instance, djinni::DispatchFunc dispatcher): djinni::ProtocolWrapper(instance, dispatcher) {} + static djinni::AnyValue make(void* instance, djinni::DispatchFunc dispatcher); + void update(const textsort::ItemList& items) override; +}; + +djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList& params); + +djinni::AnyValue SortItems_runSort(const djinni::ParameterList& params); + +djinni::AnyValue SortItems_sort(const djinni::ParameterList& params); + +djinni::AnyValue TextboxListener_update(const djinni::ParameterList& params); + +} diff --git a/support-lib/BUILD b/support-lib/BUILD index 384ea200..f9fe786c 100644 --- a/support-lib/BUILD +++ b/support-lib/BUILD @@ -1,11 +1,13 @@ load("@rules_cc//cc:defs.bzl", "cc_library", "objc_library") load("@rules_java//java:defs.bzl", "java_library") +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") cc_library( name = "djinni-support-common", srcs = glob(["cpp/*.cpp"]), hdrs = glob(["*.hpp", "cpp/*.hpp"]), includes = ["cpp"], + tags = ["swift_module"], visibility = ["//visibility:public"], ) @@ -77,3 +79,42 @@ sh_library( data = glob(["ts/*.ts"]), visibility = ["//visibility:public"], ) + +swift_library( + name = "djinni-support-swift", + module_name = "DjinniSupport", + srcs = glob([ + "swift/*.swift", + ]), + copts = [ + "-cxx-interoperability-mode=default", + "-Xcc", "-std=c++17", + ], + deps = [ + ":djinni-support-common", + ":djinni-support-swiftxx", + ], + visibility = ["//visibility:public"], +) + +cc_library( + name = "djinni-support-swiftxx", + srcs = glob([ + "swiftxx/*.cpp", + ]), + hdrs = glob([ + "swiftxx/*.hpp", + ]), + includes = [ + "swiftxx", + ".", + ], + deps = [ + ":djinni-support-common", + ], + copts = [ + "-std=c++17", + ], + tags = ["swift_module"], + visibility = ["//visibility:public"], +) diff --git a/support-lib/swift/DjinniSupport.swift b/support-lib/swift/DjinniSupport.swift new file mode 100644 index 00000000..a7c11219 --- /dev/null +++ b/support-lib/swift/DjinniSupport.swift @@ -0,0 +1,47 @@ +import support_lib_djinni_support_common +import support_lib_djinni_support_swiftxx + +public protocol Marshaller { + associatedtype SwiftType + static func fromCpp(_ v: djinni.AnyValue) -> SwiftType + static func toCpp(_ s: SwiftType) -> djinni.AnyValue +} + +public enum EnumMarshaller: Marshaller where T.RawValue == Int32 { + public typealias SwiftType = T + public static func fromCpp(_ v: djinni.AnyValue) -> SwiftType { + return SwiftType(rawValue: djinni.toI32(v))! + } + public static func toCpp(_ s: SwiftType) -> djinni.AnyValue { + return djinni.fromI32(s.rawValue) + } +} + +public enum StringMarshaller: Marshaller { + public typealias SwiftType = String + static public func fromCpp(_ v: djinni.AnyValue) -> SwiftType { + return String(djinni.toString(v)) + } + static public func toCpp(_ s: SwiftType) -> djinni.AnyValue { + return djinni.fromString(std.string(s)) + } +} + +public enum ListMarshaller: Marshaller { + public typealias SwiftType = [T.SwiftType] + static public func fromCpp(_ v: djinni.AnyValue) -> SwiftType { + let size = djinni.getSize(v) + var array = SwiftType() + for i in 0.. djinni.AnyValue { + let composite = djinni.makeCompositeValue() + for item in s { + djinni.addMember(composite, T.toCpp(item)) + } + return composite + } +} diff --git a/support-lib/swiftxx/djinni_support.cpp b/support-lib/swiftxx/djinni_support.cpp new file mode 100644 index 00000000..29c14f3f --- /dev/null +++ b/support-lib/swiftxx/djinni_support.cpp @@ -0,0 +1,62 @@ +#include "djinni_support.hpp" + +namespace djinni { + +StringValue toString(const AnyValue& v) { + return std::get(v); +} +AnyValue fromString(const StringValue& s) { + return {s}; +} + +I32Value toI32(const AnyValue& v) { + return std::get(v); +} + +AnyValue fromI32(I32Value v) { + return {v}; +} + +size_t getSize(const AnyValue& v) { + auto composite = std::get(v); + return composite->getSize(); +} + +AnyValue getMember(const AnyValue& v, size_t i) { + auto composite = std::get(v); + return composite->getValue(i); +} + +void addMember(const AnyValue& c, const AnyValue& v) { + auto composite = std::get(c); + composite->addValue(v); +} + +void setReturnValue(AnyValue* ret, const AnyValue& v) { + *ret = v; +} + +AnyValue nilValue() { + return VoidValue{}; +} + +AnyValue makeCompositeValue() { + return { std::make_shared() }; +} + + +ProtocolWrapper::ProtocolWrapper(void* instance, DispatchFunc dispatcher): + _instance(instance), _dispatcher(dispatcher) +{} + +ProtocolWrapper::~ProtocolWrapper() { + _dispatcher(_instance, -1, nullptr, nullptr); +} + +AnyValue ProtocolWrapper::callProtocol(int idx, const ParameterList& params) { + AnyValue ret = VoidValue(); + _dispatcher(_instance, idx, ¶ms, &ret); + return ret; +} + +} diff --git a/support-lib/swiftxx/djinni_support.hpp b/support-lib/swiftxx/djinni_support.hpp new file mode 100644 index 00000000..7dcdfcb3 --- /dev/null +++ b/support-lib/swiftxx/djinni_support.hpp @@ -0,0 +1,105 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace djinni { + +struct VoidValue{}; +using BoolValue = bool; +using I8Value = int8_t; +using I16Value = int16_t; +using I32Value = int32_t; +using I64Value = int64_t; +using FloatValue = float; +using DoubleValue = double; +using StringValue = std::string; +using BinaryValue = std::vector; +using DateValue = std::chrono::system_clock::time_point; +using EnumValue = int32_t; +using InterfaceValue = std::shared_ptr; + +struct CompositeValue; +using CompositeValuePtr = std::shared_ptr; + +using AnyValue = std::variant; + +struct CompositeValue { + virtual ~CompositeValue() = default; + std::vector _elems; + + void addValue(const AnyValue& v) { + _elems.push_back(v); + } + AnyValue getValue(size_t i) const { return _elems[i]; } + size_t getSize() const { return _elems.size(); } +}; + +struct ListValue: CompositeValue {}; +struct SetValue: CompositeValue {}; +struct MapValue: CompositeValue {}; +struct OptionalValue: CompositeValue {}; +struct RecordValue: CompositeValue {}; +struct ParameterList: CompositeValue {}; + +StringValue toString(const AnyValue& v); +AnyValue fromString(const StringValue& s); +I32Value toI32(const AnyValue& v); +AnyValue fromI32(I32Value v); + +size_t getSize(const AnyValue& v); +AnyValue getMember(const AnyValue& v, size_t i); +void addMember(const AnyValue& c, const AnyValue& v); +void setReturnValue(AnyValue* ret, const AnyValue& v); + +typedef void (*DispatchFunc)(void* instance, int idx /* -1 for cleanup*/, const ParameterList* params, AnyValue* ret); +class ProtocolWrapper { + void* _instance; + DispatchFunc _dispatcher; +protected: + ProtocolWrapper(void* instance, DispatchFunc dispatcher); + AnyValue callProtocol(int idx, const ParameterList& params); +public: + virtual ~ProtocolWrapper(); +}; + +AnyValue nilValue(); +AnyValue makeCompositeValue(); + +struct String { + using CppType = std::string; + static AnyValue fromCpp(const CppType& v) { + return {v}; + } + static CppType toCpp(const AnyValue& v) { + return std::get(v); + } +}; + +template +struct List { + using CppType = std::vector; + static AnyValue fromCpp(const CppType& v) { + auto ret = std::make_shared(); + for (const auto& e: v) { + ret->addValue(T::fromCpp(e)); + } + return {ret}; + } + static CppType toCpp(const AnyValue& v) { + CppType vec; + auto c = std::get(v); + for (const auto& item: c->_elems) { + vec.push_back(T::toCpp(item)); + } + return vec; + } +}; + +} diff --git a/test-suite/BUILD b/test-suite/BUILD index 9b3576b6..ca17f02c 100644 --- a/test-suite/BUILD +++ b/test-suite/BUILD @@ -28,6 +28,7 @@ cc_library( "//support-lib:djinni-support-common", "@com_google_protobuf//:protobuf" ], + tags = ["swift_module"], linkstatic = True, alwayslink = 1, ) @@ -195,5 +196,11 @@ sh_binary( swift_test( name = "djinni-swift-tests", - srcs = ['handwritten-src/swift/AllTests.swift'] + srcs = ['handwritten-src/swift/AllTests.swift'], + deps = ['//examples:textsort-swiftimp'], + copts = [ + "-cxx-interoperability-mode=default", + "-Xcc", + "-std=c++17" + ], ) diff --git a/test-suite/handwritten-src/swift/AllTests.swift b/test-suite/handwritten-src/swift/AllTests.swift index 507bb461..a74dfdfd 100644 --- a/test-suite/handwritten-src/swift/AllTests.swift +++ b/test-suite/handwritten-src/swift/AllTests.swift @@ -1,12 +1,19 @@ import XCTest -// @testable import swift +@testable import TextSort; +@testable import TextSortImp; + +class MyListener: TextboxListener { + func update(items: ItemList) { + print("*** update() called") + print(items) + } +} final class AllTests: XCTestCase { func testExample() throws { - // XCTest Documentation - // https://developer.apple.com/documentation/xctest - - // Defining Test Cases and Test Methods - // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods + let listener = MyListener() + let s = SortItems_statics.createWithListener(listener: listener) + let items = ItemList(items: ["bbb", "ccc", "aaa"]) + s.sort(order: SortOrder.ASCENDING, items: items) } } From 1d847905ff6ea7717b389cba77cbf1611ac5935a Mon Sep 17 00:00:00 2001 From: Li Feng Date: Thu, 16 May 2024 15:37:43 +1000 Subject: [PATCH 09/68] cpp files --- .../generated-src/swiftxx/NativeItemList.hpp | 20 ++++++ .../generated-src/swiftxx/NativeSortItems.cpp | 62 +------------------ .../generated-src/swiftxx/NativeSortItems.hpp | 18 +++--- .../generated-src/swiftxx/NativeSortOrder.hpp | 18 ++++++ .../swiftxx/NativeTextboxListener.cpp | 23 +++++++ .../swiftxx/NativeTextboxListener.hpp | 24 +++++++ 6 files changed, 96 insertions(+), 69 deletions(-) create mode 100644 examples/generated-src/swiftxx/NativeItemList.hpp create mode 100644 examples/generated-src/swiftxx/NativeSortOrder.hpp create mode 100644 examples/generated-src/swiftxx/NativeTextboxListener.cpp create mode 100644 examples/generated-src/swiftxx/NativeTextboxListener.hpp diff --git a/examples/generated-src/swiftxx/NativeItemList.hpp b/examples/generated-src/swiftxx/NativeItemList.hpp new file mode 100644 index 00000000..fcfd65b7 --- /dev/null +++ b/examples/generated-src/swiftxx/NativeItemList.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include "djinni_support.hpp" + +namespace djinni_generated { + +struct NativeItemList { + static djinni::AnyValue fromCpp(const textsort::ItemList& v) { + auto ret = std::make_shared(); + ret->addValue(djinni::List::fromCpp(v.items)); + return {ret}; + } + static textsort::ItemList toCpp(const djinni::AnyValue& v) { + auto c = std::get(v); + return textsort::ItemList(djinni::List::toCpp(c->getValue(0))); + } +}; + +} diff --git a/examples/generated-src/swiftxx/NativeSortItems.cpp b/examples/generated-src/swiftxx/NativeSortItems.cpp index 0eaf5eb5..4da069e2 100644 --- a/examples/generated-src/swiftxx/NativeSortItems.cpp +++ b/examples/generated-src/swiftxx/NativeSortItems.cpp @@ -1,55 +1,10 @@ #include -#include +#include +#include +#include namespace djinni_generated { -struct NativeItemList { - static djinni::AnyValue fromCpp(const textsort::ItemList& v) { - auto ret = std::make_shared(); - ret->addValue(djinni::List::fromCpp(v.items)); - return {ret}; - } - static textsort::ItemList toCpp(const djinni::AnyValue& v) { - auto c = std::get(v); - return textsort::ItemList(djinni::List::toCpp(c->getValue(0))); - } -}; - - -void TextboxListenerProtocolWrapper::update(const textsort::ItemList& items) { - djinni::ParameterList params; - params.addValue(NativeItemList::fromCpp(items)); - callProtocol(0, params); -} - - -struct NativeTextboxListener { - static std::shared_ptr toCpp(const djinni::AnyValue& v) { - auto p = std::get(v); - return std::reinterpret_pointer_cast(p); - } -}; - -struct NativeSortItems { - static djinni::AnyValue fromCpp(const std::shared_ptr& v) { - return {v}; - } - static std::shared_ptr toCpp(const djinni::AnyValue& v) { - auto p = std::get(v); - return std::reinterpret_pointer_cast(p); - } -}; - -struct NativeSortOrder { - static djinni::AnyValue fromCpp(textsort::sort_order v) { - return {static_cast(v)}; - } - static textsort::sort_order toCpp(const djinni::AnyValue& v) { - auto i = std::get(v); - return static_cast(i); - } -}; - djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList& params) { auto listener = NativeTextboxListener::toCpp(params.getValue(0)); auto ret = textsort::SortItems::create_with_listener(listener); @@ -70,15 +25,4 @@ djinni::AnyValue SortItems_sort(const djinni::ParameterList& params) { return djinni::nilValue(); } -djinni::AnyValue TextboxListener_update(const djinni::ParameterList& params) { - auto inst = NativeTextboxListener::toCpp(params.getValue(0)); - auto items = NativeItemList::toCpp(params.getValue(1)); - inst->update(items); - return djinni::nilValue(); -} - -djinni::AnyValue TextboxListenerProtocolWrapper::make(void* instance, djinni::DispatchFunc dispatcher) { - return {std::make_shared(instance, dispatcher)}; -} - } diff --git a/examples/generated-src/swiftxx/NativeSortItems.hpp b/examples/generated-src/swiftxx/NativeSortItems.hpp index 0859bb1f..420b7bd1 100644 --- a/examples/generated-src/swiftxx/NativeSortItems.hpp +++ b/examples/generated-src/swiftxx/NativeSortItems.hpp @@ -1,24 +1,22 @@ #pragma once #include "sort_items.hpp" -#include "textbox_listener.hpp" #include "djinni_support.hpp" namespace djinni_generated { -class TextboxListenerProtocolWrapper: public textsort::TextboxListener, public djinni::ProtocolWrapper { -public: - TextboxListenerProtocolWrapper(void* instance, djinni::DispatchFunc dispatcher): djinni::ProtocolWrapper(instance, dispatcher) {} - static djinni::AnyValue make(void* instance, djinni::DispatchFunc dispatcher); - void update(const textsort::ItemList& items) override; +struct NativeSortItems { + static djinni::AnyValue fromCpp(const std::shared_ptr& v) { + return {v}; + } + static std::shared_ptr toCpp(const djinni::AnyValue& v) { + auto p = std::get(v); + return std::reinterpret_pointer_cast(p); + } }; djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList& params); - djinni::AnyValue SortItems_runSort(const djinni::ParameterList& params); - djinni::AnyValue SortItems_sort(const djinni::ParameterList& params); -djinni::AnyValue TextboxListener_update(const djinni::ParameterList& params); - } diff --git a/examples/generated-src/swiftxx/NativeSortOrder.hpp b/examples/generated-src/swiftxx/NativeSortOrder.hpp new file mode 100644 index 00000000..f7907008 --- /dev/null +++ b/examples/generated-src/swiftxx/NativeSortOrder.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "sort_order.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +struct NativeSortOrder { + static djinni::AnyValue fromCpp(textsort::sort_order v) { + return {static_cast(v)}; + } + static textsort::sort_order toCpp(const djinni::AnyValue& v) { + auto i = std::get(v); + return static_cast(i); + } +}; + +} diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.cpp b/examples/generated-src/swiftxx/NativeTextboxListener.cpp new file mode 100644 index 00000000..49ff9e39 --- /dev/null +++ b/examples/generated-src/swiftxx/NativeTextboxListener.cpp @@ -0,0 +1,23 @@ +#include +#include + +namespace djinni_generated { + +void TextboxListenerProtocolWrapper::update(const textsort::ItemList& items) { + djinni::ParameterList params; + params.addValue(NativeItemList::fromCpp(items)); + callProtocol(0, params); +} + +djinni::AnyValue TextboxListener_update(const djinni::ParameterList& params) { + auto inst = NativeTextboxListener::toCpp(params.getValue(0)); + auto items = NativeItemList::toCpp(params.getValue(1)); + inst->update(items); + return djinni::nilValue(); +} + +djinni::AnyValue TextboxListenerProtocolWrapper::make(void* instance, djinni::DispatchFunc dispatcher) { + return {std::make_shared(instance, dispatcher)}; +} + +} diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.hpp b/examples/generated-src/swiftxx/NativeTextboxListener.hpp new file mode 100644 index 00000000..f1c340de --- /dev/null +++ b/examples/generated-src/swiftxx/NativeTextboxListener.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "textbox_listener.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +class TextboxListenerProtocolWrapper: public textsort::TextboxListener, public djinni::ProtocolWrapper { +public: + TextboxListenerProtocolWrapper(void* instance, djinni::DispatchFunc dispatcher): djinni::ProtocolWrapper(instance, dispatcher) {} + static djinni::AnyValue make(void* instance, djinni::DispatchFunc dispatcher); + void update(const textsort::ItemList& items) override; +}; + +struct NativeTextboxListener { + static std::shared_ptr toCpp(const djinni::AnyValue& v) { + auto p = std::get(v); + return std::reinterpret_pointer_cast(p); + } +}; + +djinni::AnyValue TextboxListener_update(const djinni::ParameterList& params); + +} From ff0c4e8b7a4d358c7cfa0f079d39c4ea0a059ddb Mon Sep 17 00:00:00 2001 From: Li Feng Date: Thu, 16 May 2024 15:44:43 +1000 Subject: [PATCH 10/68] remove unneeded dep --- support-lib/BUILD | 1 - support-lib/swift/DjinniSupport.swift | 1 - 2 files changed, 2 deletions(-) diff --git a/support-lib/BUILD b/support-lib/BUILD index f9fe786c..36053ede 100644 --- a/support-lib/BUILD +++ b/support-lib/BUILD @@ -91,7 +91,6 @@ swift_library( "-Xcc", "-std=c++17", ], deps = [ - ":djinni-support-common", ":djinni-support-swiftxx", ], visibility = ["//visibility:public"], diff --git a/support-lib/swift/DjinniSupport.swift b/support-lib/swift/DjinniSupport.swift index a7c11219..becf53a7 100644 --- a/support-lib/swift/DjinniSupport.swift +++ b/support-lib/swift/DjinniSupport.swift @@ -1,4 +1,3 @@ -import support_lib_djinni_support_common import support_lib_djinni_support_swiftxx public protocol Marshaller { From 2e8e189cbc92cec75ebd534346e2865430aad09a Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 17 May 2024 14:14:15 +1000 Subject: [PATCH 11/68] optimize parameter copy --- .../generated-src/swift/SortItems+Private.swift | 6 +++--- .../swift/TextboxListener+Private.swift | 4 ++-- .../generated-src/swiftxx/NativeSortItems.cpp | 16 ++++++++-------- .../generated-src/swiftxx/NativeSortItems.hpp | 6 +++--- .../swiftxx/NativeTextboxListener.cpp | 8 ++++---- .../swiftxx/NativeTextboxListener.hpp | 2 +- support-lib/swiftxx/djinni_support.cpp | 8 ++++++-- support-lib/swiftxx/djinni_support.hpp | 3 ++- 8 files changed, 29 insertions(+), 24 deletions(-) diff --git a/examples/generated-src/swift/SortItems+Private.swift b/examples/generated-src/swift/SortItems+Private.swift index 38c5bdf4..9c2683a8 100644 --- a/examples/generated-src/swift/SortItems+Private.swift +++ b/examples/generated-src/swift/SortItems+Private.swift @@ -13,7 +13,7 @@ class SortItemsProxy: SortItems { params.addValue(inst) params.addValue(SortOrderMarshaller.toCpp(order)) params.addValue(ItemListMarshaller.toCpp(items)) - djinni_generated.SortItems_sort(params) + djinni_generated.SortItems_sort(¶ms) } } @@ -31,13 +31,13 @@ public class SortItems_statics { static func createWithListener(listener: TextboxListener)-> SortItems { var params = djinni.ParameterList() params.addValue(TextboxListenerMarshaller.toCpp(listener)) - let ret = djinni_generated.SortItems_createWithListener(params) + let ret = djinni_generated.SortItems_createWithListener(¶ms) return SortItemsMarshaller.fromCpp(ret) } static func runSort(items: ItemList)-> ItemList { var params = djinni.ParameterList() params.addValue(ItemListMarshaller.toCpp(items)) - let ret = djinni_generated.SortItems_runSort(params) + let ret = djinni_generated.SortItems_runSort(¶ms) return ItemListMarshaller.fromCpp(ret) } } diff --git a/examples/generated-src/swift/TextboxListener+Private.swift b/examples/generated-src/swift/TextboxListener+Private.swift index 6458c9dc..99a6445f 100644 --- a/examples/generated-src/swift/TextboxListener+Private.swift +++ b/examples/generated-src/swift/TextboxListener+Private.swift @@ -12,7 +12,7 @@ class TextboxListenerProxy: TextboxListener { var params = djinni.ParameterList() params.addValue(inst) params.addValue(ItemListMarshaller.toCpp(items)) - djinni_generated.TextboxListener_update(params) + djinni_generated.TextboxListener_update(¶ms) } } @@ -27,7 +27,7 @@ func textboxListenerDispatcher(_ instance: UnsafeMutableRawPointer?, } guard let listener = Unmanaged.fromOpaque(ptr).takeUnretainedValue() as? TextboxListener else { return } if (idx == 0) { - let items = ItemListMarshaller.fromCpp(params.pointee.getValue(0)) + let items = ItemListMarshaller.fromCpp(djinni.getMember(params, 0)) listener.update(items: items) } } diff --git a/examples/generated-src/swiftxx/NativeSortItems.cpp b/examples/generated-src/swiftxx/NativeSortItems.cpp index 4da069e2..4e69d754 100644 --- a/examples/generated-src/swiftxx/NativeSortItems.cpp +++ b/examples/generated-src/swiftxx/NativeSortItems.cpp @@ -5,22 +5,22 @@ namespace djinni_generated { -djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList& params) { - auto listener = NativeTextboxListener::toCpp(params.getValue(0)); +djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList* params) { + auto listener = NativeTextboxListener::toCpp(params->getValue(0)); auto ret = textsort::SortItems::create_with_listener(listener); return NativeSortItems::fromCpp(ret); } -djinni::AnyValue SortItems_runSort(const djinni::ParameterList& params) { - auto items = NativeItemList::toCpp(params.getValue(0)); +djinni::AnyValue SortItems_runSort(const djinni::ParameterList* params) { + auto items = NativeItemList::toCpp(params->getValue(0)); auto ret = textsort::SortItems::run_sort(items); return NativeItemList::fromCpp(ret); } -djinni::AnyValue SortItems_sort(const djinni::ParameterList& params) { - auto inst = NativeSortItems::toCpp(params.getValue(0)); - auto order = NativeSortOrder::toCpp(params.getValue(1)); - auto items = NativeItemList::toCpp(params.getValue(2)); +djinni::AnyValue SortItems_sort(const djinni::ParameterList* params) { + auto inst = NativeSortItems::toCpp(params->getValue(0)); + auto order = NativeSortOrder::toCpp(params->getValue(1)); + auto items = NativeItemList::toCpp(params->getValue(2)); inst->sort(order, items); return djinni::nilValue(); } diff --git a/examples/generated-src/swiftxx/NativeSortItems.hpp b/examples/generated-src/swiftxx/NativeSortItems.hpp index 420b7bd1..8b200473 100644 --- a/examples/generated-src/swiftxx/NativeSortItems.hpp +++ b/examples/generated-src/swiftxx/NativeSortItems.hpp @@ -15,8 +15,8 @@ struct NativeSortItems { } }; -djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList& params); -djinni::AnyValue SortItems_runSort(const djinni::ParameterList& params); -djinni::AnyValue SortItems_sort(const djinni::ParameterList& params); +djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList* params); +djinni::AnyValue SortItems_runSort(const djinni::ParameterList* params); +djinni::AnyValue SortItems_sort(const djinni::ParameterList* params); } diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.cpp b/examples/generated-src/swiftxx/NativeTextboxListener.cpp index 49ff9e39..7bdeecf4 100644 --- a/examples/generated-src/swiftxx/NativeTextboxListener.cpp +++ b/examples/generated-src/swiftxx/NativeTextboxListener.cpp @@ -6,12 +6,12 @@ namespace djinni_generated { void TextboxListenerProtocolWrapper::update(const textsort::ItemList& items) { djinni::ParameterList params; params.addValue(NativeItemList::fromCpp(items)); - callProtocol(0, params); + callProtocol(0, ¶ms); } -djinni::AnyValue TextboxListener_update(const djinni::ParameterList& params) { - auto inst = NativeTextboxListener::toCpp(params.getValue(0)); - auto items = NativeItemList::toCpp(params.getValue(1)); +djinni::AnyValue TextboxListener_update(const djinni::ParameterList* params) { + auto inst = NativeTextboxListener::toCpp(params->getValue(0)); + auto items = NativeItemList::toCpp(params->getValue(1)); inst->update(items); return djinni::nilValue(); } diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.hpp b/examples/generated-src/swiftxx/NativeTextboxListener.hpp index f1c340de..2156ae6a 100644 --- a/examples/generated-src/swiftxx/NativeTextboxListener.hpp +++ b/examples/generated-src/swiftxx/NativeTextboxListener.hpp @@ -19,6 +19,6 @@ struct NativeTextboxListener { } }; -djinni::AnyValue TextboxListener_update(const djinni::ParameterList& params); +djinni::AnyValue TextboxListener_update(const djinni::ParameterList* params); } diff --git a/support-lib/swiftxx/djinni_support.cpp b/support-lib/swiftxx/djinni_support.cpp index 29c14f3f..0ffd9336 100644 --- a/support-lib/swiftxx/djinni_support.cpp +++ b/support-lib/swiftxx/djinni_support.cpp @@ -27,6 +27,10 @@ AnyValue getMember(const AnyValue& v, size_t i) { return composite->getValue(i); } +AnyValue getMember(const ParameterList* v, size_t i) { + return v->getValue(i); +} + void addMember(const AnyValue& c, const AnyValue& v) { auto composite = std::get(c); composite->addValue(v); @@ -53,9 +57,9 @@ ProtocolWrapper::~ProtocolWrapper() { _dispatcher(_instance, -1, nullptr, nullptr); } -AnyValue ProtocolWrapper::callProtocol(int idx, const ParameterList& params) { +AnyValue ProtocolWrapper::callProtocol(int idx, const ParameterList* params) { AnyValue ret = VoidValue(); - _dispatcher(_instance, idx, ¶ms, &ret); + _dispatcher(_instance, idx, params, &ret); return ret; } diff --git a/support-lib/swiftxx/djinni_support.hpp b/support-lib/swiftxx/djinni_support.hpp index 7dcdfcb3..6de049df 100644 --- a/support-lib/swiftxx/djinni_support.hpp +++ b/support-lib/swiftxx/djinni_support.hpp @@ -55,6 +55,7 @@ AnyValue fromI32(I32Value v); size_t getSize(const AnyValue& v); AnyValue getMember(const AnyValue& v, size_t i); +AnyValue getMember(const ParameterList* v, size_t i); void addMember(const AnyValue& c, const AnyValue& v); void setReturnValue(AnyValue* ret, const AnyValue& v); @@ -64,7 +65,7 @@ class ProtocolWrapper { DispatchFunc _dispatcher; protected: ProtocolWrapper(void* instance, DispatchFunc dispatcher); - AnyValue callProtocol(int idx, const ParameterList& params); + AnyValue callProtocol(int idx, const ParameterList* params); public: virtual ~ProtocolWrapper(); }; From 3e3a662ecb9026fb56b05ec30b125a57511e18b8 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Tue, 21 May 2024 13:48:50 +1000 Subject: [PATCH 12/68] refactor --- .../swift/ItemList+Private.swift | 14 +++- .../swift/SortItems+Private.swift | 16 +++- .../swift/TextboxListener+Private.swift | 50 +++++------- .../generated-src/swiftxx/NativeItemList.hpp | 3 + .../generated-src/swiftxx/NativeSortItems.cpp | 13 ++- .../generated-src/swiftxx/NativeSortItems.hpp | 12 +-- .../generated-src/swiftxx/NativeSortOrder.hpp | 11 +-- .../swiftxx/NativeTextboxListener.cpp | 2 +- .../swiftxx/NativeTextboxListener.hpp | 7 +- support-lib/swift/DjinniSupport.swift | 51 +++++++++--- support-lib/swiftxx/djinni_support.cpp | 37 +++------ support-lib/swiftxx/djinni_support.hpp | 79 ++++++++++++------- .../handwritten-src/swift/AllTests.swift | 3 + 13 files changed, 174 insertions(+), 124 deletions(-) diff --git a/examples/generated-src/swift/ItemList+Private.swift b/examples/generated-src/swift/ItemList+Private.swift index d6203ba1..47aad4ca 100644 --- a/examples/generated-src/swift/ItemList+Private.swift +++ b/examples/generated-src/swift/ItemList+Private.swift @@ -5,12 +5,18 @@ import support_lib_djinni_support_swiftxx // C++ support library enum ItemListMarshaller: Marshaller { typealias SwiftType = ItemList static func fromCpp(_ v: djinni.AnyValue) -> SwiftType { - let items = DjinniSupport.ListMarshaller.fromCpp(djinni.getMember(v, 0)) - return ItemList(items: items) + return withUnsafePointer(to: v) { p in + // generate one line for each member of the record + let items = DjinniSupport.ListMarshaller.fromCpp(djinni.getMember(p, 0)) + // generate a struct constructor call + return ItemList(items: items) + } } static func toCpp(_ s: SwiftType) -> djinni.AnyValue { - let v = djinni.makeCompositeValue() - djinni.addMember(v, ListMarshaller.toCpp(s.items)) + // construct the record container + var v = djinni.makeCompositeValue() + // generate one line for each member of the record + djinni.addMember(&v, ListMarshaller.toCpp(s.items)) return v } } diff --git a/examples/generated-src/swift/SortItems+Private.swift b/examples/generated-src/swift/SortItems+Private.swift index 9c2683a8..756216c4 100644 --- a/examples/generated-src/swift/SortItems+Private.swift +++ b/examples/generated-src/swift/SortItems+Private.swift @@ -3,35 +3,49 @@ import DjinniSupport // Swift support library import support_lib_djinni_support_swiftxx // C++ support library import examples_textsort_swiftxx // C++ bridge code +// generate Proxy class if interface is +c class SortItemsProxy: SortItems { + // generate fixed member and init var inst: djinni.AnyValue init(_ inst: djinni.AnyValue) { self.inst = inst } + // generate method stubs func sort(order: SortOrder, items: ItemList) { var params = djinni.ParameterList() + // add instance as first parameter params.addValue(inst) + // generate a line for each parameter params.addValue(SortOrderMarshaller.toCpp(order)) params.addValue(ItemListMarshaller.toCpp(items)) + // forward to C++ implementation djinni_generated.SortItems_sort(¶ms) + // convert result back to swift (if return type is not void) } } enum SortItemsMarshaller: DjinniSupport.Marshaller { typealias SwiftType = SortItems + // generate fromCpp() if interface is +c static func fromCpp(_ v: djinni.AnyValue) -> SwiftType { return SortItemsProxy(v) } + // generate unimplemented toCpp() if interface lacks +swift static func toCpp(_ v: SwiftType) -> djinni.AnyValue { - return djinni.nilValue() // no +swift + fatalError("n/a") } } +// Generate stubs for static methods (if there are any) public class SortItems_statics { static func createWithListener(listener: TextboxListener)-> SortItems { + // build prameter list var params = djinni.ParameterList() + // generate one line for each parameter params.addValue(TextboxListenerMarshaller.toCpp(listener)) + // forward to C++ implementation let ret = djinni_generated.SortItems_createWithListener(¶ms) + // convert result back to swift return SortItemsMarshaller.fromCpp(ret) } static func runSort(items: ItemList)-> ItemList { diff --git a/examples/generated-src/swift/TextboxListener+Private.swift b/examples/generated-src/swift/TextboxListener+Private.swift index 99a6445f..04ba098a 100644 --- a/examples/generated-src/swift/TextboxListener+Private.swift +++ b/examples/generated-src/swift/TextboxListener+Private.swift @@ -3,42 +3,30 @@ import TextSort import DjinniSupport import support_lib_djinni_support_swiftxx -class TextboxListenerProxy: TextboxListener { - var inst: djinni.AnyValue - init(_ inst: djinni.AnyValue) { - self.inst = inst - } - func update(items: ItemList) { - var params = djinni.ParameterList() - params.addValue(inst) - params.addValue(ItemListMarshaller.toCpp(items)) - djinni_generated.TextboxListener_update(¶ms) - } -} +// have to declare this type in each file because for some reason we can't export typealiases with C++ types from DjinniSupport.swift +typealias MethodDispatcher = (Any, UnsafePointer?, UnsafeMutablePointer?) -> Void -func textboxListenerDispatcher(_ instance: UnsafeMutableRawPointer?, - idx: Int32, - params: UnsafePointer?, - ret: UnsafeMutablePointer?) -> Void { - guard let ptr = instance else { return } - if (idx < 0) { - let _ = Unmanaged.fromOpaque(ptr).takeRetainedValue() - return - } - guard let listener = Unmanaged.fromOpaque(ptr).takeUnretainedValue() as? TextboxListener else { return } - if (idx == 0) { - let items = ItemListMarshaller.fromCpp(djinni.getMember(params, 0)) - listener.update(items: items) - } -} +let textboxListenerMethods: [MethodDispatcher] = [ + // generate one entry for each interface method + { inst, params, ret in + // generate one line for each parameter + let items = ItemListMarshaller.fromCpp(djinni.getMember(params, 0)) + // call swift object through protocol + (inst as! TextboxListener).update(items: items) + // update ret if method has return value + }, +] enum TextboxListenerMarshaller: DjinniSupport.Marshaller { typealias SwiftType = TextboxListener + // generate unimplemented fromCpp() if interface lacks +c static func fromCpp(_ v: djinni.AnyValue) -> SwiftType { - return TextboxListenerProxy(v) + fatalError("n/a") } - static func toCpp(_ listener: TextboxListener) -> djinni.AnyValue { - let instance = Unmanaged.passRetained(listener as AnyObject).toOpaque() - return djinni_generated.TextboxListenerProtocolWrapper.make(instance, textboxListenerDispatcher) + // generate toCpp() with the dispatch func + static func toCpp(_ listener: SwiftType) -> djinni.AnyValue { + let ctx = ProtocolWrapperContext(inst: listener, vtbl: textboxListenerMethods) + let p = Unmanaged.passRetained(ctx).toOpaque() + return djinni_generated.TextboxListenerProtocolWrapper.make(p, DjinniSupport.dispatcherProtocalCall) } } diff --git a/examples/generated-src/swiftxx/NativeItemList.hpp b/examples/generated-src/swiftxx/NativeItemList.hpp index fcfd65b7..f32857de 100644 --- a/examples/generated-src/swiftxx/NativeItemList.hpp +++ b/examples/generated-src/swiftxx/NativeItemList.hpp @@ -7,12 +7,15 @@ namespace djinni_generated { struct NativeItemList { static djinni::AnyValue fromCpp(const textsort::ItemList& v) { + // generate record container auto ret = std::make_shared(); + // generate one line for each member of the record ret->addValue(djinni::List::fromCpp(v.items)); return {ret}; } static textsort::ItemList toCpp(const djinni::AnyValue& v) { auto c = std::get(v); + // generate an argument for each member of the record return textsort::ItemList(djinni::List::toCpp(c->getValue(0))); } }; diff --git a/examples/generated-src/swiftxx/NativeSortItems.cpp b/examples/generated-src/swiftxx/NativeSortItems.cpp index 4e69d754..3149b264 100644 --- a/examples/generated-src/swiftxx/NativeSortItems.cpp +++ b/examples/generated-src/swiftxx/NativeSortItems.cpp @@ -6,23 +6,34 @@ namespace djinni_generated { djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList* params) { + // static method: + // generate a line for each parameter of the method auto listener = NativeTextboxListener::toCpp(params->getValue(0)); + // call the C++ static method implementation auto ret = textsort::SortItems::create_with_listener(listener); + // convert result to intermediate form return NativeSortItems::fromCpp(ret); } djinni::AnyValue SortItems_runSort(const djinni::ParameterList* params) { + // static method: auto items = NativeItemList::toCpp(params->getValue(0)); auto ret = textsort::SortItems::run_sort(items); return NativeItemList::fromCpp(ret); } djinni::AnyValue SortItems_sort(const djinni::ParameterList* params) { + // instance method: + // retrieve the instance pointer from params[0] auto inst = NativeSortItems::toCpp(params->getValue(0)); + // generate a line for each parameter of the method auto order = NativeSortOrder::toCpp(params->getValue(1)); auto items = NativeItemList::toCpp(params->getValue(2)); + // call the C++ instance method implementation inst->sort(order, items); - return djinni::nilValue(); + // convert result to intermediate form + // return nil for void methods + return djinni::makeVoidValue(); } } diff --git a/examples/generated-src/swiftxx/NativeSortItems.hpp b/examples/generated-src/swiftxx/NativeSortItems.hpp index 8b200473..402798f6 100644 --- a/examples/generated-src/swiftxx/NativeSortItems.hpp +++ b/examples/generated-src/swiftxx/NativeSortItems.hpp @@ -5,16 +5,10 @@ namespace djinni_generated { -struct NativeSortItems { - static djinni::AnyValue fromCpp(const std::shared_ptr& v) { - return {v}; - } - static std::shared_ptr toCpp(const djinni::AnyValue& v) { - auto p = std::get(v); - return std::reinterpret_pointer_cast(p); - } -}; +// Alias to generic interface marshaller +using NativeSortItems = djinni::Interface; +// Generate forward declarations for each static and instance method djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList* params); djinni::AnyValue SortItems_runSort(const djinni::ParameterList* params); djinni::AnyValue SortItems_sort(const djinni::ParameterList* params); diff --git a/examples/generated-src/swiftxx/NativeSortOrder.hpp b/examples/generated-src/swiftxx/NativeSortOrder.hpp index f7907008..79c98cb9 100644 --- a/examples/generated-src/swiftxx/NativeSortOrder.hpp +++ b/examples/generated-src/swiftxx/NativeSortOrder.hpp @@ -5,14 +5,7 @@ namespace djinni_generated { -struct NativeSortOrder { - static djinni::AnyValue fromCpp(textsort::sort_order v) { - return {static_cast(v)}; - } - static textsort::sort_order toCpp(const djinni::AnyValue& v) { - auto i = std::get(v); - return static_cast(i); - } -}; +// Alias to generic enum marshaller +using NativeSortOrder = djinni::Enum; } diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.cpp b/examples/generated-src/swiftxx/NativeTextboxListener.cpp index 7bdeecf4..3d26102e 100644 --- a/examples/generated-src/swiftxx/NativeTextboxListener.cpp +++ b/examples/generated-src/swiftxx/NativeTextboxListener.cpp @@ -13,7 +13,7 @@ djinni::AnyValue TextboxListener_update(const djinni::ParameterList* params) { auto inst = NativeTextboxListener::toCpp(params->getValue(0)); auto items = NativeItemList::toCpp(params->getValue(1)); inst->update(items); - return djinni::nilValue(); + return djinni::makeVoidValue(); } djinni::AnyValue TextboxListenerProtocolWrapper::make(void* instance, djinni::DispatchFunc dispatcher) { diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.hpp b/examples/generated-src/swiftxx/NativeTextboxListener.hpp index 2156ae6a..af895029 100644 --- a/examples/generated-src/swiftxx/NativeTextboxListener.hpp +++ b/examples/generated-src/swiftxx/NativeTextboxListener.hpp @@ -12,12 +12,7 @@ class TextboxListenerProtocolWrapper: public textsort::TextboxListener, public d void update(const textsort::ItemList& items) override; }; -struct NativeTextboxListener { - static std::shared_ptr toCpp(const djinni::AnyValue& v) { - auto p = std::get(v); - return std::reinterpret_pointer_cast(p); - } -}; +using NativeTextboxListener = djinni::Interface; djinni::AnyValue TextboxListener_update(const djinni::ParameterList* params); diff --git a/support-lib/swift/DjinniSupport.swift b/support-lib/swift/DjinniSupport.swift index becf53a7..9ba8c984 100644 --- a/support-lib/swift/DjinniSupport.swift +++ b/support-lib/swift/DjinniSupport.swift @@ -1,5 +1,36 @@ import support_lib_djinni_support_swiftxx +public class ProtocolWrapperContext { + public typealias MethodDispatcher = (Any, UnsafePointer?, UnsafeMutablePointer?) -> Void + + var inst: Any + var vtbl: [MethodDispatcher] + + public init(inst: Any, vtbl: [MethodDispatcher]) { + self.inst = inst + self.vtbl = vtbl + } + + public func dispatch(idx: Int32, params: UnsafePointer?, ret: UnsafeMutablePointer?) -> Void { + vtbl[Int(idx)](inst, params, ret) + } +} + +public func dispatcherProtocalCall(_ ptr: UnsafeMutableRawPointer?, + idx: Int32, + params: UnsafePointer?, + ret: UnsafeMutablePointer?) -> Void { + guard let pctx = ptr else { return } + if (idx < 0) { + // release and destroy the context + let _ = Unmanaged.fromOpaque(pctx).takeRetainedValue() + } else { + // dynamic dispatch on the vtbl + let ctx = Unmanaged.fromOpaque(pctx).takeUnretainedValue() + ctx.dispatch(idx: idx, params: params, ret: ret) + } +} + public protocol Marshaller { associatedtype SwiftType static func fromCpp(_ v: djinni.AnyValue) -> SwiftType @@ -9,37 +40,39 @@ public protocol Marshaller { public enum EnumMarshaller: Marshaller where T.RawValue == Int32 { public typealias SwiftType = T public static func fromCpp(_ v: djinni.AnyValue) -> SwiftType { - return SwiftType(rawValue: djinni.toI32(v))! + return SwiftType(rawValue: djinni.I32.toCpp(v))! } public static func toCpp(_ s: SwiftType) -> djinni.AnyValue { - return djinni.fromI32(s.rawValue) + return djinni.I32.fromCpp(s.rawValue) } } public enum StringMarshaller: Marshaller { public typealias SwiftType = String static public func fromCpp(_ v: djinni.AnyValue) -> SwiftType { - return String(djinni.toString(v)) + return SwiftType(djinni.String.toCpp(v)) } static public func toCpp(_ s: SwiftType) -> djinni.AnyValue { - return djinni.fromString(std.string(s)) + return djinni.String.fromCpp(std.string(s)) } } public enum ListMarshaller: Marshaller { public typealias SwiftType = [T.SwiftType] static public func fromCpp(_ v: djinni.AnyValue) -> SwiftType { - let size = djinni.getSize(v) var array = SwiftType() - for i in 0.. djinni.AnyValue { - let composite = djinni.makeCompositeValue() + var composite = djinni.makeCompositeValue() for item in s { - djinni.addMember(composite, T.toCpp(item)) + djinni.addMember(&composite, T.toCpp(item)) } return composite } diff --git a/support-lib/swiftxx/djinni_support.cpp b/support-lib/swiftxx/djinni_support.cpp index 0ffd9336..24db276c 100644 --- a/support-lib/swiftxx/djinni_support.cpp +++ b/support-lib/swiftxx/djinni_support.cpp @@ -2,28 +2,13 @@ namespace djinni { -StringValue toString(const AnyValue& v) { - return std::get(v); -} -AnyValue fromString(const StringValue& s) { - return {s}; -} - -I32Value toI32(const AnyValue& v) { - return std::get(v); -} - -AnyValue fromI32(I32Value v) { - return {v}; -} - -size_t getSize(const AnyValue& v) { - auto composite = std::get(v); +size_t getSize(const AnyValue* v) { + auto composite = std::get(*v); return composite->getSize(); } -AnyValue getMember(const AnyValue& v, size_t i) { - auto composite = std::get(v); +AnyValue getMember(const AnyValue* v, size_t i) { + auto composite = std::get(*v); return composite->getValue(i); } @@ -31,8 +16,8 @@ AnyValue getMember(const ParameterList* v, size_t i) { return v->getValue(i); } -void addMember(const AnyValue& c, const AnyValue& v) { - auto composite = std::get(c); +void addMember(const AnyValue* c, const AnyValue& v) { + auto composite = std::get(*c); composite->addValue(v); } @@ -40,7 +25,7 @@ void setReturnValue(AnyValue* ret, const AnyValue& v) { *ret = v; } -AnyValue nilValue() { +AnyValue makeVoidValue() { return VoidValue{}; } @@ -49,17 +34,17 @@ AnyValue makeCompositeValue() { } -ProtocolWrapper::ProtocolWrapper(void* instance, DispatchFunc dispatcher): - _instance(instance), _dispatcher(dispatcher) +ProtocolWrapper::ProtocolWrapper(void* ctx, DispatchFunc dispatcher): + _ctx(ctx), _dispatcher(dispatcher) {} ProtocolWrapper::~ProtocolWrapper() { - _dispatcher(_instance, -1, nullptr, nullptr); + _dispatcher(_ctx, -1, nullptr, nullptr); } AnyValue ProtocolWrapper::callProtocol(int idx, const ParameterList* params) { AnyValue ret = VoidValue(); - _dispatcher(_instance, idx, params, &ret); + _dispatcher(_ctx, idx, params, &ret); return ret; } diff --git a/support-lib/swiftxx/djinni_support.hpp b/support-lib/swiftxx/djinni_support.hpp index 6de049df..a45d4de8 100644 --- a/support-lib/swiftxx/djinni_support.hpp +++ b/support-lib/swiftxx/djinni_support.hpp @@ -4,30 +4,26 @@ #include #include #include -#include namespace djinni { - +// -------- Intermediate data structure and functions to manipulate them from Swift struct VoidValue{}; -using BoolValue = bool; -using I8Value = int8_t; -using I16Value = int16_t; +// I32 covers bool, i8, i16, i32, enum using I32Value = int32_t; using I64Value = int64_t; -using FloatValue = float; +// double covers float too using DoubleValue = double; using StringValue = std::string; using BinaryValue = std::vector; using DateValue = std::chrono::system_clock::time_point; -using EnumValue = int32_t; using InterfaceValue = std::shared_ptr; struct CompositeValue; using CompositeValuePtr = std::shared_ptr; using AnyValue = std::variant; struct CompositeValue { @@ -41,37 +37,54 @@ struct CompositeValue { size_t getSize() const { return _elems.size(); } }; -struct ListValue: CompositeValue {}; -struct SetValue: CompositeValue {}; -struct MapValue: CompositeValue {}; -struct OptionalValue: CompositeValue {}; -struct RecordValue: CompositeValue {}; struct ParameterList: CompositeValue {}; -StringValue toString(const AnyValue& v); -AnyValue fromString(const StringValue& s); -I32Value toI32(const AnyValue& v); -AnyValue fromI32(I32Value v); - -size_t getSize(const AnyValue& v); -AnyValue getMember(const AnyValue& v, size_t i); +size_t getSize(const AnyValue* v); +AnyValue getMember(const AnyValue* v, size_t i); +void addMember(const AnyValue* c, const AnyValue& v); AnyValue getMember(const ParameterList* v, size_t i); -void addMember(const AnyValue& c, const AnyValue& v); void setReturnValue(AnyValue* ret, const AnyValue& v); +AnyValue makeVoidValue(); +AnyValue makeCompositeValue(); -typedef void (*DispatchFunc)(void* instance, int idx /* -1 for cleanup*/, const ParameterList* params, AnyValue* ret); +// -------- Swift protocol trampoline +typedef void (*DispatchFunc)(void* ctx, int idx /* -1 for cleanup*/, const ParameterList* params, AnyValue* ret); class ProtocolWrapper { - void* _instance; + void* _ctx; DispatchFunc _dispatcher; protected: - ProtocolWrapper(void* instance, DispatchFunc dispatcher); + ProtocolWrapper(void* ctx, DispatchFunc dispatcher); AnyValue callProtocol(int idx, const ParameterList* params); public: virtual ~ProtocolWrapper(); }; -AnyValue nilValue(); -AnyValue makeCompositeValue(); +// -------- Built-in marshallers (conversion between C++ types and intermediate types) +template +struct Integer { + using CppType = T; + static djinni::AnyValue fromCpp(T v) { + return {static_cast(v)}; + } + static T toCpp(const djinni::AnyValue& v) { + auto i = std::get(v); + return static_cast(i); + } +}; + +using I32 = Integer; + +template +struct Enum { + using CppType = T; + static djinni::AnyValue fromCpp(T v) { + return {static_cast(v)}; + } + static T toCpp(const djinni::AnyValue& v) { + auto i = std::get(v); + return static_cast(i); + } +}; struct String { using CppType = std::string; @@ -103,4 +116,16 @@ struct List { } }; +template +struct Interface { + using CppType = std::shared_ptr; + static djinni::AnyValue fromCpp(const CppType& v) { + return {v}; + } + static CppType toCpp(const djinni::AnyValue& v) { + auto p = std::get(v); + return std::reinterpret_pointer_cast(p); + } +}; + } diff --git a/test-suite/handwritten-src/swift/AllTests.swift b/test-suite/handwritten-src/swift/AllTests.swift index a74dfdfd..39ae4da5 100644 --- a/test-suite/handwritten-src/swift/AllTests.swift +++ b/test-suite/handwritten-src/swift/AllTests.swift @@ -3,6 +3,9 @@ import XCTest @testable import TextSortImp; class MyListener: TextboxListener { + deinit { + print("*** deinit called") + } func update(items: ItemList) { print("*** update() called") print(items) From 420ccc23af8f5a62de0431119315690be790f5f0 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Tue, 21 May 2024 15:27:40 +1000 Subject: [PATCH 13/68] refactor --- examples/generated-src/swiftxx/NativeSortItems.cpp | 1 + examples/generated-src/swiftxx/NativeSortItems.hpp | 2 +- examples/generated-src/swiftxx/NativeTextboxListener.cpp | 8 +------- examples/generated-src/swiftxx/NativeTextboxListener.hpp | 5 +++-- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/examples/generated-src/swiftxx/NativeSortItems.cpp b/examples/generated-src/swiftxx/NativeSortItems.cpp index 3149b264..2c115d36 100644 --- a/examples/generated-src/swiftxx/NativeSortItems.cpp +++ b/examples/generated-src/swiftxx/NativeSortItems.cpp @@ -22,6 +22,7 @@ djinni::AnyValue SortItems_runSort(const djinni::ParameterList* params) { return NativeItemList::fromCpp(ret); } +// +c instance method stub djinni::AnyValue SortItems_sort(const djinni::ParameterList* params) { // instance method: // retrieve the instance pointer from params[0] diff --git a/examples/generated-src/swiftxx/NativeSortItems.hpp b/examples/generated-src/swiftxx/NativeSortItems.hpp index 402798f6..02856769 100644 --- a/examples/generated-src/swiftxx/NativeSortItems.hpp +++ b/examples/generated-src/swiftxx/NativeSortItems.hpp @@ -8,7 +8,7 @@ namespace djinni_generated { // Alias to generic interface marshaller using NativeSortItems = djinni::Interface; -// Generate forward declarations for each static and instance method +// Generate forward declarations for each static and +c instance method djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList* params); djinni::AnyValue SortItems_runSort(const djinni::ParameterList* params); djinni::AnyValue SortItems_sort(const djinni::ParameterList* params); diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.cpp b/examples/generated-src/swiftxx/NativeTextboxListener.cpp index 3d26102e..240758eb 100644 --- a/examples/generated-src/swiftxx/NativeTextboxListener.cpp +++ b/examples/generated-src/swiftxx/NativeTextboxListener.cpp @@ -3,19 +3,13 @@ namespace djinni_generated { +// +swift method stub void TextboxListenerProtocolWrapper::update(const textsort::ItemList& items) { djinni::ParameterList params; params.addValue(NativeItemList::fromCpp(items)); callProtocol(0, ¶ms); } -djinni::AnyValue TextboxListener_update(const djinni::ParameterList* params) { - auto inst = NativeTextboxListener::toCpp(params->getValue(0)); - auto items = NativeItemList::toCpp(params->getValue(1)); - inst->update(items); - return djinni::makeVoidValue(); -} - djinni::AnyValue TextboxListenerProtocolWrapper::make(void* instance, djinni::DispatchFunc dispatcher) { return {std::make_shared(instance, dispatcher)}; } diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.hpp b/examples/generated-src/swiftxx/NativeTextboxListener.hpp index af895029..ee463696 100644 --- a/examples/generated-src/swiftxx/NativeTextboxListener.hpp +++ b/examples/generated-src/swiftxx/NativeTextboxListener.hpp @@ -5,15 +5,16 @@ namespace djinni_generated { +// generate proxy class for C++ callers class TextboxListenerProtocolWrapper: public textsort::TextboxListener, public djinni::ProtocolWrapper { public: TextboxListenerProtocolWrapper(void* instance, djinni::DispatchFunc dispatcher): djinni::ProtocolWrapper(instance, dispatcher) {} + // factory method for Swift caller static djinni::AnyValue make(void* instance, djinni::DispatchFunc dispatcher); + // generate method stubs void update(const textsort::ItemList& items) override; }; using NativeTextboxListener = djinni::Interface; -djinni::AnyValue TextboxListener_update(const djinni::ParameterList* params); - } From 1135f3a4971b9ca173fc5fcaabb9ab3d91f317f0 Mon Sep 17 00:00:00 2001 From: Jan Buenker Date: Tue, 21 May 2024 11:57:58 +0200 Subject: [PATCH 14/68] Make DJFuture results nonnull in objective C --- support-lib/objc/DJFuture.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support-lib/objc/DJFuture.h b/support-lib/objc/DJFuture.h index c456cfe5..be1faa8a 100644 --- a/support-lib/objc/DJFuture.h +++ b/support-lib/objc/DJFuture.h @@ -25,7 +25,7 @@ // If the future is ready, then calling its `get` method will not block. - (BOOL) isReady; // Block and wait for the result (or exception). This can only be called once. -- (nullable DJValue) get; +- (nonnull DJValue) get; // Tell the future to Call the specified handler routine when it becomes // ready. Returns a new future that wraps the return value of the handler // routine. The current future becomes invalid after this call. @@ -40,7 +40,7 @@ - (nonnull DJFuture *)getFuture; // `setValue` or `setException` can only be called once on a promise. After // which the internal state becomes invalid. -- (void)setValue:(nullable DJValue)val; +- (void)setValue:(nonnull DJValue)val; // for NSNull* (void) - (void)setValue; - (void)setException:(nonnull NSException *)exception; From 28423022a1b8a875305410cc58c026ffeb0bdb1f Mon Sep 17 00:00:00 2001 From: Li Feng Date: Wed, 22 May 2024 16:29:04 +1000 Subject: [PATCH 15/68] namespace --- .../swift/ItemList+Private.swift | 10 ++--- .../swift/SortItems+Private.swift | 14 +++---- .../swift/TextboxListener+Private.swift | 8 ++-- .../generated-src/swiftxx/NativeItemList.hpp | 12 +++--- .../generated-src/swiftxx/NativeSortItems.cpp | 8 ++-- .../generated-src/swiftxx/NativeSortItems.hpp | 8 ++-- .../generated-src/swiftxx/NativeSortOrder.hpp | 2 +- .../swiftxx/NativeTextboxListener.cpp | 4 +- .../swiftxx/NativeTextboxListener.hpp | 8 ++-- support-lib/swift/DjinniSupport.swift | 40 +++++++++---------- support-lib/swiftxx/djinni_support.cpp | 2 +- support-lib/swiftxx/djinni_support.hpp | 20 +++++----- 12 files changed, 68 insertions(+), 68 deletions(-) diff --git a/examples/generated-src/swift/ItemList+Private.swift b/examples/generated-src/swift/ItemList+Private.swift index 47aad4ca..a738d013 100644 --- a/examples/generated-src/swift/ItemList+Private.swift +++ b/examples/generated-src/swift/ItemList+Private.swift @@ -4,19 +4,19 @@ import support_lib_djinni_support_swiftxx // C++ support library enum ItemListMarshaller: Marshaller { typealias SwiftType = ItemList - static func fromCpp(_ v: djinni.AnyValue) -> SwiftType { + static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: v) { p in // generate one line for each member of the record - let items = DjinniSupport.ListMarshaller.fromCpp(djinni.getMember(p, 0)) + let items = DjinniSupport.ListMarshaller.fromCpp(djinni.swift.getMember(p, 0)) // generate a struct constructor call return ItemList(items: items) } } - static func toCpp(_ s: SwiftType) -> djinni.AnyValue { + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { // construct the record container - var v = djinni.makeCompositeValue() + var v = djinni.swift.makeCompositeValue() // generate one line for each member of the record - djinni.addMember(&v, ListMarshaller.toCpp(s.items)) + djinni.swift.addMember(&v, ListMarshaller.toCpp(s.items)) return v } } diff --git a/examples/generated-src/swift/SortItems+Private.swift b/examples/generated-src/swift/SortItems+Private.swift index 756216c4..8616447a 100644 --- a/examples/generated-src/swift/SortItems+Private.swift +++ b/examples/generated-src/swift/SortItems+Private.swift @@ -6,13 +6,13 @@ import examples_textsort_swiftxx // C++ bridge code // generate Proxy class if interface is +c class SortItemsProxy: SortItems { // generate fixed member and init - var inst: djinni.AnyValue - init(_ inst: djinni.AnyValue) { + var inst: djinni.swift.AnyValue + init(_ inst: djinni.swift.AnyValue) { self.inst = inst } // generate method stubs func sort(order: SortOrder, items: ItemList) { - var params = djinni.ParameterList() + var params = djinni.swift.ParameterList() // add instance as first parameter params.addValue(inst) // generate a line for each parameter @@ -27,11 +27,11 @@ class SortItemsProxy: SortItems { enum SortItemsMarshaller: DjinniSupport.Marshaller { typealias SwiftType = SortItems // generate fromCpp() if interface is +c - static func fromCpp(_ v: djinni.AnyValue) -> SwiftType { + static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { return SortItemsProxy(v) } // generate unimplemented toCpp() if interface lacks +swift - static func toCpp(_ v: SwiftType) -> djinni.AnyValue { + static func toCpp(_ v: SwiftType) -> djinni.swift.AnyValue { fatalError("n/a") } } @@ -40,7 +40,7 @@ enum SortItemsMarshaller: DjinniSupport.Marshaller { public class SortItems_statics { static func createWithListener(listener: TextboxListener)-> SortItems { // build prameter list - var params = djinni.ParameterList() + var params = djinni.swift.ParameterList() // generate one line for each parameter params.addValue(TextboxListenerMarshaller.toCpp(listener)) // forward to C++ implementation @@ -49,7 +49,7 @@ public class SortItems_statics { return SortItemsMarshaller.fromCpp(ret) } static func runSort(items: ItemList)-> ItemList { - var params = djinni.ParameterList() + var params = djinni.swift.ParameterList() params.addValue(ItemListMarshaller.toCpp(items)) let ret = djinni_generated.SortItems_runSort(¶ms) return ItemListMarshaller.fromCpp(ret) diff --git a/examples/generated-src/swift/TextboxListener+Private.swift b/examples/generated-src/swift/TextboxListener+Private.swift index 04ba098a..3f70de79 100644 --- a/examples/generated-src/swift/TextboxListener+Private.swift +++ b/examples/generated-src/swift/TextboxListener+Private.swift @@ -4,13 +4,13 @@ import DjinniSupport import support_lib_djinni_support_swiftxx // have to declare this type in each file because for some reason we can't export typealiases with C++ types from DjinniSupport.swift -typealias MethodDispatcher = (Any, UnsafePointer?, UnsafeMutablePointer?) -> Void +typealias MethodDispatcher = (Any, UnsafePointer?, UnsafeMutablePointer?) -> Void let textboxListenerMethods: [MethodDispatcher] = [ // generate one entry for each interface method { inst, params, ret in // generate one line for each parameter - let items = ItemListMarshaller.fromCpp(djinni.getMember(params, 0)) + let items = ItemListMarshaller.fromCpp(djinni.swift.getMember(params, 0)) // call swift object through protocol (inst as! TextboxListener).update(items: items) // update ret if method has return value @@ -20,11 +20,11 @@ let textboxListenerMethods: [MethodDispatcher] = [ enum TextboxListenerMarshaller: DjinniSupport.Marshaller { typealias SwiftType = TextboxListener // generate unimplemented fromCpp() if interface lacks +c - static func fromCpp(_ v: djinni.AnyValue) -> SwiftType { + static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { fatalError("n/a") } // generate toCpp() with the dispatch func - static func toCpp(_ listener: SwiftType) -> djinni.AnyValue { + static func toCpp(_ listener: SwiftType) -> djinni.swift.AnyValue { let ctx = ProtocolWrapperContext(inst: listener, vtbl: textboxListenerMethods) let p = Unmanaged.passRetained(ctx).toOpaque() return djinni_generated.TextboxListenerProtocolWrapper.make(p, DjinniSupport.dispatcherProtocalCall) diff --git a/examples/generated-src/swiftxx/NativeItemList.hpp b/examples/generated-src/swiftxx/NativeItemList.hpp index f32857de..3dbeab03 100644 --- a/examples/generated-src/swiftxx/NativeItemList.hpp +++ b/examples/generated-src/swiftxx/NativeItemList.hpp @@ -6,17 +6,17 @@ namespace djinni_generated { struct NativeItemList { - static djinni::AnyValue fromCpp(const textsort::ItemList& v) { + static djinni::swift::AnyValue fromCpp(const textsort::ItemList& v) { // generate record container - auto ret = std::make_shared(); + auto ret = std::make_shared(); // generate one line for each member of the record - ret->addValue(djinni::List::fromCpp(v.items)); + ret->addValue(djinni::swift::List::fromCpp(v.items)); return {ret}; } - static textsort::ItemList toCpp(const djinni::AnyValue& v) { - auto c = std::get(v); + static textsort::ItemList toCpp(const djinni::swift::AnyValue& v) { + auto c = std::get(v); // generate an argument for each member of the record - return textsort::ItemList(djinni::List::toCpp(c->getValue(0))); + return textsort::ItemList(djinni::swift::List::toCpp(c->getValue(0))); } }; diff --git a/examples/generated-src/swiftxx/NativeSortItems.cpp b/examples/generated-src/swiftxx/NativeSortItems.cpp index 2c115d36..3c241af6 100644 --- a/examples/generated-src/swiftxx/NativeSortItems.cpp +++ b/examples/generated-src/swiftxx/NativeSortItems.cpp @@ -5,7 +5,7 @@ namespace djinni_generated { -djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList* params) { +djinni::swift::AnyValue SortItems_createWithListener(const djinni::swift::ParameterList* params) { // static method: // generate a line for each parameter of the method auto listener = NativeTextboxListener::toCpp(params->getValue(0)); @@ -15,7 +15,7 @@ djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList* param return NativeSortItems::fromCpp(ret); } -djinni::AnyValue SortItems_runSort(const djinni::ParameterList* params) { +djinni::swift::AnyValue SortItems_runSort(const djinni::swift::ParameterList* params) { // static method: auto items = NativeItemList::toCpp(params->getValue(0)); auto ret = textsort::SortItems::run_sort(items); @@ -23,7 +23,7 @@ djinni::AnyValue SortItems_runSort(const djinni::ParameterList* params) { } // +c instance method stub -djinni::AnyValue SortItems_sort(const djinni::ParameterList* params) { +djinni::swift::AnyValue SortItems_sort(const djinni::swift::ParameterList* params) { // instance method: // retrieve the instance pointer from params[0] auto inst = NativeSortItems::toCpp(params->getValue(0)); @@ -34,7 +34,7 @@ djinni::AnyValue SortItems_sort(const djinni::ParameterList* params) { inst->sort(order, items); // convert result to intermediate form // return nil for void methods - return djinni::makeVoidValue(); + return djinni::swift::makeVoidValue(); } } diff --git a/examples/generated-src/swiftxx/NativeSortItems.hpp b/examples/generated-src/swiftxx/NativeSortItems.hpp index 02856769..278f2f5f 100644 --- a/examples/generated-src/swiftxx/NativeSortItems.hpp +++ b/examples/generated-src/swiftxx/NativeSortItems.hpp @@ -6,11 +6,11 @@ namespace djinni_generated { // Alias to generic interface marshaller -using NativeSortItems = djinni::Interface; +using NativeSortItems = djinni::swift::Interface; // Generate forward declarations for each static and +c instance method -djinni::AnyValue SortItems_createWithListener(const djinni::ParameterList* params); -djinni::AnyValue SortItems_runSort(const djinni::ParameterList* params); -djinni::AnyValue SortItems_sort(const djinni::ParameterList* params); +djinni::swift::AnyValue SortItems_createWithListener(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue SortItems_runSort(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue SortItems_sort(const djinni::swift::ParameterList* params); } diff --git a/examples/generated-src/swiftxx/NativeSortOrder.hpp b/examples/generated-src/swiftxx/NativeSortOrder.hpp index 79c98cb9..52e307cf 100644 --- a/examples/generated-src/swiftxx/NativeSortOrder.hpp +++ b/examples/generated-src/swiftxx/NativeSortOrder.hpp @@ -6,6 +6,6 @@ namespace djinni_generated { // Alias to generic enum marshaller -using NativeSortOrder = djinni::Enum; +using NativeSortOrder = djinni::swift::Enum; } diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.cpp b/examples/generated-src/swiftxx/NativeTextboxListener.cpp index 240758eb..e974ce53 100644 --- a/examples/generated-src/swiftxx/NativeTextboxListener.cpp +++ b/examples/generated-src/swiftxx/NativeTextboxListener.cpp @@ -5,12 +5,12 @@ namespace djinni_generated { // +swift method stub void TextboxListenerProtocolWrapper::update(const textsort::ItemList& items) { - djinni::ParameterList params; + djinni::swift::ParameterList params; params.addValue(NativeItemList::fromCpp(items)); callProtocol(0, ¶ms); } -djinni::AnyValue TextboxListenerProtocolWrapper::make(void* instance, djinni::DispatchFunc dispatcher) { +djinni::swift::AnyValue TextboxListenerProtocolWrapper::make(void* instance, djinni::swift::DispatchFunc dispatcher) { return {std::make_shared(instance, dispatcher)}; } diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.hpp b/examples/generated-src/swiftxx/NativeTextboxListener.hpp index ee463696..2dfcd33c 100644 --- a/examples/generated-src/swiftxx/NativeTextboxListener.hpp +++ b/examples/generated-src/swiftxx/NativeTextboxListener.hpp @@ -6,15 +6,15 @@ namespace djinni_generated { // generate proxy class for C++ callers -class TextboxListenerProtocolWrapper: public textsort::TextboxListener, public djinni::ProtocolWrapper { +class TextboxListenerProtocolWrapper: public textsort::TextboxListener, public djinni::swift::ProtocolWrapper { public: - TextboxListenerProtocolWrapper(void* instance, djinni::DispatchFunc dispatcher): djinni::ProtocolWrapper(instance, dispatcher) {} + TextboxListenerProtocolWrapper(void* instance, djinni::swift::DispatchFunc dispatcher): djinni::swift::ProtocolWrapper(instance, dispatcher) {} // factory method for Swift caller - static djinni::AnyValue make(void* instance, djinni::DispatchFunc dispatcher); + static djinni::swift::AnyValue make(void* instance, djinni::swift::DispatchFunc dispatcher); // generate method stubs void update(const textsort::ItemList& items) override; }; -using NativeTextboxListener = djinni::Interface; +using NativeTextboxListener = djinni::swift::Interface; } diff --git a/support-lib/swift/DjinniSupport.swift b/support-lib/swift/DjinniSupport.swift index 9ba8c984..8e1414e8 100644 --- a/support-lib/swift/DjinniSupport.swift +++ b/support-lib/swift/DjinniSupport.swift @@ -1,7 +1,7 @@ import support_lib_djinni_support_swiftxx public class ProtocolWrapperContext { - public typealias MethodDispatcher = (Any, UnsafePointer?, UnsafeMutablePointer?) -> Void + public typealias MethodDispatcher = (Any, UnsafePointer?, UnsafeMutablePointer?) -> Void var inst: Any var vtbl: [MethodDispatcher] @@ -11,15 +11,15 @@ public class ProtocolWrapperContext { self.vtbl = vtbl } - public func dispatch(idx: Int32, params: UnsafePointer?, ret: UnsafeMutablePointer?) -> Void { + public func dispatch(idx: Int32, params: UnsafePointer?, ret: UnsafeMutablePointer?) -> Void { vtbl[Int(idx)](inst, params, ret) } } public func dispatcherProtocalCall(_ ptr: UnsafeMutableRawPointer?, idx: Int32, - params: UnsafePointer?, - ret: UnsafeMutablePointer?) -> Void { + params: UnsafePointer?, + ret: UnsafeMutablePointer?) -> Void { guard let pctx = ptr else { return } if (idx < 0) { // release and destroy the context @@ -33,46 +33,46 @@ public func dispatcherProtocalCall(_ ptr: UnsafeMutableRawPointer?, public protocol Marshaller { associatedtype SwiftType - static func fromCpp(_ v: djinni.AnyValue) -> SwiftType - static func toCpp(_ s: SwiftType) -> djinni.AnyValue + static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue } public enum EnumMarshaller: Marshaller where T.RawValue == Int32 { public typealias SwiftType = T - public static func fromCpp(_ v: djinni.AnyValue) -> SwiftType { - return SwiftType(rawValue: djinni.I32.toCpp(v))! + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return SwiftType(rawValue: djinni.swift.I32.toCpp(v))! } - public static func toCpp(_ s: SwiftType) -> djinni.AnyValue { - return djinni.I32.fromCpp(s.rawValue) + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.I32.fromCpp(s.rawValue) } } public enum StringMarshaller: Marshaller { public typealias SwiftType = String - static public func fromCpp(_ v: djinni.AnyValue) -> SwiftType { - return SwiftType(djinni.String.toCpp(v)) + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return SwiftType(djinni.swift.String.toCpp(v)) } - static public func toCpp(_ s: SwiftType) -> djinni.AnyValue { - return djinni.String.fromCpp(std.string(s)) + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.String.fromCpp(std.string(s)) } } public enum ListMarshaller: Marshaller { public typealias SwiftType = [T.SwiftType] - static public func fromCpp(_ v: djinni.AnyValue) -> SwiftType { + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { var array = SwiftType() withUnsafePointer(to: v) { p in - let size = djinni.getSize(p) + let size = djinni.swift.getSize(p) for i in 0.. djinni.AnyValue { - var composite = djinni.makeCompositeValue() + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var composite = djinni.swift.makeCompositeValue() for item in s { - djinni.addMember(&composite, T.toCpp(item)) + djinni.swift.addMember(&composite, T.toCpp(item)) } return composite } diff --git a/support-lib/swiftxx/djinni_support.cpp b/support-lib/swiftxx/djinni_support.cpp index 24db276c..bf1c9a23 100644 --- a/support-lib/swiftxx/djinni_support.cpp +++ b/support-lib/swiftxx/djinni_support.cpp @@ -1,6 +1,6 @@ #include "djinni_support.hpp" -namespace djinni { +namespace djinni::swift { size_t getSize(const AnyValue* v) { auto composite = std::get(*v); diff --git a/support-lib/swiftxx/djinni_support.hpp b/support-lib/swiftxx/djinni_support.hpp index a45d4de8..065a0361 100644 --- a/support-lib/swiftxx/djinni_support.hpp +++ b/support-lib/swiftxx/djinni_support.hpp @@ -5,7 +5,7 @@ #include #include -namespace djinni { +namespace djinni::swift { // -------- Intermediate data structure and functions to manipulate them from Swift struct VoidValue{}; // I32 covers bool, i8, i16, i32, enum @@ -63,10 +63,10 @@ class ProtocolWrapper { template struct Integer { using CppType = T; - static djinni::AnyValue fromCpp(T v) { + static AnyValue fromCpp(T v) { return {static_cast(v)}; } - static T toCpp(const djinni::AnyValue& v) { + static T toCpp(const AnyValue& v) { auto i = std::get(v); return static_cast(i); } @@ -77,11 +77,11 @@ using I32 = Integer; template struct Enum { using CppType = T; - static djinni::AnyValue fromCpp(T v) { + static AnyValue fromCpp(T v) { return {static_cast(v)}; } - static T toCpp(const djinni::AnyValue& v) { - auto i = std::get(v); + static T toCpp(const AnyValue& v) { + auto i = std::get(v); return static_cast(i); } }; @@ -108,7 +108,7 @@ struct List { } static CppType toCpp(const AnyValue& v) { CppType vec; - auto c = std::get(v); + auto c = std::get(v); for (const auto& item: c->_elems) { vec.push_back(T::toCpp(item)); } @@ -119,11 +119,11 @@ struct List { template struct Interface { using CppType = std::shared_ptr; - static djinni::AnyValue fromCpp(const CppType& v) { + static AnyValue fromCpp(const CppType& v) { return {v}; } - static CppType toCpp(const djinni::AnyValue& v) { - auto p = std::get(v); + static CppType toCpp(const AnyValue& v) { + auto p = std::get(v); return std::reinterpret_pointer_cast(p); } }; From 5d95c1b1c0916dcc6da27c2d333cc36d8c4d1308 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 24 May 2024 14:16:48 +1000 Subject: [PATCH 16/68] implement proxy caches --- .../swift/SortItems+Private.swift | 13 +- examples/generated-src/swift/SortItems.swift | 2 +- .../swift/TextboxListener+Private.swift | 17 ++- .../generated-src/swift/TextboxListener.swift | 2 +- .../swiftxx/NativeTextboxListener.cpp | 6 +- .../swiftxx/NativeTextboxListener.hpp | 5 +- support-lib/swift/DjinniSupport.swift | 118 ++++++++++++++++-- support-lib/swiftxx/djinni_support.cpp | 18 ++- support-lib/swiftxx/djinni_support.hpp | 46 ++++++- 9 files changed, 182 insertions(+), 45 deletions(-) diff --git a/examples/generated-src/swift/SortItems+Private.swift b/examples/generated-src/swift/SortItems+Private.swift index 8616447a..b4472188 100644 --- a/examples/generated-src/swift/SortItems+Private.swift +++ b/examples/generated-src/swift/SortItems+Private.swift @@ -4,12 +4,7 @@ import support_lib_djinni_support_swiftxx // C++ support library import examples_textsort_swiftxx // C++ bridge code // generate Proxy class if interface is +c -class SortItemsProxy: SortItems { - // generate fixed member and init - var inst: djinni.swift.AnyValue - init(_ inst: djinni.swift.AnyValue) { - self.inst = inst - } +final class CppProxy: DjinniSupport.CppProxy, SortItems { // generate method stubs func sort(order: SortOrder, items: ItemList) { var params = djinni.swift.ParameterList() @@ -28,11 +23,11 @@ enum SortItemsMarshaller: DjinniSupport.Marshaller { typealias SwiftType = SortItems // generate fromCpp() if interface is +c static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - return SortItemsProxy(v) + return cppInterfaceToSwift(v, {c in CppProxy(c)}) } - // generate unimplemented toCpp() if interface lacks +swift + // generate unimplemented factory call if interface lacks +swift static func toCpp(_ v: SwiftType) -> djinni.swift.AnyValue { - fatalError("n/a") + return swiftInterfaceToCpp(v, {_ in fatalError("n/a") }) } } diff --git a/examples/generated-src/swift/SortItems.swift b/examples/generated-src/swift/SortItems.swift index f919db64..bfdc1b6d 100644 --- a/examples/generated-src/swift/SortItems.swift +++ b/examples/generated-src/swift/SortItems.swift @@ -1,3 +1,3 @@ -public protocol SortItems { +public protocol SortItems: AnyObject { func sort(order: SortOrder, items: ItemList) } diff --git a/examples/generated-src/swift/TextboxListener+Private.swift b/examples/generated-src/swift/TextboxListener+Private.swift index 3f70de79..38e6c8dc 100644 --- a/examples/generated-src/swift/TextboxListener+Private.swift +++ b/examples/generated-src/swift/TextboxListener+Private.swift @@ -3,30 +3,29 @@ import TextSort import DjinniSupport import support_lib_djinni_support_swiftxx -// have to declare this type in each file because for some reason we can't export typealiases with C++ types from DjinniSupport.swift -typealias MethodDispatcher = (Any, UnsafePointer?, UnsafeMutablePointer?) -> Void +typealias Vtbl = [(T, UnsafePointer?, UnsafeMutablePointer?) -> Void] -let textboxListenerMethods: [MethodDispatcher] = [ +let textboxListenerMethods: Vtbl = [ // generate one entry for each interface method { inst, params, ret in // generate one line for each parameter let items = ItemListMarshaller.fromCpp(djinni.swift.getMember(params, 0)) // call swift object through protocol - (inst as! TextboxListener).update(items: items) + inst.update(items: items) // update ret if method has return value }, ] enum TextboxListenerMarshaller: DjinniSupport.Marshaller { typealias SwiftType = TextboxListener - // generate unimplemented fromCpp() if interface lacks +c static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - fatalError("n/a") + return cppInterfaceToSwift(v, {_ in fatalError("n/a")}) } // generate toCpp() with the dispatch func static func toCpp(_ listener: SwiftType) -> djinni.swift.AnyValue { - let ctx = ProtocolWrapperContext(inst: listener, vtbl: textboxListenerMethods) - let p = Unmanaged.passRetained(ctx).toOpaque() - return djinni_generated.TextboxListenerProtocolWrapper.make(p, DjinniSupport.dispatcherProtocalCall) + return swiftInterfaceToCpp(listener, + {s in + let ctx = ProtocolWrapperContext(inst: s, vtbl: textboxListenerMethods) + return djinni_generated.TextboxListenerSwiftProxy.make(Unmanaged.passRetained(ctx).toOpaque(), DjinniSupport.dispatcherProtocalCall)}) } } diff --git a/examples/generated-src/swift/TextboxListener.swift b/examples/generated-src/swift/TextboxListener.swift index e5c354e6..217dbfeb 100644 --- a/examples/generated-src/swift/TextboxListener.swift +++ b/examples/generated-src/swift/TextboxListener.swift @@ -1,3 +1,3 @@ -public protocol TextboxListener { +public protocol TextboxListener: AnyObject { func update(items: ItemList) } diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.cpp b/examples/generated-src/swiftxx/NativeTextboxListener.cpp index e974ce53..097c6565 100644 --- a/examples/generated-src/swiftxx/NativeTextboxListener.cpp +++ b/examples/generated-src/swiftxx/NativeTextboxListener.cpp @@ -4,14 +4,14 @@ namespace djinni_generated { // +swift method stub -void TextboxListenerProtocolWrapper::update(const textsort::ItemList& items) { +void TextboxListenerSwiftProxy::update(const textsort::ItemList& items) { djinni::swift::ParameterList params; params.addValue(NativeItemList::fromCpp(items)); callProtocol(0, ¶ms); } -djinni::swift::AnyValue TextboxListenerProtocolWrapper::make(void* instance, djinni::swift::DispatchFunc dispatcher) { - return {std::make_shared(instance, dispatcher)}; +djinni::swift::AnyValue TextboxListenerSwiftProxy::make(void* instance, djinni::swift::DispatchFunc dispatcher) { + return {std::make_shared(instance, dispatcher)}; } } diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.hpp b/examples/generated-src/swiftxx/NativeTextboxListener.hpp index 2dfcd33c..7c70fe15 100644 --- a/examples/generated-src/swiftxx/NativeTextboxListener.hpp +++ b/examples/generated-src/swiftxx/NativeTextboxListener.hpp @@ -6,9 +6,10 @@ namespace djinni_generated { // generate proxy class for C++ callers -class TextboxListenerProtocolWrapper: public textsort::TextboxListener, public djinni::swift::ProtocolWrapper { +class TextboxListenerSwiftProxy: public textsort::TextboxListener, + public djinni::swift::ProtocolWrapper { public: - TextboxListenerProtocolWrapper(void* instance, djinni::swift::DispatchFunc dispatcher): djinni::swift::ProtocolWrapper(instance, dispatcher) {} + TextboxListenerSwiftProxy(void* instance, djinni::swift::DispatchFunc dispatcher): ProtocolWrapper(instance, dispatcher) {} // factory method for Swift caller static djinni::swift::AnyValue make(void* instance, djinni::swift::DispatchFunc dispatcher); // generate method stubs diff --git a/support-lib/swift/DjinniSupport.swift b/support-lib/swift/DjinniSupport.swift index 8e1414e8..10a5d2a6 100644 --- a/support-lib/swift/DjinniSupport.swift +++ b/support-lib/swift/DjinniSupport.swift @@ -1,32 +1,48 @@ import support_lib_djinni_support_swiftxx -public class ProtocolWrapperContext { - public typealias MethodDispatcher = (Any, UnsafePointer?, UnsafeMutablePointer?) -> Void +public typealias Vtbl = [(T, UnsafePointer?, UnsafeMutablePointer?) -> Void] - var inst: Any - var vtbl: [MethodDispatcher] +public class GenericProtocolWrapperContext { + public func dispatch(idx: Int32, params: UnsafePointer?, ret: UnsafeMutablePointer?) -> Void { + fatalError("pure virtual") + } + public func getInst() -> AnyObject { + fatalError("pure virtual") + } +} - public init(inst: Any, vtbl: [MethodDispatcher]) { +public final class ProtocolWrapperContext: GenericProtocolWrapperContext { + var inst: T + var vtbl: Vtbl + public init(inst: T, vtbl: Vtbl) { self.inst = inst self.vtbl = vtbl } - - public func dispatch(idx: Int32, params: UnsafePointer?, ret: UnsafeMutablePointer?) -> Void { + public override func dispatch(idx: Int32, params: UnsafePointer?, ret: UnsafeMutablePointer?) -> Void { vtbl[Int(idx)](inst, params, ret) } + public override func getInst() -> AnyObject { + return inst as AnyObject + } } -public func dispatcherProtocalCall(_ ptr: UnsafeMutableRawPointer?, - idx: Int32, - params: UnsafePointer?, - ret: UnsafeMutablePointer?) -> Void { +public func dispatcherProtocalCall( + ptr: UnsafeMutableRawPointer?, + idx: Int32, + params: UnsafePointer?, + ret: UnsafeMutablePointer?) + -> Void { guard let pctx = ptr else { return } if (idx < 0) { // release and destroy the context - let _ = Unmanaged.fromOpaque(pctx).takeRetainedValue() + let ctx = Unmanaged.fromOpaque(pctx).takeRetainedValue() + print("swift proxy cache before destroy", SwiftProxyCache.shared.mapPtrToProxy) + let key = Unmanaged.passUnretained(ctx.getInst()).toOpaque() + SwiftProxyCache.shared.mapPtrToProxy.removeValue(forKey: key) + print("swift proxy cache after destroy", SwiftProxyCache.shared.mapPtrToProxy) } else { // dynamic dispatch on the vtbl - let ctx = Unmanaged.fromOpaque(pctx).takeUnretainedValue() + let ctx = Unmanaged.fromOpaque(pctx).takeUnretainedValue() ctx.dispatch(idx: idx, params: params, ret: ret) } } @@ -50,9 +66,11 @@ public enum EnumMarshaller: Marshaller where T.RawValue == public enum StringMarshaller: Marshaller { public typealias SwiftType = String static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + // TODO: optimize - pass by pointer return SwiftType(djinni.swift.String.toCpp(v)) } static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + // TODO: optimize - pass swift string to c++ return djinni.swift.String.fromCpp(std.string(s)) } } @@ -77,3 +95,77 @@ public enum ListMarshaller: Marshaller { return composite } } + +open class CppProxy { + public var inst: djinni.swift.AnyValue + public init(_ inst: djinni.swift.AnyValue) { + self.inst = inst + } + deinit { + destroyCppProxy(inst) + } +} + +class CppProxyCache { + static let shared = CppProxyCache() + // c++ objects in swift + var mapPtrToProxy: [UnsafeRawPointer: UnsafeMutableRawPointer] = [:] +} + +class SwiftProxyCache { + static let shared = SwiftProxyCache() + // swift objects in c++ + var mapPtrToProxy: [UnsafeMutableRawPointer: djinni.swift.WeakSwiftProxy] = [:] +} + +// 1. object is a an existing cpp proxy : return cpp proxy +// 2. object is a an existing swift proxy: unwrap the original swift object +// 3. need to create a new proxy : call newProxyFunc +public func cppInterfaceToSwift(_ c: djinni.swift.AnyValue, + _ newProxyFunc: (djinni.swift.AnyValue)->I) -> I { + return withUnsafePointer(to: c) { p in + let info = djinni.swift.getInterfaceInfo(p) + // for 1. check the cpp proxy cache + if let s = CppProxyCache.shared.mapPtrToProxy[info.cppPointer] { + return Unmanaged.fromOpaque(s).takeUnretainedValue() as! I + } + // for 2. check if c++ ptr exists in SwiftProxyCache.mapCPtrToSwift + if let pctx = info.ctxPointer { + let ctx = Unmanaged.fromOpaque(pctx).takeUnretainedValue() + return ctx.getInst() as! I + } + // 3. + let newProxy = newProxyFunc(c) + CppProxyCache.shared.mapPtrToProxy[info.cppPointer] = Unmanaged.passUnretained(newProxy as AnyObject).toOpaque() + return newProxy + } +} + +// 1. object is a an existing cpp proxy : unwrap swift proxy +// 2. object is a an existing swift proxy: return existing +// 3. need to create a new proxy : call newProxyFunc +public func swiftInterfaceToCpp(_ s: I, + _ newProxyFunc: (I)->djinni.swift.AnyValue) -> djinni.swift.AnyValue { + // 1. try cast to CppProxy and unwrap + if let cppproxy = s as? CppProxy { + return cppproxy.inst + } + // 2. check swift proxy cache + let key = Unmanaged.passUnretained(s as AnyObject).toOpaque() + if let weakProxy = SwiftProxyCache.shared.mapPtrToProxy[key] { + return djinni.swift.strongify(weakProxy) + } + // 3. + let newProxy = newProxyFunc(s) + SwiftProxyCache.shared.mapPtrToProxy[key] = djinni.swift.weakify(newProxy) + return newProxy +} + +public func destroyCppProxy(_ inst: djinni.swift.AnyValue) { + withUnsafePointer(to: inst) { p in + let info = djinni.swift.getInterfaceInfo(p) + print("before destroy cppproxycache entry", CppProxyCache.shared.mapPtrToProxy) + CppProxyCache.shared.mapPtrToProxy.removeValue(forKey: info.cppPointer) + print("after destroy cppproxycache entry", CppProxyCache.shared.mapPtrToProxy) + } +} diff --git a/support-lib/swiftxx/djinni_support.cpp b/support-lib/swiftxx/djinni_support.cpp index bf1c9a23..df8df88e 100644 --- a/support-lib/swiftxx/djinni_support.cpp +++ b/support-lib/swiftxx/djinni_support.cpp @@ -16,7 +16,7 @@ AnyValue getMember(const ParameterList* v, size_t i) { return v->getValue(i); } -void addMember(const AnyValue* c, const AnyValue& v) { +void addMember(AnyValue* c, const AnyValue& v) { auto composite = std::get(*c); composite->addValue(v); } @@ -25,6 +25,20 @@ void setReturnValue(AnyValue* ret, const AnyValue& v) { *ret = v; } +WeakSwiftProxy weakify(const AnyValue& v) { + auto i = std::get(v); + return i.sptr; +} + +AnyValue strongify(const WeakSwiftProxy& v) { + return {v.lock()}; +} + +InterfaceInfo getInterfaceInfo(const AnyValue* v) { + auto i = std::get(*v); + return {i.ptr.get(), i.sptr.get()}; +} + AnyValue makeVoidValue() { return VoidValue{}; } @@ -43,7 +57,7 @@ ProtocolWrapper::~ProtocolWrapper() { } AnyValue ProtocolWrapper::callProtocol(int idx, const ParameterList* params) { - AnyValue ret = VoidValue(); + AnyValue ret = VoidValue(); // output parameter _dispatcher(_ctx, idx, params, &ret); return ret; } diff --git a/support-lib/swiftxx/djinni_support.hpp b/support-lib/swiftxx/djinni_support.hpp index 065a0361..5f11161e 100644 --- a/support-lib/swiftxx/djinni_support.hpp +++ b/support-lib/swiftxx/djinni_support.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace djinni::swift { // -------- Intermediate data structure and functions to manipulate them from Swift @@ -16,7 +17,14 @@ using DoubleValue = double; using StringValue = std::string; using BinaryValue = std::vector; using DateValue = std::chrono::system_clock::time_point; -using InterfaceValue = std::shared_ptr; + +class ProtocolWrapper; +struct InterfaceValue { + std::shared_ptr ptr; + std::shared_ptr sptr; + template + InterfaceValue(const std::shared_ptr& p) : ptr(p), sptr(std::dynamic_pointer_cast(p)) {} +}; struct CompositeValue; using CompositeValuePtr = std::shared_ptr; @@ -33,6 +41,9 @@ struct CompositeValue { void addValue(const AnyValue& v) { _elems.push_back(v); } + void addValue(AnyValue&& v) { + _elems.push_back(std::move(v)); + } AnyValue getValue(size_t i) const { return _elems[i]; } size_t getSize() const { return _elems.size(); } }; @@ -41,22 +52,33 @@ struct ParameterList: CompositeValue {}; size_t getSize(const AnyValue* v); AnyValue getMember(const AnyValue* v, size_t i); -void addMember(const AnyValue* c, const AnyValue& v); +void addMember(AnyValue* c, const AnyValue& v); AnyValue getMember(const ParameterList* v, size_t i); void setReturnValue(AnyValue* ret, const AnyValue& v); AnyValue makeVoidValue(); AnyValue makeCompositeValue(); +struct InterfaceInfo { + void* cppPointer; + void* ctxPointer; +}; +InterfaceInfo getInterfaceInfo(const AnyValue* v); + +using WeakSwiftProxy = std::weak_ptr; +WeakSwiftProxy weakify(const AnyValue& v); +AnyValue strongify(const WeakSwiftProxy& v); + // -------- Swift protocol trampoline typedef void (*DispatchFunc)(void* ctx, int idx /* -1 for cleanup*/, const ParameterList* params, AnyValue* ret); class ProtocolWrapper { +protected: void* _ctx; DispatchFunc _dispatcher; -protected: ProtocolWrapper(void* ctx, DispatchFunc dispatcher); AnyValue callProtocol(int idx, const ParameterList* params); public: virtual ~ProtocolWrapper(); + void* ctx() const { return _ctx; } }; // -------- Built-in marshallers (conversion between C++ types and intermediate types) @@ -123,9 +145,23 @@ struct Interface { return {v}; } static CppType toCpp(const AnyValue& v) { - auto p = std::get(v); - return std::reinterpret_pointer_cast(p); + auto i = std::get(v); + return std::reinterpret_pointer_cast(i.ptr); } }; +// // Keeps track of C++ objects in Swift +// class CppProxyCache { +// static CppProxyCache& instance(); +// std::unordered_map _mapPtrToProxy; +// public: +// }; + +// // Keeps track of Swift objects in C++ +// class SwiftProxyCache { +// static SwiftProxyCache& instance(); +// std::unordered_map _mapPtrToProxy; +// public: +// }; + } From 85526899eb0657317561f129f848c5a8c77923e5 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Tue, 4 Jun 2024 11:12:20 +1000 Subject: [PATCH 17/68] initial codegen --- examples/BUILD | 3 +- .../swift/ItemList+Private.swift | 29 ++- examples/generated-src/swift/ItemList.swift | 10 +- .../swift/SortItems+Private.swift | 46 ++-- examples/generated-src/swift/SortItems.swift | 6 +- .../swift/SortOrder+Private.swift | 7 +- examples/generated-src/swift/SortOrder.swift | 7 +- .../swift/TextboxListener+Private.swift | 34 +-- .../generated-src/swift/TextboxListener.swift | 5 +- .../generated-src/swiftxx/NativeItemList.hpp | 23 -- .../generated-src/swiftxx/NativeSortItems.cpp | 40 ---- .../generated-src/swiftxx/NativeSortOrder.hpp | 11 - .../swiftxx/NativeTextboxListener.cpp | 17 -- .../swiftxx/NativeTextboxListener.hpp | 21 -- .../generated-src/swiftxx/SwiftItemList.cpp | 18 ++ .../generated-src/swiftxx/SwiftItemList.hpp | 17 ++ .../generated-src/swiftxx/SwiftSortItems.cpp | 29 +++ ...NativeSortItems.hpp => SwiftSortItems.hpp} | 13 +- .../generated-src/swiftxx/SwiftSortOrder.cpp | 9 + .../generated-src/swiftxx/SwiftSortOrder.hpp | 13 ++ .../swiftxx/SwiftTextboxListener.cpp | 10 + .../swiftxx/SwiftTextboxListener.hpp | 13 ++ examples/run_djinni.sh | 10 + src/source/Main.scala | 28 +++ src/source/Marshal.scala | 1 + src/source/SwiftGenerator.scala | 216 ++++++++++++++++++ src/source/SwiftMarshal.scala | 129 +++++++++++ src/source/SwiftxxGenerator.scala | 196 ++++++++++++++++ src/source/SwiftxxMarshal.scala | 98 ++++++++ src/source/ast.scala | 4 +- src/source/generator.scala | 39 +++- src/source/parser.scala | 19 +- support-lib/BUILD | 3 +- support-lib/swift/DjinniSupport.swift | 15 +- support-lib/swiftxx/djinni_support.hpp | 14 -- test-suite/BUILD | 1 - 36 files changed, 921 insertions(+), 233 deletions(-) delete mode 100644 examples/generated-src/swiftxx/NativeItemList.hpp delete mode 100644 examples/generated-src/swiftxx/NativeSortItems.cpp delete mode 100644 examples/generated-src/swiftxx/NativeSortOrder.hpp delete mode 100644 examples/generated-src/swiftxx/NativeTextboxListener.cpp delete mode 100644 examples/generated-src/swiftxx/NativeTextboxListener.hpp create mode 100644 examples/generated-src/swiftxx/SwiftItemList.cpp create mode 100644 examples/generated-src/swiftxx/SwiftItemList.hpp create mode 100644 examples/generated-src/swiftxx/SwiftSortItems.cpp rename examples/generated-src/swiftxx/{NativeSortItems.hpp => SwiftSortItems.hpp} (64%) create mode 100644 examples/generated-src/swiftxx/SwiftSortOrder.cpp create mode 100644 examples/generated-src/swiftxx/SwiftSortOrder.hpp create mode 100644 examples/generated-src/swiftxx/SwiftTextboxListener.cpp create mode 100644 examples/generated-src/swiftxx/SwiftTextboxListener.hpp create mode 100644 src/source/SwiftGenerator.scala create mode 100644 src/source/SwiftMarshal.scala create mode 100644 src/source/SwiftxxGenerator.scala create mode 100644 src/source/SwiftxxMarshal.scala diff --git a/examples/BUILD b/examples/BUILD index 3396df15..4ab33436 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -20,7 +20,6 @@ cc_library( deps = [ "//support-lib:djinni-support-common", ], - tags = ["swift_module"], alwayslink = 1, visibility = ["//visibility:public"], ) @@ -164,6 +163,6 @@ cc_library( copts = [ "-std=c++17", ], - tags = ["swift_module"], + tags = ["swift_module=TextSortCxx"], visibility = ["//visibility:public"], ) diff --git a/examples/generated-src/swift/ItemList+Private.swift b/examples/generated-src/swift/ItemList+Private.swift index a738d013..accd5600 100644 --- a/examples/generated-src/swift/ItemList+Private.swift +++ b/examples/generated-src/swift/ItemList+Private.swift @@ -1,22 +1,21 @@ -import TextSort // Swift Djinni API -import DjinniSupport // Swift support library -import support_lib_djinni_support_swiftxx // C++ support library +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni -enum ItemListMarshaller: Marshaller { +import DjinniSupport +import DjinniSupportCxx +import TextSort + +enum ItemListMarshaller: DjinniSupport.Marshaller { typealias SwiftType = ItemList - static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - return withUnsafePointer(to: v) { p in - // generate one line for each member of the record - let items = DjinniSupport.ListMarshaller.fromCpp(djinni.swift.getMember(p, 0)) - // generate a struct constructor call - return ItemList(items: items) + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let items = ListMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(items: items) } } static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - // construct the record container - var v = djinni.swift.makeCompositeValue() - // generate one line for each member of the record - djinni.swift.addMember(&v, ListMarshaller.toCpp(s.items)) - return v + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, ListMarshaller.toCpp(s.items)) + return ret } } diff --git a/examples/generated-src/swift/ItemList.swift b/examples/generated-src/swift/ItemList.swift index ae413d4a..1f39d371 100644 --- a/examples/generated-src/swift/ItemList.swift +++ b/examples/generated-src/swift/ItemList.swift @@ -1,7 +1,11 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + public struct ItemList { - public var items: [String] + public var items: Array - public init(items: [String]) { + public init(items: Array) + { self.items = items } -}; +} diff --git a/examples/generated-src/swift/SortItems+Private.swift b/examples/generated-src/swift/SortItems+Private.swift index b4472188..d18e1556 100644 --- a/examples/generated-src/swift/SortItems+Private.swift +++ b/examples/generated-src/swift/SortItems+Private.swift @@ -1,52 +1,38 @@ -import TextSort // Swift Djinni API -import DjinniSupport // Swift support library -import support_lib_djinni_support_swiftxx // C++ support library -import examples_textsort_swiftxx // C++ bridge code +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +import DjinniSupport +import DjinniSupportCxx +import TextSort +import TextSortCxx -// generate Proxy class if interface is +c final class CppProxy: DjinniSupport.CppProxy, SortItems { - // generate method stubs - func sort(order: SortOrder, items: ItemList) { + func sort(order: SortOrder, items: ItemList) -> Void { var params = djinni.swift.ParameterList() - // add instance as first parameter params.addValue(inst) - // generate a line for each parameter params.addValue(SortOrderMarshaller.toCpp(order)) params.addValue(ItemListMarshaller.toCpp(items)) - // forward to C++ implementation djinni_generated.SortItems_sort(¶ms) - // convert result back to swift (if return type is not void) } } - enum SortItemsMarshaller: DjinniSupport.Marshaller { typealias SwiftType = SortItems - // generate fromCpp() if interface is +c - static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - return cppInterfaceToSwift(v, {c in CppProxy(c)}) + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { CppProxy(c) }) } - // generate unimplemented factory call if interface lacks +swift - static func toCpp(_ v: SwiftType) -> djinni.swift.AnyValue { - return swiftInterfaceToCpp(v, {_ in fatalError("n/a") }) + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } - -// Generate stubs for static methods (if there are any) public class SortItems_statics { - static func createWithListener(listener: TextboxListener)-> SortItems { - // build prameter list + static func createWithListener(listener: TextboxListener) -> SortItems { var params = djinni.swift.ParameterList() - // generate one line for each parameter params.addValue(TextboxListenerMarshaller.toCpp(listener)) - // forward to C++ implementation - let ret = djinni_generated.SortItems_createWithListener(¶ms) - // convert result back to swift - return SortItemsMarshaller.fromCpp(ret) + return SortItemsMarshaller.fromCpp(djinni_generated.SortItems_createWithListener(¶ms)) } - static func runSort(items: ItemList)-> ItemList { + static func runSort(items: ItemList) -> ItemList { var params = djinni.swift.ParameterList() params.addValue(ItemListMarshaller.toCpp(items)) - let ret = djinni_generated.SortItems_runSort(¶ms) - return ItemListMarshaller.fromCpp(ret) + return ItemListMarshaller.fromCpp(djinni_generated.SortItems_runSort(¶ms)) } } diff --git a/examples/generated-src/swift/SortItems.swift b/examples/generated-src/swift/SortItems.swift index bfdc1b6d..38a31719 100644 --- a/examples/generated-src/swift/SortItems.swift +++ b/examples/generated-src/swift/SortItems.swift @@ -1,3 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + public protocol SortItems: AnyObject { - func sort(order: SortOrder, items: ItemList) + /** For the iOS / Android demo */ + func sort(order: SortOrder, items: ItemList) -> Void } diff --git a/examples/generated-src/swift/SortOrder+Private.swift b/examples/generated-src/swift/SortOrder+Private.swift index d2ce68aa..0d793a72 100644 --- a/examples/generated-src/swift/SortOrder+Private.swift +++ b/examples/generated-src/swift/SortOrder+Private.swift @@ -1,4 +1,7 @@ -import TextSort +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + import DjinniSupport +import TextSort -typealias SortOrderMarshaller = EnumMarshaller +typealias SortOrderMarshaller = DjinniSupport.EnumMarshaller diff --git a/examples/generated-src/swift/SortOrder.swift b/examples/generated-src/swift/SortOrder.swift index 66cf38eb..afb553ff 100644 --- a/examples/generated-src/swift/SortOrder.swift +++ b/examples/generated-src/swift/SortOrder.swift @@ -1,5 +1,8 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + public enum SortOrder: Int32 { - case ASCENDING = 0 + case ASCENDING = 0 case DESCENDING = 1 - case RANDOM = 2 + case RANDOM = 2 } diff --git a/examples/generated-src/swift/TextboxListener+Private.swift b/examples/generated-src/swift/TextboxListener+Private.swift index 38e6c8dc..1c6f8aa8 100644 --- a/examples/generated-src/swift/TextboxListener+Private.swift +++ b/examples/generated-src/swift/TextboxListener+Private.swift @@ -1,31 +1,17 @@ -import examples_textsort_swiftxx -import TextSort -import DjinniSupport -import support_lib_djinni_support_swiftxx - -typealias Vtbl = [(T, UnsafePointer?, UnsafeMutablePointer?) -> Void] +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni -let textboxListenerMethods: Vtbl = [ - // generate one entry for each interface method - { inst, params, ret in - // generate one line for each parameter - let items = ItemListMarshaller.fromCpp(djinni.swift.getMember(params, 0)) - // call swift object through protocol - inst.update(items: items) - // update ret if method has return value - }, -] +import DjinniSupport +import DjinniSupportCxx +import TextSort +import TextSortCxx enum TextboxListenerMarshaller: DjinniSupport.Marshaller { typealias SwiftType = TextboxListener - static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - return cppInterfaceToSwift(v, {_ in fatalError("n/a")}) + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { fatalError("n/a") }) } - // generate toCpp() with the dispatch func - static func toCpp(_ listener: SwiftType) -> djinni.swift.AnyValue { - return swiftInterfaceToCpp(listener, - {s in - let ctx = ProtocolWrapperContext(inst: s, vtbl: textboxListenerMethods) - return djinni_generated.TextboxListenerSwiftProxy.make(Unmanaged.passRetained(ctx).toOpaque(), DjinniSupport.dispatcherProtocalCall)}) + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/examples/generated-src/swift/TextboxListener.swift b/examples/generated-src/swift/TextboxListener.swift index 217dbfeb..57c08932 100644 --- a/examples/generated-src/swift/TextboxListener.swift +++ b/examples/generated-src/swift/TextboxListener.swift @@ -1,3 +1,6 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + public protocol TextboxListener: AnyObject { - func update(items: ItemList) + func update(items: ItemList) -> Void } diff --git a/examples/generated-src/swiftxx/NativeItemList.hpp b/examples/generated-src/swiftxx/NativeItemList.hpp deleted file mode 100644 index 3dbeab03..00000000 --- a/examples/generated-src/swiftxx/NativeItemList.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include -#include "djinni_support.hpp" - -namespace djinni_generated { - -struct NativeItemList { - static djinni::swift::AnyValue fromCpp(const textsort::ItemList& v) { - // generate record container - auto ret = std::make_shared(); - // generate one line for each member of the record - ret->addValue(djinni::swift::List::fromCpp(v.items)); - return {ret}; - } - static textsort::ItemList toCpp(const djinni::swift::AnyValue& v) { - auto c = std::get(v); - // generate an argument for each member of the record - return textsort::ItemList(djinni::swift::List::toCpp(c->getValue(0))); - } -}; - -} diff --git a/examples/generated-src/swiftxx/NativeSortItems.cpp b/examples/generated-src/swiftxx/NativeSortItems.cpp deleted file mode 100644 index 3c241af6..00000000 --- a/examples/generated-src/swiftxx/NativeSortItems.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include -#include - -namespace djinni_generated { - -djinni::swift::AnyValue SortItems_createWithListener(const djinni::swift::ParameterList* params) { - // static method: - // generate a line for each parameter of the method - auto listener = NativeTextboxListener::toCpp(params->getValue(0)); - // call the C++ static method implementation - auto ret = textsort::SortItems::create_with_listener(listener); - // convert result to intermediate form - return NativeSortItems::fromCpp(ret); -} - -djinni::swift::AnyValue SortItems_runSort(const djinni::swift::ParameterList* params) { - // static method: - auto items = NativeItemList::toCpp(params->getValue(0)); - auto ret = textsort::SortItems::run_sort(items); - return NativeItemList::fromCpp(ret); -} - -// +c instance method stub -djinni::swift::AnyValue SortItems_sort(const djinni::swift::ParameterList* params) { - // instance method: - // retrieve the instance pointer from params[0] - auto inst = NativeSortItems::toCpp(params->getValue(0)); - // generate a line for each parameter of the method - auto order = NativeSortOrder::toCpp(params->getValue(1)); - auto items = NativeItemList::toCpp(params->getValue(2)); - // call the C++ instance method implementation - inst->sort(order, items); - // convert result to intermediate form - // return nil for void methods - return djinni::swift::makeVoidValue(); -} - -} diff --git a/examples/generated-src/swiftxx/NativeSortOrder.hpp b/examples/generated-src/swiftxx/NativeSortOrder.hpp deleted file mode 100644 index 52e307cf..00000000 --- a/examples/generated-src/swiftxx/NativeSortOrder.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "sort_order.hpp" -#include "djinni_support.hpp" - -namespace djinni_generated { - -// Alias to generic enum marshaller -using NativeSortOrder = djinni::swift::Enum; - -} diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.cpp b/examples/generated-src/swiftxx/NativeTextboxListener.cpp deleted file mode 100644 index 097c6565..00000000 --- a/examples/generated-src/swiftxx/NativeTextboxListener.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -namespace djinni_generated { - -// +swift method stub -void TextboxListenerSwiftProxy::update(const textsort::ItemList& items) { - djinni::swift::ParameterList params; - params.addValue(NativeItemList::fromCpp(items)); - callProtocol(0, ¶ms); -} - -djinni::swift::AnyValue TextboxListenerSwiftProxy::make(void* instance, djinni::swift::DispatchFunc dispatcher) { - return {std::make_shared(instance, dispatcher)}; -} - -} diff --git a/examples/generated-src/swiftxx/NativeTextboxListener.hpp b/examples/generated-src/swiftxx/NativeTextboxListener.hpp deleted file mode 100644 index 7c70fe15..00000000 --- a/examples/generated-src/swiftxx/NativeTextboxListener.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "textbox_listener.hpp" -#include "djinni_support.hpp" - -namespace djinni_generated { - -// generate proxy class for C++ callers -class TextboxListenerSwiftProxy: public textsort::TextboxListener, - public djinni::swift::ProtocolWrapper { -public: - TextboxListenerSwiftProxy(void* instance, djinni::swift::DispatchFunc dispatcher): ProtocolWrapper(instance, dispatcher) {} - // factory method for Swift caller - static djinni::swift::AnyValue make(void* instance, djinni::swift::DispatchFunc dispatcher); - // generate method stubs - void update(const textsort::ItemList& items) override; -}; - -using NativeTextboxListener = djinni::swift::Interface; - -} diff --git a/examples/generated-src/swiftxx/SwiftItemList.cpp b/examples/generated-src/swiftxx/SwiftItemList.cpp new file mode 100644 index 00000000..9ab39e84 --- /dev/null +++ b/examples/generated-src/swiftxx/SwiftItemList.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +#include "SwiftItemList.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue SwiftItemList::fromCpp(const ::textsort::ItemList& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::List<::djinni::swift::String>::fromCpp(c.items)); + return {ret}; +} +::textsort::ItemList SwiftItemList::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::textsort::ItemList(::djinni::swift::List<::djinni::swift::String>::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/examples/generated-src/swiftxx/SwiftItemList.hpp b/examples/generated-src/swiftxx/SwiftItemList.hpp new file mode 100644 index 00000000..ebf6a7c9 --- /dev/null +++ b/examples/generated-src/swiftxx/SwiftItemList.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "item_list.hpp" + +namespace djinni_generated { + +struct SwiftItemList { + using CppType = ::textsort::ItemList; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/examples/generated-src/swiftxx/SwiftSortItems.cpp b/examples/generated-src/swiftxx/SwiftSortItems.cpp new file mode 100644 index 00000000..7898f6c1 --- /dev/null +++ b/examples/generated-src/swiftxx/SwiftSortItems.cpp @@ -0,0 +1,29 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +#include "SwiftSortItems.hpp" // my header +#include "SwiftItemList.hpp" +#include "SwiftSortOrder.hpp" +#include "SwiftTextboxListener.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue SortItems_sort(const djinni::swift::ParameterList* params) { + auto inst = SwiftSortItems::toCpp(params->getValue(0)); + auto _order = ::djinni_generated::SwiftSortOrder::toCpp(params->getValue(1)); + auto _items = ::djinni_generated::SwiftItemList::toCpp(params->getValue(2)); + inst->sort(_order, _items); + return djinni::swift::makeVoidValue(); +} +djinni::swift::AnyValue SortItems_createWithListener(const djinni::swift::ParameterList* params) { + auto _listener = ::djinni_generated::SwiftTextboxListener::toCpp(params->getValue(0)); + auto ret = ::textsort::SortItems::create_with_listener(_listener); + return ::djinni_generated::SwiftSortItems::fromCpp(ret); +} +djinni::swift::AnyValue SortItems_runSort(const djinni::swift::ParameterList* params) { + auto _items = ::djinni_generated::SwiftItemList::toCpp(params->getValue(0)); + auto ret = ::textsort::SortItems::run_sort(_items); + return ::djinni_generated::SwiftItemList::fromCpp(ret); +} + +} // namespace djinni_generated diff --git a/examples/generated-src/swiftxx/NativeSortItems.hpp b/examples/generated-src/swiftxx/SwiftSortItems.hpp similarity index 64% rename from examples/generated-src/swiftxx/NativeSortItems.hpp rename to examples/generated-src/swiftxx/SwiftSortItems.hpp index 278f2f5f..639daaf9 100644 --- a/examples/generated-src/swiftxx/NativeSortItems.hpp +++ b/examples/generated-src/swiftxx/SwiftSortItems.hpp @@ -1,16 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + #pragma once -#include "sort_items.hpp" #include "djinni_support.hpp" +#include "sort_items.hpp" namespace djinni_generated { -// Alias to generic interface marshaller -using NativeSortItems = djinni::swift::Interface; +using SwiftSortItems = djinni::swift::Interface<::textsort::SortItems>; -// Generate forward declarations for each static and +c instance method +djinni::swift::AnyValue SortItems_sort(const djinni::swift::ParameterList* params); djinni::swift::AnyValue SortItems_createWithListener(const djinni::swift::ParameterList* params); djinni::swift::AnyValue SortItems_runSort(const djinni::swift::ParameterList* params); -djinni::swift::AnyValue SortItems_sort(const djinni::swift::ParameterList* params); -} +} // namespace djinni_generated diff --git a/examples/generated-src/swiftxx/SwiftSortOrder.cpp b/examples/generated-src/swiftxx/SwiftSortOrder.cpp new file mode 100644 index 00000000..36ac5897 --- /dev/null +++ b/examples/generated-src/swiftxx/SwiftSortOrder.cpp @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +#include "SwiftSortOrder.hpp" // my header + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/examples/generated-src/swiftxx/SwiftSortOrder.hpp b/examples/generated-src/swiftxx/SwiftSortOrder.hpp new file mode 100644 index 00000000..184b7d07 --- /dev/null +++ b/examples/generated-src/swiftxx/SwiftSortOrder.hpp @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "sort_order.hpp" + +namespace djinni_generated { + +using SwiftSortOrder = djinni::swift::Enum<::textsort::sort_order>; + +} // namespace djinni_generated diff --git a/examples/generated-src/swiftxx/SwiftTextboxListener.cpp b/examples/generated-src/swiftxx/SwiftTextboxListener.cpp new file mode 100644 index 00000000..86639863 --- /dev/null +++ b/examples/generated-src/swiftxx/SwiftTextboxListener.cpp @@ -0,0 +1,10 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +#include "SwiftTextboxListener.hpp" // my header +#include "SwiftItemList.hpp" + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/examples/generated-src/swiftxx/SwiftTextboxListener.hpp b/examples/generated-src/swiftxx/SwiftTextboxListener.hpp new file mode 100644 index 00000000..63d7822e --- /dev/null +++ b/examples/generated-src/swiftxx/SwiftTextboxListener.hpp @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "textbox_listener.hpp" + +namespace djinni_generated { + +using SwiftTextboxListener = djinni::swift::Interface<::textsort::TextboxListener>; + +} // namespace djinni_generated diff --git a/examples/run_djinni.sh b/examples/run_djinni.sh index 6fb27b10..570a0712 100755 --- a/examples/run_djinni.sh +++ b/examples/run_djinni.sh @@ -25,6 +25,8 @@ objc_out="$base_dir/generated-src/objc" java_out="$base_dir/generated-src/java/com/dropbox/textsort" wasm_out="$base_dir/generated-src/wasm" ts_out="$base_dir/generated-src/ts" +swift_out="$base_dir/generated-src/swift" +swiftxx_out="$base_dir/generated-src/swiftxx" java_package="com.dropbox.textsort" @@ -77,6 +79,12 @@ fi --ts-out "$temp_out/ts" \ --ts-module "example" \ \ + --swift-out "$temp_out/swift" \ + --swift-module "TextSort" \ + --swiftxx-out "$temp_out/swiftxx" \ + --ident-swiftxx-class SwiftFooBar \ + --ident-swiftxx-file SwiftFooBar \ + \ --idl "$in" # Copy changes from "$temp_output" to final dir. @@ -96,6 +104,8 @@ mirror "jni" "$temp_out/jni" "$jni_out" mirror "objc" "$temp_out/objc" "$objc_out" mirror "wasm" "$temp_out/wasm" "$wasm_out" mirror "ts" "$temp_out/ts" "$ts_out" +mirror "swift" "$temp_out/swift" "$swift_out" +mirror "swiftxx" "$temp_out/swiftxx" "$swiftxx_out" date > "$gen_stamp" diff --git a/src/source/Main.scala b/src/source/Main.scala index 429d8710..d8dff9d8 100644 --- a/src/source/Main.scala +++ b/src/source/Main.scala @@ -111,6 +111,14 @@ object Main { var composerIncludePrefix: String = "" var composerIncludeCppPrefix: String = "" var composerBaseLibIncludePrefix: String = "" + var swiftOutFolder: Option[File] = None + var swiftModule: String = "Module" + var swiftIdentStyle = IdentStyle.swiftDefault + var swiftxxOutFolder: Option[File] = None + var swiftxxNamespace: String = "djinni_generated" + var swiftxxBaseLibModule: String = "DjinniSupportCxx" + var swiftxxClassIdentStyleOptional: Option[IdentConverter] = None + var swiftxxFileIdentStyleOptional: Option[IdentConverter] = None var inFileListPath: Option[File] = None var outFileListPath: Option[File] = None var skipGeneration: Boolean = false @@ -290,6 +298,13 @@ object Main { opt[File]("composer-ts-out").valueName("").foreach(x => composerTsOutFolder = Some(x)) .text("The output for the Composer TypeScript interface files (Generator disabled if unspecified).") note("") + opt[File]("swift-out").valueName("").foreach(x => swiftOutFolder = Some(x)) + .text("The output folder for Swift files (Generator disabled if unspecified).") + opt[String]("swift-module").valueName("").foreach(swiftModule = _) + .text("Swift module name (default: \"Module\").") + opt[File]("swiftxx-out").valueName("").foreach(x => swiftxxOutFolder = Some(x)) + .text("The output folder for private Swift/C++ interop files (Generator disabled if unspecified).") + note("") opt[File]("yaml-out").valueName("").foreach(x => yamlOutFolder = Some(x)) .text("The output folder for YAML files (Generator disabled if unspecified).") opt[String]("yaml-out-file").valueName("").foreach(x => yamlOutFile = Some(x)) @@ -328,6 +343,8 @@ object Main { identStyle("ident-objc-file", c => { objcFileIdentStyleOptional = Some(c) }) identStyle("ident-composer-class", c => { composerClassIdentStyleOptional = Some(c)}) identStyle("ident-composer-file", c => { composerFileIdentStyleOptional = Some(c)}) + identStyle("ident-swiftxx-class", c => { swiftxxClassIdentStyleOptional = Some(c)}) + identStyle("ident-swiftxx-file", c => { swiftxxFileIdentStyleOptional = Some(c)}) } if (!argParser.parse(args)) { @@ -353,6 +370,9 @@ object Main { cppIdentStyle = cppIdentStyle.copy(enumType = cppTypeEnumIdentStyle) } + val swiftxxClassIdentStyle = swiftxxClassIdentStyleOptional.getOrElse(cppIdentStyle.ty) + val swiftxxFileIdentStyle = swiftxxFileIdentStyleOptional.getOrElse(cppFileIdentStyle) + // Parse IDL file. System.out.println("Parsing...") val inFileListWriter = if (inFileListPath.isDefined) { @@ -491,6 +511,14 @@ object Main { composerClassIdentStyle, composerFileIdentStyle, composerTsOutFolder, + swiftOutFolder, + swiftIdentStyle, + swiftModule, + swiftxxOutFolder, + swiftxxNamespace, + swiftxxBaseLibModule, + swiftxxClassIdentStyle, + swiftxxFileIdentStyle, outFileListWriter, skipGeneration, yamlOutFolder, diff --git a/src/source/Marshal.scala b/src/source/Marshal.scala index f4fff656..27b2e0d9 100644 --- a/src/source/Marshal.scala +++ b/src/source/Marshal.scala @@ -40,6 +40,7 @@ abstract class Marshal(spec: Spec) { protected val idCpp = spec.cppIdentStyle protected val idJava = spec.javaIdentStyle protected val idObjc = spec.objcIdentStyle + protected val idSwift = spec.swiftIdentStyle protected def withNs(namespace: Option[String], t: String) = namespace match { case None => t diff --git a/src/source/SwiftGenerator.scala b/src/source/SwiftGenerator.scala new file mode 100644 index 00000000..1582d7ab --- /dev/null +++ b/src/source/SwiftGenerator.scala @@ -0,0 +1,216 @@ +/** + * Copyright 2024 Snap, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package djinni + +import java.io._ +import djinni.ast.Record.DerivingType +import djinni.ast._ +import djinni.generatorTools._ +import djinni.meta._ +import djinni.writer.IndentWriter +import scala.collection.mutable.ListBuffer +import scala.collection.mutable.TreeSet +import java.util.regex.Pattern +import java.util.regex.Matcher + +class SwiftGenerator(spec: Spec) extends Generator(spec) { + + val marshal = new SwiftMarshal(spec) + + def writeSwiftFile(ident: String, origin: String, refs: Iterable[String], f: IndentWriter => Unit) { + createFile(spec.swiftOutFolder.get, idSwift.ty(ident) + ".swift", (w: IndentWriter) => { + w.wl("// AUTOGENERATED FILE - DO NOT MODIFY!") + w.wl("// This file was generated by Djinni from " + origin) + w.wl + f(w) + }) + } + def writeSwiftPrivateFile(ident: String, origin: String, refs: Iterable[String], f: IndentWriter => Unit) { + createFile(spec.swiftOutFolder.get, idSwift.ty(ident) + "+Private.swift", (w: IndentWriter) => { + w.wl("// AUTOGENERATED FILE - DO NOT MODIFY!") + w.wl("// This file was generated by Djinni from " + origin) + w.wl + if (refs.nonEmpty) { + refs.foreach(s => w.wl(s"import $s")) + w.wl + } + f(w) + }) + } + + override def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum) { + writeSwiftFile(ident, origin, List[String](), w => { + w.w(s"public enum ${marshal.typename(ident, e)}: Int32").braced { + writeEnumOptionNone(w, e, idSwift.enum, "=", "case ", "") + writeEnumOptions(w, e, idSwift.enum, "=", "case ", "") + writeEnumOptionAll(w, e, idSwift.enum, "=", "case ", "") + } + }) + writeSwiftPrivateFile(ident, origin, List[String]("DjinniSupport", spec.swiftModule), w => { + w.wl(s"typealias ${marshal.typename(ident, e)}Marshaller = DjinniSupport.EnumMarshaller<${marshal.typename(ident, e)}>") + }) + } + + // return the base type if tm is optional otherwise None + private def optionalBase(tm: MExpr) : Option[MExpr] = { + tm.base match { + case MOptional => Some(tm.args.head) + case _ => None + } + } + + override def generateRecord(origin: String, ident: Ident, doc: Doc, params: Seq[TypeParam], r: Record) { + writeSwiftFile(ident, origin, List[String](), w => { + writeDoc(w, doc) + w.w(s"public struct ${marshal.typename(ident, r)}").braced { + for (f <- r.fields) { + writeDoc(w, f.doc) + w.wl(s"public var ${idSwift.field(f.ident)}: ${marshal.fieldType(f.ty)}") + } + val initParams = r.fields.map(f => s"${idSwift.field(f.ident)}: ${marshal.fieldType(f.ty)}").mkString(", ") + w.wl + w.wl(s"public init(${initParams})").braced { + for (f <- r.fields) { + w.wl(s"self.${idSwift.field(f.ident)} = ${idSwift.field(f.ident)}") + } + } + } + }) + writeSwiftPrivateFile(ident, origin, List[String]("DjinniSupport", spec.swiftxxBaseLibModule, spec.swiftModule), w => { + val t = marshal.typename(ident, r) + w.w(s"enum ${t}Marshaller: DjinniSupport.Marshaller").braced { + w.wl(s"typealias SwiftType = $t") + w.w("static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced { + w.wl("return withUnsafePointer(to: c) { p in").nested { + for ((f, i) <- r.fields.view.zipWithIndex) { + val swiftExp = s"djinni.swift.getMember(p, $i)" + w.wl(s"let ${idSwift.field(f.ident)} = ${marshal.fromCpp(f.ty, swiftExp)}") + } + val members = r.fields.map(f => s"${idSwift.field(f.ident)}: ${idSwift.field(f.ident)}").mkString(", ") + w.wl(s"return SwiftType(${members})") + } + w.wl("}") + } + w.w("static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced { + w.wl("var ret = djinni.swift.makeCompositeValue()") + for (f <- r.fields) { + val swiftExpr = s"s.${idSwift.field(f.ident)}" + w.wl(s"djinni.swift.addMember(&ret, ${marshal.toCpp(f.ty,swiftExpr )})") + } + w.wl("return ret") + } + } + }) + } + override def generateInterface(origin: String, ident: Ident, doc: Doc, typeParams: Seq[TypeParam], i: Interface) { + writeSwiftFile(ident, origin, List[String](), w => { + writeDoc(w, doc) + w.w(s"public protocol ${marshal.typename(ident, i)}: AnyObject").braced { + for (m <- i.methods.filter(!_.static)) { + writeMethodDoc(w, m, idSwift.local) + w.w(s"func ${idSwift.method(m.ident)}(") + w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.paramType(p.ty)}").mkString(", ")) + w.wl(s") -> ${marshal.returnType(m.ret)}") + } + } + }) + writeSwiftPrivateFile(ident, origin, List[String]("DjinniSupport", spec.swiftxxBaseLibModule, spec.swiftModule, spec.swiftModule + "Cxx"), w => { + writeDoc(w, doc) + // Define CppProxy class if interface is implemented in C++ + if (i.ext.cpp) { + w.w(s"final class CppProxy: DjinniSupport.CppProxy, ${marshal.typename(ident, i)}").braced { + for (m <- i.methods.filter(!_.static)) { + w.w(s"func ${idSwift.method(m.ident)}(") + w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.paramType(p.ty)}").mkString(", ")) + w.w(s") -> ${marshal.returnType(m.ret)}").braced { + w.wl("var params = djinni.swift.ParameterList()") + w.wl("params.addValue(inst)") + for (p <- m.params) { + w.wl(s"params.addValue(${marshal.toCpp(p.ty, p.ident)})") + } + val call = s"${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(¶ms)" + if (m.ret.isEmpty) { + w.wl(call) + } else { + w.wl(s"return ${marshal.fromCpp(m.ret.get, call)}") + } + } + } + } + } + // Define the vtbl for protocol wrapper if interface is implemented in Swift + val swiftProxyClassName = s"${marshal.typename(ident, i)}SwiftProxy" + val swiftProxyVtbl = s"${idSwift.local(ident)}Methods" + if (i.ext.swift) { + w.wl(s"let $swiftProxyVtbl: Vtbl<${marshal.typename(ident, i)}> = [").nested { + for (m <- i.methods.filter(!_.static)) { + w.wl("{ inst, params, ret in").nested { + for ((p, i) <- m.params.view.zipWithIndex) { + val pi = s"djinni.swift.getMember(params, $i)" + w.wl(s"let _${idSwift.local(p.ident)} = ${marshal.fromCpp(p.ty, pi)}") + } + val args = m.params.map(p => s"${idSwift.local(p.ident)}: _${idSwift.local(p.ident)}").mkString(", ") + val call = s"inst.${idSwift.method(m.ident)}(${args})" + if (m.ret.isEmpty) { + w.wl(call) + } else { + w.wl(s"djinni.swift.setReturnValue(ret, ${marshal.toCpp(m.ret.get, call)})") + } + } + w.wl("},") + } + } + w.wl("]") + w.wl + } + // Define the marshaller + w.w(s"enum ${marshal.typename(ident, i)}Marshaller: DjinniSupport.Marshaller").braced { + w.wl(s"typealias SwiftType = ${marshal.typename(ident, i)}") + w.w("static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced { + val newProxyBlock = if (i.ext.cpp) {"{ CppProxy(c) }"} else {"{ fatalError(\"n/a\") }"} + w.wl(s"return cppInterfaceToSwift(c, ${newProxyBlock})") + } + w.w("static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced { + val newProxyBlock = if (i.ext.swift) {s"{ ${spec.swiftxxNamespace}.$swiftProxyClassName.make(ctxPtr(s, ${swiftProxyVtbl}), dispatcherProtocalCall)}"} else {"{ fatalError(\"n/a\") }"} + w.wl(s"return swiftInterfaceToCpp(s, ${newProxyBlock})") + } + } + // Define static method stubs + val staticMethods = i.methods.filter(_.static) + if (!staticMethods.isEmpty) { + w.w(s"public class ${marshal.typename(ident, i)}_statics").braced { + for (m <- staticMethods) { + w.w(s"static func ${idSwift.method(m.ident)}(") + w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.paramType(p.ty)}").mkString(", ")) + w.w(s") -> ${marshal.returnType(m.ret)}").braced { + w.wl("var params = djinni.swift.ParameterList()") + for (p <- m.params) { + w.wl(s"params.addValue(${marshal.toCpp(p.ty, p.ident)})") + } + val call = s"${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(¶ms)" + if (m.ret.isEmpty) { + w.wl(call) + } else { + w.wl(s"return ${marshal.fromCpp(m.ret.get, call)}") + } + } + } + } + } + }) + } +} diff --git a/src/source/SwiftMarshal.scala b/src/source/SwiftMarshal.scala new file mode 100644 index 00000000..019f33e3 --- /dev/null +++ b/src/source/SwiftMarshal.scala @@ -0,0 +1,129 @@ +/** + * Copyright 2024 Snap, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package djinni + +import djinni.ast._ +import djinni.generatorTools._ +import djinni.meta._ + +class SwiftMarshal(spec: Spec) extends Marshal(spec) { + override def typename(tm: MExpr): String = toSwiftType(tm, None) + def typename(name: String, ty: TypeDef): String = idSwift.ty(name) + + override def fqTypename(tm: MExpr): String = toSwiftType(tm, None) + def fqTypename(name: String, ty: TypeDef): String = idSwift.ty(name) + + override def paramType(tm: MExpr): String = toSwiftType(tm, None) + override def fqParamType(tm: MExpr): String = toSwiftType(tm, None) + + override def returnType(ret: Option[TypeRef]): String = ret.fold("Void")(ty => toSwiftType(ty.resolved, None)) + override def fqReturnType(ret: Option[TypeRef]): String = ret.fold("Void")(ty => toSwiftType(ty.resolved, None)) + + override def fieldType(tm: MExpr): String = toSwiftType(tm, None) + override def fqFieldType(tm: MExpr): String = toSwiftType(tm, spec.javaPackage) + + override def toCpp(tm: MExpr, expr: String): String = s"${helperClass(tm)}.toCpp(${expr})" + override def fromCpp(tm: MExpr, expr: String): String = s"${helperClass(tm)}.fromCpp(${expr})" + + private def toSwiftType(tm: MExpr, packageName: Option[String]): String = { + def args(tm: MExpr) = if (tm.args.isEmpty) "" else tm.args.map(f(_)).mkString("<", ", ", ">") + def f(tm: MExpr): String = { + tm.base match { + case MOptional => + assert(tm.args.size == 1) + val arg = tm.args.head + arg.base match { + case MOptional => throw new AssertionError("nested optional?") + case m => s"Optional<${f(arg)}>" + } + // case e: MExtern => e.swift.typename + (if (e.ts.generic) args(tm) else "") + case e: MExtern => throw new AssertionError("TODO") + case p: MProtobuf => p.name + case o => + val base = o match { + case p: MPrimitive => swiftPrimitiveType(p) + case MString => "String" + case MDate => "Date" + case MBinary => "Data" + case MOptional => throw new AssertionError("optional should have been special cased") + case MList => "Array" + case MArray => "Array" + case MSet => "Set" + case MMap => "Dictionary" + case d: MDef => idSwift.ty(d.name) + case e: MExtern => throw new AssertionError("unreachable") + case e: MProtobuf => throw new AssertionError("unreachable") + case p: MParam => idSwift.typeParam(p.name) + case MVoid => "Void" + } + base + args(tm) + } + } + f(tm) + } + + private def swiftPrimitiveType(p: MPrimitive): String = p._idlName match { + case "bool" => "Bool" + case "i64" => "Int64" + case "i32" => "Int32" + case "i16" => "Int16" + case "i8" => "Int8" + case "float" => "Float" + case "double" => "Double" + case _ => throw new AssertionError("unknown primitive type") + } + + def helperClass(name: String) = idSwift.ty(name) + "Marshaller" // TODO: make naming configurable + private def helperClass(tm: MExpr): String = helperName(tm) + helperTemplates(tm) + def helperName(tm: MExpr): String = tm.base match { + case d: MDef => helperClass(d.name) + case e: MExtern => e.jni.translator // TODO: swift translator + case o => o match { + case p: MPrimitive => p.idlName match { + case "i8" => "I8Marshaller" + case "i16" => "I16Marshaller" + case "i32" => "I32Marshaller" + case "i64" => "I64Marshaller" + case "f32" => "F32Marshaller" + case "f64" => "F64Marshaller" + case "bool" => "BoolMarshaller" + } + case MOptional => "OptionalMarshaller" + case MBinary => "BinaryMarshaller" + case MString => "StringMarshaller" + case MDate => "DateMarshaller" + case MList => "ListMarshaller" + case MSet => "SetMarshaller" + case MMap => "MapMarshaller" + case MProtobuf(_,_,_) => "ProtobufMarshaller" + case MArray => "ArrayMarshaller" + case d: MDef => throw new AssertionError("unreachable") + case e: MExtern => throw new AssertionError("unreachable") + case p: MParam => throw new AssertionError("not applicable") + case MVoid => "VoidMarshaller" + } + } + private def helperTemplates(tm: MExpr): String = { + def f() = if(tm.args.isEmpty) "" else tm.args.map(helperClass).mkString("<", ", ", ">") + tm.base match { + case MOptional | MList | MSet | MArray => + assert(tm.args.size == 1) + f + case _ => f + } + } +} diff --git a/src/source/SwiftxxGenerator.scala b/src/source/SwiftxxGenerator.scala new file mode 100644 index 00000000..4df8e101 --- /dev/null +++ b/src/source/SwiftxxGenerator.scala @@ -0,0 +1,196 @@ +/** + * Copyright 2024 Snap, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package djinni + +import java.io._ +import djinni.ast.Record.DerivingType +import djinni.ast._ +import djinni.generatorTools._ +import djinni.meta._ +import djinni.writer.IndentWriter +import scala.collection.mutable.ListBuffer +import scala.collection.mutable.TreeSet +import java.util.regex.Pattern +import java.util.regex.Matcher +import scala.collection.mutable + +class SwiftxxGenerator(spec: Spec) extends Generator(spec) { + val cppMarshal = new CppMarshal(spec) + val marshal = new SwiftxxMarshal(spec) + + class SwiftRefs(name: String) { + var swiftHpp = mutable.TreeSet[String]() + var swiftCpp = mutable.TreeSet[String]() + swiftHpp.add("#include " + q(spec.cppFileIdentStyle(name) + "." + spec.cppHeaderExt)) + swiftHpp.add("#include " + q("djinni_support.hpp")) + spec.cppNnHeader match { + case Some(nnHdr) => swiftHpp.add("#include " + nnHdr) + case _ => + } + + def find(ty: TypeRef) { find(ty.resolved) } + def find(tm: MExpr) { + tm.args.foreach(find) + find(tm.base) + } + def find(m: Meta) = for(r <- marshal.references(m, name)) r match { + case ImportRef(arg) => swiftCpp.add("#include " + arg) + case _ => + } + } + + val writeSwiftCppFile = writeCppFileGeneric(spec.swiftxxOutFolder.get, spec.swiftxxNamespace, spec.swiftxxFileIdentStyle, "") _ + def writeSwiftHppFile(name: String, origin: String, includes: Iterable[String], fwds: Iterable[String], f: IndentWriter => Unit, f2: IndentWriter => Unit = (w => {})) = + writeHppFileGeneric(spec.swiftxxOutFolder.get, spec.swiftxxNamespace, spec.swiftxxFileIdentStyle)(name, origin, includes, fwds, f, f2) + + override def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum) { + val refs = new SwiftRefs(ident.name) + writeSwiftHppFile(ident, origin, refs.swiftHpp, Nil, w => { + w.wl(s"using ${spec.swiftxxClassIdentStyle(ident)} = djinni::swift::Enum<${cppMarshal.fqTypename(ident, e)}>;") + }) + writeSwiftCppFile(ident, origin, List[String](), w => {}) + } + + override def generateRecord(origin: String, ident: Ident, doc: Doc, params: Seq[TypeParam], r: Record) { + val refs = new SwiftRefs(ident.name) + r.fields.foreach(f => refs.find(f.ty)) + val helper = marshal.helperClass(ident) + writeSwiftHppFile(ident, origin, refs.swiftHpp, Nil, w => { + w.w(s"struct $helper").bracedEnd(";") { + w.wl(s"using CppType = ${cppMarshal.fqTypename(ident, r)};") + w.wl(s"static djinni::swift::AnyValue fromCpp(const CppType& c);") + w.wl(s"static CppType toCpp(const djinni::swift::AnyValue& s);") + } + }) + writeSwiftCppFile(ident, origin, refs.swiftCpp, w => { + w.w(s"djinni::swift::AnyValue ${helper}::fromCpp(const ${cppMarshal.fqTypename(ident, r)}& c)").braced { + w.wl("auto ret = std::make_shared();") + for (f <- r.fields) { + val member = s"c.${idCpp.field(f.ident)}" + w.wl(s"ret->addValue(${marshal.fromCpp(f.ty, member)});") + } + w.wl("return {ret};") + } + w.w(s"${cppMarshal.fqTypename(ident, r)} ${helper}::toCpp(const djinni::swift::AnyValue& s)").braced { + w.wl("auto p = std::get(s);") + val members = r.fields.view.zipWithIndex.map{case (f, i) => { + val expr = s"p->getValue($i)" + s"${marshal.toCpp(f.ty, expr)}" + }}.mkString(", ") + w.wl(s"return ${cppMarshal.fqTypename(ident, r)}($members);") + } + }) + } + override def generateInterface(origin: String, ident: Ident, doc: Doc, typeParams: Seq[TypeParam], i: Interface) { + val refs = new SwiftRefs(ident.name) + i.methods.foreach(m => { + m.params.foreach(p => refs.find(p.ty)) + m.ret.foreach(refs.find) + }) + i.consts.foreach(c => { + refs.find(c.ty) + }) + val helper = marshal.helperClass(ident) + val proxy = idSwift.ty(ident) + "SwiftProxy" + writeSwiftHppFile(ident, origin, refs.swiftHpp, Nil, w => { + w.wl(s"using ${spec.swiftxxClassIdentStyle(ident)} = djinni::swift::Interface<${cppMarshal.fqTypename(ident, i)}>;") + if (i.ext.cpp) { + w.wl + i.methods.foreach(m => { + if (m.static || m.lang.swift) { + w.wl(s"djinni::swift::AnyValue ${idSwift.ty(ident)}_${idSwift.method(m.ident)}(const djinni::swift::ParameterList* params);") + } + }) + } + if (i.ext.swift) { + w.wl + w.w(s"class $proxy: public ${cppMarshal.fqTypename(ident, i)}, public djinni::swift::ProtocolWrapper").bracedEnd(";") { + w.wlOutdent("public:") + w.wl(s"$proxy(void* instance, djinni::swift::DispatchFunc dispatcher): ProtocolWrapper(instance, dispatcher) {}") + w.wl("static djinni::swift::AnyValue make(void* instance, djinni::swift::DispatchFunc dispatcher);") + i.methods.foreach(m => { + val ret = cppMarshal.fqReturnType(m.ret) + val params = m.params.map(p => cppMarshal.fqParamType(p.ty) + " " + idCpp.local(p.ident)) + if (!m.static) { + val constFlag = if (m.const) " const" else "" + w.wl(s"$ret ${idCpp.method(m.ident)}${params.mkString("(", ", ", ")")}$constFlag override;") + } + }) + } + } + }) + writeSwiftCppFile(ident, origin, refs.swiftCpp, w => { + if (i.ext.cpp) { + i.methods.foreach(m => { + if (m.static || m.lang.swift) { + w.w(s"djinni::swift::AnyValue ${idSwift.ty(ident)}_${idSwift.method(m.ident)}(const djinni::swift::ParameterList* params)").braced { + // get self + if (!m.static) { + w.wl(s"auto inst = ${marshal.helperClass(ident)}::toCpp(params->getValue(0));") + } + // get args + val iOffset = if (m.static) 0 else 1 + for ((p, i) <- m.params.view.zipWithIndex) { + val pi = s"params->getValue(${i + iOffset})" + w.wl(s"auto _${idCpp.local(p.ident)} = ${marshal.toCpp(p.ty, pi)};") + } + // make the call + if (!m.ret.isEmpty) { + w.w("auto ret = ") + } + if (m.static) { + w.w(s"${cppMarshal.fqTypename(ident, i)}::") + } else { + w.w("inst->") + } + val args = m.params.map(p => s"_${idCpp.local(p.ident)}").mkString(", ") + w.wl(s"${idCpp.method(m.ident)}($args);") + // return + if (m.ret.isEmpty) { + w.wl("return djinni::swift::makeVoidValue();") + } else { + w.wl("return " + marshal.fromCpp(m.ret.get, "ret") + ";") + } + } + } + }) + } + if (i.ext.swift) { + w.w(s"djinni::swift::AnyValue ${proxy}::make(void* instance, djinni::swift::DispatchFunc dispatcher)").braced { + w.wl(s"return {std::make_shared<$proxy>(instance, dispatcher)};") + } + for ((m, idx) <- i.methods.filter(!_.static).view.zipWithIndex) { + val ret = cppMarshal.fqReturnType(m.ret) + val params = m.params.map(p => cppMarshal.fqParamType(p.ty) + " " + idCpp.local(p.ident)) + val constFlag = if (m.const) " const" else "" + w.w(s"$ret $proxy::${idCpp.method(m.ident)}${params.mkString("(", ", ", ")")}$constFlag").braced { + w.wl("djinni::swift::ParameterList params;") + for (p <- m.params) { + w.wl(s"params.addValue(${marshal.fromCpp(p.ty, idCpp.local(p.ident))});") + } + val call = s"callProtocol($idx, ¶ms)" + if (m.ret.isEmpty) { + w.wl(call + ";") + } else { + w.wl("return " + marshal.toCpp(m.ret.get, call) + ";") + } + } + } + } + }) + } +} diff --git a/src/source/SwiftxxMarshal.scala b/src/source/SwiftxxMarshal.scala new file mode 100644 index 00000000..bad85226 --- /dev/null +++ b/src/source/SwiftxxMarshal.scala @@ -0,0 +1,98 @@ +/** + * Copyright 2024 Snap, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package djinni + +import djinni.ast._ +import djinni.generatorTools._ +import djinni.meta._ + +class SwiftxxMarshal(spec: Spec) extends Marshal(spec) { + + override def typename(tm: MExpr): String = throw new AssertionError("not applicable") + def typename(name: String, ty: TypeDef): String = throw new AssertionError("not applicable") + + override def fqTypename(tm: MExpr): String = throw new AssertionError("not applicable") + def fqTypename(name: String, ty: TypeDef): String = throw new AssertionError("not applicable") + + override def paramType(tm: MExpr): String = throw new AssertionError("not applicable") + override def fqParamType(tm: MExpr): String = throw new AssertionError("not applicable") + + override def returnType(ret: Option[TypeRef]): String = throw new AssertionError("not applicable") + override def fqReturnType(ret: Option[TypeRef]): String = throw new AssertionError("not applicable") + + override def fieldType(tm: MExpr): String = throw new AssertionError("not applicable") + override def fqFieldType(tm: MExpr): String = throw new AssertionError("not applicable") + + override def toCpp(tm: MExpr, expr: String): String = s"${helperClass(tm)}::toCpp(${expr})" + override def fromCpp(tm: MExpr, expr: String): String = s"${helperClass(tm)}::fromCpp(${expr})" + + def references(m: Meta, exclude: String = ""): Seq[SymbolReference] = m match { + case p: MProtobuf => { + List() + // val headers = List() + // p.body.java.jniHeader match { + // case Some(serialzerHeader) => ImportRef(serialzerHeader) :: headers + // case _ => headers + // } + } + case d: MDef => List(ImportRef(include(d.name))) + case e: MExtern => List() + case _ => List() + } + + def include(ident: String) = q(spec.swiftxxFileIdentStyle(ident) + "." + spec.cppHeaderExt) + + def helperClass(name: String) = spec.swiftxxClassIdentStyle(name) + private def helperClass(tm: MExpr): String = helperName(tm) + helperTemplates(tm) + def helperName(tm: MExpr): String = tm.base match { + case d: MDef => withNs(Some(spec.swiftxxNamespace), helperClass(d.name)) + case e: MExtern => e.jni.translator // TODO: swift translator + case o => withNs(Some("djinni::swift"), o match { + case p: MPrimitive => p.idlName match { + case "i8" => "I8" + case "i16" => "I16" + case "i32" => "I32" + case "i64" => "I64" + case "f32" => "F32" + case "f64" => "F64" + case "bool" => "Bool" + } + case MOptional => "Optional" + case MBinary => "Binary" + case MString => "String" + case MDate => "Date" + case MList => "List" + case MSet => "Set" + case MMap => "Map" + case MProtobuf(_,_,_) => "Protobuf" + case MArray => "Array" + case d: MDef => throw new AssertionError("unreachable") + case e: MExtern => throw new AssertionError("unreachable") + case p: MParam => throw new AssertionError("not applicable") + case MVoid => "Void" + }) + } + private def helperTemplates(tm: MExpr): String = { + def f() = if(tm.args.isEmpty) "" else tm.args.map(helperClass).mkString("<", ", ", ">") + tm.base match { + case MOptional | MList | MSet | MArray => + assert(tm.args.size == 1) + f + case _ => f + } + } +} diff --git a/src/source/ast.scala b/src/source/ast.scala index 62e3d699..ab186c07 100644 --- a/src/source/ast.scala +++ b/src/source/ast.scala @@ -52,9 +52,9 @@ case class ExternTypeDecl(override val ident: Ident, override val params: Seq[Ty case class ProtobufTypeDecl(override val ident: Ident, override val params: Seq[TypeParam], override val body: TypeDef, override val origin: String) extends TypeDecl // `Ext.js` is shared by both wasm and composer -case class Ext(java: Boolean, cpp: Boolean, objc: Boolean, js: Boolean) { +case class Ext(java: Boolean, cpp: Boolean, objc: Boolean, js: Boolean, swift: Boolean) { def any(): Boolean = { - java || cpp || objc || js + java || cpp || objc || js || swift } } diff --git a/src/source/generator.scala b/src/source/generator.scala index e7b01dd4..aa33df5a 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -113,6 +113,14 @@ package object generatorTools { composerClassIdentStyle: IdentConverter, composerFileIdentStyle: IdentConverter, composerTsOutFolder: Option[File], + swiftOutFolder: Option[File], + swiftIdentStyle: SwiftIdentStyle, + swiftModule: String, + swiftxxOutFolder: Option[File], + swiftxxNamespace: String, + swiftxxBaseLibModule: String, + swiftxxClassIdentStyle: IdentConverter, + swiftxxFileIdentStyle: IdentConverter, outFileListWriter: Option[Writer], skipGeneration: Boolean, yamlOutFolder: Option[File], @@ -161,6 +169,9 @@ package object generatorTools { case class JsIdentStyle(ty: IdentConverter, typeParam: IdentConverter, method: IdentConverter, field: IdentConverter, local: IdentConverter, enum: IdentConverter, const: IdentConverter) + case class SwiftIdentStyle(ty: IdentConverter, typeParam: IdentConverter, + method: IdentConverter, field: IdentConverter, local: IdentConverter, + enum: IdentConverter, const: IdentConverter) object IdentStyle { private val camelUpperStrict = (s: String) => { @@ -187,6 +198,7 @@ package object generatorTools { val cppDefault = CppIdentStyle(camelUpper, camelUpper, camelUpper, underLower, underLower, underLower, underCaps, underCaps) val objcDefault = ObjcIdentStyle(camelUpper, camelUpper, camelLower, camelLower, camelLower, camelUpper, camelUpper) val jsDefault = JsIdentStyle(camelUpper, camelUpper, camelLower, camelLower, camelLower, underCaps, underCaps) + val swiftDefault = SwiftIdentStyle(camelUpper, camelUpper, camelLower, camelLower, camelLower, underCaps, underCaps) val styles = Map( "FooBar" -> camelUpper, @@ -321,6 +333,18 @@ package object generatorTools { } new TsGenerator(spec, true).generate(idl) } + if (spec.swiftOutFolder.isDefined) { + if (!spec.skipGeneration) { + createFolder("Swift", spec.swiftOutFolder.get) + } + new SwiftGenerator(spec).generate(idl) + } + if (spec.swiftxxOutFolder.isDefined) { + if (!spec.skipGeneration) { + createFolder("Swift/C++ interop", spec.swiftxxOutFolder.get) + } + new SwiftxxGenerator(spec).generate(idl) + } if (spec.yamlOutFolder.isDefined) { if (!spec.skipGeneration) { createFolder("YAML", spec.yamlOutFolder.get) @@ -381,6 +405,7 @@ abstract class Generator(spec: Spec) val idJava = spec.javaIdentStyle val idObjc = spec.objcIdentStyle val idJs = spec.jsIdentStyle + val idSwift = spec.swiftIdentStyle def wrapNamespace(w: IndentWriter, ns: String, f: IndentWriter => Unit) { ns match { @@ -495,35 +520,35 @@ abstract class Generator(spec: Spec) def normalEnumOptions(e: Enum) = e.options.filter(_.specialFlag == None) - def writeEnumOptionNone(w: IndentWriter, e: Enum, ident: IdentConverter, delim: String = "=") { + def writeEnumOptionNone(w: IndentWriter, e: Enum, ident: IdentConverter, delim: String = "=", prefix: String = "", lineEnd: String = ",") { for (o <- e.options.find(_.specialFlag == Some(Enum.SpecialFlag.NoFlags))) { writeDoc(w, o.doc) - w.wl(ident(o.ident.name) + s" $delim 0,") + w.wl(prefix + ident(o.ident.name) + s" $delim 0$lineEnd") } } - def writeEnumOptions(w: IndentWriter, e: Enum, ident: IdentConverter, delim: String = "=") { + def writeEnumOptions(w: IndentWriter, e: Enum, ident: IdentConverter, delim: String = "=", prefix: String = "", lineEnd: String = ",") { var shift = 0 for (o <- normalEnumOptions(e)) { writeDoc(w, o.doc) - w.wl(ident(o.ident.name) + (if(e.flags) s" $delim 1 << $shift" else s" $delim $shift") + ",") + w.wl(prefix + ident(o.ident.name) + (if(e.flags) s" $delim 1 << $shift" else s" $delim $shift") + lineEnd) shift += 1 } } - def writeEnumOptionAll(w: IndentWriter, e: Enum, ident: IdentConverter, delim: String = "=") { + def writeEnumOptionAll(w: IndentWriter, e: Enum, ident: IdentConverter, delim: String = "=", prefix: String = "", lineEnd: String = ",") { for ( o <- e.options.find(_.specialFlag.contains(Enum.SpecialFlag.AllFlags)) ) { writeDoc(w, o.doc) - w.w(ident(o.ident.name) + s" $delim ") + w.w(prefix + ident(o.ident.name) + s" $delim ") w.w( normalEnumOptions(e) .zipWithIndex .map{case(o, i) => s"(1 << $i)"} .fold("0")((acc, o) => acc + " | " + o) ) - w.wl(",") + w.wl(lineEnd) } } diff --git a/src/source/parser.scala b/src/source/parser.scala index 9be204cb..d5ce84e9 100644 --- a/src/source/parser.scala +++ b/src/source/parser.scala @@ -86,18 +86,25 @@ private object IdlParser extends RegexParsers { } def ext(default: Ext) = (rep1("+" ~> ident) >> checkExts) | success(default) - def extRecord = ext(Ext(false, false, false, false)) - def extInterface = ext(Ext(true, true, true, true)) - def supportLang = ext(Ext(true, true, true, true)) + def extRecord = ext(Ext(false, false, false, false, false)) + def extInterface = ext(Ext(true, true, true, true, true)) + def supportLang = ext(Ext(true, true, true, true, true)) def checkExts(parts: List[Ident]): Parser[Ext] = { var foundCpp = false var foundJava = false var foundObjc = false var foundJavascript = false + var foundSwift = false for (part <- parts) part.name match { + case "nc" => { + foundJava = true + foundObjc = true + foundJavascript = true + foundSwift = true + } case "c" => { if (foundCpp) return err("Found multiple \"c\" modifiers.") foundCpp = true @@ -119,9 +126,13 @@ private object IdlParser extends RegexParsers { if (foundJavascript) return err("Found multiple \"js\" modifiers.") foundJavascript = true } + case "sw" => { + if (foundSwift) return err("Found multiple \"sw\" modifiers.") + foundSwift = true + } case _ => return err("Invalid modifier \"" + part.name + "\"") } - success(Ext(foundJava, foundCpp, foundObjc, foundJavascript)) + success(Ext(foundJava, foundCpp, foundObjc, foundJavascript, foundSwift)) } def typeDef: Parser[TypeDef] = record | enum | flags | interface diff --git a/support-lib/BUILD b/support-lib/BUILD index 36053ede..6e477e8a 100644 --- a/support-lib/BUILD +++ b/support-lib/BUILD @@ -7,7 +7,6 @@ cc_library( srcs = glob(["cpp/*.cpp"]), hdrs = glob(["*.hpp", "cpp/*.hpp"]), includes = ["cpp"], - tags = ["swift_module"], visibility = ["//visibility:public"], ) @@ -114,6 +113,6 @@ cc_library( copts = [ "-std=c++17", ], - tags = ["swift_module"], + tags = ["swift_module=DjinniSupportCxx"], visibility = ["//visibility:public"], ) diff --git a/support-lib/swift/DjinniSupport.swift b/support-lib/swift/DjinniSupport.swift index 10a5d2a6..2bdecdc1 100644 --- a/support-lib/swift/DjinniSupport.swift +++ b/support-lib/swift/DjinniSupport.swift @@ -1,4 +1,4 @@ -import support_lib_djinni_support_swiftxx +import DjinniSupportCxx public typealias Vtbl = [(T, UnsafePointer?, UnsafeMutablePointer?) -> Void] @@ -122,7 +122,7 @@ class SwiftProxyCache { // 2. object is a an existing swift proxy: unwrap the original swift object // 3. need to create a new proxy : call newProxyFunc public func cppInterfaceToSwift(_ c: djinni.swift.AnyValue, - _ newProxyFunc: (djinni.swift.AnyValue)->I) -> I { + _ newProxyFunc: ()->I) -> I { return withUnsafePointer(to: c) { p in let info = djinni.swift.getInterfaceInfo(p) // for 1. check the cpp proxy cache @@ -135,7 +135,7 @@ public func cppInterfaceToSwift(_ c: djinni.swift.AnyValue, return ctx.getInst() as! I } // 3. - let newProxy = newProxyFunc(c) + let newProxy = newProxyFunc() CppProxyCache.shared.mapPtrToProxy[info.cppPointer] = Unmanaged.passUnretained(newProxy as AnyObject).toOpaque() return newProxy } @@ -145,7 +145,7 @@ public func cppInterfaceToSwift(_ c: djinni.swift.AnyValue, // 2. object is a an existing swift proxy: return existing // 3. need to create a new proxy : call newProxyFunc public func swiftInterfaceToCpp(_ s: I, - _ newProxyFunc: (I)->djinni.swift.AnyValue) -> djinni.swift.AnyValue { + _ newProxyFunc: ()->djinni.swift.AnyValue) -> djinni.swift.AnyValue { // 1. try cast to CppProxy and unwrap if let cppproxy = s as? CppProxy { return cppproxy.inst @@ -156,11 +156,16 @@ public func swiftInterfaceToCpp(_ s: I, return djinni.swift.strongify(weakProxy) } // 3. - let newProxy = newProxyFunc(s) + let newProxy = newProxyFunc() SwiftProxyCache.shared.mapPtrToProxy[key] = djinni.swift.weakify(newProxy) return newProxy } +public func ctxPtr (_ s: I, _ vtbl: Vtbl) -> UnsafeMutableRawPointer { + let ctx = ProtocolWrapperContext(inst: s, vtbl: vtbl) + return Unmanaged.passRetained(ctx).toOpaque() +} + public func destroyCppProxy(_ inst: djinni.swift.AnyValue) { withUnsafePointer(to: inst) { p in let info = djinni.swift.getInterfaceInfo(p) diff --git a/support-lib/swiftxx/djinni_support.hpp b/support-lib/swiftxx/djinni_support.hpp index 5f11161e..d24d5ddb 100644 --- a/support-lib/swiftxx/djinni_support.hpp +++ b/support-lib/swiftxx/djinni_support.hpp @@ -150,18 +150,4 @@ struct Interface { } }; -// // Keeps track of C++ objects in Swift -// class CppProxyCache { -// static CppProxyCache& instance(); -// std::unordered_map _mapPtrToProxy; -// public: -// }; - -// // Keeps track of Swift objects in C++ -// class SwiftProxyCache { -// static SwiftProxyCache& instance(); -// std::unordered_map _mapPtrToProxy; -// public: -// }; - } diff --git a/test-suite/BUILD b/test-suite/BUILD index ca17f02c..83726ee3 100644 --- a/test-suite/BUILD +++ b/test-suite/BUILD @@ -28,7 +28,6 @@ cc_library( "//support-lib:djinni-support-common", "@com_google_protobuf//:protobuf" ], - tags = ["swift_module"], linkstatic = True, alwayslink = 1, ) From cf0fb530e09307fac6f4a6edf6bf5bd7800d978f Mon Sep 17 00:00:00 2001 From: Li Feng Date: Tue, 4 Jun 2024 11:19:06 +1000 Subject: [PATCH 18/68] +nc --- examples/example.djinni | 2 +- .../generated-src/swift/TextboxListener+Private.swift | 9 ++++++++- examples/generated-src/swiftxx/SwiftTextboxListener.cpp | 8 ++++++++ examples/generated-src/swiftxx/SwiftTextboxListener.hpp | 7 +++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/examples/example.djinni b/examples/example.djinni index 4c13eeac..6a013909 100755 --- a/examples/example.djinni +++ b/examples/example.djinni @@ -17,6 +17,6 @@ sort_items = interface +c { static run_sort(items: item_list): item_list; } -textbox_listener = interface +j +o +w { +textbox_listener = interface +nc { update(items: item_list); } diff --git a/examples/generated-src/swift/TextboxListener+Private.swift b/examples/generated-src/swift/TextboxListener+Private.swift index 1c6f8aa8..c0259d68 100644 --- a/examples/generated-src/swift/TextboxListener+Private.swift +++ b/examples/generated-src/swift/TextboxListener+Private.swift @@ -6,12 +6,19 @@ import DjinniSupportCxx import TextSort import TextSortCxx +let textboxListenerMethods: Vtbl = [ + { inst, params, ret in + let _items = ItemListMarshaller.fromCpp(djinni.swift.getMember(params, 0)) + inst.update(items: _items) + }, +] + enum TextboxListenerMarshaller: DjinniSupport.Marshaller { typealias SwiftType = TextboxListener static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { fatalError("n/a") }) } static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - return swiftInterfaceToCpp(s, { fatalError("n/a") }) + return swiftInterfaceToCpp(s, { djinni_generated.TextboxListenerSwiftProxy.make(ctxPtr(s, textboxListenerMethods), dispatcherProtocalCall)}) } } diff --git a/examples/generated-src/swiftxx/SwiftTextboxListener.cpp b/examples/generated-src/swiftxx/SwiftTextboxListener.cpp index 86639863..838a99ef 100644 --- a/examples/generated-src/swiftxx/SwiftTextboxListener.cpp +++ b/examples/generated-src/swiftxx/SwiftTextboxListener.cpp @@ -6,5 +6,13 @@ namespace djinni_generated { +djinni::swift::AnyValue TextboxListenerSwiftProxy::make(void* instance, djinni::swift::DispatchFunc dispatcher) { + return {std::make_shared(instance, dispatcher)}; +} +void TextboxListenerSwiftProxy::update(const ::textsort::ItemList & items) { + djinni::swift::ParameterList params; + params.addValue(::djinni_generated::SwiftItemList::fromCpp(items)); + callProtocol(0, ¶ms); +} } // namespace djinni_generated diff --git a/examples/generated-src/swiftxx/SwiftTextboxListener.hpp b/examples/generated-src/swiftxx/SwiftTextboxListener.hpp index 63d7822e..2c731585 100644 --- a/examples/generated-src/swiftxx/SwiftTextboxListener.hpp +++ b/examples/generated-src/swiftxx/SwiftTextboxListener.hpp @@ -10,4 +10,11 @@ namespace djinni_generated { using SwiftTextboxListener = djinni::swift::Interface<::textsort::TextboxListener>; +class TextboxListenerSwiftProxy: public ::textsort::TextboxListener, public djinni::swift::ProtocolWrapper { +public: + TextboxListenerSwiftProxy(void* instance, djinni::swift::DispatchFunc dispatcher): ProtocolWrapper(instance, dispatcher) {} + static djinni::swift::AnyValue make(void* instance, djinni::swift::DispatchFunc dispatcher); + void update(const ::textsort::ItemList & items) override; +}; + } // namespace djinni_generated From 9972b74a3fa0686a75739972fd156d1af84d4507 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 14 Jun 2024 13:27:38 +1000 Subject: [PATCH 19/68] wip --- examples/BUILD | 4 +- src/source/JavaMarshal.scala | 2 +- src/source/SwiftGenerator.scala | 120 +++++++++--- src/source/SwiftMarshal.scala | 19 +- src/source/SwiftxxGenerator.scala | 2 +- src/source/SwiftxxMarshal.scala | 23 +-- src/source/YamlGenerator.scala | 20 +- src/source/meta.scala | 12 +- support-lib/dataref.yaml | 4 + support-lib/dataview.yaml | 4 + support-lib/future.yaml | 8 + support-lib/jni/Future_jni.hpp | 2 +- support-lib/outcome.yaml | 3 + support-lib/swift/DjinniSupport.swift | 171 +++++++++++++++++- support-lib/swiftxx/Future_swift.hpp | 25 +++ support-lib/swiftxx/djinni_support.cpp | 13 ++ support-lib/swiftxx/djinni_support.hpp | 146 +++++++++++++-- test-suite/BUILD | 74 +++++++- test-suite/djinni/all.djinni | 9 - test-suite/djinni/common.djinni | 1 + test-suite/djinni/test.djinni | 12 +- .../djinni/vendor/third-party/date.yaml | 3 + .../handwritten-src/swift/AllTests.swift | 2 +- test-suite/run_djinni.sh | 10 + 24 files changed, 610 insertions(+), 79 deletions(-) create mode 100644 support-lib/swiftxx/Future_swift.hpp diff --git a/examples/BUILD b/examples/BUILD index 4ab33436..b28dc7f6 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -125,8 +125,8 @@ swift_library( ) swift_library( - name = "textsort-swiftimp", - module_name = "TextSortImp", + name = "textsort-swift-bridge", + module_name = "TextSortBridge", srcs = glob([swift_private_files,]), copts = [ "-cxx-interoperability-mode=default", diff --git a/src/source/JavaMarshal.scala b/src/source/JavaMarshal.scala index bc9aff0c..49a7bc2d 100644 --- a/src/source/JavaMarshal.scala +++ b/src/source/JavaMarshal.scala @@ -89,7 +89,7 @@ class JavaMarshal(spec: Spec) extends Marshal(spec) { def isEnumFlags(m: Meta): Boolean = m match { case MDef(_, _, _, Enum(_, true)) => true - case MExtern(_, _, _, Enum(_, true), _, _, _, _, _,_,_,_) => true + case MExtern(_, _, _, Enum(_, true), _, _, _, _, _,_,_,_,_,_) => true case _ => false } def isEnumFlags(tm: MExpr): Boolean = tm.base match { diff --git a/src/source/SwiftGenerator.scala b/src/source/SwiftGenerator.scala index 1582d7ab..c0386004 100644 --- a/src/source/SwiftGenerator.scala +++ b/src/source/SwiftGenerator.scala @@ -26,6 +26,7 @@ import scala.collection.mutable.ListBuffer import scala.collection.mutable.TreeSet import java.util.regex.Pattern import java.util.regex.Matcher +import scala.collection.mutable class SwiftGenerator(spec: Spec) extends Generator(spec) { @@ -36,6 +37,10 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { w.wl("// AUTOGENERATED FILE - DO NOT MODIFY!") w.wl("// This file was generated by Djinni from " + origin) w.wl + if (refs.nonEmpty) { + refs.foreach(s => w.wl(s"import $s")) + w.wl + } f(w) }) } @@ -52,12 +57,47 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { }) } + def writeFlagNone(w: IndentWriter, e: Enum, ident: IdentConverter, t: String) { + for (o <- e.options.find(_.specialFlag == Some(Enum.SpecialFlag.NoFlags))) { + writeDoc(w, o.doc) + w.wl(s"public static let ${ident(o.ident.name)}: $t = []") + } + } + def writeFlags(w: IndentWriter, e: Enum, ident: IdentConverter, t: String) { + var shift = 0 + for (o <- normalEnumOptions(e)) { + writeDoc(w, o.doc) + w.wl(s"public static let ${ident(o.ident.name)} = $t(rawValue: 1 << $shift)") + shift += 1 + } + } + def writeFlagAll(w: IndentWriter, e: Enum, ident: IdentConverter, t: String) { + for ( + o <- e.options.find(_.specialFlag.contains(Enum.SpecialFlag.AllFlags)) + ) { + writeDoc(w, o.doc) + val all = normalEnumOptions(e) + .map{case o => "."+ident(o.ident.name)} + .mkString(", ") + w.w(s"public static let ${ident(o.ident.name)}: $t = [${all}]") + } + } + override def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum) { writeSwiftFile(ident, origin, List[String](), w => { - w.w(s"public enum ${marshal.typename(ident, e)}: Int32").braced { - writeEnumOptionNone(w, e, idSwift.enum, "=", "case ", "") - writeEnumOptions(w, e, idSwift.enum, "=", "case ", "") - writeEnumOptionAll(w, e, idSwift.enum, "=", "case ", "") + val t = marshal.typename(ident, e) + if (e.flags) { + w.w(s"public struct $t: OptionSet").braced { + w.wl("public let rawValue: Int32") + w.wl("public init(rawValue: Int32) { self.rawValue = rawValue }") + writeFlagNone(w, e, idSwift.enum, t) + writeFlags(w, e, idSwift.enum, t) + writeFlagAll(w, e, idSwift.enum, t) + } + } else { + w.w(s"public enum ${marshal.typename(ident, e)}: Int32").braced { + writeEnumOptions(w, e, idSwift.enum, "=", "case ", "") + } } }) writeSwiftPrivateFile(ident, origin, List[String]("DjinniSupport", spec.swiftModule), w => { @@ -73,8 +113,34 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { } } + private def swiftMethodName(ident: String) = { + val reservedNames = Array("init", "deinit") + val name = idSwift.method(ident) + if (reservedNames.contains(name)) { + "_" + name + } else { + name + } + } + + class SwiftRefs(name: String) { + var swiftImports = mutable.TreeSet[String]() + swiftImports.add("Foundation") + def find(ty: TypeRef) { find(ty.resolved) } + def find(tm: MExpr) { + tm.args.foreach(find) + find(tm.base) + } + def find(m: Meta) = for(r <- marshal.references(m, name)) r match { + case ImportRef(arg) => swiftImports.add(arg) + case _ => + } + } + override def generateRecord(origin: String, ident: Ident, doc: Doc, params: Seq[TypeParam], r: Record) { - writeSwiftFile(ident, origin, List[String](), w => { + val refs = new SwiftRefs(ident.name) + r.fields.foreach(f => refs.find(f.ty)) + writeSwiftFile(ident, origin, refs.swiftImports, w => { writeDoc(w, doc) w.w(s"public struct ${marshal.typename(ident, r)}").braced { for (f <- r.fields) { @@ -90,7 +156,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { } } }) - writeSwiftPrivateFile(ident, origin, List[String]("DjinniSupport", spec.swiftxxBaseLibModule, spec.swiftModule), w => { + writeSwiftPrivateFile(ident, origin, List[String]("DjinniSupport", "Foundation", spec.swiftxxBaseLibModule, spec.swiftModule), w => { val t = marshal.typename(ident, r) w.w(s"enum ${t}Marshaller: DjinniSupport.Marshaller").braced { w.wl(s"typealias SwiftType = $t") @@ -106,41 +172,53 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { w.wl("}") } w.w("static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced { - w.wl("var ret = djinni.swift.makeCompositeValue()") - for (f <- r.fields) { - val swiftExpr = s"s.${idSwift.field(f.ident)}" - w.wl(s"djinni.swift.addMember(&ret, ${marshal.toCpp(f.ty,swiftExpr )})") + if (r.fields.nonEmpty) { + w.wl("var ret = djinni.swift.makeCompositeValue()") + for (f <- r.fields) { + val swiftExpr = s"s.${idSwift.field(f.ident)}" + w.wl(s"djinni.swift.addMember(&ret, ${marshal.toCpp(f.ty,swiftExpr )})") + } + w.wl("return ret") + } else { + w.wl("return djinni.swift.makeCompositeValue()") } - w.wl("return ret") } } }) } override def generateInterface(origin: String, ident: Ident, doc: Doc, typeParams: Seq[TypeParam], i: Interface) { - writeSwiftFile(ident, origin, List[String](), w => { + val refs = new SwiftRefs(ident.name) + i.methods.foreach(m => { + m.params.foreach(p => refs.find(p.ty)) + m.ret.foreach(refs.find) + }) + i.consts.foreach(c => { + refs.find(c.ty) + }) + writeSwiftFile(ident, origin, refs.swiftImports, w => { writeDoc(w, doc) w.w(s"public protocol ${marshal.typename(ident, i)}: AnyObject").braced { for (m <- i.methods.filter(!_.static)) { writeMethodDoc(w, m, idSwift.local) - w.w(s"func ${idSwift.method(m.ident)}(") + w.w(s"func ${swiftMethodName(m.ident)}(") w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.paramType(p.ty)}").mkString(", ")) w.wl(s") -> ${marshal.returnType(m.ret)}") } } }) - writeSwiftPrivateFile(ident, origin, List[String]("DjinniSupport", spec.swiftxxBaseLibModule, spec.swiftModule, spec.swiftModule + "Cxx"), w => { + writeSwiftPrivateFile(ident, origin, List[String]("DjinniSupport", "Foundation",spec.swiftxxBaseLibModule, spec.swiftModule, spec.swiftModule + "Cxx"), w => { writeDoc(w, doc) // Define CppProxy class if interface is implemented in C++ if (i.ext.cpp) { - w.w(s"final class CppProxy: DjinniSupport.CppProxy, ${marshal.typename(ident, i)}").braced { + w.w(s"final class ${marshal.typename(ident, i)}CppProxy: DjinniSupport.CppProxy, ${marshal.typename(ident, i)}").braced { for (m <- i.methods.filter(!_.static)) { - w.w(s"func ${idSwift.method(m.ident)}(") + w.w(s"func ${swiftMethodName(m.ident)}(") w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.paramType(p.ty)}").mkString(", ")) w.w(s") -> ${marshal.returnType(m.ret)}").braced { w.wl("var params = djinni.swift.ParameterList()") w.wl("params.addValue(inst)") for (p <- m.params) { - w.wl(s"params.addValue(${marshal.toCpp(p.ty, p.ident)})") + w.wl(s"params.addValue(${marshal.toCpp(p.ty, idSwift.local(p.ident))})") } val call = s"${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(¶ms)" if (m.ret.isEmpty) { @@ -164,7 +242,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { w.wl(s"let _${idSwift.local(p.ident)} = ${marshal.fromCpp(p.ty, pi)}") } val args = m.params.map(p => s"${idSwift.local(p.ident)}: _${idSwift.local(p.ident)}").mkString(", ") - val call = s"inst.${idSwift.method(m.ident)}(${args})" + val call = s"inst.${swiftMethodName(m.ident)}(${args})" if (m.ret.isEmpty) { w.wl(call) } else { @@ -181,7 +259,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { w.w(s"enum ${marshal.typename(ident, i)}Marshaller: DjinniSupport.Marshaller").braced { w.wl(s"typealias SwiftType = ${marshal.typename(ident, i)}") w.w("static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced { - val newProxyBlock = if (i.ext.cpp) {"{ CppProxy(c) }"} else {"{ fatalError(\"n/a\") }"} + val newProxyBlock = if (i.ext.cpp) {s"{ ${marshal.typename(ident, i)}CppProxy(c) }"} else {"{ fatalError(\"n/a\") }"} w.wl(s"return cppInterfaceToSwift(c, ${newProxyBlock})") } w.w("static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced { @@ -194,12 +272,12 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { if (!staticMethods.isEmpty) { w.w(s"public class ${marshal.typename(ident, i)}_statics").braced { for (m <- staticMethods) { - w.w(s"static func ${idSwift.method(m.ident)}(") + w.w(s"static func ${swiftMethodName(m.ident)}(") w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.paramType(p.ty)}").mkString(", ")) w.w(s") -> ${marshal.returnType(m.ret)}").braced { w.wl("var params = djinni.swift.ParameterList()") for (p <- m.params) { - w.wl(s"params.addValue(${marshal.toCpp(p.ty, p.ident)})") + w.wl(s"params.addValue(${marshal.toCpp(p.ty, idSwift.local(p.ident))})") } val call = s"${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(¶ms)" if (m.ret.isEmpty) { diff --git a/src/source/SwiftMarshal.scala b/src/source/SwiftMarshal.scala index 019f33e3..b937d577 100644 --- a/src/source/SwiftMarshal.scala +++ b/src/source/SwiftMarshal.scala @@ -39,6 +39,13 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { override def toCpp(tm: MExpr, expr: String): String = s"${helperClass(tm)}.toCpp(${expr})" override def fromCpp(tm: MExpr, expr: String): String = s"${helperClass(tm)}.fromCpp(${expr})" + def references(m: Meta, exclude: String = ""): Seq[SymbolReference] = m match { + case p: MProtobuf => List() + case d: MDef => List() + case e: MExtern => List(ImportRef(e.swift.module)) + case _ => List() + } + private def toSwiftType(tm: MExpr, packageName: Option[String]): String = { def args(tm: MExpr) = if (tm.args.isEmpty) "" else tm.args.map(f(_)).mkString("<", ", ", ">") def f(tm: MExpr): String = { @@ -50,8 +57,8 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { case MOptional => throw new AssertionError("nested optional?") case m => s"Optional<${f(arg)}>" } - // case e: MExtern => e.swift.typename + (if (e.ts.generic) args(tm) else "") - case e: MExtern => throw new AssertionError("TODO") + case e: MExtern => e.swift.typename + (if (e.swift.generic) args(tm) else "") + // case e: MExtern => throw new AssertionError("TODO") case p: MProtobuf => p.name case o => val base = o match { @@ -82,16 +89,16 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { case "i32" => "Int32" case "i16" => "Int16" case "i8" => "Int8" - case "float" => "Float" - case "double" => "Double" - case _ => throw new AssertionError("unknown primitive type") + case "f32" => "Float" + case "f64" => "Double" + case _ => throw new AssertionError("unknown primitive type: " + p._idlName) } def helperClass(name: String) = idSwift.ty(name) + "Marshaller" // TODO: make naming configurable private def helperClass(tm: MExpr): String = helperName(tm) + helperTemplates(tm) def helperName(tm: MExpr): String = tm.base match { case d: MDef => helperClass(d.name) - case e: MExtern => e.jni.translator // TODO: swift translator + case e: MExtern => e.swift.translator case o => o match { case p: MPrimitive => p.idlName match { case "i8" => "I8Marshaller" diff --git a/src/source/SwiftxxGenerator.scala b/src/source/SwiftxxGenerator.scala index 4df8e101..5d3d8cbf 100644 --- a/src/source/SwiftxxGenerator.scala +++ b/src/source/SwiftxxGenerator.scala @@ -157,7 +157,7 @@ class SwiftxxGenerator(spec: Spec) extends Generator(spec) { } else { w.w("inst->") } - val args = m.params.map(p => s"_${idCpp.local(p.ident)}").mkString(", ") + val args = m.params.map(p => s"std::move(_${idCpp.local(p.ident)})").mkString(", ") w.wl(s"${idCpp.method(m.ident)}($args);") // return if (m.ret.isEmpty) { diff --git a/src/source/SwiftxxMarshal.scala b/src/source/SwiftxxMarshal.scala index bad85226..476951b1 100644 --- a/src/source/SwiftxxMarshal.scala +++ b/src/source/SwiftxxMarshal.scala @@ -41,26 +41,23 @@ class SwiftxxMarshal(spec: Spec) extends Marshal(spec) { override def fromCpp(tm: MExpr, expr: String): String = s"${helperClass(tm)}::fromCpp(${expr})" def references(m: Meta, exclude: String = ""): Seq[SymbolReference] = m match { - case p: MProtobuf => { - List() - // val headers = List() - // p.body.java.jniHeader match { - // case Some(serialzerHeader) => ImportRef(serialzerHeader) :: headers - // case _ => headers - // } - } + case p: MProtobuf => List() case d: MDef => List(ImportRef(include(d.name))) - case e: MExtern => List() + case e: MExtern => List(ImportRef(resolveExtSwiftxxHdr(e.swiftxx.header))) case _ => List() } def include(ident: String) = q(spec.swiftxxFileIdentStyle(ident) + "." + spec.cppHeaderExt) + def resolveExtSwiftxxHdr(path: String) = { + path.replaceAll("\\$", ""); + } + def helperClass(name: String) = spec.swiftxxClassIdentStyle(name) private def helperClass(tm: MExpr): String = helperName(tm) + helperTemplates(tm) def helperName(tm: MExpr): String = tm.base match { case d: MDef => withNs(Some(spec.swiftxxNamespace), helperClass(d.name)) - case e: MExtern => e.jni.translator // TODO: swift translator + case e: MExtern => e.swiftxx.translator case o => withNs(Some("djinni::swift"), o match { case p: MPrimitive => p.idlName match { case "i8" => "I8" @@ -89,7 +86,11 @@ class SwiftxxMarshal(spec: Spec) extends Marshal(spec) { private def helperTemplates(tm: MExpr): String = { def f() = if(tm.args.isEmpty) "" else tm.args.map(helperClass).mkString("<", ", ", ">") tm.base match { - case MOptional | MList | MSet | MArray => + case MOptional => + assert(tm.args.size == 1) + val argHelperClass = helperClass(tm.args.head) + s"<${spec.cppOptionalTemplate}, $argHelperClass>" + case MList | MSet | MArray => assert(tm.args.size == 1) f case _ => f diff --git a/src/source/YamlGenerator.scala b/src/source/YamlGenerator.scala index c61bdd87..290061cd 100644 --- a/src/source/YamlGenerator.scala +++ b/src/source/YamlGenerator.scala @@ -37,6 +37,8 @@ class YamlGenerator(spec: Spec) extends Generator(spec) { val wasmMarshal = new WasmGenerator(spec) val composerMarshal = new ComposerGenerator(spec) val tsMarshal = new TsGenerator(spec, false) + val swiftMarshal = new SwiftMarshal(spec) + val swiftxxMarshal = new SwiftxxMarshal(spec) case class QuotedString(str: String) // For anything that migt require escaping @@ -81,6 +83,9 @@ class YamlGenerator(spec: Spec) extends Generator(spec) { if (spec.wasmOutFolder.isDefined || spec.composerOutFolder.isDefined) { w.wl("ts:").nested {write(w, ts(td)) } } + if (spec.swiftOutFolder.isDefined) { + w.wl("swift:").nested {write(w, swift(td))} + } } private def write(w: IndentWriter, m: Map[String, Any]) { @@ -209,6 +214,11 @@ class YamlGenerator(spec: Spec) extends Generator(spec) { //, "generic" -> false ) + private def swift(td: TypeDecl) = Map[String, Any]( + "typename" -> QuotedString(swiftMarshal.fqTypename(td.ident, td.body)), + "module" -> QuotedString(spec.swiftModule) + ) + // TODO: there has to be a way to do all this without the MExpr/Meta conversions? private def mexpr(td: TypeDecl) = MExpr(meta(td), List()) @@ -295,7 +305,15 @@ object YamlGenerator { MExtern.Ts( getOptionalField(td, "ts", "typename"), getOptionalField(td, "ts", "module"), - getOptionalField(td, "ts", "generic", false)) + getOptionalField(td, "ts", "generic", false)), + MExtern.Swift( + getOptionalField(td, "swift", "typename"), + getOptionalField(td, "swift", "module"), + getOptionalField(td, "swift", "translator"), + getOptionalField(td, "swift", "generic", false)), + MExtern.Swiftxx( + getOptionalField(td, "swiftxx", "translator"), + getOptionalField(td, "swiftxx", "header")) ) private def nested(td: ExternTypeDecl, key: String) = { diff --git a/src/source/meta.scala b/src/source/meta.scala index 2c21827f..2768fc5b 100644 --- a/src/source/meta.scala +++ b/src/source/meta.scala @@ -33,7 +33,7 @@ abstract sealed class Meta case class MParam(name: String) extends Meta { val numParams = 0 } case class MDef(name: String, override val numParams: Int, defType: DefType, body: TypeDef) extends Meta -case class MExtern(name: String, override val numParams: Int, defType: DefType, body: TypeDef, cpp: MExtern.Cpp, objc: MExtern.Objc, objcpp: MExtern.Objcpp, java: MExtern.Java, jni: MExtern.Jni, wasm: MExtern.Wasm, composer: MExtern.Composer, ts: MExtern.Ts) extends Meta +case class MExtern(name: String, override val numParams: Int, defType: DefType, body: TypeDef, cpp: MExtern.Cpp, objc: MExtern.Objc, objcpp: MExtern.Objcpp, java: MExtern.Java, jni: MExtern.Jni, wasm: MExtern.Wasm, composer: MExtern.Composer, ts: MExtern.Ts, swift: MExtern.Swift, swiftxx: MExtern.Swiftxx) extends Meta object MExtern { // These hold the information marshals need to interface with existing types correctly // All include paths are complete including quotation marks "a/b/c" or angle brackets . @@ -87,6 +87,16 @@ object MExtern { module: String, // The module to import for the type generic: Boolean ) + case class Swift( + typename: String, + module: String, + translator: String, + generic: Boolean + ) + case class Swiftxx( + translator: String, + header: String + ) } case class MProtobuf(name: String, override val numParams: Int, body: ProtobufMessage) extends Meta diff --git a/support-lib/dataref.yaml b/support-lib/dataref.yaml index 9b404575..4f3777d1 100644 --- a/support-lib/dataref.yaml +++ b/support-lib/dataref.yaml @@ -36,3 +36,7 @@ ts: composer: translator: '::djinni::composer::NativeDataRef' header: '"$DataRef_composer.hpp"' +swift: + typename: 'Data' + module: 'Foundation' + generic: false diff --git a/support-lib/dataview.yaml b/support-lib/dataview.yaml index 6edc19f7..9046bf8c 100644 --- a/support-lib/dataview.yaml +++ b/support-lib/dataview.yaml @@ -36,3 +36,7 @@ ts: composer: translator: '::djinni::composer::NativeDataView' header: '"$DataView_composer.hpp"' +swift: + typename: 'Data' + module: 'Foundation' + generic: false diff --git a/support-lib/future.yaml b/support-lib/future.yaml index b2c922ac..eff05f54 100644 --- a/support-lib/future.yaml +++ b/support-lib/future.yaml @@ -39,3 +39,11 @@ ts: composer: translator: '::djinni::composer::FutureAdaptor' header: '"$Future_composer.hpp"' +swift: + typename: 'DJFuture' + module: 'DjinniSupport' + translator: 'FutureMarshaller' + generic: true +swiftxx: + translator: '::djinni::swift::FutureAdaptor' + header: '"$Future_swift.hpp"' diff --git a/support-lib/jni/Future_jni.hpp b/support-lib/jni/Future_jni.hpp index 592493bc..668109ba 100644 --- a/support-lib/jni/Future_jni.hpp +++ b/support-lib/jni/Future_jni.hpp @@ -126,7 +126,7 @@ class FutureAdaptor return f; } - static LocalRef fromCpp(JNIEnv* jniEnv, CppType c) + static LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) { const auto& promiseJniInfo = JniClass::get(); diff --git a/support-lib/outcome.yaml b/support-lib/outcome.yaml index 5d859d7f..7bd160ac 100644 --- a/support-lib/outcome.yaml +++ b/support-lib/outcome.yaml @@ -39,3 +39,6 @@ ts: composer: translator: '::djinni::composer::Outcome' header: '"$Outcome_composer.hpp"' +swift: + typename: 'Result' + generic: true diff --git a/support-lib/swift/DjinniSupport.swift b/support-lib/swift/DjinniSupport.swift index 2bdecdc1..b34b07f0 100644 --- a/support-lib/swift/DjinniSupport.swift +++ b/support-lib/swift/DjinniSupport.swift @@ -1,4 +1,6 @@ import DjinniSupportCxx +import Foundation +import Combine public typealias Vtbl = [(T, UnsafePointer?, UnsafeMutablePointer?) -> Void] @@ -63,15 +65,116 @@ public enum EnumMarshaller: Marshaller where T.RawValue == } } +public enum SmallIntMarshaller: Marshaller { + public typealias SwiftType = T + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return SwiftType(exactly: djinni.swift.I32.toCpp(v))! + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.I32.fromCpp(Int32(s)) + } +} +public enum I64Marshaller: Marshaller { + public typealias SwiftType = Int64 + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return SwiftType(exactly: djinni.swift.I64.toCpp(v))! + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.I64.fromCpp(s) + } +} +public enum FloatMarshaller: Marshaller { + public typealias SwiftType = T + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return T(djinni.swift.F64.toCpp(v)) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.F64.fromCpp(Double(s)) + } +} +public enum BoolMarshaller: Marshaller { + public typealias SwiftType = Bool + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return djinni.swift.I32.toCpp(v) != 0 + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.I32.fromCpp(s ? 1 : 0) + } +} + +public typealias I8Marshaller = SmallIntMarshaller +public typealias I16Marshaller = SmallIntMarshaller +public typealias I32Marshaller = SmallIntMarshaller +public typealias F32Marshaller = FloatMarshaller +public typealias F64Marshaller = FloatMarshaller + public enum StringMarshaller: Marshaller { public typealias SwiftType = String static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - // TODO: optimize - pass by pointer - return SwiftType(djinni.swift.String.toCpp(v)) + let range = djinni.swift.getRange(v) + let typedPtr = range.bytes.bindMemory(to: CChar.self, capacity: range.size) + return String(cString: typedPtr) + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + let bytes = s.utf8CString + return bytes.withUnsafeBufferPointer { ptr in + return djinni.swift.makeRangeValue(UnsafeMutableRawPointer(mutating: ptr.baseAddress!), + ptr.count) + } + } +} + +public enum BinaryMarshaller: Marshaller { + public typealias SwiftType = Data + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + let range = djinni.swift.getRange(v) + return Data(bytes: range.bytes, count: range.size) } static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - // TODO: optimize - pass swift string to c++ - return djinni.swift.String.fromCpp(std.string(s)) + return s.withUnsafeBytes { (ptr: UnsafeRawBufferPointer) in + return djinni.swift.makeRangeValue(UnsafeMutableRawPointer(mutating: ptr.baseAddress!), + ptr.count) + } + } +} + +public enum DateMarshaller: Marshaller { + public typealias SwiftType = Date + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + let millisecondsSinceEpoch = I64Marshaller.fromCpp(v) + return Date(timeIntervalSince1970: Double(millisecondsSinceEpoch)) + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return I64Marshaller.toCpp(Int64(s.timeIntervalSince1970)) + } +} + +public enum VoidMarshaller: Marshaller { + public typealias SwiftType = Void + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return () + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.makeVoidValue() + } +} + +public enum OptionalMarshaller: Marshaller { + public typealias SwiftType = T.SwiftType? + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: v) { p in + if (djinni.swift.isVoidValue(p)) { + return nil + } + return T.fromCpp(v) + } + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + if (s == nil) { + return djinni.swift.makeVoidValue() + } else { + return T.toCpp(s!) + } } } @@ -96,6 +199,52 @@ public enum ListMarshaller: Marshaller { } } +public typealias ArrayMarshaller = ListMarshaller + +public enum SetMarshaller: Marshaller where T.SwiftType: Hashable { + public typealias SwiftType = Set + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + var s = SwiftType() + withUnsafePointer(to: v) { p in + let size = djinni.swift.getSize(p) + for i in 0.. djinni.swift.AnyValue { + var composite = djinni.swift.makeCompositeValue() + for item in s { + djinni.swift.addMember(&composite, T.toCpp(item)) + } + return composite + } +} + +public enum MapMarshaller: Marshaller where K.SwiftType: Hashable { + public typealias SwiftType = Dictionary + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + var s = SwiftType() + withUnsafePointer(to: v) { p in + let size = djinni.swift.getSize(p) + for i in stride(from: 0, to: size, by: 2) { + s.updateValue(V.fromCpp(djinni.swift.getMember(p, i+1)), + forKey: K.fromCpp(djinni.swift.getMember(p, i))) + } + } + return s + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var composite = djinni.swift.makeCompositeValue() + for (k, v) in s { + djinni.swift.addMember(&composite, K.toCpp(k)) + djinni.swift.addMember(&composite, V.toCpp(v)) + } + return composite + } +} + open class CppProxy { public var inst: djinni.swift.AnyValue public init(_ inst: djinni.swift.AnyValue) { @@ -174,3 +323,17 @@ public func destroyCppProxy(_ inst: djinni.swift.AnyValue) { print("after destroy cppproxycache entry", CppProxyCache.shared.mapPtrToProxy) } } + +public typealias DJFuture = Future + +public enum FutureMarshaller: Marshaller { + public typealias SwiftType = DJFuture + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return Future() { promise in + promise(Result.success(T.fromCpp(v))) + } + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.makeVoidValue() + } +} diff --git a/support-lib/swiftxx/Future_swift.hpp b/support-lib/swiftxx/Future_swift.hpp new file mode 100644 index 00000000..85e076a8 --- /dev/null +++ b/support-lib/swiftxx/Future_swift.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "djinni_support.hpp" +#include "../cpp/Future.hpp" + +namespace djinni::swift { + +// TODO implement +template +class FutureAdaptor +{ + using CppResType = typename RESULT::CppType; +public: + using CppType = Future; + + static CppType toCpp(const AnyValue& o) { + Promise p; + return p.getFuture(); + } + static AnyValue fromCpp(const CppType& c) { + return makeVoidValue(); + } +}; + +} diff --git a/support-lib/swiftxx/djinni_support.cpp b/support-lib/swiftxx/djinni_support.cpp index df8df88e..b29a49eb 100644 --- a/support-lib/swiftxx/djinni_support.cpp +++ b/support-lib/swiftxx/djinni_support.cpp @@ -2,6 +2,14 @@ namespace djinni::swift { +AnyValue makeRangeValue(void* bytes, size_t size) { + return RangeValue{bytes, size}; +} + +RangeValue getRange(const AnyValue& v) { + return std::get(v); +} + size_t getSize(const AnyValue* v) { auto composite = std::get(*v); return composite->getSize(); @@ -43,6 +51,11 @@ AnyValue makeVoidValue() { return VoidValue{}; } +bool isVoidValue(const AnyValue* c) { + return std::holds_alternative(*c); +} + + AnyValue makeCompositeValue() { return { std::make_shared() }; } diff --git a/support-lib/swiftxx/djinni_support.hpp b/support-lib/swiftxx/djinni_support.hpp index d24d5ddb..7deab3e5 100644 --- a/support-lib/swiftxx/djinni_support.hpp +++ b/support-lib/swiftxx/djinni_support.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace djinni::swift { // -------- Intermediate data structure and functions to manipulate them from Swift @@ -14,8 +15,12 @@ using I32Value = int32_t; using I64Value = int64_t; // double covers float too using DoubleValue = double; -using StringValue = std::string; -using BinaryValue = std::vector; +// using StringValue = std::string; +// using BinaryValue = std::vector; +struct RangeValue { + const void* bytes; + size_t size; +}; using DateValue = std::chrono::system_clock::time_point; class ProtocolWrapper; @@ -29,10 +34,15 @@ struct InterfaceValue { struct CompositeValue; using CompositeValuePtr = std::shared_ptr; +struct OpaqueValue { + virtual ~OpaqueValue() = default; +}; +using OpaqueValuePtr = std::shared_ptr; + using AnyValue = std::variant; + RangeValue, DateValue, + InterfaceValue, OpaqueValuePtr, CompositeValuePtr>; struct CompositeValue { virtual ~CompositeValue() = default; @@ -50,12 +60,15 @@ struct CompositeValue { struct ParameterList: CompositeValue {}; +AnyValue makeRangeValue(void* bytes, size_t size); +RangeValue getRange(const AnyValue& v); size_t getSize(const AnyValue* v); AnyValue getMember(const AnyValue* v, size_t i); void addMember(AnyValue* c, const AnyValue& v); AnyValue getMember(const ParameterList* v, size_t i); void setReturnValue(AnyValue* ret, const AnyValue& v); AnyValue makeVoidValue(); +bool isVoidValue(const AnyValue* c); AnyValue makeCompositeValue(); struct InterfaceInfo { @@ -83,7 +96,7 @@ class ProtocolWrapper { // -------- Built-in marshallers (conversion between C++ types and intermediate types) template -struct Integer { +struct Number { using CppType = T; static AnyValue fromCpp(T v) { return {static_cast(v)}; @@ -94,7 +107,13 @@ struct Integer { } }; -using I32 = Integer; +using Bool = Number; +using I8 = Number; +using I16 = Number; +using I32 = Number; +using I64 = Number; +using F32 = Number; +using F64 = Number; template struct Enum { @@ -110,11 +129,12 @@ struct Enum { struct String { using CppType = std::string; - static AnyValue fromCpp(const CppType& v) { - return {v}; + static AnyValue fromCpp(const CppType& c) { + return RangeValue{c.data(), c.size()}; } static CppType toCpp(const AnyValue& v) { - return std::get(v); + auto range = std::get(v); + return {reinterpret_cast(range.bytes), range.size}; } }; @@ -138,16 +158,120 @@ struct List { } }; +template using Array = List; + +template +struct Set { + using CppType = std::unordered_set; + static AnyValue fromCpp(const CppType& v) { + auto ret = std::make_shared(); + for (const auto& e: v) { + ret->addValue(T::fromCpp(e)); + } + return {ret}; + } + static CppType toCpp(const AnyValue& v) { + CppType vec; + auto c = std::get(v); + for (const auto& item: c->_elems) { + vec.insert(T::toCpp(item)); + } + return vec; + } +}; + +template +struct Map { + using CppType = std::unordered_map; + static AnyValue fromCpp(const CppType& c) { + auto ret = std::make_shared(); + for (const auto& [k, v]: c) { + ret->addValue(T::fromCpp(k)); + ret->addValue(U::fromCpp(v)); + } + return {ret}; + } + static CppType toCpp(const AnyValue& v) { + CppType map; + auto c = std::get(v); + for (auto i = c->_elems.begin(); i != c->_elems.end(); i += 2) { + map.insert_or_assign(T::toCpp(*i), U::toCpp(*(i+1))); + } + return map; + } +}; + +template class OptionalType, class T> +struct Optional { + template + static OptionalType opt_type(...); + template + static typename C::CppOptType opt_type(typename C::CppOptType*); + using CppType = decltype(opt_type(nullptr)); + + static AnyValue fromCpp(const OptionalType& c) { + return c ? T::fromCpp(*c) : makeVoidValue(); + } + static CppType toCpp(const AnyValue& v) { + if (std::holds_alternative(v)) { + return CppType{}; + } else { + return T::toCpp(v); + } + } + template + static AnyValue fromCpp(const typename C::CppOptType& cppOpt) { + return T::fromCppOpt(cppOpt); + } +}; + +class Date { +public: + using CppType = std::chrono::system_clock::time_point; + + static CppType toCpp(const AnyValue& v) { + auto millisecondsSinceEpoch = std::chrono::milliseconds(std::get(v)); + return CppType(std::chrono::duration_cast(millisecondsSinceEpoch)); + } + static AnyValue fromCpp(const CppType& c) { + auto millisecondsSinceEpoch = std::chrono::duration_cast(c.time_since_epoch()); + return {static_cast(millisecondsSinceEpoch.count())}; + } +}; + +class Binary { +public: + using CppType = std::vector; + + static AnyValue fromCpp(const CppType& c) { + return RangeValue{c.data(), c.size()}; + } + static CppType toCpp(const AnyValue& v) { + auto range = std::get(v); + const auto* ptr = reinterpret_cast(range.bytes); + return {ptr, ptr + range.size}; + } +}; + +class Void { +public: + using CppType = void; +}; + template struct Interface { using CppType = std::shared_ptr; - static AnyValue fromCpp(const CppType& v) { - return {v}; + using CppOptType = std::shared_ptr; + static AnyValue fromCpp(const CppType& c) { + return {c}; } static CppType toCpp(const AnyValue& v) { auto i = std::get(v); return std::reinterpret_pointer_cast(i.ptr); } + static AnyValue fromCppOpt(const CppOptType& c) { + return {c}; + } }; } diff --git a/test-suite/BUILD b/test-suite/BUILD index 83726ee3..c8684b62 100644 --- a/test-suite/BUILD +++ b/test-suite/BUILD @@ -4,18 +4,23 @@ load("@build_bazel_rules_apple//apple:macos.bzl", "macos_unit_test") load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library", "swift_test") load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") +exclude_files = ["handwritten-src/cpp/proto_test_helpers.*", + "handwritten-src/cpp/TranslateDuration.*", + "handwritten-src/cpp/data_helpers.*", + "handwritten-src/cpp/outcome_test_helpers.*"] + cc_library( name = "djinni-tests-common", srcs = glob([ "generated-src/cpp/*.cpp", "handwritten-src/cpp/*.cpp", "djinni/vendor/third-party/proto/cpp/*.cc", - ]), + ], exclude=exclude_files), hdrs = glob([ "generated-src/cpp/*.hpp", "handwritten-src/cpp/*.hpp", "djinni/vendor/third-party/proto/cpp/*.h", - ]), + ], exclude=exclude_files), includes = [ "generated-src/cpp", "handwritten-src/cpp", @@ -196,10 +201,73 @@ sh_binary( swift_test( name = "djinni-swift-tests", srcs = ['handwritten-src/swift/AllTests.swift'], - deps = ['//examples:textsort-swiftimp'], + deps = ['//examples:textsort-swift-bridge'], copts = [ "-cxx-interoperability-mode=default", "-Xcc", "-std=c++17" ], ) + +swift_private_files = "generated-src/swift/*+Private.swift" + +swift_library( + name = "test-swift", + module_name = "TestSuite", + generated_header_name = "TestSuite-Swift.h", + generates_header = True, + srcs = glob([ + "generated-src/swift/*.swift", + ], exclude = [ swift_private_files ]), + copts = [ + "-cxx-interoperability-mode=default", + "-Xcc", "-std=c++17", + ], + deps = [ + "//support-lib:djinni-support-swift", + ], + visibility = ["//visibility:public"], +) + +swift_library( + name = "test-swift-bridge", + module_name = "TestSuiteBridge", + srcs = glob([swift_private_files,]), + copts = [ + "-cxx-interoperability-mode=default", + "-Xcc", "-std=c++17", + ], + deps = [ + ":djinni-tests-common", + ":test-swift", + ":test-swiftxx", + "//support-lib:djinni-support-swift", + "//support-lib:djinni-support-swiftxx", + ], + visibility = ["//visibility:public"], +) + +cc_library( + name = "test-swiftxx", + srcs = glob([ + "generated-src/swiftxx/*.cpp", + ]), + hdrs = glob([ + "generated-src/swiftxx/*.hpp", + ]), + includes = [ + "generated-src/swiftxx", + ".", + ], + deps = [ + ":djinni-tests-common", + ":test-swift", + "//support-lib:djinni-support-common", + "//support-lib:djinni-support-swiftxx", + ], + copts = [ + "-std=c++17", + ], + tags = ["swift_module=TestSuiteCxx"], + visibility = ["//visibility:public"], +) diff --git a/test-suite/djinni/all.djinni b/test-suite/djinni/all.djinni index fec1d113..481bbe2e 100644 --- a/test-suite/djinni/all.djinni +++ b/test-suite/djinni/all.djinni @@ -1,10 +1 @@ @import "common.djinni" - -@import "enum_flags.djinni" -@import "constant_enum.djinni" -@import "data_ref_view.djinni" - -@import "vendor/third-party/date.djinni" -@import "third-party/duration.djinni" -@import "third-party/outcome.djinni" -@import "third-party/proto.djinni" diff --git a/test-suite/djinni/common.djinni b/test-suite/djinni/common.djinni index 1a078536..7fe1a9d6 100644 --- a/test-suite/djinni/common.djinni +++ b/test-suite/djinni/common.djinni @@ -6,6 +6,7 @@ @import "exception.djinni" @import "client_interface.djinni" @import "enum.djinni" +@import "enum_flags.djinni" @import "user_token.djinni" @import "test.djinni" @import "primtypes.djinni" diff --git a/test-suite/djinni/test.djinni b/test-suite/djinni/test.djinni index dc0845f3..9900ab81 100644 --- a/test-suite/djinni/test.djinni +++ b/test-suite/djinni/test.djinni @@ -78,12 +78,12 @@ empty_record = record { # Test for conflict of method name with an interface name. # See the comments about scopeSymbols in CppMarshal.scala for more info. -Conflict = interface +c { -} -conflict_user = interface +c { - Conflict(): Conflict; - conflict_arg(cs: set): bool; -} +# Conflict = interface +c { +# } +# conflict_user = interface +c { +# Conflict(): Conflict; +# conflict_arg(cs: set): bool; +# } # we need to test optional interface # this one will be used diff --git a/test-suite/djinni/vendor/third-party/date.yaml b/test-suite/djinni/vendor/third-party/date.yaml index 82f10f38..cb2c1f4b 100644 --- a/test-suite/djinni/vendor/third-party/date.yaml +++ b/test-suite/djinni/vendor/third-party/date.yaml @@ -37,3 +37,6 @@ wasm: ts: typename: 'Date' module: '' +swift: + typename: 'Date' + module: '' diff --git a/test-suite/handwritten-src/swift/AllTests.swift b/test-suite/handwritten-src/swift/AllTests.swift index 39ae4da5..13b520a3 100644 --- a/test-suite/handwritten-src/swift/AllTests.swift +++ b/test-suite/handwritten-src/swift/AllTests.swift @@ -1,6 +1,6 @@ import XCTest @testable import TextSort; -@testable import TextSortImp; +@testable import TextSortBridge; class MyListener: TextboxListener { deinit { diff --git a/test-suite/run_djinni.sh b/test-suite/run_djinni.sh index 3623248d..1ba73bba 100755 --- a/test-suite/run_djinni.sh +++ b/test-suite/run_djinni.sh @@ -37,6 +37,8 @@ objc_out="$base_dir/generated-src/objc" java_out="$base_dir/generated-src/java/com/dropbox/djinni/test" wasm_out="$base_dir/generated-src/wasm" ts_out="$base_dir/generated-src/ts" +swift_out="$base_dir/generated-src/swift" +swiftxx_out="$base_dir/generated-src/swiftxx" yaml_out="$base_dir/generated-src/yaml" java_package="com.dropbox.djinni.test" @@ -135,6 +137,12 @@ fi --ts-out "$temp_out_relative/ts" \ --ts-module "test" \ \ + --swift-out "$temp_out/swift" \ + --swift-module "TestSuite" \ + --swiftxx-out "$temp_out/swiftxx" \ + --ident-swiftxx-class NativeFooBar \ + --ident-swiftxx-file NativeFooBar \ + \ --list-in-files "./generated-src/inFileList.txt" \ --list-out-files "./generated-src/outFileList.txt"\ \ @@ -318,6 +326,8 @@ mirror "jni" "$temp_out/jni" "$jni_out" mirror "objc" "$temp_out/objc" "$objc_out" mirror "wasm" "$temp_out/wasm" "$wasm_out" mirror "ts" "$temp_out/ts" "$ts_out" +mirror "swift" "$temp_out/swift" "$swift_out" +mirror "swiftxx" "$temp_out/swiftxx" "$swiftxx_out" date > "$gen_stamp" From 36c027ea36085e5bc8ef7c6f6a17abe9e3b0bc82 Mon Sep 17 00:00:00 2001 From: Jan Buenker Date: Mon, 8 Jul 2024 16:44:22 +0200 Subject: [PATCH 20/68] Use official C++ 20 coroutine feature test macro __cpp_coroutines is no longer defined by clang starting at clang 17 --- support-lib/cpp/Future.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support-lib/cpp/Future.hpp b/support-lib/cpp/Future.hpp index dede703d..6207d6e9 100644 --- a/support-lib/cpp/Future.hpp +++ b/support-lib/cpp/Future.hpp @@ -25,7 +25,7 @@ #include #include -#ifdef __cpp_coroutines +#if defined(__cpp_coroutines) || defined(__cpp_impl_coroutine) #if __has_include() #include namespace djinni::detail { From ea62a3b6a7426529c0dddef551550e36b6028d78 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Thu, 11 Jul 2024 13:17:31 +1000 Subject: [PATCH 21/68] all swift tests passing --- bzl/deps.bzl | 15 + .../swift/ItemList+Private.swift | 1 + examples/generated-src/swift/ItemList.swift | 2 + .../swift/SortItems+Private.swift | 23 +- examples/generated-src/swift/SortItems.swift | 4 +- examples/generated-src/swift/SortOrder.swift | 6 +- .../swift/TextboxListener+Private.swift | 3 +- .../generated-src/swift/TextboxListener.swift | 4 +- .../generated-src/swiftxx/SwiftSortItems.cpp | 21 +- src/source/ComposerGenerator.scala | 2 +- src/source/CppGenerator.scala | 2 + src/source/ObjcGenerator.scala | 1 + src/source/ObjcMarshal.scala | 6 +- src/source/SwiftGenerator.scala | 100 ++++-- src/source/SwiftMarshal.scala | 29 +- src/source/SwiftxxGenerator.scala | 71 ++-- src/source/SwiftxxMarshal.scala | 7 +- src/source/TsGenerator.scala | 2 +- src/source/WasmGenerator.scala | 2 +- src/source/YamlGenerator.scala | 19 +- src/source/ast.scala | 3 +- src/source/generator.scala | 3 +- src/source/meta.scala | 1 + src/source/parser.scala | 8 + support-lib/BUILD | 1 + support-lib/dataref.yaml | 7 +- support-lib/dataview.yaml | 7 +- support-lib/future.yaml | 1 + support-lib/jni/Future_jni.hpp | 2 +- support-lib/outcome.yaml | 5 + support-lib/swift/DJData.swift | 31 ++ support-lib/swift/DJFuture.swift | 65 ++++ support-lib/swift/DJMarshal.swift | 205 +++++++++++ support-lib/swift/DJOutcome.swift | 29 ++ support-lib/swift/DJProtobuf.swift | 20 ++ support-lib/swift/DjinniSupport.swift | 232 ++----------- support-lib/swiftxx/Data_swift.cpp | 159 +++++++++ support-lib/swiftxx/Data_swift.hpp | 25 ++ support-lib/swiftxx/Future_swift.cpp | 25 ++ support-lib/swiftxx/Future_swift.hpp | 127 ++++++- support-lib/swiftxx/Outcome_swift.hpp | 36 ++ support-lib/swiftxx/djinni_support.cpp | 51 ++- support-lib/swiftxx/djinni_support.hpp | 89 ++++- test-suite/BUILD | 30 +- test-suite/djinni/all.djinni | 9 + test-suite/djinni/client_interface.djinni | 2 +- test-suite/djinni/common.djinni | 1 - test-suite/djinni/constants.djinni | 2 +- test-suite/djinni/exception.djinni | 2 +- test-suite/djinni/test.djinni | 14 +- test-suite/djinni/user_token.djinni | 2 +- .../djinni/vendor/third-party/date.yaml | 6 +- .../djinni/vendor/third-party/duration.yaml | 42 +++ .../djinni/vendor/third-party/proto.yaml | 4 +- .../vendor/third-party/proto/run_protoc.sh | 1 + .../third-party/proto/swift/test.pb.swift | 293 ++++++++++++++++ .../third-party/proto/swift/test2.pb.swift | 77 +++++ .../djinni/vendor/third-party/proto2.yaml | 3 + .../generated-src/cpp/conflict_user.hpp | 4 +- .../generated-src/cpp/constant_record.cpp | 18 + .../generated-src/cpp/constant_record.hpp | 3 + .../com/dropbox/djinni/test/ConflictUser.java | 8 +- .../dropbox/djinni/test/ConstantRecord.java | 19 ++ .../generated-src/jni/NativeConflictUser.cpp | 2 +- .../objc/DBConflictUser+Private.mm | 4 +- .../generated-src/objc/DBConflictUser.h | 2 +- .../generated-src/objc/DBConstantRecord.mm | 17 + test-suite/generated-src/outFileList.txt | 241 +++++++++++++ .../swift/AccessFlags+Private.swift | 7 + .../generated-src/swift/AccessFlags.swift | 17 + .../swift/AssortedPrimitives+Private.swift | 49 +++ .../swift/AssortedPrimitives.swift | 39 +++ .../swift/AsyncInterface+Private.swift | 25 ++ .../generated-src/swift/AsyncInterface.swift | 9 + .../swift/ClientInterface+Private.swift | 45 +++ .../generated-src/swift/ClientInterface.swift | 14 + .../swift/ClientReturnedRecord+Private.swift | 27 ++ .../swift/ClientReturnedRecord.swift | 18 + .../generated-src/swift/Color+Private.swift | 7 + test-suite/generated-src/swift/Color.swift | 17 + .../swift/Conflict+Private.swift | 25 ++ test-suite/generated-src/swift/Conflict.swift | 11 + .../swift/ConflictUser+Private.swift | 36 ++ .../generated-src/swift/ConflictUser.swift | 9 + .../swift/ConstantEnum+Private.swift | 7 + .../generated-src/swift/ConstantEnum.swift | 7 + .../ConstantInterfaceWithEnum+Private.swift | 22 ++ .../swift/ConstantInterfaceWithEnum.swift | 8 + .../swift/ConstantRecord+Private.swift | 25 ++ .../generated-src/swift/ConstantRecord.swift | 16 + .../swift/ConstantWithEnum+Private.swift | 20 ++ .../swift/ConstantWithEnum.swift | 13 + .../swift/Constants+Private.swift | 20 ++ .../generated-src/swift/Constants.swift | 49 +++ .../swift/ConstantsInterface+Private.swift | 28 ++ .../swift/ConstantsInterface.swift | 14 + .../swift/CppException+Private.swift | 52 +++ .../generated-src/swift/CppException.swift | 10 + .../swift/DataRefTest+Private.swift | 86 +++++ .../generated-src/swift/DataRefTest.swift | 15 + .../swift/DateRecord+Private.swift | 23 ++ .../generated-src/swift/DateRecord.swift | 14 + .../swift/EmptyFlags+Private.swift | 7 + .../generated-src/swift/EmptyFlags.swift | 8 + .../swift/EmptyRecord+Private.swift | 20 ++ .../generated-src/swift/EmptyRecord.swift | 16 + .../swift/EnumUsageInterface+Private.swift | 61 ++++ .../swift/EnumUsageInterface.swift | 12 + .../swift/EnumUsageRecord+Private.swift | 31 ++ .../generated-src/swift/EnumUsageRecord.swift | 21 ++ .../swift/ExtendedRecord+Private.swift | 23 ++ .../generated-src/swift/ExtendedRecord.swift | 16 + .../swift/ExternInterface1+Private.swift | 37 ++ .../swift/ExternInterface1.swift | 9 + .../swift/ExternInterface2+Private.swift | 18 + .../swift/ExternInterface2.swift | 8 + .../ExternRecordWithDerivings+Private.swift | 25 ++ .../swift/ExternRecordWithDerivings.swift | 16 + .../swift/FirstListener+Private.swift | 19 ++ .../generated-src/swift/FirstListener.swift | 9 + .../swift/FlagRoundtrip+Private.swift | 51 +++ .../generated-src/swift/FlagRoundtrip.swift | 7 + ...InterfaceUsingExtendedRecord+Private.swift | 29 ++ .../swift/InterfaceUsingExtendedRecord.swift | 8 + .../swift/JavaOnlyListener+Private.swift | 18 + .../swift/JavaOnlyListener.swift | 7 + .../swift/ListenerCaller+Private.swift | 49 +++ .../generated-src/swift/ListenerCaller.swift | 15 + .../swift/MapDateRecord+Private.swift | 23 ++ .../generated-src/swift/MapDateRecord.swift | 14 + .../swift/MapListRecord+Private.swift | 23 ++ .../generated-src/swift/MapListRecord.swift | 13 + .../swift/MapRecord+Private.swift | 25 ++ .../generated-src/swift/MapRecord.swift | 15 + .../swift/NestedCollection+Private.swift | 23 ++ .../swift/NestedCollection.swift | 13 + .../swift/NestedOutcome+Private.swift | 23 ++ .../generated-src/swift/NestedOutcome.swift | 13 + .../swift/ObjcOnlyListener+Private.swift | 18 + .../swift/ObjcOnlyListener.swift | 7 + .../swift/PrimitiveList+Private.swift | 23 ++ .../generated-src/swift/PrimitiveList.swift | 13 + .../swift/ProtoTests+Private.swift | 115 +++++++ .../generated-src/swift/ProtoTests.swift | 8 + .../RecordUsingExtendedRecord+Private.swift | 23 ++ .../swift/RecordUsingExtendedRecord.swift | 16 + .../swift/RecordWithDerivings+Private.swift | 37 ++ .../swift/RecordWithDerivings.swift | 27 ++ ...cordWithDurationAndDerivings+Private.swift | 23 ++ .../RecordWithDurationAndDerivings.swift | 13 + .../RecordWithEmbeddedCppProto+Private.swift | 24 ++ .../swift/RecordWithEmbeddedCppProto.swift | 14 + .../RecordWithEmbeddedProto+Private.swift | 24 ++ .../swift/RecordWithEmbeddedProto.swift | 14 + .../swift/RecordWithFlags+Private.swift | 23 ++ .../generated-src/swift/RecordWithFlags.swift | 13 + .../RecordWithNestedDerivings+Private.swift | 25 ++ .../swift/RecordWithNestedDerivings.swift | 15 + .../swift/ReturnOne+Private.swift | 37 ++ .../generated-src/swift/ReturnOne.swift | 9 + .../swift/ReturnTwo+Private.swift | 37 ++ .../generated-src/swift/ReturnTwo.swift | 9 + .../ReverseClientInterface+Private.swift | 52 +++ .../swift/ReverseClientInterface.swift | 10 + .../swift/SampleInterface+Private.swift | 25 ++ .../generated-src/swift/SampleInterface.swift | 11 + .../swift/SecondListener+Private.swift | 19 ++ .../generated-src/swift/SecondListener.swift | 9 + .../swift/SetRecord+Private.swift | 25 ++ .../generated-src/swift/SetRecord.swift | 15 + .../swift/SupportCopying+Private.swift | 23 ++ .../generated-src/swift/SupportCopying.swift | 13 + .../swift/TestArray+Private.swift | 51 +++ .../generated-src/swift/TestArray.swift | 7 + .../swift/TestDuration+Private.swift | 163 +++++++++ .../generated-src/swift/TestDuration.swift | 7 + .../swift/TestHelpers+Private.swift | 282 ++++++++++++++++ .../generated-src/swift/TestHelpers.swift | 13 + ...ptionalExternInterfaceRecord+Private.swift | 23 ++ .../TestOptionalExternInterfaceRecord.swift | 13 + .../swift/TestOutcome+Private.swift | 75 ++++ .../generated-src/swift/TestOutcome.swift | 7 + .../TestStaticMethodLanguage+Private.swift | 21 ++ .../swift/TestStaticMethodLanguage.swift | 7 + .../swift/ThrowingInterface+Private.swift | 24 ++ .../swift/ThrowingInterface.swift | 8 + .../swift/UserToken+Private.swift | 34 ++ .../generated-src/swift/UserToken.swift | 8 + .../UsesSingleLanguageListeners+Private.swift | 53 +++ .../swift/UsesSingleLanguageListeners.swift | 15 + .../swift/VarnameInterface+Private.swift | 37 ++ .../swift/VarnameInterface.swift | 14 + .../swift/VarnameRecord+Private.swift | 23 ++ .../generated-src/swift/VarnameRecord.swift | 18 + .../generated-src/swift/Vec2+Private.swift | 25 ++ test-suite/generated-src/swift/Vec2.swift | 15 + .../swift/WcharTestHelpers+Private.swift | 49 +++ .../swift/WcharTestHelpers.swift | 7 + .../swift/WcharTestRec+Private.swift | 23 ++ .../generated-src/swift/WcharTestRec.swift | 13 + .../swiftxx/NativeAccessFlags.cpp | 9 + .../swiftxx/NativeAccessFlags.hpp | 13 + .../swiftxx/NativeAssortedPrimitives.cpp | 31 ++ .../swiftxx/NativeAssortedPrimitives.hpp | 17 + .../swiftxx/NativeAsyncInterface.cpp | 18 + .../swiftxx/NativeAsyncInterface.hpp | 20 ++ .../swiftxx/NativeClientInterface.cpp | 41 +++ .../swiftxx/NativeClientInterface.hpp | 24 ++ .../swiftxx/NativeClientReturnedRecord.cpp | 20 ++ .../swiftxx/NativeClientReturnedRecord.hpp | 17 + .../generated-src/swiftxx/NativeColor.cpp | 9 + .../generated-src/swiftxx/NativeColor.hpp | 13 + .../generated-src/swiftxx/NativeConflict.cpp | 9 + .../generated-src/swiftxx/NativeConflict.hpp | 14 + .../swiftxx/NativeConflictUser.cpp | 27 ++ .../swiftxx/NativeConflictUser.hpp | 16 + .../swiftxx/NativeConstantEnum.cpp | 9 + .../swiftxx/NativeConstantEnum.hpp | 13 + .../NativeConstantInterfaceWithEnum.cpp | 10 + .../NativeConstantInterfaceWithEnum.hpp | 14 + .../swiftxx/NativeConstantRecord.cpp | 19 ++ .../swiftxx/NativeConstantRecord.hpp | 17 + .../swiftxx/NativeConstantWithEnum.cpp | 17 + .../swiftxx/NativeConstantWithEnum.hpp | 17 + .../generated-src/swiftxx/NativeConstants.cpp | 17 + .../generated-src/swiftxx/NativeConstants.hpp | 17 + .../swiftxx/NativeConstantsInterface.cpp | 18 + .../swiftxx/NativeConstantsInterface.hpp | 15 + .../swiftxx/NativeCppException.cpp | 43 +++ .../swiftxx/NativeCppException.hpp | 18 + .../swiftxx/NativeDataRefTest.cpp | 84 +++++ .../swiftxx/NativeDataRefTest.hpp | 23 ++ .../swiftxx/NativeDateRecord.cpp | 19 ++ .../swiftxx/NativeDateRecord.hpp | 17 + .../swiftxx/NativeEmptyFlags.cpp | 9 + .../swiftxx/NativeEmptyFlags.hpp | 13 + .../swiftxx/NativeEmptyRecord.cpp | 17 + .../swiftxx/NativeEmptyRecord.hpp | 17 + .../swiftxx/NativeEnumUsageInterface.cpp | 55 +++ .../swiftxx/NativeEnumUsageInterface.hpp | 19 ++ .../swiftxx/NativeEnumUsageRecord.cpp | 23 ++ .../swiftxx/NativeEnumUsageRecord.hpp | 17 + .../swiftxx/NativeExtendedRecord.cpp | 18 + .../swiftxx/NativeExtendedRecord.hpp | 17 + .../swiftxx/NativeExternInterface1.cpp | 30 ++ .../swiftxx/NativeExternInterface1.hpp | 16 + .../swiftxx/NativeExternInterface2.cpp | 11 + .../swiftxx/NativeExternInterface2.hpp | 13 + .../NativeExternRecordWithDerivings.cpp | 21 ++ .../NativeExternRecordWithDerivings.hpp | 17 + .../swiftxx/NativeFirstListener.cpp | 9 + .../swiftxx/NativeFirstListener.hpp | 13 + .../swiftxx/NativeFlagRoundtrip.cpp | 43 +++ .../swiftxx/NativeFlagRoundtrip.hpp | 18 + .../NativeInterfaceUsingExtendedRecord.cpp | 20 ++ .../NativeInterfaceUsingExtendedRecord.hpp | 15 + .../swiftxx/NativeJavaOnlyListener.cpp | 9 + .../swiftxx/NativeJavaOnlyListener.hpp | 13 + .../swiftxx/NativeListenerCaller.cpp | 36 ++ .../swiftxx/NativeListenerCaller.hpp | 17 + .../swiftxx/NativeMapDateRecord.cpp | 19 ++ .../swiftxx/NativeMapDateRecord.hpp | 17 + .../swiftxx/NativeMapListRecord.cpp | 18 + .../swiftxx/NativeMapListRecord.hpp | 17 + .../generated-src/swiftxx/NativeMapRecord.cpp | 19 ++ .../generated-src/swiftxx/NativeMapRecord.hpp | 17 + .../swiftxx/NativeNestedCollection.cpp | 18 + .../swiftxx/NativeNestedCollection.hpp | 17 + .../swiftxx/NativeNestedOutcome.cpp | 19 ++ .../swiftxx/NativeNestedOutcome.hpp | 17 + .../swiftxx/NativeObjcOnlyListener.cpp | 9 + .../swiftxx/NativeObjcOnlyListener.hpp | 13 + .../swiftxx/NativePrimitiveList.cpp | 18 + .../swiftxx/NativePrimitiveList.hpp | 17 + .../swiftxx/NativeProtoTests.cpp | 116 +++++++ .../swiftxx/NativeProtoTests.hpp | 27 ++ .../NativeRecordUsingExtendedRecord.cpp | 19 ++ .../NativeRecordUsingExtendedRecord.hpp | 17 + .../swiftxx/NativeRecordWithDerivings.cpp | 25 ++ .../swiftxx/NativeRecordWithDerivings.hpp | 17 + .../NativeRecordWithDurationAndDerivings.cpp | 19 ++ .../NativeRecordWithDurationAndDerivings.hpp | 17 + .../NativeRecordWithEmbeddedCppProto.cpp | 18 + .../NativeRecordWithEmbeddedCppProto.hpp | 17 + .../swiftxx/NativeRecordWithEmbeddedProto.cpp | 18 + .../swiftxx/NativeRecordWithEmbeddedProto.hpp | 17 + .../swiftxx/NativeRecordWithFlags.cpp | 19 ++ .../swiftxx/NativeRecordWithFlags.hpp | 17 + .../NativeRecordWithNestedDerivings.cpp | 20 ++ .../NativeRecordWithNestedDerivings.hpp | 17 + .../generated-src/swiftxx/NativeReturnOne.cpp | 24 ++ .../generated-src/swiftxx/NativeReturnOne.hpp | 16 + .../generated-src/swiftxx/NativeReturnTwo.cpp | 24 ++ .../generated-src/swiftxx/NativeReturnTwo.hpp | 16 + .../swiftxx/NativeReverseClientInterface.cpp | 42 +++ .../swiftxx/NativeReverseClientInterface.hpp | 18 + .../swiftxx/NativeSampleInterface.cpp | 9 + .../swiftxx/NativeSampleInterface.hpp | 14 + .../swiftxx/NativeSecondListener.cpp | 9 + .../swiftxx/NativeSecondListener.hpp | 13 + .../generated-src/swiftxx/NativeSetRecord.cpp | 19 ++ .../generated-src/swiftxx/NativeSetRecord.hpp | 17 + .../swiftxx/NativeSupportCopying.cpp | 18 + .../swiftxx/NativeSupportCopying.hpp | 17 + .../generated-src/swiftxx/NativeTestArray.cpp | 42 +++ .../generated-src/swiftxx/NativeTestArray.hpp | 18 + .../swiftxx/NativeTestDuration.cpp | 170 ++++++++++ .../swiftxx/NativeTestDuration.hpp | 34 ++ .../swiftxx/NativeTestHelpers.cpp | 319 ++++++++++++++++++ .../swiftxx/NativeTestHelpers.hpp | 53 +++ ...ativeTestOptionalExternInterfaceRecord.cpp | 19 ++ ...ativeTestOptionalExternInterfaceRecord.hpp | 17 + .../swiftxx/NativeTestOutcome.cpp | 71 ++++ .../swiftxx/NativeTestOutcome.hpp | 22 ++ .../NativeTestStaticMethodLanguage.cpp | 9 + .../NativeTestStaticMethodLanguage.hpp | 14 + .../swiftxx/NativeThrowingInterface.cpp | 16 + .../swiftxx/NativeThrowingInterface.hpp | 20 ++ .../generated-src/swiftxx/NativeUserToken.cpp | 24 ++ .../generated-src/swiftxx/NativeUserToken.hpp | 22 ++ .../NativeUsesSingleLanguageListeners.cpp | 45 +++ .../NativeUsesSingleLanguageListeners.hpp | 18 + .../swiftxx/NativeVarnameInterface.cpp | 28 ++ .../swiftxx/NativeVarnameInterface.hpp | 16 + .../swiftxx/NativeVarnameRecord.cpp | 18 + .../swiftxx/NativeVarnameRecord.hpp | 17 + .../generated-src/swiftxx/NativeVec2.cpp | 19 ++ .../generated-src/swiftxx/NativeVec2.hpp | 17 + .../swiftxx/NativeWcharTestHelpers.cpp | 40 +++ .../swiftxx/NativeWcharTestHelpers.hpp | 18 + .../swiftxx/NativeWcharTestRec.cpp | 18 + .../swiftxx/NativeWcharTestRec.hpp | 17 + test-suite/generated-src/ts/test.ts | 2 +- .../generated-src/wasm/NativeConflictUser.cpp | 2 +- .../handwritten-src/cpp/Duration-swift.hpp | 36 ++ .../handwritten-src/swift/ArrayTest.swift | 23 ++ .../handwritten-src/swift/AsyncTest.swift | 105 ++++++ .../swift/ClientInterfaceTest.swift | 58 ++++ .../handwritten-src/swift/ConstantsTest.swift | 16 + .../swift/CppExceptionTest.swift | 30 ++ .../handwritten-src/swift/DataTest.swift | 55 +++ .../swift/Duration+Helper.swift | 30 ++ .../handwritten-src/swift/DurationTest.swift | 39 +++ .../handwritten-src/swift/EnumTest.swift | 46 +++ .../{AllTests.swift => ExampleTest.swift} | 6 +- .../handwritten-src/swift/MapRecordTest.swift | 40 +++ .../swift/NestedCollectionTest.swift | 16 + .../swift/OutcomeTest+Error.swift | 2 + .../handwritten-src/swift/OutcomeTest.swift | 42 +++ .../swift/PrimitiveListTest.swift | 20 ++ .../swift/PrimitivesTest.swift | 11 + .../handwritten-src/swift/ProtoTest.swift | 61 ++++ .../handwritten-src/swift/SetRecordTest.swift | 20 ++ .../handwritten-src/swift/TokenTest.swift | 47 +++ .../handwritten-src/swift/WcharTest.swift | 15 + test-suite/run_djinni.sh | 16 +- 356 files changed, 9141 insertions(+), 391 deletions(-) create mode 100644 support-lib/swift/DJData.swift create mode 100644 support-lib/swift/DJFuture.swift create mode 100644 support-lib/swift/DJMarshal.swift create mode 100644 support-lib/swift/DJOutcome.swift create mode 100644 support-lib/swift/DJProtobuf.swift create mode 100644 support-lib/swiftxx/Data_swift.cpp create mode 100644 support-lib/swiftxx/Data_swift.hpp create mode 100644 support-lib/swiftxx/Future_swift.cpp create mode 100644 support-lib/swiftxx/Outcome_swift.hpp create mode 100644 test-suite/djinni/vendor/third-party/proto/swift/test.pb.swift create mode 100644 test-suite/djinni/vendor/third-party/proto/swift/test2.pb.swift create mode 100644 test-suite/generated-src/cpp/constant_record.cpp create mode 100644 test-suite/generated-src/swift/AccessFlags+Private.swift create mode 100644 test-suite/generated-src/swift/AccessFlags.swift create mode 100644 test-suite/generated-src/swift/AssortedPrimitives+Private.swift create mode 100644 test-suite/generated-src/swift/AssortedPrimitives.swift create mode 100644 test-suite/generated-src/swift/AsyncInterface+Private.swift create mode 100644 test-suite/generated-src/swift/AsyncInterface.swift create mode 100644 test-suite/generated-src/swift/ClientInterface+Private.swift create mode 100644 test-suite/generated-src/swift/ClientInterface.swift create mode 100644 test-suite/generated-src/swift/ClientReturnedRecord+Private.swift create mode 100644 test-suite/generated-src/swift/ClientReturnedRecord.swift create mode 100644 test-suite/generated-src/swift/Color+Private.swift create mode 100644 test-suite/generated-src/swift/Color.swift create mode 100644 test-suite/generated-src/swift/Conflict+Private.swift create mode 100644 test-suite/generated-src/swift/Conflict.swift create mode 100644 test-suite/generated-src/swift/ConflictUser+Private.swift create mode 100644 test-suite/generated-src/swift/ConflictUser.swift create mode 100644 test-suite/generated-src/swift/ConstantEnum+Private.swift create mode 100644 test-suite/generated-src/swift/ConstantEnum.swift create mode 100644 test-suite/generated-src/swift/ConstantInterfaceWithEnum+Private.swift create mode 100644 test-suite/generated-src/swift/ConstantInterfaceWithEnum.swift create mode 100644 test-suite/generated-src/swift/ConstantRecord+Private.swift create mode 100644 test-suite/generated-src/swift/ConstantRecord.swift create mode 100644 test-suite/generated-src/swift/ConstantWithEnum+Private.swift create mode 100644 test-suite/generated-src/swift/ConstantWithEnum.swift create mode 100644 test-suite/generated-src/swift/Constants+Private.swift create mode 100644 test-suite/generated-src/swift/Constants.swift create mode 100644 test-suite/generated-src/swift/ConstantsInterface+Private.swift create mode 100644 test-suite/generated-src/swift/ConstantsInterface.swift create mode 100644 test-suite/generated-src/swift/CppException+Private.swift create mode 100644 test-suite/generated-src/swift/CppException.swift create mode 100644 test-suite/generated-src/swift/DataRefTest+Private.swift create mode 100644 test-suite/generated-src/swift/DataRefTest.swift create mode 100644 test-suite/generated-src/swift/DateRecord+Private.swift create mode 100644 test-suite/generated-src/swift/DateRecord.swift create mode 100644 test-suite/generated-src/swift/EmptyFlags+Private.swift create mode 100644 test-suite/generated-src/swift/EmptyFlags.swift create mode 100644 test-suite/generated-src/swift/EmptyRecord+Private.swift create mode 100644 test-suite/generated-src/swift/EmptyRecord.swift create mode 100644 test-suite/generated-src/swift/EnumUsageInterface+Private.swift create mode 100644 test-suite/generated-src/swift/EnumUsageInterface.swift create mode 100644 test-suite/generated-src/swift/EnumUsageRecord+Private.swift create mode 100644 test-suite/generated-src/swift/EnumUsageRecord.swift create mode 100644 test-suite/generated-src/swift/ExtendedRecord+Private.swift create mode 100644 test-suite/generated-src/swift/ExtendedRecord.swift create mode 100644 test-suite/generated-src/swift/ExternInterface1+Private.swift create mode 100644 test-suite/generated-src/swift/ExternInterface1.swift create mode 100644 test-suite/generated-src/swift/ExternInterface2+Private.swift create mode 100644 test-suite/generated-src/swift/ExternInterface2.swift create mode 100644 test-suite/generated-src/swift/ExternRecordWithDerivings+Private.swift create mode 100644 test-suite/generated-src/swift/ExternRecordWithDerivings.swift create mode 100644 test-suite/generated-src/swift/FirstListener+Private.swift create mode 100644 test-suite/generated-src/swift/FirstListener.swift create mode 100644 test-suite/generated-src/swift/FlagRoundtrip+Private.swift create mode 100644 test-suite/generated-src/swift/FlagRoundtrip.swift create mode 100644 test-suite/generated-src/swift/InterfaceUsingExtendedRecord+Private.swift create mode 100644 test-suite/generated-src/swift/InterfaceUsingExtendedRecord.swift create mode 100644 test-suite/generated-src/swift/JavaOnlyListener+Private.swift create mode 100644 test-suite/generated-src/swift/JavaOnlyListener.swift create mode 100644 test-suite/generated-src/swift/ListenerCaller+Private.swift create mode 100644 test-suite/generated-src/swift/ListenerCaller.swift create mode 100644 test-suite/generated-src/swift/MapDateRecord+Private.swift create mode 100644 test-suite/generated-src/swift/MapDateRecord.swift create mode 100644 test-suite/generated-src/swift/MapListRecord+Private.swift create mode 100644 test-suite/generated-src/swift/MapListRecord.swift create mode 100644 test-suite/generated-src/swift/MapRecord+Private.swift create mode 100644 test-suite/generated-src/swift/MapRecord.swift create mode 100644 test-suite/generated-src/swift/NestedCollection+Private.swift create mode 100644 test-suite/generated-src/swift/NestedCollection.swift create mode 100644 test-suite/generated-src/swift/NestedOutcome+Private.swift create mode 100644 test-suite/generated-src/swift/NestedOutcome.swift create mode 100644 test-suite/generated-src/swift/ObjcOnlyListener+Private.swift create mode 100644 test-suite/generated-src/swift/ObjcOnlyListener.swift create mode 100644 test-suite/generated-src/swift/PrimitiveList+Private.swift create mode 100644 test-suite/generated-src/swift/PrimitiveList.swift create mode 100644 test-suite/generated-src/swift/ProtoTests+Private.swift create mode 100644 test-suite/generated-src/swift/ProtoTests.swift create mode 100644 test-suite/generated-src/swift/RecordUsingExtendedRecord+Private.swift create mode 100644 test-suite/generated-src/swift/RecordUsingExtendedRecord.swift create mode 100644 test-suite/generated-src/swift/RecordWithDerivings+Private.swift create mode 100644 test-suite/generated-src/swift/RecordWithDerivings.swift create mode 100644 test-suite/generated-src/swift/RecordWithDurationAndDerivings+Private.swift create mode 100644 test-suite/generated-src/swift/RecordWithDurationAndDerivings.swift create mode 100644 test-suite/generated-src/swift/RecordWithEmbeddedCppProto+Private.swift create mode 100644 test-suite/generated-src/swift/RecordWithEmbeddedCppProto.swift create mode 100644 test-suite/generated-src/swift/RecordWithEmbeddedProto+Private.swift create mode 100644 test-suite/generated-src/swift/RecordWithEmbeddedProto.swift create mode 100644 test-suite/generated-src/swift/RecordWithFlags+Private.swift create mode 100644 test-suite/generated-src/swift/RecordWithFlags.swift create mode 100644 test-suite/generated-src/swift/RecordWithNestedDerivings+Private.swift create mode 100644 test-suite/generated-src/swift/RecordWithNestedDerivings.swift create mode 100644 test-suite/generated-src/swift/ReturnOne+Private.swift create mode 100644 test-suite/generated-src/swift/ReturnOne.swift create mode 100644 test-suite/generated-src/swift/ReturnTwo+Private.swift create mode 100644 test-suite/generated-src/swift/ReturnTwo.swift create mode 100644 test-suite/generated-src/swift/ReverseClientInterface+Private.swift create mode 100644 test-suite/generated-src/swift/ReverseClientInterface.swift create mode 100644 test-suite/generated-src/swift/SampleInterface+Private.swift create mode 100644 test-suite/generated-src/swift/SampleInterface.swift create mode 100644 test-suite/generated-src/swift/SecondListener+Private.swift create mode 100644 test-suite/generated-src/swift/SecondListener.swift create mode 100644 test-suite/generated-src/swift/SetRecord+Private.swift create mode 100644 test-suite/generated-src/swift/SetRecord.swift create mode 100644 test-suite/generated-src/swift/SupportCopying+Private.swift create mode 100644 test-suite/generated-src/swift/SupportCopying.swift create mode 100644 test-suite/generated-src/swift/TestArray+Private.swift create mode 100644 test-suite/generated-src/swift/TestArray.swift create mode 100644 test-suite/generated-src/swift/TestDuration+Private.swift create mode 100644 test-suite/generated-src/swift/TestDuration.swift create mode 100644 test-suite/generated-src/swift/TestHelpers+Private.swift create mode 100644 test-suite/generated-src/swift/TestHelpers.swift create mode 100644 test-suite/generated-src/swift/TestOptionalExternInterfaceRecord+Private.swift create mode 100644 test-suite/generated-src/swift/TestOptionalExternInterfaceRecord.swift create mode 100644 test-suite/generated-src/swift/TestOutcome+Private.swift create mode 100644 test-suite/generated-src/swift/TestOutcome.swift create mode 100644 test-suite/generated-src/swift/TestStaticMethodLanguage+Private.swift create mode 100644 test-suite/generated-src/swift/TestStaticMethodLanguage.swift create mode 100644 test-suite/generated-src/swift/ThrowingInterface+Private.swift create mode 100644 test-suite/generated-src/swift/ThrowingInterface.swift create mode 100644 test-suite/generated-src/swift/UserToken+Private.swift create mode 100644 test-suite/generated-src/swift/UserToken.swift create mode 100644 test-suite/generated-src/swift/UsesSingleLanguageListeners+Private.swift create mode 100644 test-suite/generated-src/swift/UsesSingleLanguageListeners.swift create mode 100644 test-suite/generated-src/swift/VarnameInterface+Private.swift create mode 100644 test-suite/generated-src/swift/VarnameInterface.swift create mode 100644 test-suite/generated-src/swift/VarnameRecord+Private.swift create mode 100644 test-suite/generated-src/swift/VarnameRecord.swift create mode 100644 test-suite/generated-src/swift/Vec2+Private.swift create mode 100644 test-suite/generated-src/swift/Vec2.swift create mode 100644 test-suite/generated-src/swift/WcharTestHelpers+Private.swift create mode 100644 test-suite/generated-src/swift/WcharTestHelpers.swift create mode 100644 test-suite/generated-src/swift/WcharTestRec+Private.swift create mode 100644 test-suite/generated-src/swift/WcharTestRec.swift create mode 100644 test-suite/generated-src/swiftxx/NativeAccessFlags.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeAccessFlags.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeAssortedPrimitives.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeAssortedPrimitives.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeAsyncInterface.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeAsyncInterface.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeClientInterface.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeClientInterface.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeClientReturnedRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeClientReturnedRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeColor.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeColor.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeConflict.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeConflict.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeConflictUser.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeConflictUser.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeConstantEnum.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeConstantEnum.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeConstantInterfaceWithEnum.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeConstantInterfaceWithEnum.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeConstantRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeConstantRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeConstantWithEnum.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeConstantWithEnum.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeConstants.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeConstants.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeConstantsInterface.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeConstantsInterface.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeCppException.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeCppException.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeDataRefTest.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeDataRefTest.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeDateRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeDateRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeEmptyFlags.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeEmptyFlags.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeEmptyRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeEmptyRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeEnumUsageInterface.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeEnumUsageInterface.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeEnumUsageRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeEnumUsageRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeExtendedRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeExtendedRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeExternInterface1.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeExternInterface1.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeExternInterface2.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeExternInterface2.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeExternRecordWithDerivings.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeExternRecordWithDerivings.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeFirstListener.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeFirstListener.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeFlagRoundtrip.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeFlagRoundtrip.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeInterfaceUsingExtendedRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeInterfaceUsingExtendedRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeJavaOnlyListener.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeJavaOnlyListener.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeListenerCaller.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeListenerCaller.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeMapDateRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeMapDateRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeMapListRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeMapListRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeMapRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeMapRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeNestedCollection.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeNestedCollection.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeNestedOutcome.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeNestedOutcome.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeObjcOnlyListener.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeObjcOnlyListener.hpp create mode 100644 test-suite/generated-src/swiftxx/NativePrimitiveList.cpp create mode 100644 test-suite/generated-src/swiftxx/NativePrimitiveList.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeProtoTests.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeProtoTests.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordUsingExtendedRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordUsingExtendedRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordWithDerivings.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordWithDerivings.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordWithDurationAndDerivings.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordWithDurationAndDerivings.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedCppProto.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedCppProto.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedProto.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedProto.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordWithFlags.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordWithFlags.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordWithNestedDerivings.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeRecordWithNestedDerivings.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeReturnOne.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeReturnOne.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeReturnTwo.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeReturnTwo.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeReverseClientInterface.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeReverseClientInterface.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeSampleInterface.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeSampleInterface.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeSecondListener.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeSecondListener.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeSetRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeSetRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeSupportCopying.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeSupportCopying.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeTestArray.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeTestArray.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeTestDuration.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeTestDuration.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeTestHelpers.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeTestHelpers.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeTestOptionalExternInterfaceRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeTestOptionalExternInterfaceRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeTestOutcome.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeTestOutcome.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeTestStaticMethodLanguage.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeTestStaticMethodLanguage.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeThrowingInterface.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeThrowingInterface.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeUserToken.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeUserToken.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeUsesSingleLanguageListeners.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeUsesSingleLanguageListeners.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeVarnameInterface.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeVarnameInterface.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeVarnameRecord.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeVarnameRecord.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeVec2.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeVec2.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeWcharTestHelpers.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeWcharTestHelpers.hpp create mode 100644 test-suite/generated-src/swiftxx/NativeWcharTestRec.cpp create mode 100644 test-suite/generated-src/swiftxx/NativeWcharTestRec.hpp create mode 100644 test-suite/handwritten-src/cpp/Duration-swift.hpp create mode 100644 test-suite/handwritten-src/swift/ArrayTest.swift create mode 100644 test-suite/handwritten-src/swift/AsyncTest.swift create mode 100644 test-suite/handwritten-src/swift/ClientInterfaceTest.swift create mode 100644 test-suite/handwritten-src/swift/ConstantsTest.swift create mode 100644 test-suite/handwritten-src/swift/CppExceptionTest.swift create mode 100644 test-suite/handwritten-src/swift/DataTest.swift create mode 100644 test-suite/handwritten-src/swift/Duration+Helper.swift create mode 100644 test-suite/handwritten-src/swift/DurationTest.swift create mode 100644 test-suite/handwritten-src/swift/EnumTest.swift rename test-suite/handwritten-src/swift/{AllTests.swift => ExampleTest.swift} (70%) create mode 100644 test-suite/handwritten-src/swift/MapRecordTest.swift create mode 100644 test-suite/handwritten-src/swift/NestedCollectionTest.swift create mode 100644 test-suite/handwritten-src/swift/OutcomeTest+Error.swift create mode 100644 test-suite/handwritten-src/swift/OutcomeTest.swift create mode 100644 test-suite/handwritten-src/swift/PrimitiveListTest.swift create mode 100644 test-suite/handwritten-src/swift/PrimitivesTest.swift create mode 100644 test-suite/handwritten-src/swift/ProtoTest.swift create mode 100644 test-suite/handwritten-src/swift/SetRecordTest.swift create mode 100644 test-suite/handwritten-src/swift/TokenTest.swift create mode 100644 test-suite/handwritten-src/swift/WcharTest.swift diff --git a/bzl/deps.bzl b/bzl/deps.bzl index f39e1185..35889a85 100644 --- a/bzl/deps.bzl +++ b/bzl/deps.bzl @@ -47,3 +47,18 @@ def djinni_deps(): url = "https://github.com/bazelbuild/rules_jvm_external/archive/{}.zip".format(rules_jvm_external_tag), sha256 = "62133c125bf4109dfd9d2af64830208356ce4ef8b165a6ef15bbff7460b35c3a", ) + swiftprotobuf_version = "1.27.0" + maybe( + name = "apple_swift_protobuf", + repo_rule = http_archive, + url = "https://github.com/apple/swift-protobuf/archive/refs/tags/{}.tar.gz".format(swiftprotobuf_version), + strip_prefix = "swift-protobuf-{}".format(swiftprotobuf_version), + sha256 = "387ab60f4814e76ed3ae689690c658cf6dab1bc1c6ed67d6c14c33de9daed4d2", + build_file_content = """ +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") +swift_library( + name = "swift-protobuf", + module_name = "SwiftProtobuf", + srcs = glob(["Sources/SwiftProtobuf/**/*.swift"]), + visibility = ["//visibility:public"], +)""") diff --git a/examples/generated-src/swift/ItemList+Private.swift b/examples/generated-src/swift/ItemList+Private.swift index accd5600..d31eccc5 100644 --- a/examples/generated-src/swift/ItemList+Private.swift +++ b/examples/generated-src/swift/ItemList+Private.swift @@ -2,6 +2,7 @@ // This file was generated by Djinni from example.djinni import DjinniSupport +import Foundation import DjinniSupportCxx import TextSort diff --git a/examples/generated-src/swift/ItemList.swift b/examples/generated-src/swift/ItemList.swift index 1f39d371..a7a787b7 100644 --- a/examples/generated-src/swift/ItemList.swift +++ b/examples/generated-src/swift/ItemList.swift @@ -1,6 +1,8 @@ // AUTOGENERATED FILE - DO NOT MODIFY! // This file was generated by Djinni from example.djinni +import Foundation + public struct ItemList { public var items: Array diff --git a/examples/generated-src/swift/SortItems+Private.swift b/examples/generated-src/swift/SortItems+Private.swift index d18e1556..f654a427 100644 --- a/examples/generated-src/swift/SortItems+Private.swift +++ b/examples/generated-src/swift/SortItems+Private.swift @@ -3,36 +3,43 @@ import DjinniSupport import DjinniSupportCxx +import Foundation import TextSort import TextSortCxx -final class CppProxy: DjinniSupport.CppProxy, SortItems { - func sort(order: SortOrder, items: ItemList) -> Void { +final class SortItemsCppProxy: DjinniSupport.CppProxy, SortItems { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func sort(order: TextSort.SortOrder, items: TextSort.ItemList) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(SortOrderMarshaller.toCpp(order)) params.addValue(ItemListMarshaller.toCpp(items)) - djinni_generated.SortItems_sort(¶ms) + var ret = djinni_generated.SortItems_sort(¶ms) + try handleCppErrors(&ret) } } enum SortItemsMarshaller: DjinniSupport.Marshaller { typealias SwiftType = SortItems static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { - return cppInterfaceToSwift(c, { CppProxy(c) }) + return cppInterfaceToSwift(c, { SortItemsCppProxy(c) as SwiftType }) } static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class SortItems_statics { - static func createWithListener(listener: TextboxListener) -> SortItems { + static func createWithListener(listener: TextSort.TextboxListener) throws -> TextSort.SortItems { var params = djinni.swift.ParameterList() params.addValue(TextboxListenerMarshaller.toCpp(listener)) - return SortItemsMarshaller.fromCpp(djinni_generated.SortItems_createWithListener(¶ms)) + var ret = djinni_generated.SortItems_createWithListener(¶ms) + try handleCppErrors(&ret) + return SortItemsMarshaller.fromCpp(ret) } - static func runSort(items: ItemList) -> ItemList { + static func runSort(items: TextSort.ItemList) throws -> TextSort.ItemList { var params = djinni.swift.ParameterList() params.addValue(ItemListMarshaller.toCpp(items)) - return ItemListMarshaller.fromCpp(djinni_generated.SortItems_runSort(¶ms)) + var ret = djinni_generated.SortItems_runSort(¶ms) + try handleCppErrors(&ret) + return ItemListMarshaller.fromCpp(ret) } } diff --git a/examples/generated-src/swift/SortItems.swift b/examples/generated-src/swift/SortItems.swift index 38a31719..d4aace50 100644 --- a/examples/generated-src/swift/SortItems.swift +++ b/examples/generated-src/swift/SortItems.swift @@ -1,7 +1,9 @@ // AUTOGENERATED FILE - DO NOT MODIFY! // This file was generated by Djinni from example.djinni +import Foundation + public protocol SortItems: AnyObject { /** For the iOS / Android demo */ - func sort(order: SortOrder, items: ItemList) -> Void + func sort(order: TextSort.SortOrder, items: TextSort.ItemList) throws -> Void } diff --git a/examples/generated-src/swift/SortOrder.swift b/examples/generated-src/swift/SortOrder.swift index afb553ff..5b5f84b4 100644 --- a/examples/generated-src/swift/SortOrder.swift +++ b/examples/generated-src/swift/SortOrder.swift @@ -2,7 +2,7 @@ // This file was generated by Djinni from example.djinni public enum SortOrder: Int32 { - case ASCENDING = 0 - case DESCENDING = 1 - case RANDOM = 2 + case ascending = 0 + case descending = 1 + case random = 2 } diff --git a/examples/generated-src/swift/TextboxListener+Private.swift b/examples/generated-src/swift/TextboxListener+Private.swift index c0259d68..3694bcba 100644 --- a/examples/generated-src/swift/TextboxListener+Private.swift +++ b/examples/generated-src/swift/TextboxListener+Private.swift @@ -3,13 +3,14 @@ import DjinniSupport import DjinniSupportCxx +import Foundation import TextSort import TextSortCxx let textboxListenerMethods: Vtbl = [ { inst, params, ret in let _items = ItemListMarshaller.fromCpp(djinni.swift.getMember(params, 0)) - inst.update(items: _items) + try inst.update(items: _items) }, ] diff --git a/examples/generated-src/swift/TextboxListener.swift b/examples/generated-src/swift/TextboxListener.swift index 57c08932..8e4665dc 100644 --- a/examples/generated-src/swift/TextboxListener.swift +++ b/examples/generated-src/swift/TextboxListener.swift @@ -1,6 +1,8 @@ // AUTOGENERATED FILE - DO NOT MODIFY! // This file was generated by Djinni from example.djinni +import Foundation + public protocol TextboxListener: AnyObject { - func update(items: ItemList) -> Void + func update(items: TextSort.ItemList) throws -> Void } diff --git a/examples/generated-src/swiftxx/SwiftSortItems.cpp b/examples/generated-src/swiftxx/SwiftSortItems.cpp index 7898f6c1..54d1734d 100644 --- a/examples/generated-src/swiftxx/SwiftSortItems.cpp +++ b/examples/generated-src/swiftxx/SwiftSortItems.cpp @@ -8,22 +8,31 @@ namespace djinni_generated { -djinni::swift::AnyValue SortItems_sort(const djinni::swift::ParameterList* params) { +djinni::swift::AnyValue SortItems_sort(const djinni::swift::ParameterList* params) try { auto inst = SwiftSortItems::toCpp(params->getValue(0)); auto _order = ::djinni_generated::SwiftSortOrder::toCpp(params->getValue(1)); auto _items = ::djinni_generated::SwiftItemList::toCpp(params->getValue(2)); - inst->sort(_order, _items); + inst->sort(std::move(_order), std::move(_items)); return djinni::swift::makeVoidValue(); } -djinni::swift::AnyValue SortItems_createWithListener(const djinni::swift::ParameterList* params) { +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue SortItems_createWithListener(const djinni::swift::ParameterList* params) try { auto _listener = ::djinni_generated::SwiftTextboxListener::toCpp(params->getValue(0)); - auto ret = ::textsort::SortItems::create_with_listener(_listener); + auto ret = ::textsort::SortItems::create_with_listener(std::move(_listener)); return ::djinni_generated::SwiftSortItems::fromCpp(ret); } -djinni::swift::AnyValue SortItems_runSort(const djinni::swift::ParameterList* params) { +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue SortItems_runSort(const djinni::swift::ParameterList* params) try { auto _items = ::djinni_generated::SwiftItemList::toCpp(params->getValue(0)); - auto ret = ::textsort::SortItems::run_sort(_items); + auto ret = ::textsort::SortItems::run_sort(std::move(_items)); return ::djinni_generated::SwiftItemList::fromCpp(ret); } +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} } // namespace djinni_generated diff --git a/src/source/ComposerGenerator.scala b/src/source/ComposerGenerator.scala index 81ec1935..031c851f 100644 --- a/src/source/ComposerGenerator.scala +++ b/src/source/ComposerGenerator.scala @@ -116,7 +116,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { case MMap => assert(tm.args.size == 2) f - case MProtobuf(name, _, ProtobufMessage(cpp,_,_,Some(ts))) => + case MProtobuf(name, _, ProtobufMessage(cpp,_,_,Some(ts),_)) => assert(tm.args.size == 0) val tsname = if (ts.ns.isEmpty) name else ts.ns + "." + name s"""<${withNs(Some(cpp.ns), name)}, ${jsClassNameAsCppType(tsname)}>""" diff --git a/src/source/CppGenerator.scala b/src/source/CppGenerator.scala index 31b0e709..77c2a41d 100644 --- a/src/source/CppGenerator.scala +++ b/src/source/CppGenerator.scala @@ -49,10 +49,12 @@ class CppGenerator(spec: Spec) extends Generator(spec) { case ImportRef(arg) => hpp.add("#include " + arg) case DeclRef(decl, Some(spec.cppNamespace)) => hppFwds.add(decl) case DeclRef(_, _) => + case _ => } for(r <- marshal.cppReferences(m, name, forwardDeclareOnly)) r match { case ImportRef(arg) => cpp.add("#include " + arg) case DeclRef(_, _) => + case _ => } } } diff --git a/src/source/ObjcGenerator.scala b/src/source/ObjcGenerator.scala index 079cc982..d25b48b3 100644 --- a/src/source/ObjcGenerator.scala +++ b/src/source/ObjcGenerator.scala @@ -42,6 +42,7 @@ class ObjcGenerator(spec: Spec) extends BaseObjcGenerator(spec) { def find(m: Meta) = for(r <- marshal.references(m)) r match { case ImportRef(arg) => header.add("#import " + arg) case DeclRef(decl, _) => header.add(decl) + case _ => } } diff --git a/src/source/ObjcMarshal.scala b/src/source/ObjcMarshal.scala index 92aa0d94..4acf7c1a 100644 --- a/src/source/ObjcMarshal.scala +++ b/src/source/ObjcMarshal.scala @@ -34,7 +34,7 @@ class ObjcMarshal(spec: Spec) extends Marshal(spec) { def fqTypename(name: String, ty: TypeDef): String = typename(name, ty) def cppProtoType(tm: MExpr):Option[String] = tm.base match { - case MProtobuf(name, _, ProtobufMessage(cpp, _, None, _)) => Some(cpp.ns + "::" + name) + case MProtobuf(name, _, ProtobufMessage(cpp, _, None, _, _)) => Some(cpp.ns + "::" + name) case _ => None } @@ -55,7 +55,7 @@ class ObjcMarshal(spec: Spec) extends Marshal(spec) { case DInterface => interfaceNullity case DRecord => if(e.objc.pointer) nonnull else None } - case MProtobuf(_, _, ProtobufMessage(_, _, None, _)) => None + case MProtobuf(_, _, ProtobufMessage(_, _, None, _, _)) => None case _ => nonnull } } @@ -195,7 +195,7 @@ class ObjcMarshal(spec: Spec) extends Marshal(spec) { def toBoxedParamType(tm: MExpr): String = { tm.base match { - case MProtobuf(_, _, ProtobufMessage(_, _, None,_)) => + case MProtobuf(_, _, ProtobufMessage(_, _, None,_, _)) => throw new AssertionError("C++ proto types are not compatible with generics") case _ => { val (name, needRef) = toObjcType(tm, true) diff --git a/src/source/SwiftGenerator.scala b/src/source/SwiftGenerator.scala index c0386004..b2bbf307 100644 --- a/src/source/SwiftGenerator.scala +++ b/src/source/SwiftGenerator.scala @@ -125,6 +125,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { class SwiftRefs(name: String) { var swiftImports = mutable.TreeSet[String]() + var privateImports = mutable.TreeSet[String]("DjinniSupport", "Foundation",spec.swiftxxBaseLibModule, spec.swiftModule, spec.swiftModule + "Cxx") swiftImports.add("Foundation") def find(ty: TypeRef) { find(ty.resolved) } def find(tm: MExpr) { @@ -132,22 +133,61 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { find(tm.base) } def find(m: Meta) = for(r <- marshal.references(m, name)) r match { - case ImportRef(arg) => swiftImports.add(arg) + // don't import empty module name (e.g. types defined in stdlib) or same module as the current one + case ImportRef(arg) => if (arg.nonEmpty && arg != spec.swiftModule) { swiftImports.add(arg) } + case PrivateImportRef(arg) => if (arg.nonEmpty && arg != spec.swiftModule) { privateImports.add(arg) } case _ => } } + def generateSwiftConstants(w: IndentWriter, consts: Seq[Const]) = { + + def writeSwiftConst(w: IndentWriter, ty: TypeRef, v: Any): Unit = v match { + case l: Long => w.w(l.toString) + case d: Double => w.w(d.toString) + case b: Boolean => w.w(if (b) "true" else "false") + case s: String => w.w(s) + case e: EnumValue => w.w(s"${marshal.typename(ty)}.${idSwift.enum(e)}") + case v: ConstRef => w.w(idSwift.const(v)) + case z: Map[_, _] => { // Value is record + val recordMdef = ty.resolved.base.asInstanceOf[MDef] + val record = recordMdef.body.asInstanceOf[Record] + val vMap = z.asInstanceOf[Map[String, Any]] + w.wl(s"${marshal.typename(ty)}(") + w.increase() + // Use exact sequence + val skipFirst = SkipFirst() + for (f <- record.fields) { + skipFirst {w.wl(",")} + w.w(idSwift.field(f.ident) + ":") + writeSwiftConst(w, f.ty, vMap.apply(f.ident.name)) + } + w.w(")") + w.decrease() + } + } + + for (c <- consts) { + writeDoc(w, c.doc) + w.w(s"public static let ${idSwift.const(c.ident)}: ${marshal.fieldType(c.ty)} = ") + writeSwiftConst(w, c.ty, c.value) + w.wl + } + } + override def generateRecord(origin: String, ident: Ident, doc: Doc, params: Seq[TypeParam], r: Record) { val refs = new SwiftRefs(ident.name) r.fields.foreach(f => refs.find(f.ty)) writeSwiftFile(ident, origin, refs.swiftImports, w => { writeDoc(w, doc) - w.w(s"public struct ${marshal.typename(ident, r)}").braced { + val eqClause = if (r.derivingTypes.contains(DerivingType.Eq)) ": Equatable" else "" + w.w(s"public struct ${marshal.typename(ident, r)}${eqClause}").braced { + generateSwiftConstants(w, r.consts) for (f <- r.fields) { writeDoc(w, f.doc) - w.wl(s"public var ${idSwift.field(f.ident)}: ${marshal.fieldType(f.ty)}") + w.wl(s"public var ${idSwift.field(f.ident)}: ${marshal.fqFieldType(f.ty)}") } - val initParams = r.fields.map(f => s"${idSwift.field(f.ident)}: ${marshal.fieldType(f.ty)}").mkString(", ") + val initParams = r.fields.map(f => s"${idSwift.field(f.ident)}: ${marshal.fqFieldType(f.ty)}").mkString(", ") w.wl w.wl(s"public init(${initParams})").braced { for (f <- r.fields) { @@ -156,10 +196,9 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { } } }) - writeSwiftPrivateFile(ident, origin, List[String]("DjinniSupport", "Foundation", spec.swiftxxBaseLibModule, spec.swiftModule), w => { - val t = marshal.typename(ident, r) - w.w(s"enum ${t}Marshaller: DjinniSupport.Marshaller").braced { - w.wl(s"typealias SwiftType = $t") + writeSwiftPrivateFile(ident, origin, refs.privateImports, w => { + w.w(s"enum ${marshal.typename(ident, r)}Marshaller: DjinniSupport.Marshaller").braced { + w.wl(s"typealias SwiftType = ${marshal.fqTypename(ident, r)}") w.w("static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced { w.wl("return withUnsafePointer(to: c) { p in").nested { for ((f, i) <- r.fields.view.zipWithIndex) { @@ -201,30 +240,30 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { for (m <- i.methods.filter(!_.static)) { writeMethodDoc(w, m, idSwift.local) w.w(s"func ${swiftMethodName(m.ident)}(") - w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.paramType(p.ty)}").mkString(", ")) - w.wl(s") -> ${marshal.returnType(m.ret)}") + w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.fqParamType(p.ty)}").mkString(", ")) + w.wl(s") throws -> ${marshal.fqReturnType(m.ret)}") } } }) - writeSwiftPrivateFile(ident, origin, List[String]("DjinniSupport", "Foundation",spec.swiftxxBaseLibModule, spec.swiftModule, spec.swiftModule + "Cxx"), w => { + writeSwiftPrivateFile(ident, origin, refs.privateImports, w => { writeDoc(w, doc) // Define CppProxy class if interface is implemented in C++ if (i.ext.cpp) { - w.w(s"final class ${marshal.typename(ident, i)}CppProxy: DjinniSupport.CppProxy, ${marshal.typename(ident, i)}").braced { + w.w(s"final class ${marshal.typename(ident, i)}CppProxy: DjinniSupport.CppProxy, ${marshal.fqTypename(ident, i)}").braced { + w.wl("init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } ") for (m <- i.methods.filter(!_.static)) { w.w(s"func ${swiftMethodName(m.ident)}(") - w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.paramType(p.ty)}").mkString(", ")) - w.w(s") -> ${marshal.returnType(m.ret)}").braced { + w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.fqParamType(p.ty)}").mkString(", ")) + w.w(s") throws -> ${marshal.fqReturnType(m.ret)}").braced { w.wl("var params = djinni.swift.ParameterList()") w.wl("params.addValue(inst)") for (p <- m.params) { w.wl(s"params.addValue(${marshal.toCpp(p.ty, idSwift.local(p.ident))})") } - val call = s"${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(¶ms)" - if (m.ret.isEmpty) { - w.wl(call) - } else { - w.wl(s"return ${marshal.fromCpp(m.ret.get, call)}") + w.wl(s"var ret = ${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(¶ms)") + w.wl("try handleCppErrors(&ret)") + if (!m.ret.isEmpty) { + w.wl(s"return ${marshal.fromCpp(m.ret.get, "ret")}") } } } @@ -244,9 +283,9 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { val args = m.params.map(p => s"${idSwift.local(p.ident)}: _${idSwift.local(p.ident)}").mkString(", ") val call = s"inst.${swiftMethodName(m.ident)}(${args})" if (m.ret.isEmpty) { - w.wl(call) + w.wl("try " + call) } else { - w.wl(s"djinni.swift.setReturnValue(ret, ${marshal.toCpp(m.ret.get, call)})") + w.wl(s"djinni.swift.setReturnValue(ret, try ${marshal.toCpp(m.ret.get, call)})") } } w.wl("},") @@ -257,9 +296,9 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { } // Define the marshaller w.w(s"enum ${marshal.typename(ident, i)}Marshaller: DjinniSupport.Marshaller").braced { - w.wl(s"typealias SwiftType = ${marshal.typename(ident, i)}") + w.wl(s"typealias SwiftType = ${marshal.fqTypename(ident, i)}") w.w("static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced { - val newProxyBlock = if (i.ext.cpp) {s"{ ${marshal.typename(ident, i)}CppProxy(c) }"} else {"{ fatalError(\"n/a\") }"} + val newProxyBlock = if (i.ext.cpp) {s"{ ${marshal.typename(ident, i)}CppProxy(c) as SwiftType }"} else {"{ fatalError(\"n/a\") }"} w.wl(s"return cppInterfaceToSwift(c, ${newProxyBlock})") } w.w("static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced { @@ -268,22 +307,21 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { } } // Define static method stubs - val staticMethods = i.methods.filter(_.static) + val staticMethods = i.methods.filter(m => m.static && m.lang.swift) if (!staticMethods.isEmpty) { w.w(s"public class ${marshal.typename(ident, i)}_statics").braced { for (m <- staticMethods) { w.w(s"static func ${swiftMethodName(m.ident)}(") - w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.paramType(p.ty)}").mkString(", ")) - w.w(s") -> ${marshal.returnType(m.ret)}").braced { + w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.fqParamType(p.ty)}").mkString(", ")) + w.w(s") throws -> ${marshal.fqReturnType(m.ret)}").braced { w.wl("var params = djinni.swift.ParameterList()") for (p <- m.params) { w.wl(s"params.addValue(${marshal.toCpp(p.ty, idSwift.local(p.ident))})") } - val call = s"${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(¶ms)" - if (m.ret.isEmpty) { - w.wl(call) - } else { - w.wl(s"return ${marshal.fromCpp(m.ret.get, call)}") + w.wl(s"var ret = ${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(¶ms)") + w.wl("try handleCppErrors(&ret)") + if (!m.ret.isEmpty) { + w.wl(s"return ${marshal.fromCpp(m.ret.get, "ret")}") } } } diff --git a/src/source/SwiftMarshal.scala b/src/source/SwiftMarshal.scala index b937d577..fd52068d 100644 --- a/src/source/SwiftMarshal.scala +++ b/src/source/SwiftMarshal.scala @@ -24,25 +24,27 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { override def typename(tm: MExpr): String = toSwiftType(tm, None) def typename(name: String, ty: TypeDef): String = idSwift.ty(name) - override def fqTypename(tm: MExpr): String = toSwiftType(tm, None) - def fqTypename(name: String, ty: TypeDef): String = idSwift.ty(name) + override def fqTypename(tm: MExpr): String = toSwiftType(tm, Some(spec.swiftModule)) + def fqTypename(name: String, ty: TypeDef): String = withPackage(Some(spec.swiftModule), idSwift.ty(name)) override def paramType(tm: MExpr): String = toSwiftType(tm, None) - override def fqParamType(tm: MExpr): String = toSwiftType(tm, None) + override def fqParamType(tm: MExpr): String = toSwiftType(tm, Some(spec.swiftModule)) override def returnType(ret: Option[TypeRef]): String = ret.fold("Void")(ty => toSwiftType(ty.resolved, None)) - override def fqReturnType(ret: Option[TypeRef]): String = ret.fold("Void")(ty => toSwiftType(ty.resolved, None)) + override def fqReturnType(ret: Option[TypeRef]): String = ret.fold("Void")(ty => toSwiftType(ty.resolved, Some(spec.swiftModule))) override def fieldType(tm: MExpr): String = toSwiftType(tm, None) - override def fqFieldType(tm: MExpr): String = toSwiftType(tm, spec.javaPackage) + override def fqFieldType(tm: MExpr): String = toSwiftType(tm, Some(spec.swiftModule)) override def toCpp(tm: MExpr, expr: String): String = s"${helperClass(tm)}.toCpp(${expr})" override def fromCpp(tm: MExpr, expr: String): String = s"${helperClass(tm)}.fromCpp(${expr})" + private def withPackage(packageName: Option[String], t: String) = packageName.fold(t)(_ + "." + t) + def references(m: Meta, exclude: String = ""): Seq[SymbolReference] = m match { - case p: MProtobuf => List() + case MProtobuf(name, _, ProtobufMessage(_,_,_,_,Some(swift))) => List(ImportRef(swift.module), PrivateImportRef(swift.module)) case d: MDef => List() - case e: MExtern => List(ImportRef(e.swift.module)) + case e: MExtern => List(ImportRef(e.swift.module), PrivateImportRef(e.swift.translatorModule)) case _ => List() } @@ -58,8 +60,10 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { case m => s"Optional<${f(arg)}>" } case e: MExtern => e.swift.typename + (if (e.swift.generic) args(tm) else "") - // case e: MExtern => throw new AssertionError("TODO") - case p: MProtobuf => p.name + case p: MProtobuf => p.body.swift match { + case Some(o) => o.prefix + p.name + case None => p.name + } case o => val base = o match { case p: MPrimitive => swiftPrimitiveType(p) @@ -71,7 +75,7 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { case MArray => "Array" case MSet => "Set" case MMap => "Dictionary" - case d: MDef => idSwift.ty(d.name) + case d: MDef => withPackage(packageName, idSwift.ty(d.name)) case e: MExtern => throw new AssertionError("unreachable") case e: MProtobuf => throw new AssertionError("unreachable") case p: MParam => idSwift.typeParam(p.name) @@ -116,7 +120,10 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { case MList => "ListMarshaller" case MSet => "SetMarshaller" case MMap => "MapMarshaller" - case MProtobuf(_,_,_) => "ProtobufMarshaller" + case p: MProtobuf => p.body.swift match { + case Some(o) => "ProtobufMarshaller<" + o.prefix + p.name + ">" + case None => s"[invalid protobuf: ${p.name}]" + } case MArray => "ArrayMarshaller" case d: MDef => throw new AssertionError("unreachable") case e: MExtern => throw new AssertionError("unreachable") diff --git a/src/source/SwiftxxGenerator.scala b/src/source/SwiftxxGenerator.scala index 5d3d8cbf..f7125531 100644 --- a/src/source/SwiftxxGenerator.scala +++ b/src/source/SwiftxxGenerator.scala @@ -81,7 +81,7 @@ class SwiftxxGenerator(spec: Spec) extends Generator(spec) { w.wl("auto ret = std::make_shared();") for (f <- r.fields) { val member = s"c.${idCpp.field(f.ident)}" - w.wl(s"ret->addValue(${marshal.fromCpp(f.ty, member)});") + w.wl(s"ret->addValue(${marshal.fromCpp(f.ty, cppMarshal.maybeMove(member, f.ty))});") } w.wl("return {ret};") } @@ -110,10 +110,8 @@ class SwiftxxGenerator(spec: Spec) extends Generator(spec) { w.wl(s"using ${spec.swiftxxClassIdentStyle(ident)} = djinni::swift::Interface<${cppMarshal.fqTypename(ident, i)}>;") if (i.ext.cpp) { w.wl - i.methods.foreach(m => { - if (m.static || m.lang.swift) { - w.wl(s"djinni::swift::AnyValue ${idSwift.ty(ident)}_${idSwift.method(m.ident)}(const djinni::swift::ParameterList* params);") - } + i.methods.filter(m => !m.static || (m.static && m.lang.swift)).foreach(m => { + w.wl(s"djinni::swift::AnyValue ${idSwift.ty(ident)}_${idSwift.method(m.ident)}(const djinni::swift::ParameterList* params);") }) } if (i.ext.swift) { @@ -135,37 +133,38 @@ class SwiftxxGenerator(spec: Spec) extends Generator(spec) { }) writeSwiftCppFile(ident, origin, refs.swiftCpp, w => { if (i.ext.cpp) { - i.methods.foreach(m => { - if (m.static || m.lang.swift) { - w.w(s"djinni::swift::AnyValue ${idSwift.ty(ident)}_${idSwift.method(m.ident)}(const djinni::swift::ParameterList* params)").braced { - // get self - if (!m.static) { - w.wl(s"auto inst = ${marshal.helperClass(ident)}::toCpp(params->getValue(0));") - } - // get args - val iOffset = if (m.static) 0 else 1 - for ((p, i) <- m.params.view.zipWithIndex) { - val pi = s"params->getValue(${i + iOffset})" - w.wl(s"auto _${idCpp.local(p.ident)} = ${marshal.toCpp(p.ty, pi)};") - } - // make the call - if (!m.ret.isEmpty) { - w.w("auto ret = ") - } - if (m.static) { - w.w(s"${cppMarshal.fqTypename(ident, i)}::") - } else { - w.w("inst->") - } - val args = m.params.map(p => s"std::move(_${idCpp.local(p.ident)})").mkString(", ") - w.wl(s"${idCpp.method(m.ident)}($args);") - // return - if (m.ret.isEmpty) { - w.wl("return djinni::swift::makeVoidValue();") - } else { - w.wl("return " + marshal.fromCpp(m.ret.get, "ret") + ";") - } + i.methods.filter(m => !m.static || (m.static && m.lang.swift)).foreach(m => { + w.w(s"djinni::swift::AnyValue ${idSwift.ty(ident)}_${idSwift.method(m.ident)}(const djinni::swift::ParameterList* params) try").braced { + // get self + if (!m.static) { + w.wl(s"auto inst = ${marshal.helperClass(ident)}::toCpp(params->getValue(0));") + } + // get args + val iOffset = if (m.static) 0 else 1 + for ((p, i) <- m.params.view.zipWithIndex) { + val pi = s"params->getValue(${i + iOffset})" + w.wl(s"auto _${idCpp.local(p.ident)} = ${marshal.toCpp(p.ty, pi)};") + } + // make the call + if (!m.ret.isEmpty) { + w.w("auto ret = ") + } + if (m.static) { + w.w(s"${cppMarshal.fqTypename(ident, i)}::") + } else { + w.w("inst->") } + val args = m.params.map(p => s"std::move(_${idCpp.local(p.ident)})").mkString(", ") + w.wl(s"${idCpp.method(m.ident)}($args);") + // return + if (m.ret.isEmpty) { + w.wl("return djinni::swift::makeVoidValue();") + } else { + w.wl("return " + marshal.fromCpp(m.ret.get, cppMarshal.maybeMove("ret", m.ret.get)) + ";") + } + } + w.w("catch (const std::exception& e)").braced { + w.wl("return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}};") } }) } @@ -180,7 +179,7 @@ class SwiftxxGenerator(spec: Spec) extends Generator(spec) { w.w(s"$ret $proxy::${idCpp.method(m.ident)}${params.mkString("(", ", ", ")")}$constFlag").braced { w.wl("djinni::swift::ParameterList params;") for (p <- m.params) { - w.wl(s"params.addValue(${marshal.fromCpp(p.ty, idCpp.local(p.ident))});") + w.wl(s"params.addValue(${marshal.fromCpp(p.ty, cppMarshal.maybeMove(idCpp.local(p.ident), p.ty))});") } val call = s"callProtocol($idx, ¶ms)" if (m.ret.isEmpty) { diff --git a/src/source/SwiftxxMarshal.scala b/src/source/SwiftxxMarshal.scala index 476951b1..66c3f3e0 100644 --- a/src/source/SwiftxxMarshal.scala +++ b/src/source/SwiftxxMarshal.scala @@ -70,12 +70,15 @@ class SwiftxxMarshal(spec: Spec) extends Marshal(spec) { } case MOptional => "Optional" case MBinary => "Binary" - case MString => "String" + case MString => if (spec.cppUseWideStrings) "WString" else "String" case MDate => "Date" case MList => "List" case MSet => "Set" case MMap => "Map" - case MProtobuf(_,_,_) => "Protobuf" + case p: MProtobuf => p.body.swift match { + case Some(o) => "Protobuf" + "<" + withNs(Some(p.body.cpp.ns), p.name) + ">" + case None => s"[invalid protobuf: ${p.name}]" + } case MArray => "Array" case d: MDef => throw new AssertionError("unreachable") case e: MExtern => throw new AssertionError("unreachable") diff --git a/src/source/TsGenerator.scala b/src/source/TsGenerator.scala index 7632bf52..9a8fe699 100644 --- a/src/source/TsGenerator.scala +++ b/src/source/TsGenerator.scala @@ -120,7 +120,7 @@ class TsGenerator(spec: Spec, composerMode: Boolean) extends Generator(spec) { def references(m: Meta): Seq[TsSymbolRefBase] = m match { case e: MExtern => List(TsSymbolRef(idJs.ty(e.name), fixDjinniSupportModulePath(e.ts.module))) - case MProtobuf(name, _, ProtobufMessage(_,_,_,Some(ts))) => + case MProtobuf(name, _, ProtobufMessage(_,_,_,Some(ts),_)) => if (composerMode) List(ProtoSymbolRef(name, ts.module, ts.ns)) else List(TsSymbolRef(name, ts.module)) case _ => List() diff --git a/src/source/WasmGenerator.scala b/src/source/WasmGenerator.scala index bee87e5b..e648d2fd 100644 --- a/src/source/WasmGenerator.scala +++ b/src/source/WasmGenerator.scala @@ -80,7 +80,7 @@ class WasmGenerator(spec: Spec) extends Generator(spec) { case MMap => assert(tm.args.size == 2) f - case MProtobuf(name, _, ProtobufMessage(cpp,_,_,Some(ts))) => + case MProtobuf(name, _, ProtobufMessage(cpp,_,_,Some(ts),_)) => assert(tm.args.size == 0) val tsname = if (ts.ns.isEmpty) name else ts.ns + "." + name s"""<${withNs(Some(cpp.ns), name)}, ${jsClassNameAsCppType(tsname)}>""" diff --git a/src/source/YamlGenerator.scala b/src/source/YamlGenerator.scala index 290061cd..40678a51 100644 --- a/src/source/YamlGenerator.scala +++ b/src/source/YamlGenerator.scala @@ -86,6 +86,9 @@ class YamlGenerator(spec: Spec) extends Generator(spec) { if (spec.swiftOutFolder.isDefined) { w.wl("swift:").nested {write(w, swift(td))} } + if (spec.swiftxxOutFolder.isDefined) { + w.wl("swiftxx:").nested {write(w, swiftxx(td))} + } } private def write(w: IndentWriter, m: Map[String, Any]) { @@ -215,8 +218,14 @@ class YamlGenerator(spec: Spec) extends Generator(spec) { ) private def swift(td: TypeDecl) = Map[String, Any]( - "typename" -> QuotedString(swiftMarshal.fqTypename(td.ident, td.body)), - "module" -> QuotedString(spec.swiftModule) + "typename" -> QuotedString(swiftMarshal.typename(td.ident, td.body)), + "module" -> QuotedString(spec.swiftModule), + "translator" -> QuotedString(swiftMarshal.helperName(mexpr(td))), + "translator.module" -> QuotedString(spec.swiftModule) + ) + private def swiftxx(td: TypeDecl) = Map[String, Any]( + "translator" -> QuotedString(swiftxxMarshal.helperName(mexpr(td))), + "header" -> QuotedString(swiftxxMarshal.include(td.ident)) ) // TODO: there has to be a way to do all this without the MExpr/Meta conversions? @@ -308,8 +317,9 @@ object YamlGenerator { getOptionalField(td, "ts", "generic", false)), MExtern.Swift( getOptionalField(td, "swift", "typename"), - getOptionalField(td, "swift", "module"), + getOptionalField(td, "swift", "module", ""), getOptionalField(td, "swift", "translator"), + getOptionalField(td, "swift", "translator.module", ""), getOptionalField(td, "swift", "generic", false)), MExtern.Swiftxx( getOptionalField(td, "swiftxx", "translator"), @@ -331,8 +341,7 @@ object YamlGenerator { nested(td, key)(subKey).toString } catch { case e: java.util.NoSuchElementException => { - // println(s"Warning: in ${td.origin}, missing field $key/$subKey") - "[unspecified]" + s"[unspecified field `$key/$subKey` in `${td.origin}`]" } } } diff --git a/src/source/ast.scala b/src/source/ast.scala index ab186c07..9adcfa97 100644 --- a/src/source/ast.scala +++ b/src/source/ast.scala @@ -97,10 +97,11 @@ object Interface { case class Field(ident: Ident, ty: TypeRef, doc: Doc) -case class ProtobufMessage(cpp: ProtobufMessage.Cpp, java: ProtobufMessage.Java, objc: Option[ProtobufMessage.Objc], ts: Option[ProtobufMessage.Ts]) extends TypeDef +case class ProtobufMessage(cpp: ProtobufMessage.Cpp, java: ProtobufMessage.Java, objc: Option[ProtobufMessage.Objc], ts: Option[ProtobufMessage.Ts], swift: Option[ProtobufMessage.Swift]) extends TypeDef object ProtobufMessage { case class Cpp(header: String, ns: String) case class Java(pkg: String, jniClass: Option[String], jniHeader: Option[String]) case class Objc(header: String, prefix: String) case class Ts(module: String, ns: String) + case class Swift(module: String, prefix: String) } diff --git a/src/source/generator.scala b/src/source/generator.scala index aa33df5a..d937f3c8 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -198,7 +198,7 @@ package object generatorTools { val cppDefault = CppIdentStyle(camelUpper, camelUpper, camelUpper, underLower, underLower, underLower, underCaps, underCaps) val objcDefault = ObjcIdentStyle(camelUpper, camelUpper, camelLower, camelLower, camelLower, camelUpper, camelUpper) val jsDefault = JsIdentStyle(camelUpper, camelUpper, camelLower, camelLower, camelLower, underCaps, underCaps) - val swiftDefault = SwiftIdentStyle(camelUpper, camelUpper, camelLower, camelLower, camelLower, underCaps, underCaps) + val swiftDefault = SwiftIdentStyle(camelUpper, camelUpper, camelLower, camelLower, camelLower, camelLower, camelLower) val styles = Map( "FooBar" -> camelUpper, @@ -360,6 +360,7 @@ package object generatorTools { sealed abstract class SymbolReference case class ImportRef(arg: String) extends SymbolReference // Already contains <> or "" in C contexts + case class PrivateImportRef(arg: String) extends SymbolReference case class DeclRef(decl: String, namespace: Option[String]) extends SymbolReference } diff --git a/src/source/meta.scala b/src/source/meta.scala index 2768fc5b..89f09e1a 100644 --- a/src/source/meta.scala +++ b/src/source/meta.scala @@ -91,6 +91,7 @@ object MExtern { typename: String, module: String, translator: String, + translatorModule: String, generic: Boolean ) case class Swiftxx( diff --git a/src/source/parser.scala b/src/source/parser.scala index d5ce84e9..c0883e67 100644 --- a/src/source/parser.scala +++ b/src/source/parser.scala @@ -382,6 +382,14 @@ def parseProtobufManifest(origin: String, in: java.io.Reader): Either[Error, Seq Some(ProtobufMessage.Ts(p("module"), p("namespace"))) } case None => None + }, + // Swift is optional + Option(doc.get("swift")) match { + case Some(properties) => { + val p = properties.asInstanceOf[JMap[String, String]].toMap + Some(ProtobufMessage.Swift(p("module"), p("prefix"))) + } + case None => None } ) for(message <- doc.get("messages").asInstanceOf[java.util.List[String]]) { diff --git a/support-lib/BUILD b/support-lib/BUILD index 6e477e8a..e51c3093 100644 --- a/support-lib/BUILD +++ b/support-lib/BUILD @@ -91,6 +91,7 @@ swift_library( ], deps = [ ":djinni-support-swiftxx", + "@apple_swift_protobuf//:swift-protobuf" ], visibility = ["//visibility:public"], ) diff --git a/support-lib/dataref.yaml b/support-lib/dataref.yaml index 4f3777d1..e32bf8c4 100644 --- a/support-lib/dataref.yaml +++ b/support-lib/dataref.yaml @@ -37,6 +37,11 @@ composer: translator: '::djinni::composer::NativeDataRef' header: '"$DataRef_composer.hpp"' swift: - typename: 'Data' + typename: 'NSData' module: 'Foundation' generic: false + translator: 'DataRefMarshaller' + translator.module: 'DjinniSupport' +swiftxx: + translator: '::djinni::swift::DataRefAdaptor' + header: '"Data_swift.hpp"' diff --git a/support-lib/dataview.yaml b/support-lib/dataview.yaml index 9046bf8c..8d9dea9e 100644 --- a/support-lib/dataview.yaml +++ b/support-lib/dataview.yaml @@ -37,6 +37,11 @@ composer: translator: '::djinni::composer::NativeDataView' header: '"$DataView_composer.hpp"' swift: - typename: 'Data' + typename: 'NSData' module: 'Foundation' generic: false + translator: 'DataViewMarshaller' + translator.module: 'DjinniSupport' +swiftxx: + translator: '::djinni::swift::DataViewAdaptor' + header: '"Data_swift.hpp"' diff --git a/support-lib/future.yaml b/support-lib/future.yaml index eff05f54..61286327 100644 --- a/support-lib/future.yaml +++ b/support-lib/future.yaml @@ -43,6 +43,7 @@ swift: typename: 'DJFuture' module: 'DjinniSupport' translator: 'FutureMarshaller' + translator.module: 'DjinniSupport' generic: true swiftxx: translator: '::djinni::swift::FutureAdaptor' diff --git a/support-lib/jni/Future_jni.hpp b/support-lib/jni/Future_jni.hpp index 668109ba..592493bc 100644 --- a/support-lib/jni/Future_jni.hpp +++ b/support-lib/jni/Future_jni.hpp @@ -126,7 +126,7 @@ class FutureAdaptor return f; } - static LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) + static LocalRef fromCpp(JNIEnv* jniEnv, CppType c) { const auto& promiseJniInfo = JniClass::get(); diff --git a/support-lib/outcome.yaml b/support-lib/outcome.yaml index 7bd160ac..ae875e0a 100644 --- a/support-lib/outcome.yaml +++ b/support-lib/outcome.yaml @@ -42,3 +42,8 @@ composer: swift: typename: 'Result' generic: true + translator: 'OutcomeMarshaller' + translator.module: 'DjinniSupport' +swiftxx: + translator: '::djinni::swift::OutcomeAdaptor' + header: '"Outcome_swift.hpp"' diff --git a/support-lib/swift/DJData.swift b/support-lib/swift/DJData.swift new file mode 100644 index 00000000..c9a0fcc8 --- /dev/null +++ b/support-lib/swift/DJData.swift @@ -0,0 +1,31 @@ +import DjinniSupportCxx +import Foundation + +public enum DataViewMarshaller: Marshaller { + public typealias SwiftType = NSData + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + let range = djinni.swift.getBinaryRange(v) + return SwiftType(bytesNoCopy: UnsafeMutableRawPointer(mutating: range.bytes!), length: range.size, deallocator:.none) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.makeRangeValue(s.bytes, s.length) + } +} + +public enum DataRefMarshaller: Marshaller { + public typealias SwiftType = NSData + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + let range = djinni.swift.getBinaryRange(v) + let cfdata = Unmanaged.fromOpaque(range.bytes!).takeRetainedValue() + return cfdata as NSData + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + if s is CFMutableData { + let cfdataref = Unmanaged.passRetained(s as! CFMutableData).toOpaque() + return djinni.swift.makeRangeValue(cfdataref, 1) + } else { + let cfdataref = Unmanaged.passRetained(s as CFData).toOpaque() + return djinni.swift.makeRangeValue(cfdataref, 0) + } + } +} diff --git a/support-lib/swift/DJFuture.swift b/support-lib/swift/DJFuture.swift new file mode 100644 index 00000000..382abe63 --- /dev/null +++ b/support-lib/swift/DJFuture.swift @@ -0,0 +1,65 @@ +import DjinniSupportCxx +import Foundation +import Combine + +public typealias DJFuture = Future + +protocol AbstractPromiseHolder: AnyObject { + func fulfillPromise(value: UnsafePointer) +} + +class PromiseHolder: AbstractPromiseHolder { + var promise: DJFuture.Promise + init(marshaller: T.Type, promise: @escaping DJFuture.Promise) { + self.promise = promise + } + func fulfillPromise(value: UnsafePointer) { + if (!djinni.swift.isError(value)) { + promise(.success(T.fromCpp(value.pointee))) + } else { + promise(.failure(DjinniError(djinni.swift.getError(value)))) + } + } +} + +public func futureCb( + ptr: UnsafeMutableRawPointer?, + result: UnsafeMutablePointer?) + -> Void { + let ctx = Unmanaged.fromOpaque(ptr!).takeRetainedValue() + let promiseHolder = ctx as! AbstractPromiseHolder + promiseHolder.fulfillPromise(value:result!) +} + +public func cleanupCb(psubscription: UnsafeMutableRawPointer?) -> Void { + let _ = Unmanaged.fromOpaque(psubscription!).takeRetainedValue() +} + +public enum FutureMarshaller: Marshaller { + public typealias SwiftType = DJFuture + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return Future() { promise in + let promiseHolder = PromiseHolder(marshaller: T.self, promise: promise) + let promiseHolderPtr = Unmanaged.passRetained(promiseHolder).toOpaque() + withUnsafePointer(to: v) { p in + djinni.swift.setFutureCb(p, futureCb, promiseHolderPtr) + } + } + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var futureValue = djinni.swift.makeFutureValue(cleanupCb) + let subscription = s.sink { completion in + if case let .failure(e) = completion { + var errorValue = djinni.swift.makeVoidValue() + djinni.swift.setErrorValue(&errorValue, e.wrapped) + djinni.swift.setFutureResult(&futureValue, &errorValue) + } + } receiveValue:{ v in + var cppValue = T.toCpp(v) + djinni.swift.setFutureResult(&futureValue, &cppValue) + } + let pSubscription = Unmanaged.passRetained(subscription).toOpaque() + djinni.swift.storeSubscription(&futureValue, pSubscription) + return futureValue + } +} diff --git a/support-lib/swift/DJMarshal.swift b/support-lib/swift/DJMarshal.swift new file mode 100644 index 00000000..d5d8f574 --- /dev/null +++ b/support-lib/swift/DJMarshal.swift @@ -0,0 +1,205 @@ +import DjinniSupportCxx +import Foundation + +public protocol Marshaller { + associatedtype SwiftType + static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue +} + +public enum EnumMarshaller: Marshaller where T.RawValue == Int32 { + public typealias SwiftType = T + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return SwiftType(rawValue: djinni.swift.I32.toCpp(v))! + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.I32.fromCpp(s.rawValue) + } +} + +public enum SmallIntMarshaller: Marshaller { + public typealias SwiftType = T + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return SwiftType(exactly: djinni.swift.I32.toCpp(v))! + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.I32.fromCpp(Int32(s)) + } +} +public enum I64Marshaller: Marshaller { + public typealias SwiftType = Int64 + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return SwiftType(exactly: djinni.swift.I64.toCpp(v))! + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.I64.fromCpp(s) + } +} +public enum FloatMarshaller: Marshaller { + public typealias SwiftType = T + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return T(djinni.swift.F64.toCpp(v)) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.F64.fromCpp(Double(s)) + } +} +public enum BoolMarshaller: Marshaller { + public typealias SwiftType = Bool + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return djinni.swift.I32.toCpp(v) != 0 + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.I32.fromCpp(s ? 1 : 0) + } +} + +public typealias I8Marshaller = SmallIntMarshaller +public typealias I16Marshaller = SmallIntMarshaller +public typealias I32Marshaller = SmallIntMarshaller +public typealias F32Marshaller = FloatMarshaller +public typealias F64Marshaller = FloatMarshaller + +public enum StringMarshaller: Marshaller { + public typealias SwiftType = String + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + let range = djinni.swift.getBinaryRange(v) + if (range.size > 0) { + return String(data: Data(bytes: range.bytes, count: range.size), encoding: String.Encoding.utf8) ?? "invalid" + } else { + return String() + } + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + let bytes = s.utf8CString + return bytes.withUnsafeBufferPointer { ptr in + return djinni.swift.makeStringValue(UnsafeMutableRawPointer(mutating: ptr.baseAddress!), + ptr.count - 1) // minus terminating \0 + } + } +} + +public enum BinaryMarshaller: Marshaller { + public typealias SwiftType = Data + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + let range = djinni.swift.getBinaryRange(v) + if (range.size > 0) { + return Data(bytes: range.bytes, count: range.size) + } else { + return Data() + } + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return s.withUnsafeBytes { (ptr: UnsafeRawBufferPointer) in + return djinni.swift.makeBinaryValue(UnsafeMutableRawPointer(mutating: ptr.baseAddress!), + ptr.count) + } + } +} + +public enum DateMarshaller: Marshaller { + public typealias SwiftType = Date + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + let millisecondsSinceEpoch = I64Marshaller.fromCpp(v) + return Date(timeIntervalSince1970: Double(millisecondsSinceEpoch)) + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return I64Marshaller.toCpp(Int64(s.timeIntervalSince1970)) + } +} + +public enum VoidMarshaller: Marshaller { + public typealias SwiftType = Void + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return () + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.makeVoidValue() + } +} + +public enum OptionalMarshaller: Marshaller { + public typealias SwiftType = T.SwiftType? + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: v) { p in + if (djinni.swift.isVoidValue(p)) { + return nil + } + return T.fromCpp(v) + } + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + if (s == nil) { + return djinni.swift.makeVoidValue() + } else { + return T.toCpp(s!) + } + } +} + +public enum ListMarshaller: Marshaller { + public typealias SwiftType = [T.SwiftType] + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + var array = SwiftType() + withUnsafePointer(to: v) { p in + let size = djinni.swift.getSize(p) + for i in 0.. djinni.swift.AnyValue { + var composite = djinni.swift.makeCompositeValue() + for item in s { + djinni.swift.addMember(&composite, T.toCpp(item)) + } + return composite + } +} + +public typealias ArrayMarshaller = ListMarshaller + +public enum SetMarshaller: Marshaller where T.SwiftType: Hashable { + public typealias SwiftType = Set + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + var s = SwiftType() + withUnsafePointer(to: v) { p in + let size = djinni.swift.getSize(p) + for i in 0.. djinni.swift.AnyValue { + var composite = djinni.swift.makeCompositeValue() + for item in s { + djinni.swift.addMember(&composite, T.toCpp(item)) + } + return composite + } +} + +public enum MapMarshaller: Marshaller where K.SwiftType: Hashable { + public typealias SwiftType = Dictionary + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + var s = SwiftType() + withUnsafePointer(to: v) { p in + let size = djinni.swift.getSize(p) + for i in stride(from: 0, to: size, by: 2) { + s.updateValue(V.fromCpp(djinni.swift.getMember(p, i+1)), + forKey: K.fromCpp(djinni.swift.getMember(p, i))) + } + } + return s + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var composite = djinni.swift.makeCompositeValue() + for (k, v) in s { + djinni.swift.addMember(&composite, K.toCpp(k)) + djinni.swift.addMember(&composite, V.toCpp(v)) + } + return composite + } +} diff --git a/support-lib/swift/DJOutcome.swift b/support-lib/swift/DJOutcome.swift new file mode 100644 index 00000000..dbc2ca1e --- /dev/null +++ b/support-lib/swift/DJOutcome.swift @@ -0,0 +1,29 @@ +import DjinniSupportCxx +import Foundation + +public enum OutcomeMarshaller: Marshaller + where Err.SwiftType: Error { + public typealias SwiftType = Result + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + withUnsafePointer(to: v) { p in + var r = djinni.swift.getMember(p, 0) + if (!djinni.swift.isVoidValue(&r)) { + return .success(Res.fromCpp(r)) + } else { + let e = djinni.swift.getMember(p, 1) + return .failure(Err.fromCpp(e)) + } + } + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var comp = djinni.swift.makeCompositeValue() + switch s { + case .success(let r): + djinni.swift.addMember(&comp, Res.toCpp(r)) + case .failure(let e): + djinni.swift.addMember(&comp, djinni.swift.makeVoidValue()) + djinni.swift.addMember(&comp, Err.toCpp(e)) + } + return comp + } +} diff --git a/support-lib/swift/DJProtobuf.swift b/support-lib/swift/DJProtobuf.swift new file mode 100644 index 00000000..40ef1994 --- /dev/null +++ b/support-lib/swift/DJProtobuf.swift @@ -0,0 +1,20 @@ +import DjinniSupportCxx +import SwiftProtobuf +import Foundation + +public enum ProtobufMarshaller: Marshaller { + public typealias SwiftType = T + static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + let range = djinni.swift.getBinaryRange(v) + if (range.size > 0) { + let bin = Data(bytesNoCopy:UnsafeMutableRawPointer(mutating: range.bytes), count:range.size, deallocator:.none) + return try! T(serializedBytes: bin) + } else { + return T() + } + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + let bin: Data = try! s.serializedBytes() + return BinaryMarshaller.toCpp(bin) + } +} diff --git a/support-lib/swift/DjinniSupport.swift b/support-lib/swift/DjinniSupport.swift index b34b07f0..09ad6e08 100644 --- a/support-lib/swift/DjinniSupport.swift +++ b/support-lib/swift/DjinniSupport.swift @@ -1,8 +1,7 @@ import DjinniSupportCxx import Foundation -import Combine -public typealias Vtbl = [(T, UnsafePointer?, UnsafeMutablePointer?) -> Void] +public typealias Vtbl = [(T, UnsafePointer?, UnsafeMutablePointer?) throws -> Void] public class GenericProtocolWrapperContext { public func dispatch(idx: Int32, params: UnsafePointer?, ret: UnsafeMutablePointer?) -> Void { @@ -21,7 +20,13 @@ public final class ProtocolWrapperContext: GenericProtocolWrapperContext { self.vtbl = vtbl } public override func dispatch(idx: Int32, params: UnsafePointer?, ret: UnsafeMutablePointer?) -> Void { - vtbl[Int(idx)](inst, params, ret) + do { + try vtbl[Int(idx)](inst, params, ret) + } catch let error as DjinniError { + djinni.swift.setErrorValue(ret, error.wrapped) + } catch { + djinni.swift.setErrorMessage(ret, std.string(String(describing: error))) + } } public override func getInst() -> AnyObject { return inst as AnyObject @@ -49,205 +54,9 @@ public func dispatcherProtocalCall( } } -public protocol Marshaller { - associatedtype SwiftType - static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue -} - -public enum EnumMarshaller: Marshaller where T.RawValue == Int32 { - public typealias SwiftType = T - public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - return SwiftType(rawValue: djinni.swift.I32.toCpp(v))! - } - public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - return djinni.swift.I32.fromCpp(s.rawValue) - } -} - -public enum SmallIntMarshaller: Marshaller { - public typealias SwiftType = T - public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - return SwiftType(exactly: djinni.swift.I32.toCpp(v))! - } - public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - return djinni.swift.I32.fromCpp(Int32(s)) - } -} -public enum I64Marshaller: Marshaller { - public typealias SwiftType = Int64 - public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - return SwiftType(exactly: djinni.swift.I64.toCpp(v))! - } - public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - return djinni.swift.I64.fromCpp(s) - } -} -public enum FloatMarshaller: Marshaller { - public typealias SwiftType = T - public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - return T(djinni.swift.F64.toCpp(v)) - } - public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - return djinni.swift.F64.fromCpp(Double(s)) - } -} -public enum BoolMarshaller: Marshaller { - public typealias SwiftType = Bool - public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - return djinni.swift.I32.toCpp(v) != 0 - } - public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - return djinni.swift.I32.fromCpp(s ? 1 : 0) - } -} - -public typealias I8Marshaller = SmallIntMarshaller -public typealias I16Marshaller = SmallIntMarshaller -public typealias I32Marshaller = SmallIntMarshaller -public typealias F32Marshaller = FloatMarshaller -public typealias F64Marshaller = FloatMarshaller - -public enum StringMarshaller: Marshaller { - public typealias SwiftType = String - static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - let range = djinni.swift.getRange(v) - let typedPtr = range.bytes.bindMemory(to: CChar.self, capacity: range.size) - return String(cString: typedPtr) - } - static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - let bytes = s.utf8CString - return bytes.withUnsafeBufferPointer { ptr in - return djinni.swift.makeRangeValue(UnsafeMutableRawPointer(mutating: ptr.baseAddress!), - ptr.count) - } - } -} - -public enum BinaryMarshaller: Marshaller { - public typealias SwiftType = Data - static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - let range = djinni.swift.getRange(v) - return Data(bytes: range.bytes, count: range.size) - } - static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - return s.withUnsafeBytes { (ptr: UnsafeRawBufferPointer) in - return djinni.swift.makeRangeValue(UnsafeMutableRawPointer(mutating: ptr.baseAddress!), - ptr.count) - } - } -} - -public enum DateMarshaller: Marshaller { - public typealias SwiftType = Date - static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - let millisecondsSinceEpoch = I64Marshaller.fromCpp(v) - return Date(timeIntervalSince1970: Double(millisecondsSinceEpoch)) - } - static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - return I64Marshaller.toCpp(Int64(s.timeIntervalSince1970)) - } -} - -public enum VoidMarshaller: Marshaller { - public typealias SwiftType = Void - static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - return () - } - static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - return djinni.swift.makeVoidValue() - } -} - -public enum OptionalMarshaller: Marshaller { - public typealias SwiftType = T.SwiftType? - static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - return withUnsafePointer(to: v) { p in - if (djinni.swift.isVoidValue(p)) { - return nil - } - return T.fromCpp(v) - } - } - static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - if (s == nil) { - return djinni.swift.makeVoidValue() - } else { - return T.toCpp(s!) - } - } -} - -public enum ListMarshaller: Marshaller { - public typealias SwiftType = [T.SwiftType] - static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - var array = SwiftType() - withUnsafePointer(to: v) { p in - let size = djinni.swift.getSize(p) - for i in 0.. djinni.swift.AnyValue { - var composite = djinni.swift.makeCompositeValue() - for item in s { - djinni.swift.addMember(&composite, T.toCpp(item)) - } - return composite - } -} - -public typealias ArrayMarshaller = ListMarshaller - -public enum SetMarshaller: Marshaller where T.SwiftType: Hashable { - public typealias SwiftType = Set - static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - var s = SwiftType() - withUnsafePointer(to: v) { p in - let size = djinni.swift.getSize(p) - for i in 0.. djinni.swift.AnyValue { - var composite = djinni.swift.makeCompositeValue() - for item in s { - djinni.swift.addMember(&composite, T.toCpp(item)) - } - return composite - } -} - -public enum MapMarshaller: Marshaller where K.SwiftType: Hashable { - public typealias SwiftType = Dictionary - static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - var s = SwiftType() - withUnsafePointer(to: v) { p in - let size = djinni.swift.getSize(p) - for i in stride(from: 0, to: size, by: 2) { - s.updateValue(V.fromCpp(djinni.swift.getMember(p, i+1)), - forKey: K.fromCpp(djinni.swift.getMember(p, i))) - } - } - return s - } - static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - var composite = djinni.swift.makeCompositeValue() - for (k, v) in s { - djinni.swift.addMember(&composite, K.toCpp(k)) - djinni.swift.addMember(&composite, V.toCpp(v)) - } - return composite - } -} - open class CppProxy { public var inst: djinni.swift.AnyValue - public init(_ inst: djinni.swift.AnyValue) { + public init(inst: djinni.swift.AnyValue) { self.inst = inst } deinit { @@ -324,16 +133,19 @@ public func destroyCppProxy(_ inst: djinni.swift.AnyValue) { } } -public typealias DJFuture = Future - -public enum FutureMarshaller: Marshaller { - public typealias SwiftType = DJFuture - public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { - return Future() { promise in - promise(Result.success(T.fromCpp(v))) - } +public class DjinniError: Error { + var wrapped: djinni.swift.ErrorValue + init(_ wrapped: djinni.swift.ErrorValue) { + self.wrapped = wrapped + } + public init(_ msg: String) { + self.wrapped = djinni.swift.ErrorValue(std.string(msg)) } - public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - return djinni.swift.makeVoidValue() + public var errorMessage: String { return String(wrapped.msg) } +} + +public func handleCppErrors(_ ret: UnsafePointer) throws { + if (djinni.swift.isError(ret)) { + throw DjinniError(djinni.swift.getError(ret)) } } diff --git a/support-lib/swiftxx/Data_swift.cpp b/support-lib/swiftxx/Data_swift.cpp new file mode 100644 index 00000000..c36512af --- /dev/null +++ b/support-lib/swiftxx/Data_swift.cpp @@ -0,0 +1,159 @@ +#include "Data_swift.hpp" +#include + +namespace djinni { + +class DataRefSwift : public DataRef::Impl { +public: + // create empty buffer from c++ + explicit DataRefSwift(size_t len) { + allocate(len); + } + // create new data object and initialize with data. although this still + // copies data, it does the allocation and initialization in one step. + explicit DataRefSwift(const void* data, size_t len) { + _mutableData = CFDataCreateMutable(kCFAllocatorDefault, len); + assert(_mutableData != nullptr); + CFDataAppendBytes(_mutableData, reinterpret_cast(data), len); + _data = _mutableData; + } + // take over a std::vector's buffer without copying it + explicit DataRefSwift(std::vector&& vec) { + if (!vec.empty()) { + takeOver(std::move(vec)); + } else { + allocate(0); + } + } + // take over a std::string's buffer without copying it + explicit DataRefSwift(std::string&& str) { + if (!str.empty()) { + takeOver(std::move(str)); + } else { + allocate(0); + } + } + // wrap an immutable CFData object + explicit DataRefSwift(CFDataRef data) { + _data = data; + _mutableData = nullptr; + CFRetain(_data); + } + // wrap a mutable CFData object (CFMutableData) + explicit DataRefSwift(CFMutableDataRef data) { + _data = data; + _mutableData = data; + CFRetain(_data); + } + DataRefSwift(const DataRefSwift&) = delete; + ~DataRefSwift() { + CFRelease(_data); + } + + const uint8_t* buf() const override { + // must query from the CF object every time in case the buffer is + // relocated. + return CFDataGetBytePtr(_data); + } + size_t len() const override { + // must query from the CF object every time in case the buffer is + // resized. + return CFDataGetLength(_data); + } + uint8_t* mutableBuf() override { + return _mutableData ? CFDataGetMutableBytePtr(_mutableData) : nullptr; + } + + PlatformObject platformObj() const { + return _data; + } + +private: + CFDataRef _data; + CFMutableDataRef _mutableData; + + void allocate(size_t len) { + _mutableData = CFDataCreateMutable(kCFAllocatorDefault, len); + assert(_mutableData != nullptr); + CFDataSetLength(_mutableData, len); + _data = _mutableData; + } + + template + void takeOver(T&& obj) { + using DataObj = std::decay_t; + CFAllocatorContext context = {}; + // create a new instance and steal the input object's buffer + auto* p = new DataObj(std::forward(obj)); + auto buf = reinterpret_cast(p->data()); + auto len = p->size(); + context.info = p; + context.deallocate = [](void*, void* info) { + // delete the wrapped object + auto* p = reinterpret_cast(info); + delete p; + }; + CFAllocatorRef deallocator = CFAllocatorCreate(kCFAllocatorDefault, &context); + assert(deallocator != nullptr); + // create the CFData without copying + _data = CFDataCreateWithBytesNoCopy(nullptr, buf, len, deallocator); + assert(_data != nullptr); + CFRelease(deallocator); // CFDataCreateWithBytesNoCopy retains the object, so release here + _mutableData = nullptr; // our CFData is immutable because it can't realloc and resize + } +}; + +DataRef::DataRef(size_t len) { + _impl = std::make_shared(len); +} + +DataRef::DataRef(const void* data, size_t len) { + _impl = std::make_shared(data, len); +} + +DataRef::DataRef(std::vector&& vec) { + _impl = std::make_shared(std::move(vec)); +} +DataRef::DataRef(std::string&& str) { + _impl = std::make_shared(std::move(str)); +} + +DataRef::DataRef(CFMutableDataRef platformObj) { + _impl = std::make_shared(platformObj); +} + +DataRef::DataRef(CFDataRef platformObj) { + _impl = std::make_shared(platformObj); +} + +} + +namespace djinni::swift { + +DataView DataViewAdaptor::toCpp(const AnyValue& s) { + auto range = std::get(s); + return DataView(reinterpret_cast(range.bytes), range.size); +} + +AnyValue DataViewAdaptor::fromCpp(DataView c) { + return RangeValue{c.buf(), c.len()}; +} + +DataRef DataRefAdaptor::toCpp(const AnyValue& s) { + auto range = std::get(s); + if (range.size > 0) { + auto cfmutabledataref = const_cast(reinterpret_cast(range.bytes)); + return DataRef(cfmutabledataref); + } else { + return DataRef(reinterpret_cast(range.bytes)); + } +} + +AnyValue DataRefAdaptor::fromCpp(const DataRef& c) { + auto impl = std::dynamic_pointer_cast(c.impl()); + auto cfdata = impl->platformObj(); + CFRetain(cfdata); + return RangeValue{reinterpret_cast(cfdata), 0}; +} + +} diff --git a/support-lib/swiftxx/Data_swift.hpp b/support-lib/swiftxx/Data_swift.hpp new file mode 100644 index 00000000..dfe93b3e --- /dev/null +++ b/support-lib/swiftxx/Data_swift.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "djinni_support.hpp" +#include "../cpp/DataView.hpp" +#include "../cpp/DataRef.hpp" + +namespace djinni::swift { + +class DataViewAdaptor +{ +public: + using CppType = DataView; + static CppType toCpp(const AnyValue& s); + static AnyValue fromCpp(CppType c); +}; + +class DataRefAdaptor +{ +public: + using CppType = DataRef; + static CppType toCpp(const AnyValue& s); + static AnyValue fromCpp(const CppType& c); +}; + +} diff --git a/support-lib/swiftxx/Future_swift.cpp b/support-lib/swiftxx/Future_swift.cpp new file mode 100644 index 00000000..160e0b27 --- /dev/null +++ b/support-lib/swiftxx/Future_swift.cpp @@ -0,0 +1,25 @@ +#include "Future_swift.hpp" + +namespace djinni::swift { + +void setFutureCb(const AnyValue* futureValue, FutureCb cb, void* ctx) { + auto holder = std::dynamic_pointer_cast(std::get(*futureValue)); + holder->setFutureCb(cb, ctx); +} + +AnyValue makeFutureValue(CleanupCb cleanup) { + OpaqueValuePtr holder = std::make_shared>(cleanup); + return {holder}; +} + +void setFutureResult(const AnyValue* futureValue, const AnyValue* futureResult) { + auto holder = std::dynamic_pointer_cast>(std::get(*futureValue)); + holder->setValue(futureResult); +} + +void storeSubscription(const AnyValue* futureValue, void* subscription) { + auto holder = std::dynamic_pointer_cast>(std::get(*futureValue)); + holder->subscription = subscription; +} + +} diff --git a/support-lib/swiftxx/Future_swift.hpp b/support-lib/swiftxx/Future_swift.hpp index 85e076a8..5d04316a 100644 --- a/support-lib/swiftxx/Future_swift.hpp +++ b/support-lib/swiftxx/Future_swift.hpp @@ -5,7 +5,79 @@ namespace djinni::swift { -// TODO implement +typedef void (*FutureCb)(void* ctx, AnyValue* result); +typedef void (*CleanupCb)(void* subscription); + +struct AbstractFutureHolder: OpaqueValue { + virtual ~AbstractFutureHolder() = default; + virtual void setFutureCb(FutureCb cb, void* ctx) = 0; +}; + +template +struct FutureHolder: AbstractFutureHolder { + using CppResType = typename RESULT::CppType; + djinni::Future future; + explicit FutureHolder(djinni::Future f) : future(std::move(f)) {} + + void setFutureCb(FutureCb cb, void* ctx) override { + future.then([cb, ctx] (Future f) { + try { + auto v = RESULT::fromCpp(f.get()); + cb(ctx, &v); + } catch (ErrorValue& e) { + AnyValue errorValue = e; + cb(ctx, &errorValue); + } + }); + } +}; +template<> +struct FutureHolder: AbstractFutureHolder { + djinni::Future future; + explicit FutureHolder(djinni::Future f) : future(std::move(f)) {} + + void setFutureCb(FutureCb cb, void* ctx) override { + future.then([cb, ctx] (Future f) { + try { + auto v = makeVoidValue(); + cb(ctx, &v); + } catch (ErrorValue& e) { + AnyValue errorValue = e; + cb(ctx, &errorValue); + } + }); + } +}; + +void setFutureCb(const AnyValue* futureValue, FutureCb cb, void* ctx); +AnyValue makeFutureValue(CleanupCb cleanup); +void setFutureResult(const AnyValue* futureValue, const AnyValue* futureResult); +void storeSubscription(const AnyValue* futureValue, void* subscription); + +struct AnyValueFutureAdapter { + using CppType = AnyValue; + static AnyValue fromCpp(CppType c) {return c;} +}; + +template<> +struct FutureHolder: AbstractFutureHolder { + djinni::Promise promise; + std::shared_ptr> future; + void* subscription = nullptr; + CleanupCb cleanup; + FutureHolder(CleanupCb cleanup) { + this->cleanup = cleanup; + this->future = std::make_shared>(promise.getFuture()); + } + ~FutureHolder() { + cleanup(subscription); + } + void setFutureCb(FutureCb cb, void* ctx) override {} + void setValue(const AnyValue* futureValue) { + promise.setValue(*futureValue); + } +}; + template class FutureAdaptor { @@ -14,11 +86,58 @@ class FutureAdaptor using CppType = Future; static CppType toCpp(const AnyValue& o) { + auto holder = std::dynamic_pointer_cast>(std::get(o)); + if (holder) { + return std::move(holder->future); + } + auto anyHolder = std::dynamic_pointer_cast>(std::get(o)); Promise p; - return p.getFuture(); + auto f = p.getFuture(); + anyHolder->future->then([p = std::move(p)] (Future f) mutable { + auto res = f.get(); + if (std::holds_alternative(res)) { + const auto& e = std::get(res); + p.setException(e); + } else { + p.setValue(RESULT::toCpp(res)); + } + }); + return f; + } + static AnyValue fromCpp(CppType c) { + OpaqueValuePtr holder = std::make_shared>(std::move(c)); + return {holder}; + } +}; + +template <> +class FutureAdaptor +{ +public: + using CppType = Future; + + static CppType toCpp(const AnyValue& o) { + auto holder = std::dynamic_pointer_cast>(std::get(o)); + if (holder) { + return std::move(holder->future); + } + auto anyHolder = std::dynamic_pointer_cast>(std::get(o)); + Promise p; + auto f = p.getFuture(); + anyHolder->future->then([p = std::move(p)] (Future f) mutable { + auto res = f.get(); + if (std::holds_alternative(res)) { + const auto& e = std::get(res); + p.setException(e); + } else { + p.setValue(); + } + }); + return f; } - static AnyValue fromCpp(const CppType& c) { - return makeVoidValue(); + static AnyValue fromCpp(CppType c) { + OpaqueValuePtr holder = std::make_shared>(std::move(c)); + return {holder}; } }; diff --git a/support-lib/swiftxx/Outcome_swift.hpp b/support-lib/swiftxx/Outcome_swift.hpp new file mode 100644 index 00000000..8d7ebb5d --- /dev/null +++ b/support-lib/swiftxx/Outcome_swift.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include "djinni_support.hpp" +#include "../cpp/expected.hpp" + +namespace djinni::swift { + +template +class OutcomeAdaptor { + using ResultCppType = typename RESULT::CppType; + using ErrorCppType = typename ERROR::CppType; +public: + using CppType = expected; + static CppType toCpp(const AnyValue& s) { + auto comp = std::get(s); + auto val = comp->getValue(0); + if (!std::holds_alternative(val)) { + return { RESULT::toCpp(val) }; + } else { + auto err = comp->getValue(1); + return make_unexpected(ERROR::toCpp(err)); + } + } + static AnyValue fromCpp(const CppType& c) { + auto ret = std::make_shared(); + if (c.has_value()) { + ret->addValue(RESULT::fromCpp(c.value())); + } else { + ret->addValue(makeVoidValue()); + ret->addValue(ERROR::fromCpp(c.error())); + } + return {ret}; + } +}; + +} diff --git a/support-lib/swiftxx/djinni_support.cpp b/support-lib/swiftxx/djinni_support.cpp index b29a49eb..683aa5e2 100644 --- a/support-lib/swiftxx/djinni_support.cpp +++ b/support-lib/swiftxx/djinni_support.cpp @@ -2,12 +2,29 @@ namespace djinni::swift { -AnyValue makeRangeValue(void* bytes, size_t size) { +AnyValue makeStringValue(const char* bytes, size_t size) { + return StringValue(bytes, size); +} + +AnyValue makeBinaryValue(const void* bytes, size_t size) { + auto p = reinterpret_cast(bytes); + return BinaryValue{p, p + size}; +} + +AnyValue makeRangeValue(const void* bytes, size_t size) { return RangeValue{bytes, size}; } -RangeValue getRange(const AnyValue& v) { - return std::get(v); +RangeValue getBinaryRange(const AnyValue& v) { + if (std::holds_alternative(v)) { + const auto& s = std::get(v); + return {s.data(), s.size()}; + } else if (std::holds_alternative(v)) { + const auto& b = std::get(v); + return {b.data(), b.size()}; + } else { + return std::get(v); + } } size_t getSize(const AnyValue* v) { @@ -33,6 +50,14 @@ void setReturnValue(AnyValue* ret, const AnyValue& v) { *ret = v; } +void setErrorValue(AnyValue* ret, const ErrorValue& v) { + *ret = v; +} + +void setErrorMessage(AnyValue* ret, const std::string& s) { + *ret = ErrorValue{s}; +} + WeakSwiftProxy weakify(const AnyValue& v) { auto i = std::get(v); return i.sptr; @@ -44,7 +69,8 @@ AnyValue strongify(const WeakSwiftProxy& v) { InterfaceInfo getInterfaceInfo(const AnyValue* v) { auto i = std::get(*v); - return {i.ptr.get(), i.sptr.get()}; + // return {i.ptr.get(), i.sptr.get()}; + return {i.ptr.get(), i.sptr ? i.sptr->ctx() : nullptr }; } AnyValue makeVoidValue() { @@ -60,6 +86,13 @@ AnyValue makeCompositeValue() { return { std::make_shared() }; } +bool isError(const AnyValue* ret) { + return std::holds_alternative(*ret); +} + +ErrorValue getError(const AnyValue* ret) { + return std::get(*ret); +} ProtocolWrapper::ProtocolWrapper(void* ctx, DispatchFunc dispatcher): _ctx(ctx), _dispatcher(dispatcher) @@ -72,6 +105,16 @@ ProtocolWrapper::~ProtocolWrapper() { AnyValue ProtocolWrapper::callProtocol(int idx, const ParameterList* params) { AnyValue ret = VoidValue(); // output parameter _dispatcher(_ctx, idx, params, &ret); + if (std::holds_alternative(ret)) { + const auto& e = std::get(ret); + if (e.cause) { + // previously thrown c++ exception + std::rethrow_exception(e.cause); + } else { + // swift error + throw e; + } + } return ret; } diff --git a/support-lib/swiftxx/djinni_support.hpp b/support-lib/swiftxx/djinni_support.hpp index 7deab3e5..1ad2af37 100644 --- a/support-lib/swiftxx/djinni_support.hpp +++ b/support-lib/swiftxx/djinni_support.hpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include @@ -15,13 +17,31 @@ using I32Value = int32_t; using I64Value = int64_t; // double covers float too using DoubleValue = double; -// using StringValue = std::string; -// using BinaryValue = std::vector; +using StringValue = std::string; +using BinaryValue = std::vector; struct RangeValue { const void* bytes; size_t size; }; using DateValue = std::chrono::system_clock::time_point; +struct ErrorValue: public std::exception { + std::string msg; + std::exception_ptr cause; + + ErrorValue(const std::string& msg) + :msg(msg), cause(nullptr) {} + ErrorValue(const std::string& msg, std::exception_ptr cause) + :msg(msg), cause(cause) {} + ErrorValue(const ErrorValue& other) = default; + ErrorValue(ErrorValue&& other) = default; + + ErrorValue& operator=(const ErrorValue& other) = default; + ErrorValue& operator=(ErrorValue&& other) = default; + + const char* what() const noexcept override { + return msg.c_str(); + } +}; class ProtocolWrapper; struct InterfaceValue { @@ -39,10 +59,9 @@ struct OpaqueValue { }; using OpaqueValuePtr = std::shared_ptr; -using AnyValue = std::variant; +using AnyValue = std::variant; struct CompositeValue { virtual ~CompositeValue() = default; @@ -60,16 +79,22 @@ struct CompositeValue { struct ParameterList: CompositeValue {}; -AnyValue makeRangeValue(void* bytes, size_t size); -RangeValue getRange(const AnyValue& v); +AnyValue makeStringValue(const char* bytes, size_t size); +AnyValue makeBinaryValue(const void* bytes, size_t size); +RangeValue getBinaryRange(const AnyValue& v); +AnyValue makeRangeValue(const void* bytes, size_t size); size_t getSize(const AnyValue* v); AnyValue getMember(const AnyValue* v, size_t i); void addMember(AnyValue* c, const AnyValue& v); AnyValue getMember(const ParameterList* v, size_t i); void setReturnValue(AnyValue* ret, const AnyValue& v); +void setErrorValue(AnyValue* ret, const ErrorValue& v); +void setErrorMessage(AnyValue* ret, const std::string& s); AnyValue makeVoidValue(); bool isVoidValue(const AnyValue* c); AnyValue makeCompositeValue(); +bool isError(const AnyValue* ret); +ErrorValue getError(const AnyValue* ret); struct InterfaceInfo { void* cppPointer; @@ -130,11 +155,22 @@ struct Enum { struct String { using CppType = std::string; static AnyValue fromCpp(const CppType& c) { - return RangeValue{c.data(), c.size()}; + return c; } static CppType toCpp(const AnyValue& v) { - auto range = std::get(v); - return {reinterpret_cast(range.bytes), range.size}; + return std::get(v); + } +}; + +struct WString { + using Utf8Converter = std::wstring_convert>; + using CppType = std::wstring; + static AnyValue fromCpp(const CppType& c) { + return Utf8Converter().to_bytes(c); + } + static CppType toCpp(const AnyValue& v) { + auto utf8str = std::get(v); + return Utf8Converter{}.from_bytes(utf8str); } }; @@ -221,7 +257,7 @@ struct Optional { } template static AnyValue fromCpp(const typename C::CppOptType& cppOpt) { - return T::fromCppOpt(cppOpt); + return cppOpt ? T::fromCppOpt(cppOpt) : makeVoidValue(); } }; @@ -244,12 +280,10 @@ class Binary { using CppType = std::vector; static AnyValue fromCpp(const CppType& c) { - return RangeValue{c.data(), c.size()}; + return makeBinaryValue(c.data(), c.size()); } static CppType toCpp(const AnyValue& v) { - auto range = std::get(v); - const auto* ptr = reinterpret_cast(range.bytes); - return {ptr, ptr + range.size}; + return std::get(v); } }; @@ -274,4 +308,27 @@ struct Interface { } }; +template +class Protobuf { +public: + using CppType = CPP_PROTO; + static CppType toCpp(const AnyValue& s) { + auto bin = std::get(s); + CPP_PROTO cppProto; + bool success = cppProto.ParseFromArray(bin.data(), bin.size()); + if (!success) { + throw ErrorValue(std::string("failed to parse protobuf type ") + cppProto.GetTypeName()); + } + return cppProto; + } + static AnyValue fromCpp(const CppType& c) { + BinaryValue bin(c.ByteSizeLong()); + bool success = c.SerializeToArray(bin.data(), static_cast(bin.size())); + if (!success) { + return ErrorValue("failed to serialize protobuf type " + c.GetTypeName()); + } + return {bin}; + } +}; + } diff --git a/test-suite/BUILD b/test-suite/BUILD index c8684b62..f7a18767 100644 --- a/test-suite/BUILD +++ b/test-suite/BUILD @@ -4,23 +4,18 @@ load("@build_bazel_rules_apple//apple:macos.bzl", "macos_unit_test") load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library", "swift_test") load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") -exclude_files = ["handwritten-src/cpp/proto_test_helpers.*", - "handwritten-src/cpp/TranslateDuration.*", - "handwritten-src/cpp/data_helpers.*", - "handwritten-src/cpp/outcome_test_helpers.*"] - cc_library( name = "djinni-tests-common", srcs = glob([ "generated-src/cpp/*.cpp", "handwritten-src/cpp/*.cpp", "djinni/vendor/third-party/proto/cpp/*.cc", - ], exclude=exclude_files), + ]), hdrs = glob([ "generated-src/cpp/*.hpp", "handwritten-src/cpp/*.hpp", "djinni/vendor/third-party/proto/cpp/*.h", - ], exclude=exclude_files), + ]), includes = [ "generated-src/cpp", "handwritten-src/cpp", @@ -198,10 +193,13 @@ sh_binary( "handwritten-src/js/*.js"]) + [":wasm"] ) +swift_helper_files = "handwritten-src/swift/*+Helper.swift" +swift_error_files = "handwritten-src/swift/*+Error.swift" + swift_test( name = "djinni-swift-tests", - srcs = ['handwritten-src/swift/AllTests.swift'], - deps = ['//examples:textsort-swift-bridge'], + srcs = glob(['handwritten-src/swift/*.swift'], exclude = [swift_helper_files, swift_error_files]), + deps = [':test-swift-bridge', '//examples:textsort-swift-bridge'], copts = [ "-cxx-interoperability-mode=default", "-Xcc", @@ -218,6 +216,7 @@ swift_library( generates_header = True, srcs = glob([ "generated-src/swift/*.swift", + swift_error_files ], exclude = [ swift_private_files ]), copts = [ "-cxx-interoperability-mode=default", @@ -225,6 +224,7 @@ swift_library( ], deps = [ "//support-lib:djinni-support-swift", + ":protobuf-test-swift" ], visibility = ["//visibility:public"], ) @@ -232,7 +232,7 @@ swift_library( swift_library( name = "test-swift-bridge", module_name = "TestSuiteBridge", - srcs = glob([swift_private_files,]), + srcs = glob([swift_private_files, swift_helper_files]), copts = [ "-cxx-interoperability-mode=default", "-Xcc", "-std=c++17", @@ -247,6 +247,16 @@ swift_library( visibility = ["//visibility:public"], ) +swift_library( + name = "protobuf-test-swift", + module_name = "ProtobufTest", + srcs = glob(["djinni/vendor/third-party/proto/swift/*.swift"]), + deps = [ + "@apple_swift_protobuf//:swift-protobuf" + ], + visibility = ["//visibility:public"], +) + cc_library( name = "test-swiftxx", srcs = glob([ diff --git a/test-suite/djinni/all.djinni b/test-suite/djinni/all.djinni index 481bbe2e..fec1d113 100644 --- a/test-suite/djinni/all.djinni +++ b/test-suite/djinni/all.djinni @@ -1 +1,10 @@ @import "common.djinni" + +@import "enum_flags.djinni" +@import "constant_enum.djinni" +@import "data_ref_view.djinni" + +@import "vendor/third-party/date.djinni" +@import "third-party/duration.djinni" +@import "third-party/outcome.djinni" +@import "third-party/proto.djinni" diff --git a/test-suite/djinni/client_interface.djinni b/test-suite/djinni/client_interface.djinni index 43810561..815520f2 100644 --- a/test-suite/djinni/client_interface.djinni +++ b/test-suite/djinni/client_interface.djinni @@ -6,7 +6,7 @@ client_returned_record = record { } # Client interface -client_interface = interface +j +o +w { +client_interface = interface +nc { # Returns record of given string get_record(record_id: i64, utf8string: string, misc: optional): client_returned_record; identifier_check(data: binary, r: i32, jret: i64): f64; diff --git a/test-suite/djinni/common.djinni b/test-suite/djinni/common.djinni index 7fe1a9d6..1a078536 100644 --- a/test-suite/djinni/common.djinni +++ b/test-suite/djinni/common.djinni @@ -6,7 +6,6 @@ @import "exception.djinni" @import "client_interface.djinni" @import "enum.djinni" -@import "enum_flags.djinni" @import "user_token.djinni" @import "test.djinni" @import "primtypes.djinni" diff --git a/test-suite/djinni/constants.djinni b/test-suite/djinni/constants.djinni index 82314b25..6be08493 100644 --- a/test-suite/djinni/constants.djinni +++ b/test-suite/djinni/constants.djinni @@ -2,7 +2,7 @@ constant_record = record { some_integer: i32; some_string: string; -} +} deriving(eq) # Record containing constants constants = record { diff --git a/test-suite/djinni/exception.djinni b/test-suite/djinni/exception.djinni index 92b81a0e..6f1a1558 100644 --- a/test-suite/djinni/exception.djinni +++ b/test-suite/djinni/exception.djinni @@ -1,4 +1,4 @@ -throwing_interface = interface +w { +throwing_interface = interface +w +sw { throw_exception(); } diff --git a/test-suite/djinni/test.djinni b/test-suite/djinni/test.djinni index 9900ab81..0c914681 100644 --- a/test-suite/djinni/test.djinni +++ b/test-suite/djinni/test.djinni @@ -1,6 +1,6 @@ @extern "../../support-lib/future.yaml" -async_interface = interface +j +o +w { +async_interface = interface +nc { future_roundtrip(f: future): future; } @@ -78,12 +78,12 @@ empty_record = record { # Test for conflict of method name with an interface name. # See the comments about scopeSymbols in CppMarshal.scala for more info. -# Conflict = interface +c { -# } -# conflict_user = interface +c { -# Conflict(): Conflict; -# conflict_arg(cs: set): bool; -# } +Conflict = interface +c { +} +conflict_user = interface +c { + Conflict(): Conflict; + conflict_arg(cs: list): bool; +} # we need to test optional interface # this one will be used diff --git a/test-suite/djinni/user_token.djinni b/test-suite/djinni/user_token.djinni index 8628c8d8..f6e4edcb 100644 --- a/test-suite/djinni/user_token.djinni +++ b/test-suite/djinni/user_token.djinni @@ -1,3 +1,3 @@ -user_token = interface +c +j +o +w { +user_token = interface +c +nc { whoami() : string; } diff --git a/test-suite/djinni/vendor/third-party/date.yaml b/test-suite/djinni/vendor/third-party/date.yaml index cb2c1f4b..8ae3858a 100644 --- a/test-suite/djinni/vendor/third-party/date.yaml +++ b/test-suite/djinni/vendor/third-party/date.yaml @@ -39,4 +39,8 @@ ts: module: '' swift: typename: 'Date' - module: '' + translator: 'DateMarshaller' + module: 'DjinniSupport' +swiftxx: + translator: '::djinni::swift::Date' + header: '"djinni_support.hpp"' diff --git a/test-suite/djinni/vendor/third-party/duration.yaml b/test-suite/djinni/vendor/third-party/duration.yaml index 4a8b2d23..ad253731 100644 --- a/test-suite/djinni/vendor/third-party/duration.yaml +++ b/test-suite/djinni/vendor/third-party/duration.yaml @@ -38,6 +38,12 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationMarshaller' +swiftxx: + translator: '::djinni::swift::Duration' + header: '"Duration-swift.hpp"' --- name: h typedef: 'record' @@ -74,6 +80,12 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationH' +swiftxx: + translator: '::djinni::swift::Duration_h' + header: '"Duration-swift.hpp"' --- name: min typedef: 'record' @@ -110,6 +122,12 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationMin' +swiftxx: + translator: '::djinni::swift::Duration_min' + header: '"Duration-swift.hpp"' --- name: s typedef: 'record' @@ -146,6 +164,12 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationS' +swiftxx: + translator: '::djinni::swift::Duration_s' + header: '"Duration-swift.hpp"' --- name: ms typedef: 'record' @@ -182,6 +206,12 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationMs' +swiftxx: + translator: '::djinni::swift::Duration_ms' + header: '"Duration-swift.hpp"' --- name: us typedef: 'record' @@ -218,6 +248,12 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationUs' +swiftxx: + translator: '::djinni::swift::Duration_us' + header: '"Duration-swift.hpp"' --- name: ns typedef: 'record' @@ -254,3 +290,9 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationNs' +swiftxx: + translator: '::djinni::swift::Duration_ns' + header: '"Duration-swift.hpp"' diff --git a/test-suite/djinni/vendor/third-party/proto.yaml b/test-suite/djinni/vendor/third-party/proto.yaml index b14f0aa6..72ebbf07 100644 --- a/test-suite/djinni/vendor/third-party/proto.yaml +++ b/test-suite/djinni/vendor/third-party/proto.yaml @@ -9,7 +9,9 @@ objc: ts: module: '../../djinni/vendor/third-party/proto/ts/test' namespace: 'prototest' - +swift: + module: 'ProtobufTest' + prefix: 'Djinni_Test_' messages: - Person - AddressBook diff --git a/test-suite/djinni/vendor/third-party/proto/run_protoc.sh b/test-suite/djinni/vendor/third-party/proto/run_protoc.sh index 8b44d4cf..5f5e11e1 100755 --- a/test-suite/djinni/vendor/third-party/proto/run_protoc.sh +++ b/test-suite/djinni/vendor/third-party/proto/run_protoc.sh @@ -1,3 +1,4 @@ #! /usr/bin/env bash +# Swift codegen: with protoc-gen-swift (from https://github.com/apple/swift-protobuf) in path, add `--swift_out=swift --swift_opt=Visibility=public` to command line protoc --plugin=$(which protoc-gen-ts_proto) --objc_out=objc --java_out=java --cpp_out=cpp --ts_proto_out=ts test.proto protoc --plugin=$(which protoc-gen-ts_proto) --java_out=java --cpp_out=cpp --ts_proto_out=ts test2.proto diff --git a/test-suite/djinni/vendor/third-party/proto/swift/test.pb.swift b/test-suite/djinni/vendor/third-party/proto/swift/test.pb.swift new file mode 100644 index 00000000..6b838dcd --- /dev/null +++ b/test-suite/djinni/vendor/third-party/proto/swift/test.pb.swift @@ -0,0 +1,293 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: test.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +public struct Djinni_Test_Person: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var name: String { + get {return _name ?? String()} + set {_name = newValue} + } + /// Returns true if `name` has been explicitly set. + public var hasName: Bool {return self._name != nil} + /// Clears the value of `name`. Subsequent reads from it will return its default value. + public mutating func clearName() {self._name = nil} + + public var id: Int32 { + get {return _id ?? 0} + set {_id = newValue} + } + /// Returns true if `id` has been explicitly set. + public var hasID: Bool {return self._id != nil} + /// Clears the value of `id`. Subsequent reads from it will return its default value. + public mutating func clearID() {self._id = nil} + + public var email: String { + get {return _email ?? String()} + set {_email = newValue} + } + /// Returns true if `email` has been explicitly set. + public var hasEmail: Bool {return self._email != nil} + /// Clears the value of `email`. Subsequent reads from it will return its default value. + public mutating func clearEmail() {self._email = nil} + + public var phones: [Djinni_Test_Person.PhoneNumber] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum PhoneType: SwiftProtobuf.Enum, Swift.CaseIterable { + public typealias RawValue = Int + case mobile // = 0 + case home // = 1 + case work // = 2 + + public init() { + self = .mobile + } + + public init?(rawValue: Int) { + switch rawValue { + case 0: self = .mobile + case 1: self = .home + case 2: self = .work + default: return nil + } + } + + public var rawValue: Int { + switch self { + case .mobile: return 0 + case .home: return 1 + case .work: return 2 + } + } + + } + + public struct PhoneNumber: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var number: String { + get {return _number ?? String()} + set {_number = newValue} + } + /// Returns true if `number` has been explicitly set. + public var hasNumber: Bool {return self._number != nil} + /// Clears the value of `number`. Subsequent reads from it will return its default value. + public mutating func clearNumber() {self._number = nil} + + public var type: Djinni_Test_Person.PhoneType { + get {return _type ?? .home} + set {_type = newValue} + } + /// Returns true if `type` has been explicitly set. + public var hasType: Bool {return self._type != nil} + /// Clears the value of `type`. Subsequent reads from it will return its default value. + public mutating func clearType() {self._type = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _number: String? = nil + fileprivate var _type: Djinni_Test_Person.PhoneType? = nil + } + + public init() {} + + fileprivate var _name: String? = nil + fileprivate var _id: Int32? = nil + fileprivate var _email: String? = nil +} + +public struct Djinni_Test_AddressBook: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var people: [Djinni_Test_Person] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "djinni.test" + +extension Djinni_Test_Person: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Person" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "id"), + 3: .same(proto: "email"), + 4: .same(proto: "phones"), + ] + + public var isInitialized: Bool { + if self._name == nil {return false} + if self._id == nil {return false} + if !SwiftProtobuf.Internal.areAllInitialized(self.phones) {return false} + return true + } + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self._name) }() + case 2: try { try decoder.decodeSingularInt32Field(value: &self._id) }() + case 3: try { try decoder.decodeSingularStringField(value: &self._email) }() + case 4: try { try decoder.decodeRepeatedMessageField(value: &self.phones) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._name { + try visitor.visitSingularStringField(value: v, fieldNumber: 1) + } }() + try { if let v = self._id { + try visitor.visitSingularInt32Field(value: v, fieldNumber: 2) + } }() + try { if let v = self._email { + try visitor.visitSingularStringField(value: v, fieldNumber: 3) + } }() + if !self.phones.isEmpty { + try visitor.visitRepeatedMessageField(value: self.phones, fieldNumber: 4) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Djinni_Test_Person, rhs: Djinni_Test_Person) -> Bool { + if lhs._name != rhs._name {return false} + if lhs._id != rhs._id {return false} + if lhs._email != rhs._email {return false} + if lhs.phones != rhs.phones {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Djinni_Test_Person.PhoneType: SwiftProtobuf._ProtoNameProviding { + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "MOBILE"), + 1: .same(proto: "HOME"), + 2: .same(proto: "WORK"), + ] +} + +extension Djinni_Test_Person.PhoneNumber: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Djinni_Test_Person.protoMessageName + ".PhoneNumber" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "number"), + 2: .same(proto: "type"), + ] + + public var isInitialized: Bool { + if self._number == nil {return false} + return true + } + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self._number) }() + case 2: try { try decoder.decodeSingularEnumField(value: &self._type) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._number { + try visitor.visitSingularStringField(value: v, fieldNumber: 1) + } }() + try { if let v = self._type { + try visitor.visitSingularEnumField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Djinni_Test_Person.PhoneNumber, rhs: Djinni_Test_Person.PhoneNumber) -> Bool { + if lhs._number != rhs._number {return false} + if lhs._type != rhs._type {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Djinni_Test_AddressBook: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".AddressBook" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "people"), + ] + + public var isInitialized: Bool { + if !SwiftProtobuf.Internal.areAllInitialized(self.people) {return false} + return true + } + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.people) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.people.isEmpty { + try visitor.visitRepeatedMessageField(value: self.people, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Djinni_Test_AddressBook, rhs: Djinni_Test_AddressBook) -> Bool { + if lhs.people != rhs.people {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/test-suite/djinni/vendor/third-party/proto/swift/test2.pb.swift b/test-suite/djinni/vendor/third-party/proto/swift/test2.pb.swift new file mode 100644 index 00000000..53d0ba78 --- /dev/null +++ b/test-suite/djinni/vendor/third-party/proto/swift/test2.pb.swift @@ -0,0 +1,77 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: test2.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +public struct Djinni_Test2_PersistingState: Sendable { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var userID: String = String() + + public var isActive: Bool = false + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "djinni.test2" + +extension Djinni_Test2_PersistingState: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PersistingState" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "user_id"), + 2: .standard(proto: "is_active"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.userID) }() + case 2: try { try decoder.decodeSingularBoolField(value: &self.isActive) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.userID.isEmpty { + try visitor.visitSingularStringField(value: self.userID, fieldNumber: 1) + } + if self.isActive != false { + try visitor.visitSingularBoolField(value: self.isActive, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Djinni_Test2_PersistingState, rhs: Djinni_Test2_PersistingState) -> Bool { + if lhs.userID != rhs.userID {return false} + if lhs.isActive != rhs.isActive {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/test-suite/djinni/vendor/third-party/proto2.yaml b/test-suite/djinni/vendor/third-party/proto2.yaml index 8b6cf4c6..e6d0face 100644 --- a/test-suite/djinni/vendor/third-party/proto2.yaml +++ b/test-suite/djinni/vendor/third-party/proto2.yaml @@ -6,6 +6,9 @@ java: ts: module: '../../djinni/vendor/third-party/proto/ts/test2' namespace: 'prototest2' +swift: + module: 'ProtobufTest' + prefix: 'Djinni_Test2_' messages: - PersistingState diff --git a/test-suite/generated-src/cpp/conflict_user.hpp b/test-suite/generated-src/cpp/conflict_user.hpp index bc6a6686..9786e885 100644 --- a/test-suite/generated-src/cpp/conflict_user.hpp +++ b/test-suite/generated-src/cpp/conflict_user.hpp @@ -4,7 +4,7 @@ #pragma once #include -#include +#include namespace testsuite { @@ -16,7 +16,7 @@ class ConflictUser { virtual /*not-null*/ std::shared_ptr<::testsuite::Conflict> Conflict() = 0; - virtual bool conflict_arg(const std::unordered_set> & cs) = 0; + virtual bool conflict_arg(const std::vector> & cs) = 0; }; } // namespace testsuite diff --git a/test-suite/generated-src/cpp/constant_record.cpp b/test-suite/generated-src/cpp/constant_record.cpp new file mode 100644 index 00000000..00c30c96 --- /dev/null +++ b/test-suite/generated-src/cpp/constant_record.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +#include "constant_record.hpp" // my header + +namespace testsuite { + + +bool operator==(const ConstantRecord& lhs, const ConstantRecord& rhs) { + return lhs.some_integer == rhs.some_integer && + lhs.some_string == rhs.some_string; +} + +bool operator!=(const ConstantRecord& lhs, const ConstantRecord& rhs) { + return !(lhs == rhs); +} + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/constant_record.hpp b/test-suite/generated-src/cpp/constant_record.hpp index c2c5da68..5519b593 100644 --- a/test-suite/generated-src/cpp/constant_record.hpp +++ b/test-suite/generated-src/cpp/constant_record.hpp @@ -14,6 +14,9 @@ struct ConstantRecord final { int32_t some_integer; std::string some_string; + friend bool operator==(const ConstantRecord& lhs, const ConstantRecord& rhs); + friend bool operator!=(const ConstantRecord& lhs, const ConstantRecord& rhs); + ConstantRecord(int32_t some_integer_, std::string some_string_) : some_integer(std::move(some_integer_)) diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ConflictUser.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ConflictUser.java index 7bc066f8..f6bf3b8b 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ConflictUser.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ConflictUser.java @@ -4,7 +4,7 @@ package com.dropbox.djinni.test; import com.snapchat.djinni.NativeObjectManager; -import java.util.HashSet; +import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; @@ -13,7 +13,7 @@ public abstract class ConflictUser { @CheckForNull public abstract Conflict Conflict(); - public abstract boolean conflictArg(@Nonnull HashSet cs); + public abstract boolean conflictArg(@Nonnull ArrayList cs); public static final class CppProxy extends ConflictUser { @@ -37,11 +37,11 @@ public Conflict Conflict() private native Conflict native_Conflict(long _nativeRef); @Override - public boolean conflictArg(HashSet cs) + public boolean conflictArg(ArrayList cs) { assert !this.destroyed.get() : "trying to use a destroyed object"; return native_conflictArg(this.nativeRef, cs); } - private native boolean native_conflictArg(long _nativeRef, HashSet cs); + private native boolean native_conflictArg(long _nativeRef, ArrayList cs); } } diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ConstantRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ConstantRecord.java index 103c54e7..6946fbcc 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ConstantRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ConstantRecord.java @@ -38,6 +38,25 @@ public void setSomeString(@Nonnull String someString) { this.mSomeString = someString; } + @Override + public boolean equals(@CheckForNull Object obj) { + if (!(obj instanceof ConstantRecord)) { + return false; + } + ConstantRecord other = (ConstantRecord) obj; + return this.mSomeInteger == other.mSomeInteger && + this.mSomeString.equals(other.mSomeString); + } + + @Override + public int hashCode() { + // Pick an arbitrary non-zero starting value + int hashCode = 17; + hashCode = hashCode * 31 + mSomeInteger; + hashCode = hashCode * 31 + mSomeString.hashCode(); + return hashCode; + } + @Override public String toString() { return "ConstantRecord{" + diff --git a/test-suite/generated-src/jni/NativeConflictUser.cpp b/test-suite/generated-src/jni/NativeConflictUser.cpp index 34deb948..f4f403cb 100644 --- a/test-suite/generated-src/jni/NativeConflictUser.cpp +++ b/test-suite/generated-src/jni/NativeConflictUser.cpp @@ -32,7 +32,7 @@ CJNIEXPORT jboolean JNICALL Java_com_dropbox_djinni_test_ConflictUser_00024CppPr { try { const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::ConflictUser>(nativeRef); - auto r = ref->conflict_arg(::djinni::Set<::djinni_generated::NativeConflict>::toCpp(jniEnv, j_cs)); + auto r = ref->conflict_arg(::djinni::List<::djinni_generated::NativeConflict>::toCpp(jniEnv, j_cs)); return ::djinni::release(::djinni::Bool::fromCpp(jniEnv, r)); } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) } diff --git a/test-suite/generated-src/objc/DBConflictUser+Private.mm b/test-suite/generated-src/objc/DBConflictUser+Private.mm index 818e0a79..eb6dd45a 100644 --- a/test-suite/generated-src/objc/DBConflictUser+Private.mm +++ b/test-suite/generated-src/objc/DBConflictUser+Private.mm @@ -39,9 +39,9 @@ - (nullable DBConflict *)Conflict { } DJINNI_TRANSLATE_EXCEPTIONS() } -- (BOOL)conflictArg:(nonnull NSSet *)cs { +- (BOOL)conflictArg:(nonnull NSArray *)cs { try { - auto objcpp_result_ = _cppRefHandle.get()->conflict_arg(::djinni::Set<::djinni_generated::Conflict>::toCpp(cs)); + auto objcpp_result_ = _cppRefHandle.get()->conflict_arg(::djinni::List<::djinni_generated::Conflict>::toCpp(cs)); return ::djinni::Bool::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/test-suite/generated-src/objc/DBConflictUser.h b/test-suite/generated-src/objc/DBConflictUser.h index 5d351b25..1aef47f4 100644 --- a/test-suite/generated-src/objc/DBConflictUser.h +++ b/test-suite/generated-src/objc/DBConflictUser.h @@ -9,6 +9,6 @@ - (nullable DBConflict *)Conflict; -- (BOOL)conflictArg:(nonnull NSSet *)cs; +- (BOOL)conflictArg:(nonnull NSArray *)cs; @end diff --git a/test-suite/generated-src/objc/DBConstantRecord.mm b/test-suite/generated-src/objc/DBConstantRecord.mm index d3ff8d90..9dc54925 100644 --- a/test-suite/generated-src/objc/DBConstantRecord.mm +++ b/test-suite/generated-src/objc/DBConstantRecord.mm @@ -23,6 +23,23 @@ + (nonnull instancetype)constantRecordWithSomeInteger:(int32_t)someInteger someString:someString]; } +- (BOOL)isEqual:(id)other +{ + if (![other isKindOfClass:[DBConstantRecord class]]) { + return NO; + } + DBConstantRecord *typedOther = (DBConstantRecord *)other; + return self.someInteger == typedOther.someInteger && + [self.someString isEqualToString:typedOther.someString]; +} + +- (NSUInteger)hash +{ + return NSStringFromClass([self class]).hash ^ + (NSUInteger)self.someInteger ^ + self.someString.hash; +} + #ifndef DJINNI_DISABLE_DESCRIPTION_METHODS - (NSString *)description { diff --git a/test-suite/generated-src/outFileList.txt b/test-suite/generated-src/outFileList.txt index 555f56f8..c807d95a 100644 --- a/test-suite/generated-src/outFileList.txt +++ b/test-suite/generated-src/outFileList.txt @@ -42,6 +42,7 @@ djinni-output-temp/cpp/listener_caller.hpp djinni-output-temp/cpp/return_one.hpp djinni-output-temp/cpp/return_two.hpp djinni-output-temp/cpp/constant_record.hpp +djinni-output-temp/cpp/constant_record.cpp djinni-output-temp/cpp/constants.hpp djinni-output-temp/cpp/constants.cpp djinni-output-temp/cpp/constants_interface.hpp @@ -574,4 +575,244 @@ djinni-output-temp/wasm/NativeRecordWithNestedDerivings.cpp djinni-output-temp/wasm/NativeSetRecord.hpp djinni-output-temp/wasm/NativeSetRecord.cpp djinni-output-temp/ts/test.ts +djinni-output-temp/swift/RecordWithEmbeddedProto.swift +djinni-output-temp/swift/RecordWithEmbeddedProto+Private.swift +djinni-output-temp/swift/RecordWithEmbeddedCppProto.swift +djinni-output-temp/swift/RecordWithEmbeddedCppProto+Private.swift +djinni-output-temp/swift/ProtoTests.swift +djinni-output-temp/swift/ProtoTests+Private.swift +djinni-output-temp/swift/NestedOutcome.swift +djinni-output-temp/swift/NestedOutcome+Private.swift +djinni-output-temp/swift/TestOutcome.swift +djinni-output-temp/swift/TestOutcome+Private.swift +djinni-output-temp/swift/TestDuration.swift +djinni-output-temp/swift/TestDuration+Private.swift +djinni-output-temp/swift/RecordWithDurationAndDerivings.swift +djinni-output-temp/swift/RecordWithDurationAndDerivings+Private.swift +djinni-output-temp/swift/DateRecord.swift +djinni-output-temp/swift/DateRecord+Private.swift +djinni-output-temp/swift/MapDateRecord.swift +djinni-output-temp/swift/MapDateRecord+Private.swift +djinni-output-temp/swift/DataRefTest.swift +djinni-output-temp/swift/DataRefTest+Private.swift +djinni-output-temp/swift/ConstantEnum.swift +djinni-output-temp/swift/ConstantEnum+Private.swift +djinni-output-temp/swift/ConstantWithEnum.swift +djinni-output-temp/swift/ConstantWithEnum+Private.swift +djinni-output-temp/swift/ConstantInterfaceWithEnum.swift +djinni-output-temp/swift/ConstantInterfaceWithEnum+Private.swift +djinni-output-temp/swift/AccessFlags.swift +djinni-output-temp/swift/AccessFlags+Private.swift +djinni-output-temp/swift/EmptyFlags.swift +djinni-output-temp/swift/EmptyFlags+Private.swift +djinni-output-temp/swift/FlagRoundtrip.swift +djinni-output-temp/swift/FlagRoundtrip+Private.swift +djinni-output-temp/swift/RecordWithFlags.swift +djinni-output-temp/swift/RecordWithFlags+Private.swift +djinni-output-temp/swift/TestStaticMethodLanguage.swift +djinni-output-temp/swift/TestStaticMethodLanguage+Private.swift +djinni-output-temp/swift/SupportCopying.swift +djinni-output-temp/swift/SupportCopying+Private.swift +djinni-output-temp/swift/Vec2.swift +djinni-output-temp/swift/Vec2+Private.swift +djinni-output-temp/swift/TestArray.swift +djinni-output-temp/swift/TestArray+Private.swift +djinni-output-temp/swift/VarnameRecord.swift +djinni-output-temp/swift/VarnameRecord+Private.swift +djinni-output-temp/swift/VarnameInterface.swift +djinni-output-temp/swift/VarnameInterface+Private.swift +djinni-output-temp/swift/ExtendedRecord.swift +djinni-output-temp/swift/ExtendedRecord+Private.swift +djinni-output-temp/swift/RecordUsingExtendedRecord.swift +djinni-output-temp/swift/RecordUsingExtendedRecord+Private.swift +djinni-output-temp/swift/InterfaceUsingExtendedRecord.swift +djinni-output-temp/swift/InterfaceUsingExtendedRecord+Private.swift +djinni-output-temp/swift/ObjcOnlyListener.swift +djinni-output-temp/swift/ObjcOnlyListener+Private.swift +djinni-output-temp/swift/JavaOnlyListener.swift +djinni-output-temp/swift/JavaOnlyListener+Private.swift +djinni-output-temp/swift/UsesSingleLanguageListeners.swift +djinni-output-temp/swift/UsesSingleLanguageListeners+Private.swift +djinni-output-temp/swift/FirstListener.swift +djinni-output-temp/swift/FirstListener+Private.swift +djinni-output-temp/swift/SecondListener.swift +djinni-output-temp/swift/SecondListener+Private.swift +djinni-output-temp/swift/ListenerCaller.swift +djinni-output-temp/swift/ListenerCaller+Private.swift +djinni-output-temp/swift/ReturnOne.swift +djinni-output-temp/swift/ReturnOne+Private.swift +djinni-output-temp/swift/ReturnTwo.swift +djinni-output-temp/swift/ReturnTwo+Private.swift +djinni-output-temp/swift/ConstantRecord.swift +djinni-output-temp/swift/ConstantRecord+Private.swift +djinni-output-temp/swift/Constants.swift +djinni-output-temp/swift/Constants+Private.swift +djinni-output-temp/swift/ConstantsInterface.swift +djinni-output-temp/swift/ConstantsInterface+Private.swift +djinni-output-temp/swift/AssortedPrimitives.swift +djinni-output-temp/swift/AssortedPrimitives+Private.swift +djinni-output-temp/swift/AsyncInterface.swift +djinni-output-temp/swift/AsyncInterface+Private.swift +djinni-output-temp/swift/TestHelpers.swift +djinni-output-temp/swift/TestHelpers+Private.swift +djinni-output-temp/swift/EmptyRecord.swift +djinni-output-temp/swift/EmptyRecord+Private.swift +djinni-output-temp/swift/Conflict.swift +djinni-output-temp/swift/Conflict+Private.swift +djinni-output-temp/swift/ConflictUser.swift +djinni-output-temp/swift/ConflictUser+Private.swift +djinni-output-temp/swift/SampleInterface.swift +djinni-output-temp/swift/SampleInterface+Private.swift +djinni-output-temp/swift/UserToken.swift +djinni-output-temp/swift/UserToken+Private.swift +djinni-output-temp/swift/Color.swift +djinni-output-temp/swift/Color+Private.swift +djinni-output-temp/swift/EnumUsageRecord.swift +djinni-output-temp/swift/EnumUsageRecord+Private.swift +djinni-output-temp/swift/EnumUsageInterface.swift +djinni-output-temp/swift/EnumUsageInterface+Private.swift +djinni-output-temp/swift/ClientReturnedRecord.swift +djinni-output-temp/swift/ClientReturnedRecord+Private.swift +djinni-output-temp/swift/ClientInterface.swift +djinni-output-temp/swift/ClientInterface+Private.swift +djinni-output-temp/swift/ReverseClientInterface.swift +djinni-output-temp/swift/ReverseClientInterface+Private.swift +djinni-output-temp/swift/ThrowingInterface.swift +djinni-output-temp/swift/ThrowingInterface+Private.swift +djinni-output-temp/swift/CppException.swift +djinni-output-temp/swift/CppException+Private.swift +djinni-output-temp/swift/PrimitiveList.swift +djinni-output-temp/swift/PrimitiveList+Private.swift +djinni-output-temp/swift/MapRecord.swift +djinni-output-temp/swift/MapRecord+Private.swift +djinni-output-temp/swift/MapListRecord.swift +djinni-output-temp/swift/MapListRecord+Private.swift +djinni-output-temp/swift/NestedCollection.swift +djinni-output-temp/swift/NestedCollection+Private.swift +djinni-output-temp/swift/RecordWithDerivings.swift +djinni-output-temp/swift/RecordWithDerivings+Private.swift +djinni-output-temp/swift/RecordWithNestedDerivings.swift +djinni-output-temp/swift/RecordWithNestedDerivings+Private.swift +djinni-output-temp/swift/SetRecord.swift +djinni-output-temp/swift/SetRecord+Private.swift +djinni-output-temp/swiftxx/NativeRecordWithEmbeddedProto.hpp +djinni-output-temp/swiftxx/NativeRecordWithEmbeddedProto.cpp +djinni-output-temp/swiftxx/NativeRecordWithEmbeddedCppProto.hpp +djinni-output-temp/swiftxx/NativeRecordWithEmbeddedCppProto.cpp +djinni-output-temp/swiftxx/NativeProtoTests.hpp +djinni-output-temp/swiftxx/NativeProtoTests.cpp +djinni-output-temp/swiftxx/NativeNestedOutcome.hpp +djinni-output-temp/swiftxx/NativeNestedOutcome.cpp +djinni-output-temp/swiftxx/NativeTestOutcome.hpp +djinni-output-temp/swiftxx/NativeTestOutcome.cpp +djinni-output-temp/swiftxx/NativeTestDuration.hpp +djinni-output-temp/swiftxx/NativeTestDuration.cpp +djinni-output-temp/swiftxx/NativeRecordWithDurationAndDerivings.hpp +djinni-output-temp/swiftxx/NativeRecordWithDurationAndDerivings.cpp +djinni-output-temp/swiftxx/NativeDateRecord.hpp +djinni-output-temp/swiftxx/NativeDateRecord.cpp +djinni-output-temp/swiftxx/NativeMapDateRecord.hpp +djinni-output-temp/swiftxx/NativeMapDateRecord.cpp +djinni-output-temp/swiftxx/NativeDataRefTest.hpp +djinni-output-temp/swiftxx/NativeDataRefTest.cpp +djinni-output-temp/swiftxx/NativeConstantEnum.hpp +djinni-output-temp/swiftxx/NativeConstantEnum.cpp +djinni-output-temp/swiftxx/NativeConstantWithEnum.hpp +djinni-output-temp/swiftxx/NativeConstantWithEnum.cpp +djinni-output-temp/swiftxx/NativeConstantInterfaceWithEnum.hpp +djinni-output-temp/swiftxx/NativeConstantInterfaceWithEnum.cpp +djinni-output-temp/swiftxx/NativeAccessFlags.hpp +djinni-output-temp/swiftxx/NativeAccessFlags.cpp +djinni-output-temp/swiftxx/NativeEmptyFlags.hpp +djinni-output-temp/swiftxx/NativeEmptyFlags.cpp +djinni-output-temp/swiftxx/NativeFlagRoundtrip.hpp +djinni-output-temp/swiftxx/NativeFlagRoundtrip.cpp +djinni-output-temp/swiftxx/NativeRecordWithFlags.hpp +djinni-output-temp/swiftxx/NativeRecordWithFlags.cpp +djinni-output-temp/swiftxx/NativeTestStaticMethodLanguage.hpp +djinni-output-temp/swiftxx/NativeTestStaticMethodLanguage.cpp +djinni-output-temp/swiftxx/NativeSupportCopying.hpp +djinni-output-temp/swiftxx/NativeSupportCopying.cpp +djinni-output-temp/swiftxx/NativeVec2.hpp +djinni-output-temp/swiftxx/NativeVec2.cpp +djinni-output-temp/swiftxx/NativeTestArray.hpp +djinni-output-temp/swiftxx/NativeTestArray.cpp +djinni-output-temp/swiftxx/NativeVarnameRecord.hpp +djinni-output-temp/swiftxx/NativeVarnameRecord.cpp +djinni-output-temp/swiftxx/NativeVarnameInterface.hpp +djinni-output-temp/swiftxx/NativeVarnameInterface.cpp +djinni-output-temp/swiftxx/NativeExtendedRecord.hpp +djinni-output-temp/swiftxx/NativeExtendedRecord.cpp +djinni-output-temp/swiftxx/NativeRecordUsingExtendedRecord.hpp +djinni-output-temp/swiftxx/NativeRecordUsingExtendedRecord.cpp +djinni-output-temp/swiftxx/NativeInterfaceUsingExtendedRecord.hpp +djinni-output-temp/swiftxx/NativeInterfaceUsingExtendedRecord.cpp +djinni-output-temp/swiftxx/NativeObjcOnlyListener.hpp +djinni-output-temp/swiftxx/NativeObjcOnlyListener.cpp +djinni-output-temp/swiftxx/NativeJavaOnlyListener.hpp +djinni-output-temp/swiftxx/NativeJavaOnlyListener.cpp +djinni-output-temp/swiftxx/NativeUsesSingleLanguageListeners.hpp +djinni-output-temp/swiftxx/NativeUsesSingleLanguageListeners.cpp +djinni-output-temp/swiftxx/NativeFirstListener.hpp +djinni-output-temp/swiftxx/NativeFirstListener.cpp +djinni-output-temp/swiftxx/NativeSecondListener.hpp +djinni-output-temp/swiftxx/NativeSecondListener.cpp +djinni-output-temp/swiftxx/NativeListenerCaller.hpp +djinni-output-temp/swiftxx/NativeListenerCaller.cpp +djinni-output-temp/swiftxx/NativeReturnOne.hpp +djinni-output-temp/swiftxx/NativeReturnOne.cpp +djinni-output-temp/swiftxx/NativeReturnTwo.hpp +djinni-output-temp/swiftxx/NativeReturnTwo.cpp +djinni-output-temp/swiftxx/NativeConstantRecord.hpp +djinni-output-temp/swiftxx/NativeConstantRecord.cpp +djinni-output-temp/swiftxx/NativeConstants.hpp +djinni-output-temp/swiftxx/NativeConstants.cpp +djinni-output-temp/swiftxx/NativeConstantsInterface.hpp +djinni-output-temp/swiftxx/NativeConstantsInterface.cpp +djinni-output-temp/swiftxx/NativeAssortedPrimitives.hpp +djinni-output-temp/swiftxx/NativeAssortedPrimitives.cpp +djinni-output-temp/swiftxx/NativeAsyncInterface.hpp +djinni-output-temp/swiftxx/NativeAsyncInterface.cpp +djinni-output-temp/swiftxx/NativeTestHelpers.hpp +djinni-output-temp/swiftxx/NativeTestHelpers.cpp +djinni-output-temp/swiftxx/NativeEmptyRecord.hpp +djinni-output-temp/swiftxx/NativeEmptyRecord.cpp +djinni-output-temp/swiftxx/NativeConflict.hpp +djinni-output-temp/swiftxx/NativeConflict.cpp +djinni-output-temp/swiftxx/NativeConflictUser.hpp +djinni-output-temp/swiftxx/NativeConflictUser.cpp +djinni-output-temp/swiftxx/NativeSampleInterface.hpp +djinni-output-temp/swiftxx/NativeSampleInterface.cpp +djinni-output-temp/swiftxx/NativeUserToken.hpp +djinni-output-temp/swiftxx/NativeUserToken.cpp +djinni-output-temp/swiftxx/NativeColor.hpp +djinni-output-temp/swiftxx/NativeColor.cpp +djinni-output-temp/swiftxx/NativeEnumUsageRecord.hpp +djinni-output-temp/swiftxx/NativeEnumUsageRecord.cpp +djinni-output-temp/swiftxx/NativeEnumUsageInterface.hpp +djinni-output-temp/swiftxx/NativeEnumUsageInterface.cpp +djinni-output-temp/swiftxx/NativeClientReturnedRecord.hpp +djinni-output-temp/swiftxx/NativeClientReturnedRecord.cpp +djinni-output-temp/swiftxx/NativeClientInterface.hpp +djinni-output-temp/swiftxx/NativeClientInterface.cpp +djinni-output-temp/swiftxx/NativeReverseClientInterface.hpp +djinni-output-temp/swiftxx/NativeReverseClientInterface.cpp +djinni-output-temp/swiftxx/NativeThrowingInterface.hpp +djinni-output-temp/swiftxx/NativeThrowingInterface.cpp +djinni-output-temp/swiftxx/NativeCppException.hpp +djinni-output-temp/swiftxx/NativeCppException.cpp +djinni-output-temp/swiftxx/NativePrimitiveList.hpp +djinni-output-temp/swiftxx/NativePrimitiveList.cpp +djinni-output-temp/swiftxx/NativeMapRecord.hpp +djinni-output-temp/swiftxx/NativeMapRecord.cpp +djinni-output-temp/swiftxx/NativeMapListRecord.hpp +djinni-output-temp/swiftxx/NativeMapListRecord.cpp +djinni-output-temp/swiftxx/NativeNestedCollection.hpp +djinni-output-temp/swiftxx/NativeNestedCollection.cpp +djinni-output-temp/swiftxx/NativeRecordWithDerivings.hpp +djinni-output-temp/swiftxx/NativeRecordWithDerivings.cpp +djinni-output-temp/swiftxx/NativeRecordWithNestedDerivings.hpp +djinni-output-temp/swiftxx/NativeRecordWithNestedDerivings.cpp +djinni-output-temp/swiftxx/NativeSetRecord.hpp +djinni-output-temp/swiftxx/NativeSetRecord.cpp djinni-output-temp/yaml/yaml-test.yaml diff --git a/test-suite/generated-src/swift/AccessFlags+Private.swift b/test-suite/generated-src/swift/AccessFlags+Private.swift new file mode 100644 index 00000000..fdce498d --- /dev/null +++ b/test-suite/generated-src/swift/AccessFlags+Private.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +import DjinniSupport +import TestSuite + +typealias AccessFlagsMarshaller = DjinniSupport.EnumMarshaller diff --git a/test-suite/generated-src/swift/AccessFlags.swift b/test-suite/generated-src/swift/AccessFlags.swift new file mode 100644 index 00000000..6869cf65 --- /dev/null +++ b/test-suite/generated-src/swift/AccessFlags.swift @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +public struct AccessFlags: OptionSet { + public let rawValue: Int32 + public init(rawValue: Int32) { self.rawValue = rawValue } + public static let nobody: AccessFlags = [] + public static let ownerRead = AccessFlags(rawValue: 1 << 0) + public static let ownerWrite = AccessFlags(rawValue: 1 << 1) + public static let ownerExecute = AccessFlags(rawValue: 1 << 2) + public static let groupRead = AccessFlags(rawValue: 1 << 3) + public static let groupWrite = AccessFlags(rawValue: 1 << 4) + public static let groupExecute = AccessFlags(rawValue: 1 << 5) + public static let systemRead = AccessFlags(rawValue: 1 << 6) + public static let systemWrite = AccessFlags(rawValue: 1 << 7) + public static let systemExecute = AccessFlags(rawValue: 1 << 8) + public static let everybody: AccessFlags = [.ownerRead, .ownerWrite, .ownerExecute, .groupRead, .groupWrite, .groupExecute, .systemRead, .systemWrite, .systemExecute]} diff --git a/test-suite/generated-src/swift/AssortedPrimitives+Private.swift b/test-suite/generated-src/swift/AssortedPrimitives+Private.swift new file mode 100644 index 00000000..75c29919 --- /dev/null +++ b/test-suite/generated-src/swift/AssortedPrimitives+Private.swift @@ -0,0 +1,49 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from primtypes.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum AssortedPrimitivesMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.AssortedPrimitives + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let b = BoolMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + let eight = I8Marshaller.fromCpp(djinni.swift.getMember(p, 1)) + let sixteen = I16Marshaller.fromCpp(djinni.swift.getMember(p, 2)) + let thirtytwo = I32Marshaller.fromCpp(djinni.swift.getMember(p, 3)) + let sixtyfour = I64Marshaller.fromCpp(djinni.swift.getMember(p, 4)) + let fthirtytwo = F32Marshaller.fromCpp(djinni.swift.getMember(p, 5)) + let fsixtyfour = F64Marshaller.fromCpp(djinni.swift.getMember(p, 6)) + let oB = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 7)) + let oEight = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 8)) + let oSixteen = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 9)) + let oThirtytwo = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 10)) + let oSixtyfour = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 11)) + let oFthirtytwo = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 12)) + let oFsixtyfour = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 13)) + return SwiftType(b: b, eight: eight, sixteen: sixteen, thirtytwo: thirtytwo, sixtyfour: sixtyfour, fthirtytwo: fthirtytwo, fsixtyfour: fsixtyfour, oB: oB, oEight: oEight, oSixteen: oSixteen, oThirtytwo: oThirtytwo, oSixtyfour: oSixtyfour, oFthirtytwo: oFthirtytwo, oFsixtyfour: oFsixtyfour) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, BoolMarshaller.toCpp(s.b)) + djinni.swift.addMember(&ret, I8Marshaller.toCpp(s.eight)) + djinni.swift.addMember(&ret, I16Marshaller.toCpp(s.sixteen)) + djinni.swift.addMember(&ret, I32Marshaller.toCpp(s.thirtytwo)) + djinni.swift.addMember(&ret, I64Marshaller.toCpp(s.sixtyfour)) + djinni.swift.addMember(&ret, F32Marshaller.toCpp(s.fthirtytwo)) + djinni.swift.addMember(&ret, F64Marshaller.toCpp(s.fsixtyfour)) + djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.oB)) + djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.oEight)) + djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.oSixteen)) + djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.oThirtytwo)) + djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.oSixtyfour)) + djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.oFthirtytwo)) + djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.oFsixtyfour)) + return ret + } +} diff --git a/test-suite/generated-src/swift/AssortedPrimitives.swift b/test-suite/generated-src/swift/AssortedPrimitives.swift new file mode 100644 index 00000000..242ee7c6 --- /dev/null +++ b/test-suite/generated-src/swift/AssortedPrimitives.swift @@ -0,0 +1,39 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from primtypes.djinni + +import Foundation + +public struct AssortedPrimitives: Equatable { + public var b: Bool + public var eight: Int8 + public var sixteen: Int16 + public var thirtytwo: Int32 + public var sixtyfour: Int64 + public var fthirtytwo: Float + public var fsixtyfour: Double + public var oB: Optional + public var oEight: Optional + public var oSixteen: Optional + public var oThirtytwo: Optional + public var oSixtyfour: Optional + public var oFthirtytwo: Optional + public var oFsixtyfour: Optional + + public init(b: Bool, eight: Int8, sixteen: Int16, thirtytwo: Int32, sixtyfour: Int64, fthirtytwo: Float, fsixtyfour: Double, oB: Optional, oEight: Optional, oSixteen: Optional, oThirtytwo: Optional, oSixtyfour: Optional, oFthirtytwo: Optional, oFsixtyfour: Optional) + { + self.b = b + self.eight = eight + self.sixteen = sixteen + self.thirtytwo = thirtytwo + self.sixtyfour = sixtyfour + self.fthirtytwo = fthirtytwo + self.fsixtyfour = fsixtyfour + self.oB = oB + self.oEight = oEight + self.oSixteen = oSixteen + self.oThirtytwo = oThirtytwo + self.oSixtyfour = oSixtyfour + self.oFthirtytwo = oFthirtytwo + self.oFsixtyfour = oFsixtyfour + } +} diff --git a/test-suite/generated-src/swift/AsyncInterface+Private.swift b/test-suite/generated-src/swift/AsyncInterface+Private.swift new file mode 100644 index 00000000..8908389d --- /dev/null +++ b/test-suite/generated-src/swift/AsyncInterface+Private.swift @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +let asyncInterfaceMethods: Vtbl = [ + { inst, params, ret in + let _f = FutureMarshaller.fromCpp(djinni.swift.getMember(params, 0)) + djinni.swift.setReturnValue(ret, try FutureMarshaller.toCpp(inst.futureRoundtrip(f: _f))) + }, +] + +enum AsyncInterfaceMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.AsyncInterface + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { fatalError("n/a") }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { djinni_generated.AsyncInterfaceSwiftProxy.make(ctxPtr(s, asyncInterfaceMethods), dispatcherProtocalCall)}) + } +} diff --git a/test-suite/generated-src/swift/AsyncInterface.swift b/test-suite/generated-src/swift/AsyncInterface.swift new file mode 100644 index 00000000..a5f04b2c --- /dev/null +++ b/test-suite/generated-src/swift/AsyncInterface.swift @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +import DjinniSupport +import Foundation + +public protocol AsyncInterface: AnyObject { + func futureRoundtrip(f: DJFuture) throws -> DJFuture +} diff --git a/test-suite/generated-src/swift/ClientInterface+Private.swift b/test-suite/generated-src/swift/ClientInterface+Private.swift new file mode 100644 index 00000000..97ceddb5 --- /dev/null +++ b/test-suite/generated-src/swift/ClientInterface+Private.swift @@ -0,0 +1,45 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from client_interface.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +/** Client interface */ +let clientInterfaceMethods: Vtbl = [ + { inst, params, ret in + let _recordId = I64Marshaller.fromCpp(djinni.swift.getMember(params, 0)) + let _utf8string = StringMarshaller.fromCpp(djinni.swift.getMember(params, 1)) + let _misc = OptionalMarshaller.fromCpp(djinni.swift.getMember(params, 2)) + djinni.swift.setReturnValue(ret, try ClientReturnedRecordMarshaller.toCpp(inst.getRecord(recordId: _recordId, utf8string: _utf8string, misc: _misc))) + }, + { inst, params, ret in + let _data = BinaryMarshaller.fromCpp(djinni.swift.getMember(params, 0)) + let _r = I32Marshaller.fromCpp(djinni.swift.getMember(params, 1)) + let _jret = I64Marshaller.fromCpp(djinni.swift.getMember(params, 2)) + djinni.swift.setReturnValue(ret, try F64Marshaller.toCpp(inst.identifierCheck(data: _data, r: _r, jret: _jret))) + }, + { inst, params, ret in + djinni.swift.setReturnValue(ret, try StringMarshaller.toCpp(inst.returnStr())) + }, + { inst, params, ret in + let _i = ClientInterfaceMarshaller.fromCpp(djinni.swift.getMember(params, 0)) + djinni.swift.setReturnValue(ret, try StringMarshaller.toCpp(inst.methTakingInterface(i: _i))) + }, + { inst, params, ret in + let _i = OptionalMarshaller.fromCpp(djinni.swift.getMember(params, 0)) + djinni.swift.setReturnValue(ret, try StringMarshaller.toCpp(inst.methTakingOptionalInterface(i: _i))) + }, +] + +enum ClientInterfaceMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ClientInterface + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { fatalError("n/a") }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { djinni_generated.ClientInterfaceSwiftProxy.make(ctxPtr(s, clientInterfaceMethods), dispatcherProtocalCall)}) + } +} diff --git a/test-suite/generated-src/swift/ClientInterface.swift b/test-suite/generated-src/swift/ClientInterface.swift new file mode 100644 index 00000000..fd36ddd1 --- /dev/null +++ b/test-suite/generated-src/swift/ClientInterface.swift @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from client_interface.djinni + +import Foundation + +/** Client interface */ +public protocol ClientInterface: AnyObject { + /** Returns record of given string */ + func getRecord(recordId: Int64, utf8string: String, misc: Optional) throws -> TestSuite.ClientReturnedRecord + func identifierCheck(data: Data, r: Int32, jret: Int64) throws -> Double + func returnStr() throws -> String + func methTakingInterface(i: TestSuite.ClientInterface) throws -> String + func methTakingOptionalInterface(i: Optional) throws -> String +} diff --git a/test-suite/generated-src/swift/ClientReturnedRecord+Private.swift b/test-suite/generated-src/swift/ClientReturnedRecord+Private.swift new file mode 100644 index 00000000..11496b4f --- /dev/null +++ b/test-suite/generated-src/swift/ClientReturnedRecord+Private.swift @@ -0,0 +1,27 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from client_interface.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum ClientReturnedRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ClientReturnedRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let recordId = I64Marshaller.fromCpp(djinni.swift.getMember(p, 0)) + let content = StringMarshaller.fromCpp(djinni.swift.getMember(p, 1)) + let misc = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 2)) + return SwiftType(recordId: recordId, content: content, misc: misc) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, I64Marshaller.toCpp(s.recordId)) + djinni.swift.addMember(&ret, StringMarshaller.toCpp(s.content)) + djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.misc)) + return ret + } +} diff --git a/test-suite/generated-src/swift/ClientReturnedRecord.swift b/test-suite/generated-src/swift/ClientReturnedRecord.swift new file mode 100644 index 00000000..621c28bb --- /dev/null +++ b/test-suite/generated-src/swift/ClientReturnedRecord.swift @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from client_interface.djinni + +import Foundation + +/** Record returned by a client */ +public struct ClientReturnedRecord { + public var recordId: Int64 + public var content: String + public var misc: Optional + + public init(recordId: Int64, content: String, misc: Optional) + { + self.recordId = recordId + self.content = content + self.misc = misc + } +} diff --git a/test-suite/generated-src/swift/Color+Private.swift b/test-suite/generated-src/swift/Color+Private.swift new file mode 100644 index 00000000..9a233fc1 --- /dev/null +++ b/test-suite/generated-src/swift/Color+Private.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum.djinni + +import DjinniSupport +import TestSuite + +typealias ColorMarshaller = DjinniSupport.EnumMarshaller diff --git a/test-suite/generated-src/swift/Color.swift b/test-suite/generated-src/swift/Color.swift new file mode 100644 index 00000000..28ed95c5 --- /dev/null +++ b/test-suite/generated-src/swift/Color.swift @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum.djinni + +public enum Color: Int32 { + case red = 0 + case orange = 1 + case yellow = 2 + case green = 3 + case blue = 4 + /** + * "It is customary to list indigo as a color lying between blue and violet, but it has + * never seemed to me that indigo is worth the dignity of being considered a separate + * color. To my eyes it seems merely deep blue." --Isaac Asimov + */ + case indigo = 5 + case violet = 6 +} diff --git a/test-suite/generated-src/swift/Conflict+Private.swift b/test-suite/generated-src/swift/Conflict+Private.swift new file mode 100644 index 00000000..f7443b2c --- /dev/null +++ b/test-suite/generated-src/swift/Conflict+Private.swift @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +/** + * Test for conflict of method name with an interface name. + * See the comments about scopeSymbols in CppMarshal.scala for more info. + */ +final class ConflictCppProxy: DjinniSupport.CppProxy, TestSuite.Conflict { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } +} +enum ConflictMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.Conflict + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { ConflictCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/Conflict.swift b/test-suite/generated-src/swift/Conflict.swift new file mode 100644 index 00000000..b84ca0eb --- /dev/null +++ b/test-suite/generated-src/swift/Conflict.swift @@ -0,0 +1,11 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +import Foundation + +/** + * Test for conflict of method name with an interface name. + * See the comments about scopeSymbols in CppMarshal.scala for more info. + */ +public protocol Conflict: AnyObject { +} diff --git a/test-suite/generated-src/swift/ConflictUser+Private.swift b/test-suite/generated-src/swift/ConflictUser+Private.swift new file mode 100644 index 00000000..f73c9df3 --- /dev/null +++ b/test-suite/generated-src/swift/ConflictUser+Private.swift @@ -0,0 +1,36 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class ConflictUserCppProxy: DjinniSupport.CppProxy, TestSuite.ConflictUser { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func Conflict() throws -> TestSuite.Conflict { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.ConflictUser_Conflict(¶ms) + try handleCppErrors(&ret) + return ConflictMarshaller.fromCpp(ret) + } + func conflictArg(cs: Array) throws -> Bool { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(ListMarshaller.toCpp(cs)) + var ret = djinni_generated.ConflictUser_conflictArg(¶ms) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } +} +enum ConflictUserMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ConflictUser + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { ConflictUserCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/ConflictUser.swift b/test-suite/generated-src/swift/ConflictUser.swift new file mode 100644 index 00000000..79d870ec --- /dev/null +++ b/test-suite/generated-src/swift/ConflictUser.swift @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +import Foundation + +public protocol ConflictUser: AnyObject { + func Conflict() throws -> TestSuite.Conflict + func conflictArg(cs: Array) throws -> Bool +} diff --git a/test-suite/generated-src/swift/ConstantEnum+Private.swift b/test-suite/generated-src/swift/ConstantEnum+Private.swift new file mode 100644 index 00000000..94de0827 --- /dev/null +++ b/test-suite/generated-src/swift/ConstantEnum+Private.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constant_enum.djinni + +import DjinniSupport +import TestSuite + +typealias ConstantEnumMarshaller = DjinniSupport.EnumMarshaller diff --git a/test-suite/generated-src/swift/ConstantEnum.swift b/test-suite/generated-src/swift/ConstantEnum.swift new file mode 100644 index 00000000..5be61eca --- /dev/null +++ b/test-suite/generated-src/swift/ConstantEnum.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constant_enum.djinni + +public enum ConstantEnum: Int32 { + case someValue = 0 + case someOtherValue = 1 +} diff --git a/test-suite/generated-src/swift/ConstantInterfaceWithEnum+Private.swift b/test-suite/generated-src/swift/ConstantInterfaceWithEnum+Private.swift new file mode 100644 index 00000000..5d6f14ae --- /dev/null +++ b/test-suite/generated-src/swift/ConstantInterfaceWithEnum+Private.swift @@ -0,0 +1,22 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constant_enum.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +/** Interface containing enum constant */ +final class ConstantInterfaceWithEnumCppProxy: DjinniSupport.CppProxy, TestSuite.ConstantInterfaceWithEnum { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } +} +enum ConstantInterfaceWithEnumMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ConstantInterfaceWithEnum + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { ConstantInterfaceWithEnumCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/ConstantInterfaceWithEnum.swift b/test-suite/generated-src/swift/ConstantInterfaceWithEnum.swift new file mode 100644 index 00000000..c14ab585 --- /dev/null +++ b/test-suite/generated-src/swift/ConstantInterfaceWithEnum.swift @@ -0,0 +1,8 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constant_enum.djinni + +import Foundation + +/** Interface containing enum constant */ +public protocol ConstantInterfaceWithEnum: AnyObject { +} diff --git a/test-suite/generated-src/swift/ConstantRecord+Private.swift b/test-suite/generated-src/swift/ConstantRecord+Private.swift new file mode 100644 index 00000000..59c1b2d3 --- /dev/null +++ b/test-suite/generated-src/swift/ConstantRecord+Private.swift @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum ConstantRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ConstantRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let someInteger = I32Marshaller.fromCpp(djinni.swift.getMember(p, 0)) + let someString = StringMarshaller.fromCpp(djinni.swift.getMember(p, 1)) + return SwiftType(someInteger: someInteger, someString: someString) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, I32Marshaller.toCpp(s.someInteger)) + djinni.swift.addMember(&ret, StringMarshaller.toCpp(s.someString)) + return ret + } +} diff --git a/test-suite/generated-src/swift/ConstantRecord.swift b/test-suite/generated-src/swift/ConstantRecord.swift new file mode 100644 index 00000000..f2bdc097 --- /dev/null +++ b/test-suite/generated-src/swift/ConstantRecord.swift @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +import Foundation + +/** Record for use in constants */ +public struct ConstantRecord: Equatable { + public var someInteger: Int32 + public var someString: String + + public init(someInteger: Int32, someString: String) + { + self.someInteger = someInteger + self.someString = someString + } +} diff --git a/test-suite/generated-src/swift/ConstantWithEnum+Private.swift b/test-suite/generated-src/swift/ConstantWithEnum+Private.swift new file mode 100644 index 00000000..edff8b12 --- /dev/null +++ b/test-suite/generated-src/swift/ConstantWithEnum+Private.swift @@ -0,0 +1,20 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constant_enum.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum ConstantWithEnumMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ConstantWithEnum + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + return SwiftType() + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.makeCompositeValue() + } +} diff --git a/test-suite/generated-src/swift/ConstantWithEnum.swift b/test-suite/generated-src/swift/ConstantWithEnum.swift new file mode 100644 index 00000000..15f0c079 --- /dev/null +++ b/test-suite/generated-src/swift/ConstantWithEnum.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constant_enum.djinni + +import Foundation + +/** Record containing enum constant */ +public struct ConstantWithEnum { + public static let constEnum: ConstantEnum = ConstantEnum.someValue + + public init() + { + } +} diff --git a/test-suite/generated-src/swift/Constants+Private.swift b/test-suite/generated-src/swift/Constants+Private.swift new file mode 100644 index 00000000..1a25dffd --- /dev/null +++ b/test-suite/generated-src/swift/Constants+Private.swift @@ -0,0 +1,20 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum ConstantsMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.Constants + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + return SwiftType() + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.makeCompositeValue() + } +} diff --git a/test-suite/generated-src/swift/Constants.swift b/test-suite/generated-src/swift/Constants.swift new file mode 100644 index 00000000..af680700 --- /dev/null +++ b/test-suite/generated-src/swift/Constants.swift @@ -0,0 +1,49 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +import Foundation + +/** Record containing constants */ +public struct Constants { + /** bool_constant has documentation. */ + public static let boolConstant: Bool = true + public static let i8Constant: Int8 = 1 + public static let i16Constant: Int16 = 2 + public static let i32Constant: Int32 = 3 + public static let i64Constant: Int64 = 4 + public static let f32Constant: Float = 5.0 + /** + * f64_constant has long documentation. + * (Second line of multi-line documentation. + * Indented third line of multi-line documentation.) + */ + public static let f64Constant: Double = 5.0 + public static let optBoolConstant: Optional = true + public static let optI8Constant: Optional = 1 + /** opt_i16_constant has documentation. */ + public static let optI16Constant: Optional = 2 + public static let optI32Constant: Optional = 3 + public static let optI64Constant: Optional = 4 + /** + * opt_f32_constant has long documentation. + * (Second line of multi-line documentation. + * Indented third line of multi-line documentation.) + */ + public static let optF32Constant: Optional = 5.0 + public static let optF64Constant: Optional = 5.0 + public static let stringConstant: String = "string-constant" + public static let optStringConstant: Optional = "string-constant" + public static let objectConstant: ConstantRecord = ConstantRecord( + someInteger:i32Constant, + someString:stringConstant) + /** + * No support for null optional constants + * No support for optional constant records + * No support for constant binary, list, set, map + */ + public static let dummy: Bool = false + + public init() + { + } +} diff --git a/test-suite/generated-src/swift/ConstantsInterface+Private.swift b/test-suite/generated-src/swift/ConstantsInterface+Private.swift new file mode 100644 index 00000000..6d740e70 --- /dev/null +++ b/test-suite/generated-src/swift/ConstantsInterface+Private.swift @@ -0,0 +1,28 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +/** Interface containing constants */ +final class ConstantsInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.ConstantsInterface { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func dummy() throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.ConstantsInterface_dummy(¶ms) + try handleCppErrors(&ret) + } +} +enum ConstantsInterfaceMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ConstantsInterface + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { ConstantsInterfaceCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/ConstantsInterface.swift b/test-suite/generated-src/swift/ConstantsInterface.swift new file mode 100644 index 00000000..60961016 --- /dev/null +++ b/test-suite/generated-src/swift/ConstantsInterface.swift @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +import Foundation + +/** Interface containing constants */ +public protocol ConstantsInterface: AnyObject { + /** + * No support for null optional constants + * No support for optional constant records + * No support for constant binary, list, set, map + */ + func dummy() throws -> Void +} diff --git a/test-suite/generated-src/swift/CppException+Private.swift b/test-suite/generated-src/swift/CppException+Private.swift new file mode 100644 index 00000000..93b7b243 --- /dev/null +++ b/test-suite/generated-src/swift/CppException+Private.swift @@ -0,0 +1,52 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from exception.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class CppExceptionCppProxy: DjinniSupport.CppProxy, TestSuite.CppException { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func throwAnException() throws -> Int32 { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.CppException_throwAnException(¶ms) + try handleCppErrors(&ret) + return I32Marshaller.fromCpp(ret) + } + func callThrowingInterface(cb: TestSuite.ThrowingInterface) throws -> Int32 { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(ThrowingInterfaceMarshaller.toCpp(cb)) + var ret = djinni_generated.CppException_callThrowingInterface(¶ms) + try handleCppErrors(&ret) + return I32Marshaller.fromCpp(ret) + } + func callThrowingAndCatch(cb: TestSuite.ThrowingInterface) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(ThrowingInterfaceMarshaller.toCpp(cb)) + var ret = djinni_generated.CppException_callThrowingAndCatch(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } +} +enum CppExceptionMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.CppException + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { CppExceptionCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class CppException_statics { + static func get() throws -> TestSuite.CppException { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.CppException_get(¶ms) + try handleCppErrors(&ret) + return CppExceptionMarshaller.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/CppException.swift b/test-suite/generated-src/swift/CppException.swift new file mode 100644 index 00000000..7c578d25 --- /dev/null +++ b/test-suite/generated-src/swift/CppException.swift @@ -0,0 +1,10 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from exception.djinni + +import Foundation + +public protocol CppException: AnyObject { + func throwAnException() throws -> Int32 + func callThrowingInterface(cb: TestSuite.ThrowingInterface) throws -> Int32 + func callThrowingAndCatch(cb: TestSuite.ThrowingInterface) throws -> String +} diff --git a/test-suite/generated-src/swift/DataRefTest+Private.swift b/test-suite/generated-src/swift/DataRefTest+Private.swift new file mode 100644 index 00000000..34c89c90 --- /dev/null +++ b/test-suite/generated-src/swift/DataRefTest+Private.swift @@ -0,0 +1,86 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from data_ref_view.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class DataRefTestCppProxy: DjinniSupport.CppProxy, TestSuite.DataRefTest { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func sendData(data: NSData) throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(DataRefMarshaller.toCpp(data)) + var ret = djinni_generated.DataRefTest_sendData(¶ms) + try handleCppErrors(&ret) + } + func retriveAsBin() throws -> Data { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.DataRefTest_retriveAsBin(¶ms) + try handleCppErrors(&ret) + return BinaryMarshaller.fromCpp(ret) + } + func sendMutableData(data: NSData) throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(DataRefMarshaller.toCpp(data)) + var ret = djinni_generated.DataRefTest_sendMutableData(¶ms) + try handleCppErrors(&ret) + } + func generateData() throws -> NSData { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.DataRefTest_generateData(¶ms) + try handleCppErrors(&ret) + return DataRefMarshaller.fromCpp(ret) + } + func dataFromVec() throws -> NSData { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.DataRefTest_dataFromVec(¶ms) + try handleCppErrors(&ret) + return DataRefMarshaller.fromCpp(ret) + } + func dataFromStr() throws -> NSData { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.DataRefTest_dataFromStr(¶ms) + try handleCppErrors(&ret) + return DataRefMarshaller.fromCpp(ret) + } + func sendDataView(data: NSData) throws -> Data { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(DataViewMarshaller.toCpp(data)) + var ret = djinni_generated.DataRefTest_sendDataView(¶ms) + try handleCppErrors(&ret) + return BinaryMarshaller.fromCpp(ret) + } + func recvDataView() throws -> NSData { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.DataRefTest_recvDataView(¶ms) + try handleCppErrors(&ret) + return DataViewMarshaller.fromCpp(ret) + } +} +enum DataRefTestMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.DataRefTest + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { DataRefTestCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class DataRefTest_statics { + static func create() throws -> TestSuite.DataRefTest { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.DataRefTest_create(¶ms) + try handleCppErrors(&ret) + return DataRefTestMarshaller.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/DataRefTest.swift b/test-suite/generated-src/swift/DataRefTest.swift new file mode 100644 index 00000000..cf9f06fc --- /dev/null +++ b/test-suite/generated-src/swift/DataRefTest.swift @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from data_ref_view.djinni + +import Foundation + +public protocol DataRefTest: AnyObject { + func sendData(data: NSData) throws -> Void + func retriveAsBin() throws -> Data + func sendMutableData(data: NSData) throws -> Void + func generateData() throws -> NSData + func dataFromVec() throws -> NSData + func dataFromStr() throws -> NSData + func sendDataView(data: NSData) throws -> Data + func recvDataView() throws -> NSData +} diff --git a/test-suite/generated-src/swift/DateRecord+Private.swift b/test-suite/generated-src/swift/DateRecord+Private.swift new file mode 100644 index 00000000..0e12bb74 --- /dev/null +++ b/test-suite/generated-src/swift/DateRecord+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from date.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum DateRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.DateRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let createdAt = DateMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(createdAt: createdAt) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, DateMarshaller.toCpp(s.createdAt)) + return ret + } +} diff --git a/test-suite/generated-src/swift/DateRecord.swift b/test-suite/generated-src/swift/DateRecord.swift new file mode 100644 index 00000000..4d6d1a8e --- /dev/null +++ b/test-suite/generated-src/swift/DateRecord.swift @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from date.djinni + +import DjinniSupport +import Foundation + +public struct DateRecord: Equatable { + public var createdAt: Date + + public init(createdAt: Date) + { + self.createdAt = createdAt + } +} diff --git a/test-suite/generated-src/swift/EmptyFlags+Private.swift b/test-suite/generated-src/swift/EmptyFlags+Private.swift new file mode 100644 index 00000000..f09a089e --- /dev/null +++ b/test-suite/generated-src/swift/EmptyFlags+Private.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +import DjinniSupport +import TestSuite + +typealias EmptyFlagsMarshaller = DjinniSupport.EnumMarshaller diff --git a/test-suite/generated-src/swift/EmptyFlags.swift b/test-suite/generated-src/swift/EmptyFlags.swift new file mode 100644 index 00000000..591c8b5e --- /dev/null +++ b/test-suite/generated-src/swift/EmptyFlags.swift @@ -0,0 +1,8 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +public struct EmptyFlags: OptionSet { + public let rawValue: Int32 + public init(rawValue: Int32) { self.rawValue = rawValue } + public static let none: EmptyFlags = [] + public static let all: EmptyFlags = []} diff --git a/test-suite/generated-src/swift/EmptyRecord+Private.swift b/test-suite/generated-src/swift/EmptyRecord+Private.swift new file mode 100644 index 00000000..24c4fd65 --- /dev/null +++ b/test-suite/generated-src/swift/EmptyRecord+Private.swift @@ -0,0 +1,20 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum EmptyRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.EmptyRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + return SwiftType() + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.makeCompositeValue() + } +} diff --git a/test-suite/generated-src/swift/EmptyRecord.swift b/test-suite/generated-src/swift/EmptyRecord.swift new file mode 100644 index 00000000..d5102d9b --- /dev/null +++ b/test-suite/generated-src/swift/EmptyRecord.swift @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +import Foundation + +/** + * Empty record + * (Second line of multi-line documentation. + * Indented third line of multi-line documentation.) + */ +public struct EmptyRecord { + + public init() + { + } +} diff --git a/test-suite/generated-src/swift/EnumUsageInterface+Private.swift b/test-suite/generated-src/swift/EnumUsageInterface+Private.swift new file mode 100644 index 00000000..5ee3399e --- /dev/null +++ b/test-suite/generated-src/swift/EnumUsageInterface+Private.swift @@ -0,0 +1,61 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class EnumUsageInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.EnumUsageInterface { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func e(e: TestSuite.Color) throws -> TestSuite.Color { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(ColorMarshaller.toCpp(e)) + var ret = djinni_generated.EnumUsageInterface_e(¶ms) + try handleCppErrors(&ret) + return ColorMarshaller.fromCpp(ret) + } + func o(o: Optional) throws -> Optional { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(OptionalMarshaller.toCpp(o)) + var ret = djinni_generated.EnumUsageInterface_o(¶ms) + try handleCppErrors(&ret) + return OptionalMarshaller.fromCpp(ret) + } + func l(l: Array) throws -> Array { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(ListMarshaller.toCpp(l)) + var ret = djinni_generated.EnumUsageInterface_l(¶ms) + try handleCppErrors(&ret) + return ListMarshaller.fromCpp(ret) + } + func s(s: Set) throws -> Set { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(SetMarshaller.toCpp(s)) + var ret = djinni_generated.EnumUsageInterface_s(¶ms) + try handleCppErrors(&ret) + return SetMarshaller.fromCpp(ret) + } + func m(m: Dictionary) throws -> Dictionary { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(MapMarshaller.toCpp(m)) + var ret = djinni_generated.EnumUsageInterface_m(¶ms) + try handleCppErrors(&ret) + return MapMarshaller.fromCpp(ret) + } +} +enum EnumUsageInterfaceMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.EnumUsageInterface + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { EnumUsageInterfaceCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/EnumUsageInterface.swift b/test-suite/generated-src/swift/EnumUsageInterface.swift new file mode 100644 index 00000000..c9129e65 --- /dev/null +++ b/test-suite/generated-src/swift/EnumUsageInterface.swift @@ -0,0 +1,12 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum.djinni + +import Foundation + +public protocol EnumUsageInterface: AnyObject { + func e(e: TestSuite.Color) throws -> TestSuite.Color + func o(o: Optional) throws -> Optional + func l(l: Array) throws -> Array + func s(s: Set) throws -> Set + func m(m: Dictionary) throws -> Dictionary +} diff --git a/test-suite/generated-src/swift/EnumUsageRecord+Private.swift b/test-suite/generated-src/swift/EnumUsageRecord+Private.swift new file mode 100644 index 00000000..fd7f34bd --- /dev/null +++ b/test-suite/generated-src/swift/EnumUsageRecord+Private.swift @@ -0,0 +1,31 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum EnumUsageRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.EnumUsageRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let e = ColorMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + let o = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 1)) + let l = ListMarshaller.fromCpp(djinni.swift.getMember(p, 2)) + let s = SetMarshaller.fromCpp(djinni.swift.getMember(p, 3)) + let m = MapMarshaller.fromCpp(djinni.swift.getMember(p, 4)) + return SwiftType(e: e, o: o, l: l, s: s, m: m) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, ColorMarshaller.toCpp(s.e)) + djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.o)) + djinni.swift.addMember(&ret, ListMarshaller.toCpp(s.l)) + djinni.swift.addMember(&ret, SetMarshaller.toCpp(s.s)) + djinni.swift.addMember(&ret, MapMarshaller.toCpp(s.m)) + return ret + } +} diff --git a/test-suite/generated-src/swift/EnumUsageRecord.swift b/test-suite/generated-src/swift/EnumUsageRecord.swift new file mode 100644 index 00000000..45834e25 --- /dev/null +++ b/test-suite/generated-src/swift/EnumUsageRecord.swift @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum.djinni + +import Foundation + +public struct EnumUsageRecord { + public var e: TestSuite.Color + public var o: Optional + public var l: Array + public var s: Set + public var m: Dictionary + + public init(e: TestSuite.Color, o: Optional, l: Array, s: Set, m: Dictionary) + { + self.e = e + self.o = o + self.l = l + self.s = s + self.m = m + } +} diff --git a/test-suite/generated-src/swift/ExtendedRecord+Private.swift b/test-suite/generated-src/swift/ExtendedRecord+Private.swift new file mode 100644 index 00000000..6b68248f --- /dev/null +++ b/test-suite/generated-src/swift/ExtendedRecord+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from extended_record.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum ExtendedRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ExtendedRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let foo = BoolMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(foo: foo) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, BoolMarshaller.toCpp(s.foo)) + return ret + } +} diff --git a/test-suite/generated-src/swift/ExtendedRecord.swift b/test-suite/generated-src/swift/ExtendedRecord.swift new file mode 100644 index 00000000..b219f83a --- /dev/null +++ b/test-suite/generated-src/swift/ExtendedRecord.swift @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from extended_record.djinni + +import Foundation + +/** Extended record */ +public struct ExtendedRecord { + public static let extendedRecordConst: ExtendedRecord = ExtendedRecord( + foo:true) + public var foo: Bool + + public init(foo: Bool) + { + self.foo = foo + } +} diff --git a/test-suite/generated-src/swift/ExternInterface1+Private.swift b/test-suite/generated-src/swift/ExternInterface1+Private.swift new file mode 100644 index 00000000..eedb643f --- /dev/null +++ b/test-suite/generated-src/swift/ExternInterface1+Private.swift @@ -0,0 +1,37 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class ExternInterface1CppProxy: DjinniSupport.CppProxy, TestSuite.ExternInterface1 { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func foo(i: ClientInterface) throws -> ClientReturnedRecord { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(ClientInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.ExternInterface1_foo(¶ms) + try handleCppErrors(&ret) + return ClientReturnedRecordMarshaller.fromCpp(ret) + } + func bar(e: Color) throws -> Color { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(ColorMarshaller.toCpp(e)) + var ret = djinni_generated.ExternInterface1_bar(¶ms) + try handleCppErrors(&ret) + return ColorMarshaller.fromCpp(ret) + } +} +enum ExternInterface1Marshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ExternInterface1 + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { ExternInterface1CppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/ExternInterface1.swift b/test-suite/generated-src/swift/ExternInterface1.swift new file mode 100644 index 00000000..af065b06 --- /dev/null +++ b/test-suite/generated-src/swift/ExternInterface1.swift @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +import Foundation + +public protocol ExternInterface1: AnyObject { + func foo(i: ClientInterface) throws -> ClientReturnedRecord + func bar(e: Color) throws -> Color +} diff --git a/test-suite/generated-src/swift/ExternInterface2+Private.swift b/test-suite/generated-src/swift/ExternInterface2+Private.swift new file mode 100644 index 00000000..073b61d7 --- /dev/null +++ b/test-suite/generated-src/swift/ExternInterface2+Private.swift @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum ExternInterface2Marshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ExternInterface2 + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { fatalError("n/a") }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/ExternInterface2.swift b/test-suite/generated-src/swift/ExternInterface2.swift new file mode 100644 index 00000000..e74a1fb2 --- /dev/null +++ b/test-suite/generated-src/swift/ExternInterface2.swift @@ -0,0 +1,8 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +import Foundation + +public protocol ExternInterface2: AnyObject { + func foo(i: TestHelpers) throws -> TestSuite.ExternRecordWithDerivings +} diff --git a/test-suite/generated-src/swift/ExternRecordWithDerivings+Private.swift b/test-suite/generated-src/swift/ExternRecordWithDerivings+Private.swift new file mode 100644 index 00000000..9a00f402 --- /dev/null +++ b/test-suite/generated-src/swift/ExternRecordWithDerivings+Private.swift @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum ExternRecordWithDerivingsMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ExternRecordWithDerivings + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let member = RecordWithDerivingsMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + let e = ColorMarshaller.fromCpp(djinni.swift.getMember(p, 1)) + return SwiftType(member: member, e: e) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, RecordWithDerivingsMarshaller.toCpp(s.member)) + djinni.swift.addMember(&ret, ColorMarshaller.toCpp(s.e)) + return ret + } +} diff --git a/test-suite/generated-src/swift/ExternRecordWithDerivings.swift b/test-suite/generated-src/swift/ExternRecordWithDerivings.swift new file mode 100644 index 00000000..5c77ff81 --- /dev/null +++ b/test-suite/generated-src/swift/ExternRecordWithDerivings.swift @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +import Foundation + +/** This file tests YAML dumped by Djinni can be parsed back in */ +public struct ExternRecordWithDerivings: Equatable { + public var member: RecordWithDerivings + public var e: Color + + public init(member: RecordWithDerivings, e: Color) + { + self.member = member + self.e = e + } +} diff --git a/test-suite/generated-src/swift/FirstListener+Private.swift b/test-suite/generated-src/swift/FirstListener+Private.swift new file mode 100644 index 00000000..958fb54a --- /dev/null +++ b/test-suite/generated-src/swift/FirstListener+Private.swift @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +/** Used for ObjC multiple inheritance tests */ +enum FirstListenerMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.FirstListener + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { fatalError("n/a") }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/FirstListener.swift b/test-suite/generated-src/swift/FirstListener.swift new file mode 100644 index 00000000..cdade435 --- /dev/null +++ b/test-suite/generated-src/swift/FirstListener.swift @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +import Foundation + +/** Used for ObjC multiple inheritance tests */ +public protocol FirstListener: AnyObject { + func first() throws -> Void +} diff --git a/test-suite/generated-src/swift/FlagRoundtrip+Private.swift b/test-suite/generated-src/swift/FlagRoundtrip+Private.swift new file mode 100644 index 00000000..7a4d32a6 --- /dev/null +++ b/test-suite/generated-src/swift/FlagRoundtrip+Private.swift @@ -0,0 +1,51 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class FlagRoundtripCppProxy: DjinniSupport.CppProxy, TestSuite.FlagRoundtrip { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } +} +enum FlagRoundtripMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.FlagRoundtrip + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { FlagRoundtripCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class FlagRoundtrip_statics { + static func roundtripAccess(flag: TestSuite.AccessFlags) throws -> TestSuite.AccessFlags { + var params = djinni.swift.ParameterList() + params.addValue(AccessFlagsMarshaller.toCpp(flag)) + var ret = djinni_generated.FlagRoundtrip_roundtripAccess(¶ms) + try handleCppErrors(&ret) + return AccessFlagsMarshaller.fromCpp(ret) + } + static func roundtripEmpty(flag: TestSuite.EmptyFlags) throws -> TestSuite.EmptyFlags { + var params = djinni.swift.ParameterList() + params.addValue(EmptyFlagsMarshaller.toCpp(flag)) + var ret = djinni_generated.FlagRoundtrip_roundtripEmpty(¶ms) + try handleCppErrors(&ret) + return EmptyFlagsMarshaller.fromCpp(ret) + } + static func roundtripAccessBoxed(flag: Optional) throws -> Optional { + var params = djinni.swift.ParameterList() + params.addValue(OptionalMarshaller.toCpp(flag)) + var ret = djinni_generated.FlagRoundtrip_roundtripAccessBoxed(¶ms) + try handleCppErrors(&ret) + return OptionalMarshaller.fromCpp(ret) + } + static func roundtripEmptyBoxed(flag: Optional) throws -> Optional { + var params = djinni.swift.ParameterList() + params.addValue(OptionalMarshaller.toCpp(flag)) + var ret = djinni_generated.FlagRoundtrip_roundtripEmptyBoxed(¶ms) + try handleCppErrors(&ret) + return OptionalMarshaller.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/FlagRoundtrip.swift b/test-suite/generated-src/swift/FlagRoundtrip.swift new file mode 100644 index 00000000..fc70c76e --- /dev/null +++ b/test-suite/generated-src/swift/FlagRoundtrip.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +import Foundation + +public protocol FlagRoundtrip: AnyObject { +} diff --git a/test-suite/generated-src/swift/InterfaceUsingExtendedRecord+Private.swift b/test-suite/generated-src/swift/InterfaceUsingExtendedRecord+Private.swift new file mode 100644 index 00000000..7bb3d2dd --- /dev/null +++ b/test-suite/generated-src/swift/InterfaceUsingExtendedRecord+Private.swift @@ -0,0 +1,29 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from extended_record.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class InterfaceUsingExtendedRecordCppProxy: DjinniSupport.CppProxy, TestSuite.InterfaceUsingExtendedRecord { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func meth(er: TestSuite.ExtendedRecord) throws -> TestSuite.ExtendedRecord { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(ExtendedRecordMarshaller.toCpp(er)) + var ret = djinni_generated.InterfaceUsingExtendedRecord_meth(¶ms) + try handleCppErrors(&ret) + return ExtendedRecordMarshaller.fromCpp(ret) + } +} +enum InterfaceUsingExtendedRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.InterfaceUsingExtendedRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { InterfaceUsingExtendedRecordCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/InterfaceUsingExtendedRecord.swift b/test-suite/generated-src/swift/InterfaceUsingExtendedRecord.swift new file mode 100644 index 00000000..965c84d3 --- /dev/null +++ b/test-suite/generated-src/swift/InterfaceUsingExtendedRecord.swift @@ -0,0 +1,8 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from extended_record.djinni + +import Foundation + +public protocol InterfaceUsingExtendedRecord: AnyObject { + func meth(er: TestSuite.ExtendedRecord) throws -> TestSuite.ExtendedRecord +} diff --git a/test-suite/generated-src/swift/JavaOnlyListener+Private.swift b/test-suite/generated-src/swift/JavaOnlyListener+Private.swift new file mode 100644 index 00000000..36734f2c --- /dev/null +++ b/test-suite/generated-src/swift/JavaOnlyListener+Private.swift @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from single_language_interfaces.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum JavaOnlyListenerMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.JavaOnlyListener + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { fatalError("n/a") }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/JavaOnlyListener.swift b/test-suite/generated-src/swift/JavaOnlyListener.swift new file mode 100644 index 00000000..e294d87c --- /dev/null +++ b/test-suite/generated-src/swift/JavaOnlyListener.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from single_language_interfaces.djinni + +import Foundation + +public protocol JavaOnlyListener: AnyObject { +} diff --git a/test-suite/generated-src/swift/ListenerCaller+Private.swift b/test-suite/generated-src/swift/ListenerCaller+Private.swift new file mode 100644 index 00000000..2db7fd5c --- /dev/null +++ b/test-suite/generated-src/swift/ListenerCaller+Private.swift @@ -0,0 +1,49 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +/** + * Tester for the ability to call two interfaces which might be + * implemented on the same object. That's not relevant in all + * languages, due to the details of multiple inheritance and object + * comparison. + */ +final class ListenerCallerCppProxy: DjinniSupport.CppProxy, TestSuite.ListenerCaller { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func callFirst() throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.ListenerCaller_callFirst(¶ms) + try handleCppErrors(&ret) + } + func callSecond() throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.ListenerCaller_callSecond(¶ms) + try handleCppErrors(&ret) + } +} +enum ListenerCallerMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ListenerCaller + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { ListenerCallerCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class ListenerCaller_statics { + static func _init(firstL: TestSuite.FirstListener, secondL: TestSuite.SecondListener) throws -> TestSuite.ListenerCaller { + var params = djinni.swift.ParameterList() + params.addValue(FirstListenerMarshaller.toCpp(firstL)) + params.addValue(SecondListenerMarshaller.toCpp(secondL)) + var ret = djinni_generated.ListenerCaller_init(¶ms) + try handleCppErrors(&ret) + return ListenerCallerMarshaller.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/ListenerCaller.swift b/test-suite/generated-src/swift/ListenerCaller.swift new file mode 100644 index 00000000..d9a889ba --- /dev/null +++ b/test-suite/generated-src/swift/ListenerCaller.swift @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +import Foundation + +/** + * Tester for the ability to call two interfaces which might be + * implemented on the same object. That's not relevant in all + * languages, due to the details of multiple inheritance and object + * comparison. + */ +public protocol ListenerCaller: AnyObject { + func callFirst() throws -> Void + func callSecond() throws -> Void +} diff --git a/test-suite/generated-src/swift/MapDateRecord+Private.swift b/test-suite/generated-src/swift/MapDateRecord+Private.swift new file mode 100644 index 00000000..2e26e5fd --- /dev/null +++ b/test-suite/generated-src/swift/MapDateRecord+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from date.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum MapDateRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.MapDateRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let datesById = MapMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(datesById: datesById) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, MapMarshaller.toCpp(s.datesById)) + return ret + } +} diff --git a/test-suite/generated-src/swift/MapDateRecord.swift b/test-suite/generated-src/swift/MapDateRecord.swift new file mode 100644 index 00000000..d92c7e07 --- /dev/null +++ b/test-suite/generated-src/swift/MapDateRecord.swift @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from date.djinni + +import DjinniSupport +import Foundation + +public struct MapDateRecord { + public var datesById: Dictionary + + public init(datesById: Dictionary) + { + self.datesById = datesById + } +} diff --git a/test-suite/generated-src/swift/MapListRecord+Private.swift b/test-suite/generated-src/swift/MapListRecord+Private.swift new file mode 100644 index 00000000..76d2dfc9 --- /dev/null +++ b/test-suite/generated-src/swift/MapListRecord+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from map.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum MapListRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.MapListRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let mapList = ListMarshaller>.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(mapList: mapList) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, ListMarshaller>.toCpp(s.mapList)) + return ret + } +} diff --git a/test-suite/generated-src/swift/MapListRecord.swift b/test-suite/generated-src/swift/MapListRecord.swift new file mode 100644 index 00000000..f2af3686 --- /dev/null +++ b/test-suite/generated-src/swift/MapListRecord.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from map.djinni + +import Foundation + +public struct MapListRecord { + public var mapList: Array> + + public init(mapList: Array>) + { + self.mapList = mapList + } +} diff --git a/test-suite/generated-src/swift/MapRecord+Private.swift b/test-suite/generated-src/swift/MapRecord+Private.swift new file mode 100644 index 00000000..2ec9220e --- /dev/null +++ b/test-suite/generated-src/swift/MapRecord+Private.swift @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from map.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum MapRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.MapRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let map = MapMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + let imap = MapMarshaller.fromCpp(djinni.swift.getMember(p, 1)) + return SwiftType(map: map, imap: imap) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, MapMarshaller.toCpp(s.map)) + djinni.swift.addMember(&ret, MapMarshaller.toCpp(s.imap)) + return ret + } +} diff --git a/test-suite/generated-src/swift/MapRecord.swift b/test-suite/generated-src/swift/MapRecord.swift new file mode 100644 index 00000000..e397998a --- /dev/null +++ b/test-suite/generated-src/swift/MapRecord.swift @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from map.djinni + +import Foundation + +public struct MapRecord { + public var map: Dictionary + public var imap: Dictionary + + public init(map: Dictionary, imap: Dictionary) + { + self.map = map + self.imap = imap + } +} diff --git a/test-suite/generated-src/swift/NestedCollection+Private.swift b/test-suite/generated-src/swift/NestedCollection+Private.swift new file mode 100644 index 00000000..f8ad387a --- /dev/null +++ b/test-suite/generated-src/swift/NestedCollection+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from nested_collection.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum NestedCollectionMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.NestedCollection + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let setList = ListMarshaller>.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(setList: setList) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, ListMarshaller>.toCpp(s.setList)) + return ret + } +} diff --git a/test-suite/generated-src/swift/NestedCollection.swift b/test-suite/generated-src/swift/NestedCollection.swift new file mode 100644 index 00000000..471baf67 --- /dev/null +++ b/test-suite/generated-src/swift/NestedCollection.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from nested_collection.djinni + +import Foundation + +public struct NestedCollection { + public var setList: Array> + + public init(setList: Array>) + { + self.setList = setList + } +} diff --git a/test-suite/generated-src/swift/NestedOutcome+Private.swift b/test-suite/generated-src/swift/NestedOutcome+Private.swift new file mode 100644 index 00000000..13ce4e5d --- /dev/null +++ b/test-suite/generated-src/swift/NestedOutcome+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from outcome.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum NestedOutcomeMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.NestedOutcome + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let o = OutcomeMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(o: o) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, OutcomeMarshaller.toCpp(s.o)) + return ret + } +} diff --git a/test-suite/generated-src/swift/NestedOutcome.swift b/test-suite/generated-src/swift/NestedOutcome.swift new file mode 100644 index 00000000..788f5c56 --- /dev/null +++ b/test-suite/generated-src/swift/NestedOutcome.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from outcome.djinni + +import Foundation + +public struct NestedOutcome: Equatable { + public var o: Result + + public init(o: Result) + { + self.o = o + } +} diff --git a/test-suite/generated-src/swift/ObjcOnlyListener+Private.swift b/test-suite/generated-src/swift/ObjcOnlyListener+Private.swift new file mode 100644 index 00000000..e6de364d --- /dev/null +++ b/test-suite/generated-src/swift/ObjcOnlyListener+Private.swift @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from single_language_interfaces.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum ObjcOnlyListenerMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ObjcOnlyListener + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { fatalError("n/a") }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/ObjcOnlyListener.swift b/test-suite/generated-src/swift/ObjcOnlyListener.swift new file mode 100644 index 00000000..4d5eae9c --- /dev/null +++ b/test-suite/generated-src/swift/ObjcOnlyListener.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from single_language_interfaces.djinni + +import Foundation + +public protocol ObjcOnlyListener: AnyObject { +} diff --git a/test-suite/generated-src/swift/PrimitiveList+Private.swift b/test-suite/generated-src/swift/PrimitiveList+Private.swift new file mode 100644 index 00000000..ac7ae449 --- /dev/null +++ b/test-suite/generated-src/swift/PrimitiveList+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from primitive_list.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum PrimitiveListMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.PrimitiveList + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let list = ListMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(list: list) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, ListMarshaller.toCpp(s.list)) + return ret + } +} diff --git a/test-suite/generated-src/swift/PrimitiveList.swift b/test-suite/generated-src/swift/PrimitiveList.swift new file mode 100644 index 00000000..45613a96 --- /dev/null +++ b/test-suite/generated-src/swift/PrimitiveList.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from primitive_list.djinni + +import Foundation + +public struct PrimitiveList { + public var list: Array + + public init(list: Array) + { + self.list = list + } +} diff --git a/test-suite/generated-src/swift/ProtoTests+Private.swift b/test-suite/generated-src/swift/ProtoTests+Private.swift new file mode 100644 index 00000000..a53e65de --- /dev/null +++ b/test-suite/generated-src/swift/ProtoTests+Private.swift @@ -0,0 +1,115 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from proto.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import ProtobufTest +import TestSuite +import TestSuiteCxx + +final class ProtoTestsCppProxy: DjinniSupport.CppProxy, TestSuite.ProtoTests { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } +} +enum ProtoTestsMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ProtoTests + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { ProtoTestsCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class ProtoTests_statics { + static func protoToStrings(x: Djinni_Test_AddressBook) throws -> Array { + var params = djinni.swift.ParameterList() + params.addValue(ProtobufMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_protoToStrings(¶ms) + try handleCppErrors(&ret) + return ListMarshaller.fromCpp(ret) + } + static func stringsToProto(x: Array) throws -> Djinni_Test_AddressBook { + var params = djinni.swift.ParameterList() + params.addValue(ListMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringsToProto(¶ms) + try handleCppErrors(&ret) + return ProtobufMarshaller.fromCpp(ret) + } + static func embeddedProtoToString(x: TestSuite.RecordWithEmbeddedProto) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(RecordWithEmbeddedProtoMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_embeddedProtoToString(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + static func stringToEmbeddedProto(x: String) throws -> TestSuite.RecordWithEmbeddedProto { + var params = djinni.swift.ParameterList() + params.addValue(StringMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringToEmbeddedProto(¶ms) + try handleCppErrors(&ret) + return RecordWithEmbeddedProtoMarshaller.fromCpp(ret) + } + static func cppProtoToString(x: Djinni_Test2_PersistingState) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(ProtobufMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_cppProtoToString(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + static func stringToCppProto(x: String) throws -> Djinni_Test2_PersistingState { + var params = djinni.swift.ParameterList() + params.addValue(StringMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringToCppProto(¶ms) + try handleCppErrors(&ret) + return ProtobufMarshaller.fromCpp(ret) + } + static func embeddedCppProtoToString(x: TestSuite.RecordWithEmbeddedCppProto) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(RecordWithEmbeddedCppProtoMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_embeddedCppProtoToString(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + static func stringToEmbeddedCppProto(x: String) throws -> TestSuite.RecordWithEmbeddedCppProto { + var params = djinni.swift.ParameterList() + params.addValue(StringMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringToEmbeddedCppProto(¶ms) + try handleCppErrors(&ret) + return RecordWithEmbeddedCppProtoMarshaller.fromCpp(ret) + } + static func protoListToStrings(x: Array) throws -> Array { + var params = djinni.swift.ParameterList() + params.addValue(ListMarshaller>.toCpp(x)) + var ret = djinni_generated.ProtoTests_protoListToStrings(¶ms) + try handleCppErrors(&ret) + return ListMarshaller.fromCpp(ret) + } + static func stringsToProtoList(x: Array) throws -> Array { + var params = djinni.swift.ParameterList() + params.addValue(ListMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringsToProtoList(¶ms) + try handleCppErrors(&ret) + return ListMarshaller>.fromCpp(ret) + } + static func optionalProtoToString(x: Optional) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(OptionalMarshaller>.toCpp(x)) + var ret = djinni_generated.ProtoTests_optionalProtoToString(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + static func stringToOptionalProto(x: String) throws -> Optional { + var params = djinni.swift.ParameterList() + params.addValue(StringMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringToOptionalProto(¶ms) + try handleCppErrors(&ret) + return OptionalMarshaller>.fromCpp(ret) + } + static func stringToProtoOutcome(x: String) throws -> Result { + var params = djinni.swift.ParameterList() + params.addValue(StringMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringToProtoOutcome(¶ms) + try handleCppErrors(&ret) + return OutcomeMarshaller, I32Marshaller>.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/ProtoTests.swift b/test-suite/generated-src/swift/ProtoTests.swift new file mode 100644 index 00000000..3f6daa35 --- /dev/null +++ b/test-suite/generated-src/swift/ProtoTests.swift @@ -0,0 +1,8 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from proto.djinni + +import Foundation +import ProtobufTest + +public protocol ProtoTests: AnyObject { +} diff --git a/test-suite/generated-src/swift/RecordUsingExtendedRecord+Private.swift b/test-suite/generated-src/swift/RecordUsingExtendedRecord+Private.swift new file mode 100644 index 00000000..a8fdedfd --- /dev/null +++ b/test-suite/generated-src/swift/RecordUsingExtendedRecord+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from extended_record.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum RecordUsingExtendedRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.RecordUsingExtendedRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let er = ExtendedRecordMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(er: er) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, ExtendedRecordMarshaller.toCpp(s.er)) + return ret + } +} diff --git a/test-suite/generated-src/swift/RecordUsingExtendedRecord.swift b/test-suite/generated-src/swift/RecordUsingExtendedRecord.swift new file mode 100644 index 00000000..2f3d01c6 --- /dev/null +++ b/test-suite/generated-src/swift/RecordUsingExtendedRecord.swift @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from extended_record.djinni + +import Foundation + +public struct RecordUsingExtendedRecord { + public static let cr: RecordUsingExtendedRecord = RecordUsingExtendedRecord( + er:ExtendedRecord( + foo:false)) + public var er: TestSuite.ExtendedRecord + + public init(er: TestSuite.ExtendedRecord) + { + self.er = er + } +} diff --git a/test-suite/generated-src/swift/RecordWithDerivings+Private.swift b/test-suite/generated-src/swift/RecordWithDerivings+Private.swift new file mode 100644 index 00000000..d9fbbd89 --- /dev/null +++ b/test-suite/generated-src/swift/RecordWithDerivings+Private.swift @@ -0,0 +1,37 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from derivings.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum RecordWithDerivingsMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.RecordWithDerivings + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let eight = I8Marshaller.fromCpp(djinni.swift.getMember(p, 0)) + let sixteen = I16Marshaller.fromCpp(djinni.swift.getMember(p, 1)) + let thirtytwo = I32Marshaller.fromCpp(djinni.swift.getMember(p, 2)) + let sixtyfour = I64Marshaller.fromCpp(djinni.swift.getMember(p, 3)) + let fthirtytwo = F32Marshaller.fromCpp(djinni.swift.getMember(p, 4)) + let fsixtyfour = F64Marshaller.fromCpp(djinni.swift.getMember(p, 5)) + let d = DateMarshaller.fromCpp(djinni.swift.getMember(p, 6)) + let s = StringMarshaller.fromCpp(djinni.swift.getMember(p, 7)) + return SwiftType(eight: eight, sixteen: sixteen, thirtytwo: thirtytwo, sixtyfour: sixtyfour, fthirtytwo: fthirtytwo, fsixtyfour: fsixtyfour, d: d, s: s) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, I8Marshaller.toCpp(s.eight)) + djinni.swift.addMember(&ret, I16Marshaller.toCpp(s.sixteen)) + djinni.swift.addMember(&ret, I32Marshaller.toCpp(s.thirtytwo)) + djinni.swift.addMember(&ret, I64Marshaller.toCpp(s.sixtyfour)) + djinni.swift.addMember(&ret, F32Marshaller.toCpp(s.fthirtytwo)) + djinni.swift.addMember(&ret, F64Marshaller.toCpp(s.fsixtyfour)) + djinni.swift.addMember(&ret, DateMarshaller.toCpp(s.d)) + djinni.swift.addMember(&ret, StringMarshaller.toCpp(s.s)) + return ret + } +} diff --git a/test-suite/generated-src/swift/RecordWithDerivings.swift b/test-suite/generated-src/swift/RecordWithDerivings.swift new file mode 100644 index 00000000..58353a7b --- /dev/null +++ b/test-suite/generated-src/swift/RecordWithDerivings.swift @@ -0,0 +1,27 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from derivings.djinni + +import Foundation + +public struct RecordWithDerivings: Equatable { + public var eight: Int8 + public var sixteen: Int16 + public var thirtytwo: Int32 + public var sixtyfour: Int64 + public var fthirtytwo: Float + public var fsixtyfour: Double + public var d: Date + public var s: String + + public init(eight: Int8, sixteen: Int16, thirtytwo: Int32, sixtyfour: Int64, fthirtytwo: Float, fsixtyfour: Double, d: Date, s: String) + { + self.eight = eight + self.sixteen = sixteen + self.thirtytwo = thirtytwo + self.sixtyfour = sixtyfour + self.fthirtytwo = fthirtytwo + self.fsixtyfour = fsixtyfour + self.d = d + self.s = s + } +} diff --git a/test-suite/generated-src/swift/RecordWithDurationAndDerivings+Private.swift b/test-suite/generated-src/swift/RecordWithDurationAndDerivings+Private.swift new file mode 100644 index 00000000..149a8ae2 --- /dev/null +++ b/test-suite/generated-src/swift/RecordWithDurationAndDerivings+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from duration.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum RecordWithDurationAndDerivingsMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.RecordWithDurationAndDerivings + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let dt = DurationMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(dt: dt) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, DurationMarshaller.toCpp(s.dt)) + return ret + } +} diff --git a/test-suite/generated-src/swift/RecordWithDurationAndDerivings.swift b/test-suite/generated-src/swift/RecordWithDurationAndDerivings.swift new file mode 100644 index 00000000..495935c8 --- /dev/null +++ b/test-suite/generated-src/swift/RecordWithDurationAndDerivings.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from duration.djinni + +import Foundation + +public struct RecordWithDurationAndDerivings: Equatable { + public var dt: Duration + + public init(dt: Duration) + { + self.dt = dt + } +} diff --git a/test-suite/generated-src/swift/RecordWithEmbeddedCppProto+Private.swift b/test-suite/generated-src/swift/RecordWithEmbeddedCppProto+Private.swift new file mode 100644 index 00000000..b4ebe851 --- /dev/null +++ b/test-suite/generated-src/swift/RecordWithEmbeddedCppProto+Private.swift @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from proto.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import ProtobufTest +import TestSuite +import TestSuiteCxx + +enum RecordWithEmbeddedCppProtoMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.RecordWithEmbeddedCppProto + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let state = ProtobufMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(state: state) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, ProtobufMarshaller.toCpp(s.state)) + return ret + } +} diff --git a/test-suite/generated-src/swift/RecordWithEmbeddedCppProto.swift b/test-suite/generated-src/swift/RecordWithEmbeddedCppProto.swift new file mode 100644 index 00000000..987bb8cc --- /dev/null +++ b/test-suite/generated-src/swift/RecordWithEmbeddedCppProto.swift @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from proto.djinni + +import Foundation +import ProtobufTest + +public struct RecordWithEmbeddedCppProto { + public var state: Djinni_Test2_PersistingState + + public init(state: Djinni_Test2_PersistingState) + { + self.state = state + } +} diff --git a/test-suite/generated-src/swift/RecordWithEmbeddedProto+Private.swift b/test-suite/generated-src/swift/RecordWithEmbeddedProto+Private.swift new file mode 100644 index 00000000..0409625d --- /dev/null +++ b/test-suite/generated-src/swift/RecordWithEmbeddedProto+Private.swift @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from proto.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import ProtobufTest +import TestSuite +import TestSuiteCxx + +enum RecordWithEmbeddedProtoMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.RecordWithEmbeddedProto + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let person = ProtobufMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(person: person) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, ProtobufMarshaller.toCpp(s.person)) + return ret + } +} diff --git a/test-suite/generated-src/swift/RecordWithEmbeddedProto.swift b/test-suite/generated-src/swift/RecordWithEmbeddedProto.swift new file mode 100644 index 00000000..32ffb1d1 --- /dev/null +++ b/test-suite/generated-src/swift/RecordWithEmbeddedProto.swift @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from proto.djinni + +import Foundation +import ProtobufTest + +public struct RecordWithEmbeddedProto { + public var person: Djinni_Test_Person + + public init(person: Djinni_Test_Person) + { + self.person = person + } +} diff --git a/test-suite/generated-src/swift/RecordWithFlags+Private.swift b/test-suite/generated-src/swift/RecordWithFlags+Private.swift new file mode 100644 index 00000000..7f507716 --- /dev/null +++ b/test-suite/generated-src/swift/RecordWithFlags+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum RecordWithFlagsMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.RecordWithFlags + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let access = AccessFlagsMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(access: access) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, AccessFlagsMarshaller.toCpp(s.access)) + return ret + } +} diff --git a/test-suite/generated-src/swift/RecordWithFlags.swift b/test-suite/generated-src/swift/RecordWithFlags.swift new file mode 100644 index 00000000..be9acbcc --- /dev/null +++ b/test-suite/generated-src/swift/RecordWithFlags.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +import Foundation + +public struct RecordWithFlags { + public var access: TestSuite.AccessFlags + + public init(access: TestSuite.AccessFlags) + { + self.access = access + } +} diff --git a/test-suite/generated-src/swift/RecordWithNestedDerivings+Private.swift b/test-suite/generated-src/swift/RecordWithNestedDerivings+Private.swift new file mode 100644 index 00000000..8d3a46a3 --- /dev/null +++ b/test-suite/generated-src/swift/RecordWithNestedDerivings+Private.swift @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from derivings.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum RecordWithNestedDerivingsMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.RecordWithNestedDerivings + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let key = I32Marshaller.fromCpp(djinni.swift.getMember(p, 0)) + let rec = RecordWithDerivingsMarshaller.fromCpp(djinni.swift.getMember(p, 1)) + return SwiftType(key: key, rec: rec) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, I32Marshaller.toCpp(s.key)) + djinni.swift.addMember(&ret, RecordWithDerivingsMarshaller.toCpp(s.rec)) + return ret + } +} diff --git a/test-suite/generated-src/swift/RecordWithNestedDerivings.swift b/test-suite/generated-src/swift/RecordWithNestedDerivings.swift new file mode 100644 index 00000000..52e14756 --- /dev/null +++ b/test-suite/generated-src/swift/RecordWithNestedDerivings.swift @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from derivings.djinni + +import Foundation + +public struct RecordWithNestedDerivings: Equatable { + public var key: Int32 + public var rec: TestSuite.RecordWithDerivings + + public init(key: Int32, rec: TestSuite.RecordWithDerivings) + { + self.key = key + self.rec = rec + } +} diff --git a/test-suite/generated-src/swift/ReturnOne+Private.swift b/test-suite/generated-src/swift/ReturnOne+Private.swift new file mode 100644 index 00000000..bf26cd44 --- /dev/null +++ b/test-suite/generated-src/swift/ReturnOne+Private.swift @@ -0,0 +1,37 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +/** Used for C++ multiple inheritance tests */ +final class ReturnOneCppProxy: DjinniSupport.CppProxy, TestSuite.ReturnOne { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func returnOne() throws -> Int8 { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.ReturnOne_returnOne(¶ms) + try handleCppErrors(&ret) + return I8Marshaller.fromCpp(ret) + } +} +enum ReturnOneMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ReturnOne + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { ReturnOneCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class ReturnOne_statics { + static func getInstance() throws -> TestSuite.ReturnOne { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.ReturnOne_getInstance(¶ms) + try handleCppErrors(&ret) + return ReturnOneMarshaller.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/ReturnOne.swift b/test-suite/generated-src/swift/ReturnOne.swift new file mode 100644 index 00000000..e86e4005 --- /dev/null +++ b/test-suite/generated-src/swift/ReturnOne.swift @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +import Foundation + +/** Used for C++ multiple inheritance tests */ +public protocol ReturnOne: AnyObject { + func returnOne() throws -> Int8 +} diff --git a/test-suite/generated-src/swift/ReturnTwo+Private.swift b/test-suite/generated-src/swift/ReturnTwo+Private.swift new file mode 100644 index 00000000..06fbf133 --- /dev/null +++ b/test-suite/generated-src/swift/ReturnTwo+Private.swift @@ -0,0 +1,37 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +/** Used for C++ multiple inheritance tests */ +final class ReturnTwoCppProxy: DjinniSupport.CppProxy, TestSuite.ReturnTwo { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func returnTwo() throws -> Int8 { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.ReturnTwo_returnTwo(¶ms) + try handleCppErrors(&ret) + return I8Marshaller.fromCpp(ret) + } +} +enum ReturnTwoMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ReturnTwo + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { ReturnTwoCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class ReturnTwo_statics { + static func getInstance() throws -> TestSuite.ReturnTwo { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.ReturnTwo_getInstance(¶ms) + try handleCppErrors(&ret) + return ReturnTwoMarshaller.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/ReturnTwo.swift b/test-suite/generated-src/swift/ReturnTwo.swift new file mode 100644 index 00000000..5d345af4 --- /dev/null +++ b/test-suite/generated-src/swift/ReturnTwo.swift @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +import Foundation + +/** Used for C++ multiple inheritance tests */ +public protocol ReturnTwo: AnyObject { + func returnTwo() throws -> Int8 +} diff --git a/test-suite/generated-src/swift/ReverseClientInterface+Private.swift b/test-suite/generated-src/swift/ReverseClientInterface+Private.swift new file mode 100644 index 00000000..e9b26f3c --- /dev/null +++ b/test-suite/generated-src/swift/ReverseClientInterface+Private.swift @@ -0,0 +1,52 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from client_interface.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class ReverseClientInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.ReverseClientInterface { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func returnStr() throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.ReverseClientInterface_returnStr(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + func methTakingInterface(i: TestSuite.ReverseClientInterface) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(ReverseClientInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.ReverseClientInterface_methTakingInterface(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + func methTakingOptionalInterface(i: Optional) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(OptionalMarshaller.toCpp(i)) + var ret = djinni_generated.ReverseClientInterface_methTakingOptionalInterface(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } +} +enum ReverseClientInterfaceMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ReverseClientInterface + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { ReverseClientInterfaceCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class ReverseClientInterface_statics { + static func create() throws -> TestSuite.ReverseClientInterface { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.ReverseClientInterface_create(¶ms) + try handleCppErrors(&ret) + return ReverseClientInterfaceMarshaller.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/ReverseClientInterface.swift b/test-suite/generated-src/swift/ReverseClientInterface.swift new file mode 100644 index 00000000..9be264c6 --- /dev/null +++ b/test-suite/generated-src/swift/ReverseClientInterface.swift @@ -0,0 +1,10 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from client_interface.djinni + +import Foundation + +public protocol ReverseClientInterface: AnyObject { + func returnStr() throws -> String + func methTakingInterface(i: TestSuite.ReverseClientInterface) throws -> String + func methTakingOptionalInterface(i: Optional) throws -> String +} diff --git a/test-suite/generated-src/swift/SampleInterface+Private.swift b/test-suite/generated-src/swift/SampleInterface+Private.swift new file mode 100644 index 00000000..11f2bfe4 --- /dev/null +++ b/test-suite/generated-src/swift/SampleInterface+Private.swift @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +/** + * we need to test optional interface + * this one will be used + */ +final class SampleInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.SampleInterface { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } +} +enum SampleInterfaceMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.SampleInterface + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { SampleInterfaceCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/SampleInterface.swift b/test-suite/generated-src/swift/SampleInterface.swift new file mode 100644 index 00000000..44dae5f3 --- /dev/null +++ b/test-suite/generated-src/swift/SampleInterface.swift @@ -0,0 +1,11 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +import Foundation + +/** + * we need to test optional interface + * this one will be used + */ +public protocol SampleInterface: AnyObject { +} diff --git a/test-suite/generated-src/swift/SecondListener+Private.swift b/test-suite/generated-src/swift/SecondListener+Private.swift new file mode 100644 index 00000000..be010122 --- /dev/null +++ b/test-suite/generated-src/swift/SecondListener+Private.swift @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +/** Used for ObjC multiple inheritance tests */ +enum SecondListenerMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.SecondListener + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { fatalError("n/a") }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/SecondListener.swift b/test-suite/generated-src/swift/SecondListener.swift new file mode 100644 index 00000000..c9e0497a --- /dev/null +++ b/test-suite/generated-src/swift/SecondListener.swift @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +import Foundation + +/** Used for ObjC multiple inheritance tests */ +public protocol SecondListener: AnyObject { + func second() throws -> Void +} diff --git a/test-suite/generated-src/swift/SetRecord+Private.swift b/test-suite/generated-src/swift/SetRecord+Private.swift new file mode 100644 index 00000000..68f19674 --- /dev/null +++ b/test-suite/generated-src/swift/SetRecord+Private.swift @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from set.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum SetRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.SetRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let set = SetMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + let iset = SetMarshaller.fromCpp(djinni.swift.getMember(p, 1)) + return SwiftType(set: set, iset: iset) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, SetMarshaller.toCpp(s.set)) + djinni.swift.addMember(&ret, SetMarshaller.toCpp(s.iset)) + return ret + } +} diff --git a/test-suite/generated-src/swift/SetRecord.swift b/test-suite/generated-src/swift/SetRecord.swift new file mode 100644 index 00000000..3ecd9b4f --- /dev/null +++ b/test-suite/generated-src/swift/SetRecord.swift @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from set.djinni + +import Foundation + +public struct SetRecord { + public var set: Set + public var iset: Set + + public init(set: Set, iset: Set) + { + self.set = set + self.iset = iset + } +} diff --git a/test-suite/generated-src/swift/SupportCopying+Private.swift b/test-suite/generated-src/swift/SupportCopying+Private.swift new file mode 100644 index 00000000..6dd09de5 --- /dev/null +++ b/test-suite/generated-src/swift/SupportCopying+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from nscopying.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum SupportCopyingMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.SupportCopying + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let x = I32Marshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(x: x) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, I32Marshaller.toCpp(s.x)) + return ret + } +} diff --git a/test-suite/generated-src/swift/SupportCopying.swift b/test-suite/generated-src/swift/SupportCopying.swift new file mode 100644 index 00000000..90a5c515 --- /dev/null +++ b/test-suite/generated-src/swift/SupportCopying.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from nscopying.djinni + +import Foundation + +public struct SupportCopying { + public var x: Int32 + + public init(x: Int32) + { + self.x = x + } +} diff --git a/test-suite/generated-src/swift/TestArray+Private.swift b/test-suite/generated-src/swift/TestArray+Private.swift new file mode 100644 index 00000000..1eb8b8c5 --- /dev/null +++ b/test-suite/generated-src/swift/TestArray+Private.swift @@ -0,0 +1,51 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from array.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class TestArrayCppProxy: DjinniSupport.CppProxy, TestSuite.TestArray { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } +} +enum TestArrayMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.TestArray + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { TestArrayCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class TestArray_statics { + static func testStringArray(a: Array) throws -> Array { + var params = djinni.swift.ParameterList() + params.addValue(ArrayMarshaller.toCpp(a)) + var ret = djinni_generated.TestArray_testStringArray(¶ms) + try handleCppErrors(&ret) + return ArrayMarshaller.fromCpp(ret) + } + static func testIntArray(a: Array) throws -> Array { + var params = djinni.swift.ParameterList() + params.addValue(ArrayMarshaller.toCpp(a)) + var ret = djinni_generated.TestArray_testIntArray(¶ms) + try handleCppErrors(&ret) + return ArrayMarshaller.fromCpp(ret) + } + static func testRecordArray(a: Array) throws -> Array { + var params = djinni.swift.ParameterList() + params.addValue(ArrayMarshaller.toCpp(a)) + var ret = djinni_generated.TestArray_testRecordArray(¶ms) + try handleCppErrors(&ret) + return ArrayMarshaller.fromCpp(ret) + } + static func testArrayOfArray(a: Array>) throws -> Array> { + var params = djinni.swift.ParameterList() + params.addValue(ArrayMarshaller>.toCpp(a)) + var ret = djinni_generated.TestArray_testArrayOfArray(¶ms) + try handleCppErrors(&ret) + return ArrayMarshaller>.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/TestArray.swift b/test-suite/generated-src/swift/TestArray.swift new file mode 100644 index 00000000..61f818dd --- /dev/null +++ b/test-suite/generated-src/swift/TestArray.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from array.djinni + +import Foundation + +public protocol TestArray: AnyObject { +} diff --git a/test-suite/generated-src/swift/TestDuration+Private.swift b/test-suite/generated-src/swift/TestDuration+Private.swift new file mode 100644 index 00000000..ed78f6ac --- /dev/null +++ b/test-suite/generated-src/swift/TestDuration+Private.swift @@ -0,0 +1,163 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from duration.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class TestDurationCppProxy: DjinniSupport.CppProxy, TestSuite.TestDuration { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } +} +enum TestDurationMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.TestDuration + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { TestDurationCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class TestDuration_statics { + static func hoursString(dt: Duration) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(DurationMarshaller.toCpp(dt)) + var ret = djinni_generated.TestDuration_hoursString(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + static func minutesString(dt: Duration) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(DurationMarshaller.toCpp(dt)) + var ret = djinni_generated.TestDuration_minutesString(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + static func secondsString(dt: Duration) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(DurationMarshaller.toCpp(dt)) + var ret = djinni_generated.TestDuration_secondsString(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + static func millisString(dt: Duration) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(DurationMarshaller.toCpp(dt)) + var ret = djinni_generated.TestDuration_millisString(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + static func microsString(dt: Duration) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(DurationMarshaller.toCpp(dt)) + var ret = djinni_generated.TestDuration_microsString(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + static func nanosString(dt: Duration) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(DurationMarshaller.toCpp(dt)) + var ret = djinni_generated.TestDuration_nanosString(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + static func hours(count: Int32) throws -> Duration { + var params = djinni.swift.ParameterList() + params.addValue(I32Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_hours(¶ms) + try handleCppErrors(&ret) + return DurationMarshaller.fromCpp(ret) + } + static func minutes(count: Int32) throws -> Duration { + var params = djinni.swift.ParameterList() + params.addValue(I32Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_minutes(¶ms) + try handleCppErrors(&ret) + return DurationMarshaller.fromCpp(ret) + } + static func seconds(count: Int32) throws -> Duration { + var params = djinni.swift.ParameterList() + params.addValue(I32Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_seconds(¶ms) + try handleCppErrors(&ret) + return DurationMarshaller.fromCpp(ret) + } + static func millis(count: Int32) throws -> Duration { + var params = djinni.swift.ParameterList() + params.addValue(I32Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_millis(¶ms) + try handleCppErrors(&ret) + return DurationMarshaller.fromCpp(ret) + } + static func micros(count: Int32) throws -> Duration { + var params = djinni.swift.ParameterList() + params.addValue(I32Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_micros(¶ms) + try handleCppErrors(&ret) + return DurationMarshaller.fromCpp(ret) + } + static func nanos(count: Int32) throws -> Duration { + var params = djinni.swift.ParameterList() + params.addValue(I32Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_nanos(¶ms) + try handleCppErrors(&ret) + return DurationMarshaller.fromCpp(ret) + } + static func hoursf(count: Double) throws -> Duration { + var params = djinni.swift.ParameterList() + params.addValue(F64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_hoursf(¶ms) + try handleCppErrors(&ret) + return DurationMarshaller.fromCpp(ret) + } + static func minutesf(count: Double) throws -> Duration { + var params = djinni.swift.ParameterList() + params.addValue(F64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_minutesf(¶ms) + try handleCppErrors(&ret) + return DurationMarshaller.fromCpp(ret) + } + static func secondsf(count: Double) throws -> Duration { + var params = djinni.swift.ParameterList() + params.addValue(F64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_secondsf(¶ms) + try handleCppErrors(&ret) + return DurationMarshaller.fromCpp(ret) + } + static func millisf(count: Double) throws -> Duration { + var params = djinni.swift.ParameterList() + params.addValue(F64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_millisf(¶ms) + try handleCppErrors(&ret) + return DurationMarshaller.fromCpp(ret) + } + static func microsf(count: Double) throws -> Duration { + var params = djinni.swift.ParameterList() + params.addValue(F64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_microsf(¶ms) + try handleCppErrors(&ret) + return DurationMarshaller.fromCpp(ret) + } + static func nanosf(count: Double) throws -> Duration { + var params = djinni.swift.ParameterList() + params.addValue(F64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_nanosf(¶ms) + try handleCppErrors(&ret) + return DurationMarshaller.fromCpp(ret) + } + static func box(count: Int64) throws -> Optional { + var params = djinni.swift.ParameterList() + params.addValue(I64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_box(¶ms) + try handleCppErrors(&ret) + return OptionalMarshaller>.fromCpp(ret) + } + static func unbox(dt: Optional) throws -> Int64 { + var params = djinni.swift.ParameterList() + params.addValue(OptionalMarshaller>.toCpp(dt)) + var ret = djinni_generated.TestDuration_unbox(¶ms) + try handleCppErrors(&ret) + return I64Marshaller.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/TestDuration.swift b/test-suite/generated-src/swift/TestDuration.swift new file mode 100644 index 00000000..ab56fd37 --- /dev/null +++ b/test-suite/generated-src/swift/TestDuration.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from duration.djinni + +import Foundation + +public protocol TestDuration: AnyObject { +} diff --git a/test-suite/generated-src/swift/TestHelpers+Private.swift b/test-suite/generated-src/swift/TestHelpers+Private.swift new file mode 100644 index 00000000..01481f94 --- /dev/null +++ b/test-suite/generated-src/swift/TestHelpers+Private.swift @@ -0,0 +1,282 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +/** + * Helper methods used by various different tests. + * (Second line of multi-line documentation. + * Indented third line of multi-line documentation.) + */ +final class TestHelpersCppProxy: DjinniSupport.CppProxy, TestSuite.TestHelpers { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } +} +enum TestHelpersMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.TestHelpers + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { TestHelpersCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class TestHelpers_statics { + static func getSetRecord() throws -> TestSuite.SetRecord { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getSetRecord(¶ms) + try handleCppErrors(&ret) + return SetRecordMarshaller.fromCpp(ret) + } + static func checkSetRecord(rec: TestSuite.SetRecord) throws -> Bool { + var params = djinni.swift.ParameterList() + params.addValue(SetRecordMarshaller.toCpp(rec)) + var ret = djinni_generated.TestHelpers_checkSetRecord(¶ms) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } + static func getPrimitiveList() throws -> TestSuite.PrimitiveList { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getPrimitiveList(¶ms) + try handleCppErrors(&ret) + return PrimitiveListMarshaller.fromCpp(ret) + } + static func checkPrimitiveList(pl: TestSuite.PrimitiveList) throws -> Bool { + var params = djinni.swift.ParameterList() + params.addValue(PrimitiveListMarshaller.toCpp(pl)) + var ret = djinni_generated.TestHelpers_checkPrimitiveList(¶ms) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } + static func getNestedCollection() throws -> TestSuite.NestedCollection { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getNestedCollection(¶ms) + try handleCppErrors(&ret) + return NestedCollectionMarshaller.fromCpp(ret) + } + static func checkNestedCollection(nc: TestSuite.NestedCollection) throws -> Bool { + var params = djinni.swift.ParameterList() + params.addValue(NestedCollectionMarshaller.toCpp(nc)) + var ret = djinni_generated.TestHelpers_checkNestedCollection(¶ms) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } + static func getMap() throws -> Dictionary { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getMap(¶ms) + try handleCppErrors(&ret) + return MapMarshaller.fromCpp(ret) + } + static func checkMap(m: Dictionary) throws -> Bool { + var params = djinni.swift.ParameterList() + params.addValue(MapMarshaller.toCpp(m)) + var ret = djinni_generated.TestHelpers_checkMap(¶ms) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } + static func getEmptyMap() throws -> Dictionary { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getEmptyMap(¶ms) + try handleCppErrors(&ret) + return MapMarshaller.fromCpp(ret) + } + static func checkEmptyMap(m: Dictionary) throws -> Bool { + var params = djinni.swift.ParameterList() + params.addValue(MapMarshaller.toCpp(m)) + var ret = djinni_generated.TestHelpers_checkEmptyMap(¶ms) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } + static func getMapListRecord() throws -> TestSuite.MapListRecord { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getMapListRecord(¶ms) + try handleCppErrors(&ret) + return MapListRecordMarshaller.fromCpp(ret) + } + static func checkMapListRecord(m: TestSuite.MapListRecord) throws -> Bool { + var params = djinni.swift.ParameterList() + params.addValue(MapListRecordMarshaller.toCpp(m)) + var ret = djinni_generated.TestHelpers_checkMapListRecord(¶ms) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } + static func checkClientInterfaceAscii(i: TestSuite.ClientInterface) throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(ClientInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.TestHelpers_checkClientInterfaceAscii(¶ms) + try handleCppErrors(&ret) + } + static func checkClientInterfaceNonascii(i: TestSuite.ClientInterface) throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(ClientInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.TestHelpers_checkClientInterfaceNonascii(¶ms) + try handleCppErrors(&ret) + } + static func checkClientInterfaceArgs(i: TestSuite.ClientInterface) throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(ClientInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.TestHelpers_checkClientInterfaceArgs(¶ms) + try handleCppErrors(&ret) + } + static func checkEnumMap(m: Dictionary) throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(MapMarshaller.toCpp(m)) + var ret = djinni_generated.TestHelpers_checkEnumMap(¶ms) + try handleCppErrors(&ret) + } + static func checkEnum(c: TestSuite.Color) throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(ColorMarshaller.toCpp(c)) + var ret = djinni_generated.TestHelpers_checkEnum(¶ms) + try handleCppErrors(&ret) + } + static func tokenId(t: Optional) throws -> Optional { + var params = djinni.swift.ParameterList() + params.addValue(OptionalMarshaller.toCpp(t)) + var ret = djinni_generated.TestHelpers_tokenId(¶ms) + try handleCppErrors(&ret) + return OptionalMarshaller.fromCpp(ret) + } + static func createCppToken() throws -> TestSuite.UserToken { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_createCppToken(¶ms) + try handleCppErrors(&ret) + return UserTokenMarshaller.fromCpp(ret) + } + static func checkCppToken(t: TestSuite.UserToken) throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(UserTokenMarshaller.toCpp(t)) + var ret = djinni_generated.TestHelpers_checkCppToken(¶ms) + try handleCppErrors(&ret) + } + static func cppTokenId(t: TestSuite.UserToken) throws -> Int64 { + var params = djinni.swift.ParameterList() + params.addValue(UserTokenMarshaller.toCpp(t)) + var ret = djinni_generated.TestHelpers_cppTokenId(¶ms) + try handleCppErrors(&ret) + return I64Marshaller.fromCpp(ret) + } + static func checkTokenType(t: TestSuite.UserToken, type: String) throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(UserTokenMarshaller.toCpp(t)) + params.addValue(StringMarshaller.toCpp(type)) + var ret = djinni_generated.TestHelpers_checkTokenType(¶ms) + try handleCppErrors(&ret) + } + static func returnNone() throws -> Optional { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_returnNone(¶ms) + try handleCppErrors(&ret) + return OptionalMarshaller.fromCpp(ret) + } + static func assortedPrimitivesId(i: TestSuite.AssortedPrimitives) throws -> TestSuite.AssortedPrimitives { + var params = djinni.swift.ParameterList() + params.addValue(AssortedPrimitivesMarshaller.toCpp(i)) + var ret = djinni_generated.TestHelpers_assortedPrimitivesId(¶ms) + try handleCppErrors(&ret) + return AssortedPrimitivesMarshaller.fromCpp(ret) + } + static func idBinary(b: Data) throws -> Data { + var params = djinni.swift.ParameterList() + params.addValue(BinaryMarshaller.toCpp(b)) + var ret = djinni_generated.TestHelpers_idBinary(¶ms) + try handleCppErrors(&ret) + return BinaryMarshaller.fromCpp(ret) + } + static func getAsyncResult() throws -> DJFuture { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getAsyncResult(¶ms) + try handleCppErrors(&ret) + return FutureMarshaller.fromCpp(ret) + } + static func futureRoundtrip(f: DJFuture) throws -> DJFuture { + var params = djinni.swift.ParameterList() + params.addValue(FutureMarshaller.toCpp(f)) + var ret = djinni_generated.TestHelpers_futureRoundtrip(¶ms) + try handleCppErrors(&ret) + return FutureMarshaller.fromCpp(ret) + } + static func asyncEarlyThrow() throws -> DJFuture { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_asyncEarlyThrow(¶ms) + try handleCppErrors(&ret) + return FutureMarshaller.fromCpp(ret) + } + static func voidAsyncMethod(f: DJFuture) throws -> DJFuture { + var params = djinni.swift.ParameterList() + params.addValue(FutureMarshaller.toCpp(f)) + var ret = djinni_generated.TestHelpers_voidAsyncMethod(¶ms) + try handleCppErrors(&ret) + return FutureMarshaller.fromCpp(ret) + } + static func addOneIfPresent(f: DJFuture>) throws -> DJFuture> { + var params = djinni.swift.ParameterList() + params.addValue(FutureMarshaller>.toCpp(f)) + var ret = djinni_generated.TestHelpers_addOneIfPresent(¶ms) + try handleCppErrors(&ret) + return FutureMarshaller>.fromCpp(ret) + } + static func returnExceptionString(f: DJFuture) throws -> DJFuture { + var params = djinni.swift.ParameterList() + params.addValue(FutureMarshaller.toCpp(f)) + var ret = djinni_generated.TestHelpers_returnExceptionString(¶ms) + try handleCppErrors(&ret) + return FutureMarshaller.fromCpp(ret) + } + static func checkAsyncInterface(i: TestSuite.AsyncInterface) throws -> DJFuture { + var params = djinni.swift.ParameterList() + params.addValue(AsyncInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.TestHelpers_checkAsyncInterface(¶ms) + try handleCppErrors(&ret) + return FutureMarshaller.fromCpp(ret) + } + static func checkAsyncComposition(i: TestSuite.AsyncInterface) throws -> DJFuture { + var params = djinni.swift.ParameterList() + params.addValue(AsyncInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.TestHelpers_checkAsyncComposition(¶ms) + try handleCppErrors(&ret) + return FutureMarshaller.fromCpp(ret) + } + static func getOptionalList() throws -> Array> { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getOptionalList(¶ms) + try handleCppErrors(&ret) + return ListMarshaller>.fromCpp(ret) + } + static func checkOptionalList(ol: Array>) throws -> Bool { + var params = djinni.swift.ParameterList() + params.addValue(ListMarshaller>.toCpp(ol)) + var ret = djinni_generated.TestHelpers_checkOptionalList(¶ms) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } + static func getOptionalSet() throws -> Set> { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getOptionalSet(¶ms) + try handleCppErrors(&ret) + return SetMarshaller>.fromCpp(ret) + } + static func checkOptionalSet(os: Set>) throws -> Bool { + var params = djinni.swift.ParameterList() + params.addValue(SetMarshaller>.toCpp(os)) + var ret = djinni_generated.TestHelpers_checkOptionalSet(¶ms) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } + static func getOptionalMap() throws -> Dictionary, Optional> { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getOptionalMap(¶ms) + try handleCppErrors(&ret) + return MapMarshaller, OptionalMarshaller>.fromCpp(ret) + } + static func checkOptionalMap(om: Dictionary, Optional>) throws -> Bool { + var params = djinni.swift.ParameterList() + params.addValue(MapMarshaller, OptionalMarshaller>.toCpp(om)) + var ret = djinni_generated.TestHelpers_checkOptionalMap(¶ms) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/TestHelpers.swift b/test-suite/generated-src/swift/TestHelpers.swift new file mode 100644 index 00000000..03c491eb --- /dev/null +++ b/test-suite/generated-src/swift/TestHelpers.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +import DjinniSupport +import Foundation + +/** + * Helper methods used by various different tests. + * (Second line of multi-line documentation. + * Indented third line of multi-line documentation.) + */ +public protocol TestHelpers: AnyObject { +} diff --git a/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord+Private.swift b/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord+Private.swift new file mode 100644 index 00000000..5a3a122d --- /dev/null +++ b/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum TestOptionalExternInterfaceRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.TestOptionalExternInterfaceRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let sampleInterface = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(sampleInterface: sampleInterface) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.sampleInterface)) + return ret + } +} diff --git a/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord.swift b/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord.swift new file mode 100644 index 00000000..19809406 --- /dev/null +++ b/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +import Foundation + +public struct TestOptionalExternInterfaceRecord { + public var sampleInterface: Optional + + public init(sampleInterface: Optional) + { + self.sampleInterface = sampleInterface + } +} diff --git a/test-suite/generated-src/swift/TestOutcome+Private.swift b/test-suite/generated-src/swift/TestOutcome+Private.swift new file mode 100644 index 00000000..b5c000b5 --- /dev/null +++ b/test-suite/generated-src/swift/TestOutcome+Private.swift @@ -0,0 +1,75 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from outcome.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class TestOutcomeCppProxy: DjinniSupport.CppProxy, TestSuite.TestOutcome { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } +} +enum TestOutcomeMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.TestOutcome + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { TestOutcomeCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class TestOutcome_statics { + static func getSuccessOutcome() throws -> Result { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestOutcome_getSuccessOutcome(¶ms) + try handleCppErrors(&ret) + return OutcomeMarshaller.fromCpp(ret) + } + static func getErrorOutcome() throws -> Result { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestOutcome_getErrorOutcome(¶ms) + try handleCppErrors(&ret) + return OutcomeMarshaller.fromCpp(ret) + } + static func putSuccessOutcome(x: Result) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(OutcomeMarshaller.toCpp(x)) + var ret = djinni_generated.TestOutcome_putSuccessOutcome(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + static func putErrorOutcome(x: Result) throws -> Int32 { + var params = djinni.swift.ParameterList() + params.addValue(OutcomeMarshaller.toCpp(x)) + var ret = djinni_generated.TestOutcome_putErrorOutcome(¶ms) + try handleCppErrors(&ret) + return I32Marshaller.fromCpp(ret) + } + static func getNestedSuccessOutcome() throws -> TestSuite.NestedOutcome { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestOutcome_getNestedSuccessOutcome(¶ms) + try handleCppErrors(&ret) + return NestedOutcomeMarshaller.fromCpp(ret) + } + static func getNestedErrorOutcome() throws -> TestSuite.NestedOutcome { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.TestOutcome_getNestedErrorOutcome(¶ms) + try handleCppErrors(&ret) + return NestedOutcomeMarshaller.fromCpp(ret) + } + static func putNestedSuccessOutcome(x: TestSuite.NestedOutcome) throws -> Int32 { + var params = djinni.swift.ParameterList() + params.addValue(NestedOutcomeMarshaller.toCpp(x)) + var ret = djinni_generated.TestOutcome_putNestedSuccessOutcome(¶ms) + try handleCppErrors(&ret) + return I32Marshaller.fromCpp(ret) + } + static func putNestedErrorOutcome(x: TestSuite.NestedOutcome) throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(NestedOutcomeMarshaller.toCpp(x)) + var ret = djinni_generated.TestOutcome_putNestedErrorOutcome(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/TestOutcome.swift b/test-suite/generated-src/swift/TestOutcome.swift new file mode 100644 index 00000000..e9871829 --- /dev/null +++ b/test-suite/generated-src/swift/TestOutcome.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from outcome.djinni + +import Foundation + +public protocol TestOutcome: AnyObject { +} diff --git a/test-suite/generated-src/swift/TestStaticMethodLanguage+Private.swift b/test-suite/generated-src/swift/TestStaticMethodLanguage+Private.swift new file mode 100644 index 00000000..f319b2cb --- /dev/null +++ b/test-suite/generated-src/swift/TestStaticMethodLanguage+Private.swift @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from static_method_language.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class TestStaticMethodLanguageCppProxy: DjinniSupport.CppProxy, TestSuite.TestStaticMethodLanguage { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } +} +enum TestStaticMethodLanguageMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.TestStaticMethodLanguage + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { TestStaticMethodLanguageCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/TestStaticMethodLanguage.swift b/test-suite/generated-src/swift/TestStaticMethodLanguage.swift new file mode 100644 index 00000000..ceeded9d --- /dev/null +++ b/test-suite/generated-src/swift/TestStaticMethodLanguage.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from static_method_language.djinni + +import Foundation + +public protocol TestStaticMethodLanguage: AnyObject { +} diff --git a/test-suite/generated-src/swift/ThrowingInterface+Private.swift b/test-suite/generated-src/swift/ThrowingInterface+Private.swift new file mode 100644 index 00000000..bc876fa8 --- /dev/null +++ b/test-suite/generated-src/swift/ThrowingInterface+Private.swift @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from exception.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +let throwingInterfaceMethods: Vtbl = [ + { inst, params, ret in + try inst.throwException() + }, +] + +enum ThrowingInterfaceMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.ThrowingInterface + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { fatalError("n/a") }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { djinni_generated.ThrowingInterfaceSwiftProxy.make(ctxPtr(s, throwingInterfaceMethods), dispatcherProtocalCall)}) + } +} diff --git a/test-suite/generated-src/swift/ThrowingInterface.swift b/test-suite/generated-src/swift/ThrowingInterface.swift new file mode 100644 index 00000000..b3e9115c --- /dev/null +++ b/test-suite/generated-src/swift/ThrowingInterface.swift @@ -0,0 +1,8 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from exception.djinni + +import Foundation + +public protocol ThrowingInterface: AnyObject { + func throwException() throws -> Void +} diff --git a/test-suite/generated-src/swift/UserToken+Private.swift b/test-suite/generated-src/swift/UserToken+Private.swift new file mode 100644 index 00000000..1022e051 --- /dev/null +++ b/test-suite/generated-src/swift/UserToken+Private.swift @@ -0,0 +1,34 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from user_token.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class UserTokenCppProxy: DjinniSupport.CppProxy, TestSuite.UserToken { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func whoami() throws -> String { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.UserToken_whoami(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } +} +let userTokenMethods: Vtbl = [ + { inst, params, ret in + djinni.swift.setReturnValue(ret, try StringMarshaller.toCpp(inst.whoami())) + }, +] + +enum UserTokenMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.UserToken + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { UserTokenCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { djinni_generated.UserTokenSwiftProxy.make(ctxPtr(s, userTokenMethods), dispatcherProtocalCall)}) + } +} diff --git a/test-suite/generated-src/swift/UserToken.swift b/test-suite/generated-src/swift/UserToken.swift new file mode 100644 index 00000000..42715830 --- /dev/null +++ b/test-suite/generated-src/swift/UserToken.swift @@ -0,0 +1,8 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from user_token.djinni + +import Foundation + +public protocol UserToken: AnyObject { + func whoami() throws -> String +} diff --git a/test-suite/generated-src/swift/UsesSingleLanguageListeners+Private.swift b/test-suite/generated-src/swift/UsesSingleLanguageListeners+Private.swift new file mode 100644 index 00000000..dfef4831 --- /dev/null +++ b/test-suite/generated-src/swift/UsesSingleLanguageListeners+Private.swift @@ -0,0 +1,53 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from single_language_interfaces.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +/** + * Generating and compiling this makes sure other languages don't break + * on references to interfaces they don't need. + */ +final class UsesSingleLanguageListenersCppProxy: DjinniSupport.CppProxy, TestSuite.UsesSingleLanguageListeners { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func callForObjC(l: TestSuite.ObjcOnlyListener) throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(ObjcOnlyListenerMarshaller.toCpp(l)) + var ret = djinni_generated.UsesSingleLanguageListeners_callForObjC(¶ms) + try handleCppErrors(&ret) + } + func returnForObjC() throws -> TestSuite.ObjcOnlyListener { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.UsesSingleLanguageListeners_returnForObjC(¶ms) + try handleCppErrors(&ret) + return ObjcOnlyListenerMarshaller.fromCpp(ret) + } + func callForJava(l: TestSuite.JavaOnlyListener) throws -> Void { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(JavaOnlyListenerMarshaller.toCpp(l)) + var ret = djinni_generated.UsesSingleLanguageListeners_callForJava(¶ms) + try handleCppErrors(&ret) + } + func returnForJava() throws -> TestSuite.JavaOnlyListener { + var params = djinni.swift.ParameterList() + params.addValue(inst) + var ret = djinni_generated.UsesSingleLanguageListeners_returnForJava(¶ms) + try handleCppErrors(&ret) + return JavaOnlyListenerMarshaller.fromCpp(ret) + } +} +enum UsesSingleLanguageListenersMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.UsesSingleLanguageListeners + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { UsesSingleLanguageListenersCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/UsesSingleLanguageListeners.swift b/test-suite/generated-src/swift/UsesSingleLanguageListeners.swift new file mode 100644 index 00000000..dbc44915 --- /dev/null +++ b/test-suite/generated-src/swift/UsesSingleLanguageListeners.swift @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from single_language_interfaces.djinni + +import Foundation + +/** + * Generating and compiling this makes sure other languages don't break + * on references to interfaces they don't need. + */ +public protocol UsesSingleLanguageListeners: AnyObject { + func callForObjC(l: TestSuite.ObjcOnlyListener) throws -> Void + func returnForObjC() throws -> TestSuite.ObjcOnlyListener + func callForJava(l: TestSuite.JavaOnlyListener) throws -> Void + func returnForJava() throws -> TestSuite.JavaOnlyListener +} diff --git a/test-suite/generated-src/swift/VarnameInterface+Private.swift b/test-suite/generated-src/swift/VarnameInterface+Private.swift new file mode 100644 index 00000000..36ee2246 --- /dev/null +++ b/test-suite/generated-src/swift/VarnameInterface+Private.swift @@ -0,0 +1,37 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from varnames.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class VarnameInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.VarnameInterface { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } + func Rmethod(RArg: TestSuite.VarnameRecord) throws -> TestSuite.VarnameRecord { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(VarnameRecordMarshaller.toCpp(RArg)) + var ret = djinni_generated.VarnameInterface_Rmethod(¶ms) + try handleCppErrors(&ret) + return VarnameRecordMarshaller.fromCpp(ret) + } + func Imethod(IArg: TestSuite.VarnameInterface) throws -> TestSuite.VarnameInterface { + var params = djinni.swift.ParameterList() + params.addValue(inst) + params.addValue(VarnameInterfaceMarshaller.toCpp(IArg)) + var ret = djinni_generated.VarnameInterface_Imethod(¶ms) + try handleCppErrors(&ret) + return VarnameInterfaceMarshaller.fromCpp(ret) + } +} +enum VarnameInterfaceMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.VarnameInterface + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { VarnameInterfaceCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} diff --git a/test-suite/generated-src/swift/VarnameInterface.swift b/test-suite/generated-src/swift/VarnameInterface.swift new file mode 100644 index 00000000..db530ae8 --- /dev/null +++ b/test-suite/generated-src/swift/VarnameInterface.swift @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from varnames.djinni + +import Foundation + +public protocol VarnameInterface: AnyObject { + /** + * We should also rewrite parameter names in docstrings. + * RArg should be rewritten. + * _i_arg_ should not. + */ + func Rmethod(RArg: TestSuite.VarnameRecord) throws -> TestSuite.VarnameRecord + func Imethod(IArg: TestSuite.VarnameInterface) throws -> TestSuite.VarnameInterface +} diff --git a/test-suite/generated-src/swift/VarnameRecord+Private.swift b/test-suite/generated-src/swift/VarnameRecord+Private.swift new file mode 100644 index 00000000..35312006 --- /dev/null +++ b/test-suite/generated-src/swift/VarnameRecord+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from varnames.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum VarnameRecordMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.VarnameRecord + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let Field = I8Marshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(Field: Field) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, I8Marshaller.toCpp(s.Field)) + return ret + } +} diff --git a/test-suite/generated-src/swift/VarnameRecord.swift b/test-suite/generated-src/swift/VarnameRecord.swift new file mode 100644 index 00000000..c67599e9 --- /dev/null +++ b/test-suite/generated-src/swift/VarnameRecord.swift @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from varnames.djinni + +import Foundation + +/** + * Underscore is used as a separator in Djinni names, so we don't really + * anticipate it to be used as a prefix/suffix. Some name styles behave + * badly when it is. However this test case ensures we at least don't crash. + */ +public struct VarnameRecord { + public var Field: Int8 + + public init(Field: Int8) + { + self.Field = Field + } +} diff --git a/test-suite/generated-src/swift/Vec2+Private.swift b/test-suite/generated-src/swift/Vec2+Private.swift new file mode 100644 index 00000000..03154084 --- /dev/null +++ b/test-suite/generated-src/swift/Vec2+Private.swift @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from array.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum Vec2Marshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.Vec2 + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let x = I32Marshaller.fromCpp(djinni.swift.getMember(p, 0)) + let y = I32Marshaller.fromCpp(djinni.swift.getMember(p, 1)) + return SwiftType(x: x, y: y) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, I32Marshaller.toCpp(s.x)) + djinni.swift.addMember(&ret, I32Marshaller.toCpp(s.y)) + return ret + } +} diff --git a/test-suite/generated-src/swift/Vec2.swift b/test-suite/generated-src/swift/Vec2.swift new file mode 100644 index 00000000..9168da99 --- /dev/null +++ b/test-suite/generated-src/swift/Vec2.swift @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from array.djinni + +import Foundation + +public struct Vec2: Equatable { + public var x: Int32 + public var y: Int32 + + public init(x: Int32, y: Int32) + { + self.x = x + self.y = y + } +} diff --git a/test-suite/generated-src/swift/WcharTestHelpers+Private.swift b/test-suite/generated-src/swift/WcharTestHelpers+Private.swift new file mode 100644 index 00000000..79845ef8 --- /dev/null +++ b/test-suite/generated-src/swift/WcharTestHelpers+Private.swift @@ -0,0 +1,49 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from wchar_test.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +final class WcharTestHelpersCppProxy: DjinniSupport.CppProxy, TestSuite.WcharTestHelpers { + init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } +} +enum WcharTestHelpersMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.WcharTestHelpers + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return cppInterfaceToSwift(c, { WcharTestHelpersCppProxy(c) as SwiftType }) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class WcharTestHelpers_statics { + static func getRecord() throws -> TestSuite.WcharTestRec { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.WcharTestHelpers_getRecord(¶ms) + try handleCppErrors(&ret) + return WcharTestRecMarshaller.fromCpp(ret) + } + static func getString() throws -> String { + var params = djinni.swift.ParameterList() + var ret = djinni_generated.WcharTestHelpers_getString(¶ms) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } + static func checkString(str: String) throws -> Bool { + var params = djinni.swift.ParameterList() + params.addValue(StringMarshaller.toCpp(str)) + var ret = djinni_generated.WcharTestHelpers_checkString(¶ms) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } + static func checkRecord(rec: TestSuite.WcharTestRec) throws -> Bool { + var params = djinni.swift.ParameterList() + params.addValue(WcharTestRecMarshaller.toCpp(rec)) + var ret = djinni_generated.WcharTestHelpers_checkRecord(¶ms) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } +} diff --git a/test-suite/generated-src/swift/WcharTestHelpers.swift b/test-suite/generated-src/swift/WcharTestHelpers.swift new file mode 100644 index 00000000..41aa917a --- /dev/null +++ b/test-suite/generated-src/swift/WcharTestHelpers.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from wchar_test.djinni + +import Foundation + +public protocol WcharTestHelpers: AnyObject { +} diff --git a/test-suite/generated-src/swift/WcharTestRec+Private.swift b/test-suite/generated-src/swift/WcharTestRec+Private.swift new file mode 100644 index 00000000..46c55e19 --- /dev/null +++ b/test-suite/generated-src/swift/WcharTestRec+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from wchar_test.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TestSuite +import TestSuiteCxx + +enum WcharTestRecMarshaller: DjinniSupport.Marshaller { + typealias SwiftType = TestSuite.WcharTestRec + static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { + return withUnsafePointer(to: c) { p in + let s = StringMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(s: s) + } + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, StringMarshaller.toCpp(s.s)) + return ret + } +} diff --git a/test-suite/generated-src/swift/WcharTestRec.swift b/test-suite/generated-src/swift/WcharTestRec.swift new file mode 100644 index 00000000..092355c0 --- /dev/null +++ b/test-suite/generated-src/swift/WcharTestRec.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from wchar_test.djinni + +import Foundation + +public struct WcharTestRec { + public var s: String + + public init(s: String) + { + self.s = s + } +} diff --git a/test-suite/generated-src/swiftxx/NativeAccessFlags.cpp b/test-suite/generated-src/swiftxx/NativeAccessFlags.cpp new file mode 100644 index 00000000..9c9604bc --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeAccessFlags.cpp @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +#include "NativeAccessFlags.hpp" // my header + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeAccessFlags.hpp b/test-suite/generated-src/swiftxx/NativeAccessFlags.hpp new file mode 100644 index 00000000..b3f7aaea --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeAccessFlags.hpp @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +#pragma once + +#include "access_flags.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +using NativeAccessFlags = djinni::swift::Enum<::testsuite::access_flags>; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeAssortedPrimitives.cpp b/test-suite/generated-src/swiftxx/NativeAssortedPrimitives.cpp new file mode 100644 index 00000000..f87e822f --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeAssortedPrimitives.cpp @@ -0,0 +1,31 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from primtypes.djinni + +#include "NativeAssortedPrimitives.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeAssortedPrimitives::fromCpp(const ::testsuite::AssortedPrimitives& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::Bool::fromCpp(c.b)); + ret->addValue(::djinni::swift::I8::fromCpp(c.eight)); + ret->addValue(::djinni::swift::I16::fromCpp(c.sixteen)); + ret->addValue(::djinni::swift::I32::fromCpp(c.thirtytwo)); + ret->addValue(::djinni::swift::I64::fromCpp(c.sixtyfour)); + ret->addValue(::djinni::swift::F32::fromCpp(c.fthirtytwo)); + ret->addValue(::djinni::swift::F64::fromCpp(c.fsixtyfour)); + ret->addValue(::djinni::swift::Optional::fromCpp(c.o_b)); + ret->addValue(::djinni::swift::Optional::fromCpp(c.o_eight)); + ret->addValue(::djinni::swift::Optional::fromCpp(c.o_sixteen)); + ret->addValue(::djinni::swift::Optional::fromCpp(c.o_thirtytwo)); + ret->addValue(::djinni::swift::Optional::fromCpp(c.o_sixtyfour)); + ret->addValue(::djinni::swift::Optional::fromCpp(c.o_fthirtytwo)); + ret->addValue(::djinni::swift::Optional::fromCpp(c.o_fsixtyfour)); + return {ret}; +} +::testsuite::AssortedPrimitives NativeAssortedPrimitives::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::AssortedPrimitives(::djinni::swift::Bool::toCpp(p->getValue(0)), ::djinni::swift::I8::toCpp(p->getValue(1)), ::djinni::swift::I16::toCpp(p->getValue(2)), ::djinni::swift::I32::toCpp(p->getValue(3)), ::djinni::swift::I64::toCpp(p->getValue(4)), ::djinni::swift::F32::toCpp(p->getValue(5)), ::djinni::swift::F64::toCpp(p->getValue(6)), ::djinni::swift::Optional::toCpp(p->getValue(7)), ::djinni::swift::Optional::toCpp(p->getValue(8)), ::djinni::swift::Optional::toCpp(p->getValue(9)), ::djinni::swift::Optional::toCpp(p->getValue(10)), ::djinni::swift::Optional::toCpp(p->getValue(11)), ::djinni::swift::Optional::toCpp(p->getValue(12)), ::djinni::swift::Optional::toCpp(p->getValue(13))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeAssortedPrimitives.hpp b/test-suite/generated-src/swiftxx/NativeAssortedPrimitives.hpp new file mode 100644 index 00000000..dc3ce07f --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeAssortedPrimitives.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from primtypes.djinni + +#pragma once + +#include "assorted_primitives.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +struct NativeAssortedPrimitives { + using CppType = ::testsuite::AssortedPrimitives; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeAsyncInterface.cpp b/test-suite/generated-src/swiftxx/NativeAsyncInterface.cpp new file mode 100644 index 00000000..9b5574ec --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeAsyncInterface.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +#include "NativeAsyncInterface.hpp" // my header +#include "Future_swift.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue AsyncInterfaceSwiftProxy::make(void* instance, djinni::swift::DispatchFunc dispatcher) { + return {std::make_shared(instance, dispatcher)}; +} +::djinni::Future AsyncInterfaceSwiftProxy::future_roundtrip(::djinni::Future f) { + djinni::swift::ParameterList params; + params.addValue(::djinni::swift::FutureAdaptor<::djinni::swift::I32>::fromCpp(std::move(f))); + return ::djinni::swift::FutureAdaptor<::djinni::swift::String>::toCpp(callProtocol(0, ¶ms)); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeAsyncInterface.hpp b/test-suite/generated-src/swiftxx/NativeAsyncInterface.hpp new file mode 100644 index 00000000..aba7992e --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeAsyncInterface.hpp @@ -0,0 +1,20 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +#pragma once + +#include "async_interface.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +using NativeAsyncInterface = djinni::swift::Interface<::testsuite::AsyncInterface>; + +class AsyncInterfaceSwiftProxy: public ::testsuite::AsyncInterface, public djinni::swift::ProtocolWrapper { +public: + AsyncInterfaceSwiftProxy(void* instance, djinni::swift::DispatchFunc dispatcher): ProtocolWrapper(instance, dispatcher) {} + static djinni::swift::AnyValue make(void* instance, djinni::swift::DispatchFunc dispatcher); + ::djinni::Future future_roundtrip(::djinni::Future f) override; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeClientInterface.cpp b/test-suite/generated-src/swiftxx/NativeClientInterface.cpp new file mode 100644 index 00000000..74d6194c --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeClientInterface.cpp @@ -0,0 +1,41 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from client_interface.djinni + +#include "NativeClientInterface.hpp" // my header +#include "NativeClientReturnedRecord.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue ClientInterfaceSwiftProxy::make(void* instance, djinni::swift::DispatchFunc dispatcher) { + return {std::make_shared(instance, dispatcher)}; +} +::testsuite::ClientReturnedRecord ClientInterfaceSwiftProxy::get_record(int64_t record_id, const std::string & utf8string, const std::experimental::optional & misc) { + djinni::swift::ParameterList params; + params.addValue(::djinni::swift::I64::fromCpp(record_id)); + params.addValue(::djinni::swift::String::fromCpp(utf8string)); + params.addValue(::djinni::swift::Optional::fromCpp(misc)); + return ::djinni_generated::NativeClientReturnedRecord::toCpp(callProtocol(0, ¶ms)); +} +double ClientInterfaceSwiftProxy::identifier_check(const std::vector & data, int32_t r, int64_t jret) { + djinni::swift::ParameterList params; + params.addValue(::djinni::swift::Binary::fromCpp(data)); + params.addValue(::djinni::swift::I32::fromCpp(r)); + params.addValue(::djinni::swift::I64::fromCpp(jret)); + return ::djinni::swift::F64::toCpp(callProtocol(1, ¶ms)); +} +std::string ClientInterfaceSwiftProxy::return_str() { + djinni::swift::ParameterList params; + return ::djinni::swift::String::toCpp(callProtocol(2, ¶ms)); +} +std::string ClientInterfaceSwiftProxy::meth_taking_interface(const /*not-null*/ std::shared_ptr<::testsuite::ClientInterface> & i) { + djinni::swift::ParameterList params; + params.addValue(::djinni_generated::NativeClientInterface::fromCpp(i)); + return ::djinni::swift::String::toCpp(callProtocol(3, ¶ms)); +} +std::string ClientInterfaceSwiftProxy::meth_taking_optional_interface(const /*nullable*/ std::shared_ptr<::testsuite::ClientInterface> & i) { + djinni::swift::ParameterList params; + params.addValue(::djinni::swift::Optional::fromCpp(i)); + return ::djinni::swift::String::toCpp(callProtocol(4, ¶ms)); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeClientInterface.hpp b/test-suite/generated-src/swiftxx/NativeClientInterface.hpp new file mode 100644 index 00000000..f09ad551 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeClientInterface.hpp @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from client_interface.djinni + +#pragma once + +#include "client_interface.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +using NativeClientInterface = djinni::swift::Interface<::testsuite::ClientInterface>; + +class ClientInterfaceSwiftProxy: public ::testsuite::ClientInterface, public djinni::swift::ProtocolWrapper { +public: + ClientInterfaceSwiftProxy(void* instance, djinni::swift::DispatchFunc dispatcher): ProtocolWrapper(instance, dispatcher) {} + static djinni::swift::AnyValue make(void* instance, djinni::swift::DispatchFunc dispatcher); + ::testsuite::ClientReturnedRecord get_record(int64_t record_id, const std::string & utf8string, const std::experimental::optional & misc) override; + double identifier_check(const std::vector & data, int32_t r, int64_t jret) override; + std::string return_str() override; + std::string meth_taking_interface(const /*not-null*/ std::shared_ptr<::testsuite::ClientInterface> & i) override; + std::string meth_taking_optional_interface(const /*nullable*/ std::shared_ptr<::testsuite::ClientInterface> & i) override; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeClientReturnedRecord.cpp b/test-suite/generated-src/swiftxx/NativeClientReturnedRecord.cpp new file mode 100644 index 00000000..c395bd3c --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeClientReturnedRecord.cpp @@ -0,0 +1,20 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from client_interface.djinni + +#include "NativeClientReturnedRecord.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeClientReturnedRecord::fromCpp(const ::testsuite::ClientReturnedRecord& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::I64::fromCpp(c.record_id)); + ret->addValue(::djinni::swift::String::fromCpp(c.content)); + ret->addValue(::djinni::swift::Optional::fromCpp(c.misc)); + return {ret}; +} +::testsuite::ClientReturnedRecord NativeClientReturnedRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::ClientReturnedRecord(::djinni::swift::I64::toCpp(p->getValue(0)), ::djinni::swift::String::toCpp(p->getValue(1)), ::djinni::swift::Optional::toCpp(p->getValue(2))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeClientReturnedRecord.hpp b/test-suite/generated-src/swiftxx/NativeClientReturnedRecord.hpp new file mode 100644 index 00000000..67d32751 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeClientReturnedRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from client_interface.djinni + +#pragma once + +#include "client_returned_record.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +struct NativeClientReturnedRecord { + using CppType = ::testsuite::ClientReturnedRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeColor.cpp b/test-suite/generated-src/swiftxx/NativeColor.cpp new file mode 100644 index 00000000..e9984790 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeColor.cpp @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum.djinni + +#include "NativeColor.hpp" // my header + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeColor.hpp b/test-suite/generated-src/swiftxx/NativeColor.hpp new file mode 100644 index 00000000..6034fa4b --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeColor.hpp @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum.djinni + +#pragma once + +#include "color.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +using NativeColor = djinni::swift::Enum<::testsuite::color>; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConflict.cpp b/test-suite/generated-src/swiftxx/NativeConflict.cpp new file mode 100644 index 00000000..f4108793 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConflict.cpp @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +#include "NativeConflict.hpp" // my header + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConflict.hpp b/test-suite/generated-src/swiftxx/NativeConflict.hpp new file mode 100644 index 00000000..d263045e --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConflict.hpp @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +#pragma once + +#include "Conflict.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +using NativeConflict = djinni::swift::Interface<::testsuite::Conflict>; + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConflictUser.cpp b/test-suite/generated-src/swiftxx/NativeConflictUser.cpp new file mode 100644 index 00000000..3bf3699e --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConflictUser.cpp @@ -0,0 +1,27 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +#include "NativeConflictUser.hpp" // my header +#include "NativeConflict.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue ConflictUser_Conflict(const djinni::swift::ParameterList* params) try { + auto inst = NativeConflictUser::toCpp(params->getValue(0)); + auto ret = inst->Conflict(); + return ::djinni_generated::NativeConflict::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ConflictUser_conflictArg(const djinni::swift::ParameterList* params) try { + auto inst = NativeConflictUser::toCpp(params->getValue(0)); + auto _cs = ::djinni::swift::List<::djinni_generated::NativeConflict>::toCpp(params->getValue(1)); + auto ret = inst->conflict_arg(std::move(_cs)); + return ::djinni::swift::Bool::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConflictUser.hpp b/test-suite/generated-src/swiftxx/NativeConflictUser.hpp new file mode 100644 index 00000000..af75f23e --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConflictUser.hpp @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +#pragma once + +#include "conflict_user.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +using NativeConflictUser = djinni::swift::Interface<::testsuite::ConflictUser>; + +djinni::swift::AnyValue ConflictUser_Conflict(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ConflictUser_conflictArg(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConstantEnum.cpp b/test-suite/generated-src/swiftxx/NativeConstantEnum.cpp new file mode 100644 index 00000000..ecd09bae --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConstantEnum.cpp @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constant_enum.djinni + +#include "NativeConstantEnum.hpp" // my header + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConstantEnum.hpp b/test-suite/generated-src/swiftxx/NativeConstantEnum.hpp new file mode 100644 index 00000000..359786d3 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConstantEnum.hpp @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constant_enum.djinni + +#pragma once + +#include "constant_enum.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +using NativeConstantEnum = djinni::swift::Enum<::testsuite::constant_enum>; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConstantInterfaceWithEnum.cpp b/test-suite/generated-src/swiftxx/NativeConstantInterfaceWithEnum.cpp new file mode 100644 index 00000000..75d8ec2d --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConstantInterfaceWithEnum.cpp @@ -0,0 +1,10 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constant_enum.djinni + +#include "NativeConstantInterfaceWithEnum.hpp" // my header +#include "NativeConstantEnum.hpp" + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConstantInterfaceWithEnum.hpp b/test-suite/generated-src/swiftxx/NativeConstantInterfaceWithEnum.hpp new file mode 100644 index 00000000..538a6ecc --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConstantInterfaceWithEnum.hpp @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constant_enum.djinni + +#pragma once + +#include "constant_interface_with_enum.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +using NativeConstantInterfaceWithEnum = djinni::swift::Interface<::testsuite::ConstantInterfaceWithEnum>; + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConstantRecord.cpp b/test-suite/generated-src/swiftxx/NativeConstantRecord.cpp new file mode 100644 index 00000000..1446f49e --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConstantRecord.cpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +#include "NativeConstantRecord.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeConstantRecord::fromCpp(const ::testsuite::ConstantRecord& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::I32::fromCpp(c.some_integer)); + ret->addValue(::djinni::swift::String::fromCpp(c.some_string)); + return {ret}; +} +::testsuite::ConstantRecord NativeConstantRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::ConstantRecord(::djinni::swift::I32::toCpp(p->getValue(0)), ::djinni::swift::String::toCpp(p->getValue(1))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConstantRecord.hpp b/test-suite/generated-src/swiftxx/NativeConstantRecord.hpp new file mode 100644 index 00000000..a8905b98 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConstantRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +#pragma once + +#include "constant_record.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +struct NativeConstantRecord { + using CppType = ::testsuite::ConstantRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConstantWithEnum.cpp b/test-suite/generated-src/swiftxx/NativeConstantWithEnum.cpp new file mode 100644 index 00000000..124b5bab --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConstantWithEnum.cpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constant_enum.djinni + +#include "NativeConstantWithEnum.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeConstantWithEnum::fromCpp(const ::testsuite::ConstantWithEnum& c) { + auto ret = std::make_shared(); + return {ret}; +} +::testsuite::ConstantWithEnum NativeConstantWithEnum::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::ConstantWithEnum(); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConstantWithEnum.hpp b/test-suite/generated-src/swiftxx/NativeConstantWithEnum.hpp new file mode 100644 index 00000000..8280e790 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConstantWithEnum.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constant_enum.djinni + +#pragma once + +#include "constant_with_enum.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +struct NativeConstantWithEnum { + using CppType = ::testsuite::ConstantWithEnum; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConstants.cpp b/test-suite/generated-src/swiftxx/NativeConstants.cpp new file mode 100644 index 00000000..c1c85fba --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConstants.cpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +#include "NativeConstants.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeConstants::fromCpp(const ::testsuite::Constants& c) { + auto ret = std::make_shared(); + return {ret}; +} +::testsuite::Constants NativeConstants::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::Constants(); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConstants.hpp b/test-suite/generated-src/swiftxx/NativeConstants.hpp new file mode 100644 index 00000000..efc79f11 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConstants.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +#pragma once + +#include "constants.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +struct NativeConstants { + using CppType = ::testsuite::Constants; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConstantsInterface.cpp b/test-suite/generated-src/swiftxx/NativeConstantsInterface.cpp new file mode 100644 index 00000000..939bd3ed --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConstantsInterface.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +#include "NativeConstantsInterface.hpp" // my header +#include "NativeConstantRecord.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue ConstantsInterface_dummy(const djinni::swift::ParameterList* params) try { + auto inst = NativeConstantsInterface::toCpp(params->getValue(0)); + inst->dummy(); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeConstantsInterface.hpp b/test-suite/generated-src/swiftxx/NativeConstantsInterface.hpp new file mode 100644 index 00000000..07d9060e --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeConstantsInterface.hpp @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from constants.djinni + +#pragma once + +#include "constants_interface.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +using NativeConstantsInterface = djinni::swift::Interface<::testsuite::ConstantsInterface>; + +djinni::swift::AnyValue ConstantsInterface_dummy(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeCppException.cpp b/test-suite/generated-src/swiftxx/NativeCppException.cpp new file mode 100644 index 00000000..ba1c8de8 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeCppException.cpp @@ -0,0 +1,43 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from exception.djinni + +#include "NativeCppException.hpp" // my header +#include "NativeThrowingInterface.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue CppException_throwAnException(const djinni::swift::ParameterList* params) try { + auto inst = NativeCppException::toCpp(params->getValue(0)); + auto ret = inst->throw_an_exception(); + return ::djinni::swift::I32::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue CppException_callThrowingInterface(const djinni::swift::ParameterList* params) try { + auto inst = NativeCppException::toCpp(params->getValue(0)); + auto _cb = ::djinni_generated::NativeThrowingInterface::toCpp(params->getValue(1)); + auto ret = inst->call_throwing_interface(std::move(_cb)); + return ::djinni::swift::I32::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue CppException_callThrowingAndCatch(const djinni::swift::ParameterList* params) try { + auto inst = NativeCppException::toCpp(params->getValue(0)); + auto _cb = ::djinni_generated::NativeThrowingInterface::toCpp(params->getValue(1)); + auto ret = inst->call_throwing_and_catch(std::move(_cb)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue CppException_get(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::CppException::get(); + return ::djinni_generated::NativeCppException::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeCppException.hpp b/test-suite/generated-src/swiftxx/NativeCppException.hpp new file mode 100644 index 00000000..c01ab58f --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeCppException.hpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from exception.djinni + +#pragma once + +#include "cpp_exception.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +using NativeCppException = djinni::swift::Interface<::testsuite::CppException>; + +djinni::swift::AnyValue CppException_throwAnException(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue CppException_callThrowingInterface(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue CppException_callThrowingAndCatch(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue CppException_get(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeDataRefTest.cpp b/test-suite/generated-src/swiftxx/NativeDataRefTest.cpp new file mode 100644 index 00000000..4bd1322e --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeDataRefTest.cpp @@ -0,0 +1,84 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from data_ref_view.djinni + +#include "NativeDataRefTest.hpp" // my header +#include "Data_swift.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue DataRefTest_sendData(const djinni::swift::ParameterList* params) try { + auto inst = NativeDataRefTest::toCpp(params->getValue(0)); + auto _data = ::djinni::swift::DataRefAdaptor::toCpp(params->getValue(1)); + inst->sendData(std::move(_data)); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue DataRefTest_retriveAsBin(const djinni::swift::ParameterList* params) try { + auto inst = NativeDataRefTest::toCpp(params->getValue(0)); + auto ret = inst->retriveAsBin(); + return ::djinni::swift::Binary::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue DataRefTest_sendMutableData(const djinni::swift::ParameterList* params) try { + auto inst = NativeDataRefTest::toCpp(params->getValue(0)); + auto _data = ::djinni::swift::DataRefAdaptor::toCpp(params->getValue(1)); + inst->sendMutableData(std::move(_data)); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue DataRefTest_generateData(const djinni::swift::ParameterList* params) try { + auto inst = NativeDataRefTest::toCpp(params->getValue(0)); + auto ret = inst->generateData(); + return ::djinni::swift::DataRefAdaptor::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue DataRefTest_dataFromVec(const djinni::swift::ParameterList* params) try { + auto inst = NativeDataRefTest::toCpp(params->getValue(0)); + auto ret = inst->dataFromVec(); + return ::djinni::swift::DataRefAdaptor::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue DataRefTest_dataFromStr(const djinni::swift::ParameterList* params) try { + auto inst = NativeDataRefTest::toCpp(params->getValue(0)); + auto ret = inst->dataFromStr(); + return ::djinni::swift::DataRefAdaptor::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue DataRefTest_sendDataView(const djinni::swift::ParameterList* params) try { + auto inst = NativeDataRefTest::toCpp(params->getValue(0)); + auto _data = ::djinni::swift::DataViewAdaptor::toCpp(params->getValue(1)); + auto ret = inst->sendDataView(std::move(_data)); + return ::djinni::swift::Binary::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue DataRefTest_recvDataView(const djinni::swift::ParameterList* params) try { + auto inst = NativeDataRefTest::toCpp(params->getValue(0)); + auto ret = inst->recvDataView(); + return ::djinni::swift::DataViewAdaptor::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue DataRefTest_create(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::DataRefTest::create(); + return ::djinni_generated::NativeDataRefTest::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeDataRefTest.hpp b/test-suite/generated-src/swiftxx/NativeDataRefTest.hpp new file mode 100644 index 00000000..2ab9deb5 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeDataRefTest.hpp @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from data_ref_view.djinni + +#pragma once + +#include "DataRefTest.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +using NativeDataRefTest = djinni::swift::Interface<::testsuite::DataRefTest>; + +djinni::swift::AnyValue DataRefTest_sendData(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue DataRefTest_retriveAsBin(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue DataRefTest_sendMutableData(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue DataRefTest_generateData(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue DataRefTest_dataFromVec(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue DataRefTest_dataFromStr(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue DataRefTest_sendDataView(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue DataRefTest_recvDataView(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue DataRefTest_create(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeDateRecord.cpp b/test-suite/generated-src/swiftxx/NativeDateRecord.cpp new file mode 100644 index 00000000..19a309fc --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeDateRecord.cpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from date.djinni + +#include "NativeDateRecord.hpp" // my header +#include "djinni_support.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue NativeDateRecord::fromCpp(const ::testsuite::DateRecord& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::Date::fromCpp(c.created_at)); + return {ret}; +} +::testsuite::DateRecord NativeDateRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::DateRecord(::djinni::swift::Date::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeDateRecord.hpp b/test-suite/generated-src/swiftxx/NativeDateRecord.hpp new file mode 100644 index 00000000..532f41a5 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeDateRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from date.djinni + +#pragma once + +#include "date_record.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +struct NativeDateRecord { + using CppType = ::testsuite::DateRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeEmptyFlags.cpp b/test-suite/generated-src/swiftxx/NativeEmptyFlags.cpp new file mode 100644 index 00000000..ccfe6e65 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeEmptyFlags.cpp @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +#include "NativeEmptyFlags.hpp" // my header + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeEmptyFlags.hpp b/test-suite/generated-src/swiftxx/NativeEmptyFlags.hpp new file mode 100644 index 00000000..6d7ad9f3 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeEmptyFlags.hpp @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "empty_flags.hpp" + +namespace djinni_generated { + +using NativeEmptyFlags = djinni::swift::Enum<::testsuite::empty_flags>; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeEmptyRecord.cpp b/test-suite/generated-src/swiftxx/NativeEmptyRecord.cpp new file mode 100644 index 00000000..078a170f --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeEmptyRecord.cpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +#include "NativeEmptyRecord.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeEmptyRecord::fromCpp(const ::testsuite::EmptyRecord& c) { + auto ret = std::make_shared(); + return {ret}; +} +::testsuite::EmptyRecord NativeEmptyRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::EmptyRecord(); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeEmptyRecord.hpp b/test-suite/generated-src/swiftxx/NativeEmptyRecord.hpp new file mode 100644 index 00000000..9618dcaa --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeEmptyRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "empty_record.hpp" + +namespace djinni_generated { + +struct NativeEmptyRecord { + using CppType = ::testsuite::EmptyRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeEnumUsageInterface.cpp b/test-suite/generated-src/swiftxx/NativeEnumUsageInterface.cpp new file mode 100644 index 00000000..b9d977aa --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeEnumUsageInterface.cpp @@ -0,0 +1,55 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum.djinni + +#include "NativeEnumUsageInterface.hpp" // my header +#include "NativeColor.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue EnumUsageInterface_e(const djinni::swift::ParameterList* params) try { + auto inst = NativeEnumUsageInterface::toCpp(params->getValue(0)); + auto _e = ::djinni_generated::NativeColor::toCpp(params->getValue(1)); + auto ret = inst->e(std::move(_e)); + return ::djinni_generated::NativeColor::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue EnumUsageInterface_o(const djinni::swift::ParameterList* params) try { + auto inst = NativeEnumUsageInterface::toCpp(params->getValue(0)); + auto _o = ::djinni::swift::Optional::toCpp(params->getValue(1)); + auto ret = inst->o(std::move(_o)); + return ::djinni::swift::Optional::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue EnumUsageInterface_l(const djinni::swift::ParameterList* params) try { + auto inst = NativeEnumUsageInterface::toCpp(params->getValue(0)); + auto _l = ::djinni::swift::List<::djinni_generated::NativeColor>::toCpp(params->getValue(1)); + auto ret = inst->l(std::move(_l)); + return ::djinni::swift::List<::djinni_generated::NativeColor>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue EnumUsageInterface_s(const djinni::swift::ParameterList* params) try { + auto inst = NativeEnumUsageInterface::toCpp(params->getValue(0)); + auto _s = ::djinni::swift::Set<::djinni_generated::NativeColor>::toCpp(params->getValue(1)); + auto ret = inst->s(std::move(_s)); + return ::djinni::swift::Set<::djinni_generated::NativeColor>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue EnumUsageInterface_m(const djinni::swift::ParameterList* params) try { + auto inst = NativeEnumUsageInterface::toCpp(params->getValue(0)); + auto _m = ::djinni::swift::Map<::djinni_generated::NativeColor, ::djinni_generated::NativeColor>::toCpp(params->getValue(1)); + auto ret = inst->m(std::move(_m)); + return ::djinni::swift::Map<::djinni_generated::NativeColor, ::djinni_generated::NativeColor>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeEnumUsageInterface.hpp b/test-suite/generated-src/swiftxx/NativeEnumUsageInterface.hpp new file mode 100644 index 00000000..a867f7f5 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeEnumUsageInterface.hpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "enum_usage_interface.hpp" + +namespace djinni_generated { + +using NativeEnumUsageInterface = djinni::swift::Interface<::testsuite::EnumUsageInterface>; + +djinni::swift::AnyValue EnumUsageInterface_e(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue EnumUsageInterface_o(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue EnumUsageInterface_l(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue EnumUsageInterface_s(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue EnumUsageInterface_m(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeEnumUsageRecord.cpp b/test-suite/generated-src/swiftxx/NativeEnumUsageRecord.cpp new file mode 100644 index 00000000..210858d4 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeEnumUsageRecord.cpp @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum.djinni + +#include "NativeEnumUsageRecord.hpp" // my header +#include "NativeColor.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue NativeEnumUsageRecord::fromCpp(const ::testsuite::EnumUsageRecord& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni_generated::NativeColor::fromCpp(c.e)); + ret->addValue(::djinni::swift::Optional::fromCpp(c.o)); + ret->addValue(::djinni::swift::List<::djinni_generated::NativeColor>::fromCpp(c.l)); + ret->addValue(::djinni::swift::Set<::djinni_generated::NativeColor>::fromCpp(c.s)); + ret->addValue(::djinni::swift::Map<::djinni_generated::NativeColor, ::djinni_generated::NativeColor>::fromCpp(c.m)); + return {ret}; +} +::testsuite::EnumUsageRecord NativeEnumUsageRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::EnumUsageRecord(::djinni_generated::NativeColor::toCpp(p->getValue(0)), ::djinni::swift::Optional::toCpp(p->getValue(1)), ::djinni::swift::List<::djinni_generated::NativeColor>::toCpp(p->getValue(2)), ::djinni::swift::Set<::djinni_generated::NativeColor>::toCpp(p->getValue(3)), ::djinni::swift::Map<::djinni_generated::NativeColor, ::djinni_generated::NativeColor>::toCpp(p->getValue(4))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeEnumUsageRecord.hpp b/test-suite/generated-src/swiftxx/NativeEnumUsageRecord.hpp new file mode 100644 index 00000000..22bf667a --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeEnumUsageRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "enum_usage_record.hpp" + +namespace djinni_generated { + +struct NativeEnumUsageRecord { + using CppType = ::testsuite::EnumUsageRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeExtendedRecord.cpp b/test-suite/generated-src/swiftxx/NativeExtendedRecord.cpp new file mode 100644 index 00000000..944a2f5a --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeExtendedRecord.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from extended_record.djinni + +#include "NativeExtendedRecord.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeExtendedRecord::fromCpp(const ::testsuite::ExtendedRecord& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::Bool::fromCpp(c.foo)); + return {ret}; +} +::testsuite::ExtendedRecord NativeExtendedRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::ExtendedRecord(::djinni::swift::Bool::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeExtendedRecord.hpp b/test-suite/generated-src/swiftxx/NativeExtendedRecord.hpp new file mode 100644 index 00000000..dcf52c8d --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeExtendedRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from extended_record.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "extended_record.hpp" + +namespace djinni_generated { + +struct NativeExtendedRecord { + using CppType = ::testsuite::ExtendedRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeExternInterface1.cpp b/test-suite/generated-src/swiftxx/NativeExternInterface1.cpp new file mode 100644 index 00000000..562d1117 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeExternInterface1.cpp @@ -0,0 +1,30 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +#include "NativeExternInterface1.hpp" // my header +#include "NativeClientInterface.hpp" +#include "NativeClientReturnedRecord.hpp" +#include "NativeColor.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue ExternInterface1_foo(const djinni::swift::ParameterList* params) try { + auto inst = NativeExternInterface1::toCpp(params->getValue(0)); + auto _i = ::djinni_generated::NativeClientInterface::toCpp(params->getValue(1)); + auto ret = inst->foo(std::move(_i)); + return ::djinni_generated::NativeClientReturnedRecord::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ExternInterface1_bar(const djinni::swift::ParameterList* params) try { + auto inst = NativeExternInterface1::toCpp(params->getValue(0)); + auto _e = ::djinni_generated::NativeColor::toCpp(params->getValue(1)); + auto ret = inst->bar(std::move(_e)); + return ::djinni_generated::NativeColor::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeExternInterface1.hpp b/test-suite/generated-src/swiftxx/NativeExternInterface1.hpp new file mode 100644 index 00000000..6e28e238 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeExternInterface1.hpp @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "extern_interface_1.hpp" + +namespace djinni_generated { + +using NativeExternInterface1 = djinni::swift::Interface<::ExternInterface1>; + +djinni::swift::AnyValue ExternInterface1_foo(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ExternInterface1_bar(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeExternInterface2.cpp b/test-suite/generated-src/swiftxx/NativeExternInterface2.cpp new file mode 100644 index 00000000..f3f3c7e1 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeExternInterface2.cpp @@ -0,0 +1,11 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +#include "NativeExternInterface2.hpp" // my header +#include "NativeExternRecordWithDerivings.hpp" +#include "NativeTestHelpers.hpp" + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeExternInterface2.hpp b/test-suite/generated-src/swiftxx/NativeExternInterface2.hpp new file mode 100644 index 00000000..e6aae2ca --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeExternInterface2.hpp @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "extern_interface_2.hpp" + +namespace djinni_generated { + +using NativeExternInterface2 = djinni::swift::Interface<::ExternInterface2>; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeExternRecordWithDerivings.cpp b/test-suite/generated-src/swiftxx/NativeExternRecordWithDerivings.cpp new file mode 100644 index 00000000..3c6be11c --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeExternRecordWithDerivings.cpp @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +#include "NativeExternRecordWithDerivings.hpp" // my header +#include "NativeColor.hpp" +#include "NativeRecordWithDerivings.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue NativeExternRecordWithDerivings::fromCpp(const ::ExternRecordWithDerivings& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni_generated::NativeRecordWithDerivings::fromCpp(c.member)); + ret->addValue(::djinni_generated::NativeColor::fromCpp(c.e)); + return {ret}; +} +::ExternRecordWithDerivings NativeExternRecordWithDerivings::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::ExternRecordWithDerivings(::djinni_generated::NativeRecordWithDerivings::toCpp(p->getValue(0)), ::djinni_generated::NativeColor::toCpp(p->getValue(1))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeExternRecordWithDerivings.hpp b/test-suite/generated-src/swiftxx/NativeExternRecordWithDerivings.hpp new file mode 100644 index 00000000..b63e4335 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeExternRecordWithDerivings.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "extern_record_with_derivings.hpp" + +namespace djinni_generated { + +struct NativeExternRecordWithDerivings { + using CppType = ::ExternRecordWithDerivings; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeFirstListener.cpp b/test-suite/generated-src/swiftxx/NativeFirstListener.cpp new file mode 100644 index 00000000..93da14e3 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeFirstListener.cpp @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +#include "NativeFirstListener.hpp" // my header + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeFirstListener.hpp b/test-suite/generated-src/swiftxx/NativeFirstListener.hpp new file mode 100644 index 00000000..be86e01a --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeFirstListener.hpp @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "first_listener.hpp" + +namespace djinni_generated { + +using NativeFirstListener = djinni::swift::Interface<::testsuite::FirstListener>; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeFlagRoundtrip.cpp b/test-suite/generated-src/swiftxx/NativeFlagRoundtrip.cpp new file mode 100644 index 00000000..93e804ee --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeFlagRoundtrip.cpp @@ -0,0 +1,43 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +#include "NativeFlagRoundtrip.hpp" // my header +#include "NativeAccessFlags.hpp" +#include "NativeEmptyFlags.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue FlagRoundtrip_roundtripAccess(const djinni::swift::ParameterList* params) try { + auto _flag = ::djinni_generated::NativeAccessFlags::toCpp(params->getValue(0)); + auto ret = ::testsuite::FlagRoundtrip::roundtrip_access(std::move(_flag)); + return ::djinni_generated::NativeAccessFlags::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue FlagRoundtrip_roundtripEmpty(const djinni::swift::ParameterList* params) try { + auto _flag = ::djinni_generated::NativeEmptyFlags::toCpp(params->getValue(0)); + auto ret = ::testsuite::FlagRoundtrip::roundtrip_empty(std::move(_flag)); + return ::djinni_generated::NativeEmptyFlags::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue FlagRoundtrip_roundtripAccessBoxed(const djinni::swift::ParameterList* params) try { + auto _flag = ::djinni::swift::Optional::toCpp(params->getValue(0)); + auto ret = ::testsuite::FlagRoundtrip::roundtrip_access_boxed(std::move(_flag)); + return ::djinni::swift::Optional::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue FlagRoundtrip_roundtripEmptyBoxed(const djinni::swift::ParameterList* params) try { + auto _flag = ::djinni::swift::Optional::toCpp(params->getValue(0)); + auto ret = ::testsuite::FlagRoundtrip::roundtrip_empty_boxed(std::move(_flag)); + return ::djinni::swift::Optional::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeFlagRoundtrip.hpp b/test-suite/generated-src/swiftxx/NativeFlagRoundtrip.hpp new file mode 100644 index 00000000..f2efa6d1 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeFlagRoundtrip.hpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "flag_roundtrip.hpp" + +namespace djinni_generated { + +using NativeFlagRoundtrip = djinni::swift::Interface<::testsuite::FlagRoundtrip>; + +djinni::swift::AnyValue FlagRoundtrip_roundtripAccess(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue FlagRoundtrip_roundtripEmpty(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue FlagRoundtrip_roundtripAccessBoxed(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue FlagRoundtrip_roundtripEmptyBoxed(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeInterfaceUsingExtendedRecord.cpp b/test-suite/generated-src/swiftxx/NativeInterfaceUsingExtendedRecord.cpp new file mode 100644 index 00000000..ddc88a16 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeInterfaceUsingExtendedRecord.cpp @@ -0,0 +1,20 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from extended_record.djinni + +#include "NativeInterfaceUsingExtendedRecord.hpp" // my header +#include "NativeExtendedRecord.hpp" +#include "NativeRecordUsingExtendedRecord.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue InterfaceUsingExtendedRecord_meth(const djinni::swift::ParameterList* params) try { + auto inst = NativeInterfaceUsingExtendedRecord::toCpp(params->getValue(0)); + auto _er = ::djinni_generated::NativeExtendedRecord::toCpp(params->getValue(1)); + auto ret = inst->meth(std::move(_er)); + return ::djinni_generated::NativeExtendedRecord::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeInterfaceUsingExtendedRecord.hpp b/test-suite/generated-src/swiftxx/NativeInterfaceUsingExtendedRecord.hpp new file mode 100644 index 00000000..0c471b70 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeInterfaceUsingExtendedRecord.hpp @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from extended_record.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "interface_using_extended_record.hpp" + +namespace djinni_generated { + +using NativeInterfaceUsingExtendedRecord = djinni::swift::Interface<::testsuite::InterfaceUsingExtendedRecord>; + +djinni::swift::AnyValue InterfaceUsingExtendedRecord_meth(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeJavaOnlyListener.cpp b/test-suite/generated-src/swiftxx/NativeJavaOnlyListener.cpp new file mode 100644 index 00000000..d7cd1a81 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeJavaOnlyListener.cpp @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from single_language_interfaces.djinni + +#include "NativeJavaOnlyListener.hpp" // my header + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeJavaOnlyListener.hpp b/test-suite/generated-src/swiftxx/NativeJavaOnlyListener.hpp new file mode 100644 index 00000000..6e3d9c84 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeJavaOnlyListener.hpp @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from single_language_interfaces.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "java_only_listener.hpp" + +namespace djinni_generated { + +using NativeJavaOnlyListener = djinni::swift::Interface<::testsuite::JavaOnlyListener>; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeListenerCaller.cpp b/test-suite/generated-src/swiftxx/NativeListenerCaller.cpp new file mode 100644 index 00000000..29791044 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeListenerCaller.cpp @@ -0,0 +1,36 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +#include "NativeListenerCaller.hpp" // my header +#include "NativeFirstListener.hpp" +#include "NativeSecondListener.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue ListenerCaller_init(const djinni::swift::ParameterList* params) try { + auto _first_l = ::djinni_generated::NativeFirstListener::toCpp(params->getValue(0)); + auto _second_l = ::djinni_generated::NativeSecondListener::toCpp(params->getValue(1)); + auto ret = ::testsuite::ListenerCaller::init(std::move(_first_l), std::move(_second_l)); + return ::djinni_generated::NativeListenerCaller::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ListenerCaller_callFirst(const djinni::swift::ParameterList* params) try { + auto inst = NativeListenerCaller::toCpp(params->getValue(0)); + inst->callFirst(); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ListenerCaller_callSecond(const djinni::swift::ParameterList* params) try { + auto inst = NativeListenerCaller::toCpp(params->getValue(0)); + inst->callSecond(); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeListenerCaller.hpp b/test-suite/generated-src/swiftxx/NativeListenerCaller.hpp new file mode 100644 index 00000000..7aae8648 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeListenerCaller.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "listener_caller.hpp" + +namespace djinni_generated { + +using NativeListenerCaller = djinni::swift::Interface<::testsuite::ListenerCaller>; + +djinni::swift::AnyValue ListenerCaller_init(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ListenerCaller_callFirst(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ListenerCaller_callSecond(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeMapDateRecord.cpp b/test-suite/generated-src/swiftxx/NativeMapDateRecord.cpp new file mode 100644 index 00000000..19bbc195 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeMapDateRecord.cpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from date.djinni + +#include "NativeMapDateRecord.hpp" // my header +#include "djinni_support.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue NativeMapDateRecord::fromCpp(const ::testsuite::MapDateRecord& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::Map<::djinni::swift::String, ::djinni::swift::Date>::fromCpp(c.dates_by_id)); + return {ret}; +} +::testsuite::MapDateRecord NativeMapDateRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::MapDateRecord(::djinni::swift::Map<::djinni::swift::String, ::djinni::swift::Date>::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeMapDateRecord.hpp b/test-suite/generated-src/swiftxx/NativeMapDateRecord.hpp new file mode 100644 index 00000000..c0a2f61e --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeMapDateRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from date.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "map_date_record.hpp" + +namespace djinni_generated { + +struct NativeMapDateRecord { + using CppType = ::testsuite::MapDateRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeMapListRecord.cpp b/test-suite/generated-src/swiftxx/NativeMapListRecord.cpp new file mode 100644 index 00000000..b030bbb1 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeMapListRecord.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from map.djinni + +#include "NativeMapListRecord.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeMapListRecord::fromCpp(const ::testsuite::MapListRecord& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::List<::djinni::swift::Map<::djinni::swift::String, ::djinni::swift::I64>>::fromCpp(c.map_list)); + return {ret}; +} +::testsuite::MapListRecord NativeMapListRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::MapListRecord(::djinni::swift::List<::djinni::swift::Map<::djinni::swift::String, ::djinni::swift::I64>>::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeMapListRecord.hpp b/test-suite/generated-src/swiftxx/NativeMapListRecord.hpp new file mode 100644 index 00000000..aae4733e --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeMapListRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from map.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "map_list_record.hpp" + +namespace djinni_generated { + +struct NativeMapListRecord { + using CppType = ::testsuite::MapListRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeMapRecord.cpp b/test-suite/generated-src/swiftxx/NativeMapRecord.cpp new file mode 100644 index 00000000..da9e8b51 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeMapRecord.cpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from map.djinni + +#include "NativeMapRecord.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeMapRecord::fromCpp(const ::testsuite::MapRecord& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::Map<::djinni::swift::String, ::djinni::swift::I64>::fromCpp(c.map)); + ret->addValue(::djinni::swift::Map<::djinni::swift::I32, ::djinni::swift::I32>::fromCpp(c.imap)); + return {ret}; +} +::testsuite::MapRecord NativeMapRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::MapRecord(::djinni::swift::Map<::djinni::swift::String, ::djinni::swift::I64>::toCpp(p->getValue(0)), ::djinni::swift::Map<::djinni::swift::I32, ::djinni::swift::I32>::toCpp(p->getValue(1))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeMapRecord.hpp b/test-suite/generated-src/swiftxx/NativeMapRecord.hpp new file mode 100644 index 00000000..30d367ce --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeMapRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from map.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "map_record.hpp" + +namespace djinni_generated { + +struct NativeMapRecord { + using CppType = ::testsuite::MapRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeNestedCollection.cpp b/test-suite/generated-src/swiftxx/NativeNestedCollection.cpp new file mode 100644 index 00000000..e74a2857 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeNestedCollection.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from nested_collection.djinni + +#include "NativeNestedCollection.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeNestedCollection::fromCpp(const ::testsuite::NestedCollection& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::List<::djinni::swift::Set<::djinni::swift::String>>::fromCpp(c.set_list)); + return {ret}; +} +::testsuite::NestedCollection NativeNestedCollection::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::NestedCollection(::djinni::swift::List<::djinni::swift::Set<::djinni::swift::String>>::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeNestedCollection.hpp b/test-suite/generated-src/swiftxx/NativeNestedCollection.hpp new file mode 100644 index 00000000..49c62b94 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeNestedCollection.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from nested_collection.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "nested_collection.hpp" + +namespace djinni_generated { + +struct NativeNestedCollection { + using CppType = ::testsuite::NestedCollection; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeNestedOutcome.cpp b/test-suite/generated-src/swiftxx/NativeNestedOutcome.cpp new file mode 100644 index 00000000..23d422ed --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeNestedOutcome.cpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from outcome.djinni + +#include "NativeNestedOutcome.hpp" // my header +#include "Outcome_swift.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue NativeNestedOutcome::fromCpp(const ::testsuite::NestedOutcome& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::OutcomeAdaptor<::djinni::swift::I32, ::djinni::swift::String>::fromCpp(c.o)); + return {ret}; +} +::testsuite::NestedOutcome NativeNestedOutcome::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::NestedOutcome(::djinni::swift::OutcomeAdaptor<::djinni::swift::I32, ::djinni::swift::String>::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeNestedOutcome.hpp b/test-suite/generated-src/swiftxx/NativeNestedOutcome.hpp new file mode 100644 index 00000000..599607fd --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeNestedOutcome.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from outcome.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "nested_outcome.hpp" + +namespace djinni_generated { + +struct NativeNestedOutcome { + using CppType = ::testsuite::NestedOutcome; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeObjcOnlyListener.cpp b/test-suite/generated-src/swiftxx/NativeObjcOnlyListener.cpp new file mode 100644 index 00000000..f0d60b83 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeObjcOnlyListener.cpp @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from single_language_interfaces.djinni + +#include "NativeObjcOnlyListener.hpp" // my header + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeObjcOnlyListener.hpp b/test-suite/generated-src/swiftxx/NativeObjcOnlyListener.hpp new file mode 100644 index 00000000..7451ea8b --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeObjcOnlyListener.hpp @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from single_language_interfaces.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "objc_only_listener.hpp" + +namespace djinni_generated { + +using NativeObjcOnlyListener = djinni::swift::Interface<::testsuite::ObjcOnlyListener>; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativePrimitiveList.cpp b/test-suite/generated-src/swiftxx/NativePrimitiveList.cpp new file mode 100644 index 00000000..e5589e2e --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativePrimitiveList.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from primitive_list.djinni + +#include "NativePrimitiveList.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativePrimitiveList::fromCpp(const ::testsuite::PrimitiveList& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::List<::djinni::swift::I64>::fromCpp(c.list)); + return {ret}; +} +::testsuite::PrimitiveList NativePrimitiveList::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::PrimitiveList(::djinni::swift::List<::djinni::swift::I64>::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativePrimitiveList.hpp b/test-suite/generated-src/swiftxx/NativePrimitiveList.hpp new file mode 100644 index 00000000..51fbc07e --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativePrimitiveList.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from primitive_list.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "primitive_list.hpp" + +namespace djinni_generated { + +struct NativePrimitiveList { + using CppType = ::testsuite::PrimitiveList; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeProtoTests.cpp b/test-suite/generated-src/swiftxx/NativeProtoTests.cpp new file mode 100644 index 00000000..fc18b43c --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeProtoTests.cpp @@ -0,0 +1,116 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from proto.djinni + +#include "NativeProtoTests.hpp" // my header +#include "NativeRecordWithEmbeddedCppProto.hpp" +#include "NativeRecordWithEmbeddedProto.hpp" +#include "Outcome_swift.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue ProtoTests_protoToStrings(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::Protobuf<::djinni::test::AddressBook>::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::protoToStrings(std::move(_x)); + return ::djinni::swift::List<::djinni::swift::String>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ProtoTests_stringsToProto(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::List<::djinni::swift::String>::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::stringsToProto(std::move(_x)); + return ::djinni::swift::Protobuf<::djinni::test::AddressBook>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ProtoTests_embeddedProtoToString(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni_generated::NativeRecordWithEmbeddedProto::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::embeddedProtoToString(std::move(_x)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ProtoTests_stringToEmbeddedProto(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::String::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::stringToEmbeddedProto(std::move(_x)); + return ::djinni_generated::NativeRecordWithEmbeddedProto::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ProtoTests_cppProtoToString(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::Protobuf<::djinni::test2::PersistingState>::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::cppProtoToString(std::move(_x)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ProtoTests_stringToCppProto(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::String::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::stringToCppProto(std::move(_x)); + return ::djinni::swift::Protobuf<::djinni::test2::PersistingState>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ProtoTests_embeddedCppProtoToString(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni_generated::NativeRecordWithEmbeddedCppProto::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::embeddedCppProtoToString(std::move(_x)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ProtoTests_stringToEmbeddedCppProto(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::String::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::stringToEmbeddedCppProto(std::move(_x)); + return ::djinni_generated::NativeRecordWithEmbeddedCppProto::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ProtoTests_protoListToStrings(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::List<::djinni::swift::Protobuf<::djinni::test::Person>>::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::protoListToStrings(std::move(_x)); + return ::djinni::swift::List<::djinni::swift::String>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ProtoTests_stringsToProtoList(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::List<::djinni::swift::String>::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::stringsToProtoList(std::move(_x)); + return ::djinni::swift::List<::djinni::swift::Protobuf<::djinni::test::Person>>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ProtoTests_optionalProtoToString(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::Optional>::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::optionalProtoToString(std::move(_x)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ProtoTests_stringToOptionalProto(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::String::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::stringToOptionalProto(std::move(_x)); + return ::djinni::swift::Optional>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ProtoTests_stringToProtoOutcome(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::String::toCpp(params->getValue(0)); + auto ret = ::testsuite::ProtoTests::stringToProtoOutcome(std::move(_x)); + return ::djinni::swift::OutcomeAdaptor<::djinni::swift::Protobuf<::djinni::test::Person>, ::djinni::swift::I32>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeProtoTests.hpp b/test-suite/generated-src/swiftxx/NativeProtoTests.hpp new file mode 100644 index 00000000..aa367b70 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeProtoTests.hpp @@ -0,0 +1,27 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from proto.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "proto_tests.hpp" + +namespace djinni_generated { + +using NativeProtoTests = djinni::swift::Interface<::testsuite::ProtoTests>; + +djinni::swift::AnyValue ProtoTests_protoToStrings(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ProtoTests_stringsToProto(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ProtoTests_embeddedProtoToString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ProtoTests_stringToEmbeddedProto(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ProtoTests_cppProtoToString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ProtoTests_stringToCppProto(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ProtoTests_embeddedCppProtoToString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ProtoTests_stringToEmbeddedCppProto(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ProtoTests_protoListToStrings(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ProtoTests_stringsToProtoList(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ProtoTests_optionalProtoToString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ProtoTests_stringToOptionalProto(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ProtoTests_stringToProtoOutcome(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordUsingExtendedRecord.cpp b/test-suite/generated-src/swiftxx/NativeRecordUsingExtendedRecord.cpp new file mode 100644 index 00000000..aaab3167 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordUsingExtendedRecord.cpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from extended_record.djinni + +#include "NativeRecordUsingExtendedRecord.hpp" // my header +#include "NativeExtendedRecord.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue NativeRecordUsingExtendedRecord::fromCpp(const ::testsuite::RecordUsingExtendedRecord& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni_generated::NativeExtendedRecord::fromCpp(c.er)); + return {ret}; +} +::testsuite::RecordUsingExtendedRecord NativeRecordUsingExtendedRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::RecordUsingExtendedRecord(::djinni_generated::NativeExtendedRecord::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordUsingExtendedRecord.hpp b/test-suite/generated-src/swiftxx/NativeRecordUsingExtendedRecord.hpp new file mode 100644 index 00000000..fad64294 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordUsingExtendedRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from extended_record.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "record_using_extended_record.hpp" + +namespace djinni_generated { + +struct NativeRecordUsingExtendedRecord { + using CppType = ::testsuite::RecordUsingExtendedRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordWithDerivings.cpp b/test-suite/generated-src/swiftxx/NativeRecordWithDerivings.cpp new file mode 100644 index 00000000..9abee253 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordWithDerivings.cpp @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from derivings.djinni + +#include "NativeRecordWithDerivings.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeRecordWithDerivings::fromCpp(const ::testsuite::RecordWithDerivings& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::I8::fromCpp(c.eight)); + ret->addValue(::djinni::swift::I16::fromCpp(c.sixteen)); + ret->addValue(::djinni::swift::I32::fromCpp(c.thirtytwo)); + ret->addValue(::djinni::swift::I64::fromCpp(c.sixtyfour)); + ret->addValue(::djinni::swift::F32::fromCpp(c.fthirtytwo)); + ret->addValue(::djinni::swift::F64::fromCpp(c.fsixtyfour)); + ret->addValue(::djinni::swift::Date::fromCpp(c.d)); + ret->addValue(::djinni::swift::String::fromCpp(c.s)); + return {ret}; +} +::testsuite::RecordWithDerivings NativeRecordWithDerivings::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::RecordWithDerivings(::djinni::swift::I8::toCpp(p->getValue(0)), ::djinni::swift::I16::toCpp(p->getValue(1)), ::djinni::swift::I32::toCpp(p->getValue(2)), ::djinni::swift::I64::toCpp(p->getValue(3)), ::djinni::swift::F32::toCpp(p->getValue(4)), ::djinni::swift::F64::toCpp(p->getValue(5)), ::djinni::swift::Date::toCpp(p->getValue(6)), ::djinni::swift::String::toCpp(p->getValue(7))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordWithDerivings.hpp b/test-suite/generated-src/swiftxx/NativeRecordWithDerivings.hpp new file mode 100644 index 00000000..48758ab2 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordWithDerivings.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from derivings.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "record_with_derivings.hpp" + +namespace djinni_generated { + +struct NativeRecordWithDerivings { + using CppType = ::testsuite::RecordWithDerivings; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordWithDurationAndDerivings.cpp b/test-suite/generated-src/swiftxx/NativeRecordWithDurationAndDerivings.cpp new file mode 100644 index 00000000..7d240c3a --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordWithDurationAndDerivings.cpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from duration.djinni + +#include "NativeRecordWithDurationAndDerivings.hpp" // my header +#include "Duration-swift.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue NativeRecordWithDurationAndDerivings::fromCpp(const ::testsuite::RecordWithDurationAndDerivings& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::Duration<::djinni::swift::F64, ::djinni::swift::Duration_ns>::fromCpp(c.dt)); + return {ret}; +} +::testsuite::RecordWithDurationAndDerivings NativeRecordWithDurationAndDerivings::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::RecordWithDurationAndDerivings(::djinni::swift::Duration<::djinni::swift::F64, ::djinni::swift::Duration_ns>::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordWithDurationAndDerivings.hpp b/test-suite/generated-src/swiftxx/NativeRecordWithDurationAndDerivings.hpp new file mode 100644 index 00000000..d0d25277 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordWithDurationAndDerivings.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from duration.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "record_with_duration_and_derivings.hpp" + +namespace djinni_generated { + +struct NativeRecordWithDurationAndDerivings { + using CppType = ::testsuite::RecordWithDurationAndDerivings; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedCppProto.cpp b/test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedCppProto.cpp new file mode 100644 index 00000000..c11629fd --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedCppProto.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from proto.djinni + +#include "NativeRecordWithEmbeddedCppProto.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeRecordWithEmbeddedCppProto::fromCpp(const ::testsuite::RecordWithEmbeddedCppProto& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::Protobuf<::djinni::test2::PersistingState>::fromCpp(c.state)); + return {ret}; +} +::testsuite::RecordWithEmbeddedCppProto NativeRecordWithEmbeddedCppProto::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::RecordWithEmbeddedCppProto(::djinni::swift::Protobuf<::djinni::test2::PersistingState>::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedCppProto.hpp b/test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedCppProto.hpp new file mode 100644 index 00000000..fc5b0258 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedCppProto.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from proto.djinni + +#pragma once + +#include "RecordWithEmbeddedCppProto.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +struct NativeRecordWithEmbeddedCppProto { + using CppType = ::testsuite::RecordWithEmbeddedCppProto; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedProto.cpp b/test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedProto.cpp new file mode 100644 index 00000000..bcc88f01 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedProto.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from proto.djinni + +#include "NativeRecordWithEmbeddedProto.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeRecordWithEmbeddedProto::fromCpp(const ::testsuite::RecordWithEmbeddedProto& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::Protobuf<::djinni::test::Person>::fromCpp(c.person)); + return {ret}; +} +::testsuite::RecordWithEmbeddedProto NativeRecordWithEmbeddedProto::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::RecordWithEmbeddedProto(::djinni::swift::Protobuf<::djinni::test::Person>::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedProto.hpp b/test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedProto.hpp new file mode 100644 index 00000000..ec566a3b --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordWithEmbeddedProto.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from proto.djinni + +#pragma once + +#include "RecordWithEmbeddedProto.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +struct NativeRecordWithEmbeddedProto { + using CppType = ::testsuite::RecordWithEmbeddedProto; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordWithFlags.cpp b/test-suite/generated-src/swiftxx/NativeRecordWithFlags.cpp new file mode 100644 index 00000000..f70436f2 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordWithFlags.cpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +#include "NativeRecordWithFlags.hpp" // my header +#include "NativeAccessFlags.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue NativeRecordWithFlags::fromCpp(const ::testsuite::RecordWithFlags& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni_generated::NativeAccessFlags::fromCpp(c.access)); + return {ret}; +} +::testsuite::RecordWithFlags NativeRecordWithFlags::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::RecordWithFlags(::djinni_generated::NativeAccessFlags::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordWithFlags.hpp b/test-suite/generated-src/swiftxx/NativeRecordWithFlags.hpp new file mode 100644 index 00000000..0704eb39 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordWithFlags.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from enum_flags.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "record_with_flags.hpp" + +namespace djinni_generated { + +struct NativeRecordWithFlags { + using CppType = ::testsuite::RecordWithFlags; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordWithNestedDerivings.cpp b/test-suite/generated-src/swiftxx/NativeRecordWithNestedDerivings.cpp new file mode 100644 index 00000000..4831b4a2 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordWithNestedDerivings.cpp @@ -0,0 +1,20 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from derivings.djinni + +#include "NativeRecordWithNestedDerivings.hpp" // my header +#include "NativeRecordWithDerivings.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue NativeRecordWithNestedDerivings::fromCpp(const ::testsuite::RecordWithNestedDerivings& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::I32::fromCpp(c.key)); + ret->addValue(::djinni_generated::NativeRecordWithDerivings::fromCpp(c.rec)); + return {ret}; +} +::testsuite::RecordWithNestedDerivings NativeRecordWithNestedDerivings::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::RecordWithNestedDerivings(::djinni::swift::I32::toCpp(p->getValue(0)), ::djinni_generated::NativeRecordWithDerivings::toCpp(p->getValue(1))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeRecordWithNestedDerivings.hpp b/test-suite/generated-src/swiftxx/NativeRecordWithNestedDerivings.hpp new file mode 100644 index 00000000..0e46f59a --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeRecordWithNestedDerivings.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from derivings.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "record_with_nested_derivings.hpp" + +namespace djinni_generated { + +struct NativeRecordWithNestedDerivings { + using CppType = ::testsuite::RecordWithNestedDerivings; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeReturnOne.cpp b/test-suite/generated-src/swiftxx/NativeReturnOne.cpp new file mode 100644 index 00000000..52704a89 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeReturnOne.cpp @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +#include "NativeReturnOne.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue ReturnOne_getInstance(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::ReturnOne::get_instance(); + return ::djinni_generated::NativeReturnOne::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ReturnOne_returnOne(const djinni::swift::ParameterList* params) try { + auto inst = NativeReturnOne::toCpp(params->getValue(0)); + auto ret = inst->return_one(); + return ::djinni::swift::I8::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeReturnOne.hpp b/test-suite/generated-src/swiftxx/NativeReturnOne.hpp new file mode 100644 index 00000000..6ee3f1c2 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeReturnOne.hpp @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "return_one.hpp" + +namespace djinni_generated { + +using NativeReturnOne = djinni::swift::Interface<::testsuite::ReturnOne>; + +djinni::swift::AnyValue ReturnOne_getInstance(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ReturnOne_returnOne(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeReturnTwo.cpp b/test-suite/generated-src/swiftxx/NativeReturnTwo.cpp new file mode 100644 index 00000000..4aefd0fb --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeReturnTwo.cpp @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +#include "NativeReturnTwo.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue ReturnTwo_getInstance(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::ReturnTwo::get_instance(); + return ::djinni_generated::NativeReturnTwo::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ReturnTwo_returnTwo(const djinni::swift::ParameterList* params) try { + auto inst = NativeReturnTwo::toCpp(params->getValue(0)); + auto ret = inst->return_two(); + return ::djinni::swift::I8::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeReturnTwo.hpp b/test-suite/generated-src/swiftxx/NativeReturnTwo.hpp new file mode 100644 index 00000000..ce40ec02 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeReturnTwo.hpp @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "return_two.hpp" + +namespace djinni_generated { + +using NativeReturnTwo = djinni::swift::Interface<::testsuite::ReturnTwo>; + +djinni::swift::AnyValue ReturnTwo_getInstance(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ReturnTwo_returnTwo(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeReverseClientInterface.cpp b/test-suite/generated-src/swiftxx/NativeReverseClientInterface.cpp new file mode 100644 index 00000000..fc5ef420 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeReverseClientInterface.cpp @@ -0,0 +1,42 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from client_interface.djinni + +#include "NativeReverseClientInterface.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue ReverseClientInterface_returnStr(const djinni::swift::ParameterList* params) try { + auto inst = NativeReverseClientInterface::toCpp(params->getValue(0)); + auto ret = inst->return_str(); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ReverseClientInterface_methTakingInterface(const djinni::swift::ParameterList* params) try { + auto inst = NativeReverseClientInterface::toCpp(params->getValue(0)); + auto _i = ::djinni_generated::NativeReverseClientInterface::toCpp(params->getValue(1)); + auto ret = inst->meth_taking_interface(std::move(_i)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ReverseClientInterface_methTakingOptionalInterface(const djinni::swift::ParameterList* params) try { + auto inst = NativeReverseClientInterface::toCpp(params->getValue(0)); + auto _i = ::djinni::swift::Optional::toCpp(params->getValue(1)); + auto ret = inst->meth_taking_optional_interface(std::move(_i)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue ReverseClientInterface_create(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::ReverseClientInterface::create(); + return ::djinni_generated::NativeReverseClientInterface::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeReverseClientInterface.hpp b/test-suite/generated-src/swiftxx/NativeReverseClientInterface.hpp new file mode 100644 index 00000000..efd5ee80 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeReverseClientInterface.hpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from client_interface.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "reverse_client_interface.hpp" + +namespace djinni_generated { + +using NativeReverseClientInterface = djinni::swift::Interface<::testsuite::ReverseClientInterface>; + +djinni::swift::AnyValue ReverseClientInterface_returnStr(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ReverseClientInterface_methTakingInterface(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ReverseClientInterface_methTakingOptionalInterface(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue ReverseClientInterface_create(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeSampleInterface.cpp b/test-suite/generated-src/swiftxx/NativeSampleInterface.cpp new file mode 100644 index 00000000..99fdef12 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeSampleInterface.cpp @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +#include "NativeSampleInterface.hpp" // my header + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeSampleInterface.hpp b/test-suite/generated-src/swiftxx/NativeSampleInterface.hpp new file mode 100644 index 00000000..465c4546 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeSampleInterface.hpp @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "sample_interface.hpp" + +namespace djinni_generated { + +using NativeSampleInterface = djinni::swift::Interface<::testsuite::SampleInterface>; + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeSecondListener.cpp b/test-suite/generated-src/swiftxx/NativeSecondListener.cpp new file mode 100644 index 00000000..0051eaf0 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeSecondListener.cpp @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +#include "NativeSecondListener.hpp" // my header + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeSecondListener.hpp b/test-suite/generated-src/swiftxx/NativeSecondListener.hpp new file mode 100644 index 00000000..5196abe2 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeSecondListener.hpp @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from multiple_inheritance.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "second_listener.hpp" + +namespace djinni_generated { + +using NativeSecondListener = djinni::swift::Interface<::testsuite::SecondListener>; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeSetRecord.cpp b/test-suite/generated-src/swiftxx/NativeSetRecord.cpp new file mode 100644 index 00000000..e87fd039 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeSetRecord.cpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from set.djinni + +#include "NativeSetRecord.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeSetRecord::fromCpp(const ::testsuite::SetRecord& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::Set<::djinni::swift::String>::fromCpp(c.set)); + ret->addValue(::djinni::swift::Set<::djinni::swift::I32>::fromCpp(c.iset)); + return {ret}; +} +::testsuite::SetRecord NativeSetRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::SetRecord(::djinni::swift::Set<::djinni::swift::String>::toCpp(p->getValue(0)), ::djinni::swift::Set<::djinni::swift::I32>::toCpp(p->getValue(1))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeSetRecord.hpp b/test-suite/generated-src/swiftxx/NativeSetRecord.hpp new file mode 100644 index 00000000..02722b52 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeSetRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from set.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "set_record.hpp" + +namespace djinni_generated { + +struct NativeSetRecord { + using CppType = ::testsuite::SetRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeSupportCopying.cpp b/test-suite/generated-src/swiftxx/NativeSupportCopying.cpp new file mode 100644 index 00000000..31100727 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeSupportCopying.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from nscopying.djinni + +#include "NativeSupportCopying.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeSupportCopying::fromCpp(const ::testsuite::SupportCopying& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::I32::fromCpp(c.x)); + return {ret}; +} +::testsuite::SupportCopying NativeSupportCopying::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::SupportCopying(::djinni::swift::I32::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeSupportCopying.hpp b/test-suite/generated-src/swiftxx/NativeSupportCopying.hpp new file mode 100644 index 00000000..32b191b1 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeSupportCopying.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from nscopying.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "support_copying.hpp" + +namespace djinni_generated { + +struct NativeSupportCopying { + using CppType = ::testsuite::SupportCopying; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeTestArray.cpp b/test-suite/generated-src/swiftxx/NativeTestArray.cpp new file mode 100644 index 00000000..ec0cad39 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeTestArray.cpp @@ -0,0 +1,42 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from array.djinni + +#include "NativeTestArray.hpp" // my header +#include "NativeVec2.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue TestArray_testStringArray(const djinni::swift::ParameterList* params) try { + auto _a = ::djinni::swift::Array<::djinni::swift::String>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestArray::testStringArray(std::move(_a)); + return ::djinni::swift::Array<::djinni::swift::String>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestArray_testIntArray(const djinni::swift::ParameterList* params) try { + auto _a = ::djinni::swift::Array<::djinni::swift::I32>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestArray::testIntArray(std::move(_a)); + return ::djinni::swift::Array<::djinni::swift::I32>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestArray_testRecordArray(const djinni::swift::ParameterList* params) try { + auto _a = ::djinni::swift::Array<::djinni_generated::NativeVec2>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestArray::testRecordArray(std::move(_a)); + return ::djinni::swift::Array<::djinni_generated::NativeVec2>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestArray_testArrayOfArray(const djinni::swift::ParameterList* params) try { + auto _a = ::djinni::swift::Array<::djinni::swift::Array<::djinni::swift::I32>>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestArray::testArrayOfArray(std::move(_a)); + return ::djinni::swift::Array<::djinni::swift::Array<::djinni::swift::I32>>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeTestArray.hpp b/test-suite/generated-src/swiftxx/NativeTestArray.hpp new file mode 100644 index 00000000..3c3c9c92 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeTestArray.hpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from array.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "test_array.hpp" + +namespace djinni_generated { + +using NativeTestArray = djinni::swift::Interface<::testsuite::TestArray>; + +djinni::swift::AnyValue TestArray_testStringArray(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestArray_testIntArray(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestArray_testRecordArray(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestArray_testArrayOfArray(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeTestDuration.cpp b/test-suite/generated-src/swiftxx/NativeTestDuration.cpp new file mode 100644 index 00000000..6927a899 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeTestDuration.cpp @@ -0,0 +1,170 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from duration.djinni + +#include "NativeTestDuration.hpp" // my header +#include "Duration-swift.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue TestDuration_hoursString(const djinni::swift::ParameterList* params) try { + auto _dt = ::djinni::swift::Duration<::djinni::swift::I32, ::djinni::swift::Duration_h>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::hoursString(std::move(_dt)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_minutesString(const djinni::swift::ParameterList* params) try { + auto _dt = ::djinni::swift::Duration<::djinni::swift::I32, ::djinni::swift::Duration_min>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::minutesString(std::move(_dt)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_secondsString(const djinni::swift::ParameterList* params) try { + auto _dt = ::djinni::swift::Duration<::djinni::swift::I32, ::djinni::swift::Duration_s>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::secondsString(std::move(_dt)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_millisString(const djinni::swift::ParameterList* params) try { + auto _dt = ::djinni::swift::Duration<::djinni::swift::I32, ::djinni::swift::Duration_ms>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::millisString(std::move(_dt)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_microsString(const djinni::swift::ParameterList* params) try { + auto _dt = ::djinni::swift::Duration<::djinni::swift::I32, ::djinni::swift::Duration_us>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::microsString(std::move(_dt)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_nanosString(const djinni::swift::ParameterList* params) try { + auto _dt = ::djinni::swift::Duration<::djinni::swift::I32, ::djinni::swift::Duration_ns>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::nanosString(std::move(_dt)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_hours(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::I32::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::hours(std::move(_count)); + return ::djinni::swift::Duration<::djinni::swift::I32, ::djinni::swift::Duration_h>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_minutes(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::I32::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::minutes(std::move(_count)); + return ::djinni::swift::Duration<::djinni::swift::I32, ::djinni::swift::Duration_min>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_seconds(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::I32::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::seconds(std::move(_count)); + return ::djinni::swift::Duration<::djinni::swift::I32, ::djinni::swift::Duration_s>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_millis(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::I32::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::millis(std::move(_count)); + return ::djinni::swift::Duration<::djinni::swift::I32, ::djinni::swift::Duration_ms>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_micros(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::I32::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::micros(std::move(_count)); + return ::djinni::swift::Duration<::djinni::swift::I32, ::djinni::swift::Duration_us>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_nanos(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::I32::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::nanos(std::move(_count)); + return ::djinni::swift::Duration<::djinni::swift::I32, ::djinni::swift::Duration_ns>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_hoursf(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::F64::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::hoursf(std::move(_count)); + return ::djinni::swift::Duration<::djinni::swift::F64, ::djinni::swift::Duration_h>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_minutesf(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::F64::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::minutesf(std::move(_count)); + return ::djinni::swift::Duration<::djinni::swift::F64, ::djinni::swift::Duration_min>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_secondsf(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::F64::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::secondsf(std::move(_count)); + return ::djinni::swift::Duration<::djinni::swift::F64, ::djinni::swift::Duration_s>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_millisf(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::F64::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::millisf(std::move(_count)); + return ::djinni::swift::Duration<::djinni::swift::F64, ::djinni::swift::Duration_ms>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_microsf(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::F64::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::microsf(std::move(_count)); + return ::djinni::swift::Duration<::djinni::swift::F64, ::djinni::swift::Duration_us>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_nanosf(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::F64::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::nanosf(std::move(_count)); + return ::djinni::swift::Duration<::djinni::swift::F64, ::djinni::swift::Duration_ns>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_box(const djinni::swift::ParameterList* params) try { + auto _count = ::djinni::swift::I64::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::box(std::move(_count)); + return ::djinni::swift::Optional>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestDuration_unbox(const djinni::swift::ParameterList* params) try { + auto _dt = ::djinni::swift::Optional>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestDuration::unbox(std::move(_dt)); + return ::djinni::swift::I64::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeTestDuration.hpp b/test-suite/generated-src/swiftxx/NativeTestDuration.hpp new file mode 100644 index 00000000..177d8235 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeTestDuration.hpp @@ -0,0 +1,34 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from duration.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "test_duration.hpp" + +namespace djinni_generated { + +using NativeTestDuration = djinni::swift::Interface<::testsuite::TestDuration>; + +djinni::swift::AnyValue TestDuration_hoursString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_minutesString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_secondsString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_millisString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_microsString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_nanosString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_hours(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_minutes(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_seconds(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_millis(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_micros(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_nanos(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_hoursf(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_minutesf(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_secondsf(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_millisf(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_microsf(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_nanosf(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_box(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestDuration_unbox(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeTestHelpers.cpp b/test-suite/generated-src/swiftxx/NativeTestHelpers.cpp new file mode 100644 index 00000000..ac4d481b --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeTestHelpers.cpp @@ -0,0 +1,319 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +#include "NativeTestHelpers.hpp" // my header +#include "Future_swift.hpp" +#include "NativeAssortedPrimitives.hpp" +#include "NativeAsyncInterface.hpp" +#include "NativeClientInterface.hpp" +#include "NativeColor.hpp" +#include "NativeMapListRecord.hpp" +#include "NativeNestedCollection.hpp" +#include "NativePrimitiveList.hpp" +#include "NativeSetRecord.hpp" +#include "NativeUserToken.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue TestHelpers_getSetRecord(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::get_set_record(); + return ::djinni_generated::NativeSetRecord::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkSetRecord(const djinni::swift::ParameterList* params) try { + auto _rec = ::djinni_generated::NativeSetRecord::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::check_set_record(std::move(_rec)); + return ::djinni::swift::Bool::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_getPrimitiveList(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::get_primitive_list(); + return ::djinni_generated::NativePrimitiveList::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkPrimitiveList(const djinni::swift::ParameterList* params) try { + auto _pl = ::djinni_generated::NativePrimitiveList::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::check_primitive_list(std::move(_pl)); + return ::djinni::swift::Bool::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_getNestedCollection(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::get_nested_collection(); + return ::djinni_generated::NativeNestedCollection::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkNestedCollection(const djinni::swift::ParameterList* params) try { + auto _nc = ::djinni_generated::NativeNestedCollection::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::check_nested_collection(std::move(_nc)); + return ::djinni::swift::Bool::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_getMap(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::get_map(); + return ::djinni::swift::Map<::djinni::swift::String, ::djinni::swift::I64>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkMap(const djinni::swift::ParameterList* params) try { + auto _m = ::djinni::swift::Map<::djinni::swift::String, ::djinni::swift::I64>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::check_map(std::move(_m)); + return ::djinni::swift::Bool::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_getEmptyMap(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::get_empty_map(); + return ::djinni::swift::Map<::djinni::swift::String, ::djinni::swift::I64>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkEmptyMap(const djinni::swift::ParameterList* params) try { + auto _m = ::djinni::swift::Map<::djinni::swift::String, ::djinni::swift::I64>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::check_empty_map(std::move(_m)); + return ::djinni::swift::Bool::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_getMapListRecord(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::get_map_list_record(); + return ::djinni_generated::NativeMapListRecord::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkMapListRecord(const djinni::swift::ParameterList* params) try { + auto _m = ::djinni_generated::NativeMapListRecord::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::check_map_list_record(std::move(_m)); + return ::djinni::swift::Bool::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkClientInterfaceAscii(const djinni::swift::ParameterList* params) try { + auto _i = ::djinni_generated::NativeClientInterface::toCpp(params->getValue(0)); + ::testsuite::TestHelpers::check_client_interface_ascii(std::move(_i)); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkClientInterfaceNonascii(const djinni::swift::ParameterList* params) try { + auto _i = ::djinni_generated::NativeClientInterface::toCpp(params->getValue(0)); + ::testsuite::TestHelpers::check_client_interface_nonascii(std::move(_i)); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkClientInterfaceArgs(const djinni::swift::ParameterList* params) try { + auto _i = ::djinni_generated::NativeClientInterface::toCpp(params->getValue(0)); + ::testsuite::TestHelpers::check_client_interface_args(std::move(_i)); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkEnumMap(const djinni::swift::ParameterList* params) try { + auto _m = ::djinni::swift::Map<::djinni_generated::NativeColor, ::djinni::swift::String>::toCpp(params->getValue(0)); + ::testsuite::TestHelpers::check_enum_map(std::move(_m)); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkEnum(const djinni::swift::ParameterList* params) try { + auto _c = ::djinni_generated::NativeColor::toCpp(params->getValue(0)); + ::testsuite::TestHelpers::check_enum(std::move(_c)); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_tokenId(const djinni::swift::ParameterList* params) try { + auto _t = ::djinni::swift::Optional::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::token_id(std::move(_t)); + return ::djinni::swift::Optional::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_createCppToken(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::create_cpp_token(); + return ::djinni_generated::NativeUserToken::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkCppToken(const djinni::swift::ParameterList* params) try { + auto _t = ::djinni_generated::NativeUserToken::toCpp(params->getValue(0)); + ::testsuite::TestHelpers::check_cpp_token(std::move(_t)); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_cppTokenId(const djinni::swift::ParameterList* params) try { + auto _t = ::djinni_generated::NativeUserToken::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::cpp_token_id(std::move(_t)); + return ::djinni::swift::I64::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkTokenType(const djinni::swift::ParameterList* params) try { + auto _t = ::djinni_generated::NativeUserToken::toCpp(params->getValue(0)); + auto _type = ::djinni::swift::String::toCpp(params->getValue(1)); + ::testsuite::TestHelpers::check_token_type(std::move(_t), std::move(_type)); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_returnNone(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::return_none(); + return ::djinni::swift::Optional::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_assortedPrimitivesId(const djinni::swift::ParameterList* params) try { + auto _i = ::djinni_generated::NativeAssortedPrimitives::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::assorted_primitives_id(std::move(_i)); + return ::djinni_generated::NativeAssortedPrimitives::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_idBinary(const djinni::swift::ParameterList* params) try { + auto _b = ::djinni::swift::Binary::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::id_binary(std::move(_b)); + return ::djinni::swift::Binary::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_getAsyncResult(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::get_async_result(); + return ::djinni::swift::FutureAdaptor<::djinni::swift::I32>::fromCpp(std::move(ret)); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_futureRoundtrip(const djinni::swift::ParameterList* params) try { + auto _f = ::djinni::swift::FutureAdaptor<::djinni::swift::I32>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::future_roundtrip(std::move(_f)); + return ::djinni::swift::FutureAdaptor<::djinni::swift::String>::fromCpp(std::move(ret)); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_asyncEarlyThrow(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::async_early_throw(); + return ::djinni::swift::FutureAdaptor<::djinni::swift::I32>::fromCpp(std::move(ret)); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_voidAsyncMethod(const djinni::swift::ParameterList* params) try { + auto _f = ::djinni::swift::FutureAdaptor<::djinni::swift::Void>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::void_async_method(std::move(_f)); + return ::djinni::swift::FutureAdaptor<::djinni::swift::Void>::fromCpp(std::move(ret)); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_addOneIfPresent(const djinni::swift::ParameterList* params) try { + auto _f = ::djinni::swift::FutureAdaptor<::djinni::swift::Optional>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::add_one_if_present(std::move(_f)); + return ::djinni::swift::FutureAdaptor<::djinni::swift::Optional>::fromCpp(std::move(ret)); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_returnExceptionString(const djinni::swift::ParameterList* params) try { + auto _f = ::djinni::swift::FutureAdaptor<::djinni::swift::I32>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::return_exception_string(std::move(_f)); + return ::djinni::swift::FutureAdaptor<::djinni::swift::String>::fromCpp(std::move(ret)); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkAsyncInterface(const djinni::swift::ParameterList* params) try { + auto _i = ::djinni_generated::NativeAsyncInterface::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::check_async_interface(std::move(_i)); + return ::djinni::swift::FutureAdaptor<::djinni::swift::String>::fromCpp(std::move(ret)); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkAsyncComposition(const djinni::swift::ParameterList* params) try { + auto _i = ::djinni_generated::NativeAsyncInterface::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::check_async_composition(std::move(_i)); + return ::djinni::swift::FutureAdaptor<::djinni::swift::String>::fromCpp(std::move(ret)); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_getOptionalList(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::get_optional_list(); + return ::djinni::swift::List<::djinni::swift::Optional>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkOptionalList(const djinni::swift::ParameterList* params) try { + auto _ol = ::djinni::swift::List<::djinni::swift::Optional>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::check_optional_list(std::move(_ol)); + return ::djinni::swift::Bool::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_getOptionalSet(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::get_optional_set(); + return ::djinni::swift::Set<::djinni::swift::Optional>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkOptionalSet(const djinni::swift::ParameterList* params) try { + auto _os = ::djinni::swift::Set<::djinni::swift::Optional>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::check_optional_set(std::move(_os)); + return ::djinni::swift::Bool::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_getOptionalMap(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestHelpers::get_optional_map(); + return ::djinni::swift::Map<::djinni::swift::Optional, ::djinni::swift::Optional>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestHelpers_checkOptionalMap(const djinni::swift::ParameterList* params) try { + auto _om = ::djinni::swift::Map<::djinni::swift::Optional, ::djinni::swift::Optional>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestHelpers::check_optional_map(std::move(_om)); + return ::djinni::swift::Bool::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeTestHelpers.hpp b/test-suite/generated-src/swiftxx/NativeTestHelpers.hpp new file mode 100644 index 00000000..d6ae7612 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeTestHelpers.hpp @@ -0,0 +1,53 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from test.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "test_helpers.hpp" + +namespace djinni_generated { + +using NativeTestHelpers = djinni::swift::Interface<::testsuite::TestHelpers>; + +djinni::swift::AnyValue TestHelpers_getSetRecord(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkSetRecord(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_getPrimitiveList(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkPrimitiveList(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_getNestedCollection(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkNestedCollection(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_getMap(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkMap(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_getEmptyMap(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkEmptyMap(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_getMapListRecord(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkMapListRecord(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkClientInterfaceAscii(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkClientInterfaceNonascii(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkClientInterfaceArgs(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkEnumMap(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkEnum(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_tokenId(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_createCppToken(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkCppToken(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_cppTokenId(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkTokenType(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_returnNone(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_assortedPrimitivesId(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_idBinary(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_getAsyncResult(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_futureRoundtrip(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_asyncEarlyThrow(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_voidAsyncMethod(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_addOneIfPresent(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_returnExceptionString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkAsyncInterface(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkAsyncComposition(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_getOptionalList(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkOptionalList(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_getOptionalSet(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkOptionalSet(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_getOptionalMap(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestHelpers_checkOptionalMap(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeTestOptionalExternInterfaceRecord.cpp b/test-suite/generated-src/swiftxx/NativeTestOptionalExternInterfaceRecord.cpp new file mode 100644 index 00000000..18816968 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeTestOptionalExternInterfaceRecord.cpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +#include "NativeTestOptionalExternInterfaceRecord.hpp" // my header +#include "NativeSampleInterface.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue NativeTestOptionalExternInterfaceRecord::fromCpp(const ::TestOptionalExternInterfaceRecord& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::Optional::fromCpp(c.sample_interface)); + return {ret}; +} +::TestOptionalExternInterfaceRecord NativeTestOptionalExternInterfaceRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::TestOptionalExternInterfaceRecord(::djinni::swift::Optional::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeTestOptionalExternInterfaceRecord.hpp b/test-suite/generated-src/swiftxx/NativeTestOptionalExternInterfaceRecord.hpp new file mode 100644 index 00000000..54060181 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeTestOptionalExternInterfaceRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from yaml-test.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "test_optional_extern_interface_record.hpp" + +namespace djinni_generated { + +struct NativeTestOptionalExternInterfaceRecord { + using CppType = ::TestOptionalExternInterfaceRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeTestOutcome.cpp b/test-suite/generated-src/swiftxx/NativeTestOutcome.cpp new file mode 100644 index 00000000..5557ba8e --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeTestOutcome.cpp @@ -0,0 +1,71 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from outcome.djinni + +#include "NativeTestOutcome.hpp" // my header +#include "NativeNestedOutcome.hpp" +#include "Outcome_swift.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue TestOutcome_getSuccessOutcome(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestOutcome::getSuccessOutcome(); + return ::djinni::swift::OutcomeAdaptor<::djinni::swift::String, ::djinni::swift::I32>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestOutcome_getErrorOutcome(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestOutcome::getErrorOutcome(); + return ::djinni::swift::OutcomeAdaptor<::djinni::swift::String, ::djinni::swift::I32>::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestOutcome_putSuccessOutcome(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::OutcomeAdaptor<::djinni::swift::String, ::djinni::swift::I32>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestOutcome::putSuccessOutcome(std::move(_x)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestOutcome_putErrorOutcome(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni::swift::OutcomeAdaptor<::djinni::swift::String, ::djinni::swift::I32>::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestOutcome::putErrorOutcome(std::move(_x)); + return ::djinni::swift::I32::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestOutcome_getNestedSuccessOutcome(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestOutcome::getNestedSuccessOutcome(); + return ::djinni_generated::NativeNestedOutcome::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestOutcome_getNestedErrorOutcome(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::TestOutcome::getNestedErrorOutcome(); + return ::djinni_generated::NativeNestedOutcome::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestOutcome_putNestedSuccessOutcome(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni_generated::NativeNestedOutcome::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestOutcome::putNestedSuccessOutcome(std::move(_x)); + return ::djinni::swift::I32::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue TestOutcome_putNestedErrorOutcome(const djinni::swift::ParameterList* params) try { + auto _x = ::djinni_generated::NativeNestedOutcome::toCpp(params->getValue(0)); + auto ret = ::testsuite::TestOutcome::putNestedErrorOutcome(std::move(_x)); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeTestOutcome.hpp b/test-suite/generated-src/swiftxx/NativeTestOutcome.hpp new file mode 100644 index 00000000..0bffb127 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeTestOutcome.hpp @@ -0,0 +1,22 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from outcome.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "test_outcome.hpp" + +namespace djinni_generated { + +using NativeTestOutcome = djinni::swift::Interface<::testsuite::TestOutcome>; + +djinni::swift::AnyValue TestOutcome_getSuccessOutcome(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestOutcome_getErrorOutcome(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestOutcome_putSuccessOutcome(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestOutcome_putErrorOutcome(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestOutcome_getNestedSuccessOutcome(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestOutcome_getNestedErrorOutcome(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestOutcome_putNestedSuccessOutcome(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue TestOutcome_putNestedErrorOutcome(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeTestStaticMethodLanguage.cpp b/test-suite/generated-src/swiftxx/NativeTestStaticMethodLanguage.cpp new file mode 100644 index 00000000..c20cc7b3 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeTestStaticMethodLanguage.cpp @@ -0,0 +1,9 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from static_method_language.djinni + +#include "NativeTestStaticMethodLanguage.hpp" // my header + +namespace djinni_generated { + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeTestStaticMethodLanguage.hpp b/test-suite/generated-src/swiftxx/NativeTestStaticMethodLanguage.hpp new file mode 100644 index 00000000..5c1b2daf --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeTestStaticMethodLanguage.hpp @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from static_method_language.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "test_static_method_language.hpp" + +namespace djinni_generated { + +using NativeTestStaticMethodLanguage = djinni::swift::Interface<::testsuite::TestStaticMethodLanguage>; + + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeThrowingInterface.cpp b/test-suite/generated-src/swiftxx/NativeThrowingInterface.cpp new file mode 100644 index 00000000..daaed44a --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeThrowingInterface.cpp @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from exception.djinni + +#include "NativeThrowingInterface.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue ThrowingInterfaceSwiftProxy::make(void* instance, djinni::swift::DispatchFunc dispatcher) { + return {std::make_shared(instance, dispatcher)}; +} +void ThrowingInterfaceSwiftProxy::throw_exception() { + djinni::swift::ParameterList params; + callProtocol(0, ¶ms); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeThrowingInterface.hpp b/test-suite/generated-src/swiftxx/NativeThrowingInterface.hpp new file mode 100644 index 00000000..c1f39750 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeThrowingInterface.hpp @@ -0,0 +1,20 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from exception.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "throwing_interface.hpp" + +namespace djinni_generated { + +using NativeThrowingInterface = djinni::swift::Interface<::testsuite::ThrowingInterface>; + +class ThrowingInterfaceSwiftProxy: public ::testsuite::ThrowingInterface, public djinni::swift::ProtocolWrapper { +public: + ThrowingInterfaceSwiftProxy(void* instance, djinni::swift::DispatchFunc dispatcher): ProtocolWrapper(instance, dispatcher) {} + static djinni::swift::AnyValue make(void* instance, djinni::swift::DispatchFunc dispatcher); + void throw_exception() override; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeUserToken.cpp b/test-suite/generated-src/swiftxx/NativeUserToken.cpp new file mode 100644 index 00000000..896e97f6 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeUserToken.cpp @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from user_token.djinni + +#include "NativeUserToken.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue UserToken_whoami(const djinni::swift::ParameterList* params) try { + auto inst = NativeUserToken::toCpp(params->getValue(0)); + auto ret = inst->whoami(); + return ::djinni::swift::String::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue UserTokenSwiftProxy::make(void* instance, djinni::swift::DispatchFunc dispatcher) { + return {std::make_shared(instance, dispatcher)}; +} +std::string UserTokenSwiftProxy::whoami() { + djinni::swift::ParameterList params; + return ::djinni::swift::String::toCpp(callProtocol(0, ¶ms)); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeUserToken.hpp b/test-suite/generated-src/swiftxx/NativeUserToken.hpp new file mode 100644 index 00000000..3600daaf --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeUserToken.hpp @@ -0,0 +1,22 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from user_token.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "user_token.hpp" + +namespace djinni_generated { + +using NativeUserToken = djinni::swift::Interface<::testsuite::UserToken>; + +djinni::swift::AnyValue UserToken_whoami(const djinni::swift::ParameterList* params); + +class UserTokenSwiftProxy: public ::testsuite::UserToken, public djinni::swift::ProtocolWrapper { +public: + UserTokenSwiftProxy(void* instance, djinni::swift::DispatchFunc dispatcher): ProtocolWrapper(instance, dispatcher) {} + static djinni::swift::AnyValue make(void* instance, djinni::swift::DispatchFunc dispatcher); + std::string whoami() override; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeUsesSingleLanguageListeners.cpp b/test-suite/generated-src/swiftxx/NativeUsesSingleLanguageListeners.cpp new file mode 100644 index 00000000..d9c8a36d --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeUsesSingleLanguageListeners.cpp @@ -0,0 +1,45 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from single_language_interfaces.djinni + +#include "NativeUsesSingleLanguageListeners.hpp" // my header +#include "NativeJavaOnlyListener.hpp" +#include "NativeObjcOnlyListener.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue UsesSingleLanguageListeners_callForObjC(const djinni::swift::ParameterList* params) try { + auto inst = NativeUsesSingleLanguageListeners::toCpp(params->getValue(0)); + auto _l = ::djinni_generated::NativeObjcOnlyListener::toCpp(params->getValue(1)); + inst->callForObjC(std::move(_l)); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue UsesSingleLanguageListeners_returnForObjC(const djinni::swift::ParameterList* params) try { + auto inst = NativeUsesSingleLanguageListeners::toCpp(params->getValue(0)); + auto ret = inst->returnForObjC(); + return ::djinni_generated::NativeObjcOnlyListener::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue UsesSingleLanguageListeners_callForJava(const djinni::swift::ParameterList* params) try { + auto inst = NativeUsesSingleLanguageListeners::toCpp(params->getValue(0)); + auto _l = ::djinni_generated::NativeJavaOnlyListener::toCpp(params->getValue(1)); + inst->callForJava(std::move(_l)); + return djinni::swift::makeVoidValue(); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue UsesSingleLanguageListeners_returnForJava(const djinni::swift::ParameterList* params) try { + auto inst = NativeUsesSingleLanguageListeners::toCpp(params->getValue(0)); + auto ret = inst->returnForJava(); + return ::djinni_generated::NativeJavaOnlyListener::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeUsesSingleLanguageListeners.hpp b/test-suite/generated-src/swiftxx/NativeUsesSingleLanguageListeners.hpp new file mode 100644 index 00000000..c6b7d45f --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeUsesSingleLanguageListeners.hpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from single_language_interfaces.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "uses_single_language_listeners.hpp" + +namespace djinni_generated { + +using NativeUsesSingleLanguageListeners = djinni::swift::Interface<::testsuite::UsesSingleLanguageListeners>; + +djinni::swift::AnyValue UsesSingleLanguageListeners_callForObjC(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue UsesSingleLanguageListeners_returnForObjC(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue UsesSingleLanguageListeners_callForJava(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue UsesSingleLanguageListeners_returnForJava(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeVarnameInterface.cpp b/test-suite/generated-src/swiftxx/NativeVarnameInterface.cpp new file mode 100644 index 00000000..aacd779d --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeVarnameInterface.cpp @@ -0,0 +1,28 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from varnames.djinni + +#include "NativeVarnameInterface.hpp" // my header +#include "NativeVarnameRecord.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue VarnameInterface_Rmethod(const djinni::swift::ParameterList* params) try { + auto inst = NativeVarnameInterface::toCpp(params->getValue(0)); + auto __r_arg_ = ::djinni_generated::NativeVarnameRecord::toCpp(params->getValue(1)); + auto ret = inst->_rmethod_(std::move(__r_arg_)); + return ::djinni_generated::NativeVarnameRecord::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue VarnameInterface_Imethod(const djinni::swift::ParameterList* params) try { + auto inst = NativeVarnameInterface::toCpp(params->getValue(0)); + auto __i_arg_ = ::djinni_generated::NativeVarnameInterface::toCpp(params->getValue(1)); + auto ret = inst->_imethod_(std::move(__i_arg_)); + return ::djinni_generated::NativeVarnameInterface::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeVarnameInterface.hpp b/test-suite/generated-src/swiftxx/NativeVarnameInterface.hpp new file mode 100644 index 00000000..ac53fe47 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeVarnameInterface.hpp @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from varnames.djinni + +#pragma once + +#include "_varname_interface_.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +using NativeVarnameInterface = djinni::swift::Interface<::testsuite::VarnameInterface>; + +djinni::swift::AnyValue VarnameInterface_Rmethod(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue VarnameInterface_Imethod(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeVarnameRecord.cpp b/test-suite/generated-src/swiftxx/NativeVarnameRecord.cpp new file mode 100644 index 00000000..9c18bc9f --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeVarnameRecord.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from varnames.djinni + +#include "NativeVarnameRecord.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeVarnameRecord::fromCpp(const ::testsuite::VarnameRecord& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::I8::fromCpp(c._field_)); + return {ret}; +} +::testsuite::VarnameRecord NativeVarnameRecord::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::VarnameRecord(::djinni::swift::I8::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeVarnameRecord.hpp b/test-suite/generated-src/swiftxx/NativeVarnameRecord.hpp new file mode 100644 index 00000000..b8ce2117 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeVarnameRecord.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from varnames.djinni + +#pragma once + +#include "_varname_record_.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +struct NativeVarnameRecord { + using CppType = ::testsuite::VarnameRecord; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeVec2.cpp b/test-suite/generated-src/swiftxx/NativeVec2.cpp new file mode 100644 index 00000000..44ce0511 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeVec2.cpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from array.djinni + +#include "NativeVec2.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeVec2::fromCpp(const ::testsuite::Vec2& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::I32::fromCpp(c.x)); + ret->addValue(::djinni::swift::I32::fromCpp(c.y)); + return {ret}; +} +::testsuite::Vec2 NativeVec2::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::Vec2(::djinni::swift::I32::toCpp(p->getValue(0)), ::djinni::swift::I32::toCpp(p->getValue(1))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeVec2.hpp b/test-suite/generated-src/swiftxx/NativeVec2.hpp new file mode 100644 index 00000000..cb7ae1f2 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeVec2.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from array.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "vec2.hpp" + +namespace djinni_generated { + +struct NativeVec2 { + using CppType = ::testsuite::Vec2; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeWcharTestHelpers.cpp b/test-suite/generated-src/swiftxx/NativeWcharTestHelpers.cpp new file mode 100644 index 00000000..62b7aa65 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeWcharTestHelpers.cpp @@ -0,0 +1,40 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from wchar_test.djinni + +#include "NativeWcharTestHelpers.hpp" // my header +#include "NativeWcharTestRec.hpp" + +namespace djinni_generated { + +djinni::swift::AnyValue WcharTestHelpers_getRecord(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::WcharTestHelpers::get_record(); + return ::djinni_generated::NativeWcharTestRec::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue WcharTestHelpers_getString(const djinni::swift::ParameterList* params) try { + auto ret = ::testsuite::WcharTestHelpers::get_string(); + return ::djinni::swift::WString::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue WcharTestHelpers_checkString(const djinni::swift::ParameterList* params) try { + auto _str = ::djinni::swift::WString::toCpp(params->getValue(0)); + auto ret = ::testsuite::WcharTestHelpers::check_string(std::move(_str)); + return ::djinni::swift::Bool::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} +djinni::swift::AnyValue WcharTestHelpers_checkRecord(const djinni::swift::ParameterList* params) try { + auto _rec = ::djinni_generated::NativeWcharTestRec::toCpp(params->getValue(0)); + auto ret = ::testsuite::WcharTestHelpers::check_record(std::move(_rec)); + return ::djinni::swift::Bool::fromCpp(ret); +} +catch (const std::exception& e) { + return {djinni::swift::ErrorValue{ e.what(), std::current_exception()}}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeWcharTestHelpers.hpp b/test-suite/generated-src/swiftxx/NativeWcharTestHelpers.hpp new file mode 100644 index 00000000..906813d8 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeWcharTestHelpers.hpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from wchar_test.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "wchar_test_helpers.hpp" + +namespace djinni_generated { + +using NativeWcharTestHelpers = djinni::swift::Interface<::testsuite::WcharTestHelpers>; + +djinni::swift::AnyValue WcharTestHelpers_getRecord(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue WcharTestHelpers_getString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue WcharTestHelpers_checkString(const djinni::swift::ParameterList* params); +djinni::swift::AnyValue WcharTestHelpers_checkRecord(const djinni::swift::ParameterList* params); + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeWcharTestRec.cpp b/test-suite/generated-src/swiftxx/NativeWcharTestRec.cpp new file mode 100644 index 00000000..3c9a997c --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeWcharTestRec.cpp @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from wchar_test.djinni + +#include "NativeWcharTestRec.hpp" // my header + +namespace djinni_generated { + +djinni::swift::AnyValue NativeWcharTestRec::fromCpp(const ::testsuite::WcharTestRec& c) { + auto ret = std::make_shared(); + ret->addValue(::djinni::swift::WString::fromCpp(c.s)); + return {ret}; +} +::testsuite::WcharTestRec NativeWcharTestRec::toCpp(const djinni::swift::AnyValue& s) { + auto p = std::get(s); + return ::testsuite::WcharTestRec(::djinni::swift::WString::toCpp(p->getValue(0))); +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/swiftxx/NativeWcharTestRec.hpp b/test-suite/generated-src/swiftxx/NativeWcharTestRec.hpp new file mode 100644 index 00000000..aea619f5 --- /dev/null +++ b/test-suite/generated-src/swiftxx/NativeWcharTestRec.hpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from wchar_test.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "wchar_test_rec.hpp" + +namespace djinni_generated { + +struct NativeWcharTestRec { + using CppType = ::testsuite::WcharTestRec; + static djinni::swift::AnyValue fromCpp(const CppType& c); + static CppType toCpp(const djinni::swift::AnyValue& s); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/ts/test.ts b/test-suite/generated-src/ts/test.ts index b25df92d..83ff6c3e 100644 --- a/test-suite/generated-src/ts/test.ts +++ b/test-suite/generated-src/ts/test.ts @@ -485,7 +485,7 @@ export interface Conflict { export interface ConflictUser { Conflict(): Conflict; - conflictArg(cs: Set): boolean; + conflictArg(cs: Array): boolean; } /** diff --git a/test-suite/generated-src/wasm/NativeConflictUser.cpp b/test-suite/generated-src/wasm/NativeConflictUser.cpp index b2ed071c..f7e12fc4 100644 --- a/test-suite/generated-src/wasm/NativeConflictUser.cpp +++ b/test-suite/generated-src/wasm/NativeConflictUser.cpp @@ -25,7 +25,7 @@ em::val NativeConflictUser::Conflict(const CppType& self) { } bool NativeConflictUser::conflict_arg(const CppType& self, const em::val& w_cs) { try { - auto r = self->conflict_arg(::djinni::Set<::djinni_generated::NativeConflict>::toCpp(w_cs)); + auto r = self->conflict_arg(::djinni::List<::djinni_generated::NativeConflict>::toCpp(w_cs)); return ::djinni::Bool::fromCpp(r); } catch(const std::exception& e) { diff --git a/test-suite/handwritten-src/cpp/Duration-swift.hpp b/test-suite/handwritten-src/cpp/Duration-swift.hpp new file mode 100644 index 00000000..ec96a8f3 --- /dev/null +++ b/test-suite/handwritten-src/cpp/Duration-swift.hpp @@ -0,0 +1,36 @@ +#pragma once +#include "djinni_support.hpp" +#include + +namespace djinni::swift +{ + template + struct DurationPeriod; + + using Duration_h = DurationPeriod>; + using Duration_min = DurationPeriod>; + using Duration_s = DurationPeriod>; + using Duration_ms = DurationPeriod; + using Duration_us = DurationPeriod; + using Duration_ns = DurationPeriod; + + template + struct Duration; + + template + struct Duration> + { + using CppType = std::chrono::duration; + + using Boxed = Duration; + + static CppType toCpp(const AnyValue& s) + { + return std::chrono::duration_cast(std::chrono::duration{std::get(s)}); + } + static AnyValue fromCpp(const CppType& c) + { + return { std::chrono::duration_cast>(c).count() }; + } + }; +} diff --git a/test-suite/handwritten-src/swift/ArrayTest.swift b/test-suite/handwritten-src/swift/ArrayTest.swift new file mode 100644 index 00000000..aab2d638 --- /dev/null +++ b/test-suite/handwritten-src/swift/ArrayTest.swift @@ -0,0 +1,23 @@ +import XCTest +@testable import TestSuite +@testable import TestSuiteBridge + +final class ArrayTest: XCTestCase { + func testArrays() throws { + let inputStrings = ["1", "2", "3"] + let expectedStrings = ["3", "2", "1"] + XCTAssertEqual(try TestArray_statics.testStringArray(a:inputStrings), expectedStrings) + + let inputIntegers: [Int32] = [1, 2, 3] + let expectedIntegers: [Int32] = [3, 2, 1] + XCTAssertEqual(try TestArray_statics.testIntArray(a:inputIntegers), expectedIntegers) + + let inputRecords = [Vec2(x:1, y:1), Vec2(x:2, y:2), Vec2(x:3, y:3)] + let expectedRecords = [Vec2(x:3, y:3), Vec2(x:2, y:2), Vec2(x:1, y:1)] + XCTAssertEqual(try TestArray_statics.testRecordArray(a:inputRecords), expectedRecords) + + let inputArrays: [[Int32]] = [[1,1,1], [2,2,2], [3,3,3]] + let expectedArrays: [[Int32]] = [[3,3,3], [2,2,2], [1,1,1]] + XCTAssertEqual(try TestArray_statics.testArrayOfArray(a:inputArrays), expectedArrays) + } +} diff --git a/test-suite/handwritten-src/swift/AsyncTest.swift b/test-suite/handwritten-src/swift/AsyncTest.swift new file mode 100644 index 00000000..d4709568 --- /dev/null +++ b/test-suite/handwritten-src/swift/AsyncTest.swift @@ -0,0 +1,105 @@ +import XCTest +import DjinniSupport +import Combine +@testable import TestSuite +@testable import TestSuiteBridge + +final class AsyncTest: XCTestCase { + + class AsyncInterfaceImpl: AsyncInterface { + func futureRoundtrip(f: DJFuture) throws -> DJFuture { + var token: AnyCancellable? = nil + return DJFuture() { promise in + token = f.sink { completion in + if case .failure = completion { + XCTAssertTrue(false) + } + token = withExtendedLifetime(token) {nil} + } receiveValue: { i in + promise(.success(String(i))) + } + } + } + } + + func testConsumeNativeFuture() async throws { + let f = try TestHelpers_statics.getAsyncResult() + let i = try await f.value + XCTAssertEqual(i, 42) + } + + func testFutureRoundtrip() async throws { + var p: DJFuture.Promise? = nil + let f = DJFuture() { promise in + p = promise + } + var sink: AnyCancellable? = nil + let f2 = DJFuture() { promise in + sink = f.sink { completion in if case .failure = completion {XCTAssertTrue(false)}} + receiveValue: { s in promise(.success(Int32(s)!))} + } + let f3 = try TestHelpers_statics.futureRoundtrip(f:f2) + p!(.success("36")) + let res = try await f3.value + XCTAssertEqual(res, "36") + sink = withExtendedLifetime(sink) {nil} + } + + func testVoidRoundtrip() async throws { + let f = DJFuture() { promise in + promise(.success(())) + } + let f1 = try TestHelpers_statics.voidAsyncMethod(f:f) + try await f1.value + } + + func testFutureRoundtripWithException() async throws { + var p: DJFuture.Promise? = nil + let f = DJFuture() { promise in + p = promise + } + var sink: AnyCancellable? = nil + let f2 = DJFuture() { promise in + sink = f.sink { completion in if case .failure = completion {XCTAssertTrue(false)}} + receiveValue: { s in + promise(.failure(DjinniError("123"))) + } + } + let f3 = try TestHelpers_statics.futureRoundtrip(f:f2) + p!(.success("36")) + var s: String? = nil + do { + let _ = try await f3.value + } catch let e as DjinniError { + s = e.errorMessage + } + XCTAssertEqual(s, "123") + sink = withExtendedLifetime(sink){nil} + } + + func testFutureRoundtripBackwards() async throws { + let s = try await TestHelpers_statics.checkAsyncInterface(i:AsyncInterfaceImpl()).value + XCTAssertEqual(s, "36") + } + + func testFutureComposition() async throws { + let s = try await TestHelpers_statics.checkAsyncComposition(i: AsyncInterfaceImpl()).value + XCTAssertEqual(s, "42") + } + + func testOptionalFutureUnsetValue() async throws { + let input = DJFuture> { promise in + promise(.success(nil)) + } + let output = try await TestHelpers_statics.addOneIfPresent(f:input).value + XCTAssertNil(output) + } + + func testOptionalFutureSetValue() async throws { + let input = DJFuture> { promise in + promise(.success(10)) + } + let output = try await TestHelpers_statics.addOneIfPresent(f:input).value + XCTAssertEqual(output, 11) + } +} diff --git a/test-suite/handwritten-src/swift/ClientInterfaceTest.swift b/test-suite/handwritten-src/swift/ClientInterfaceTest.swift new file mode 100644 index 00000000..4844f910 --- /dev/null +++ b/test-suite/handwritten-src/swift/ClientInterfaceTest.swift @@ -0,0 +1,58 @@ +import XCTest +@testable import TestSuite +@testable import TestSuiteBridge + +struct ClientInterfaceError: Error { + var msg: String +} + +class ClientInterfaceImpl: ClientInterface { + func getRecord(recordId: Int64, utf8string: String, misc: Optional) throws -> TestSuite.ClientReturnedRecord { + if (utf8string != "Non-ASCII /\0 非 ASCII 字符" && utf8string != "Hello World!") { + throw ClientInterfaceError(msg: "Unexpected string. Check UTF-8?") + } + return ClientReturnedRecord(recordId:recordId, content:utf8string, misc:misc) + } + func identifierCheck(data: Data, r: Int32, jret: Int64) throws -> Double { + return 0.0 + } + func returnStr() throws -> String { + return "test" + } + func methTakingInterface(i: TestSuite.ClientInterface) throws -> String { + return try i.returnStr() + } + func methTakingOptionalInterface(i: Optional) throws -> String { + if (i != nil) { + return try i!.returnStr() + } else { + return "" + } + } +} + +final class ClientInterfaceTest: XCTestCase { + var sClientInterface: ClientInterface? = nil + + override func setUp() { + sClientInterface = ClientInterfaceImpl() + } + + func testClientReturn() throws { + try TestHelpers_statics.checkClientInterfaceAscii(i: sClientInterface!) + } + + func testClientReturnUTF8() throws { + try TestHelpers_statics.checkClientInterfaceNonascii(i: sClientInterface!) + } + + func testClientInterfaceArgs() throws { + try TestHelpers_statics.checkClientInterfaceArgs(i: sClientInterface!) + } + + func testReverseClientInterfaceArgs() throws { + let i = try ReverseClientInterface_statics.create() + XCTAssertEqual(try i.methTakingInterface(i:i), "test") + XCTAssertEqual(try i.methTakingOptionalInterface(i:i), "test") + } +} diff --git a/test-suite/handwritten-src/swift/ConstantsTest.swift b/test-suite/handwritten-src/swift/ConstantsTest.swift new file mode 100644 index 00000000..80161819 --- /dev/null +++ b/test-suite/handwritten-src/swift/ConstantsTest.swift @@ -0,0 +1,16 @@ +import XCTest +import DjinniSupport +@testable import TestSuite +@testable import TestSuiteBridge + +final class ConstantsTest: XCTestCase { + func testConstPrimitives() throws { + XCTAssertEqual(Constants.i8Constant, 1) + XCTAssertEqual(Constants.optI8Constant, 1) + XCTAssertEqual(Constants.stringConstant, "string-constant") + } + + func testConstRecords() throws { + XCTAssertEqual(Constants.objectConstant, ConstantRecord(someInteger:3, someString:"string-constant")) + } +} diff --git a/test-suite/handwritten-src/swift/CppExceptionTest.swift b/test-suite/handwritten-src/swift/CppExceptionTest.swift new file mode 100644 index 00000000..1ce19d8b --- /dev/null +++ b/test-suite/handwritten-src/swift/CppExceptionTest.swift @@ -0,0 +1,30 @@ +import XCTest +import DjinniSupport +@testable import TestSuite +@testable import TestSuiteBridge + +final class CppExceptionTest: XCTestCase { + + class SwiftThrower: ThrowingInterface { + func throwException() throws -> Void { + throw DjinniError("Swift Error") + } + } + + let cppInterface = (try? CppException_statics.get())! + + func testCppException() throws { + var thrown: DjinniError? = nil + do { + let _ = try cppInterface.throwAnException() + } catch let e as DjinniError { + thrown = e + } + XCTAssertEqual(try XCTUnwrap(thrown).errorMessage, "Exception Thrown") + } + + func testSwiftExceptionHandledByCpp() throws { + let res = try cppInterface.callThrowingAndCatch(cb:SwiftThrower()) + XCTAssertEqual(res, "Swift Error") + } +} diff --git a/test-suite/handwritten-src/swift/DataTest.swift b/test-suite/handwritten-src/swift/DataTest.swift new file mode 100644 index 00000000..48216e36 --- /dev/null +++ b/test-suite/handwritten-src/swift/DataTest.swift @@ -0,0 +1,55 @@ +import XCTest +import Foundation +@testable import TestSuite +@testable import TestSuiteBridge + +final class DataTest: XCTestCase { + + let test = (try? DataRefTest_statics.create())! + + func testSend() throws { + let input: [UInt8] = [0, 1, 2, 3] + let buf = Data(input) + try test.sendData(data:buf as NSData) + let output = try test.retriveAsBin() + XCTAssertEqual(Data(input), output) + } + + func testSendMutable() throws { + let input: [UInt8] = [0, 1, 2, 3] + let buf = NSMutableData() + buf.append(Data(input)) + try test.sendMutableData(data:buf) + XCTAssertEqual(Data([3,2,1,0]), buf as Data) + } + + func testGenerateData() throws { + let buf = try test.generateData() + let output = buf as Data + XCTAssertEqual(Data([0, 1, 2, 3]), output) + } + + func testDataFromVec() throws { + let buf = try test.dataFromVec() + let output = buf as Data + XCTAssertEqual(Data([0, 1, 2, 3]), output) + } + + func testDataFromStr() throws { + let buf = try test.dataFromStr() + let output = buf as Data + XCTAssertEqual("abcd".data(using:.utf8)![0...3], output) + } + + func testSendDataView() throws { + let input: [UInt8] = [0, 1, 2, 3] + let buf = Data(input) + let output = try test.sendDataView(data:buf as NSData) + XCTAssertEqual(buf, output) + } + + func testRecvDataView() throws { + let buf = try test.recvDataView() as Data + XCTAssertEqual(Data([0, 1, 2, 3]), buf) + } +} diff --git a/test-suite/handwritten-src/swift/Duration+Helper.swift b/test-suite/handwritten-src/swift/Duration+Helper.swift new file mode 100644 index 00000000..9adca4ab --- /dev/null +++ b/test-suite/handwritten-src/swift/Duration+Helper.swift @@ -0,0 +1,30 @@ +import Foundation +import DjinniSupport +import DjinniSupportCxx + +enum DurationS: Marshaller { + typealias SwiftType = Duration + static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + let seconds = F64Marshaller.fromCpp(v) + return Duration.seconds(seconds) + } + static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + let v = s.components + return F64Marshaller.toCpp(Double(v.seconds) + Double(v.attoseconds) * 1e-18) + } +} +typealias DurationH = DurationS +typealias DurationMin = DurationS +typealias DurationMs = DurationS +typealias DurationUs = DurationS +typealias DurationNs = DurationS + +public enum DurationMarshaller: Marshaller { + public typealias SwiftType = Duration + public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { + return Period.fromCpp(v) as! Duration + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return Period.toCpp(s as! Period.SwiftType) + } +} diff --git a/test-suite/handwritten-src/swift/DurationTest.swift b/test-suite/handwritten-src/swift/DurationTest.swift new file mode 100644 index 00000000..30e3b44f --- /dev/null +++ b/test-suite/handwritten-src/swift/DurationTest.swift @@ -0,0 +1,39 @@ +import XCTest +@testable import TestSuite +@testable import TestSuiteBridge + +extension Duration { + static func hours(_ h: Double) -> Duration {return .seconds(h*3600)} + static func minutes(_ h: Double) -> Duration {return .seconds(h*60)} +} + +final class DurationTest: XCTestCase { + func test() throws { + XCTAssertEqual(try TestDuration_statics.hoursString(dt:.hours(1)), "1") + XCTAssertEqual(try TestDuration_statics.minutesString(dt:.minutes(1)), "1") + XCTAssertEqual(try TestDuration_statics.secondsString(dt:.seconds(1)), "1") + XCTAssertEqual(try TestDuration_statics.millisString(dt:.milliseconds(1)), "1") + XCTAssertEqual(try TestDuration_statics.microsString(dt:.microseconds(1)), "1") + XCTAssertEqual(try TestDuration_statics.nanosString(dt:.nanoseconds(1)), "1") + + XCTAssertEqual(try TestDuration_statics.hours(count:1), .hours(1)) + XCTAssertEqual(try TestDuration_statics.minutes(count:1), .minutes(1)) + XCTAssertEqual(try TestDuration_statics.seconds(count:1), .seconds(1)) + XCTAssertEqual(try TestDuration_statics.millis(count:1), .milliseconds(1)) + XCTAssertEqual(try TestDuration_statics.micros(count:1), .microseconds(1)) + XCTAssertEqual(try TestDuration_statics.nanos(count:1), .nanoseconds(1)) + + XCTAssertEqual(try TestDuration_statics.hoursf(count:1.5), .minutes(90)) + XCTAssertEqual(try TestDuration_statics.minutesf(count:1.5), .seconds(90)) + XCTAssertEqual(try TestDuration_statics.secondsf(count:1.5), .milliseconds(1500)) + XCTAssertEqual(try TestDuration_statics.millisf(count:1.5), .microseconds(1500)) + XCTAssertEqual(try TestDuration_statics.microsf(count:1.5), .nanoseconds(1500)) + XCTAssertEqual(try TestDuration_statics.nanosf(count:1.0), .nanoseconds(1)) + + XCTAssertEqual(try TestDuration_statics.box(count:1), .seconds(1)) + XCTAssertNil(try TestDuration_statics.box(count:-1)) + + XCTAssertEqual(try TestDuration_statics.unbox(dt:.seconds(1)), 1) + XCTAssertEqual(try TestDuration_statics.unbox(dt:nil), -1) + } +} diff --git a/test-suite/handwritten-src/swift/EnumTest.swift b/test-suite/handwritten-src/swift/EnumTest.swift new file mode 100644 index 00000000..e2dbab69 --- /dev/null +++ b/test-suite/handwritten-src/swift/EnumTest.swift @@ -0,0 +1,46 @@ +import XCTest +@testable import TestSuite +@testable import TestSuiteBridge + +final class EnumTest: XCTestCase { + + func testEnumToString() { + XCTAssertEqual(String(describing: Color.red), "red") + XCTAssertEqual(String(describing: Color.orange), "orange") + XCTAssertEqual(String(describing: Color.yellow), "yellow") + XCTAssertEqual(String(describing: Color.green), "green") + XCTAssertEqual(String(describing: Color.blue), "blue") + XCTAssertEqual(String(describing: Color.indigo), "indigo") + XCTAssertEqual(String(describing: Color.violet), "violet") + } + + func testEnumKey() throws { + var m = Dictionary() + m[Color.red] = "red" + m[Color.orange] = "orange" + m[Color.yellow] = "yellow" + m[Color.green] = "green" + m[Color.blue] = "blue" + m[Color.indigo] = "indigo" + m[Color.violet] = "violet" + try TestHelpers_statics.checkEnumMap(m:m) + } + + func testAccessFlagRoundtrip() throws { + let flags: [AccessFlags] = [.nobody, .everybody, .ownerRead, [.ownerRead, .ownerWrite], [.ownerRead, .ownerWrite, .ownerExecute]] + for flag in flags { + XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripAccess(flag:flag)) + XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripAccessBoxed(flag:flag)) + } + XCTAssertEqual(nil, try FlagRoundtrip_statics.roundtripAccessBoxed(flag:nil)) + } + + func testEmptyFlagRoundtrip() throws { + let flags: [EmptyFlags] = [.none, .all] + for flag in flags { + XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripEmpty(flag:flag)) + XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripEmptyBoxed(flag:flag)) + } + XCTAssertEqual(nil, try FlagRoundtrip_statics.roundtripEmptyBoxed(flag:nil)) + } +} diff --git a/test-suite/handwritten-src/swift/AllTests.swift b/test-suite/handwritten-src/swift/ExampleTest.swift similarity index 70% rename from test-suite/handwritten-src/swift/AllTests.swift rename to test-suite/handwritten-src/swift/ExampleTest.swift index 13b520a3..cae8886e 100644 --- a/test-suite/handwritten-src/swift/AllTests.swift +++ b/test-suite/handwritten-src/swift/ExampleTest.swift @@ -6,7 +6,7 @@ class MyListener: TextboxListener { deinit { print("*** deinit called") } - func update(items: ItemList) { + func update(items: ItemList) throws { print("*** update() called") print(items) } @@ -15,8 +15,8 @@ class MyListener: TextboxListener { final class AllTests: XCTestCase { func testExample() throws { let listener = MyListener() - let s = SortItems_statics.createWithListener(listener: listener) + let s = try SortItems_statics.createWithListener(listener: listener) let items = ItemList(items: ["bbb", "ccc", "aaa"]) - s.sort(order: SortOrder.ASCENDING, items: items) + try s.sort(order: .ascending, items: items) } } diff --git a/test-suite/handwritten-src/swift/MapRecordTest.swift b/test-suite/handwritten-src/swift/MapRecordTest.swift new file mode 100644 index 00000000..8e7e299f --- /dev/null +++ b/test-suite/handwritten-src/swift/MapRecordTest.swift @@ -0,0 +1,40 @@ +import XCTest +@testable import TestSuite +@testable import TestSuiteBridge + +final class MapRecordTest: XCTestCase { + func testCppMapToSwiftMap() throws { + checkSwiftMap(try TestHelpers_statics.getMap()) + } + + func testEmptyCppMapToSwiftMap() throws { + XCTAssertEqual(0, try TestHelpers_statics.getEmptyMap().count) + } + + func testCppMapListToSwiftMapList() throws { + let sMapListRecord = try TestHelpers_statics.getMapListRecord() + let sMapList = sMapListRecord.mapList + XCTAssertEqual(1, sMapList.count) + checkSwiftMap(sMapList[0]) + } + + func testSwiftMapToCppMap() throws { + XCTAssertTrue(try TestHelpers_statics.checkMap(m:["String1": 1, "String2": 2, "String3": 3])) + } + + func testEmptySwiftMapToCppMap() throws { + XCTAssertTrue(try TestHelpers_statics.checkEmptyMap(m:[:])) + } + + func testSwiftMapListToCppMapList() throws { + let sMapList: [Dictionary] = [["String1": 1, "String2": 2, "String3": 3]] + XCTAssertTrue(try TestHelpers_statics.checkMapListRecord(m:MapListRecord(mapList:sMapList))) + } + + func checkSwiftMap(_ smap: Dictionary) { + XCTAssertEqual(3, smap.count) + XCTAssertEqual(smap["String1"], 1) + XCTAssertEqual(smap["String2"], 2) + XCTAssertEqual(smap["String3"], 3) + } +} diff --git a/test-suite/handwritten-src/swift/NestedCollectionTest.swift b/test-suite/handwritten-src/swift/NestedCollectionTest.swift new file mode 100644 index 00000000..0d55a0ee --- /dev/null +++ b/test-suite/handwritten-src/swift/NestedCollectionTest.swift @@ -0,0 +1,16 @@ +import XCTest +@testable import TestSuite +@testable import TestSuiteBridge + +final class NestedCollectionTest: XCTestCase { + let swiftNestedCollection = NestedCollection(setList: [Set(["String1", "String2"]), Set(["StringA", "StringB"])]) + + func testCppNestedRecordToSwiftNestedCollection() throws { + let converted = try TestHelpers_statics.getNestedCollection() + XCTAssertEqual(swiftNestedCollection.setList, converted.setList) + } + + func testSwiftNestedRecordToCppNestedCollection() throws { + XCTAssertTrue(try TestHelpers_statics.checkNestedCollection(nc:swiftNestedCollection)) + } +} diff --git a/test-suite/handwritten-src/swift/OutcomeTest+Error.swift b/test-suite/handwritten-src/swift/OutcomeTest+Error.swift new file mode 100644 index 00000000..a03371ed --- /dev/null +++ b/test-suite/handwritten-src/swift/OutcomeTest+Error.swift @@ -0,0 +1,2 @@ +extension Int32: Error {} +extension String: Error {} diff --git a/test-suite/handwritten-src/swift/OutcomeTest.swift b/test-suite/handwritten-src/swift/OutcomeTest.swift new file mode 100644 index 00000000..e7cc00ee --- /dev/null +++ b/test-suite/handwritten-src/swift/OutcomeTest.swift @@ -0,0 +1,42 @@ +import XCTest +@testable import TestSuite +@testable import TestSuiteBridge + +final class OutcomeTest: XCTestCase { + func test() throws { + // construct result outcome in native and pass to swift + let r = try TestOutcome_statics.getSuccessOutcome() + XCTAssertEqual(r, Result.success("hello")) + + // construct error outcome in native and pass to swift + let e = try TestOutcome_statics.getErrorOutcome() + XCTAssertEqual(e, Result.failure(42)) + + // result outcome and error outcome does not compare equal + XCTAssertNotEqual(r, e) + + // construct result outcome in swift then pass to native and back + XCTAssertEqual(try TestOutcome_statics.putSuccessOutcome(x:.success("hello")), "hello"); + // construct error outcome in swift then pass to native and back + XCTAssertEqual(try TestOutcome_statics.putErrorOutcome(x:.failure(42)), 42); + + // Hash equal + XCTAssertEqual(r.hashValue, Result.success("hello").hashValue) + XCTAssertEqual(e.hashValue, Result.failure(42).hashValue) + // Hash not equal between result and error + XCTAssertNotEqual(r.hashValue, Result.failure("hello").hashValue) + XCTAssertNotEqual(e.hashValue, Result.success(42).hashValue) + + // test outcome as nested object + let nr = try TestOutcome_statics.getNestedSuccessOutcome() + XCTAssertEqual(nr.o, .success(42)) + XCTAssertEqual(nr, NestedOutcome(o:.success(42))) + + let ne = try TestOutcome_statics.getNestedErrorOutcome() + XCTAssertEqual(ne.o, .failure("hello")) + XCTAssertEqual(ne, NestedOutcome(o:.failure("hello"))) + + XCTAssertEqual(try TestOutcome_statics.putNestedSuccessOutcome(x:NestedOutcome(o:.success(42))), 42) + XCTAssertEqual(try TestOutcome_statics.putNestedErrorOutcome(x:NestedOutcome(o:.failure("hello"))), "hello") + } +} diff --git a/test-suite/handwritten-src/swift/PrimitiveListTest.swift b/test-suite/handwritten-src/swift/PrimitiveListTest.swift new file mode 100644 index 00000000..48dc7093 --- /dev/null +++ b/test-suite/handwritten-src/swift/PrimitiveListTest.swift @@ -0,0 +1,20 @@ +import XCTest +@testable import TestSuite +@testable import TestSuiteBridge + +final class PrimitivesListTest: XCTestCase { + + let swiftPrimitiveList: PrimitiveList = PrimitiveList(list: [1, 2, 3]) + + func testSwiftPrimitiveListToCpp() throws { + XCTAssertTrue(try TestHelpers_statics.checkPrimitiveList(pl:swiftPrimitiveList)) + } + func testCppPrimitiveListToSwift() throws { + let converted = try TestHelpers_statics.getPrimitiveList() + XCTAssertEqual(converted.list, swiftPrimitiveList.list) + } + func testBinary() throws { + let b = Data([1,2,3]) + XCTAssertEqual(try TestHelpers_statics.idBinary(b:b), b) + } +} diff --git a/test-suite/handwritten-src/swift/PrimitivesTest.swift b/test-suite/handwritten-src/swift/PrimitivesTest.swift new file mode 100644 index 00000000..000acb2d --- /dev/null +++ b/test-suite/handwritten-src/swift/PrimitivesTest.swift @@ -0,0 +1,11 @@ +import XCTest +@testable import TestSuite +@testable import TestSuiteBridge + +final class PrimitivesTest: XCTestCase { + func testPrimitives() throws { + let p = AssortedPrimitives(b:true, eight:123, sixteen:20000, thirtytwo:1000000000, sixtyfour:1234567890123456789, fthirtytwo:1.23, fsixtyfour:1.23, + oB:true, oEight:123, oSixteen:20000, oThirtytwo:1000000000, oSixtyfour:1234567890123456789, oFthirtytwo:1.23, oFsixtyfour:1.23) + XCTAssertEqual(p, try TestHelpers_statics.assortedPrimitivesId(i:p)) + } +} diff --git a/test-suite/handwritten-src/swift/ProtoTest.swift b/test-suite/handwritten-src/swift/ProtoTest.swift new file mode 100644 index 00000000..458ab757 --- /dev/null +++ b/test-suite/handwritten-src/swift/ProtoTest.swift @@ -0,0 +1,61 @@ +import XCTest +@testable import ProtobufTest +@testable import TestSuite +@testable import TestSuiteBridge + +typealias Person = Djinni_Test_Person +typealias AddressBook = Djinni_Test_AddressBook + +final class ProtoTest: XCTestCase { + func testSwiftToNative() throws { + let p1 = Person.with {$0.name = "tom"; $0.id = 1} + let p2 = Person.with {$0.name = "jerry"; $0.id = 2} + let proto = AddressBook.with {$0.people = [p1, p2]} + let r = try ProtoTests_statics.protoToStrings(x:proto) + XCTAssertEqual(r[0], "tom") + XCTAssertEqual(r[1], "jerry") + } + + func testNativeToSwift() throws { + let names = ["tom", "jerry"] + let proto = try ProtoTests_statics.stringsToProto(x:names) + XCTAssertEqual(proto.people[0].name, "tom") + XCTAssertEqual(proto.people[1].name, "jerry") + } + + func testZeroSizeNativeToSwift() throws { + let proto = try ProtoTests_statics.stringsToProto(x:[]) + let serialized: Data = try proto.serializedBytes() + XCTAssertEqual(serialized.count, 0) + } + + func testEmbeddedProto() throws { + let p = Person.with {$0.name = "tom"; $0.id = 1} + let rec = RecordWithEmbeddedProto(person:p) + let s = try ProtoTests_statics.embeddedProtoToString(x:rec) + XCTAssertEqual(s, p.name) + let rec2 = try ProtoTests_statics.stringToEmbeddedProto(x:s); + XCTAssertEqual(s, rec2.person.name) + } + + func testBoxing() throws { + let p1 = Person.with {$0.name = "tom"; $0.id = 1} + let p2 = Person.with {$0.name = "jerry"; $0.id = 2} + var plist = [p1, p2] + let slist = try ProtoTests_statics.protoListToStrings(x:plist) + XCTAssertEqual(slist[0], "tom") + XCTAssertEqual(slist[1], "jerry") + + plist = try ProtoTests_statics.stringsToProtoList(x:slist) + XCTAssertEqual(plist[0].name, "tom") + XCTAssertEqual(plist[1].name, "jerry") + + let s = try ProtoTests_statics.optionalProtoToString(x:p1) + XCTAssertEqual(s, "tom") + let p = try ProtoTests_statics.stringToOptionalProto(x:"tom") + XCTAssertEqual(p?.name, "tom") + + let r = try ProtoTests_statics.stringToProtoOutcome(x:"tom") + XCTAssertEqual(try r.get().name, "tom") + } +} diff --git a/test-suite/handwritten-src/swift/SetRecordTest.swift b/test-suite/handwritten-src/swift/SetRecordTest.swift new file mode 100644 index 00000000..28a48ba3 --- /dev/null +++ b/test-suite/handwritten-src/swift/SetRecordTest.swift @@ -0,0 +1,20 @@ +import XCTest +@testable import TestSuite +@testable import TestSuiteBridge + +final class SetRecordTest: XCTestCase { + + func testCppSetToSwiftSet() throws { + let sSetRecord = try TestHelpers_statics.getSetRecord() + let sSet = sSetRecord.set + XCTAssertEqual(3, sSet.count) + XCTAssertTrue(sSet.contains("StringA")) + XCTAssertTrue(sSet.contains("StringB")) + XCTAssertTrue(sSet.contains("StringC")) + } + + func testSwiftSetToCppSet() throws { + let sSetRecord = SetRecord(set: Set(["StringA", "StringB", "StringC"]), iset:Set([])) + XCTAssertTrue(try TestHelpers_statics.checkSetRecord(rec:sSetRecord)) + } +} diff --git a/test-suite/handwritten-src/swift/TokenTest.swift b/test-suite/handwritten-src/swift/TokenTest.swift new file mode 100644 index 00000000..a0f7fd29 --- /dev/null +++ b/test-suite/handwritten-src/swift/TokenTest.swift @@ -0,0 +1,47 @@ +import XCTest +@testable import TestSuite +@testable import TestSuiteBridge + +final class TokenTest: XCTestCase { + + class SwiftToken: UserToken { + func whoami() throws -> String { return "Swift" } + } + + func testTokens() throws { + let st = SwiftToken() + XCTAssertIdentical(try TestHelpers_statics.tokenId(t:st), st) + } + + func testNullToken() throws { + XCTAssertNil(try TestHelpers_statics.tokenId(t:nil)) + } + + func testCppToken() throws { + let ct = try TestHelpers_statics.createCppToken(); + XCTAssertIdentical(try TestHelpers_statics.tokenId(t:ct), ct) + try TestHelpers_statics.checkCppToken(t:ct) + } + + func testTokenType() throws { + try TestHelpers_statics.checkTokenType(t:SwiftToken(), type:"Swift") + try TestHelpers_statics.checkTokenType(t:TestHelpers_statics.createCppToken(), type:"C++"); + var threw = false + do { + try TestHelpers_statics.checkTokenType(t: SwiftToken(), type:"foo") + } catch { + threw = true + } + XCTAssertTrue(threw) + } + + func testNotCppToken() { + var threw = false + do { + try TestHelpers_statics.checkCppToken(t:SwiftToken()) + } catch { + threw = true + } + XCTAssertTrue(threw) + } +} diff --git a/test-suite/handwritten-src/swift/WcharTest.swift b/test-suite/handwritten-src/swift/WcharTest.swift new file mode 100644 index 00000000..f9adc055 --- /dev/null +++ b/test-suite/handwritten-src/swift/WcharTest.swift @@ -0,0 +1,15 @@ +import XCTest +@testable import TestSuite +@testable import TestSuiteBridge + +final class WcharTest: XCTestCase { + let STR1: String = "some string with unicode \u{0000}, \u{263A}, 💩 symbols"; + let STR2: String = "another string with unicode \u{263B}, 💨 symbols"; + + func test() throws { + XCTAssertEqual(try WcharTestHelpers_statics.getRecord().s, STR1) + XCTAssertEqual(try WcharTestHelpers_statics.getString(), STR2) + XCTAssertTrue(try WcharTestHelpers_statics.checkString(str:STR2)) + XCTAssertTrue(try WcharTestHelpers_statics.checkRecord(rec:WcharTestRec(s:STR1))) + } +} diff --git a/test-suite/run_djinni.sh b/test-suite/run_djinni.sh index 1ba73bba..b189fbd4 100755 --- a/test-suite/run_djinni.sh +++ b/test-suite/run_djinni.sh @@ -101,6 +101,12 @@ fi --ts-out "$temp_out_relative/ts" \ --ts-module "test_wchar" \ \ + --swift-out "$temp_out_relative/swift" \ + --swift-module "TestSuite" \ + --swiftxx-out "$temp_out_relative/swiftxx" \ + --ident-swiftxx-class NativeFooBar \ + --ident-swiftxx-file NativeFooBar \ + \ --yaml-out "$temp_out_relative/yaml" \ --yaml-out-file "yaml-test.yaml" \ --yaml-prefix "test_" \ @@ -137,9 +143,9 @@ fi --ts-out "$temp_out_relative/ts" \ --ts-module "test" \ \ - --swift-out "$temp_out/swift" \ + --swift-out "$temp_out_relative/swift" \ --swift-module "TestSuite" \ - --swiftxx-out "$temp_out/swiftxx" \ + --swiftxx-out "$temp_out_relative/swiftxx" \ --ident-swiftxx-class NativeFooBar \ --ident-swiftxx-file NativeFooBar \ \ @@ -306,6 +312,12 @@ cp "$base_dir/djinni/yaml-test.djinni" "$temp_out/yaml" --ts-out "$temp_out_relative/ts" \ --ts-module "test_yaml" \ \ + --swift-out "$temp_out_relative/swift" \ + --swift-module "TestSuite" \ + --swiftxx-out "$temp_out_relative/swiftxx" \ + --ident-swiftxx-class NativeFooBar \ + --ident-swiftxx-file NativeFooBar \ + \ --idl "$temp_out_relative/yaml/yaml-test.djinni" \ ) From bcf8b1c30881398ad632d781be5b12ac59ba2dd2 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 12 Jul 2024 13:30:54 +1000 Subject: [PATCH 22/68] comments --- support-lib/swift/DJData.swift | 7 +- support-lib/swift/DJFuture.swift | 16 +++- support-lib/swift/DJMarshal.swift | 12 ++- support-lib/swift/DJOutcome.swift | 5 ++ support-lib/swift/DjinniSupport.swift | 117 +++++++++++++++---------- support-lib/swiftxx/Future_swift.cpp | 8 +- support-lib/swiftxx/Future_swift.hpp | 109 ++++++++--------------- support-lib/swiftxx/djinni_support.cpp | 1 - support-lib/swiftxx/djinni_support.hpp | 1 + 9 files changed, 146 insertions(+), 130 deletions(-) diff --git a/support-lib/swift/DJData.swift b/support-lib/swift/DJData.swift index c9a0fcc8..6a99b499 100644 --- a/support-lib/swift/DJData.swift +++ b/support-lib/swift/DJData.swift @@ -1,6 +1,10 @@ import DjinniSupportCxx import Foundation +// DataView and DataRef are bridged to `NSData` instead of `Data` because `Data` +// uses small buffer optimization and it does not always provide a stable +// pointer that can be safely accessed in C++ (the pointer we can get from a +// small Data object will only work within the scope of `withUnsafeBytes` block) public enum DataViewMarshaller: Marshaller { public typealias SwiftType = NSData public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { @@ -11,7 +15,8 @@ public enum DataViewMarshaller: Marshaller { return djinni.swift.makeRangeValue(s.bytes, s.length) } } - +// The C++ side implementation of DataRef uses CFData which is toll-free bridged +// to NSData. public enum DataRefMarshaller: Marshaller { public typealias SwiftType = NSData public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { diff --git a/support-lib/swift/DJFuture.swift b/support-lib/swift/DJFuture.swift index 382abe63..b267f28f 100644 --- a/support-lib/swift/DJFuture.swift +++ b/support-lib/swift/DJFuture.swift @@ -2,12 +2,15 @@ import DjinniSupportCxx import Foundation import Combine +// DJinni future<> maps to Combine.Future<> in Swift public typealias DJFuture = Future +// Type erased interface for PromiseHolder because in futureCb() we don't have +// the type parameter. protocol AbstractPromiseHolder: AnyObject { func fulfillPromise(value: UnsafePointer) } - +// The Swift Future wrapper object that can be fulfilled by a C++ call class PromiseHolder: AbstractPromiseHolder { var promise: DJFuture.Promise init(marshaller: T.Type, promise: @escaping DJFuture.Promise) { @@ -21,7 +24,9 @@ class PromiseHolder: AbstractPromiseHolder { } } } - +// A C++ friendly function. This is passed to C++ as the continuation routine of +// the C++ future. It calls the PromiseHolder and forwards the C++ future's +// result or error to the Swift future. public func futureCb( ptr: UnsafeMutableRawPointer?, result: UnsafeMutablePointer?) @@ -31,6 +36,8 @@ public func futureCb( promiseHolder.fulfillPromise(value:result!) } +// A C++ friendly function to release the subscription token stored with the C++ +// future value. public func cleanupCb(psubscription: UnsafeMutableRawPointer?) -> Void { let _ = Unmanaged.fromOpaque(psubscription!).takeRetainedValue() } @@ -39,15 +46,19 @@ public enum FutureMarshaller: Marshaller { public typealias SwiftType = DJFuture public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { return Future() { promise in + // Allocate the Swift future wrapper let promiseHolder = PromiseHolder(marshaller: T.self, promise: promise) let promiseHolderPtr = Unmanaged.passRetained(promiseHolder).toOpaque() + // And connect it with the C++ future withUnsafePointer(to: v) { p in djinni.swift.setFutureCb(p, futureCb, promiseHolderPtr) } } } public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + // Create a C++ future var futureValue = djinni.swift.makeFutureValue(cleanupCb) + // Connect it with the Swift future let subscription = s.sink { completion in if case let .failure(e) = completion { var errorValue = djinni.swift.makeVoidValue() @@ -58,6 +69,7 @@ public enum FutureMarshaller: Marshaller { var cppValue = T.toCpp(v) djinni.swift.setFutureResult(&futureValue, &cppValue) } + // Store the subscription token so that the connection remains alive. let pSubscription = Unmanaged.passRetained(subscription).toOpaque() djinni.swift.storeSubscription(&futureValue, pSubscription) return futureValue diff --git a/support-lib/swift/DJMarshal.swift b/support-lib/swift/DJMarshal.swift index d5d8f574..905f097d 100644 --- a/support-lib/swift/DJMarshal.swift +++ b/support-lib/swift/DJMarshal.swift @@ -1,12 +1,14 @@ import DjinniSupportCxx import Foundation +// Common interface for all Swift type marshallers +// The C++ type is always djinni.swift.AnyValue public protocol Marshaller { associatedtype SwiftType static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue } - +// Djinni generated enums are always backed by Int32 public enum EnumMarshaller: Marshaller where T.RawValue == Int32 { public typealias SwiftType = T public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { @@ -16,7 +18,7 @@ public enum EnumMarshaller: Marshaller where T.RawValue == return djinni.swift.I32.fromCpp(s.rawValue) } } - +// All integer types smaller than 32-bit are handled by this public enum SmallIntMarshaller: Marshaller { public typealias SwiftType = T public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { @@ -26,6 +28,7 @@ public enum SmallIntMarshaller: Marshaller { return djinni.swift.I32.fromCpp(Int32(s)) } } +// 64-bit integer public enum I64Marshaller: Marshaller { public typealias SwiftType = Int64 public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { @@ -35,6 +38,7 @@ public enum I64Marshaller: Marshaller { return djinni.swift.I64.fromCpp(s) } } +// Both float and double are marshalled to double values public enum FloatMarshaller: Marshaller { public typealias SwiftType = T public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { @@ -44,6 +48,7 @@ public enum FloatMarshaller: Marshaller { return djinni.swift.F64.fromCpp(Double(s)) } } +// Bool is marshalled as Int32 (0 or 1) public enum BoolMarshaller: Marshaller { public typealias SwiftType = Bool public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { @@ -53,7 +58,7 @@ public enum BoolMarshaller: Marshaller { return djinni.swift.I32.fromCpp(s ? 1 : 0) } } - +// Aliases for number types public typealias I8Marshaller = SmallIntMarshaller public typealias I16Marshaller = SmallIntMarshaller public typealias I32Marshaller = SmallIntMarshaller @@ -158,6 +163,7 @@ public enum ListMarshaller: Marshaller { } } +// Swift don't need to box primitive types in arrays so they are identical to list public typealias ArrayMarshaller = ListMarshaller public enum SetMarshaller: Marshaller where T.SwiftType: Hashable { diff --git a/support-lib/swift/DJOutcome.swift b/support-lib/swift/DJOutcome.swift index dbc2ca1e..2ce143dc 100644 --- a/support-lib/swift/DJOutcome.swift +++ b/support-lib/swift/DJOutcome.swift @@ -1,6 +1,11 @@ import DjinniSupportCxx import Foundation +// `outcome` is marshalled as a composite value +// 1. If the `outcome` object contains a successful value, then it's the [0] +// element in the composite value +// 2. If the `outcome` object contains an error value, then element [0] is void, +// and element [1] is the error value. public enum OutcomeMarshaller: Marshaller where Err.SwiftType: Error { public typealias SwiftType = Result diff --git a/support-lib/swift/DjinniSupport.swift b/support-lib/swift/DjinniSupport.swift index 09ad6e08..379e90c2 100644 --- a/support-lib/swift/DjinniSupport.swift +++ b/support-lib/swift/DjinniSupport.swift @@ -1,25 +1,39 @@ import DjinniSupportCxx import Foundation +// Define a C++ vtable like data structure for dispatching proxy methods to +// protocol methods. Each entry in the table is function pointer that takes 3 +// parameters +// - The object instance (that conforms to the protocol) +// - The parameter list +// - The return value (output parameter) +// The return value has to be an output parameter instead of the function's +// return type, otherwise the Swift compiler will crash (if this crash is fixed +// in a later version of the compiler, we may change this). public typealias Vtbl = [(T, UnsafePointer?, UnsafeMutablePointer?) throws -> Void] -public class GenericProtocolWrapperContext { - public func dispatch(idx: Int32, params: UnsafePointer?, ret: UnsafeMutablePointer?) -> Void { - fatalError("pure virtual") - } - public func getInst() -> AnyObject { - fatalError("pure virtual") - } +// Type erased interface for ProtocolWrapperContext. We don't have the type +// parameter T for ProtocolWrapperContext inside dispatcherProtocalCall (called +// by C++ code) +protocol GenericProtocolWrapperContext: AnyObject { + func dispatch(idx: Int32, params: UnsafePointer?, ret: UnsafeMutablePointer?) -> Void + func getInst() -> AnyObject } -public final class ProtocolWrapperContext: GenericProtocolWrapperContext { +// The bridge between C++ caller and Swift protocol. We store +// - The object instance (that conforms to our protocol) +// - The dispatch table for each callable method in the protocol +final class ProtocolWrapperContext: GenericProtocolWrapperContext { var inst: T var vtbl: Vtbl - public init(inst: T, vtbl: Vtbl) { + init(inst: T, vtbl: Vtbl) { self.inst = inst self.vtbl = vtbl } - public override func dispatch(idx: Int32, params: UnsafePointer?, ret: UnsafeMutablePointer?) -> Void { + func dispatch(idx: Int32, params: UnsafePointer?, ret: UnsafeMutablePointer?) -> Void { + // No Swift error will cross the language boundary. They are converted + // to `ErrorValue`s which will be translated into C++ exceptions on the + // other side. do { try vtbl[Int(idx)](inst, params, ret) } catch let error as DjinniError { @@ -28,71 +42,85 @@ public final class ProtocolWrapperContext: GenericProtocolWrapperContext { djinni.swift.setErrorMessage(ret, std.string(String(describing: error))) } } - public override func getInst() -> AnyObject { + func getInst() -> AnyObject { return inst as AnyObject } } +// This function has a C++ friendly signature. It is passed to C++ and will be +// used by proxy objects to dispatch protocol calls. public func dispatcherProtocalCall( - ptr: UnsafeMutableRawPointer?, - idx: Int32, - params: UnsafePointer?, - ret: UnsafeMutablePointer?) + ptr: UnsafeMutableRawPointer?, // The Swift protocol wrapper object as an opaque pointer + idx: Int32, // The method index (starting from 0) + params: UnsafePointer?, // Input parameters from C++ caller + ret: UnsafeMutablePointer?) // Return value that will be passed back to C++ -> Void { guard let pctx = ptr else { return } - if (idx < 0) { - // release and destroy the context - let ctx = Unmanaged.fromOpaque(pctx).takeRetainedValue() - print("swift proxy cache before destroy", SwiftProxyCache.shared.mapPtrToProxy) + let ctx = Unmanaged.fromOpaque(pctx).takeUnretainedValue() as! GenericProtocolWrapperContext + if (idx >= 0) { + // Dynamic dispatch on the vtbl. We use `takeUnretainedValue` here + // because we want to keep the wrapper object alive inside the C++ side + // proxy (inherits ProtocolWrapper). + ctx.dispatch(idx: idx, params: params, ret: ret) + } else { + // If the index is negative, release and destroy the context. We do + // this when the C++ side proxy (ProtocolWrapper) is destroyed. let key = Unmanaged.passUnretained(ctx.getInst()).toOpaque() SwiftProxyCache.shared.mapPtrToProxy.removeValue(forKey: key) - print("swift proxy cache after destroy", SwiftProxyCache.shared.mapPtrToProxy) - } else { - // dynamic dispatch on the vtbl - let ctx = Unmanaged.fromOpaque(pctx).takeUnretainedValue() - ctx.dispatch(idx: idx, params: params, ret: ret) } } +// Base class for a Swift callable proxy of a C++ object open class CppProxy { + // Stores a C++ interface. A C++ interface value is a double pointer: + // 1. A shared_ptr<> that keeps the C++ implementation object alive + // 2. A shared_ptr<> to a ProtocolWrapper that facilitates dispatching public var inst: djinni.swift.AnyValue public init(inst: djinni.swift.AnyValue) { self.inst = inst } deinit { - destroyCppProxy(inst) + // Remove the C++ proxy pointer from the proxy cache + withUnsafePointer(to: inst) { p in + let info = djinni.swift.getInterfaceInfo(p) + CppProxyCache.shared.mapPtrToProxy.removeValue(forKey: info.cppPointer) + } } } class CppProxyCache { static let shared = CppProxyCache() - // c++ objects in swift + // C++ objects in swift. + // Key: raw C++ implementation object pointer + // Value: Swift callable proxy converted to an *Unretained* (weak) opaque pointer var mapPtrToProxy: [UnsafeRawPointer: UnsafeMutableRawPointer] = [:] } class SwiftProxyCache { static let shared = SwiftProxyCache() - // swift objects in c++ + // Swift objects in c++ + // Key: Swift implementation object converted to an *Unretained* opaque pointer + // Value : Weak proxy, no ownership, but can be converted to a C++ callable strong proxy var mapPtrToProxy: [UnsafeMutableRawPointer: djinni.swift.WeakSwiftProxy] = [:] } -// 1. object is a an existing cpp proxy : return cpp proxy -// 2. object is a an existing swift proxy: unwrap the original swift object -// 3. need to create a new proxy : call newProxyFunc +// 1. Object is a an existing cpp proxy : return cpp proxy +// 2. Object is a an existing swift proxy: unwrap the original swift object +// 3. Need to create a new proxy : call newProxyFunc public func cppInterfaceToSwift(_ c: djinni.swift.AnyValue, _ newProxyFunc: ()->I) -> I { return withUnsafePointer(to: c) { p in let info = djinni.swift.getInterfaceInfo(p) - // for 1. check the cpp proxy cache + // 1. Check the CppProxyCache if let s = CppProxyCache.shared.mapPtrToProxy[info.cppPointer] { return Unmanaged.fromOpaque(s).takeUnretainedValue() as! I } - // for 2. check if c++ ptr exists in SwiftProxyCache.mapCPtrToSwift + // 2. Check if c++ ptr exists in SwiftProxyCache if let pctx = info.ctxPointer { - let ctx = Unmanaged.fromOpaque(pctx).takeUnretainedValue() + let ctx = Unmanaged.fromOpaque(pctx).takeUnretainedValue() as! GenericProtocolWrapperContext return ctx.getInst() as! I } - // 3. + // 3. Create new proxy and store unretained (weak) pointer in CppProxyCache let newProxy = newProxyFunc() CppProxyCache.shared.mapPtrToProxy[info.cppPointer] = Unmanaged.passUnretained(newProxy as AnyObject).toOpaque() return newProxy @@ -104,35 +132,31 @@ public func cppInterfaceToSwift(_ c: djinni.swift.AnyValue, // 3. need to create a new proxy : call newProxyFunc public func swiftInterfaceToCpp(_ s: I, _ newProxyFunc: ()->djinni.swift.AnyValue) -> djinni.swift.AnyValue { - // 1. try cast to CppProxy and unwrap + // 1. Try cast to CppProxy and unwrap if let cppproxy = s as? CppProxy { return cppproxy.inst } - // 2. check swift proxy cache + // 2. Check swift proxy cache let key = Unmanaged.passUnretained(s as AnyObject).toOpaque() if let weakProxy = SwiftProxyCache.shared.mapPtrToProxy[key] { return djinni.swift.strongify(weakProxy) } - // 3. + // 3. Create new proxy and store weak reference in SwiftProxyCache let newProxy = newProxyFunc() SwiftProxyCache.shared.mapPtrToProxy[key] = djinni.swift.weakify(newProxy) return newProxy } +// Shortcut function to create a Swift protocol wrapper context and return its +// *Retained* pointer. The returned pointer is owned by the C++ side +// ProtocolWrapper, and released in ProtocolWrapper::~ProtocolWrapper() by +// sending a dispatch request with index -1. public func ctxPtr (_ s: I, _ vtbl: Vtbl) -> UnsafeMutableRawPointer { let ctx = ProtocolWrapperContext(inst: s, vtbl: vtbl) return Unmanaged.passRetained(ctx).toOpaque() } -public func destroyCppProxy(_ inst: djinni.swift.AnyValue) { - withUnsafePointer(to: inst) { p in - let info = djinni.swift.getInterfaceInfo(p) - print("before destroy cppproxycache entry", CppProxyCache.shared.mapPtrToProxy) - CppProxyCache.shared.mapPtrToProxy.removeValue(forKey: info.cppPointer) - print("after destroy cppproxycache entry", CppProxyCache.shared.mapPtrToProxy) - } -} - +// Wraps C++ ErrorValue as a Swift throwable Error public class DjinniError: Error { var wrapped: djinni.swift.ErrorValue init(_ wrapped: djinni.swift.ErrorValue) { @@ -144,6 +168,7 @@ public class DjinniError: Error { public var errorMessage: String { return String(wrapped.msg) } } +// Called by stubs to convert C++ exceptions stored as ErrorValue to Swift errors public func handleCppErrors(_ ret: UnsafePointer) throws { if (djinni.swift.isError(ret)) { throw DjinniError(djinni.swift.getError(ret)) diff --git a/support-lib/swiftxx/Future_swift.cpp b/support-lib/swiftxx/Future_swift.cpp index 160e0b27..8fa74d50 100644 --- a/support-lib/swiftxx/Future_swift.cpp +++ b/support-lib/swiftxx/Future_swift.cpp @@ -3,22 +3,22 @@ namespace djinni::swift { void setFutureCb(const AnyValue* futureValue, FutureCb cb, void* ctx) { - auto holder = std::dynamic_pointer_cast(std::get(*futureValue)); + auto holder = std::dynamic_pointer_cast(std::get(*futureValue)); holder->setFutureCb(cb, ctx); } AnyValue makeFutureValue(CleanupCb cleanup) { - OpaqueValuePtr holder = std::make_shared>(cleanup); + OpaqueValuePtr holder = std::make_shared(cleanup); return {holder}; } void setFutureResult(const AnyValue* futureValue, const AnyValue* futureResult) { - auto holder = std::dynamic_pointer_cast>(std::get(*futureValue)); + auto holder = std::dynamic_pointer_cast(std::get(*futureValue)); holder->setValue(futureResult); } void storeSubscription(const AnyValue* futureValue, void* subscription) { - auto holder = std::dynamic_pointer_cast>(std::get(*futureValue)); + auto holder = std::dynamic_pointer_cast(std::get(*futureValue)); holder->subscription = subscription; } diff --git a/support-lib/swiftxx/Future_swift.hpp b/support-lib/swiftxx/Future_swift.hpp index 5d04316a..93ab028d 100644 --- a/support-lib/swiftxx/Future_swift.hpp +++ b/support-lib/swiftxx/Future_swift.hpp @@ -5,41 +5,38 @@ namespace djinni::swift { +// Swift function prototypes called by C++ typedef void (*FutureCb)(void* ctx, AnyValue* result); typedef void (*CleanupCb)(void* subscription); -struct AbstractFutureHolder: OpaqueValue { - virtual ~AbstractFutureHolder() = default; +// C++ function declarations called by Swift +void setFutureCb(const AnyValue* futureValue, FutureCb cb, void* ctx); +AnyValue makeFutureValue(CleanupCb cleanup); +void setFutureResult(const AnyValue* futureValue, const AnyValue* futureResult); +void storeSubscription(const AnyValue* futureValue, void* subscription); + +// Common interface for a Swift accessible C++ future +struct AbstractCppFutureHolder: OpaqueValue { + virtual ~AbstractCppFutureHolder() = default; virtual void setFutureCb(FutureCb cb, void* ctx) = 0; }; +// Holds a C++ future that returns a RESULT type template -struct FutureHolder: AbstractFutureHolder { +struct CppFutureHolder: AbstractCppFutureHolder { using CppResType = typename RESULT::CppType; djinni::Future future; - explicit FutureHolder(djinni::Future f) : future(std::move(f)) {} + explicit CppFutureHolder(djinni::Future f) : future(std::move(f)) {} - void setFutureCb(FutureCb cb, void* ctx) override { - future.then([cb, ctx] (Future f) { - try { - auto v = RESULT::fromCpp(f.get()); - cb(ctx, &v); - } catch (ErrorValue& e) { - AnyValue errorValue = e; - cb(ctx, &errorValue); - } - }); - } -}; -template<> -struct FutureHolder: AbstractFutureHolder { - djinni::Future future; - explicit FutureHolder(djinni::Future f) : future(std::move(f)) {} + template + static AnyValue getFutureResult(Future& f) {return RESULT::fromCpp(f.get());} + template<> + static AnyValue getFutureResult(Future& f) {return makeVoidValue();} void setFutureCb(FutureCb cb, void* ctx) override { - future.then([cb, ctx] (Future f) { + future.then([cb, ctx] (Future f) { try { - auto v = makeVoidValue(); + auto v = getFutureResult(f); cb(ctx, &v); } catch (ErrorValue& e) { AnyValue errorValue = e; @@ -49,30 +46,19 @@ struct FutureHolder: AbstractFutureHolder { } }; -void setFutureCb(const AnyValue* futureValue, FutureCb cb, void* ctx); -AnyValue makeFutureValue(CleanupCb cleanup); -void setFutureResult(const AnyValue* futureValue, const AnyValue* futureResult); -void storeSubscription(const AnyValue* futureValue, void* subscription); - -struct AnyValueFutureAdapter { - using CppType = AnyValue; - static AnyValue fromCpp(CppType c) {return c;} -}; - -template<> -struct FutureHolder: AbstractFutureHolder { +// Maintains the link from a Swift future to a C++ accessible future +struct SwiftFutureHolder: OpaqueValue { djinni::Promise promise; std::shared_ptr> future; void* subscription = nullptr; CleanupCb cleanup; - FutureHolder(CleanupCb cleanup) { + SwiftFutureHolder(CleanupCb cleanup) { this->cleanup = cleanup; this->future = std::make_shared>(promise.getFuture()); } - ~FutureHolder() { + ~SwiftFutureHolder() override { cleanup(subscription); } - void setFutureCb(FutureCb cb, void* ctx) override {} void setValue(const AnyValue* futureValue) { promise.setValue(*futureValue); } @@ -82,61 +68,38 @@ template class FutureAdaptor { using CppResType = typename RESULT::CppType; + + template + static void setValue(Promise& p, const AnyValue& res) {p.setValue(RESULT::toCpp(res));} + template<> + static void setValue(Promise& p, const AnyValue& res) {p.setValue();} public: using CppType = Future; static CppType toCpp(const AnyValue& o) { - auto holder = std::dynamic_pointer_cast>(std::get(o)); + // If already a C++ future (can this happen?), just return the wrapped future + auto holder = std::dynamic_pointer_cast>(std::get(o)); if (holder) { return std::move(holder->future); } - auto anyHolder = std::dynamic_pointer_cast>(std::get(o)); + // Acquire the holder for Swift future + auto swiftHolder = std::dynamic_pointer_cast(std::get(o)); Promise p; auto f = p.getFuture(); - anyHolder->future->then([p = std::move(p)] (Future f) mutable { - auto res = f.get(); - if (std::holds_alternative(res)) { - const auto& e = std::get(res); - p.setException(e); - } else { - p.setValue(RESULT::toCpp(res)); - } - }); - return f; - } - static AnyValue fromCpp(CppType c) { - OpaqueValuePtr holder = std::make_shared>(std::move(c)); - return {holder}; - } -}; - -template <> -class FutureAdaptor -{ -public: - using CppType = Future; - - static CppType toCpp(const AnyValue& o) { - auto holder = std::dynamic_pointer_cast>(std::get(o)); - if (holder) { - return std::move(holder->future); - } - auto anyHolder = std::dynamic_pointer_cast>(std::get(o)); - Promise p; - auto f = p.getFuture(); - anyHolder->future->then([p = std::move(p)] (Future f) mutable { + // And return a C++ future connected to it + swiftHolder->future->then([p = std::move(p)] (Future f) mutable { auto res = f.get(); if (std::holds_alternative(res)) { const auto& e = std::get(res); p.setException(e); } else { - p.setValue(); + setValue(p, res); } }); return f; } static AnyValue fromCpp(CppType c) { - OpaqueValuePtr holder = std::make_shared>(std::move(c)); + OpaqueValuePtr holder = std::make_shared>(std::move(c)); return {holder}; } }; diff --git a/support-lib/swiftxx/djinni_support.cpp b/support-lib/swiftxx/djinni_support.cpp index 683aa5e2..ca97a656 100644 --- a/support-lib/swiftxx/djinni_support.cpp +++ b/support-lib/swiftxx/djinni_support.cpp @@ -69,7 +69,6 @@ AnyValue strongify(const WeakSwiftProxy& v) { InterfaceInfo getInterfaceInfo(const AnyValue* v) { auto i = std::get(*v); - // return {i.ptr.get(), i.sptr.get()}; return {i.ptr.get(), i.sptr ? i.sptr->ctx() : nullptr }; } diff --git a/support-lib/swiftxx/djinni_support.hpp b/support-lib/swiftxx/djinni_support.hpp index 1ad2af37..0045e2b3 100644 --- a/support-lib/swiftxx/djinni_support.hpp +++ b/support-lib/swiftxx/djinni_support.hpp @@ -79,6 +79,7 @@ struct CompositeValue { struct ParameterList: CompositeValue {}; +// Swift callable functions AnyValue makeStringValue(const char* bytes, size_t size); AnyValue makeBinaryValue(const void* bytes, size_t size); RangeValue getBinaryRange(const AnyValue& v); From f98a415c9048248ca82067013da77175dbec57bc Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 12 Jul 2024 14:11:43 +1000 Subject: [PATCH 23/68] skip label for first parameter --- .../swift/ItemList+Private.swift | 5 +- .../swift/SortItems+Private.swift | 10 ++-- examples/generated-src/swift/SortItems.swift | 2 +- .../swift/TextboxListener+Private.swift | 4 +- .../generated-src/swift/TextboxListener.swift | 2 +- src/source/SwiftGenerator.scala | 9 +++- .../swift/AsyncInterface+Private.swift | 2 +- .../generated-src/swift/AsyncInterface.swift | 2 +- .../swift/ClientInterface+Private.swift | 8 +-- .../generated-src/swift/ClientInterface.swift | 8 +-- .../swift/ConflictUser+Private.swift | 2 +- .../generated-src/swift/ConflictUser.swift | 2 +- .../swift/CppException+Private.swift | 4 +- .../generated-src/swift/CppException.swift | 4 +- .../swift/DataRefTest+Private.swift | 6 +-- .../generated-src/swift/DataRefTest.swift | 6 +-- .../swift/EnumUsageInterface+Private.swift | 10 ++-- .../swift/EnumUsageInterface.swift | 10 ++-- .../swift/ExternInterface1+Private.swift | 4 +- .../swift/ExternInterface1.swift | 4 +- .../swift/ExternInterface2.swift | 2 +- .../swift/FlagRoundtrip+Private.swift | 8 +-- ...InterfaceUsingExtendedRecord+Private.swift | 2 +- .../swift/InterfaceUsingExtendedRecord.swift | 2 +- .../swift/ListenerCaller+Private.swift | 2 +- .../swift/ProtoTests+Private.swift | 26 +++++----- .../ReverseClientInterface+Private.swift | 4 +- .../swift/ReverseClientInterface.swift | 4 +- .../swift/TestArray+Private.swift | 8 +-- .../swift/TestDuration+Private.swift | 40 +++++++------- .../swift/TestHelpers+Private.swift | 52 +++++++++---------- .../swift/TestOutcome+Private.swift | 8 +-- .../UsesSingleLanguageListeners+Private.swift | 4 +- .../swift/UsesSingleLanguageListeners.swift | 4 +- .../swift/VarnameInterface+Private.swift | 4 +- .../swift/VarnameInterface.swift | 4 +- .../swift/WcharTestHelpers+Private.swift | 4 +- .../handwritten-src/swift/ArrayTest.swift | 8 +-- .../handwritten-src/swift/AsyncTest.swift | 16 +++--- .../swift/ClientInterfaceTest.swift | 18 +++---- .../swift/CppExceptionTest.swift | 2 +- .../handwritten-src/swift/DataTest.swift | 6 +-- .../handwritten-src/swift/DurationTest.swift | 44 ++++++++-------- .../handwritten-src/swift/EnumTest.swift | 14 ++--- .../handwritten-src/swift/ExampleTest.swift | 6 +-- .../handwritten-src/swift/MapRecordTest.swift | 6 +-- .../swift/NestedCollectionTest.swift | 2 +- .../handwritten-src/swift/OutcomeTest.swift | 8 +-- .../swift/PrimitiveListTest.swift | 4 +- .../swift/PrimitivesTest.swift | 2 +- .../handwritten-src/swift/ProtoTest.swift | 20 +++---- .../handwritten-src/swift/SetRecordTest.swift | 2 +- .../handwritten-src/swift/TokenTest.swift | 16 +++--- .../handwritten-src/swift/WcharTest.swift | 4 +- 54 files changed, 234 insertions(+), 226 deletions(-) diff --git a/examples/generated-src/swift/ItemList+Private.swift b/examples/generated-src/swift/ItemList+Private.swift index d31eccc5..170259cf 100644 --- a/examples/generated-src/swift/ItemList+Private.swift +++ b/examples/generated-src/swift/ItemList+Private.swift @@ -2,12 +2,13 @@ // This file was generated by Djinni from example.djinni import DjinniSupport -import Foundation import DjinniSupportCxx +import Foundation import TextSort +import TextSortCxx enum ItemListMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = ItemList + typealias SwiftType = TextSort.ItemList static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let items = ListMarshaller.fromCpp(djinni.swift.getMember(p, 0)) diff --git a/examples/generated-src/swift/SortItems+Private.swift b/examples/generated-src/swift/SortItems+Private.swift index f654a427..1d64c57f 100644 --- a/examples/generated-src/swift/SortItems+Private.swift +++ b/examples/generated-src/swift/SortItems+Private.swift @@ -7,9 +7,9 @@ import Foundation import TextSort import TextSortCxx -final class SortItemsCppProxy: DjinniSupport.CppProxy, SortItems { +final class SortItemsCppProxy: DjinniSupport.CppProxy, TextSort.SortItems { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } - func sort(order: TextSort.SortOrder, items: TextSort.ItemList) throws -> Void { + func sort(_ order: TextSort.SortOrder, items: TextSort.ItemList) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(SortOrderMarshaller.toCpp(order)) @@ -19,7 +19,7 @@ final class SortItemsCppProxy: DjinniSupport.CppProxy, SortItems { } } enum SortItemsMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = SortItems + typealias SwiftType = TextSort.SortItems static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { SortItemsCppProxy(c) as SwiftType }) } @@ -28,14 +28,14 @@ enum SortItemsMarshaller: DjinniSupport.Marshaller { } } public class SortItems_statics { - static func createWithListener(listener: TextSort.TextboxListener) throws -> TextSort.SortItems { + static func createWithListener(_ listener: TextSort.TextboxListener) throws -> TextSort.SortItems { var params = djinni.swift.ParameterList() params.addValue(TextboxListenerMarshaller.toCpp(listener)) var ret = djinni_generated.SortItems_createWithListener(¶ms) try handleCppErrors(&ret) return SortItemsMarshaller.fromCpp(ret) } - static func runSort(items: TextSort.ItemList) throws -> TextSort.ItemList { + static func runSort(_ items: TextSort.ItemList) throws -> TextSort.ItemList { var params = djinni.swift.ParameterList() params.addValue(ItemListMarshaller.toCpp(items)) var ret = djinni_generated.SortItems_runSort(¶ms) diff --git a/examples/generated-src/swift/SortItems.swift b/examples/generated-src/swift/SortItems.swift index d4aace50..ee378fa8 100644 --- a/examples/generated-src/swift/SortItems.swift +++ b/examples/generated-src/swift/SortItems.swift @@ -5,5 +5,5 @@ import Foundation public protocol SortItems: AnyObject { /** For the iOS / Android demo */ - func sort(order: TextSort.SortOrder, items: TextSort.ItemList) throws -> Void + func sort(_ order: TextSort.SortOrder, items: TextSort.ItemList) throws -> Void } diff --git a/examples/generated-src/swift/TextboxListener+Private.swift b/examples/generated-src/swift/TextboxListener+Private.swift index 3694bcba..5fe251b2 100644 --- a/examples/generated-src/swift/TextboxListener+Private.swift +++ b/examples/generated-src/swift/TextboxListener+Private.swift @@ -10,12 +10,12 @@ import TextSortCxx let textboxListenerMethods: Vtbl = [ { inst, params, ret in let _items = ItemListMarshaller.fromCpp(djinni.swift.getMember(params, 0)) - try inst.update(items: _items) + try inst.update(_items) }, ] enum TextboxListenerMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TextboxListener + typealias SwiftType = TextSort.TextboxListener static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { fatalError("n/a") }) } diff --git a/examples/generated-src/swift/TextboxListener.swift b/examples/generated-src/swift/TextboxListener.swift index 8e4665dc..c0a97509 100644 --- a/examples/generated-src/swift/TextboxListener.swift +++ b/examples/generated-src/swift/TextboxListener.swift @@ -4,5 +4,5 @@ import Foundation public protocol TextboxListener: AnyObject { - func update(items: TextSort.ItemList) throws -> Void + func update(_ items: TextSort.ItemList) throws -> Void } diff --git a/src/source/SwiftGenerator.scala b/src/source/SwiftGenerator.scala index b2bbf307..a4b7f43c 100644 --- a/src/source/SwiftGenerator.scala +++ b/src/source/SwiftGenerator.scala @@ -240,6 +240,8 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { for (m <- i.methods.filter(!_.static)) { writeMethodDoc(w, m, idSwift.local) w.w(s"func ${swiftMethodName(m.ident)}(") + // skip label for the first parameter + if (m.params.nonEmpty) { w.w("_ ") } w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.fqParamType(p.ty)}").mkString(", ")) w.wl(s") throws -> ${marshal.fqReturnType(m.ret)}") } @@ -253,6 +255,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { w.wl("init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } ") for (m <- i.methods.filter(!_.static)) { w.w(s"func ${swiftMethodName(m.ident)}(") + if (m.params.nonEmpty) { w.w("_ ") } w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.fqParamType(p.ty)}").mkString(", ")) w.w(s") throws -> ${marshal.fqReturnType(m.ret)}").braced { w.wl("var params = djinni.swift.ParameterList()") @@ -280,7 +283,10 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { val pi = s"djinni.swift.getMember(params, $i)" w.wl(s"let _${idSwift.local(p.ident)} = ${marshal.fromCpp(p.ty, pi)}") } - val args = m.params.map(p => s"${idSwift.local(p.ident)}: _${idSwift.local(p.ident)}").mkString(", ") + val args = m.params.view.zipWithIndex.map{case (p, i) => + val label = if (i==0) "" else s"${idSwift.local(p.ident)}: " + label + s"_${idSwift.local(p.ident)}" + }.mkString(", ") val call = s"inst.${swiftMethodName(m.ident)}(${args})" if (m.ret.isEmpty) { w.wl("try " + call) @@ -312,6 +318,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { w.w(s"public class ${marshal.typename(ident, i)}_statics").braced { for (m <- staticMethods) { w.w(s"static func ${swiftMethodName(m.ident)}(") + if (m.params.nonEmpty) { w.w("_ ") } w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.fqParamType(p.ty)}").mkString(", ")) w.w(s") throws -> ${marshal.fqReturnType(m.ret)}").braced { w.wl("var params = djinni.swift.ParameterList()") diff --git a/test-suite/generated-src/swift/AsyncInterface+Private.swift b/test-suite/generated-src/swift/AsyncInterface+Private.swift index 8908389d..348f78a8 100644 --- a/test-suite/generated-src/swift/AsyncInterface+Private.swift +++ b/test-suite/generated-src/swift/AsyncInterface+Private.swift @@ -10,7 +10,7 @@ import TestSuiteCxx let asyncInterfaceMethods: Vtbl = [ { inst, params, ret in let _f = FutureMarshaller.fromCpp(djinni.swift.getMember(params, 0)) - djinni.swift.setReturnValue(ret, try FutureMarshaller.toCpp(inst.futureRoundtrip(f: _f))) + djinni.swift.setReturnValue(ret, try FutureMarshaller.toCpp(inst.futureRoundtrip(_f))) }, ] diff --git a/test-suite/generated-src/swift/AsyncInterface.swift b/test-suite/generated-src/swift/AsyncInterface.swift index a5f04b2c..c248391d 100644 --- a/test-suite/generated-src/swift/AsyncInterface.swift +++ b/test-suite/generated-src/swift/AsyncInterface.swift @@ -5,5 +5,5 @@ import DjinniSupport import Foundation public protocol AsyncInterface: AnyObject { - func futureRoundtrip(f: DJFuture) throws -> DJFuture + func futureRoundtrip(_ f: DJFuture) throws -> DJFuture } diff --git a/test-suite/generated-src/swift/ClientInterface+Private.swift b/test-suite/generated-src/swift/ClientInterface+Private.swift index 97ceddb5..516b6cc6 100644 --- a/test-suite/generated-src/swift/ClientInterface+Private.swift +++ b/test-suite/generated-src/swift/ClientInterface+Private.swift @@ -13,24 +13,24 @@ let clientInterfaceMethods: Vtbl = [ let _recordId = I64Marshaller.fromCpp(djinni.swift.getMember(params, 0)) let _utf8string = StringMarshaller.fromCpp(djinni.swift.getMember(params, 1)) let _misc = OptionalMarshaller.fromCpp(djinni.swift.getMember(params, 2)) - djinni.swift.setReturnValue(ret, try ClientReturnedRecordMarshaller.toCpp(inst.getRecord(recordId: _recordId, utf8string: _utf8string, misc: _misc))) + djinni.swift.setReturnValue(ret, try ClientReturnedRecordMarshaller.toCpp(inst.getRecord(_recordId, utf8string: _utf8string, misc: _misc))) }, { inst, params, ret in let _data = BinaryMarshaller.fromCpp(djinni.swift.getMember(params, 0)) let _r = I32Marshaller.fromCpp(djinni.swift.getMember(params, 1)) let _jret = I64Marshaller.fromCpp(djinni.swift.getMember(params, 2)) - djinni.swift.setReturnValue(ret, try F64Marshaller.toCpp(inst.identifierCheck(data: _data, r: _r, jret: _jret))) + djinni.swift.setReturnValue(ret, try F64Marshaller.toCpp(inst.identifierCheck(_data, r: _r, jret: _jret))) }, { inst, params, ret in djinni.swift.setReturnValue(ret, try StringMarshaller.toCpp(inst.returnStr())) }, { inst, params, ret in let _i = ClientInterfaceMarshaller.fromCpp(djinni.swift.getMember(params, 0)) - djinni.swift.setReturnValue(ret, try StringMarshaller.toCpp(inst.methTakingInterface(i: _i))) + djinni.swift.setReturnValue(ret, try StringMarshaller.toCpp(inst.methTakingInterface(_i))) }, { inst, params, ret in let _i = OptionalMarshaller.fromCpp(djinni.swift.getMember(params, 0)) - djinni.swift.setReturnValue(ret, try StringMarshaller.toCpp(inst.methTakingOptionalInterface(i: _i))) + djinni.swift.setReturnValue(ret, try StringMarshaller.toCpp(inst.methTakingOptionalInterface(_i))) }, ] diff --git a/test-suite/generated-src/swift/ClientInterface.swift b/test-suite/generated-src/swift/ClientInterface.swift index fd36ddd1..74a7f072 100644 --- a/test-suite/generated-src/swift/ClientInterface.swift +++ b/test-suite/generated-src/swift/ClientInterface.swift @@ -6,9 +6,9 @@ import Foundation /** Client interface */ public protocol ClientInterface: AnyObject { /** Returns record of given string */ - func getRecord(recordId: Int64, utf8string: String, misc: Optional) throws -> TestSuite.ClientReturnedRecord - func identifierCheck(data: Data, r: Int32, jret: Int64) throws -> Double + func getRecord(_ recordId: Int64, utf8string: String, misc: Optional) throws -> TestSuite.ClientReturnedRecord + func identifierCheck(_ data: Data, r: Int32, jret: Int64) throws -> Double func returnStr() throws -> String - func methTakingInterface(i: TestSuite.ClientInterface) throws -> String - func methTakingOptionalInterface(i: Optional) throws -> String + func methTakingInterface(_ i: TestSuite.ClientInterface) throws -> String + func methTakingOptionalInterface(_ i: Optional) throws -> String } diff --git a/test-suite/generated-src/swift/ConflictUser+Private.swift b/test-suite/generated-src/swift/ConflictUser+Private.swift index f73c9df3..506285d8 100644 --- a/test-suite/generated-src/swift/ConflictUser+Private.swift +++ b/test-suite/generated-src/swift/ConflictUser+Private.swift @@ -16,7 +16,7 @@ final class ConflictUserCppProxy: DjinniSupport.CppProxy, TestSuite.ConflictUser try handleCppErrors(&ret) return ConflictMarshaller.fromCpp(ret) } - func conflictArg(cs: Array) throws -> Bool { + func conflictArg(_ cs: Array) throws -> Bool { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(ListMarshaller.toCpp(cs)) diff --git a/test-suite/generated-src/swift/ConflictUser.swift b/test-suite/generated-src/swift/ConflictUser.swift index 79d870ec..7a5d7f90 100644 --- a/test-suite/generated-src/swift/ConflictUser.swift +++ b/test-suite/generated-src/swift/ConflictUser.swift @@ -5,5 +5,5 @@ import Foundation public protocol ConflictUser: AnyObject { func Conflict() throws -> TestSuite.Conflict - func conflictArg(cs: Array) throws -> Bool + func conflictArg(_ cs: Array) throws -> Bool } diff --git a/test-suite/generated-src/swift/CppException+Private.swift b/test-suite/generated-src/swift/CppException+Private.swift index 93b7b243..c4f95dce 100644 --- a/test-suite/generated-src/swift/CppException+Private.swift +++ b/test-suite/generated-src/swift/CppException+Private.swift @@ -16,7 +16,7 @@ final class CppExceptionCppProxy: DjinniSupport.CppProxy, TestSuite.CppException try handleCppErrors(&ret) return I32Marshaller.fromCpp(ret) } - func callThrowingInterface(cb: TestSuite.ThrowingInterface) throws -> Int32 { + func callThrowingInterface(_ cb: TestSuite.ThrowingInterface) throws -> Int32 { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(ThrowingInterfaceMarshaller.toCpp(cb)) @@ -24,7 +24,7 @@ final class CppExceptionCppProxy: DjinniSupport.CppProxy, TestSuite.CppException try handleCppErrors(&ret) return I32Marshaller.fromCpp(ret) } - func callThrowingAndCatch(cb: TestSuite.ThrowingInterface) throws -> String { + func callThrowingAndCatch(_ cb: TestSuite.ThrowingInterface) throws -> String { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(ThrowingInterfaceMarshaller.toCpp(cb)) diff --git a/test-suite/generated-src/swift/CppException.swift b/test-suite/generated-src/swift/CppException.swift index 7c578d25..08b1c0a5 100644 --- a/test-suite/generated-src/swift/CppException.swift +++ b/test-suite/generated-src/swift/CppException.swift @@ -5,6 +5,6 @@ import Foundation public protocol CppException: AnyObject { func throwAnException() throws -> Int32 - func callThrowingInterface(cb: TestSuite.ThrowingInterface) throws -> Int32 - func callThrowingAndCatch(cb: TestSuite.ThrowingInterface) throws -> String + func callThrowingInterface(_ cb: TestSuite.ThrowingInterface) throws -> Int32 + func callThrowingAndCatch(_ cb: TestSuite.ThrowingInterface) throws -> String } diff --git a/test-suite/generated-src/swift/DataRefTest+Private.swift b/test-suite/generated-src/swift/DataRefTest+Private.swift index 34c89c90..dc2f42be 100644 --- a/test-suite/generated-src/swift/DataRefTest+Private.swift +++ b/test-suite/generated-src/swift/DataRefTest+Private.swift @@ -9,7 +9,7 @@ import TestSuiteCxx final class DataRefTestCppProxy: DjinniSupport.CppProxy, TestSuite.DataRefTest { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } - func sendData(data: NSData) throws -> Void { + func sendData(_ data: NSData) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(DataRefMarshaller.toCpp(data)) @@ -23,7 +23,7 @@ final class DataRefTestCppProxy: DjinniSupport.CppProxy, TestSuite.DataRefTest { try handleCppErrors(&ret) return BinaryMarshaller.fromCpp(ret) } - func sendMutableData(data: NSData) throws -> Void { + func sendMutableData(_ data: NSData) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(DataRefMarshaller.toCpp(data)) @@ -51,7 +51,7 @@ final class DataRefTestCppProxy: DjinniSupport.CppProxy, TestSuite.DataRefTest { try handleCppErrors(&ret) return DataRefMarshaller.fromCpp(ret) } - func sendDataView(data: NSData) throws -> Data { + func sendDataView(_ data: NSData) throws -> Data { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(DataViewMarshaller.toCpp(data)) diff --git a/test-suite/generated-src/swift/DataRefTest.swift b/test-suite/generated-src/swift/DataRefTest.swift index cf9f06fc..350bd74c 100644 --- a/test-suite/generated-src/swift/DataRefTest.swift +++ b/test-suite/generated-src/swift/DataRefTest.swift @@ -4,12 +4,12 @@ import Foundation public protocol DataRefTest: AnyObject { - func sendData(data: NSData) throws -> Void + func sendData(_ data: NSData) throws -> Void func retriveAsBin() throws -> Data - func sendMutableData(data: NSData) throws -> Void + func sendMutableData(_ data: NSData) throws -> Void func generateData() throws -> NSData func dataFromVec() throws -> NSData func dataFromStr() throws -> NSData - func sendDataView(data: NSData) throws -> Data + func sendDataView(_ data: NSData) throws -> Data func recvDataView() throws -> NSData } diff --git a/test-suite/generated-src/swift/EnumUsageInterface+Private.swift b/test-suite/generated-src/swift/EnumUsageInterface+Private.swift index 5ee3399e..df7bf877 100644 --- a/test-suite/generated-src/swift/EnumUsageInterface+Private.swift +++ b/test-suite/generated-src/swift/EnumUsageInterface+Private.swift @@ -9,7 +9,7 @@ import TestSuiteCxx final class EnumUsageInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.EnumUsageInterface { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } - func e(e: TestSuite.Color) throws -> TestSuite.Color { + func e(_ e: TestSuite.Color) throws -> TestSuite.Color { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(ColorMarshaller.toCpp(e)) @@ -17,7 +17,7 @@ final class EnumUsageInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.EnumUs try handleCppErrors(&ret) return ColorMarshaller.fromCpp(ret) } - func o(o: Optional) throws -> Optional { + func o(_ o: Optional) throws -> Optional { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(OptionalMarshaller.toCpp(o)) @@ -25,7 +25,7 @@ final class EnumUsageInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.EnumUs try handleCppErrors(&ret) return OptionalMarshaller.fromCpp(ret) } - func l(l: Array) throws -> Array { + func l(_ l: Array) throws -> Array { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(ListMarshaller.toCpp(l)) @@ -33,7 +33,7 @@ final class EnumUsageInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.EnumUs try handleCppErrors(&ret) return ListMarshaller.fromCpp(ret) } - func s(s: Set) throws -> Set { + func s(_ s: Set) throws -> Set { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(SetMarshaller.toCpp(s)) @@ -41,7 +41,7 @@ final class EnumUsageInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.EnumUs try handleCppErrors(&ret) return SetMarshaller.fromCpp(ret) } - func m(m: Dictionary) throws -> Dictionary { + func m(_ m: Dictionary) throws -> Dictionary { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(MapMarshaller.toCpp(m)) diff --git a/test-suite/generated-src/swift/EnumUsageInterface.swift b/test-suite/generated-src/swift/EnumUsageInterface.swift index c9129e65..91544e69 100644 --- a/test-suite/generated-src/swift/EnumUsageInterface.swift +++ b/test-suite/generated-src/swift/EnumUsageInterface.swift @@ -4,9 +4,9 @@ import Foundation public protocol EnumUsageInterface: AnyObject { - func e(e: TestSuite.Color) throws -> TestSuite.Color - func o(o: Optional) throws -> Optional - func l(l: Array) throws -> Array - func s(s: Set) throws -> Set - func m(m: Dictionary) throws -> Dictionary + func e(_ e: TestSuite.Color) throws -> TestSuite.Color + func o(_ o: Optional) throws -> Optional + func l(_ l: Array) throws -> Array + func s(_ s: Set) throws -> Set + func m(_ m: Dictionary) throws -> Dictionary } diff --git a/test-suite/generated-src/swift/ExternInterface1+Private.swift b/test-suite/generated-src/swift/ExternInterface1+Private.swift index eedb643f..25e743c7 100644 --- a/test-suite/generated-src/swift/ExternInterface1+Private.swift +++ b/test-suite/generated-src/swift/ExternInterface1+Private.swift @@ -9,7 +9,7 @@ import TestSuiteCxx final class ExternInterface1CppProxy: DjinniSupport.CppProxy, TestSuite.ExternInterface1 { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } - func foo(i: ClientInterface) throws -> ClientReturnedRecord { + func foo(_ i: ClientInterface) throws -> ClientReturnedRecord { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(ClientInterfaceMarshaller.toCpp(i)) @@ -17,7 +17,7 @@ final class ExternInterface1CppProxy: DjinniSupport.CppProxy, TestSuite.ExternIn try handleCppErrors(&ret) return ClientReturnedRecordMarshaller.fromCpp(ret) } - func bar(e: Color) throws -> Color { + func bar(_ e: Color) throws -> Color { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(ColorMarshaller.toCpp(e)) diff --git a/test-suite/generated-src/swift/ExternInterface1.swift b/test-suite/generated-src/swift/ExternInterface1.swift index af065b06..16f2a983 100644 --- a/test-suite/generated-src/swift/ExternInterface1.swift +++ b/test-suite/generated-src/swift/ExternInterface1.swift @@ -4,6 +4,6 @@ import Foundation public protocol ExternInterface1: AnyObject { - func foo(i: ClientInterface) throws -> ClientReturnedRecord - func bar(e: Color) throws -> Color + func foo(_ i: ClientInterface) throws -> ClientReturnedRecord + func bar(_ e: Color) throws -> Color } diff --git a/test-suite/generated-src/swift/ExternInterface2.swift b/test-suite/generated-src/swift/ExternInterface2.swift index e74a1fb2..16aa9b5d 100644 --- a/test-suite/generated-src/swift/ExternInterface2.swift +++ b/test-suite/generated-src/swift/ExternInterface2.swift @@ -4,5 +4,5 @@ import Foundation public protocol ExternInterface2: AnyObject { - func foo(i: TestHelpers) throws -> TestSuite.ExternRecordWithDerivings + func foo(_ i: TestHelpers) throws -> TestSuite.ExternRecordWithDerivings } diff --git a/test-suite/generated-src/swift/FlagRoundtrip+Private.swift b/test-suite/generated-src/swift/FlagRoundtrip+Private.swift index 7a4d32a6..a74c69a7 100644 --- a/test-suite/generated-src/swift/FlagRoundtrip+Private.swift +++ b/test-suite/generated-src/swift/FlagRoundtrip+Private.swift @@ -20,28 +20,28 @@ enum FlagRoundtripMarshaller: DjinniSupport.Marshaller { } } public class FlagRoundtrip_statics { - static func roundtripAccess(flag: TestSuite.AccessFlags) throws -> TestSuite.AccessFlags { + static func roundtripAccess(_ flag: TestSuite.AccessFlags) throws -> TestSuite.AccessFlags { var params = djinni.swift.ParameterList() params.addValue(AccessFlagsMarshaller.toCpp(flag)) var ret = djinni_generated.FlagRoundtrip_roundtripAccess(¶ms) try handleCppErrors(&ret) return AccessFlagsMarshaller.fromCpp(ret) } - static func roundtripEmpty(flag: TestSuite.EmptyFlags) throws -> TestSuite.EmptyFlags { + static func roundtripEmpty(_ flag: TestSuite.EmptyFlags) throws -> TestSuite.EmptyFlags { var params = djinni.swift.ParameterList() params.addValue(EmptyFlagsMarshaller.toCpp(flag)) var ret = djinni_generated.FlagRoundtrip_roundtripEmpty(¶ms) try handleCppErrors(&ret) return EmptyFlagsMarshaller.fromCpp(ret) } - static func roundtripAccessBoxed(flag: Optional) throws -> Optional { + static func roundtripAccessBoxed(_ flag: Optional) throws -> Optional { var params = djinni.swift.ParameterList() params.addValue(OptionalMarshaller.toCpp(flag)) var ret = djinni_generated.FlagRoundtrip_roundtripAccessBoxed(¶ms) try handleCppErrors(&ret) return OptionalMarshaller.fromCpp(ret) } - static func roundtripEmptyBoxed(flag: Optional) throws -> Optional { + static func roundtripEmptyBoxed(_ flag: Optional) throws -> Optional { var params = djinni.swift.ParameterList() params.addValue(OptionalMarshaller.toCpp(flag)) var ret = djinni_generated.FlagRoundtrip_roundtripEmptyBoxed(¶ms) diff --git a/test-suite/generated-src/swift/InterfaceUsingExtendedRecord+Private.swift b/test-suite/generated-src/swift/InterfaceUsingExtendedRecord+Private.swift index 7bb3d2dd..5b7a99fd 100644 --- a/test-suite/generated-src/swift/InterfaceUsingExtendedRecord+Private.swift +++ b/test-suite/generated-src/swift/InterfaceUsingExtendedRecord+Private.swift @@ -9,7 +9,7 @@ import TestSuiteCxx final class InterfaceUsingExtendedRecordCppProxy: DjinniSupport.CppProxy, TestSuite.InterfaceUsingExtendedRecord { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } - func meth(er: TestSuite.ExtendedRecord) throws -> TestSuite.ExtendedRecord { + func meth(_ er: TestSuite.ExtendedRecord) throws -> TestSuite.ExtendedRecord { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(ExtendedRecordMarshaller.toCpp(er)) diff --git a/test-suite/generated-src/swift/InterfaceUsingExtendedRecord.swift b/test-suite/generated-src/swift/InterfaceUsingExtendedRecord.swift index 965c84d3..e2cdac54 100644 --- a/test-suite/generated-src/swift/InterfaceUsingExtendedRecord.swift +++ b/test-suite/generated-src/swift/InterfaceUsingExtendedRecord.swift @@ -4,5 +4,5 @@ import Foundation public protocol InterfaceUsingExtendedRecord: AnyObject { - func meth(er: TestSuite.ExtendedRecord) throws -> TestSuite.ExtendedRecord + func meth(_ er: TestSuite.ExtendedRecord) throws -> TestSuite.ExtendedRecord } diff --git a/test-suite/generated-src/swift/ListenerCaller+Private.swift b/test-suite/generated-src/swift/ListenerCaller+Private.swift index 2db7fd5c..b21aa98f 100644 --- a/test-suite/generated-src/swift/ListenerCaller+Private.swift +++ b/test-suite/generated-src/swift/ListenerCaller+Private.swift @@ -38,7 +38,7 @@ enum ListenerCallerMarshaller: DjinniSupport.Marshaller { } } public class ListenerCaller_statics { - static func _init(firstL: TestSuite.FirstListener, secondL: TestSuite.SecondListener) throws -> TestSuite.ListenerCaller { + static func _init(_ firstL: TestSuite.FirstListener, secondL: TestSuite.SecondListener) throws -> TestSuite.ListenerCaller { var params = djinni.swift.ParameterList() params.addValue(FirstListenerMarshaller.toCpp(firstL)) params.addValue(SecondListenerMarshaller.toCpp(secondL)) diff --git a/test-suite/generated-src/swift/ProtoTests+Private.swift b/test-suite/generated-src/swift/ProtoTests+Private.swift index a53e65de..c31529b0 100644 --- a/test-suite/generated-src/swift/ProtoTests+Private.swift +++ b/test-suite/generated-src/swift/ProtoTests+Private.swift @@ -21,91 +21,91 @@ enum ProtoTestsMarshaller: DjinniSupport.Marshaller { } } public class ProtoTests_statics { - static func protoToStrings(x: Djinni_Test_AddressBook) throws -> Array { + static func protoToStrings(_ x: Djinni_Test_AddressBook) throws -> Array { var params = djinni.swift.ParameterList() params.addValue(ProtobufMarshaller.toCpp(x)) var ret = djinni_generated.ProtoTests_protoToStrings(¶ms) try handleCppErrors(&ret) return ListMarshaller.fromCpp(ret) } - static func stringsToProto(x: Array) throws -> Djinni_Test_AddressBook { + static func stringsToProto(_ x: Array) throws -> Djinni_Test_AddressBook { var params = djinni.swift.ParameterList() params.addValue(ListMarshaller.toCpp(x)) var ret = djinni_generated.ProtoTests_stringsToProto(¶ms) try handleCppErrors(&ret) return ProtobufMarshaller.fromCpp(ret) } - static func embeddedProtoToString(x: TestSuite.RecordWithEmbeddedProto) throws -> String { + static func embeddedProtoToString(_ x: TestSuite.RecordWithEmbeddedProto) throws -> String { var params = djinni.swift.ParameterList() params.addValue(RecordWithEmbeddedProtoMarshaller.toCpp(x)) var ret = djinni_generated.ProtoTests_embeddedProtoToString(¶ms) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func stringToEmbeddedProto(x: String) throws -> TestSuite.RecordWithEmbeddedProto { + static func stringToEmbeddedProto(_ x: String) throws -> TestSuite.RecordWithEmbeddedProto { var params = djinni.swift.ParameterList() params.addValue(StringMarshaller.toCpp(x)) var ret = djinni_generated.ProtoTests_stringToEmbeddedProto(¶ms) try handleCppErrors(&ret) return RecordWithEmbeddedProtoMarshaller.fromCpp(ret) } - static func cppProtoToString(x: Djinni_Test2_PersistingState) throws -> String { + static func cppProtoToString(_ x: Djinni_Test2_PersistingState) throws -> String { var params = djinni.swift.ParameterList() params.addValue(ProtobufMarshaller.toCpp(x)) var ret = djinni_generated.ProtoTests_cppProtoToString(¶ms) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func stringToCppProto(x: String) throws -> Djinni_Test2_PersistingState { + static func stringToCppProto(_ x: String) throws -> Djinni_Test2_PersistingState { var params = djinni.swift.ParameterList() params.addValue(StringMarshaller.toCpp(x)) var ret = djinni_generated.ProtoTests_stringToCppProto(¶ms) try handleCppErrors(&ret) return ProtobufMarshaller.fromCpp(ret) } - static func embeddedCppProtoToString(x: TestSuite.RecordWithEmbeddedCppProto) throws -> String { + static func embeddedCppProtoToString(_ x: TestSuite.RecordWithEmbeddedCppProto) throws -> String { var params = djinni.swift.ParameterList() params.addValue(RecordWithEmbeddedCppProtoMarshaller.toCpp(x)) var ret = djinni_generated.ProtoTests_embeddedCppProtoToString(¶ms) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func stringToEmbeddedCppProto(x: String) throws -> TestSuite.RecordWithEmbeddedCppProto { + static func stringToEmbeddedCppProto(_ x: String) throws -> TestSuite.RecordWithEmbeddedCppProto { var params = djinni.swift.ParameterList() params.addValue(StringMarshaller.toCpp(x)) var ret = djinni_generated.ProtoTests_stringToEmbeddedCppProto(¶ms) try handleCppErrors(&ret) return RecordWithEmbeddedCppProtoMarshaller.fromCpp(ret) } - static func protoListToStrings(x: Array) throws -> Array { + static func protoListToStrings(_ x: Array) throws -> Array { var params = djinni.swift.ParameterList() params.addValue(ListMarshaller>.toCpp(x)) var ret = djinni_generated.ProtoTests_protoListToStrings(¶ms) try handleCppErrors(&ret) return ListMarshaller.fromCpp(ret) } - static func stringsToProtoList(x: Array) throws -> Array { + static func stringsToProtoList(_ x: Array) throws -> Array { var params = djinni.swift.ParameterList() params.addValue(ListMarshaller.toCpp(x)) var ret = djinni_generated.ProtoTests_stringsToProtoList(¶ms) try handleCppErrors(&ret) return ListMarshaller>.fromCpp(ret) } - static func optionalProtoToString(x: Optional) throws -> String { + static func optionalProtoToString(_ x: Optional) throws -> String { var params = djinni.swift.ParameterList() params.addValue(OptionalMarshaller>.toCpp(x)) var ret = djinni_generated.ProtoTests_optionalProtoToString(¶ms) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func stringToOptionalProto(x: String) throws -> Optional { + static func stringToOptionalProto(_ x: String) throws -> Optional { var params = djinni.swift.ParameterList() params.addValue(StringMarshaller.toCpp(x)) var ret = djinni_generated.ProtoTests_stringToOptionalProto(¶ms) try handleCppErrors(&ret) return OptionalMarshaller>.fromCpp(ret) } - static func stringToProtoOutcome(x: String) throws -> Result { + static func stringToProtoOutcome(_ x: String) throws -> Result { var params = djinni.swift.ParameterList() params.addValue(StringMarshaller.toCpp(x)) var ret = djinni_generated.ProtoTests_stringToProtoOutcome(¶ms) diff --git a/test-suite/generated-src/swift/ReverseClientInterface+Private.swift b/test-suite/generated-src/swift/ReverseClientInterface+Private.swift index e9b26f3c..90e74b99 100644 --- a/test-suite/generated-src/swift/ReverseClientInterface+Private.swift +++ b/test-suite/generated-src/swift/ReverseClientInterface+Private.swift @@ -16,7 +16,7 @@ final class ReverseClientInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.Re try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - func methTakingInterface(i: TestSuite.ReverseClientInterface) throws -> String { + func methTakingInterface(_ i: TestSuite.ReverseClientInterface) throws -> String { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(ReverseClientInterfaceMarshaller.toCpp(i)) @@ -24,7 +24,7 @@ final class ReverseClientInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.Re try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - func methTakingOptionalInterface(i: Optional) throws -> String { + func methTakingOptionalInterface(_ i: Optional) throws -> String { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(OptionalMarshaller.toCpp(i)) diff --git a/test-suite/generated-src/swift/ReverseClientInterface.swift b/test-suite/generated-src/swift/ReverseClientInterface.swift index 9be264c6..4a85a005 100644 --- a/test-suite/generated-src/swift/ReverseClientInterface.swift +++ b/test-suite/generated-src/swift/ReverseClientInterface.swift @@ -5,6 +5,6 @@ import Foundation public protocol ReverseClientInterface: AnyObject { func returnStr() throws -> String - func methTakingInterface(i: TestSuite.ReverseClientInterface) throws -> String - func methTakingOptionalInterface(i: Optional) throws -> String + func methTakingInterface(_ i: TestSuite.ReverseClientInterface) throws -> String + func methTakingOptionalInterface(_ i: Optional) throws -> String } diff --git a/test-suite/generated-src/swift/TestArray+Private.swift b/test-suite/generated-src/swift/TestArray+Private.swift index 1eb8b8c5..509d63f8 100644 --- a/test-suite/generated-src/swift/TestArray+Private.swift +++ b/test-suite/generated-src/swift/TestArray+Private.swift @@ -20,28 +20,28 @@ enum TestArrayMarshaller: DjinniSupport.Marshaller { } } public class TestArray_statics { - static func testStringArray(a: Array) throws -> Array { + static func testStringArray(_ a: Array) throws -> Array { var params = djinni.swift.ParameterList() params.addValue(ArrayMarshaller.toCpp(a)) var ret = djinni_generated.TestArray_testStringArray(¶ms) try handleCppErrors(&ret) return ArrayMarshaller.fromCpp(ret) } - static func testIntArray(a: Array) throws -> Array { + static func testIntArray(_ a: Array) throws -> Array { var params = djinni.swift.ParameterList() params.addValue(ArrayMarshaller.toCpp(a)) var ret = djinni_generated.TestArray_testIntArray(¶ms) try handleCppErrors(&ret) return ArrayMarshaller.fromCpp(ret) } - static func testRecordArray(a: Array) throws -> Array { + static func testRecordArray(_ a: Array) throws -> Array { var params = djinni.swift.ParameterList() params.addValue(ArrayMarshaller.toCpp(a)) var ret = djinni_generated.TestArray_testRecordArray(¶ms) try handleCppErrors(&ret) return ArrayMarshaller.fromCpp(ret) } - static func testArrayOfArray(a: Array>) throws -> Array> { + static func testArrayOfArray(_ a: Array>) throws -> Array> { var params = djinni.swift.ParameterList() params.addValue(ArrayMarshaller>.toCpp(a)) var ret = djinni_generated.TestArray_testArrayOfArray(¶ms) diff --git a/test-suite/generated-src/swift/TestDuration+Private.swift b/test-suite/generated-src/swift/TestDuration+Private.swift index ed78f6ac..55ae27f9 100644 --- a/test-suite/generated-src/swift/TestDuration+Private.swift +++ b/test-suite/generated-src/swift/TestDuration+Private.swift @@ -20,140 +20,140 @@ enum TestDurationMarshaller: DjinniSupport.Marshaller { } } public class TestDuration_statics { - static func hoursString(dt: Duration) throws -> String { + static func hoursString(_ dt: Duration) throws -> String { var params = djinni.swift.ParameterList() params.addValue(DurationMarshaller.toCpp(dt)) var ret = djinni_generated.TestDuration_hoursString(¶ms) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func minutesString(dt: Duration) throws -> String { + static func minutesString(_ dt: Duration) throws -> String { var params = djinni.swift.ParameterList() params.addValue(DurationMarshaller.toCpp(dt)) var ret = djinni_generated.TestDuration_minutesString(¶ms) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func secondsString(dt: Duration) throws -> String { + static func secondsString(_ dt: Duration) throws -> String { var params = djinni.swift.ParameterList() params.addValue(DurationMarshaller.toCpp(dt)) var ret = djinni_generated.TestDuration_secondsString(¶ms) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func millisString(dt: Duration) throws -> String { + static func millisString(_ dt: Duration) throws -> String { var params = djinni.swift.ParameterList() params.addValue(DurationMarshaller.toCpp(dt)) var ret = djinni_generated.TestDuration_millisString(¶ms) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func microsString(dt: Duration) throws -> String { + static func microsString(_ dt: Duration) throws -> String { var params = djinni.swift.ParameterList() params.addValue(DurationMarshaller.toCpp(dt)) var ret = djinni_generated.TestDuration_microsString(¶ms) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func nanosString(dt: Duration) throws -> String { + static func nanosString(_ dt: Duration) throws -> String { var params = djinni.swift.ParameterList() params.addValue(DurationMarshaller.toCpp(dt)) var ret = djinni_generated.TestDuration_nanosString(¶ms) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func hours(count: Int32) throws -> Duration { + static func hours(_ count: Int32) throws -> Duration { var params = djinni.swift.ParameterList() params.addValue(I32Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_hours(¶ms) try handleCppErrors(&ret) return DurationMarshaller.fromCpp(ret) } - static func minutes(count: Int32) throws -> Duration { + static func minutes(_ count: Int32) throws -> Duration { var params = djinni.swift.ParameterList() params.addValue(I32Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_minutes(¶ms) try handleCppErrors(&ret) return DurationMarshaller.fromCpp(ret) } - static func seconds(count: Int32) throws -> Duration { + static func seconds(_ count: Int32) throws -> Duration { var params = djinni.swift.ParameterList() params.addValue(I32Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_seconds(¶ms) try handleCppErrors(&ret) return DurationMarshaller.fromCpp(ret) } - static func millis(count: Int32) throws -> Duration { + static func millis(_ count: Int32) throws -> Duration { var params = djinni.swift.ParameterList() params.addValue(I32Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_millis(¶ms) try handleCppErrors(&ret) return DurationMarshaller.fromCpp(ret) } - static func micros(count: Int32) throws -> Duration { + static func micros(_ count: Int32) throws -> Duration { var params = djinni.swift.ParameterList() params.addValue(I32Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_micros(¶ms) try handleCppErrors(&ret) return DurationMarshaller.fromCpp(ret) } - static func nanos(count: Int32) throws -> Duration { + static func nanos(_ count: Int32) throws -> Duration { var params = djinni.swift.ParameterList() params.addValue(I32Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_nanos(¶ms) try handleCppErrors(&ret) return DurationMarshaller.fromCpp(ret) } - static func hoursf(count: Double) throws -> Duration { + static func hoursf(_ count: Double) throws -> Duration { var params = djinni.swift.ParameterList() params.addValue(F64Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_hoursf(¶ms) try handleCppErrors(&ret) return DurationMarshaller.fromCpp(ret) } - static func minutesf(count: Double) throws -> Duration { + static func minutesf(_ count: Double) throws -> Duration { var params = djinni.swift.ParameterList() params.addValue(F64Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_minutesf(¶ms) try handleCppErrors(&ret) return DurationMarshaller.fromCpp(ret) } - static func secondsf(count: Double) throws -> Duration { + static func secondsf(_ count: Double) throws -> Duration { var params = djinni.swift.ParameterList() params.addValue(F64Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_secondsf(¶ms) try handleCppErrors(&ret) return DurationMarshaller.fromCpp(ret) } - static func millisf(count: Double) throws -> Duration { + static func millisf(_ count: Double) throws -> Duration { var params = djinni.swift.ParameterList() params.addValue(F64Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_millisf(¶ms) try handleCppErrors(&ret) return DurationMarshaller.fromCpp(ret) } - static func microsf(count: Double) throws -> Duration { + static func microsf(_ count: Double) throws -> Duration { var params = djinni.swift.ParameterList() params.addValue(F64Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_microsf(¶ms) try handleCppErrors(&ret) return DurationMarshaller.fromCpp(ret) } - static func nanosf(count: Double) throws -> Duration { + static func nanosf(_ count: Double) throws -> Duration { var params = djinni.swift.ParameterList() params.addValue(F64Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_nanosf(¶ms) try handleCppErrors(&ret) return DurationMarshaller.fromCpp(ret) } - static func box(count: Int64) throws -> Optional { + static func box(_ count: Int64) throws -> Optional { var params = djinni.swift.ParameterList() params.addValue(I64Marshaller.toCpp(count)) var ret = djinni_generated.TestDuration_box(¶ms) try handleCppErrors(&ret) return OptionalMarshaller>.fromCpp(ret) } - static func unbox(dt: Optional) throws -> Int64 { + static func unbox(_ dt: Optional) throws -> Int64 { var params = djinni.swift.ParameterList() params.addValue(OptionalMarshaller>.toCpp(dt)) var ret = djinni_generated.TestDuration_unbox(¶ms) diff --git a/test-suite/generated-src/swift/TestHelpers+Private.swift b/test-suite/generated-src/swift/TestHelpers+Private.swift index 01481f94..855aa9b4 100644 --- a/test-suite/generated-src/swift/TestHelpers+Private.swift +++ b/test-suite/generated-src/swift/TestHelpers+Private.swift @@ -31,7 +31,7 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return SetRecordMarshaller.fromCpp(ret) } - static func checkSetRecord(rec: TestSuite.SetRecord) throws -> Bool { + static func checkSetRecord(_ rec: TestSuite.SetRecord) throws -> Bool { var params = djinni.swift.ParameterList() params.addValue(SetRecordMarshaller.toCpp(rec)) var ret = djinni_generated.TestHelpers_checkSetRecord(¶ms) @@ -44,7 +44,7 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return PrimitiveListMarshaller.fromCpp(ret) } - static func checkPrimitiveList(pl: TestSuite.PrimitiveList) throws -> Bool { + static func checkPrimitiveList(_ pl: TestSuite.PrimitiveList) throws -> Bool { var params = djinni.swift.ParameterList() params.addValue(PrimitiveListMarshaller.toCpp(pl)) var ret = djinni_generated.TestHelpers_checkPrimitiveList(¶ms) @@ -57,7 +57,7 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return NestedCollectionMarshaller.fromCpp(ret) } - static func checkNestedCollection(nc: TestSuite.NestedCollection) throws -> Bool { + static func checkNestedCollection(_ nc: TestSuite.NestedCollection) throws -> Bool { var params = djinni.swift.ParameterList() params.addValue(NestedCollectionMarshaller.toCpp(nc)) var ret = djinni_generated.TestHelpers_checkNestedCollection(¶ms) @@ -70,7 +70,7 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return MapMarshaller.fromCpp(ret) } - static func checkMap(m: Dictionary) throws -> Bool { + static func checkMap(_ m: Dictionary) throws -> Bool { var params = djinni.swift.ParameterList() params.addValue(MapMarshaller.toCpp(m)) var ret = djinni_generated.TestHelpers_checkMap(¶ms) @@ -83,7 +83,7 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return MapMarshaller.fromCpp(ret) } - static func checkEmptyMap(m: Dictionary) throws -> Bool { + static func checkEmptyMap(_ m: Dictionary) throws -> Bool { var params = djinni.swift.ParameterList() params.addValue(MapMarshaller.toCpp(m)) var ret = djinni_generated.TestHelpers_checkEmptyMap(¶ms) @@ -96,44 +96,44 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return MapListRecordMarshaller.fromCpp(ret) } - static func checkMapListRecord(m: TestSuite.MapListRecord) throws -> Bool { + static func checkMapListRecord(_ m: TestSuite.MapListRecord) throws -> Bool { var params = djinni.swift.ParameterList() params.addValue(MapListRecordMarshaller.toCpp(m)) var ret = djinni_generated.TestHelpers_checkMapListRecord(¶ms) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } - static func checkClientInterfaceAscii(i: TestSuite.ClientInterface) throws -> Void { + static func checkClientInterfaceAscii(_ i: TestSuite.ClientInterface) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(ClientInterfaceMarshaller.toCpp(i)) var ret = djinni_generated.TestHelpers_checkClientInterfaceAscii(¶ms) try handleCppErrors(&ret) } - static func checkClientInterfaceNonascii(i: TestSuite.ClientInterface) throws -> Void { + static func checkClientInterfaceNonascii(_ i: TestSuite.ClientInterface) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(ClientInterfaceMarshaller.toCpp(i)) var ret = djinni_generated.TestHelpers_checkClientInterfaceNonascii(¶ms) try handleCppErrors(&ret) } - static func checkClientInterfaceArgs(i: TestSuite.ClientInterface) throws -> Void { + static func checkClientInterfaceArgs(_ i: TestSuite.ClientInterface) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(ClientInterfaceMarshaller.toCpp(i)) var ret = djinni_generated.TestHelpers_checkClientInterfaceArgs(¶ms) try handleCppErrors(&ret) } - static func checkEnumMap(m: Dictionary) throws -> Void { + static func checkEnumMap(_ m: Dictionary) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(MapMarshaller.toCpp(m)) var ret = djinni_generated.TestHelpers_checkEnumMap(¶ms) try handleCppErrors(&ret) } - static func checkEnum(c: TestSuite.Color) throws -> Void { + static func checkEnum(_ c: TestSuite.Color) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(ColorMarshaller.toCpp(c)) var ret = djinni_generated.TestHelpers_checkEnum(¶ms) try handleCppErrors(&ret) } - static func tokenId(t: Optional) throws -> Optional { + static func tokenId(_ t: Optional) throws -> Optional { var params = djinni.swift.ParameterList() params.addValue(OptionalMarshaller.toCpp(t)) var ret = djinni_generated.TestHelpers_tokenId(¶ms) @@ -146,20 +146,20 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return UserTokenMarshaller.fromCpp(ret) } - static func checkCppToken(t: TestSuite.UserToken) throws -> Void { + static func checkCppToken(_ t: TestSuite.UserToken) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(UserTokenMarshaller.toCpp(t)) var ret = djinni_generated.TestHelpers_checkCppToken(¶ms) try handleCppErrors(&ret) } - static func cppTokenId(t: TestSuite.UserToken) throws -> Int64 { + static func cppTokenId(_ t: TestSuite.UserToken) throws -> Int64 { var params = djinni.swift.ParameterList() params.addValue(UserTokenMarshaller.toCpp(t)) var ret = djinni_generated.TestHelpers_cppTokenId(¶ms) try handleCppErrors(&ret) return I64Marshaller.fromCpp(ret) } - static func checkTokenType(t: TestSuite.UserToken, type: String) throws -> Void { + static func checkTokenType(_ t: TestSuite.UserToken, type: String) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(UserTokenMarshaller.toCpp(t)) params.addValue(StringMarshaller.toCpp(type)) @@ -172,14 +172,14 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return OptionalMarshaller.fromCpp(ret) } - static func assortedPrimitivesId(i: TestSuite.AssortedPrimitives) throws -> TestSuite.AssortedPrimitives { + static func assortedPrimitivesId(_ i: TestSuite.AssortedPrimitives) throws -> TestSuite.AssortedPrimitives { var params = djinni.swift.ParameterList() params.addValue(AssortedPrimitivesMarshaller.toCpp(i)) var ret = djinni_generated.TestHelpers_assortedPrimitivesId(¶ms) try handleCppErrors(&ret) return AssortedPrimitivesMarshaller.fromCpp(ret) } - static func idBinary(b: Data) throws -> Data { + static func idBinary(_ b: Data) throws -> Data { var params = djinni.swift.ParameterList() params.addValue(BinaryMarshaller.toCpp(b)) var ret = djinni_generated.TestHelpers_idBinary(¶ms) @@ -192,7 +192,7 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return FutureMarshaller.fromCpp(ret) } - static func futureRoundtrip(f: DJFuture) throws -> DJFuture { + static func futureRoundtrip(_ f: DJFuture) throws -> DJFuture { var params = djinni.swift.ParameterList() params.addValue(FutureMarshaller.toCpp(f)) var ret = djinni_generated.TestHelpers_futureRoundtrip(¶ms) @@ -205,35 +205,35 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return FutureMarshaller.fromCpp(ret) } - static func voidAsyncMethod(f: DJFuture) throws -> DJFuture { + static func voidAsyncMethod(_ f: DJFuture) throws -> DJFuture { var params = djinni.swift.ParameterList() params.addValue(FutureMarshaller.toCpp(f)) var ret = djinni_generated.TestHelpers_voidAsyncMethod(¶ms) try handleCppErrors(&ret) return FutureMarshaller.fromCpp(ret) } - static func addOneIfPresent(f: DJFuture>) throws -> DJFuture> { + static func addOneIfPresent(_ f: DJFuture>) throws -> DJFuture> { var params = djinni.swift.ParameterList() params.addValue(FutureMarshaller>.toCpp(f)) var ret = djinni_generated.TestHelpers_addOneIfPresent(¶ms) try handleCppErrors(&ret) return FutureMarshaller>.fromCpp(ret) } - static func returnExceptionString(f: DJFuture) throws -> DJFuture { + static func returnExceptionString(_ f: DJFuture) throws -> DJFuture { var params = djinni.swift.ParameterList() params.addValue(FutureMarshaller.toCpp(f)) var ret = djinni_generated.TestHelpers_returnExceptionString(¶ms) try handleCppErrors(&ret) return FutureMarshaller.fromCpp(ret) } - static func checkAsyncInterface(i: TestSuite.AsyncInterface) throws -> DJFuture { + static func checkAsyncInterface(_ i: TestSuite.AsyncInterface) throws -> DJFuture { var params = djinni.swift.ParameterList() params.addValue(AsyncInterfaceMarshaller.toCpp(i)) var ret = djinni_generated.TestHelpers_checkAsyncInterface(¶ms) try handleCppErrors(&ret) return FutureMarshaller.fromCpp(ret) } - static func checkAsyncComposition(i: TestSuite.AsyncInterface) throws -> DJFuture { + static func checkAsyncComposition(_ i: TestSuite.AsyncInterface) throws -> DJFuture { var params = djinni.swift.ParameterList() params.addValue(AsyncInterfaceMarshaller.toCpp(i)) var ret = djinni_generated.TestHelpers_checkAsyncComposition(¶ms) @@ -246,7 +246,7 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return ListMarshaller>.fromCpp(ret) } - static func checkOptionalList(ol: Array>) throws -> Bool { + static func checkOptionalList(_ ol: Array>) throws -> Bool { var params = djinni.swift.ParameterList() params.addValue(ListMarshaller>.toCpp(ol)) var ret = djinni_generated.TestHelpers_checkOptionalList(¶ms) @@ -259,7 +259,7 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return SetMarshaller>.fromCpp(ret) } - static func checkOptionalSet(os: Set>) throws -> Bool { + static func checkOptionalSet(_ os: Set>) throws -> Bool { var params = djinni.swift.ParameterList() params.addValue(SetMarshaller>.toCpp(os)) var ret = djinni_generated.TestHelpers_checkOptionalSet(¶ms) @@ -272,7 +272,7 @@ public class TestHelpers_statics { try handleCppErrors(&ret) return MapMarshaller, OptionalMarshaller>.fromCpp(ret) } - static func checkOptionalMap(om: Dictionary, Optional>) throws -> Bool { + static func checkOptionalMap(_ om: Dictionary, Optional>) throws -> Bool { var params = djinni.swift.ParameterList() params.addValue(MapMarshaller, OptionalMarshaller>.toCpp(om)) var ret = djinni_generated.TestHelpers_checkOptionalMap(¶ms) diff --git a/test-suite/generated-src/swift/TestOutcome+Private.swift b/test-suite/generated-src/swift/TestOutcome+Private.swift index b5c000b5..ab1c423c 100644 --- a/test-suite/generated-src/swift/TestOutcome+Private.swift +++ b/test-suite/generated-src/swift/TestOutcome+Private.swift @@ -32,14 +32,14 @@ public class TestOutcome_statics { try handleCppErrors(&ret) return OutcomeMarshaller.fromCpp(ret) } - static func putSuccessOutcome(x: Result) throws -> String { + static func putSuccessOutcome(_ x: Result) throws -> String { var params = djinni.swift.ParameterList() params.addValue(OutcomeMarshaller.toCpp(x)) var ret = djinni_generated.TestOutcome_putSuccessOutcome(¶ms) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func putErrorOutcome(x: Result) throws -> Int32 { + static func putErrorOutcome(_ x: Result) throws -> Int32 { var params = djinni.swift.ParameterList() params.addValue(OutcomeMarshaller.toCpp(x)) var ret = djinni_generated.TestOutcome_putErrorOutcome(¶ms) @@ -58,14 +58,14 @@ public class TestOutcome_statics { try handleCppErrors(&ret) return NestedOutcomeMarshaller.fromCpp(ret) } - static func putNestedSuccessOutcome(x: TestSuite.NestedOutcome) throws -> Int32 { + static func putNestedSuccessOutcome(_ x: TestSuite.NestedOutcome) throws -> Int32 { var params = djinni.swift.ParameterList() params.addValue(NestedOutcomeMarshaller.toCpp(x)) var ret = djinni_generated.TestOutcome_putNestedSuccessOutcome(¶ms) try handleCppErrors(&ret) return I32Marshaller.fromCpp(ret) } - static func putNestedErrorOutcome(x: TestSuite.NestedOutcome) throws -> String { + static func putNestedErrorOutcome(_ x: TestSuite.NestedOutcome) throws -> String { var params = djinni.swift.ParameterList() params.addValue(NestedOutcomeMarshaller.toCpp(x)) var ret = djinni_generated.TestOutcome_putNestedErrorOutcome(¶ms) diff --git a/test-suite/generated-src/swift/UsesSingleLanguageListeners+Private.swift b/test-suite/generated-src/swift/UsesSingleLanguageListeners+Private.swift index dfef4831..5b4023f2 100644 --- a/test-suite/generated-src/swift/UsesSingleLanguageListeners+Private.swift +++ b/test-suite/generated-src/swift/UsesSingleLanguageListeners+Private.swift @@ -13,7 +13,7 @@ import TestSuiteCxx */ final class UsesSingleLanguageListenersCppProxy: DjinniSupport.CppProxy, TestSuite.UsesSingleLanguageListeners { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } - func callForObjC(l: TestSuite.ObjcOnlyListener) throws -> Void { + func callForObjC(_ l: TestSuite.ObjcOnlyListener) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(ObjcOnlyListenerMarshaller.toCpp(l)) @@ -27,7 +27,7 @@ final class UsesSingleLanguageListenersCppProxy: DjinniSupport.CppProxy, TestSui try handleCppErrors(&ret) return ObjcOnlyListenerMarshaller.fromCpp(ret) } - func callForJava(l: TestSuite.JavaOnlyListener) throws -> Void { + func callForJava(_ l: TestSuite.JavaOnlyListener) throws -> Void { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(JavaOnlyListenerMarshaller.toCpp(l)) diff --git a/test-suite/generated-src/swift/UsesSingleLanguageListeners.swift b/test-suite/generated-src/swift/UsesSingleLanguageListeners.swift index dbc44915..3209f748 100644 --- a/test-suite/generated-src/swift/UsesSingleLanguageListeners.swift +++ b/test-suite/generated-src/swift/UsesSingleLanguageListeners.swift @@ -8,8 +8,8 @@ import Foundation * on references to interfaces they don't need. */ public protocol UsesSingleLanguageListeners: AnyObject { - func callForObjC(l: TestSuite.ObjcOnlyListener) throws -> Void + func callForObjC(_ l: TestSuite.ObjcOnlyListener) throws -> Void func returnForObjC() throws -> TestSuite.ObjcOnlyListener - func callForJava(l: TestSuite.JavaOnlyListener) throws -> Void + func callForJava(_ l: TestSuite.JavaOnlyListener) throws -> Void func returnForJava() throws -> TestSuite.JavaOnlyListener } diff --git a/test-suite/generated-src/swift/VarnameInterface+Private.swift b/test-suite/generated-src/swift/VarnameInterface+Private.swift index 36ee2246..f18cab13 100644 --- a/test-suite/generated-src/swift/VarnameInterface+Private.swift +++ b/test-suite/generated-src/swift/VarnameInterface+Private.swift @@ -9,7 +9,7 @@ import TestSuiteCxx final class VarnameInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.VarnameInterface { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } - func Rmethod(RArg: TestSuite.VarnameRecord) throws -> TestSuite.VarnameRecord { + func Rmethod(_ RArg: TestSuite.VarnameRecord) throws -> TestSuite.VarnameRecord { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(VarnameRecordMarshaller.toCpp(RArg)) @@ -17,7 +17,7 @@ final class VarnameInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.VarnameI try handleCppErrors(&ret) return VarnameRecordMarshaller.fromCpp(ret) } - func Imethod(IArg: TestSuite.VarnameInterface) throws -> TestSuite.VarnameInterface { + func Imethod(_ IArg: TestSuite.VarnameInterface) throws -> TestSuite.VarnameInterface { var params = djinni.swift.ParameterList() params.addValue(inst) params.addValue(VarnameInterfaceMarshaller.toCpp(IArg)) diff --git a/test-suite/generated-src/swift/VarnameInterface.swift b/test-suite/generated-src/swift/VarnameInterface.swift index db530ae8..6d7bc842 100644 --- a/test-suite/generated-src/swift/VarnameInterface.swift +++ b/test-suite/generated-src/swift/VarnameInterface.swift @@ -9,6 +9,6 @@ public protocol VarnameInterface: AnyObject { * RArg should be rewritten. * _i_arg_ should not. */ - func Rmethod(RArg: TestSuite.VarnameRecord) throws -> TestSuite.VarnameRecord - func Imethod(IArg: TestSuite.VarnameInterface) throws -> TestSuite.VarnameInterface + func Rmethod(_ RArg: TestSuite.VarnameRecord) throws -> TestSuite.VarnameRecord + func Imethod(_ IArg: TestSuite.VarnameInterface) throws -> TestSuite.VarnameInterface } diff --git a/test-suite/generated-src/swift/WcharTestHelpers+Private.swift b/test-suite/generated-src/swift/WcharTestHelpers+Private.swift index 79845ef8..40047e64 100644 --- a/test-suite/generated-src/swift/WcharTestHelpers+Private.swift +++ b/test-suite/generated-src/swift/WcharTestHelpers+Private.swift @@ -32,14 +32,14 @@ public class WcharTestHelpers_statics { try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func checkString(str: String) throws -> Bool { + static func checkString(_ str: String) throws -> Bool { var params = djinni.swift.ParameterList() params.addValue(StringMarshaller.toCpp(str)) var ret = djinni_generated.WcharTestHelpers_checkString(¶ms) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } - static func checkRecord(rec: TestSuite.WcharTestRec) throws -> Bool { + static func checkRecord(_ rec: TestSuite.WcharTestRec) throws -> Bool { var params = djinni.swift.ParameterList() params.addValue(WcharTestRecMarshaller.toCpp(rec)) var ret = djinni_generated.WcharTestHelpers_checkRecord(¶ms) diff --git a/test-suite/handwritten-src/swift/ArrayTest.swift b/test-suite/handwritten-src/swift/ArrayTest.swift index aab2d638..842de7c3 100644 --- a/test-suite/handwritten-src/swift/ArrayTest.swift +++ b/test-suite/handwritten-src/swift/ArrayTest.swift @@ -6,18 +6,18 @@ final class ArrayTest: XCTestCase { func testArrays() throws { let inputStrings = ["1", "2", "3"] let expectedStrings = ["3", "2", "1"] - XCTAssertEqual(try TestArray_statics.testStringArray(a:inputStrings), expectedStrings) + XCTAssertEqual(try TestArray_statics.testStringArray(inputStrings), expectedStrings) let inputIntegers: [Int32] = [1, 2, 3] let expectedIntegers: [Int32] = [3, 2, 1] - XCTAssertEqual(try TestArray_statics.testIntArray(a:inputIntegers), expectedIntegers) + XCTAssertEqual(try TestArray_statics.testIntArray(inputIntegers), expectedIntegers) let inputRecords = [Vec2(x:1, y:1), Vec2(x:2, y:2), Vec2(x:3, y:3)] let expectedRecords = [Vec2(x:3, y:3), Vec2(x:2, y:2), Vec2(x:1, y:1)] - XCTAssertEqual(try TestArray_statics.testRecordArray(a:inputRecords), expectedRecords) + XCTAssertEqual(try TestArray_statics.testRecordArray(inputRecords), expectedRecords) let inputArrays: [[Int32]] = [[1,1,1], [2,2,2], [3,3,3]] let expectedArrays: [[Int32]] = [[3,3,3], [2,2,2], [1,1,1]] - XCTAssertEqual(try TestArray_statics.testArrayOfArray(a:inputArrays), expectedArrays) + XCTAssertEqual(try TestArray_statics.testArrayOfArray(inputArrays), expectedArrays) } } diff --git a/test-suite/handwritten-src/swift/AsyncTest.swift b/test-suite/handwritten-src/swift/AsyncTest.swift index d4709568..39419208 100644 --- a/test-suite/handwritten-src/swift/AsyncTest.swift +++ b/test-suite/handwritten-src/swift/AsyncTest.swift @@ -7,7 +7,7 @@ import Combine final class AsyncTest: XCTestCase { class AsyncInterfaceImpl: AsyncInterface { - func futureRoundtrip(f: DJFuture) throws -> DJFuture { + func futureRoundtrip(_ f: DJFuture) throws -> DJFuture { var token: AnyCancellable? = nil return DJFuture() { promise in token = f.sink { completion in @@ -38,7 +38,7 @@ final class AsyncTest: XCTestCase { sink = f.sink { completion in if case .failure = completion {XCTAssertTrue(false)}} receiveValue: { s in promise(.success(Int32(s)!))} } - let f3 = try TestHelpers_statics.futureRoundtrip(f:f2) + let f3 = try TestHelpers_statics.futureRoundtrip(f2) p!(.success("36")) let res = try await f3.value XCTAssertEqual(res, "36") @@ -49,7 +49,7 @@ final class AsyncTest: XCTestCase { let f = DJFuture() { promise in promise(.success(())) } - let f1 = try TestHelpers_statics.voidAsyncMethod(f:f) + let f1 = try TestHelpers_statics.voidAsyncMethod(f) try await f1.value } @@ -65,7 +65,7 @@ final class AsyncTest: XCTestCase { promise(.failure(DjinniError("123"))) } } - let f3 = try TestHelpers_statics.futureRoundtrip(f:f2) + let f3 = try TestHelpers_statics.futureRoundtrip(f2) p!(.success("36")) var s: String? = nil do { @@ -78,12 +78,12 @@ final class AsyncTest: XCTestCase { } func testFutureRoundtripBackwards() async throws { - let s = try await TestHelpers_statics.checkAsyncInterface(i:AsyncInterfaceImpl()).value + let s = try await TestHelpers_statics.checkAsyncInterface(AsyncInterfaceImpl()).value XCTAssertEqual(s, "36") } func testFutureComposition() async throws { - let s = try await TestHelpers_statics.checkAsyncComposition(i: AsyncInterfaceImpl()).value + let s = try await TestHelpers_statics.checkAsyncComposition(AsyncInterfaceImpl()).value XCTAssertEqual(s, "42") } @@ -91,7 +91,7 @@ final class AsyncTest: XCTestCase { let input = DJFuture> { promise in promise(.success(nil)) } - let output = try await TestHelpers_statics.addOneIfPresent(f:input).value + let output = try await TestHelpers_statics.addOneIfPresent(input).value XCTAssertNil(output) } @@ -99,7 +99,7 @@ final class AsyncTest: XCTestCase { let input = DJFuture> { promise in promise(.success(10)) } - let output = try await TestHelpers_statics.addOneIfPresent(f:input).value + let output = try await TestHelpers_statics.addOneIfPresent(input).value XCTAssertEqual(output, 11) } } diff --git a/test-suite/handwritten-src/swift/ClientInterfaceTest.swift b/test-suite/handwritten-src/swift/ClientInterfaceTest.swift index 4844f910..22dfe546 100644 --- a/test-suite/handwritten-src/swift/ClientInterfaceTest.swift +++ b/test-suite/handwritten-src/swift/ClientInterfaceTest.swift @@ -7,22 +7,22 @@ struct ClientInterfaceError: Error { } class ClientInterfaceImpl: ClientInterface { - func getRecord(recordId: Int64, utf8string: String, misc: Optional) throws -> TestSuite.ClientReturnedRecord { + func getRecord(_ recordId: Int64, utf8string: String, misc: Optional) throws -> TestSuite.ClientReturnedRecord { if (utf8string != "Non-ASCII /\0 非 ASCII 字符" && utf8string != "Hello World!") { throw ClientInterfaceError(msg: "Unexpected string. Check UTF-8?") } return ClientReturnedRecord(recordId:recordId, content:utf8string, misc:misc) } - func identifierCheck(data: Data, r: Int32, jret: Int64) throws -> Double { + func identifierCheck(_ data: Data, r: Int32, jret: Int64) throws -> Double { return 0.0 } func returnStr() throws -> String { return "test" } - func methTakingInterface(i: TestSuite.ClientInterface) throws -> String { + func methTakingInterface(_ i: TestSuite.ClientInterface) throws -> String { return try i.returnStr() } - func methTakingOptionalInterface(i: Optional) throws -> String { + func methTakingOptionalInterface(_ i: Optional) throws -> String { if (i != nil) { return try i!.returnStr() } else { @@ -39,20 +39,20 @@ final class ClientInterfaceTest: XCTestCase { } func testClientReturn() throws { - try TestHelpers_statics.checkClientInterfaceAscii(i: sClientInterface!) + try TestHelpers_statics.checkClientInterfaceAscii(sClientInterface!) } func testClientReturnUTF8() throws { - try TestHelpers_statics.checkClientInterfaceNonascii(i: sClientInterface!) + try TestHelpers_statics.checkClientInterfaceNonascii(sClientInterface!) } func testClientInterfaceArgs() throws { - try TestHelpers_statics.checkClientInterfaceArgs(i: sClientInterface!) + try TestHelpers_statics.checkClientInterfaceArgs(sClientInterface!) } func testReverseClientInterfaceArgs() throws { let i = try ReverseClientInterface_statics.create() - XCTAssertEqual(try i.methTakingInterface(i:i), "test") - XCTAssertEqual(try i.methTakingOptionalInterface(i:i), "test") + XCTAssertEqual(try i.methTakingInterface(i), "test") + XCTAssertEqual(try i.methTakingOptionalInterface(i), "test") } } diff --git a/test-suite/handwritten-src/swift/CppExceptionTest.swift b/test-suite/handwritten-src/swift/CppExceptionTest.swift index 1ce19d8b..ddb72d74 100644 --- a/test-suite/handwritten-src/swift/CppExceptionTest.swift +++ b/test-suite/handwritten-src/swift/CppExceptionTest.swift @@ -24,7 +24,7 @@ final class CppExceptionTest: XCTestCase { } func testSwiftExceptionHandledByCpp() throws { - let res = try cppInterface.callThrowingAndCatch(cb:SwiftThrower()) + let res = try cppInterface.callThrowingAndCatch(SwiftThrower()) XCTAssertEqual(res, "Swift Error") } } diff --git a/test-suite/handwritten-src/swift/DataTest.swift b/test-suite/handwritten-src/swift/DataTest.swift index 48216e36..b726f79a 100644 --- a/test-suite/handwritten-src/swift/DataTest.swift +++ b/test-suite/handwritten-src/swift/DataTest.swift @@ -10,7 +10,7 @@ final class DataTest: XCTestCase { func testSend() throws { let input: [UInt8] = [0, 1, 2, 3] let buf = Data(input) - try test.sendData(data:buf as NSData) + try test.sendData(buf as NSData) let output = try test.retriveAsBin() XCTAssertEqual(Data(input), output) } @@ -19,7 +19,7 @@ final class DataTest: XCTestCase { let input: [UInt8] = [0, 1, 2, 3] let buf = NSMutableData() buf.append(Data(input)) - try test.sendMutableData(data:buf) + try test.sendMutableData(buf) XCTAssertEqual(Data([3,2,1,0]), buf as Data) } @@ -44,7 +44,7 @@ final class DataTest: XCTestCase { func testSendDataView() throws { let input: [UInt8] = [0, 1, 2, 3] let buf = Data(input) - let output = try test.sendDataView(data:buf as NSData) + let output = try test.sendDataView(buf as NSData) XCTAssertEqual(buf, output) } diff --git a/test-suite/handwritten-src/swift/DurationTest.swift b/test-suite/handwritten-src/swift/DurationTest.swift index 30e3b44f..6df50fe1 100644 --- a/test-suite/handwritten-src/swift/DurationTest.swift +++ b/test-suite/handwritten-src/swift/DurationTest.swift @@ -9,31 +9,31 @@ extension Duration { final class DurationTest: XCTestCase { func test() throws { - XCTAssertEqual(try TestDuration_statics.hoursString(dt:.hours(1)), "1") - XCTAssertEqual(try TestDuration_statics.minutesString(dt:.minutes(1)), "1") - XCTAssertEqual(try TestDuration_statics.secondsString(dt:.seconds(1)), "1") - XCTAssertEqual(try TestDuration_statics.millisString(dt:.milliseconds(1)), "1") - XCTAssertEqual(try TestDuration_statics.microsString(dt:.microseconds(1)), "1") - XCTAssertEqual(try TestDuration_statics.nanosString(dt:.nanoseconds(1)), "1") + XCTAssertEqual(try TestDuration_statics.hoursString(.hours(1)), "1") + XCTAssertEqual(try TestDuration_statics.minutesString(.minutes(1)), "1") + XCTAssertEqual(try TestDuration_statics.secondsString(.seconds(1)), "1") + XCTAssertEqual(try TestDuration_statics.millisString(.milliseconds(1)), "1") + XCTAssertEqual(try TestDuration_statics.microsString(.microseconds(1)), "1") + XCTAssertEqual(try TestDuration_statics.nanosString(.nanoseconds(1)), "1") - XCTAssertEqual(try TestDuration_statics.hours(count:1), .hours(1)) - XCTAssertEqual(try TestDuration_statics.minutes(count:1), .minutes(1)) - XCTAssertEqual(try TestDuration_statics.seconds(count:1), .seconds(1)) - XCTAssertEqual(try TestDuration_statics.millis(count:1), .milliseconds(1)) - XCTAssertEqual(try TestDuration_statics.micros(count:1), .microseconds(1)) - XCTAssertEqual(try TestDuration_statics.nanos(count:1), .nanoseconds(1)) + XCTAssertEqual(try TestDuration_statics.hours(1), .hours(1)) + XCTAssertEqual(try TestDuration_statics.minutes(1), .minutes(1)) + XCTAssertEqual(try TestDuration_statics.seconds(1), .seconds(1)) + XCTAssertEqual(try TestDuration_statics.millis(1), .milliseconds(1)) + XCTAssertEqual(try TestDuration_statics.micros(1), .microseconds(1)) + XCTAssertEqual(try TestDuration_statics.nanos(1), .nanoseconds(1)) - XCTAssertEqual(try TestDuration_statics.hoursf(count:1.5), .minutes(90)) - XCTAssertEqual(try TestDuration_statics.minutesf(count:1.5), .seconds(90)) - XCTAssertEqual(try TestDuration_statics.secondsf(count:1.5), .milliseconds(1500)) - XCTAssertEqual(try TestDuration_statics.millisf(count:1.5), .microseconds(1500)) - XCTAssertEqual(try TestDuration_statics.microsf(count:1.5), .nanoseconds(1500)) - XCTAssertEqual(try TestDuration_statics.nanosf(count:1.0), .nanoseconds(1)) + XCTAssertEqual(try TestDuration_statics.hoursf(1.5), .minutes(90)) + XCTAssertEqual(try TestDuration_statics.minutesf(1.5), .seconds(90)) + XCTAssertEqual(try TestDuration_statics.secondsf(1.5), .milliseconds(1500)) + XCTAssertEqual(try TestDuration_statics.millisf(1.5), .microseconds(1500)) + XCTAssertEqual(try TestDuration_statics.microsf(1.5), .nanoseconds(1500)) + XCTAssertEqual(try TestDuration_statics.nanosf(1.0), .nanoseconds(1)) - XCTAssertEqual(try TestDuration_statics.box(count:1), .seconds(1)) - XCTAssertNil(try TestDuration_statics.box(count:-1)) + XCTAssertEqual(try TestDuration_statics.box(1), .seconds(1)) + XCTAssertNil(try TestDuration_statics.box(-1)) - XCTAssertEqual(try TestDuration_statics.unbox(dt:.seconds(1)), 1) - XCTAssertEqual(try TestDuration_statics.unbox(dt:nil), -1) + XCTAssertEqual(try TestDuration_statics.unbox(.seconds(1)), 1) + XCTAssertEqual(try TestDuration_statics.unbox(nil), -1) } } diff --git a/test-suite/handwritten-src/swift/EnumTest.swift b/test-suite/handwritten-src/swift/EnumTest.swift index e2dbab69..dab3a29e 100644 --- a/test-suite/handwritten-src/swift/EnumTest.swift +++ b/test-suite/handwritten-src/swift/EnumTest.swift @@ -23,24 +23,24 @@ final class EnumTest: XCTestCase { m[Color.blue] = "blue" m[Color.indigo] = "indigo" m[Color.violet] = "violet" - try TestHelpers_statics.checkEnumMap(m:m) + try TestHelpers_statics.checkEnumMap(m) } func testAccessFlagRoundtrip() throws { let flags: [AccessFlags] = [.nobody, .everybody, .ownerRead, [.ownerRead, .ownerWrite], [.ownerRead, .ownerWrite, .ownerExecute]] for flag in flags { - XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripAccess(flag:flag)) - XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripAccessBoxed(flag:flag)) + XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripAccess(flag)) + XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripAccessBoxed(flag)) } - XCTAssertEqual(nil, try FlagRoundtrip_statics.roundtripAccessBoxed(flag:nil)) + XCTAssertEqual(nil, try FlagRoundtrip_statics.roundtripAccessBoxed(nil)) } func testEmptyFlagRoundtrip() throws { let flags: [EmptyFlags] = [.none, .all] for flag in flags { - XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripEmpty(flag:flag)) - XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripEmptyBoxed(flag:flag)) + XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripEmpty(flag)) + XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripEmptyBoxed(flag)) } - XCTAssertEqual(nil, try FlagRoundtrip_statics.roundtripEmptyBoxed(flag:nil)) + XCTAssertEqual(nil, try FlagRoundtrip_statics.roundtripEmptyBoxed(nil)) } } diff --git a/test-suite/handwritten-src/swift/ExampleTest.swift b/test-suite/handwritten-src/swift/ExampleTest.swift index cae8886e..9270f00a 100644 --- a/test-suite/handwritten-src/swift/ExampleTest.swift +++ b/test-suite/handwritten-src/swift/ExampleTest.swift @@ -6,7 +6,7 @@ class MyListener: TextboxListener { deinit { print("*** deinit called") } - func update(items: ItemList) throws { + func update(_ items: ItemList) throws { print("*** update() called") print(items) } @@ -15,8 +15,8 @@ class MyListener: TextboxListener { final class AllTests: XCTestCase { func testExample() throws { let listener = MyListener() - let s = try SortItems_statics.createWithListener(listener: listener) + let s = try SortItems_statics.createWithListener(listener) let items = ItemList(items: ["bbb", "ccc", "aaa"]) - try s.sort(order: .ascending, items: items) + try s.sort(.ascending, items: items) } } diff --git a/test-suite/handwritten-src/swift/MapRecordTest.swift b/test-suite/handwritten-src/swift/MapRecordTest.swift index 8e7e299f..a27b1840 100644 --- a/test-suite/handwritten-src/swift/MapRecordTest.swift +++ b/test-suite/handwritten-src/swift/MapRecordTest.swift @@ -19,16 +19,16 @@ final class MapRecordTest: XCTestCase { } func testSwiftMapToCppMap() throws { - XCTAssertTrue(try TestHelpers_statics.checkMap(m:["String1": 1, "String2": 2, "String3": 3])) + XCTAssertTrue(try TestHelpers_statics.checkMap(["String1": 1, "String2": 2, "String3": 3])) } func testEmptySwiftMapToCppMap() throws { - XCTAssertTrue(try TestHelpers_statics.checkEmptyMap(m:[:])) + XCTAssertTrue(try TestHelpers_statics.checkEmptyMap([:])) } func testSwiftMapListToCppMapList() throws { let sMapList: [Dictionary] = [["String1": 1, "String2": 2, "String3": 3]] - XCTAssertTrue(try TestHelpers_statics.checkMapListRecord(m:MapListRecord(mapList:sMapList))) + XCTAssertTrue(try TestHelpers_statics.checkMapListRecord(MapListRecord(mapList:sMapList))) } func checkSwiftMap(_ smap: Dictionary) { diff --git a/test-suite/handwritten-src/swift/NestedCollectionTest.swift b/test-suite/handwritten-src/swift/NestedCollectionTest.swift index 0d55a0ee..c8bc22b9 100644 --- a/test-suite/handwritten-src/swift/NestedCollectionTest.swift +++ b/test-suite/handwritten-src/swift/NestedCollectionTest.swift @@ -11,6 +11,6 @@ final class NestedCollectionTest: XCTestCase { } func testSwiftNestedRecordToCppNestedCollection() throws { - XCTAssertTrue(try TestHelpers_statics.checkNestedCollection(nc:swiftNestedCollection)) + XCTAssertTrue(try TestHelpers_statics.checkNestedCollection(swiftNestedCollection)) } } diff --git a/test-suite/handwritten-src/swift/OutcomeTest.swift b/test-suite/handwritten-src/swift/OutcomeTest.swift index e7cc00ee..1ab0ffcd 100644 --- a/test-suite/handwritten-src/swift/OutcomeTest.swift +++ b/test-suite/handwritten-src/swift/OutcomeTest.swift @@ -16,9 +16,9 @@ final class OutcomeTest: XCTestCase { XCTAssertNotEqual(r, e) // construct result outcome in swift then pass to native and back - XCTAssertEqual(try TestOutcome_statics.putSuccessOutcome(x:.success("hello")), "hello"); + XCTAssertEqual(try TestOutcome_statics.putSuccessOutcome(.success("hello")), "hello"); // construct error outcome in swift then pass to native and back - XCTAssertEqual(try TestOutcome_statics.putErrorOutcome(x:.failure(42)), 42); + XCTAssertEqual(try TestOutcome_statics.putErrorOutcome(.failure(42)), 42); // Hash equal XCTAssertEqual(r.hashValue, Result.success("hello").hashValue) @@ -36,7 +36,7 @@ final class OutcomeTest: XCTestCase { XCTAssertEqual(ne.o, .failure("hello")) XCTAssertEqual(ne, NestedOutcome(o:.failure("hello"))) - XCTAssertEqual(try TestOutcome_statics.putNestedSuccessOutcome(x:NestedOutcome(o:.success(42))), 42) - XCTAssertEqual(try TestOutcome_statics.putNestedErrorOutcome(x:NestedOutcome(o:.failure("hello"))), "hello") + XCTAssertEqual(try TestOutcome_statics.putNestedSuccessOutcome(NestedOutcome(o:.success(42))), 42) + XCTAssertEqual(try TestOutcome_statics.putNestedErrorOutcome(NestedOutcome(o:.failure("hello"))), "hello") } } diff --git a/test-suite/handwritten-src/swift/PrimitiveListTest.swift b/test-suite/handwritten-src/swift/PrimitiveListTest.swift index 48dc7093..14144857 100644 --- a/test-suite/handwritten-src/swift/PrimitiveListTest.swift +++ b/test-suite/handwritten-src/swift/PrimitiveListTest.swift @@ -7,7 +7,7 @@ final class PrimitivesListTest: XCTestCase { let swiftPrimitiveList: PrimitiveList = PrimitiveList(list: [1, 2, 3]) func testSwiftPrimitiveListToCpp() throws { - XCTAssertTrue(try TestHelpers_statics.checkPrimitiveList(pl:swiftPrimitiveList)) + XCTAssertTrue(try TestHelpers_statics.checkPrimitiveList(swiftPrimitiveList)) } func testCppPrimitiveListToSwift() throws { let converted = try TestHelpers_statics.getPrimitiveList() @@ -15,6 +15,6 @@ final class PrimitivesListTest: XCTestCase { } func testBinary() throws { let b = Data([1,2,3]) - XCTAssertEqual(try TestHelpers_statics.idBinary(b:b), b) + XCTAssertEqual(try TestHelpers_statics.idBinary(b), b) } } diff --git a/test-suite/handwritten-src/swift/PrimitivesTest.swift b/test-suite/handwritten-src/swift/PrimitivesTest.swift index 000acb2d..7ed70d66 100644 --- a/test-suite/handwritten-src/swift/PrimitivesTest.swift +++ b/test-suite/handwritten-src/swift/PrimitivesTest.swift @@ -6,6 +6,6 @@ final class PrimitivesTest: XCTestCase { func testPrimitives() throws { let p = AssortedPrimitives(b:true, eight:123, sixteen:20000, thirtytwo:1000000000, sixtyfour:1234567890123456789, fthirtytwo:1.23, fsixtyfour:1.23, oB:true, oEight:123, oSixteen:20000, oThirtytwo:1000000000, oSixtyfour:1234567890123456789, oFthirtytwo:1.23, oFsixtyfour:1.23) - XCTAssertEqual(p, try TestHelpers_statics.assortedPrimitivesId(i:p)) + XCTAssertEqual(p, try TestHelpers_statics.assortedPrimitivesId(p)) } } diff --git a/test-suite/handwritten-src/swift/ProtoTest.swift b/test-suite/handwritten-src/swift/ProtoTest.swift index 458ab757..a49c8074 100644 --- a/test-suite/handwritten-src/swift/ProtoTest.swift +++ b/test-suite/handwritten-src/swift/ProtoTest.swift @@ -11,20 +11,20 @@ final class ProtoTest: XCTestCase { let p1 = Person.with {$0.name = "tom"; $0.id = 1} let p2 = Person.with {$0.name = "jerry"; $0.id = 2} let proto = AddressBook.with {$0.people = [p1, p2]} - let r = try ProtoTests_statics.protoToStrings(x:proto) + let r = try ProtoTests_statics.protoToStrings(proto) XCTAssertEqual(r[0], "tom") XCTAssertEqual(r[1], "jerry") } func testNativeToSwift() throws { let names = ["tom", "jerry"] - let proto = try ProtoTests_statics.stringsToProto(x:names) + let proto = try ProtoTests_statics.stringsToProto(names) XCTAssertEqual(proto.people[0].name, "tom") XCTAssertEqual(proto.people[1].name, "jerry") } func testZeroSizeNativeToSwift() throws { - let proto = try ProtoTests_statics.stringsToProto(x:[]) + let proto = try ProtoTests_statics.stringsToProto([]) let serialized: Data = try proto.serializedBytes() XCTAssertEqual(serialized.count, 0) } @@ -32,9 +32,9 @@ final class ProtoTest: XCTestCase { func testEmbeddedProto() throws { let p = Person.with {$0.name = "tom"; $0.id = 1} let rec = RecordWithEmbeddedProto(person:p) - let s = try ProtoTests_statics.embeddedProtoToString(x:rec) + let s = try ProtoTests_statics.embeddedProtoToString(rec) XCTAssertEqual(s, p.name) - let rec2 = try ProtoTests_statics.stringToEmbeddedProto(x:s); + let rec2 = try ProtoTests_statics.stringToEmbeddedProto(s); XCTAssertEqual(s, rec2.person.name) } @@ -42,20 +42,20 @@ final class ProtoTest: XCTestCase { let p1 = Person.with {$0.name = "tom"; $0.id = 1} let p2 = Person.with {$0.name = "jerry"; $0.id = 2} var plist = [p1, p2] - let slist = try ProtoTests_statics.protoListToStrings(x:plist) + let slist = try ProtoTests_statics.protoListToStrings(plist) XCTAssertEqual(slist[0], "tom") XCTAssertEqual(slist[1], "jerry") - plist = try ProtoTests_statics.stringsToProtoList(x:slist) + plist = try ProtoTests_statics.stringsToProtoList(slist) XCTAssertEqual(plist[0].name, "tom") XCTAssertEqual(plist[1].name, "jerry") - let s = try ProtoTests_statics.optionalProtoToString(x:p1) + let s = try ProtoTests_statics.optionalProtoToString(p1) XCTAssertEqual(s, "tom") - let p = try ProtoTests_statics.stringToOptionalProto(x:"tom") + let p = try ProtoTests_statics.stringToOptionalProto("tom") XCTAssertEqual(p?.name, "tom") - let r = try ProtoTests_statics.stringToProtoOutcome(x:"tom") + let r = try ProtoTests_statics.stringToProtoOutcome("tom") XCTAssertEqual(try r.get().name, "tom") } } diff --git a/test-suite/handwritten-src/swift/SetRecordTest.swift b/test-suite/handwritten-src/swift/SetRecordTest.swift index 28a48ba3..d9c666b2 100644 --- a/test-suite/handwritten-src/swift/SetRecordTest.swift +++ b/test-suite/handwritten-src/swift/SetRecordTest.swift @@ -15,6 +15,6 @@ final class SetRecordTest: XCTestCase { func testSwiftSetToCppSet() throws { let sSetRecord = SetRecord(set: Set(["StringA", "StringB", "StringC"]), iset:Set([])) - XCTAssertTrue(try TestHelpers_statics.checkSetRecord(rec:sSetRecord)) + XCTAssertTrue(try TestHelpers_statics.checkSetRecord(sSetRecord)) } } diff --git a/test-suite/handwritten-src/swift/TokenTest.swift b/test-suite/handwritten-src/swift/TokenTest.swift index a0f7fd29..99c1ce8d 100644 --- a/test-suite/handwritten-src/swift/TokenTest.swift +++ b/test-suite/handwritten-src/swift/TokenTest.swift @@ -10,25 +10,25 @@ final class TokenTest: XCTestCase { func testTokens() throws { let st = SwiftToken() - XCTAssertIdentical(try TestHelpers_statics.tokenId(t:st), st) + XCTAssertIdentical(try TestHelpers_statics.tokenId(st), st) } func testNullToken() throws { - XCTAssertNil(try TestHelpers_statics.tokenId(t:nil)) + XCTAssertNil(try TestHelpers_statics.tokenId(nil)) } func testCppToken() throws { let ct = try TestHelpers_statics.createCppToken(); - XCTAssertIdentical(try TestHelpers_statics.tokenId(t:ct), ct) - try TestHelpers_statics.checkCppToken(t:ct) + XCTAssertIdentical(try TestHelpers_statics.tokenId(ct), ct) + try TestHelpers_statics.checkCppToken(ct) } func testTokenType() throws { - try TestHelpers_statics.checkTokenType(t:SwiftToken(), type:"Swift") - try TestHelpers_statics.checkTokenType(t:TestHelpers_statics.createCppToken(), type:"C++"); + try TestHelpers_statics.checkTokenType(SwiftToken(), type:"Swift") + try TestHelpers_statics.checkTokenType(TestHelpers_statics.createCppToken(), type:"C++"); var threw = false do { - try TestHelpers_statics.checkTokenType(t: SwiftToken(), type:"foo") + try TestHelpers_statics.checkTokenType(SwiftToken(), type:"foo") } catch { threw = true } @@ -38,7 +38,7 @@ final class TokenTest: XCTestCase { func testNotCppToken() { var threw = false do { - try TestHelpers_statics.checkCppToken(t:SwiftToken()) + try TestHelpers_statics.checkCppToken(SwiftToken()) } catch { threw = true } diff --git a/test-suite/handwritten-src/swift/WcharTest.swift b/test-suite/handwritten-src/swift/WcharTest.swift index f9adc055..805a9c3c 100644 --- a/test-suite/handwritten-src/swift/WcharTest.swift +++ b/test-suite/handwritten-src/swift/WcharTest.swift @@ -9,7 +9,7 @@ final class WcharTest: XCTestCase { func test() throws { XCTAssertEqual(try WcharTestHelpers_statics.getRecord().s, STR1) XCTAssertEqual(try WcharTestHelpers_statics.getString(), STR2) - XCTAssertTrue(try WcharTestHelpers_statics.checkString(str:STR2)) - XCTAssertTrue(try WcharTestHelpers_statics.checkRecord(rec:WcharTestRec(s:STR1))) + XCTAssertTrue(try WcharTestHelpers_statics.checkString(STR2)) + XCTAssertTrue(try WcharTestHelpers_statics.checkRecord(WcharTestRec(s:STR1))) } } From 6f52b82dc6be6cd94121ff9fdcf9d39e356b1d05 Mon Sep 17 00:00:00 2001 From: Tommy Blunt Date: Sat, 13 Jul 2024 18:13:46 -0700 Subject: [PATCH 24/68] Fix extern type usage with non-nullable ptrs When non-nullable pointers are set, externally defined interface types were not being treated the same as file-local interface types, causing missing import headers and incorrect pointer types to be used in C++ generated code. --- src/source/CppMarshal.scala | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/source/CppMarshal.scala b/src/source/CppMarshal.scala index d4876555..d3a60f08 100644 --- a/src/source/CppMarshal.scala +++ b/src/source/CppMarshal.scala @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * This file has been modified by Snap, Inc. */ @@ -117,7 +117,12 @@ class CppMarshal(spec: Spec) extends Marshal(spec) { case e: MExtern => e.defType match { // Do not forward declare extern types, they might be in arbitrary namespaces. // This isn't a problem as extern types cannot cause dependency cycles with types being generated here - case DInterface => List(ImportRef(""), ImportRef(e.cpp.header)) + case DInterface => + val base = List(ImportRef(""), ImportRef(e.cpp.header)) + spec.cppNnHeader match { + case Some(nnHdr) => ImportRef(nnHdr) :: base + case _ => base + } case _ => List(ImportRef(resolveExtCppHdr(e.cpp.header))) } case p: MProtobuf => @@ -211,6 +216,11 @@ class CppMarshal(spec: Spec) extends Marshal(spec) { case DInterface => s"${nnType}<${withNamespace(idCpp.ty(d.name))}>" case _ => base(tm.base) + args } + case e: MExtern => + e.defType match { + case DInterface => s"${nnType}<${e.cpp.typename}>" + case _ => base(tm.base) + args + } case MOptional => tm.args.head.base match { case d: MDef => @@ -218,6 +228,11 @@ class CppMarshal(spec: Spec) extends Marshal(spec) { case DInterface => s"std::shared_ptr<${withNamespace(idCpp.ty(d.name))}>" case _ => base(tm.base) + args } + case e: MExtern => + e.defType match { + case DInterface => s"std::shared_ptr<${e.cpp.typename}>" + case _ => base(tm.base) + args + } case _ => base(tm.base) + args } case _ => base(tm.base) + args From 5858e64f7d657ea7a393b8b94480984e0dedca2f Mon Sep 17 00:00:00 2001 From: Li Feng Date: Mon, 15 Jul 2024 10:27:05 +1000 Subject: [PATCH 25/68] delete test code --- test-suite/BUILD | 2 +- .../handwritten-src/swift/ExampleTest.swift | 22 ------------------- 2 files changed, 1 insertion(+), 23 deletions(-) delete mode 100644 test-suite/handwritten-src/swift/ExampleTest.swift diff --git a/test-suite/BUILD b/test-suite/BUILD index f7a18767..1d833ad7 100644 --- a/test-suite/BUILD +++ b/test-suite/BUILD @@ -199,7 +199,7 @@ swift_error_files = "handwritten-src/swift/*+Error.swift" swift_test( name = "djinni-swift-tests", srcs = glob(['handwritten-src/swift/*.swift'], exclude = [swift_helper_files, swift_error_files]), - deps = [':test-swift-bridge', '//examples:textsort-swift-bridge'], + deps = [':test-swift-bridge'], copts = [ "-cxx-interoperability-mode=default", "-Xcc", diff --git a/test-suite/handwritten-src/swift/ExampleTest.swift b/test-suite/handwritten-src/swift/ExampleTest.swift deleted file mode 100644 index 9270f00a..00000000 --- a/test-suite/handwritten-src/swift/ExampleTest.swift +++ /dev/null @@ -1,22 +0,0 @@ -import XCTest -@testable import TextSort; -@testable import TextSortBridge; - -class MyListener: TextboxListener { - deinit { - print("*** deinit called") - } - func update(_ items: ItemList) throws { - print("*** update() called") - print(items) - } -} - -final class AllTests: XCTestCase { - func testExample() throws { - let listener = MyListener() - let s = try SortItems_statics.createWithListener(listener) - let items = ItemList(items: ["bbb", "ccc", "aaa"]) - try s.sort(.ascending, items: items) - } -} From f603002c3396bfda1af6d991708dadaa5cf70a3e Mon Sep 17 00:00:00 2001 From: Li Feng Date: Mon, 15 Jul 2024 13:16:58 +1000 Subject: [PATCH 26/68] Allow move-only types in Promise<>. (based on contribution from jb-gcx) --- support-lib/cpp/Future.hpp | 1 + test-suite/handwritten-src/cpp/test_helpers.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/support-lib/cpp/Future.hpp b/support-lib/cpp/Future.hpp index dede703d..59d5a0e0 100644 --- a/support-lib/cpp/Future.hpp +++ b/support-lib/cpp/Future.hpp @@ -57,6 +57,7 @@ struct ValueHolder { using type = T; std::optional value; T getValueUnsafe() const {return *value;} + T getValueUnsafe() {return std::move(*value);} }; template <> struct ValueHolder { diff --git a/test-suite/handwritten-src/cpp/test_helpers.cpp b/test-suite/handwritten-src/cpp/test_helpers.cpp index 34920983..a6932efa 100644 --- a/test-suite/handwritten-src/cpp/test_helpers.cpp +++ b/test-suite/handwritten-src/cpp/test_helpers.cpp @@ -19,6 +19,11 @@ namespace testsuite { +// verify we we can put move only types in futures +std::unique_ptr testFutureMove() { + return djinni::Promise>::resolve(nullptr).get(); +} + SetRecord TestHelpers::get_set_record() { return SetRecord { { "StringA", From fe7e06eb40e2af8c6963a6f815525521ab57f9d9 Mon Sep 17 00:00:00 2001 From: Jan Buenker Date: Mon, 8 Jul 2024 22:17:05 +0200 Subject: [PATCH 27/68] Make `unexpect` available for djinni expected --- support-lib/cpp/expected.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/support-lib/cpp/expected.hpp b/support-lib/cpp/expected.hpp index 31877afb..0cd3c265 100644 --- a/support-lib/cpp/expected.hpp +++ b/support-lib/cpp/expected.hpp @@ -17,6 +17,7 @@ namespace djinni { using ::std::expected; using ::std::unexpected; +inline constexpr ::std::unexpect_t unexpect{}; } @@ -28,6 +29,7 @@ namespace djinni { using ::tl::unexpected; using ::tl::expected; +inline constexpr ::tl::unexpect_t unexpect{}; } From 00878de8d537f8fba114198469897005c3f38de7 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Tue, 16 Jul 2024 10:15:21 +1000 Subject: [PATCH 28/68] delete unneeded overload --- support-lib/cpp/Future.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/support-lib/cpp/Future.hpp b/support-lib/cpp/Future.hpp index 59d5a0e0..aee1c23e 100644 --- a/support-lib/cpp/Future.hpp +++ b/support-lib/cpp/Future.hpp @@ -56,7 +56,6 @@ template struct ValueHolder { using type = T; std::optional value; - T getValueUnsafe() const {return *value;} T getValueUnsafe() {return std::move(*value);} }; template <> From fb12c73a0ef3f5c913652f45c0357be63b2435d8 Mon Sep 17 00:00:00 2001 From: Jan Buenker Date: Mon, 8 Jul 2024 16:13:01 +0200 Subject: [PATCH 29/68] Fix continuations in djinni::Future coroutines --- support-lib/cpp/Future.hpp | 51 ++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/support-lib/cpp/Future.hpp b/support-lib/cpp/Future.hpp index 6207d6e9..182ded0e 100644 --- a/support-lib/cpp/Future.hpp +++ b/support-lib/cpp/Future.hpp @@ -16,6 +16,8 @@ #pragma once +#include "expected.hpp" + #include #include #include @@ -364,34 +366,63 @@ class Future { return true; } + template struct PromiseTypeBase { Promise _promise; + std::optional> _result{}; + + struct FinalAwaiter { + constexpr bool await_ready() const noexcept { + return false; + } + bool await_suspend(std::coroutine_handle finished) const noexcept { + auto& promise_type = finished.promise(); + if (*promise_type._result) { + if constexpr (std::is_void_v) { + promise_type._promise.setValue(); + } else { + promise_type._promise.setValue(std::move(**promise_type._result)); + } + } else { + promise_type._promise.setException(std::move(promise_type._result->error())); + } + return false; + } + constexpr void await_resume() const noexcept {} + }; - detail::SuspendNever initial_suspend() { return {}; } - detail::SuspendNever final_suspend() noexcept { return {}; } + constexpr detail::SuspendNever initial_suspend() const noexcept { return {}; } + FinalAwaiter final_suspend() const noexcept { return {}; } Future get_return_object() noexcept { return _promise.getFuture(); } void unhandled_exception() { - _promise.setException(std::current_exception()); + _result.emplace(djinni::unexpect, std::current_exception()); } }; - template - struct PromiseType: PromiseTypeBase{ - template + + struct PromiseType: PromiseTypeBase{ + template >> void return_value(V&& value) { - this->_promise.setValue(std::forward(value)); + this->_result.emplace(std::forward(value)); + } + void return_value(T&& value) { + this->_result.emplace(std::move(value)); + } + void return_value(const T& value) { + this->_result.emplace(value); } }; - using promise_type = PromiseType; + using promise_type = PromiseType; #endif }; #if defined(DJINNI_FUTURE_HAS_COROUTINE_SUPPORT) -template<> template<> struct Future::PromiseType:PromiseTypeBase { +template<> +struct Future::PromiseType : PromiseTypeBase { void return_void() { - this->_promise.setValue(); + _result.emplace(); } }; #endif From ee2bcb1bb53abef60badfc37ae52e1d41e49d8c4 Mon Sep 17 00:00:00 2001 From: Jan Buenker Date: Tue, 16 Jul 2024 12:37:21 +0200 Subject: [PATCH 30/68] Add an XCTest for coroutine cleanup order --- .../objc/tests/DBCppFutureTests.mm | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 test-suite/handwritten-src/objc/tests/DBCppFutureTests.mm diff --git a/test-suite/handwritten-src/objc/tests/DBCppFutureTests.mm b/test-suite/handwritten-src/objc/tests/DBCppFutureTests.mm new file mode 100644 index 00000000..584675a4 --- /dev/null +++ b/test-suite/handwritten-src/objc/tests/DBCppFutureTests.mm @@ -0,0 +1,70 @@ +#import +#import + +#include + +#ifdef DJINNI_FUTURE_HAS_COROUTINE_SUPPORT + +namespace { + +template +struct OnCleanup { + OnCleanup(Functor&& functor) + :functor{std::move(functor)} + {} + ~OnCleanup() { + functor(); + } + Functor functor; +}; + +djinni::Future inner_coroutine(std::vector& cleanup_ids, int id, djinni::Future suspendOn) { + OnCleanup cleanup{ + [&] { + cleanup_ids.push_back(id); + } + }; + + co_await suspendOn; + co_return; // do not remove! +} + +djinni::Future outer_coroutine(std::vector& cleanup_ids, int id, djinni::Future suspendOn) { + OnCleanup cleanup{ + [&] { + cleanup_ids.push_back(id); + } + }; + + co_await inner_coroutine(cleanup_ids, id + 1, std::move(suspendOn)); + co_return; // do not remove! +} + +} + +#endif + +@interface DBCppFutureTests : XCTestCase +@end + +@implementation DBCppFutureTests + +#ifdef DJINNI_FUTURE_HAS_COROUTINE_SUPPORT +- (void) testFutureCoroutines_cleanupOrder { + std::vector cleanupIds{}; + + djinni::Promise djinniPromise{}; + + auto coroutineFuture = outer_coroutine(cleanupIds, 0, djinniPromise.getFuture()); + XCTAssertFalse(coroutineFuture.isReady()); + + djinniPromise.setValue(); + XCTAssertTrue(coroutineFuture.isReady()); + + XCTAssertEqual(cleanupIds.size(), 2); + XCTAssertEqual(cleanupIds[0], 1); // the inner coroutine should be cleaned up first + XCTAssertEqual(cleanupIds[1], 0); // ... then the outer +} +#endif + +@end From c6c9f07e0d6f73bfdaccb0980b153edc74ebf257 Mon Sep 17 00:00:00 2001 From: Jan Buenker Date: Thu, 18 Jul 2024 12:32:42 +0200 Subject: [PATCH 31/68] Fix feature detection for experimental coroutines --- support-lib/cpp/Future.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/support-lib/cpp/Future.hpp b/support-lib/cpp/Future.hpp index 182ded0e..578a55cd 100644 --- a/support-lib/cpp/Future.hpp +++ b/support-lib/cpp/Future.hpp @@ -27,15 +27,20 @@ #include #include -#if defined(__cpp_coroutines) || defined(__cpp_impl_coroutine) -#if __has_include() +#ifdef __has_include +#if __has_include() +#include +#endif +#endif + +#if defined(__cpp_impl_coroutine) && defined(__cpp_lib_coroutine) #include namespace djinni::detail { template using CoroutineHandle = std::coroutine_handle; using SuspendNever = std::suspend_never; } #define DJINNI_FUTURE_HAS_COROUTINE_SUPPORT 1 -#elif __has_include() +#elif defined(__cpp_coroutines) && __has_include() #include namespace djinni::detail { template using CoroutineHandle = std::experimental::coroutine_handle; @@ -43,7 +48,6 @@ } #define DJINNI_FUTURE_HAS_COROUTINE_SUPPORT 1 #endif -#endif namespace djinni { @@ -375,7 +379,7 @@ class Future { constexpr bool await_ready() const noexcept { return false; } - bool await_suspend(std::coroutine_handle finished) const noexcept { + bool await_suspend(detail::CoroutineHandle finished) const noexcept { auto& promise_type = finished.promise(); if (*promise_type._result) { if constexpr (std::is_void_v) { From ae855ee0dd43be735156880a72bca08e188040f8 Mon Sep 17 00:00:00 2001 From: Kwanho Lee Date: Thu, 18 Jul 2024 23:21:44 -0700 Subject: [PATCH 32/68] add SharedFuture --- .bazelrc | 2 +- support-lib/cpp/Future.hpp | 3 +- support-lib/cpp/SharedFuture.hpp | 138 ++++++++++++++++++ test-suite/BUILD | 1 + .../objc/tests/DBSharedFutureTest.mm | 61 ++++++++ 5 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 support-lib/cpp/SharedFuture.hpp create mode 100644 test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm diff --git a/.bazelrc b/.bazelrc index 8b9d0d7d..bfda4099 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1 +1 @@ -build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --incompatible_java_common_parameters=false --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder --nouse_workers_with_dexbuilder +build --cxxopt=-std=c++17 --cxxopt=-fcoroutines-ts --host_cxxopt=-std=c++17 --host_cxxopt=-fcoroutines-ts --incompatible_java_common_parameters=false --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder --nouse_workers_with_dexbuilder diff --git a/support-lib/cpp/Future.hpp b/support-lib/cpp/Future.hpp index f939aecb..f67a7a73 100644 --- a/support-lib/cpp/Future.hpp +++ b/support-lib/cpp/Future.hpp @@ -379,7 +379,8 @@ class Future { constexpr bool await_ready() const noexcept { return false; } - bool await_suspend(detail::CoroutineHandle finished) const noexcept { + template + bool await_suspend(detail::CoroutineHandle

finished) const noexcept { auto& promise_type = finished.promise(); if (*promise_type._result) { if constexpr (std::is_void_v) { diff --git a/support-lib/cpp/SharedFuture.hpp b/support-lib/cpp/SharedFuture.hpp new file mode 100644 index 00000000..734ccb5e --- /dev/null +++ b/support-lib/cpp/SharedFuture.hpp @@ -0,0 +1,138 @@ +/** + * Copyright 2021 Snap, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #pragma once + +#include "Future.hpp" + +#include +#include +#include +#include +#include + +namespace djinni { + +// SharedFuture is a wrapper around djinni::Future to allow multiple consumers (i.e. like std::shared_future) +// The API is designed to be similar to djinni::Future. +template +class SharedFuture { +public: + // Create SharedFuture from Future. Runtime error if the future is already consumed. + explicit SharedFuture(Future&& future); + + // Transform into Future. + Future toFuture() const { + if (await_ready()) { + co_return await_resume(); // return stored value directly + } + co_return co_await SharedFuture(*this); // retain copy during coroutine suspension + } + + void wait() const { + return [this]() -> Future { co_await *this; }().wait(); + } + + decltype(auto) get() const { + wait(); + return await_resume(); + } + + // Transform the result of this future into a new future. The behavior is same as Future::then except that + // it doesn't consume the future, and can be called multiple times. + template + SharedFuture>>> then(Func transform) const { + co_return transform(co_await SharedFuture(*this)); // retain copy during coroutine suspension + } + + // Overload for T = void or `transform` takes no arugment. + template>> + SharedFuture>>> then(Func transform) const { + co_await SharedFuture(*this); // retain copy during coroutine suspension + co_return transform(); + } + + // -- coroutine support implementation only; not intended externally -- + + bool await_ready() const { + std::scoped_lock lock(_sharedStates->mutex); + return _sharedStates->storedValue.has_value(); + } + + decltype(auto) await_resume() const { + if constexpr (!std::is_void_v) { + return *_sharedStates->storedValue; + } + } + + bool await_suspend(detail::CoroutineHandle<> h) const; + + struct Promise : public Future::promise_type { + SharedFuture get_return_object() noexcept { + return SharedFuture(Future::promise_type::get_return_object()); + } + }; + using promise_type = Promise; + +private: + struct SharedStates { + std::recursive_mutex mutex; + std::optional, std::monostate, T>> storedValue = std::nullopt; + std::vector> coroutineHandles; + }; + // Use a shared_ptr to allow copying SharedFuture. + std::shared_ptr _sharedStates = std::make_shared(); +}; + +// CTAD deduction guide to construct from Future directly. +template +SharedFuture(Future&&) -> SharedFuture; + +// ------------------ Implementation ------------------ + +template +SharedFuture::SharedFuture(Future&& future) { + // `future` will invoke all continuations when it is ready. + future.then([sharedStates = _sharedStates](auto futureResult) { + std::vector toCall = [&] { + std::scoped_lock lock(sharedStates->mutex); + if constexpr (std::is_void_v) { + sharedStates->storedValue.emplace(); + } else { + sharedStates->storedValue = futureResult.get(); + } + return std::move(sharedStates->coroutineHandles); + }(); + for (auto& handle : toCall) { + handle(); + } + }); +} + +template +bool SharedFuture::await_suspend(detail::CoroutineHandle<> h) const { + { + std::unique_lock lock(_sharedStates->mutex); + if (!_sharedStates->storedValue) { + _sharedStates->coroutineHandles.push_back(std::move(h)); + return true; + } + } + h(); + return true; +} + +} // namespace djinni \ No newline at end of file diff --git a/test-suite/BUILD b/test-suite/BUILD index fa6cb8dd..d13f2f83 100644 --- a/test-suite/BUILD +++ b/test-suite/BUILD @@ -55,6 +55,7 @@ objc_library( copts = [ "-ObjC++", "-std=c++17", + "-fcoroutines-ts" ], srcs = glob([ "generated-src/objc/**/*.mm", diff --git a/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm b/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm new file mode 100644 index 00000000..f2c226e4 --- /dev/null +++ b/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm @@ -0,0 +1,61 @@ +#import +#import + +#include "../../../support-lib/cpp/SharedFuture.hpp" + +@interface DBSharedFutureTest : XCTestCase +@end + +@implementation DBSharedFutureTest + +- (void)setUp +{ + [super setUp]; +} + +- (void)tearDown +{ + [super tearDown]; +} + +- (void)testCreateFuture +{ + djinni::SharedFuture resolvedInt(djinni::Promise::resolve(42)); + XCTAssertEqual(resolvedInt.get(), 42); + + djinni::Promise strPromise; + djinni::SharedFuture futureString(strPromise.getFuture()); + + strPromise.setValue(@"foo"); + XCTAssertEqualObjects(futureString.get(), @"foo"); +} + +- (void)testThen +{ + djinni::Promise intPromise; + djinni::SharedFuture futureInt(intPromise.getFuture()); + + auto transformedInt = futureInt.then([](int i) { return 2 * i; }); + + intPromise.setValue(42); + XCTAssertEqual(transformedInt.get(), 84); + + // Also verify multiple consumers and chaining. + auto transformedString = futureInt.then([](int i) { return std::to_string(i); }); + auto futurePlusOneTimesTwo = futureInt.then([](int i) { return i + 1; }).then([](int i) { return 2 * i; }); + auto futureStringLen = transformedString.then([](const std::string& s) { return s.length(); }).toFuture(); + + XCTAssertEqual(transformedString.get(), std::string("42")); + XCTAssertEqual(futurePlusOneTimesTwo.get(), (42 + 1) * 2); + XCTAssertEqual(futureStringLen.get(), 2); + + XCTAssertEqual(futureInt.get(), 42); + + auto voidFuture = transformedString.then([]() {}); + voidFuture.wait(); + + auto intFuture2 = voidFuture.then([]() { return 43; }); + XCTAssertEqual(intFuture2.get(), 43); +} + +@end From 74c6a57115a1ab3a8a3020b4abe1bdd1160e34ec Mon Sep 17 00:00:00 2001 From: techleeksnap <133064333+techleeksnap@users.noreply.github.com> Date: Thu, 18 Jul 2024 23:27:15 -0700 Subject: [PATCH 33/68] Update support-lib/cpp/SharedFuture.hpp --- support-lib/cpp/SharedFuture.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support-lib/cpp/SharedFuture.hpp b/support-lib/cpp/SharedFuture.hpp index 734ccb5e..58677347 100644 --- a/support-lib/cpp/SharedFuture.hpp +++ b/support-lib/cpp/SharedFuture.hpp @@ -135,4 +135,4 @@ bool SharedFuture::await_suspend(detail::CoroutineHandle<> h) const { return true; } -} // namespace djinni \ No newline at end of file +} // namespace djinni From 74cedd6edd163d8ef94cbb74f96e120a94249b16 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Mon, 22 Jul 2024 23:12:15 +1000 Subject: [PATCH 34/68] cleanup --- examples/BUILD | 16 ++----- test-suite/BUILD | 44 ++++--------------- .../handwritten-src/swift/ArrayTest.swift | 1 - .../handwritten-src/swift/AsyncTest.swift | 1 - .../swift/ClientInterfaceTest.swift | 2 +- .../handwritten-src/swift/ConstantsTest.swift | 1 - .../swift/CppExceptionTest.swift | 1 - .../handwritten-src/swift/DataTest.swift | 1 - .../handwritten-src/swift/DurationTest.swift | 1 - .../handwritten-src/swift/EnumTest.swift | 1 - .../handwritten-src/swift/MapRecordTest.swift | 1 - .../swift/NestedCollectionTest.swift | 1 - .../handwritten-src/swift/OutcomeTest.swift | 1 - .../swift/PrimitiveListTest.swift | 1 - .../swift/PrimitivesTest.swift | 1 - .../handwritten-src/swift/ProtoTest.swift | 1 - .../handwritten-src/swift/SetRecordTest.swift | 1 - .../handwritten-src/swift/TokenTest.swift | 1 - .../handwritten-src/swift/WcharTest.swift | 1 - 19 files changed, 12 insertions(+), 66 deletions(-) diff --git a/examples/BUILD b/examples/BUILD index 13fa3cd2..c3bfeb72 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -109,15 +109,10 @@ swift_private_files = "generated-src/swift/*+Private.swift" swift_library( name = "textsort-swift", module_name = "TextSort", - generated_header_name = "Textsort-Swift.h", - generates_header = True, srcs = glob([ "generated-src/swift/*.swift", ], exclude = [ swift_private_files ]), - copts = [ - "-cxx-interoperability-mode=default", - "-Xcc", "-std=c++17", - ], + copts = ["-cxx-interoperability-mode=default", "-Xcc", "-std=c++17",], deps = [ "//support-lib:djinni-support-swift", ], @@ -128,10 +123,7 @@ swift_library( name = "textsort-swift-bridge", module_name = "TextSortBridge", srcs = glob([swift_private_files,]), - copts = [ - "-cxx-interoperability-mode=default", - "-Xcc", "-std=c++17", - ], + copts = ["-cxx-interoperability-mode=default", "-Xcc", "-std=c++17",], deps = [ ":textsort-common", ":textsort-swift", @@ -160,9 +152,7 @@ cc_library( "//support-lib:djinni-support-common", "//support-lib:djinni-support-swiftxx", ], - copts = [ - "-std=c++17", - ], + copts = ["-std=c++17",], tags = ["swift_module=TextSortCxx"], visibility = ["//visibility:public"], ) diff --git a/test-suite/BUILD b/test-suite/BUILD index 1d833ad7..4c73d0ce 100644 --- a/test-suite/BUILD +++ b/test-suite/BUILD @@ -200,49 +200,24 @@ swift_test( name = "djinni-swift-tests", srcs = glob(['handwritten-src/swift/*.swift'], exclude = [swift_helper_files, swift_error_files]), deps = [':test-swift-bridge'], - copts = [ - "-cxx-interoperability-mode=default", - "-Xcc", - "-std=c++17" - ], + copts = ["-cxx-interoperability-mode=default", "-Xcc", "-std=c++17"], ) -swift_private_files = "generated-src/swift/*+Private.swift" - swift_library( - name = "test-swift", + name = "test-swift-bridge", module_name = "TestSuite", - generated_header_name = "TestSuite-Swift.h", - generates_header = True, srcs = glob([ "generated-src/swift/*.swift", - swift_error_files - ], exclude = [ swift_private_files ]), - copts = [ - "-cxx-interoperability-mode=default", - "-Xcc", "-std=c++17", - ], - deps = [ - "//support-lib:djinni-support-swift", - ":protobuf-test-swift" - ], - visibility = ["//visibility:public"], -) - -swift_library( - name = "test-swift-bridge", - module_name = "TestSuiteBridge", - srcs = glob([swift_private_files, swift_helper_files]), - copts = [ - "-cxx-interoperability-mode=default", - "-Xcc", "-std=c++17", - ], + swift_error_files, + swift_helper_files + ]), + copts = ["-cxx-interoperability-mode=default", "-Xcc", "-std=c++17",], deps = [ ":djinni-tests-common", - ":test-swift", ":test-swiftxx", "//support-lib:djinni-support-swift", "//support-lib:djinni-support-swiftxx", + ":protobuf-test-swift" ], visibility = ["//visibility:public"], ) @@ -271,13 +246,10 @@ cc_library( ], deps = [ ":djinni-tests-common", - ":test-swift", "//support-lib:djinni-support-common", "//support-lib:djinni-support-swiftxx", ], - copts = [ - "-std=c++17", - ], + copts = ["-std=c++17",], tags = ["swift_module=TestSuiteCxx"], visibility = ["//visibility:public"], ) diff --git a/test-suite/handwritten-src/swift/ArrayTest.swift b/test-suite/handwritten-src/swift/ArrayTest.swift index 842de7c3..1dff6673 100644 --- a/test-suite/handwritten-src/swift/ArrayTest.swift +++ b/test-suite/handwritten-src/swift/ArrayTest.swift @@ -1,6 +1,5 @@ import XCTest @testable import TestSuite -@testable import TestSuiteBridge final class ArrayTest: XCTestCase { func testArrays() throws { diff --git a/test-suite/handwritten-src/swift/AsyncTest.swift b/test-suite/handwritten-src/swift/AsyncTest.swift index 39419208..ea07f211 100644 --- a/test-suite/handwritten-src/swift/AsyncTest.swift +++ b/test-suite/handwritten-src/swift/AsyncTest.swift @@ -2,7 +2,6 @@ import XCTest import DjinniSupport import Combine @testable import TestSuite -@testable import TestSuiteBridge final class AsyncTest: XCTestCase { diff --git a/test-suite/handwritten-src/swift/ClientInterfaceTest.swift b/test-suite/handwritten-src/swift/ClientInterfaceTest.swift index 22dfe546..8380ecd2 100644 --- a/test-suite/handwritten-src/swift/ClientInterfaceTest.swift +++ b/test-suite/handwritten-src/swift/ClientInterfaceTest.swift @@ -1,6 +1,6 @@ import XCTest @testable import TestSuite -@testable import TestSuiteBridge + struct ClientInterfaceError: Error { var msg: String diff --git a/test-suite/handwritten-src/swift/ConstantsTest.swift b/test-suite/handwritten-src/swift/ConstantsTest.swift index 80161819..66d82fc3 100644 --- a/test-suite/handwritten-src/swift/ConstantsTest.swift +++ b/test-suite/handwritten-src/swift/ConstantsTest.swift @@ -1,7 +1,6 @@ import XCTest import DjinniSupport @testable import TestSuite -@testable import TestSuiteBridge final class ConstantsTest: XCTestCase { func testConstPrimitives() throws { diff --git a/test-suite/handwritten-src/swift/CppExceptionTest.swift b/test-suite/handwritten-src/swift/CppExceptionTest.swift index ddb72d74..112ae367 100644 --- a/test-suite/handwritten-src/swift/CppExceptionTest.swift +++ b/test-suite/handwritten-src/swift/CppExceptionTest.swift @@ -1,7 +1,6 @@ import XCTest import DjinniSupport @testable import TestSuite -@testable import TestSuiteBridge final class CppExceptionTest: XCTestCase { diff --git a/test-suite/handwritten-src/swift/DataTest.swift b/test-suite/handwritten-src/swift/DataTest.swift index b726f79a..ec76dac5 100644 --- a/test-suite/handwritten-src/swift/DataTest.swift +++ b/test-suite/handwritten-src/swift/DataTest.swift @@ -1,7 +1,6 @@ import XCTest import Foundation @testable import TestSuite -@testable import TestSuiteBridge final class DataTest: XCTestCase { diff --git a/test-suite/handwritten-src/swift/DurationTest.swift b/test-suite/handwritten-src/swift/DurationTest.swift index 6df50fe1..60756953 100644 --- a/test-suite/handwritten-src/swift/DurationTest.swift +++ b/test-suite/handwritten-src/swift/DurationTest.swift @@ -1,6 +1,5 @@ import XCTest @testable import TestSuite -@testable import TestSuiteBridge extension Duration { static func hours(_ h: Double) -> Duration {return .seconds(h*3600)} diff --git a/test-suite/handwritten-src/swift/EnumTest.swift b/test-suite/handwritten-src/swift/EnumTest.swift index dab3a29e..2aedfe42 100644 --- a/test-suite/handwritten-src/swift/EnumTest.swift +++ b/test-suite/handwritten-src/swift/EnumTest.swift @@ -1,6 +1,5 @@ import XCTest @testable import TestSuite -@testable import TestSuiteBridge final class EnumTest: XCTestCase { diff --git a/test-suite/handwritten-src/swift/MapRecordTest.swift b/test-suite/handwritten-src/swift/MapRecordTest.swift index a27b1840..e7f09014 100644 --- a/test-suite/handwritten-src/swift/MapRecordTest.swift +++ b/test-suite/handwritten-src/swift/MapRecordTest.swift @@ -1,6 +1,5 @@ import XCTest @testable import TestSuite -@testable import TestSuiteBridge final class MapRecordTest: XCTestCase { func testCppMapToSwiftMap() throws { diff --git a/test-suite/handwritten-src/swift/NestedCollectionTest.swift b/test-suite/handwritten-src/swift/NestedCollectionTest.swift index c8bc22b9..0d101caf 100644 --- a/test-suite/handwritten-src/swift/NestedCollectionTest.swift +++ b/test-suite/handwritten-src/swift/NestedCollectionTest.swift @@ -1,6 +1,5 @@ import XCTest @testable import TestSuite -@testable import TestSuiteBridge final class NestedCollectionTest: XCTestCase { let swiftNestedCollection = NestedCollection(setList: [Set(["String1", "String2"]), Set(["StringA", "StringB"])]) diff --git a/test-suite/handwritten-src/swift/OutcomeTest.swift b/test-suite/handwritten-src/swift/OutcomeTest.swift index 1ab0ffcd..7750ebe5 100644 --- a/test-suite/handwritten-src/swift/OutcomeTest.swift +++ b/test-suite/handwritten-src/swift/OutcomeTest.swift @@ -1,6 +1,5 @@ import XCTest @testable import TestSuite -@testable import TestSuiteBridge final class OutcomeTest: XCTestCase { func test() throws { diff --git a/test-suite/handwritten-src/swift/PrimitiveListTest.swift b/test-suite/handwritten-src/swift/PrimitiveListTest.swift index 14144857..ad6e5528 100644 --- a/test-suite/handwritten-src/swift/PrimitiveListTest.swift +++ b/test-suite/handwritten-src/swift/PrimitiveListTest.swift @@ -1,6 +1,5 @@ import XCTest @testable import TestSuite -@testable import TestSuiteBridge final class PrimitivesListTest: XCTestCase { diff --git a/test-suite/handwritten-src/swift/PrimitivesTest.swift b/test-suite/handwritten-src/swift/PrimitivesTest.swift index 7ed70d66..0a25082a 100644 --- a/test-suite/handwritten-src/swift/PrimitivesTest.swift +++ b/test-suite/handwritten-src/swift/PrimitivesTest.swift @@ -1,6 +1,5 @@ import XCTest @testable import TestSuite -@testable import TestSuiteBridge final class PrimitivesTest: XCTestCase { func testPrimitives() throws { diff --git a/test-suite/handwritten-src/swift/ProtoTest.swift b/test-suite/handwritten-src/swift/ProtoTest.swift index a49c8074..4270fa56 100644 --- a/test-suite/handwritten-src/swift/ProtoTest.swift +++ b/test-suite/handwritten-src/swift/ProtoTest.swift @@ -1,7 +1,6 @@ import XCTest @testable import ProtobufTest @testable import TestSuite -@testable import TestSuiteBridge typealias Person = Djinni_Test_Person typealias AddressBook = Djinni_Test_AddressBook diff --git a/test-suite/handwritten-src/swift/SetRecordTest.swift b/test-suite/handwritten-src/swift/SetRecordTest.swift index d9c666b2..c5afde12 100644 --- a/test-suite/handwritten-src/swift/SetRecordTest.swift +++ b/test-suite/handwritten-src/swift/SetRecordTest.swift @@ -1,6 +1,5 @@ import XCTest @testable import TestSuite -@testable import TestSuiteBridge final class SetRecordTest: XCTestCase { diff --git a/test-suite/handwritten-src/swift/TokenTest.swift b/test-suite/handwritten-src/swift/TokenTest.swift index 99c1ce8d..572d8726 100644 --- a/test-suite/handwritten-src/swift/TokenTest.swift +++ b/test-suite/handwritten-src/swift/TokenTest.swift @@ -1,6 +1,5 @@ import XCTest @testable import TestSuite -@testable import TestSuiteBridge final class TokenTest: XCTestCase { diff --git a/test-suite/handwritten-src/swift/WcharTest.swift b/test-suite/handwritten-src/swift/WcharTest.swift index 805a9c3c..2c8ccadd 100644 --- a/test-suite/handwritten-src/swift/WcharTest.swift +++ b/test-suite/handwritten-src/swift/WcharTest.swift @@ -1,6 +1,5 @@ import XCTest @testable import TestSuite -@testable import TestSuiteBridge final class WcharTest: XCTestCase { let STR1: String = "some string with unicode \u{0000}, \u{263A}, 💩 symbols"; From 513a6be95fd12e61eddd3fc7327a7ff0d3321077 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Tue, 23 Jul 2024 12:41:47 +1000 Subject: [PATCH 35/68] add support for deriving(hashable, sendable, codable) --- src/source/SwiftGenerator.scala | 9 +++++++-- src/source/ast.scala | 2 +- src/source/parser.scala | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/source/SwiftGenerator.scala b/src/source/SwiftGenerator.scala index a4b7f43c..4e413b0d 100644 --- a/src/source/SwiftGenerator.scala +++ b/src/source/SwiftGenerator.scala @@ -180,8 +180,13 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { r.fields.foreach(f => refs.find(f.ty)) writeSwiftFile(ident, origin, refs.swiftImports, w => { writeDoc(w, doc) - val eqClause = if (r.derivingTypes.contains(DerivingType.Eq)) ": Equatable" else "" - w.w(s"public struct ${marshal.typename(ident, r)}${eqClause}").braced { + val eq = if (r.derivingTypes.contains(DerivingType.Eq)) "Equatable" else "" + val hashable = if (r.derivingTypes.contains(DerivingType.Hashable)) "Hashable" else "" + val sendable = if (r.derivingTypes.contains(DerivingType.Sendable)) "Sendable" else "" + val codable = if (r.derivingTypes.contains(DerivingType.Codable)) ": Codable" else "" + val conformance = Array(eq, hashable, sendable, codable).filter(_ != "") + val conformanceClause = if (conformance.nonEmpty) ": " + conformance.mkString(", ") else "" + w.w(s"public struct ${marshal.typename(ident, r)}${conformanceClause}").braced { generateSwiftConstants(w, r.consts) for (f <- r.fields) { writeDoc(w, f.doc) diff --git a/src/source/ast.scala b/src/source/ast.scala index 9adcfa97..ed9df95d 100644 --- a/src/source/ast.scala +++ b/src/source/ast.scala @@ -86,7 +86,7 @@ case class Record(ext: Ext, fields: Seq[Field], consts: Seq[Const], derivingType object Record { object DerivingType extends Enumeration { type DerivingType = Value - val Eq, Ord, AndroidParcelable, NSCopying, Req = Value + val Eq, Ord, AndroidParcelable, NSCopying, Req, Hashable, Sendable, Codable = Value } } diff --git a/src/source/parser.scala b/src/source/parser.scala index c0883e67..75899e2f 100644 --- a/src/source/parser.scala +++ b/src/source/parser.scala @@ -156,6 +156,9 @@ private object IdlParser extends RegexParsers { case "parcelable" => Record.DerivingType.AndroidParcelable case "nscopying" => Record.DerivingType.NSCopying case "req" => Record.DerivingType.Req + case "Hashable" => Record.DerivingType.Hashable + case "Sendable" => Record.DerivingType.Sendable + case "Codable" => Record.DerivingType.Codable case _ => return err( s"""Unrecognized deriving type "${ident.name}"""") }).toSet } From ffe02b80a1df04325cb303d797b5fc20b199fbf3 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Tue, 23 Jul 2024 15:26:28 +1000 Subject: [PATCH 36/68] add error conformance --- src/source/SwiftGenerator.scala | 3 ++- src/source/ast.scala | 2 +- src/source/parser.scala | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/source/SwiftGenerator.scala b/src/source/SwiftGenerator.scala index 4e413b0d..0d0d234a 100644 --- a/src/source/SwiftGenerator.scala +++ b/src/source/SwiftGenerator.scala @@ -183,7 +183,8 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { val eq = if (r.derivingTypes.contains(DerivingType.Eq)) "Equatable" else "" val hashable = if (r.derivingTypes.contains(DerivingType.Hashable)) "Hashable" else "" val sendable = if (r.derivingTypes.contains(DerivingType.Sendable)) "Sendable" else "" - val codable = if (r.derivingTypes.contains(DerivingType.Codable)) ": Codable" else "" + val codable = if (r.derivingTypes.contains(DerivingType.Codable)) "Codable" else "" + val error = if (r.derivingTypes.contains(DerivingType.Error)) "Error" else "" val conformance = Array(eq, hashable, sendable, codable).filter(_ != "") val conformanceClause = if (conformance.nonEmpty) ": " + conformance.mkString(", ") else "" w.w(s"public struct ${marshal.typename(ident, r)}${conformanceClause}").braced { diff --git a/src/source/ast.scala b/src/source/ast.scala index ed9df95d..4849ec7e 100644 --- a/src/source/ast.scala +++ b/src/source/ast.scala @@ -86,7 +86,7 @@ case class Record(ext: Ext, fields: Seq[Field], consts: Seq[Const], derivingType object Record { object DerivingType extends Enumeration { type DerivingType = Value - val Eq, Ord, AndroidParcelable, NSCopying, Req, Hashable, Sendable, Codable = Value + val Eq, Ord, AndroidParcelable, NSCopying, Req, Hashable, Sendable, Codable, Error = Value } } diff --git a/src/source/parser.scala b/src/source/parser.scala index 75899e2f..b854794e 100644 --- a/src/source/parser.scala +++ b/src/source/parser.scala @@ -156,9 +156,10 @@ private object IdlParser extends RegexParsers { case "parcelable" => Record.DerivingType.AndroidParcelable case "nscopying" => Record.DerivingType.NSCopying case "req" => Record.DerivingType.Req - case "Hashable" => Record.DerivingType.Hashable - case "Sendable" => Record.DerivingType.Sendable - case "Codable" => Record.DerivingType.Codable + case "hashable" => Record.DerivingType.Hashable + case "sendable" => Record.DerivingType.Sendable + case "codable" => Record.DerivingType.Codable + case "error" => Record.DerivingType.Error case _ => return err( s"""Unrecognized deriving type "${ident.name}"""") }).toSet } From 14d5aa3df247a76442dee26351b80adaac39637c Mon Sep 17 00:00:00 2001 From: Li Feng Date: Tue, 23 Jul 2024 15:47:40 +1000 Subject: [PATCH 37/68] refactor --- src/source/SwiftGenerator.scala | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/source/SwiftGenerator.scala b/src/source/SwiftGenerator.scala index 0d0d234a..3792bc53 100644 --- a/src/source/SwiftGenerator.scala +++ b/src/source/SwiftGenerator.scala @@ -175,19 +175,22 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { } } + def generateConformance(deriving: Set[Record.DerivingType.Value], prefix: String) = { + val eq = if (deriving.contains(DerivingType.Eq)) "Equatable" else "" + val hashable = if (deriving.contains(DerivingType.Hashable)) "Hashable" else "" + val sendable = if (deriving.contains(DerivingType.Sendable)) "Sendable" else "" + val codable = if (deriving.contains(DerivingType.Codable)) "Codable" else "" + val error = if (deriving.contains(DerivingType.Error)) "Error" else "" + val conformance = Array(eq, hashable, sendable, codable).filter(_ != "") + if (conformance.nonEmpty) prefix + conformance.mkString(", ") else "" + } + override def generateRecord(origin: String, ident: Ident, doc: Doc, params: Seq[TypeParam], r: Record) { val refs = new SwiftRefs(ident.name) r.fields.foreach(f => refs.find(f.ty)) writeSwiftFile(ident, origin, refs.swiftImports, w => { writeDoc(w, doc) - val eq = if (r.derivingTypes.contains(DerivingType.Eq)) "Equatable" else "" - val hashable = if (r.derivingTypes.contains(DerivingType.Hashable)) "Hashable" else "" - val sendable = if (r.derivingTypes.contains(DerivingType.Sendable)) "Sendable" else "" - val codable = if (r.derivingTypes.contains(DerivingType.Codable)) "Codable" else "" - val error = if (r.derivingTypes.contains(DerivingType.Error)) "Error" else "" - val conformance = Array(eq, hashable, sendable, codable).filter(_ != "") - val conformanceClause = if (conformance.nonEmpty) ": " + conformance.mkString(", ") else "" - w.w(s"public struct ${marshal.typename(ident, r)}${conformanceClause}").braced { + w.w(s"public struct ${marshal.typename(ident, r)}${generateConformance(r.derivingTypes, ": ")}").braced { generateSwiftConstants(w, r.consts) for (f <- r.fields) { writeDoc(w, f.doc) From ba173f7645bbb8f6134d889293a3ecef67bf02a2 Mon Sep 17 00:00:00 2001 From: Logan Shire Date: Wed, 24 Jul 2024 00:12:31 -0400 Subject: [PATCH 38/68] Implement swift future --- support-lib/swift/DJFuture.swift | 118 ++++++++++++++++-- .../handwritten-src/swift/AsyncTest.swift | 44 ++++--- 2 files changed, 135 insertions(+), 27 deletions(-) diff --git a/support-lib/swift/DJFuture.swift b/support-lib/swift/DJFuture.swift index b267f28f..f72a3afb 100644 --- a/support-lib/swift/DJFuture.swift +++ b/support-lib/swift/DJFuture.swift @@ -1,6 +1,103 @@ import DjinniSupportCxx import Foundation -import Combine + +public final class Cancellable { + private let closure: () -> Void + + init(closure: @escaping () -> Void) { + self.closure = closure + } + + func cancel() { + self.closure() + } + + deinit { + self.closure() + } +} + +public typealias Lock = NSLock + +public final class Future where Failure : Error { + public typealias Promise = (Result) -> Void + + private let lock = Lock() + private var storedResult: Result? + private var subscriptions = [UUID : Promise]() + + public init(_ attemptToFulfill: @escaping (@escaping Promise) -> Void) { + attemptToFulfill { [weak self] result in + guard let self else { return } + + self.lock.lock() + + // If the promise was already fulfilled, fire an assertion failure, unlock and return: + if self.storedResult != nil { + assertionFailure("attempted to fulfill future multiple times") + self.lock.unlock() + return + } + + // Otherwise, make a copy of the completion handlers and clear them out, + // and then store the result and unlock: + let copiedSubscriptions = self.subscriptions + self.subscriptions = [:] + self.storedResult = result + self.lock.unlock() + + // Run the completion handlers in parallel after unlocking: + for subscription in copiedSubscriptions.values { + DispatchQueue.global(qos: .default).async { + subscription(result) + } + } + } + } + + public var value: Output { + get async throws { + let subscriptionID = UUID() + return try await withTaskCancellationHandler { + return try await withCheckedThrowingContinuation { continuation in + self.subscribe(subscriptionID: subscriptionID) { result in + continuation.resume(with: result) + } + } + } onCancel: { + self.cancel(subscriptionID: subscriptionID) + } + } + } + + public func getResult(subscription: @escaping Promise) -> Cancellable { + let subscriptionID = UUID() + self.subscribe(subscriptionID: subscriptionID, subscription: subscription) + return Cancellable { + self.cancel(subscriptionID: subscriptionID) + } + } + + // MARK: Private + + private func subscribe(subscriptionID: UUID, subscription: @escaping Promise) { + self.lock.lock() + defer { self.lock.unlock() } + + if let result = self.storedResult { + subscription(result) + return + } + + self.subscriptions[subscriptionID] = subscription + } + + private func cancel(subscriptionID: UUID) { + self.lock.lock() + self.subscriptions[subscriptionID] = nil + self.lock.unlock() + } +} // DJinni future<> maps to Combine.Future<> in Swift public typealias DJFuture = Future @@ -39,7 +136,7 @@ public func futureCb( // A C++ friendly function to release the subscription token stored with the C++ // future value. public func cleanupCb(psubscription: UnsafeMutableRawPointer?) -> Void { - let _ = Unmanaged.fromOpaque(psubscription!).takeRetainedValue() + let _ = Unmanaged.fromOpaque(psubscription!).takeRetainedValue() } public enum FutureMarshaller: Marshaller { @@ -59,18 +156,19 @@ public enum FutureMarshaller: Marshaller { // Create a C++ future var futureValue = djinni.swift.makeFutureValue(cleanupCb) // Connect it with the Swift future - let subscription = s.sink { completion in - if case let .failure(e) = completion { + let cancellable = s.getResult { result in + switch result { + case .success(let value): + var cppValue = T.toCpp(value) + djinni.swift.setFutureResult(&futureValue, &cppValue) + case .failure(let error): var errorValue = djinni.swift.makeVoidValue() - djinni.swift.setErrorValue(&errorValue, e.wrapped) + djinni.swift.setErrorValue(&errorValue, error.wrapped) djinni.swift.setFutureResult(&futureValue, &errorValue) } - } receiveValue:{ v in - var cppValue = T.toCpp(v) - djinni.swift.setFutureResult(&futureValue, &cppValue) } - // Store the subscription token so that the connection remains alive. - let pSubscription = Unmanaged.passRetained(subscription).toOpaque() + // Store the cancellable token so that the connection remains alive. + let pSubscription = Unmanaged.passRetained(cancellable).toOpaque() djinni.swift.storeSubscription(&futureValue, pSubscription) return futureValue } diff --git a/test-suite/handwritten-src/swift/AsyncTest.swift b/test-suite/handwritten-src/swift/AsyncTest.swift index ea07f211..432290b9 100644 --- a/test-suite/handwritten-src/swift/AsyncTest.swift +++ b/test-suite/handwritten-src/swift/AsyncTest.swift @@ -1,21 +1,21 @@ import XCTest import DjinniSupport -import Combine @testable import TestSuite final class AsyncTest: XCTestCase { class AsyncInterfaceImpl: AsyncInterface { func futureRoundtrip(_ f: DJFuture) throws -> DJFuture { - var token: AnyCancellable? = nil + var token: Cancellable? = nil return DJFuture() { promise in - token = f.sink { completion in - if case .failure = completion { - XCTAssertTrue(false) + token = f.getResult { result in + switch result { + case .success(let value): + promise(.success(String(value))) + case .failure: + XCTFail() + token = withExtendedLifetime(token) {nil} } - token = withExtendedLifetime(token) {nil} - } receiveValue: { i in - promise(.success(String(i))) } } } @@ -32,16 +32,22 @@ final class AsyncTest: XCTestCase { let f = DJFuture() { promise in p = promise } - var sink: AnyCancellable? = nil + var cancellable: Cancellable? = nil let f2 = DJFuture() { promise in - sink = f.sink { completion in if case .failure = completion {XCTAssertTrue(false)}} - receiveValue: { s in promise(.success(Int32(s)!))} + cancellable = f.getResult { result in + switch result { + case .failure: + XCTFail() + case .success(let value): + promise(.success(Int32(value)!)) + } + } } let f3 = try TestHelpers_statics.futureRoundtrip(f2) p!(.success("36")) let res = try await f3.value XCTAssertEqual(res, "36") - sink = withExtendedLifetime(sink) {nil} + cancellable = withExtendedLifetime(cancellable) {nil} } func testVoidRoundtrip() async throws { @@ -57,11 +63,15 @@ final class AsyncTest: XCTestCase { let f = DJFuture() { promise in p = promise } - var sink: AnyCancellable? = nil + var cancellable: Cancellable? = nil let f2 = DJFuture() { promise in - sink = f.sink { completion in if case .failure = completion {XCTAssertTrue(false)}} - receiveValue: { s in - promise(.failure(DjinniError("123"))) + cancellable = f.getResult { result in + switch result { + case .failure: + XCTFail() + case .success(let value): + promise(.failure(DjinniError("123"))) + } } } let f3 = try TestHelpers_statics.futureRoundtrip(f2) @@ -73,7 +83,7 @@ final class AsyncTest: XCTestCase { s = e.errorMessage } XCTAssertEqual(s, "123") - sink = withExtendedLifetime(sink){nil} + cancellable = withExtendedLifetime(cancellable){nil} } func testFutureRoundtripBackwards() async throws { From 2f0334ac16ac84b965bea42c326e676eccf16377 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Wed, 24 Jul 2024 14:40:06 +1000 Subject: [PATCH 39/68] comment --- support-lib/swift/DJFuture.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/support-lib/swift/DJFuture.swift b/support-lib/swift/DJFuture.swift index f72a3afb..5289f75d 100644 --- a/support-lib/swift/DJFuture.swift +++ b/support-lib/swift/DJFuture.swift @@ -1,6 +1,7 @@ import DjinniSupportCxx import Foundation +// A custom Future<> type thanks to Logan Shire <@LoganShireSnapchat> public final class Cancellable { private let closure: () -> Void From 9d1a289de8354d2e8cc352672e8423895749ef18 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Wed, 24 Jul 2024 14:42:40 +1000 Subject: [PATCH 40/68] fix warning --- test-suite/handwritten-src/swift/AsyncTest.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-suite/handwritten-src/swift/AsyncTest.swift b/test-suite/handwritten-src/swift/AsyncTest.swift index 432290b9..d4fc246b 100644 --- a/test-suite/handwritten-src/swift/AsyncTest.swift +++ b/test-suite/handwritten-src/swift/AsyncTest.swift @@ -14,8 +14,8 @@ final class AsyncTest: XCTestCase { promise(.success(String(value))) case .failure: XCTFail() - token = withExtendedLifetime(token) {nil} } + token = withExtendedLifetime(token) {nil} } } } @@ -69,7 +69,7 @@ final class AsyncTest: XCTestCase { switch result { case .failure: XCTFail() - case .success(let value): + case .success(_): promise(.failure(DjinniError("123"))) } } From edada37e3af5113b4e82ee26c111ac16d5df2462 Mon Sep 17 00:00:00 2001 From: Kwanho Lee Date: Tue, 23 Jul 2024 22:39:11 -0700 Subject: [PATCH 41/68] address comments --- support-lib/cpp/Future.hpp | 6 +-- support-lib/cpp/SharedFuture.hpp | 45 ++++++++++++++----- .../objc/tests/DBSharedFutureTest.mm | 38 ++++++++++++++-- 3 files changed, 71 insertions(+), 18 deletions(-) diff --git a/support-lib/cpp/Future.hpp b/support-lib/cpp/Future.hpp index f67a7a73..9e7d6080 100644 --- a/support-lib/cpp/Future.hpp +++ b/support-lib/cpp/Future.hpp @@ -370,7 +370,6 @@ class Future { return true; } - template struct PromiseTypeBase { Promise _promise; std::optional> _result{}; @@ -381,6 +380,7 @@ class Future { } template bool await_suspend(detail::CoroutineHandle

finished) const noexcept { + static_assert(std::is_base_of_v); auto& promise_type = finished.promise(); if (*promise_type._result) { if constexpr (std::is_void_v) { @@ -407,7 +407,7 @@ class Future { } }; - struct PromiseType: PromiseTypeBase{ + struct PromiseType: PromiseTypeBase { template >> void return_value(V&& value) { this->_result.emplace(std::forward(value)); @@ -425,7 +425,7 @@ class Future { #if defined(DJINNI_FUTURE_HAS_COROUTINE_SUPPORT) template<> -struct Future::PromiseType : PromiseTypeBase { +struct Future::PromiseType : PromiseTypeBase { void return_void() { _result.emplace(); } diff --git a/support-lib/cpp/SharedFuture.hpp b/support-lib/cpp/SharedFuture.hpp index 58677347..2d02b801 100644 --- a/support-lib/cpp/SharedFuture.hpp +++ b/support-lib/cpp/SharedFuture.hpp @@ -14,10 +14,12 @@ * limitations under the License. */ - #pragma once +#pragma once #include "Future.hpp" +#if defined(DJINNI_FUTURE_HAS_COROUTINE_SUPPORT) + #include #include #include @@ -43,7 +45,7 @@ class SharedFuture { } void wait() const { - return [this]() -> Future { co_await *this; }().wait(); + waitIgnoringExceptions().wait(); } decltype(auto) get() const { @@ -54,12 +56,15 @@ class SharedFuture { // Transform the result of this future into a new future. The behavior is same as Future::then except that // it doesn't consume the future, and can be called multiple times. template - SharedFuture>>> then(Func transform) const { - co_return transform(co_await SharedFuture(*this)); // retain copy during coroutine suspension + SharedFuture&>>>> then( + Func transform) const { + auto cpy = SharedFuture(*this); // retain copy during coroutine suspension + co_await waitIgnoringExceptions(); + co_return transform(cpy); } // Overload for T = void or `transform` takes no arugment. - template>> + template&>>> SharedFuture>>> then(Func transform) const { co_await SharedFuture(*this); // retain copy during coroutine suspension co_return transform(); @@ -73,8 +78,11 @@ class SharedFuture { } decltype(auto) await_resume() const { + if (!*_sharedStates->storedValue) { + std::rethrow_exception(_sharedStates->storedValue->error()); + } if constexpr (!std::is_void_v) { - return *_sharedStates->storedValue; + return const_cast(_sharedStates->storedValue->value()); } } @@ -88,9 +96,17 @@ class SharedFuture { using promise_type = Promise; private: + Future waitIgnoringExceptions() const { + try { + co_await *this; + } catch (...) { + // Ignore exceptions. + } + } + struct SharedStates { std::recursive_mutex mutex; - std::optional, std::monostate, T>> storedValue = std::nullopt; + std::optional> storedValue = std::nullopt; std::vector> coroutineHandles; }; // Use a shared_ptr to allow copying SharedFuture. @@ -109,10 +125,15 @@ SharedFuture::SharedFuture(Future&& future) { future.then([sharedStates = _sharedStates](auto futureResult) { std::vector toCall = [&] { std::scoped_lock lock(sharedStates->mutex); - if constexpr (std::is_void_v) { - sharedStates->storedValue.emplace(); - } else { - sharedStates->storedValue = futureResult.get(); + try { + if constexpr (std::is_void_v) { + futureResult.get(); + sharedStates->storedValue.emplace(); + } else { + sharedStates->storedValue = futureResult.get(); + } + } catch (const std::exception& e) { + sharedStates->storedValue = make_unexpected(std::make_exception_ptr(e)); } return std::move(sharedStates->coroutineHandles); }(); @@ -136,3 +157,5 @@ bool SharedFuture::await_suspend(detail::CoroutineHandle<> h) const { } } // namespace djinni + +#endif diff --git a/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm b/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm index f2c226e4..d02c9f08 100644 --- a/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm +++ b/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm @@ -8,6 +8,8 @@ @interface DBSharedFutureTest : XCTestCase @implementation DBSharedFutureTest +#ifdef DJINNI_FUTURE_HAS_COROUTINE_SUPPORT + - (void)setUp { [super setUp]; @@ -35,15 +37,17 @@ - (void)testThen djinni::Promise intPromise; djinni::SharedFuture futureInt(intPromise.getFuture()); - auto transformedInt = futureInt.then([](int i) { return 2 * i; }); + auto transformedInt = futureInt.then([](const auto& resolved) { return 2 * resolved.get(); }); intPromise.setValue(42); XCTAssertEqual(transformedInt.get(), 84); // Also verify multiple consumers and chaining. - auto transformedString = futureInt.then([](int i) { return std::to_string(i); }); - auto futurePlusOneTimesTwo = futureInt.then([](int i) { return i + 1; }).then([](int i) { return 2 * i; }); - auto futureStringLen = transformedString.then([](const std::string& s) { return s.length(); }).toFuture(); + auto transformedString = futureInt.then([](const auto& resolved) { return std::to_string(resolved.get()); }); + auto futurePlusOneTimesTwo = futureInt.then([](const auto& resolved) { return resolved.get() + 1; }).then([](const auto& resolved) { + return 2 * resolved.get(); + }); + auto futureStringLen = transformedString.then([](const auto& resolved) { return resolved.get().length(); }).toFuture(); XCTAssertEqual(transformedString.get(), std::string("42")); XCTAssertEqual(futurePlusOneTimesTwo.get(), (42 + 1) * 2); @@ -58,4 +62,30 @@ - (void)testThen XCTAssertEqual(intFuture2.get(), 43); } +- (void)testException +{ + // Also verify exception handling. + djinni::Promise intPromise; + djinni::SharedFuture futureInt(intPromise.getFuture()); + + intPromise.setException(std::runtime_error("mocked")); + + XCTAssertThrows(futureInt.get()); + + auto thenResult = futureInt.then([]() { return 43; }); + XCTAssertThrows(thenResult.get()); + + auto withExceptionHandling = futureInt.then([](const auto& resolved) { + try { + return resolved.get(); + } catch (...) { + return -1; + } + }); + withExceptionHandling.wait(); + XCTAssertEqual(withExceptionHandling.get(), -1); +} + +#endif + @end From c7cbf0abad1f172965e898e35418af39fd349035 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Wed, 24 Jul 2024 15:59:05 +1000 Subject: [PATCH 42/68] use atomic int64 instead of uuid as subscription token --- support-lib/swift/DJFuture.swift | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/support-lib/swift/DJFuture.swift b/support-lib/swift/DJFuture.swift index 5289f75d..9ac37be0 100644 --- a/support-lib/swift/DJFuture.swift +++ b/support-lib/swift/DJFuture.swift @@ -23,9 +23,16 @@ public typealias Lock = NSLock public final class Future where Failure : Error { public typealias Promise = (Result) -> Void + // The token only needs to be unique within the scope of the Future object + typealias Token = Int64 + var nextTokenValue: Token = 0 + private func generateToken() -> Token { + return OSAtomicIncrement64(&nextTokenValue) + } + private let lock = Lock() private var storedResult: Result? - private var subscriptions = [UUID : Promise]() + private var subscriptions = [Token : Promise]() public init(_ attemptToFulfill: @escaping (@escaping Promise) -> Void) { attemptToFulfill { [weak self] result in @@ -58,30 +65,30 @@ public final class Future where Failure : Error { public var value: Output { get async throws { - let subscriptionID = UUID() + let token = generateToken() return try await withTaskCancellationHandler { return try await withCheckedThrowingContinuation { continuation in - self.subscribe(subscriptionID: subscriptionID) { result in + self.subscribe(token: token) { result in continuation.resume(with: result) } } } onCancel: { - self.cancel(subscriptionID: subscriptionID) + self.cancel(token: token) } } } public func getResult(subscription: @escaping Promise) -> Cancellable { - let subscriptionID = UUID() - self.subscribe(subscriptionID: subscriptionID, subscription: subscription) + let token = generateToken() + self.subscribe(token: token, subscription: subscription) return Cancellable { - self.cancel(subscriptionID: subscriptionID) + self.cancel(token: token) } } // MARK: Private - private func subscribe(subscriptionID: UUID, subscription: @escaping Promise) { + private func subscribe(token: Token, subscription: @escaping Promise) { self.lock.lock() defer { self.lock.unlock() } @@ -90,12 +97,12 @@ public final class Future where Failure : Error { return } - self.subscriptions[subscriptionID] = subscription + self.subscriptions[token] = subscription } - private func cancel(subscriptionID: UUID) { + private func cancel(token: Token) { self.lock.lock() - self.subscriptions[subscriptionID] = nil + self.subscriptions[token] = nil self.lock.unlock() } } From 1a4080d7e21f6dbde9a5ad9c74ffacc0e801c725 Mon Sep 17 00:00:00 2001 From: Kwanho Lee Date: Tue, 23 Jul 2024 23:08:20 -0700 Subject: [PATCH 43/68] fix --- support-lib/cpp/SharedFuture.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support-lib/cpp/SharedFuture.hpp b/support-lib/cpp/SharedFuture.hpp index 2d02b801..d2f3abd7 100644 --- a/support-lib/cpp/SharedFuture.hpp +++ b/support-lib/cpp/SharedFuture.hpp @@ -59,7 +59,7 @@ class SharedFuture { SharedFuture&>>>> then( Func transform) const { auto cpy = SharedFuture(*this); // retain copy during coroutine suspension - co_await waitIgnoringExceptions(); + co_await cpy.waitIgnoringExceptions(); co_return transform(cpy); } From bf60220bccb0e08cc14bd1ce5600b4f1aa993e66 Mon Sep 17 00:00:00 2001 From: Kwanho Lee Date: Wed, 24 Jul 2024 08:40:09 -0700 Subject: [PATCH 44/68] address comments --- support-lib/cpp/SharedFuture.hpp | 11 ++--------- .../handwritten-src/objc/tests/DBSharedFutureTest.mm | 6 +++--- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/support-lib/cpp/SharedFuture.hpp b/support-lib/cpp/SharedFuture.hpp index d2f3abd7..97f82368 100644 --- a/support-lib/cpp/SharedFuture.hpp +++ b/support-lib/cpp/SharedFuture.hpp @@ -63,13 +63,6 @@ class SharedFuture { co_return transform(cpy); } - // Overload for T = void or `transform` takes no arugment. - template&>>> - SharedFuture>>> then(Func transform) const { - co_await SharedFuture(*this); // retain copy during coroutine suspension - co_return transform(); - } - // -- coroutine support implementation only; not intended externally -- bool await_ready() const { @@ -132,8 +125,8 @@ SharedFuture::SharedFuture(Future&& future) { } else { sharedStates->storedValue = futureResult.get(); } - } catch (const std::exception& e) { - sharedStates->storedValue = make_unexpected(std::make_exception_ptr(e)); + } catch (...) { + sharedStates->storedValue = make_unexpected(std::current_exception()); } return std::move(sharedStates->coroutineHandles); }(); diff --git a/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm b/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm index d02c9f08..fb8c3f1a 100644 --- a/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm +++ b/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm @@ -55,10 +55,10 @@ - (void)testThen XCTAssertEqual(futureInt.get(), 42); - auto voidFuture = transformedString.then([]() {}); + auto voidFuture = transformedString.then([](auto) {}); voidFuture.wait(); - auto intFuture2 = voidFuture.then([]() { return 43; }); + auto intFuture2 = voidFuture.then([](auto) { return 43; }); XCTAssertEqual(intFuture2.get(), 43); } @@ -72,7 +72,7 @@ - (void)testException XCTAssertThrows(futureInt.get()); - auto thenResult = futureInt.then([]() { return 43; }); + auto thenResult = futureInt.then([](const auto& resolved) { return resolved.get(); }); XCTAssertThrows(thenResult.get()); auto withExceptionHandling = futureInt.then([](const auto& resolved) { From 987cd7255ce6ae3fb0f407a184466f20df6b5e14 Mon Sep 17 00:00:00 2001 From: Kwanho Lee Date: Wed, 24 Jul 2024 11:22:25 -0700 Subject: [PATCH 45/68] address comments --- support-lib/cpp/SharedFuture.hpp | 12 ++++++++++-- .../objc/tests/DBSharedFutureTest.mm | 16 ++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/support-lib/cpp/SharedFuture.hpp b/support-lib/cpp/SharedFuture.hpp index 97f82368..938118ae 100644 --- a/support-lib/cpp/SharedFuture.hpp +++ b/support-lib/cpp/SharedFuture.hpp @@ -53,16 +53,24 @@ class SharedFuture { return await_resume(); } + template + using ResultT = std::remove_cv_t&>>>; + // Transform the result of this future into a new future. The behavior is same as Future::then except that // it doesn't consume the future, and can be called multiple times. template - SharedFuture&>>>> then( - Func transform) const { + Future> then(Func transform) const { auto cpy = SharedFuture(*this); // retain copy during coroutine suspension co_await cpy.waitIgnoringExceptions(); co_return transform(cpy); } + // Same as above but returns SharedFuture. + template + SharedFuture> thenShared(Func transform) const { + return SharedFuture>(then(std::move(transform))); + } + // -- coroutine support implementation only; not intended externally -- bool await_ready() const { diff --git a/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm b/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm index fb8c3f1a..c0b5ae2f 100644 --- a/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm +++ b/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm @@ -37,17 +37,17 @@ - (void)testThen djinni::Promise intPromise; djinni::SharedFuture futureInt(intPromise.getFuture()); - auto transformedInt = futureInt.then([](const auto& resolved) { return 2 * resolved.get(); }); + auto transformedInt = futureInt.thenShared([](const auto& resolved) { return 2 * resolved.get(); }); intPromise.setValue(42); XCTAssertEqual(transformedInt.get(), 84); // Also verify multiple consumers and chaining. - auto transformedString = futureInt.then([](const auto& resolved) { return std::to_string(resolved.get()); }); - auto futurePlusOneTimesTwo = futureInt.then([](const auto& resolved) { return resolved.get() + 1; }).then([](const auto& resolved) { + auto transformedString = futureInt.thenShared([](const auto& resolved) { return std::to_string(resolved.get()); }); + auto futurePlusOneTimesTwo = futureInt.then([](auto resolved) { return resolved.get() + 1; }).then([](auto resolved) { return 2 * resolved.get(); }); - auto futureStringLen = transformedString.then([](const auto& resolved) { return resolved.get().length(); }).toFuture(); + auto futureStringLen = transformedString.then([](auto resolved) { return resolved.get().length(); }); XCTAssertEqual(transformedString.get(), std::string("42")); XCTAssertEqual(futurePlusOneTimesTwo.get(), (42 + 1) * 2); @@ -55,10 +55,10 @@ - (void)testThen XCTAssertEqual(futureInt.get(), 42); - auto voidFuture = transformedString.then([](auto) {}); + auto voidFuture = transformedString.thenShared([](auto) {}); voidFuture.wait(); - auto intFuture2 = voidFuture.then([](auto) { return 43; }); + auto intFuture2 = voidFuture.thenShared([](auto) { return 43; }); XCTAssertEqual(intFuture2.get(), 43); } @@ -72,10 +72,10 @@ - (void)testException XCTAssertThrows(futureInt.get()); - auto thenResult = futureInt.then([](const auto& resolved) { return resolved.get(); }); + auto thenResult = futureInt.then([](auto resolved) { return resolved.get(); }); XCTAssertThrows(thenResult.get()); - auto withExceptionHandling = futureInt.then([](const auto& resolved) { + auto withExceptionHandling = futureInt.thenShared([](const auto& resolved) { try { return resolved.get(); } catch (...) { From 823a8ebaf43e028e500950debebdb76286bfee99 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 26 Jul 2024 12:56:58 +1000 Subject: [PATCH 46/68] add header --- support-lib/swiftxx/djinni_support.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/support-lib/swiftxx/djinni_support.hpp b/support-lib/swiftxx/djinni_support.hpp index 0045e2b3..2f6ee3ea 100644 --- a/support-lib/swiftxx/djinni_support.hpp +++ b/support-lib/swiftxx/djinni_support.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include From 954a8a92b267e9f5c5be2bc6b60adf1445e502fe Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 26 Jul 2024 14:18:47 +1000 Subject: [PATCH 47/68] move-only optionals --- support-lib/composer/djinni_composer.hpp | 3 +++ support-lib/jni/Marshal.hpp | 5 +++++ support-lib/objc/DJIMarshal+Private.h | 3 +++ support-lib/swiftxx/djinni_support.hpp | 3 +++ support-lib/wasm/djinni_wasm.hpp | 3 +++ 5 files changed, 17 insertions(+) diff --git a/support-lib/composer/djinni_composer.hpp b/support-lib/composer/djinni_composer.hpp index a1589f3c..79c42800 100644 --- a/support-lib/composer/djinni_composer.hpp +++ b/support-lib/composer/djinni_composer.hpp @@ -222,6 +222,9 @@ struct Optional { static ComposerType fromCpp(const OptionalType& c) { return c ? T::Boxed::fromCpp(*c) : Composer::Value::undefined(); } + static ComposerType fromCpp(OptionalType&& c) { + return c ? T::Boxed::fromCpp(std::move(*c)) : Composer::Value::undefined(); + } template static ComposerType fromCpp(const typename C::CppOptType& cppOpt) { return T::Boxed::fromCppOpt(cppOpt); diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index 371c452f..a44952da 100644 --- a/support-lib/jni/Marshal.hpp +++ b/support-lib/jni/Marshal.hpp @@ -325,6 +325,11 @@ namespace djinni return c ? T::Boxed::fromCpp(jniEnv, *c) : LocalRef{}; } + static LocalRef fromCpp(JNIEnv* jniEnv, OptionalType&& c) + { + return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef{}; + } + // fromCpp used for nullable shared_ptr template static LocalRef fromCpp(JNIEnv* jniEnv, const typename C::CppOptType & cppOpt) { diff --git a/support-lib/objc/DJIMarshal+Private.h b/support-lib/objc/DJIMarshal+Private.h index 08df8c3e..41b1cfe9 100644 --- a/support-lib/objc/DJIMarshal+Private.h +++ b/support-lib/objc/DJIMarshal+Private.h @@ -244,6 +244,9 @@ class Optional { static ObjcType fromCpp(const OptionalType& opt) { return opt ? T::Boxed::fromCpp(*opt) : nil; } + static ObjcType fromCpp(OptionalType&& opt) { + return opt ? T::Boxed::fromCpp(std::move(*opt)) : nil; + } // fromCpp used for nullable shared_ptr template diff --git a/support-lib/swiftxx/djinni_support.hpp b/support-lib/swiftxx/djinni_support.hpp index 2f6ee3ea..4056d536 100644 --- a/support-lib/swiftxx/djinni_support.hpp +++ b/support-lib/swiftxx/djinni_support.hpp @@ -250,6 +250,9 @@ struct Optional { static AnyValue fromCpp(const OptionalType& c) { return c ? T::fromCpp(*c) : makeVoidValue(); } + static AnyValue fromCpp(OptionalType&& c) { + return c ? T::fromCpp(std::move(*c)) : makeVoidValue(); + } static CppType toCpp(const AnyValue& v) { if (std::holds_alternative(v)) { return CppType{}; diff --git a/support-lib/wasm/djinni_wasm.hpp b/support-lib/wasm/djinni_wasm.hpp index 8add002d..00954a87 100644 --- a/support-lib/wasm/djinni_wasm.hpp +++ b/support-lib/wasm/djinni_wasm.hpp @@ -154,6 +154,9 @@ struct Optional static JsType fromCpp(const OptionalType& c) { return c ? T::Boxed::fromCpp(*c) : em::val::undefined(); } + static JsType fromCpp(OptionalType&& c) { + return c ? T::Boxed::fromCpp(std::move(*c)) : em::val::undefined(); + } template static JsType fromCpp(const typename C::CppOptType& cppOpt) { return T::Boxed::fromCppOpt(cppOpt); From d29731e19daf39b3985a214fa4516aa967e856ca Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 26 Jul 2024 14:29:38 +1000 Subject: [PATCH 48/68] touch --- support-lib/jni/Marshal.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index a44952da..87a56a5c 100644 --- a/support-lib/jni/Marshal.hpp +++ b/support-lib/jni/Marshal.hpp @@ -322,12 +322,12 @@ namespace djinni static LocalRef fromCpp(JNIEnv* jniEnv, const OptionalType &c) { - return c ? T::Boxed::fromCpp(jniEnv, *c) : LocalRef{}; + return c ? T::Boxed::fromCpp(jniEnv, *c) : LocalRef{ }; } static LocalRef fromCpp(JNIEnv* jniEnv, OptionalType&& c) { - return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef{}; + return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef{ }; } // fromCpp used for nullable shared_ptr From 8e404d8fbf35deb7ead8db3b995bb9c793cd472f Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 26 Jul 2024 14:46:22 +1000 Subject: [PATCH 49/68] test --- support-lib/jni/Marshal.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index 87a56a5c..fe158020 100644 --- a/support-lib/jni/Marshal.hpp +++ b/support-lib/jni/Marshal.hpp @@ -325,10 +325,10 @@ namespace djinni return c ? T::Boxed::fromCpp(jniEnv, *c) : LocalRef{ }; } - static LocalRef fromCpp(JNIEnv* jniEnv, OptionalType&& c) - { - return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef{ }; - } + // static LocalRef fromCpp(JNIEnv* jniEnv, OptionalType&& c) + // { + // return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef{ }; + // } // fromCpp used for nullable shared_ptr template From e1a08ff092ba15f24e77da080a231bec50108cb9 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 26 Jul 2024 14:56:49 +1000 Subject: [PATCH 50/68] uncomment --- support-lib/jni/Marshal.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index fe158020..87a56a5c 100644 --- a/support-lib/jni/Marshal.hpp +++ b/support-lib/jni/Marshal.hpp @@ -325,10 +325,10 @@ namespace djinni return c ? T::Boxed::fromCpp(jniEnv, *c) : LocalRef{ }; } - // static LocalRef fromCpp(JNIEnv* jniEnv, OptionalType&& c) - // { - // return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef{ }; - // } + static LocalRef fromCpp(JNIEnv* jniEnv, OptionalType&& c) + { + return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef{ }; + } // fromCpp used for nullable shared_ptr template From 0c74a2aaac971df993808d51d78fd7782349431e Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 26 Jul 2024 15:02:34 +1000 Subject: [PATCH 51/68] touch --- support-lib/jni/Marshal.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index 87a56a5c..bed18e57 100644 --- a/support-lib/jni/Marshal.hpp +++ b/support-lib/jni/Marshal.hpp @@ -324,7 +324,6 @@ namespace djinni { return c ? T::Boxed::fromCpp(jniEnv, *c) : LocalRef{ }; } - static LocalRef fromCpp(JNIEnv* jniEnv, OptionalType&& c) { return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef{ }; From c0b131e1c2af8a2e35cede032d065a4f01346906 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 26 Jul 2024 15:10:48 +1000 Subject: [PATCH 52/68] try again --- support-lib/jni/Marshal.hpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index bed18e57..87616715 100644 --- a/support-lib/jni/Marshal.hpp +++ b/support-lib/jni/Marshal.hpp @@ -311,8 +311,7 @@ namespace djinni using Boxed = Optional; - static CppType toCpp(JNIEnv* jniEnv, JniType j) - { + static CppType toCpp(JNIEnv* jniEnv, JniType j) { if (j) { return T::Boxed::toCpp(jniEnv, j); } else { @@ -320,12 +319,11 @@ namespace djinni } } - static LocalRef fromCpp(JNIEnv* jniEnv, const OptionalType &c) - { + static LocalRef fromCpp(JNIEnv* jniEnv, const OptionalType &c) { return c ? T::Boxed::fromCpp(jniEnv, *c) : LocalRef{ }; } - static LocalRef fromCpp(JNIEnv* jniEnv, OptionalType&& c) - { + + static LocalRef fromCpp(JNIEnv* jniEnv, OptionalType&& c) { return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef{ }; } From d3ab313794582154b95541b1c1885a5b19c626a9 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 26 Jul 2024 15:25:28 +1000 Subject: [PATCH 53/68] try again --- support-lib/jni/Marshal.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index 87616715..9e07e52b 100644 --- a/support-lib/jni/Marshal.hpp +++ b/support-lib/jni/Marshal.hpp @@ -319,7 +319,7 @@ namespace djinni } } - static LocalRef fromCpp(JNIEnv* jniEnv, const OptionalType &c) { + static LocalRef fromCpp(JNIEnv* jniEnv, const OptionalType& c) { return c ? T::Boxed::fromCpp(jniEnv, *c) : LocalRef{ }; } From c08793dfa33f03d36fbbb64e322a11b707055662 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 26 Jul 2024 15:36:56 +1000 Subject: [PATCH 54/68] comment --- support-lib/jni/Marshal.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index 9e07e52b..d9b8a57e 100644 --- a/support-lib/jni/Marshal.hpp +++ b/support-lib/jni/Marshal.hpp @@ -322,10 +322,11 @@ namespace djinni static LocalRef fromCpp(JNIEnv* jniEnv, const OptionalType& c) { return c ? T::Boxed::fromCpp(jniEnv, *c) : LocalRef{ }; } - - static LocalRef fromCpp(JNIEnv* jniEnv, OptionalType&& c) { - return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef{ }; - } + + // No idea why this overload breaks CI bazel build. + // static LocalRef fromCpp(JNIEnv* jniEnv, OptionalType&& c) { + // return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef{ }; + // } // fromCpp used for nullable shared_ptr template From 683c39f96ba990366dc9bbed7bd8dfc2332536ad Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 26 Jul 2024 16:16:00 +1000 Subject: [PATCH 55/68] touch --- support-lib/jni/Marshal.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index d9b8a57e..b3d2e845 100644 --- a/support-lib/jni/Marshal.hpp +++ b/support-lib/jni/Marshal.hpp @@ -328,6 +328,7 @@ namespace djinni // return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef{ }; // } + // fromCpp used for nullable shared_ptr template static LocalRef fromCpp(JNIEnv* jniEnv, const typename C::CppOptType & cppOpt) { From ce6add1be4db97a24576db04f99a17f38c001a40 Mon Sep 17 00:00:00 2001 From: techleeksnap <133064333+techleeksnap@users.noreply.github.com> Date: Fri, 26 Jul 2024 14:08:37 -0700 Subject: [PATCH 56/68] Update support-lib/cpp/Future.hpp --- support-lib/cpp/Future.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support-lib/cpp/Future.hpp b/support-lib/cpp/Future.hpp index 9e7d6080..71db25ab 100644 --- a/support-lib/cpp/Future.hpp +++ b/support-lib/cpp/Future.hpp @@ -380,7 +380,7 @@ class Future { } template bool await_suspend(detail::CoroutineHandle

finished) const noexcept { - static_assert(std::is_base_of_v); + static_assert(std::is_convertible_v); auto& promise_type = finished.promise(); if (*promise_type._result) { if constexpr (std::is_void_v) { From c2711982d8889cd942b3648208312aff3118f22c Mon Sep 17 00:00:00 2001 From: Li Feng Date: Wed, 31 Jul 2024 13:34:43 +1000 Subject: [PATCH 57/68] add prefix dirs --- src/source/Main.scala | 8 ++++++++ src/source/SwiftxxGenerator.scala | 4 ++-- src/source/generator.scala | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/source/Main.scala b/src/source/Main.scala index d8dff9d8..33fa6189 100644 --- a/src/source/Main.scala +++ b/src/source/Main.scala @@ -119,6 +119,8 @@ object Main { var swiftxxBaseLibModule: String = "DjinniSupportCxx" var swiftxxClassIdentStyleOptional: Option[IdentConverter] = None var swiftxxFileIdentStyleOptional: Option[IdentConverter] = None + var swiftxxIncludeCppPrefix: String = "" + var swiftxxBaseLibIncludePrefix: String = "" var inFileListPath: Option[File] = None var outFileListPath: Option[File] = None var skipGeneration: Boolean = false @@ -304,6 +306,10 @@ object Main { .text("Swift module name (default: \"Module\").") opt[File]("swiftxx-out").valueName("").foreach(x => swiftxxOutFolder = Some(x)) .text("The output folder for private Swift/C++ interop files (Generator disabled if unspecified).") + opt[String]("swiftxx-include-cpp-prefix").valueName("").foreach(swiftxxIncludeCppPrefix = _) + .text("The prefix for #includes of the main header files from Swift C++ files.") + opt[String]("swiftxx-base-lib-include-prefix").valueName("...").foreach(x => swiftxxBaseLibIncludePrefix = x) + .text("The Swift C++ base library's include path, relative to the Swift C++ classes.") note("") opt[File]("yaml-out").valueName("").foreach(x => yamlOutFolder = Some(x)) .text("The output folder for YAML files (Generator disabled if unspecified).") @@ -519,6 +525,8 @@ object Main { swiftxxBaseLibModule, swiftxxClassIdentStyle, swiftxxFileIdentStyle, + swiftxxIncludeCppPrefix, + swiftxxBaseLibIncludePrefix, outFileListWriter, skipGeneration, yamlOutFolder, diff --git a/src/source/SwiftxxGenerator.scala b/src/source/SwiftxxGenerator.scala index f7125531..82285d90 100644 --- a/src/source/SwiftxxGenerator.scala +++ b/src/source/SwiftxxGenerator.scala @@ -35,8 +35,8 @@ class SwiftxxGenerator(spec: Spec) extends Generator(spec) { class SwiftRefs(name: String) { var swiftHpp = mutable.TreeSet[String]() var swiftCpp = mutable.TreeSet[String]() - swiftHpp.add("#include " + q(spec.cppFileIdentStyle(name) + "." + spec.cppHeaderExt)) - swiftHpp.add("#include " + q("djinni_support.hpp")) + swiftHpp.add("#include " + q(spec.swiftxxIncludeCppPrefix + spec.cppFileIdentStyle(name) + "." + spec.cppHeaderExt)) + swiftHpp.add("#include " + q(spec.swiftxxBaseLibIncludePrefix + "djinni_support.hpp")) spec.cppNnHeader match { case Some(nnHdr) => swiftHpp.add("#include " + nnHdr) case _ => diff --git a/src/source/generator.scala b/src/source/generator.scala index d937f3c8..d64c4641 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -121,6 +121,8 @@ package object generatorTools { swiftxxBaseLibModule: String, swiftxxClassIdentStyle: IdentConverter, swiftxxFileIdentStyle: IdentConverter, + swiftxxIncludeCppPrefix: String, + swiftxxBaseLibIncludePrefix: String, outFileListWriter: Option[Writer], skipGeneration: Boolean, yamlOutFolder: Option[File], From 17458b935f1e7717138be31a20a0568fcb513c01 Mon Sep 17 00:00:00 2001 From: Sam Young Date: Thu, 1 Aug 2024 09:01:36 -0700 Subject: [PATCH 58/68] Small error in README.md Fixing a minor type. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 06394502..1ec38df3 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ verify the build and binary from the command line. - Protobuf type support - Local flags with `@flag` directive - DataView for copy free data passing - - DateRef for copy free data passing with ownership + - DataRef for copy free data passing with ownership - Generating string names for C++ enums - Bug fixes From 252271d0fc10ba9e96af53ac70199a0b6ec77fda Mon Sep 17 00:00:00 2001 From: Li Feng Date: Wed, 7 Aug 2024 13:30:57 +1000 Subject: [PATCH 59/68] fixes as per review comments --- support-lib/swift/DJData.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/support-lib/swift/DJData.swift b/support-lib/swift/DJData.swift index 6a99b499..5d52cd4f 100644 --- a/support-lib/swift/DJData.swift +++ b/support-lib/swift/DJData.swift @@ -9,6 +9,9 @@ public enum DataViewMarshaller: Marshaller { public typealias SwiftType = NSData public static func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { let range = djinni.swift.getBinaryRange(v) + if (range.size == 0 || range.bytes == nil) { + return SwiftType() + } return SwiftType(bytesNoCopy: UnsafeMutableRawPointer(mutating: range.bytes!), length: range.size, deallocator:.none) } public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { @@ -25,12 +28,12 @@ public enum DataRefMarshaller: Marshaller { return cfdata as NSData } public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - if s is CFMutableData { - let cfdataref = Unmanaged.passRetained(s as! CFMutableData).toOpaque() - return djinni.swift.makeRangeValue(cfdataref, 1) + if let nsMutableData = s as? NSMutableData { + let cfDataRef = Unmanaged.passRetained(nsMutableData).toOpaque() + return djinni.swift.makeRangeValue(cfDataRef, 1) } else { - let cfdataref = Unmanaged.passRetained(s as CFData).toOpaque() - return djinni.swift.makeRangeValue(cfdataref, 0) + let cfDataRef = Unmanaged.passRetained(s as CFData).toOpaque() + return djinni.swift.makeRangeValue(cfDataRef, 0) } } } From dc8b666c5d0f52a56dc49b6020565778d28d4484 Mon Sep 17 00:00:00 2001 From: Jan Buenker Date: Mon, 12 Aug 2024 16:00:42 +0200 Subject: [PATCH 60/68] Finish futures when their promise is broken --- support-lib/cpp/Future.hpp | 44 ++++++++++++------- .../objc/tests/DBCppFutureTests.mm | 32 ++++++++++++++ 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/support-lib/cpp/Future.hpp b/support-lib/cpp/Future.hpp index 71db25ab..6e94152e 100644 --- a/support-lib/cpp/Future.hpp +++ b/support-lib/cpp/Future.hpp @@ -54,6 +54,12 @@ namespace djinni { template class Future; +struct BrokenPromiseException final : public std::exception { + inline const char* what() const noexcept final { + return "djinni::Promise was destructed before setting a result"; + } +}; + namespace detail { // A wrapper object to support both void and non-void result types in @@ -117,6 +123,25 @@ using SharedStatePtr = std::shared_ptr>; template class PromiseBase { public: + virtual ~PromiseBase() noexcept { + if (_sharedState) { + setException(BrokenPromiseException{}); + } + } + PromiseBase() = default; + + // moveable + PromiseBase(PromiseBase&&) noexcept = default; + PromiseBase& operator= (PromiseBase&& other) noexcept { + std::swap(other._sharedState, _sharedState); + std::swap(other._sharedStateReadOnly, _sharedStateReadOnly); + return *this; + } + + // not copyable + PromiseBase(const PromiseBase&) = delete; + PromiseBase& operator= (const PromiseBase&) = delete; + Future getFuture(); // Use to immediately resolve a promise and return the resulting future. @@ -223,14 +248,7 @@ class Promise: public detail::PromiseBase { public: using detail::PromiseBase::setValue; using detail::PromiseBase::setException; - // default constructable - Promise() = default; - // moveable - Promise(Promise&&) noexcept = default; - Promise& operator= (Promise&&) noexcept = default; - // not copyable - Promise(const Promise&) = delete; - Promise& operator= (const Promise&) = delete; + using detail::PromiseBase::PromiseBase; }; // Promise with a void result @@ -239,14 +257,8 @@ class Promise: public detail::PromiseBase { public: void setValue() {setValue(true);} using detail::PromiseBase::setException; - // default constructable - Promise() = default; - // moveable - Promise(Promise&&) noexcept = default; - Promise& operator= (Promise&&) noexcept = default; - // not copyable - Promise(const Promise&) = delete; - Promise& operator= (const Promise&) = delete; + using detail::PromiseBase::PromiseBase; + private: // hide the bool version void setValue(const bool&) {detail::PromiseBase::setValue(true);} diff --git a/test-suite/handwritten-src/objc/tests/DBCppFutureTests.mm b/test-suite/handwritten-src/objc/tests/DBCppFutureTests.mm index 584675a4..e562b845 100644 --- a/test-suite/handwritten-src/objc/tests/DBCppFutureTests.mm +++ b/test-suite/handwritten-src/objc/tests/DBCppFutureTests.mm @@ -67,4 +67,36 @@ - (void) testFutureCoroutines_cleanupOrder { } #endif +- (void) testFuture_brokenPromise { + std::optional> promise{std::in_place}; + auto future = promise->getFuture(); + XCTAssertFalse(future.isReady()); + + auto promise2 = std::make_optional(std::move(*promise)); + XCTAssertFalse(future.isReady()); + + promise.reset(); + XCTAssertFalse(future.isReady()); + + promise2.reset(); + XCTAssertTrue(future.isReady()); + if (future.isReady()) { + XCTAssertThrowsSpecific(future.get(), djinni::BrokenPromiseException); + } +} + +- (void) testFuture_brokenPromiseAssignment { + djinni::Promise promise{}; + auto future = promise.getFuture(); + XCTAssertFalse(future.isReady()); + + promise = djinni::Promise{}; + XCTAssertTrue(future.isReady()); + if (future.isReady()) { + XCTAssertThrowsSpecific(future.get(), djinni::BrokenPromiseException); + } + + XCTAssertFalse(promise.getFuture().isReady()); +} + @end From a23752908fd7a3924acb5db9e4b68cd877d07ae6 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Tue, 13 Aug 2024 10:57:52 +1000 Subject: [PATCH 61/68] downgrade swift protobuf to 1.26 --- bzl/deps.bzl | 4 ++-- support-lib/swift/DJProtobuf.swift | 4 ++-- test-suite/handwritten-src/swift/ProtoTest.swift | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bzl/deps.bzl b/bzl/deps.bzl index 35889a85..722fb3d2 100644 --- a/bzl/deps.bzl +++ b/bzl/deps.bzl @@ -47,13 +47,13 @@ def djinni_deps(): url = "https://github.com/bazelbuild/rules_jvm_external/archive/{}.zip".format(rules_jvm_external_tag), sha256 = "62133c125bf4109dfd9d2af64830208356ce4ef8b165a6ef15bbff7460b35c3a", ) - swiftprotobuf_version = "1.27.0" + swiftprotobuf_version = "1.26.0" maybe( name = "apple_swift_protobuf", repo_rule = http_archive, url = "https://github.com/apple/swift-protobuf/archive/refs/tags/{}.tar.gz".format(swiftprotobuf_version), strip_prefix = "swift-protobuf-{}".format(swiftprotobuf_version), - sha256 = "387ab60f4814e76ed3ae689690c658cf6dab1bc1c6ed67d6c14c33de9daed4d2", + sha256 = "25224376205a54bb719fe7d97aeb9d8f5219c7ef668f426a5dab2da7db992842", build_file_content = """ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") swift_library( diff --git a/support-lib/swift/DJProtobuf.swift b/support-lib/swift/DJProtobuf.swift index 40ef1994..7019512a 100644 --- a/support-lib/swift/DJProtobuf.swift +++ b/support-lib/swift/DJProtobuf.swift @@ -8,13 +8,13 @@ public enum ProtobufMarshaller: Marshaller { let range = djinni.swift.getBinaryRange(v) if (range.size > 0) { let bin = Data(bytesNoCopy:UnsafeMutableRawPointer(mutating: range.bytes), count:range.size, deallocator:.none) - return try! T(serializedBytes: bin) + return try! T(serializedData: bin) } else { return T() } } static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { - let bin: Data = try! s.serializedBytes() + let bin: Data = try! s.serializedData() return BinaryMarshaller.toCpp(bin) } } diff --git a/test-suite/handwritten-src/swift/ProtoTest.swift b/test-suite/handwritten-src/swift/ProtoTest.swift index 4270fa56..e0b57021 100644 --- a/test-suite/handwritten-src/swift/ProtoTest.swift +++ b/test-suite/handwritten-src/swift/ProtoTest.swift @@ -24,7 +24,7 @@ final class ProtoTest: XCTestCase { func testZeroSizeNativeToSwift() throws { let proto = try ProtoTests_statics.stringsToProto([]) - let serialized: Data = try proto.serializedBytes() + let serialized: Data = try proto.serializedData() XCTAssertEqual(serialized.count, 0) } From eedf683774f3ba920def0775a7d310bec4b03932 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Thu, 15 Aug 2024 12:54:44 +1000 Subject: [PATCH 62/68] fixes --- src/source/SwiftGenerator.scala | 32 ++++++++++++++++---------------- src/source/SwiftMarshal.scala | 4 ++-- src/source/YamlGenerator.scala | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/source/SwiftGenerator.scala b/src/source/SwiftGenerator.scala index 3792bc53..9bb9212a 100644 --- a/src/source/SwiftGenerator.scala +++ b/src/source/SwiftGenerator.scala @@ -101,7 +101,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { } }) writeSwiftPrivateFile(ident, origin, List[String]("DjinniSupport", spec.swiftModule), w => { - w.wl(s"typealias ${marshal.typename(ident, e)}Marshaller = DjinniSupport.EnumMarshaller<${marshal.typename(ident, e)}>") + w.wl(s"public typealias ${marshal.typename(ident, e)}Marshaller = DjinniSupport.EnumMarshaller<${marshal.typename(ident, e)}>") }) } @@ -206,9 +206,9 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { } }) writeSwiftPrivateFile(ident, origin, refs.privateImports, w => { - w.w(s"enum ${marshal.typename(ident, r)}Marshaller: DjinniSupport.Marshaller").braced { - w.wl(s"typealias SwiftType = ${marshal.fqTypename(ident, r)}") - w.w("static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced { + w.w(s"public enum ${marshal.typename(ident, r)}Marshaller: DjinniSupport.Marshaller").braced { + w.wl(s"public typealias SwiftType = ${marshal.fqTypename(ident, r)}") + w.w("public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced { w.wl("return withUnsafePointer(to: c) { p in").nested { for ((f, i) <- r.fields.view.zipWithIndex) { val swiftExp = s"djinni.swift.getMember(p, $i)" @@ -219,7 +219,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { } w.wl("}") } - w.w("static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced { + w.w("public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced { if (r.fields.nonEmpty) { w.wl("var ret = djinni.swift.makeCompositeValue()") for (f <- r.fields) { @@ -267,12 +267,12 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { if (m.params.nonEmpty) { w.w("_ ") } w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.fqParamType(p.ty)}").mkString(", ")) w.w(s") throws -> ${marshal.fqReturnType(m.ret)}").braced { - w.wl("var params = djinni.swift.ParameterList()") - w.wl("params.addValue(inst)") + w.wl("var _params = djinni.swift.ParameterList()") + w.wl("_params.addValue(inst)") for (p <- m.params) { - w.wl(s"params.addValue(${marshal.toCpp(p.ty, idSwift.local(p.ident))})") + w.wl(s"_params.addValue(${marshal.toCpp(p.ty, idSwift.local(p.ident))})") } - w.wl(s"var ret = ${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(¶ms)") + w.wl(s"var ret = ${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(&_params)") w.wl("try handleCppErrors(&ret)") if (!m.ret.isEmpty) { w.wl(s"return ${marshal.fromCpp(m.ret.get, "ret")}") @@ -310,13 +310,13 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { w.wl } // Define the marshaller - w.w(s"enum ${marshal.typename(ident, i)}Marshaller: DjinniSupport.Marshaller").braced { - w.wl(s"typealias SwiftType = ${marshal.fqTypename(ident, i)}") - w.w("static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced { + w.w(s"public enum ${marshal.typename(ident, i)}Marshaller: DjinniSupport.Marshaller").braced { + w.wl(s"public typealias SwiftType = ${marshal.fqTypename(ident, i)}") + w.w("public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced { val newProxyBlock = if (i.ext.cpp) {s"{ ${marshal.typename(ident, i)}CppProxy(c) as SwiftType }"} else {"{ fatalError(\"n/a\") }"} w.wl(s"return cppInterfaceToSwift(c, ${newProxyBlock})") } - w.w("static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced { + w.w("public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced { val newProxyBlock = if (i.ext.swift) {s"{ ${spec.swiftxxNamespace}.$swiftProxyClassName.make(ctxPtr(s, ${swiftProxyVtbl}), dispatcherProtocalCall)}"} else {"{ fatalError(\"n/a\") }"} w.wl(s"return swiftInterfaceToCpp(s, ${newProxyBlock})") } @@ -330,11 +330,11 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { if (m.params.nonEmpty) { w.w("_ ") } w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.fqParamType(p.ty)}").mkString(", ")) w.w(s") throws -> ${marshal.fqReturnType(m.ret)}").braced { - w.wl("var params = djinni.swift.ParameterList()") + w.wl("var _params = djinni.swift.ParameterList()") for (p <- m.params) { - w.wl(s"params.addValue(${marshal.toCpp(p.ty, idSwift.local(p.ident))})") + w.wl(s"_params.addValue(${marshal.toCpp(p.ty, idSwift.local(p.ident))})") } - w.wl(s"var ret = ${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(¶ms)") + w.wl(s"var ret = ${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(&_params)") w.wl("try handleCppErrors(&ret)") if (!m.ret.isEmpty) { w.wl(s"return ${marshal.fromCpp(m.ret.get, "ret")}") diff --git a/src/source/SwiftMarshal.scala b/src/source/SwiftMarshal.scala index fd52068d..5fb91330 100644 --- a/src/source/SwiftMarshal.scala +++ b/src/source/SwiftMarshal.scala @@ -59,7 +59,7 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { case MOptional => throw new AssertionError("nested optional?") case m => s"Optional<${f(arg)}>" } - case e: MExtern => e.swift.typename + (if (e.swift.generic) args(tm) else "") + case e: MExtern => e.swift.module + "." + e.swift.typename + (if (e.swift.generic) args(tm) else "") case p: MProtobuf => p.body.swift match { case Some(o) => o.prefix + p.name case None => p.name @@ -102,7 +102,7 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { private def helperClass(tm: MExpr): String = helperName(tm) + helperTemplates(tm) def helperName(tm: MExpr): String = tm.base match { case d: MDef => helperClass(d.name) - case e: MExtern => e.swift.translator + case e: MExtern => e.swift.translatorModule + "." + e.swift.translator case o => o match { case p: MPrimitive => p.idlName match { case "i8" => "I8Marshaller" diff --git a/src/source/YamlGenerator.scala b/src/source/YamlGenerator.scala index 40678a51..1633a902 100644 --- a/src/source/YamlGenerator.scala +++ b/src/source/YamlGenerator.scala @@ -130,7 +130,7 @@ class YamlGenerator(spec: Spec) extends Generator(spec) { ) private def typeDef(td: TypeDecl) = { - def ext(e: Ext): String = (if(e.cpp) " +c" else "") + (if(e.objc) " +o" else "") + (if(e.java) " +j" else "") + (if(e.js) " +w" else "") + def ext(e: Ext): String = (if(e.cpp) " +c" else "") + (if(e.objc) " +o" else "") + (if(e.java) " +j" else "") + (if(e.js) " +w" else "") + (if(e.swift) " +sw" else "") def deriving(r: Record) = { if(r.derivingTypes.isEmpty) { "" From 6e986dd17574fedc3d937827c888761c57cdff95 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Thu, 29 Aug 2024 14:14:02 +1000 Subject: [PATCH 63/68] fixes for snap client integration --- src/source/Main.scala | 4 ++++ src/source/SwiftGenerator.scala | 4 ++-- src/source/SwiftMarshal.scala | 4 ++-- src/source/SwiftxxMarshal.scala | 4 ++-- src/source/generator.scala | 1 + support-lib/swift/DJMarshal.swift | 2 +- test-suite/generated-src/swift/TestHelpers+Private.swift | 4 ++-- 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/source/Main.scala b/src/source/Main.scala index 33fa6189..b7356bbb 100644 --- a/src/source/Main.scala +++ b/src/source/Main.scala @@ -116,6 +116,7 @@ object Main { var swiftIdentStyle = IdentStyle.swiftDefault var swiftxxOutFolder: Option[File] = None var swiftxxNamespace: String = "djinni_generated" + var swiftxxIncludePrefix: String = "" var swiftxxBaseLibModule: String = "DjinniSupportCxx" var swiftxxClassIdentStyleOptional: Option[IdentConverter] = None var swiftxxFileIdentStyleOptional: Option[IdentConverter] = None @@ -306,6 +307,8 @@ object Main { .text("Swift module name (default: \"Module\").") opt[File]("swiftxx-out").valueName("").foreach(x => swiftxxOutFolder = Some(x)) .text("The output folder for private Swift/C++ interop files (Generator disabled if unspecified).") + opt[String]("swiftxx-include-prefix").valueName("").foreach(swiftxxIncludePrefix = _) + .text("The prefix for #includes of Swift C++ header files.") opt[String]("swiftxx-include-cpp-prefix").valueName("").foreach(swiftxxIncludeCppPrefix = _) .text("The prefix for #includes of the main header files from Swift C++ files.") opt[String]("swiftxx-base-lib-include-prefix").valueName("...").foreach(x => swiftxxBaseLibIncludePrefix = x) @@ -522,6 +525,7 @@ object Main { swiftModule, swiftxxOutFolder, swiftxxNamespace, + swiftxxIncludePrefix, swiftxxBaseLibModule, swiftxxClassIdentStyle, swiftxxFileIdentStyle, diff --git a/src/source/SwiftGenerator.scala b/src/source/SwiftGenerator.scala index 9bb9212a..5c25c22b 100644 --- a/src/source/SwiftGenerator.scala +++ b/src/source/SwiftGenerator.scala @@ -125,7 +125,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { class SwiftRefs(name: String) { var swiftImports = mutable.TreeSet[String]() - var privateImports = mutable.TreeSet[String]("DjinniSupport", "Foundation",spec.swiftxxBaseLibModule, spec.swiftModule, spec.swiftModule + "Cxx") + var privateImports = mutable.TreeSet[String]("DjinniSupport", "Foundation", spec.swiftxxBaseLibModule, spec.swiftModule, spec.swiftModule + "Cxx") swiftImports.add("Foundation") def find(ty: TypeRef) { find(ty.resolved) } def find(tm: MExpr) { @@ -326,7 +326,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) { if (!staticMethods.isEmpty) { w.w(s"public class ${marshal.typename(ident, i)}_statics").braced { for (m <- staticMethods) { - w.w(s"static func ${swiftMethodName(m.ident)}(") + w.w(s"public static func ${swiftMethodName(m.ident)}(") if (m.params.nonEmpty) { w.w("_ ") } w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.fqParamType(p.ty)}").mkString(", ")) w.w(s") throws -> ${marshal.fqReturnType(m.ret)}").braced { diff --git a/src/source/SwiftMarshal.scala b/src/source/SwiftMarshal.scala index 5fb91330..c4fcc76d 100644 --- a/src/source/SwiftMarshal.scala +++ b/src/source/SwiftMarshal.scala @@ -102,7 +102,7 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { private def helperClass(tm: MExpr): String = helperName(tm) + helperTemplates(tm) def helperName(tm: MExpr): String = tm.base match { case d: MDef => helperClass(d.name) - case e: MExtern => e.swift.translatorModule + "." + e.swift.translator + case e: MExtern => e.swift.translator case o => o match { case p: MPrimitive => p.idlName match { case "i8" => "I8Marshaller" @@ -128,7 +128,7 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { case d: MDef => throw new AssertionError("unreachable") case e: MExtern => throw new AssertionError("unreachable") case p: MParam => throw new AssertionError("not applicable") - case MVoid => "VoidMarshaller" + case MVoid => "Void_Marshaller" } } private def helperTemplates(tm: MExpr): String = { diff --git a/src/source/SwiftxxMarshal.scala b/src/source/SwiftxxMarshal.scala index 66c3f3e0..f2d32672 100644 --- a/src/source/SwiftxxMarshal.scala +++ b/src/source/SwiftxxMarshal.scala @@ -47,10 +47,10 @@ class SwiftxxMarshal(spec: Spec) extends Marshal(spec) { case _ => List() } - def include(ident: String) = q(spec.swiftxxFileIdentStyle(ident) + "." + spec.cppHeaderExt) + def include(ident: String) = q(spec.swiftxxIncludePrefix + spec.swiftxxFileIdentStyle(ident) + "." + spec.cppHeaderExt) def resolveExtSwiftxxHdr(path: String) = { - path.replaceAll("\\$", ""); + path.replaceAll("\\$", spec.swiftxxBaseLibIncludePrefix); } def helperClass(name: String) = spec.swiftxxClassIdentStyle(name) diff --git a/src/source/generator.scala b/src/source/generator.scala index d64c4641..54844a27 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -118,6 +118,7 @@ package object generatorTools { swiftModule: String, swiftxxOutFolder: Option[File], swiftxxNamespace: String, + swiftxxIncludePrefix: String, swiftxxBaseLibModule: String, swiftxxClassIdentStyle: IdentConverter, swiftxxFileIdentStyle: IdentConverter, diff --git a/support-lib/swift/DJMarshal.swift b/support-lib/swift/DJMarshal.swift index 905f097d..9dcf1f14 100644 --- a/support-lib/swift/DJMarshal.swift +++ b/support-lib/swift/DJMarshal.swift @@ -113,7 +113,7 @@ public enum DateMarshaller: Marshaller { } } -public enum VoidMarshaller: Marshaller { +public enum Void_Marshaller: Marshaller { public typealias SwiftType = Void static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType { return () diff --git a/test-suite/generated-src/swift/TestHelpers+Private.swift b/test-suite/generated-src/swift/TestHelpers+Private.swift index 855aa9b4..da7c0a3c 100644 --- a/test-suite/generated-src/swift/TestHelpers+Private.swift +++ b/test-suite/generated-src/swift/TestHelpers+Private.swift @@ -207,10 +207,10 @@ public class TestHelpers_statics { } static func voidAsyncMethod(_ f: DJFuture) throws -> DJFuture { var params = djinni.swift.ParameterList() - params.addValue(FutureMarshaller.toCpp(f)) + params.addValue(FutureMarshaller.toCpp(f)) var ret = djinni_generated.TestHelpers_voidAsyncMethod(¶ms) try handleCppErrors(&ret) - return FutureMarshaller.fromCpp(ret) + return FutureMarshaller.fromCpp(ret) } static func addOneIfPresent(_ f: DJFuture>) throws -> DJFuture> { var params = djinni.swift.ParameterList() From 539df092e3899eb12a3930abe973194283c0b477 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Thu, 29 Aug 2024 15:07:39 +1000 Subject: [PATCH 64/68] fixes --- .../swift/ItemList+Private.swift | 8 +- .../swift/SortItems+Private.swift | 34 +- .../swift/SortOrder+Private.swift | 2 +- .../swift/TextboxListener+Private.swift | 8 +- src/source/SwiftMarshal.scala | 4 +- .../djinni/vendor/third-party/date.yaml | 2 +- .../djinni/vendor/third-party/duration.yaml | 7 + .../swift/AccessFlags+Private.swift | 2 +- .../swift/AssortedPrimitives+Private.swift | 8 +- .../swift/AsyncInterface+Private.swift | 12 +- .../generated-src/swift/AsyncInterface.swift | 2 +- .../swift/ClientInterface+Private.swift | 8 +- .../swift/ClientReturnedRecord+Private.swift | 8 +- .../generated-src/swift/Color+Private.swift | 2 +- .../swift/Conflict+Private.swift | 8 +- .../swift/ConflictUser+Private.swift | 22 +- .../swift/ConstantEnum+Private.swift | 2 +- .../ConstantInterfaceWithEnum+Private.swift | 8 +- .../swift/ConstantRecord+Private.swift | 8 +- .../swift/ConstantWithEnum+Private.swift | 8 +- .../swift/Constants+Private.swift | 8 +- .../swift/ConstantsInterface+Private.swift | 14 +- .../swift/CppException+Private.swift | 36 +- .../swift/DataRefTest+Private.swift | 90 ++--- .../generated-src/swift/DataRefTest.swift | 14 +- .../swift/DateRecord+Private.swift | 8 +- .../generated-src/swift/DateRecord.swift | 1 - .../swift/EmptyFlags+Private.swift | 2 +- .../swift/EmptyRecord+Private.swift | 8 +- .../swift/EnumUsageInterface+Private.swift | 48 +-- .../swift/EnumUsageRecord+Private.swift | 8 +- .../swift/ExtendedRecord+Private.swift | 8 +- .../swift/ExternInterface1+Private.swift | 32 +- .../swift/ExternInterface1.swift | 4 +- .../swift/ExternInterface2+Private.swift | 8 +- .../swift/ExternInterface2.swift | 2 +- .../ExternRecordWithDerivings+Private.swift | 16 +- .../swift/ExternRecordWithDerivings.swift | 6 +- .../swift/FirstListener+Private.swift | 8 +- .../swift/FlagRoundtrip+Private.swift | 40 +-- ...InterfaceUsingExtendedRecord+Private.swift | 16 +- .../swift/JavaOnlyListener+Private.swift | 8 +- .../swift/ListenerCaller+Private.swift | 30 +- .../swift/MapDateRecord+Private.swift | 8 +- .../generated-src/swift/MapDateRecord.swift | 1 - .../swift/MapListRecord+Private.swift | 8 +- .../swift/MapRecord+Private.swift | 8 +- .../swift/NestedCollection+Private.swift | 8 +- .../swift/NestedOutcome+Private.swift | 12 +- .../swift/ObjcOnlyListener+Private.swift | 8 +- .../swift/PrimitiveList+Private.swift | 8 +- .../swift/ProtoTests+Private.swift | 114 +++---- .../RecordUsingExtendedRecord+Private.swift | 8 +- .../swift/RecordWithDerivings+Private.swift | 8 +- ...cordWithDurationAndDerivings+Private.swift | 12 +- .../RecordWithEmbeddedCppProto+Private.swift | 8 +- .../RecordWithEmbeddedProto+Private.swift | 8 +- .../swift/RecordWithFlags+Private.swift | 8 +- .../RecordWithNestedDerivings+Private.swift | 8 +- .../swift/ReturnOne+Private.swift | 20 +- .../swift/ReturnTwo+Private.swift | 20 +- .../ReverseClientInterface+Private.swift | 36 +- .../swift/SampleInterface+Private.swift | 8 +- .../swift/SecondListener+Private.swift | 8 +- .../swift/SetRecord+Private.swift | 8 +- .../swift/SupportCopying+Private.swift | 8 +- .../swift/TestArray+Private.swift | 40 +-- .../swift/TestDuration+Private.swift | 194 +++++------ .../swift/TestHelpers+Private.swift | 312 +++++++++--------- ...ptionalExternInterfaceRecord+Private.swift | 12 +- .../TestOptionalExternInterfaceRecord.swift | 4 +- .../swift/TestOutcome+Private.swift | 68 ++-- .../TestStaticMethodLanguage+Private.swift | 8 +- .../swift/ThrowingInterface+Private.swift | 8 +- .../swift/UserToken+Private.swift | 14 +- .../UsesSingleLanguageListeners+Private.swift | 36 +- .../swift/VarnameInterface+Private.swift | 24 +- .../swift/VarnameRecord+Private.swift | 8 +- .../generated-src/swift/Vec2+Private.swift | 8 +- .../swift/WcharTestHelpers+Private.swift | 36 +- .../swift/WcharTestRec+Private.swift | 8 +- 81 files changed, 853 insertions(+), 848 deletions(-) diff --git a/examples/generated-src/swift/ItemList+Private.swift b/examples/generated-src/swift/ItemList+Private.swift index 170259cf..5e3ff565 100644 --- a/examples/generated-src/swift/ItemList+Private.swift +++ b/examples/generated-src/swift/ItemList+Private.swift @@ -7,15 +7,15 @@ import Foundation import TextSort import TextSortCxx -enum ItemListMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TextSort.ItemList - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ItemListMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TextSort.ItemList + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let items = ListMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(items: items) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, ListMarshaller.toCpp(s.items)) return ret diff --git a/examples/generated-src/swift/SortItems+Private.swift b/examples/generated-src/swift/SortItems+Private.swift index 1d64c57f..eed2207a 100644 --- a/examples/generated-src/swift/SortItems+Private.swift +++ b/examples/generated-src/swift/SortItems+Private.swift @@ -10,35 +10,35 @@ import TextSortCxx final class SortItemsCppProxy: DjinniSupport.CppProxy, TextSort.SortItems { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func sort(_ order: TextSort.SortOrder, items: TextSort.ItemList) throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(SortOrderMarshaller.toCpp(order)) - params.addValue(ItemListMarshaller.toCpp(items)) - var ret = djinni_generated.SortItems_sort(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(SortOrderMarshaller.toCpp(order)) + _params.addValue(ItemListMarshaller.toCpp(items)) + var ret = djinni_generated.SortItems_sort(&_params) try handleCppErrors(&ret) } } -enum SortItemsMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TextSort.SortItems - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum SortItemsMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TextSort.SortItems + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { SortItemsCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class SortItems_statics { - static func createWithListener(_ listener: TextSort.TextboxListener) throws -> TextSort.SortItems { - var params = djinni.swift.ParameterList() - params.addValue(TextboxListenerMarshaller.toCpp(listener)) - var ret = djinni_generated.SortItems_createWithListener(¶ms) + public static func createWithListener(_ listener: TextSort.TextboxListener) throws -> TextSort.SortItems { + var _params = djinni.swift.ParameterList() + _params.addValue(TextboxListenerMarshaller.toCpp(listener)) + var ret = djinni_generated.SortItems_createWithListener(&_params) try handleCppErrors(&ret) return SortItemsMarshaller.fromCpp(ret) } - static func runSort(_ items: TextSort.ItemList) throws -> TextSort.ItemList { - var params = djinni.swift.ParameterList() - params.addValue(ItemListMarshaller.toCpp(items)) - var ret = djinni_generated.SortItems_runSort(¶ms) + public static func runSort(_ items: TextSort.ItemList) throws -> TextSort.ItemList { + var _params = djinni.swift.ParameterList() + _params.addValue(ItemListMarshaller.toCpp(items)) + var ret = djinni_generated.SortItems_runSort(&_params) try handleCppErrors(&ret) return ItemListMarshaller.fromCpp(ret) } diff --git a/examples/generated-src/swift/SortOrder+Private.swift b/examples/generated-src/swift/SortOrder+Private.swift index 0d793a72..31fdf7f4 100644 --- a/examples/generated-src/swift/SortOrder+Private.swift +++ b/examples/generated-src/swift/SortOrder+Private.swift @@ -4,4 +4,4 @@ import DjinniSupport import TextSort -typealias SortOrderMarshaller = DjinniSupport.EnumMarshaller +public typealias SortOrderMarshaller = DjinniSupport.EnumMarshaller diff --git a/examples/generated-src/swift/TextboxListener+Private.swift b/examples/generated-src/swift/TextboxListener+Private.swift index 5fe251b2..ded4c8f9 100644 --- a/examples/generated-src/swift/TextboxListener+Private.swift +++ b/examples/generated-src/swift/TextboxListener+Private.swift @@ -14,12 +14,12 @@ let textboxListenerMethods: Vtbl = [ }, ] -enum TextboxListenerMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TextSort.TextboxListener - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum TextboxListenerMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TextSort.TextboxListener + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { fatalError("n/a") }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { djinni_generated.TextboxListenerSwiftProxy.make(ctxPtr(s, textboxListenerMethods), dispatcherProtocalCall)}) } } diff --git a/src/source/SwiftMarshal.scala b/src/source/SwiftMarshal.scala index c4fcc76d..325864d6 100644 --- a/src/source/SwiftMarshal.scala +++ b/src/source/SwiftMarshal.scala @@ -59,7 +59,7 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { case MOptional => throw new AssertionError("nested optional?") case m => s"Optional<${f(arg)}>" } - case e: MExtern => e.swift.module + "." + e.swift.typename + (if (e.swift.generic) args(tm) else "") + case e: MExtern => Array(e.swift.module, e.swift.typename).filter(s => !s.isEmpty).mkString(".") + (if (e.swift.generic) args(tm) else "") case p: MProtobuf => p.body.swift match { case Some(o) => o.prefix + p.name case None => p.name @@ -102,7 +102,7 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) { private def helperClass(tm: MExpr): String = helperName(tm) + helperTemplates(tm) def helperName(tm: MExpr): String = tm.base match { case d: MDef => helperClass(d.name) - case e: MExtern => e.swift.translator + case e: MExtern => Array(e.swift.translatorModule, e.swift.translator).filter(s => !s.isEmpty).mkString(".") case o => o match { case p: MPrimitive => p.idlName match { case "i8" => "I8Marshaller" diff --git a/test-suite/djinni/vendor/third-party/date.yaml b/test-suite/djinni/vendor/third-party/date.yaml index 8ae3858a..185bb592 100644 --- a/test-suite/djinni/vendor/third-party/date.yaml +++ b/test-suite/djinni/vendor/third-party/date.yaml @@ -40,7 +40,7 @@ ts: swift: typename: 'Date' translator: 'DateMarshaller' - module: 'DjinniSupport' + translatorModule: 'TestSuite' swiftxx: translator: '::djinni::swift::Date' header: '"djinni_support.hpp"' diff --git a/test-suite/djinni/vendor/third-party/duration.yaml b/test-suite/djinni/vendor/third-party/duration.yaml index ad253731..d931bd60 100644 --- a/test-suite/djinni/vendor/third-party/duration.yaml +++ b/test-suite/djinni/vendor/third-party/duration.yaml @@ -41,6 +41,7 @@ ts: swift: typename: 'Duration' translator: 'DurationMarshaller' + translator.module: 'TestSuite' swiftxx: translator: '::djinni::swift::Duration' header: '"Duration-swift.hpp"' @@ -83,6 +84,7 @@ ts: swift: typename: 'Duration' translator: 'DurationH' + translator.module: 'TestSuite' swiftxx: translator: '::djinni::swift::Duration_h' header: '"Duration-swift.hpp"' @@ -125,6 +127,7 @@ ts: swift: typename: 'Duration' translator: 'DurationMin' + translator.module: 'TestSuite' swiftxx: translator: '::djinni::swift::Duration_min' header: '"Duration-swift.hpp"' @@ -167,6 +170,7 @@ ts: swift: typename: 'Duration' translator: 'DurationS' + translator.module: 'TestSuite' swiftxx: translator: '::djinni::swift::Duration_s' header: '"Duration-swift.hpp"' @@ -209,6 +213,7 @@ ts: swift: typename: 'Duration' translator: 'DurationMs' + translator.module: 'TestSuite' swiftxx: translator: '::djinni::swift::Duration_ms' header: '"Duration-swift.hpp"' @@ -251,6 +256,7 @@ ts: swift: typename: 'Duration' translator: 'DurationUs' + translator.module: 'TestSuite' swiftxx: translator: '::djinni::swift::Duration_us' header: '"Duration-swift.hpp"' @@ -293,6 +299,7 @@ ts: swift: typename: 'Duration' translator: 'DurationNs' + translator.module: 'TestSuite' swiftxx: translator: '::djinni::swift::Duration_ns' header: '"Duration-swift.hpp"' diff --git a/test-suite/generated-src/swift/AccessFlags+Private.swift b/test-suite/generated-src/swift/AccessFlags+Private.swift index fdce498d..4b9a1a82 100644 --- a/test-suite/generated-src/swift/AccessFlags+Private.swift +++ b/test-suite/generated-src/swift/AccessFlags+Private.swift @@ -4,4 +4,4 @@ import DjinniSupport import TestSuite -typealias AccessFlagsMarshaller = DjinniSupport.EnumMarshaller +public typealias AccessFlagsMarshaller = DjinniSupport.EnumMarshaller diff --git a/test-suite/generated-src/swift/AssortedPrimitives+Private.swift b/test-suite/generated-src/swift/AssortedPrimitives+Private.swift index 75c29919..647b4657 100644 --- a/test-suite/generated-src/swift/AssortedPrimitives+Private.swift +++ b/test-suite/generated-src/swift/AssortedPrimitives+Private.swift @@ -7,9 +7,9 @@ import Foundation import TestSuite import TestSuiteCxx -enum AssortedPrimitivesMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.AssortedPrimitives - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum AssortedPrimitivesMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.AssortedPrimitives + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let b = BoolMarshaller.fromCpp(djinni.swift.getMember(p, 0)) let eight = I8Marshaller.fromCpp(djinni.swift.getMember(p, 1)) @@ -28,7 +28,7 @@ enum AssortedPrimitivesMarshaller: DjinniSupport.Marshaller { return SwiftType(b: b, eight: eight, sixteen: sixteen, thirtytwo: thirtytwo, sixtyfour: sixtyfour, fthirtytwo: fthirtytwo, fsixtyfour: fsixtyfour, oB: oB, oEight: oEight, oSixteen: oSixteen, oThirtytwo: oThirtytwo, oSixtyfour: oSixtyfour, oFthirtytwo: oFthirtytwo, oFsixtyfour: oFsixtyfour) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, BoolMarshaller.toCpp(s.b)) djinni.swift.addMember(&ret, I8Marshaller.toCpp(s.eight)) diff --git a/test-suite/generated-src/swift/AsyncInterface+Private.swift b/test-suite/generated-src/swift/AsyncInterface+Private.swift index 348f78a8..f4a86001 100644 --- a/test-suite/generated-src/swift/AsyncInterface+Private.swift +++ b/test-suite/generated-src/swift/AsyncInterface+Private.swift @@ -9,17 +9,17 @@ import TestSuiteCxx let asyncInterfaceMethods: Vtbl = [ { inst, params, ret in - let _f = FutureMarshaller.fromCpp(djinni.swift.getMember(params, 0)) - djinni.swift.setReturnValue(ret, try FutureMarshaller.toCpp(inst.futureRoundtrip(_f))) + let _f = DjinniSupport.FutureMarshaller.fromCpp(djinni.swift.getMember(params, 0)) + djinni.swift.setReturnValue(ret, try DjinniSupport.FutureMarshaller.toCpp(inst.futureRoundtrip(_f))) }, ] -enum AsyncInterfaceMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.AsyncInterface - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum AsyncInterfaceMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.AsyncInterface + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { fatalError("n/a") }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { djinni_generated.AsyncInterfaceSwiftProxy.make(ctxPtr(s, asyncInterfaceMethods), dispatcherProtocalCall)}) } } diff --git a/test-suite/generated-src/swift/AsyncInterface.swift b/test-suite/generated-src/swift/AsyncInterface.swift index c248391d..749fd1eb 100644 --- a/test-suite/generated-src/swift/AsyncInterface.swift +++ b/test-suite/generated-src/swift/AsyncInterface.swift @@ -5,5 +5,5 @@ import DjinniSupport import Foundation public protocol AsyncInterface: AnyObject { - func futureRoundtrip(_ f: DJFuture) throws -> DJFuture + func futureRoundtrip(_ f: DjinniSupport.DJFuture) throws -> DjinniSupport.DJFuture } diff --git a/test-suite/generated-src/swift/ClientInterface+Private.swift b/test-suite/generated-src/swift/ClientInterface+Private.swift index 516b6cc6..5399ffdd 100644 --- a/test-suite/generated-src/swift/ClientInterface+Private.swift +++ b/test-suite/generated-src/swift/ClientInterface+Private.swift @@ -34,12 +34,12 @@ let clientInterfaceMethods: Vtbl = [ }, ] -enum ClientInterfaceMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ClientInterface - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ClientInterfaceMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ClientInterface + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { fatalError("n/a") }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { djinni_generated.ClientInterfaceSwiftProxy.make(ctxPtr(s, clientInterfaceMethods), dispatcherProtocalCall)}) } } diff --git a/test-suite/generated-src/swift/ClientReturnedRecord+Private.swift b/test-suite/generated-src/swift/ClientReturnedRecord+Private.swift index 11496b4f..9510131e 100644 --- a/test-suite/generated-src/swift/ClientReturnedRecord+Private.swift +++ b/test-suite/generated-src/swift/ClientReturnedRecord+Private.swift @@ -7,9 +7,9 @@ import Foundation import TestSuite import TestSuiteCxx -enum ClientReturnedRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ClientReturnedRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ClientReturnedRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ClientReturnedRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let recordId = I64Marshaller.fromCpp(djinni.swift.getMember(p, 0)) let content = StringMarshaller.fromCpp(djinni.swift.getMember(p, 1)) @@ -17,7 +17,7 @@ enum ClientReturnedRecordMarshaller: DjinniSupport.Marshaller { return SwiftType(recordId: recordId, content: content, misc: misc) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, I64Marshaller.toCpp(s.recordId)) djinni.swift.addMember(&ret, StringMarshaller.toCpp(s.content)) diff --git a/test-suite/generated-src/swift/Color+Private.swift b/test-suite/generated-src/swift/Color+Private.swift index 9a233fc1..8c4d2207 100644 --- a/test-suite/generated-src/swift/Color+Private.swift +++ b/test-suite/generated-src/swift/Color+Private.swift @@ -4,4 +4,4 @@ import DjinniSupport import TestSuite -typealias ColorMarshaller = DjinniSupport.EnumMarshaller +public typealias ColorMarshaller = DjinniSupport.EnumMarshaller diff --git a/test-suite/generated-src/swift/Conflict+Private.swift b/test-suite/generated-src/swift/Conflict+Private.swift index f7443b2c..e889c093 100644 --- a/test-suite/generated-src/swift/Conflict+Private.swift +++ b/test-suite/generated-src/swift/Conflict+Private.swift @@ -14,12 +14,12 @@ import TestSuiteCxx final class ConflictCppProxy: DjinniSupport.CppProxy, TestSuite.Conflict { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } } -enum ConflictMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.Conflict - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ConflictMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.Conflict + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { ConflictCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/ConflictUser+Private.swift b/test-suite/generated-src/swift/ConflictUser+Private.swift index 506285d8..0062fe83 100644 --- a/test-suite/generated-src/swift/ConflictUser+Private.swift +++ b/test-suite/generated-src/swift/ConflictUser+Private.swift @@ -10,27 +10,27 @@ import TestSuiteCxx final class ConflictUserCppProxy: DjinniSupport.CppProxy, TestSuite.ConflictUser { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func Conflict() throws -> TestSuite.Conflict { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.ConflictUser_Conflict(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.ConflictUser_Conflict(&_params) try handleCppErrors(&ret) return ConflictMarshaller.fromCpp(ret) } func conflictArg(_ cs: Array) throws -> Bool { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(ListMarshaller.toCpp(cs)) - var ret = djinni_generated.ConflictUser_conflictArg(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(ListMarshaller.toCpp(cs)) + var ret = djinni_generated.ConflictUser_conflictArg(&_params) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } } -enum ConflictUserMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ConflictUser - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ConflictUserMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ConflictUser + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { ConflictUserCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/ConstantEnum+Private.swift b/test-suite/generated-src/swift/ConstantEnum+Private.swift index 94de0827..3bc3f10b 100644 --- a/test-suite/generated-src/swift/ConstantEnum+Private.swift +++ b/test-suite/generated-src/swift/ConstantEnum+Private.swift @@ -4,4 +4,4 @@ import DjinniSupport import TestSuite -typealias ConstantEnumMarshaller = DjinniSupport.EnumMarshaller +public typealias ConstantEnumMarshaller = DjinniSupport.EnumMarshaller diff --git a/test-suite/generated-src/swift/ConstantInterfaceWithEnum+Private.swift b/test-suite/generated-src/swift/ConstantInterfaceWithEnum+Private.swift index 5d6f14ae..4ff4d526 100644 --- a/test-suite/generated-src/swift/ConstantInterfaceWithEnum+Private.swift +++ b/test-suite/generated-src/swift/ConstantInterfaceWithEnum+Private.swift @@ -11,12 +11,12 @@ import TestSuiteCxx final class ConstantInterfaceWithEnumCppProxy: DjinniSupport.CppProxy, TestSuite.ConstantInterfaceWithEnum { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } } -enum ConstantInterfaceWithEnumMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ConstantInterfaceWithEnum - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ConstantInterfaceWithEnumMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ConstantInterfaceWithEnum + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { ConstantInterfaceWithEnumCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/ConstantRecord+Private.swift b/test-suite/generated-src/swift/ConstantRecord+Private.swift index 59c1b2d3..702ad583 100644 --- a/test-suite/generated-src/swift/ConstantRecord+Private.swift +++ b/test-suite/generated-src/swift/ConstantRecord+Private.swift @@ -7,16 +7,16 @@ import Foundation import TestSuite import TestSuiteCxx -enum ConstantRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ConstantRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ConstantRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ConstantRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let someInteger = I32Marshaller.fromCpp(djinni.swift.getMember(p, 0)) let someString = StringMarshaller.fromCpp(djinni.swift.getMember(p, 1)) return SwiftType(someInteger: someInteger, someString: someString) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, I32Marshaller.toCpp(s.someInteger)) djinni.swift.addMember(&ret, StringMarshaller.toCpp(s.someString)) diff --git a/test-suite/generated-src/swift/ConstantWithEnum+Private.swift b/test-suite/generated-src/swift/ConstantWithEnum+Private.swift index edff8b12..207197d9 100644 --- a/test-suite/generated-src/swift/ConstantWithEnum+Private.swift +++ b/test-suite/generated-src/swift/ConstantWithEnum+Private.swift @@ -7,14 +7,14 @@ import Foundation import TestSuite import TestSuiteCxx -enum ConstantWithEnumMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ConstantWithEnum - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ConstantWithEnumMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ConstantWithEnum + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in return SwiftType() } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return djinni.swift.makeCompositeValue() } } diff --git a/test-suite/generated-src/swift/Constants+Private.swift b/test-suite/generated-src/swift/Constants+Private.swift index 1a25dffd..a41694ae 100644 --- a/test-suite/generated-src/swift/Constants+Private.swift +++ b/test-suite/generated-src/swift/Constants+Private.swift @@ -7,14 +7,14 @@ import Foundation import TestSuite import TestSuiteCxx -enum ConstantsMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.Constants - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ConstantsMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.Constants + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in return SwiftType() } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return djinni.swift.makeCompositeValue() } } diff --git a/test-suite/generated-src/swift/ConstantsInterface+Private.swift b/test-suite/generated-src/swift/ConstantsInterface+Private.swift index 6d740e70..983df413 100644 --- a/test-suite/generated-src/swift/ConstantsInterface+Private.swift +++ b/test-suite/generated-src/swift/ConstantsInterface+Private.swift @@ -11,18 +11,18 @@ import TestSuiteCxx final class ConstantsInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.ConstantsInterface { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func dummy() throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.ConstantsInterface_dummy(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.ConstantsInterface_dummy(&_params) try handleCppErrors(&ret) } } -enum ConstantsInterfaceMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ConstantsInterface - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ConstantsInterfaceMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ConstantsInterface + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { ConstantsInterfaceCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/CppException+Private.swift b/test-suite/generated-src/swift/CppException+Private.swift index c4f95dce..0275ec7d 100644 --- a/test-suite/generated-src/swift/CppException+Private.swift +++ b/test-suite/generated-src/swift/CppException+Private.swift @@ -10,42 +10,42 @@ import TestSuiteCxx final class CppExceptionCppProxy: DjinniSupport.CppProxy, TestSuite.CppException { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func throwAnException() throws -> Int32 { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.CppException_throwAnException(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.CppException_throwAnException(&_params) try handleCppErrors(&ret) return I32Marshaller.fromCpp(ret) } func callThrowingInterface(_ cb: TestSuite.ThrowingInterface) throws -> Int32 { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(ThrowingInterfaceMarshaller.toCpp(cb)) - var ret = djinni_generated.CppException_callThrowingInterface(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(ThrowingInterfaceMarshaller.toCpp(cb)) + var ret = djinni_generated.CppException_callThrowingInterface(&_params) try handleCppErrors(&ret) return I32Marshaller.fromCpp(ret) } func callThrowingAndCatch(_ cb: TestSuite.ThrowingInterface) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(ThrowingInterfaceMarshaller.toCpp(cb)) - var ret = djinni_generated.CppException_callThrowingAndCatch(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(ThrowingInterfaceMarshaller.toCpp(cb)) + var ret = djinni_generated.CppException_callThrowingAndCatch(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } } -enum CppExceptionMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.CppException - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum CppExceptionMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.CppException + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { CppExceptionCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class CppException_statics { - static func get() throws -> TestSuite.CppException { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.CppException_get(¶ms) + public static func get() throws -> TestSuite.CppException { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.CppException_get(&_params) try handleCppErrors(&ret) return CppExceptionMarshaller.fromCpp(ret) } diff --git a/test-suite/generated-src/swift/DataRefTest+Private.swift b/test-suite/generated-src/swift/DataRefTest+Private.swift index dc2f42be..fb0f01f9 100644 --- a/test-suite/generated-src/swift/DataRefTest+Private.swift +++ b/test-suite/generated-src/swift/DataRefTest+Private.swift @@ -9,77 +9,77 @@ import TestSuiteCxx final class DataRefTestCppProxy: DjinniSupport.CppProxy, TestSuite.DataRefTest { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } - func sendData(_ data: NSData) throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(DataRefMarshaller.toCpp(data)) - var ret = djinni_generated.DataRefTest_sendData(¶ms) + func sendData(_ data: Foundation.NSData) throws -> Void { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(DjinniSupport.DataRefMarshaller.toCpp(data)) + var ret = djinni_generated.DataRefTest_sendData(&_params) try handleCppErrors(&ret) } func retriveAsBin() throws -> Data { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.DataRefTest_retriveAsBin(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.DataRefTest_retriveAsBin(&_params) try handleCppErrors(&ret) return BinaryMarshaller.fromCpp(ret) } - func sendMutableData(_ data: NSData) throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(DataRefMarshaller.toCpp(data)) - var ret = djinni_generated.DataRefTest_sendMutableData(¶ms) + func sendMutableData(_ data: Foundation.NSData) throws -> Void { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(DjinniSupport.DataRefMarshaller.toCpp(data)) + var ret = djinni_generated.DataRefTest_sendMutableData(&_params) try handleCppErrors(&ret) } - func generateData() throws -> NSData { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.DataRefTest_generateData(¶ms) + func generateData() throws -> Foundation.NSData { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.DataRefTest_generateData(&_params) try handleCppErrors(&ret) - return DataRefMarshaller.fromCpp(ret) + return DjinniSupport.DataRefMarshaller.fromCpp(ret) } - func dataFromVec() throws -> NSData { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.DataRefTest_dataFromVec(¶ms) + func dataFromVec() throws -> Foundation.NSData { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.DataRefTest_dataFromVec(&_params) try handleCppErrors(&ret) - return DataRefMarshaller.fromCpp(ret) + return DjinniSupport.DataRefMarshaller.fromCpp(ret) } - func dataFromStr() throws -> NSData { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.DataRefTest_dataFromStr(¶ms) + func dataFromStr() throws -> Foundation.NSData { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.DataRefTest_dataFromStr(&_params) try handleCppErrors(&ret) - return DataRefMarshaller.fromCpp(ret) + return DjinniSupport.DataRefMarshaller.fromCpp(ret) } - func sendDataView(_ data: NSData) throws -> Data { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(DataViewMarshaller.toCpp(data)) - var ret = djinni_generated.DataRefTest_sendDataView(¶ms) + func sendDataView(_ data: Foundation.NSData) throws -> Data { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(DjinniSupport.DataViewMarshaller.toCpp(data)) + var ret = djinni_generated.DataRefTest_sendDataView(&_params) try handleCppErrors(&ret) return BinaryMarshaller.fromCpp(ret) } - func recvDataView() throws -> NSData { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.DataRefTest_recvDataView(¶ms) + func recvDataView() throws -> Foundation.NSData { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.DataRefTest_recvDataView(&_params) try handleCppErrors(&ret) - return DataViewMarshaller.fromCpp(ret) + return DjinniSupport.DataViewMarshaller.fromCpp(ret) } } -enum DataRefTestMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.DataRefTest - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum DataRefTestMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.DataRefTest + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { DataRefTestCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class DataRefTest_statics { - static func create() throws -> TestSuite.DataRefTest { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.DataRefTest_create(¶ms) + public static func create() throws -> TestSuite.DataRefTest { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.DataRefTest_create(&_params) try handleCppErrors(&ret) return DataRefTestMarshaller.fromCpp(ret) } diff --git a/test-suite/generated-src/swift/DataRefTest.swift b/test-suite/generated-src/swift/DataRefTest.swift index 350bd74c..7c87d637 100644 --- a/test-suite/generated-src/swift/DataRefTest.swift +++ b/test-suite/generated-src/swift/DataRefTest.swift @@ -4,12 +4,12 @@ import Foundation public protocol DataRefTest: AnyObject { - func sendData(_ data: NSData) throws -> Void + func sendData(_ data: Foundation.NSData) throws -> Void func retriveAsBin() throws -> Data - func sendMutableData(_ data: NSData) throws -> Void - func generateData() throws -> NSData - func dataFromVec() throws -> NSData - func dataFromStr() throws -> NSData - func sendDataView(_ data: NSData) throws -> Data - func recvDataView() throws -> NSData + func sendMutableData(_ data: Foundation.NSData) throws -> Void + func generateData() throws -> Foundation.NSData + func dataFromVec() throws -> Foundation.NSData + func dataFromStr() throws -> Foundation.NSData + func sendDataView(_ data: Foundation.NSData) throws -> Data + func recvDataView() throws -> Foundation.NSData } diff --git a/test-suite/generated-src/swift/DateRecord+Private.swift b/test-suite/generated-src/swift/DateRecord+Private.swift index 0e12bb74..9b437108 100644 --- a/test-suite/generated-src/swift/DateRecord+Private.swift +++ b/test-suite/generated-src/swift/DateRecord+Private.swift @@ -7,15 +7,15 @@ import Foundation import TestSuite import TestSuiteCxx -enum DateRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.DateRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum DateRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.DateRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let createdAt = DateMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(createdAt: createdAt) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, DateMarshaller.toCpp(s.createdAt)) return ret diff --git a/test-suite/generated-src/swift/DateRecord.swift b/test-suite/generated-src/swift/DateRecord.swift index 4d6d1a8e..d302a076 100644 --- a/test-suite/generated-src/swift/DateRecord.swift +++ b/test-suite/generated-src/swift/DateRecord.swift @@ -1,7 +1,6 @@ // AUTOGENERATED FILE - DO NOT MODIFY! // This file was generated by Djinni from date.djinni -import DjinniSupport import Foundation public struct DateRecord: Equatable { diff --git a/test-suite/generated-src/swift/EmptyFlags+Private.swift b/test-suite/generated-src/swift/EmptyFlags+Private.swift index f09a089e..c1202c70 100644 --- a/test-suite/generated-src/swift/EmptyFlags+Private.swift +++ b/test-suite/generated-src/swift/EmptyFlags+Private.swift @@ -4,4 +4,4 @@ import DjinniSupport import TestSuite -typealias EmptyFlagsMarshaller = DjinniSupport.EnumMarshaller +public typealias EmptyFlagsMarshaller = DjinniSupport.EnumMarshaller diff --git a/test-suite/generated-src/swift/EmptyRecord+Private.swift b/test-suite/generated-src/swift/EmptyRecord+Private.swift index 24c4fd65..21b1297e 100644 --- a/test-suite/generated-src/swift/EmptyRecord+Private.swift +++ b/test-suite/generated-src/swift/EmptyRecord+Private.swift @@ -7,14 +7,14 @@ import Foundation import TestSuite import TestSuiteCxx -enum EmptyRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.EmptyRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum EmptyRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.EmptyRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in return SwiftType() } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return djinni.swift.makeCompositeValue() } } diff --git a/test-suite/generated-src/swift/EnumUsageInterface+Private.swift b/test-suite/generated-src/swift/EnumUsageInterface+Private.swift index df7bf877..04e3cb5a 100644 --- a/test-suite/generated-src/swift/EnumUsageInterface+Private.swift +++ b/test-suite/generated-src/swift/EnumUsageInterface+Private.swift @@ -10,52 +10,52 @@ import TestSuiteCxx final class EnumUsageInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.EnumUsageInterface { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func e(_ e: TestSuite.Color) throws -> TestSuite.Color { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(ColorMarshaller.toCpp(e)) - var ret = djinni_generated.EnumUsageInterface_e(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(ColorMarshaller.toCpp(e)) + var ret = djinni_generated.EnumUsageInterface_e(&_params) try handleCppErrors(&ret) return ColorMarshaller.fromCpp(ret) } func o(_ o: Optional) throws -> Optional { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(OptionalMarshaller.toCpp(o)) - var ret = djinni_generated.EnumUsageInterface_o(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(OptionalMarshaller.toCpp(o)) + var ret = djinni_generated.EnumUsageInterface_o(&_params) try handleCppErrors(&ret) return OptionalMarshaller.fromCpp(ret) } func l(_ l: Array) throws -> Array { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(ListMarshaller.toCpp(l)) - var ret = djinni_generated.EnumUsageInterface_l(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(ListMarshaller.toCpp(l)) + var ret = djinni_generated.EnumUsageInterface_l(&_params) try handleCppErrors(&ret) return ListMarshaller.fromCpp(ret) } func s(_ s: Set) throws -> Set { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(SetMarshaller.toCpp(s)) - var ret = djinni_generated.EnumUsageInterface_s(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(SetMarshaller.toCpp(s)) + var ret = djinni_generated.EnumUsageInterface_s(&_params) try handleCppErrors(&ret) return SetMarshaller.fromCpp(ret) } func m(_ m: Dictionary) throws -> Dictionary { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(MapMarshaller.toCpp(m)) - var ret = djinni_generated.EnumUsageInterface_m(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(MapMarshaller.toCpp(m)) + var ret = djinni_generated.EnumUsageInterface_m(&_params) try handleCppErrors(&ret) return MapMarshaller.fromCpp(ret) } } -enum EnumUsageInterfaceMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.EnumUsageInterface - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum EnumUsageInterfaceMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.EnumUsageInterface + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { EnumUsageInterfaceCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/EnumUsageRecord+Private.swift b/test-suite/generated-src/swift/EnumUsageRecord+Private.swift index fd7f34bd..61049fde 100644 --- a/test-suite/generated-src/swift/EnumUsageRecord+Private.swift +++ b/test-suite/generated-src/swift/EnumUsageRecord+Private.swift @@ -7,9 +7,9 @@ import Foundation import TestSuite import TestSuiteCxx -enum EnumUsageRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.EnumUsageRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum EnumUsageRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.EnumUsageRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let e = ColorMarshaller.fromCpp(djinni.swift.getMember(p, 0)) let o = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 1)) @@ -19,7 +19,7 @@ enum EnumUsageRecordMarshaller: DjinniSupport.Marshaller { return SwiftType(e: e, o: o, l: l, s: s, m: m) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, ColorMarshaller.toCpp(s.e)) djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.o)) diff --git a/test-suite/generated-src/swift/ExtendedRecord+Private.swift b/test-suite/generated-src/swift/ExtendedRecord+Private.swift index 6b68248f..e714141d 100644 --- a/test-suite/generated-src/swift/ExtendedRecord+Private.swift +++ b/test-suite/generated-src/swift/ExtendedRecord+Private.swift @@ -7,15 +7,15 @@ import Foundation import TestSuite import TestSuiteCxx -enum ExtendedRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ExtendedRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ExtendedRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ExtendedRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let foo = BoolMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(foo: foo) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, BoolMarshaller.toCpp(s.foo)) return ret diff --git a/test-suite/generated-src/swift/ExternInterface1+Private.swift b/test-suite/generated-src/swift/ExternInterface1+Private.swift index 25e743c7..df7401c6 100644 --- a/test-suite/generated-src/swift/ExternInterface1+Private.swift +++ b/test-suite/generated-src/swift/ExternInterface1+Private.swift @@ -9,29 +9,29 @@ import TestSuiteCxx final class ExternInterface1CppProxy: DjinniSupport.CppProxy, TestSuite.ExternInterface1 { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } - func foo(_ i: ClientInterface) throws -> ClientReturnedRecord { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(ClientInterfaceMarshaller.toCpp(i)) - var ret = djinni_generated.ExternInterface1_foo(¶ms) + func foo(_ i: TestSuite.ClientInterface) throws -> TestSuite.ClientReturnedRecord { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(TestSuite.ClientInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.ExternInterface1_foo(&_params) try handleCppErrors(&ret) - return ClientReturnedRecordMarshaller.fromCpp(ret) + return TestSuite.ClientReturnedRecordMarshaller.fromCpp(ret) } - func bar(_ e: Color) throws -> Color { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(ColorMarshaller.toCpp(e)) - var ret = djinni_generated.ExternInterface1_bar(¶ms) + func bar(_ e: TestSuite.Color) throws -> TestSuite.Color { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(TestSuite.ColorMarshaller.toCpp(e)) + var ret = djinni_generated.ExternInterface1_bar(&_params) try handleCppErrors(&ret) - return ColorMarshaller.fromCpp(ret) + return TestSuite.ColorMarshaller.fromCpp(ret) } } -enum ExternInterface1Marshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ExternInterface1 - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ExternInterface1Marshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ExternInterface1 + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { ExternInterface1CppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/ExternInterface1.swift b/test-suite/generated-src/swift/ExternInterface1.swift index 16f2a983..aa4bed10 100644 --- a/test-suite/generated-src/swift/ExternInterface1.swift +++ b/test-suite/generated-src/swift/ExternInterface1.swift @@ -4,6 +4,6 @@ import Foundation public protocol ExternInterface1: AnyObject { - func foo(_ i: ClientInterface) throws -> ClientReturnedRecord - func bar(_ e: Color) throws -> Color + func foo(_ i: TestSuite.ClientInterface) throws -> TestSuite.ClientReturnedRecord + func bar(_ e: TestSuite.Color) throws -> TestSuite.Color } diff --git a/test-suite/generated-src/swift/ExternInterface2+Private.swift b/test-suite/generated-src/swift/ExternInterface2+Private.swift index 073b61d7..41a35029 100644 --- a/test-suite/generated-src/swift/ExternInterface2+Private.swift +++ b/test-suite/generated-src/swift/ExternInterface2+Private.swift @@ -7,12 +7,12 @@ import Foundation import TestSuite import TestSuiteCxx -enum ExternInterface2Marshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ExternInterface2 - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ExternInterface2Marshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ExternInterface2 + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { fatalError("n/a") }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/ExternInterface2.swift b/test-suite/generated-src/swift/ExternInterface2.swift index 16aa9b5d..54098b6a 100644 --- a/test-suite/generated-src/swift/ExternInterface2.swift +++ b/test-suite/generated-src/swift/ExternInterface2.swift @@ -4,5 +4,5 @@ import Foundation public protocol ExternInterface2: AnyObject { - func foo(_ i: TestHelpers) throws -> TestSuite.ExternRecordWithDerivings + func foo(_ i: TestSuite.TestHelpers) throws -> TestSuite.ExternRecordWithDerivings } diff --git a/test-suite/generated-src/swift/ExternRecordWithDerivings+Private.swift b/test-suite/generated-src/swift/ExternRecordWithDerivings+Private.swift index 9a00f402..c31201a5 100644 --- a/test-suite/generated-src/swift/ExternRecordWithDerivings+Private.swift +++ b/test-suite/generated-src/swift/ExternRecordWithDerivings+Private.swift @@ -7,19 +7,19 @@ import Foundation import TestSuite import TestSuiteCxx -enum ExternRecordWithDerivingsMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ExternRecordWithDerivings - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ExternRecordWithDerivingsMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ExternRecordWithDerivings + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in - let member = RecordWithDerivingsMarshaller.fromCpp(djinni.swift.getMember(p, 0)) - let e = ColorMarshaller.fromCpp(djinni.swift.getMember(p, 1)) + let member = TestSuite.RecordWithDerivingsMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + let e = TestSuite.ColorMarshaller.fromCpp(djinni.swift.getMember(p, 1)) return SwiftType(member: member, e: e) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() - djinni.swift.addMember(&ret, RecordWithDerivingsMarshaller.toCpp(s.member)) - djinni.swift.addMember(&ret, ColorMarshaller.toCpp(s.e)) + djinni.swift.addMember(&ret, TestSuite.RecordWithDerivingsMarshaller.toCpp(s.member)) + djinni.swift.addMember(&ret, TestSuite.ColorMarshaller.toCpp(s.e)) return ret } } diff --git a/test-suite/generated-src/swift/ExternRecordWithDerivings.swift b/test-suite/generated-src/swift/ExternRecordWithDerivings.swift index 5c77ff81..07231672 100644 --- a/test-suite/generated-src/swift/ExternRecordWithDerivings.swift +++ b/test-suite/generated-src/swift/ExternRecordWithDerivings.swift @@ -5,10 +5,10 @@ import Foundation /** This file tests YAML dumped by Djinni can be parsed back in */ public struct ExternRecordWithDerivings: Equatable { - public var member: RecordWithDerivings - public var e: Color + public var member: TestSuite.RecordWithDerivings + public var e: TestSuite.Color - public init(member: RecordWithDerivings, e: Color) + public init(member: TestSuite.RecordWithDerivings, e: TestSuite.Color) { self.member = member self.e = e diff --git a/test-suite/generated-src/swift/FirstListener+Private.swift b/test-suite/generated-src/swift/FirstListener+Private.swift index 958fb54a..5148020b 100644 --- a/test-suite/generated-src/swift/FirstListener+Private.swift +++ b/test-suite/generated-src/swift/FirstListener+Private.swift @@ -8,12 +8,12 @@ import TestSuite import TestSuiteCxx /** Used for ObjC multiple inheritance tests */ -enum FirstListenerMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.FirstListener - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum FirstListenerMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.FirstListener + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { fatalError("n/a") }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/FlagRoundtrip+Private.swift b/test-suite/generated-src/swift/FlagRoundtrip+Private.swift index a74c69a7..c0d2c9d9 100644 --- a/test-suite/generated-src/swift/FlagRoundtrip+Private.swift +++ b/test-suite/generated-src/swift/FlagRoundtrip+Private.swift @@ -10,41 +10,41 @@ import TestSuiteCxx final class FlagRoundtripCppProxy: DjinniSupport.CppProxy, TestSuite.FlagRoundtrip { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } } -enum FlagRoundtripMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.FlagRoundtrip - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum FlagRoundtripMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.FlagRoundtrip + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { FlagRoundtripCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class FlagRoundtrip_statics { - static func roundtripAccess(_ flag: TestSuite.AccessFlags) throws -> TestSuite.AccessFlags { - var params = djinni.swift.ParameterList() - params.addValue(AccessFlagsMarshaller.toCpp(flag)) - var ret = djinni_generated.FlagRoundtrip_roundtripAccess(¶ms) + public static func roundtripAccess(_ flag: TestSuite.AccessFlags) throws -> TestSuite.AccessFlags { + var _params = djinni.swift.ParameterList() + _params.addValue(AccessFlagsMarshaller.toCpp(flag)) + var ret = djinni_generated.FlagRoundtrip_roundtripAccess(&_params) try handleCppErrors(&ret) return AccessFlagsMarshaller.fromCpp(ret) } - static func roundtripEmpty(_ flag: TestSuite.EmptyFlags) throws -> TestSuite.EmptyFlags { - var params = djinni.swift.ParameterList() - params.addValue(EmptyFlagsMarshaller.toCpp(flag)) - var ret = djinni_generated.FlagRoundtrip_roundtripEmpty(¶ms) + public static func roundtripEmpty(_ flag: TestSuite.EmptyFlags) throws -> TestSuite.EmptyFlags { + var _params = djinni.swift.ParameterList() + _params.addValue(EmptyFlagsMarshaller.toCpp(flag)) + var ret = djinni_generated.FlagRoundtrip_roundtripEmpty(&_params) try handleCppErrors(&ret) return EmptyFlagsMarshaller.fromCpp(ret) } - static func roundtripAccessBoxed(_ flag: Optional) throws -> Optional { - var params = djinni.swift.ParameterList() - params.addValue(OptionalMarshaller.toCpp(flag)) - var ret = djinni_generated.FlagRoundtrip_roundtripAccessBoxed(¶ms) + public static func roundtripAccessBoxed(_ flag: Optional) throws -> Optional { + var _params = djinni.swift.ParameterList() + _params.addValue(OptionalMarshaller.toCpp(flag)) + var ret = djinni_generated.FlagRoundtrip_roundtripAccessBoxed(&_params) try handleCppErrors(&ret) return OptionalMarshaller.fromCpp(ret) } - static func roundtripEmptyBoxed(_ flag: Optional) throws -> Optional { - var params = djinni.swift.ParameterList() - params.addValue(OptionalMarshaller.toCpp(flag)) - var ret = djinni_generated.FlagRoundtrip_roundtripEmptyBoxed(¶ms) + public static func roundtripEmptyBoxed(_ flag: Optional) throws -> Optional { + var _params = djinni.swift.ParameterList() + _params.addValue(OptionalMarshaller.toCpp(flag)) + var ret = djinni_generated.FlagRoundtrip_roundtripEmptyBoxed(&_params) try handleCppErrors(&ret) return OptionalMarshaller.fromCpp(ret) } diff --git a/test-suite/generated-src/swift/InterfaceUsingExtendedRecord+Private.swift b/test-suite/generated-src/swift/InterfaceUsingExtendedRecord+Private.swift index 5b7a99fd..7f402fce 100644 --- a/test-suite/generated-src/swift/InterfaceUsingExtendedRecord+Private.swift +++ b/test-suite/generated-src/swift/InterfaceUsingExtendedRecord+Private.swift @@ -10,20 +10,20 @@ import TestSuiteCxx final class InterfaceUsingExtendedRecordCppProxy: DjinniSupport.CppProxy, TestSuite.InterfaceUsingExtendedRecord { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func meth(_ er: TestSuite.ExtendedRecord) throws -> TestSuite.ExtendedRecord { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(ExtendedRecordMarshaller.toCpp(er)) - var ret = djinni_generated.InterfaceUsingExtendedRecord_meth(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(ExtendedRecordMarshaller.toCpp(er)) + var ret = djinni_generated.InterfaceUsingExtendedRecord_meth(&_params) try handleCppErrors(&ret) return ExtendedRecordMarshaller.fromCpp(ret) } } -enum InterfaceUsingExtendedRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.InterfaceUsingExtendedRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum InterfaceUsingExtendedRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.InterfaceUsingExtendedRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { InterfaceUsingExtendedRecordCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/JavaOnlyListener+Private.swift b/test-suite/generated-src/swift/JavaOnlyListener+Private.swift index 36734f2c..c0e8357a 100644 --- a/test-suite/generated-src/swift/JavaOnlyListener+Private.swift +++ b/test-suite/generated-src/swift/JavaOnlyListener+Private.swift @@ -7,12 +7,12 @@ import Foundation import TestSuite import TestSuiteCxx -enum JavaOnlyListenerMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.JavaOnlyListener - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum JavaOnlyListenerMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.JavaOnlyListener + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { fatalError("n/a") }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/ListenerCaller+Private.swift b/test-suite/generated-src/swift/ListenerCaller+Private.swift index b21aa98f..d07ce76d 100644 --- a/test-suite/generated-src/swift/ListenerCaller+Private.swift +++ b/test-suite/generated-src/swift/ListenerCaller+Private.swift @@ -16,33 +16,33 @@ import TestSuiteCxx final class ListenerCallerCppProxy: DjinniSupport.CppProxy, TestSuite.ListenerCaller { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func callFirst() throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.ListenerCaller_callFirst(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.ListenerCaller_callFirst(&_params) try handleCppErrors(&ret) } func callSecond() throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.ListenerCaller_callSecond(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.ListenerCaller_callSecond(&_params) try handleCppErrors(&ret) } } -enum ListenerCallerMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ListenerCaller - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ListenerCallerMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ListenerCaller + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { ListenerCallerCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class ListenerCaller_statics { - static func _init(_ firstL: TestSuite.FirstListener, secondL: TestSuite.SecondListener) throws -> TestSuite.ListenerCaller { - var params = djinni.swift.ParameterList() - params.addValue(FirstListenerMarshaller.toCpp(firstL)) - params.addValue(SecondListenerMarshaller.toCpp(secondL)) - var ret = djinni_generated.ListenerCaller_init(¶ms) + public static func _init(_ firstL: TestSuite.FirstListener, secondL: TestSuite.SecondListener) throws -> TestSuite.ListenerCaller { + var _params = djinni.swift.ParameterList() + _params.addValue(FirstListenerMarshaller.toCpp(firstL)) + _params.addValue(SecondListenerMarshaller.toCpp(secondL)) + var ret = djinni_generated.ListenerCaller_init(&_params) try handleCppErrors(&ret) return ListenerCallerMarshaller.fromCpp(ret) } diff --git a/test-suite/generated-src/swift/MapDateRecord+Private.swift b/test-suite/generated-src/swift/MapDateRecord+Private.swift index 2e26e5fd..3c0b083f 100644 --- a/test-suite/generated-src/swift/MapDateRecord+Private.swift +++ b/test-suite/generated-src/swift/MapDateRecord+Private.swift @@ -7,15 +7,15 @@ import Foundation import TestSuite import TestSuiteCxx -enum MapDateRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.MapDateRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum MapDateRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.MapDateRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let datesById = MapMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(datesById: datesById) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, MapMarshaller.toCpp(s.datesById)) return ret diff --git a/test-suite/generated-src/swift/MapDateRecord.swift b/test-suite/generated-src/swift/MapDateRecord.swift index d92c7e07..043dda69 100644 --- a/test-suite/generated-src/swift/MapDateRecord.swift +++ b/test-suite/generated-src/swift/MapDateRecord.swift @@ -1,7 +1,6 @@ // AUTOGENERATED FILE - DO NOT MODIFY! // This file was generated by Djinni from date.djinni -import DjinniSupport import Foundation public struct MapDateRecord { diff --git a/test-suite/generated-src/swift/MapListRecord+Private.swift b/test-suite/generated-src/swift/MapListRecord+Private.swift index 76d2dfc9..a025632e 100644 --- a/test-suite/generated-src/swift/MapListRecord+Private.swift +++ b/test-suite/generated-src/swift/MapListRecord+Private.swift @@ -7,15 +7,15 @@ import Foundation import TestSuite import TestSuiteCxx -enum MapListRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.MapListRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum MapListRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.MapListRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let mapList = ListMarshaller>.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(mapList: mapList) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, ListMarshaller>.toCpp(s.mapList)) return ret diff --git a/test-suite/generated-src/swift/MapRecord+Private.swift b/test-suite/generated-src/swift/MapRecord+Private.swift index 2ec9220e..06c4e566 100644 --- a/test-suite/generated-src/swift/MapRecord+Private.swift +++ b/test-suite/generated-src/swift/MapRecord+Private.swift @@ -7,16 +7,16 @@ import Foundation import TestSuite import TestSuiteCxx -enum MapRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.MapRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum MapRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.MapRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let map = MapMarshaller.fromCpp(djinni.swift.getMember(p, 0)) let imap = MapMarshaller.fromCpp(djinni.swift.getMember(p, 1)) return SwiftType(map: map, imap: imap) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, MapMarshaller.toCpp(s.map)) djinni.swift.addMember(&ret, MapMarshaller.toCpp(s.imap)) diff --git a/test-suite/generated-src/swift/NestedCollection+Private.swift b/test-suite/generated-src/swift/NestedCollection+Private.swift index f8ad387a..6d65cb51 100644 --- a/test-suite/generated-src/swift/NestedCollection+Private.swift +++ b/test-suite/generated-src/swift/NestedCollection+Private.swift @@ -7,15 +7,15 @@ import Foundation import TestSuite import TestSuiteCxx -enum NestedCollectionMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.NestedCollection - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum NestedCollectionMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.NestedCollection + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let setList = ListMarshaller>.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(setList: setList) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, ListMarshaller>.toCpp(s.setList)) return ret diff --git a/test-suite/generated-src/swift/NestedOutcome+Private.swift b/test-suite/generated-src/swift/NestedOutcome+Private.swift index 13ce4e5d..c946149d 100644 --- a/test-suite/generated-src/swift/NestedOutcome+Private.swift +++ b/test-suite/generated-src/swift/NestedOutcome+Private.swift @@ -7,17 +7,17 @@ import Foundation import TestSuite import TestSuiteCxx -enum NestedOutcomeMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.NestedOutcome - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum NestedOutcomeMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.NestedOutcome + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in - let o = OutcomeMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + let o = DjinniSupport.OutcomeMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(o: o) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() - djinni.swift.addMember(&ret, OutcomeMarshaller.toCpp(s.o)) + djinni.swift.addMember(&ret, DjinniSupport.OutcomeMarshaller.toCpp(s.o)) return ret } } diff --git a/test-suite/generated-src/swift/ObjcOnlyListener+Private.swift b/test-suite/generated-src/swift/ObjcOnlyListener+Private.swift index e6de364d..431dc77c 100644 --- a/test-suite/generated-src/swift/ObjcOnlyListener+Private.swift +++ b/test-suite/generated-src/swift/ObjcOnlyListener+Private.swift @@ -7,12 +7,12 @@ import Foundation import TestSuite import TestSuiteCxx -enum ObjcOnlyListenerMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ObjcOnlyListener - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ObjcOnlyListenerMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ObjcOnlyListener + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { fatalError("n/a") }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/PrimitiveList+Private.swift b/test-suite/generated-src/swift/PrimitiveList+Private.swift index ac7ae449..7dfd79f6 100644 --- a/test-suite/generated-src/swift/PrimitiveList+Private.swift +++ b/test-suite/generated-src/swift/PrimitiveList+Private.swift @@ -7,15 +7,15 @@ import Foundation import TestSuite import TestSuiteCxx -enum PrimitiveListMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.PrimitiveList - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum PrimitiveListMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.PrimitiveList + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let list = ListMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(list: list) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, ListMarshaller.toCpp(s.list)) return ret diff --git a/test-suite/generated-src/swift/ProtoTests+Private.swift b/test-suite/generated-src/swift/ProtoTests+Private.swift index c31529b0..2c40543a 100644 --- a/test-suite/generated-src/swift/ProtoTests+Private.swift +++ b/test-suite/generated-src/swift/ProtoTests+Private.swift @@ -11,105 +11,105 @@ import TestSuiteCxx final class ProtoTestsCppProxy: DjinniSupport.CppProxy, TestSuite.ProtoTests { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } } -enum ProtoTestsMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ProtoTests - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ProtoTestsMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ProtoTests + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { ProtoTestsCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class ProtoTests_statics { - static func protoToStrings(_ x: Djinni_Test_AddressBook) throws -> Array { - var params = djinni.swift.ParameterList() - params.addValue(ProtobufMarshaller.toCpp(x)) - var ret = djinni_generated.ProtoTests_protoToStrings(¶ms) + public static func protoToStrings(_ x: Djinni_Test_AddressBook) throws -> Array { + var _params = djinni.swift.ParameterList() + _params.addValue(ProtobufMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_protoToStrings(&_params) try handleCppErrors(&ret) return ListMarshaller.fromCpp(ret) } - static func stringsToProto(_ x: Array) throws -> Djinni_Test_AddressBook { - var params = djinni.swift.ParameterList() - params.addValue(ListMarshaller.toCpp(x)) - var ret = djinni_generated.ProtoTests_stringsToProto(¶ms) + public static func stringsToProto(_ x: Array) throws -> Djinni_Test_AddressBook { + var _params = djinni.swift.ParameterList() + _params.addValue(ListMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringsToProto(&_params) try handleCppErrors(&ret) return ProtobufMarshaller.fromCpp(ret) } - static func embeddedProtoToString(_ x: TestSuite.RecordWithEmbeddedProto) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(RecordWithEmbeddedProtoMarshaller.toCpp(x)) - var ret = djinni_generated.ProtoTests_embeddedProtoToString(¶ms) + public static func embeddedProtoToString(_ x: TestSuite.RecordWithEmbeddedProto) throws -> String { + var _params = djinni.swift.ParameterList() + _params.addValue(RecordWithEmbeddedProtoMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_embeddedProtoToString(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func stringToEmbeddedProto(_ x: String) throws -> TestSuite.RecordWithEmbeddedProto { - var params = djinni.swift.ParameterList() - params.addValue(StringMarshaller.toCpp(x)) - var ret = djinni_generated.ProtoTests_stringToEmbeddedProto(¶ms) + public static func stringToEmbeddedProto(_ x: String) throws -> TestSuite.RecordWithEmbeddedProto { + var _params = djinni.swift.ParameterList() + _params.addValue(StringMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringToEmbeddedProto(&_params) try handleCppErrors(&ret) return RecordWithEmbeddedProtoMarshaller.fromCpp(ret) } - static func cppProtoToString(_ x: Djinni_Test2_PersistingState) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(ProtobufMarshaller.toCpp(x)) - var ret = djinni_generated.ProtoTests_cppProtoToString(¶ms) + public static func cppProtoToString(_ x: Djinni_Test2_PersistingState) throws -> String { + var _params = djinni.swift.ParameterList() + _params.addValue(ProtobufMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_cppProtoToString(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func stringToCppProto(_ x: String) throws -> Djinni_Test2_PersistingState { - var params = djinni.swift.ParameterList() - params.addValue(StringMarshaller.toCpp(x)) - var ret = djinni_generated.ProtoTests_stringToCppProto(¶ms) + public static func stringToCppProto(_ x: String) throws -> Djinni_Test2_PersistingState { + var _params = djinni.swift.ParameterList() + _params.addValue(StringMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringToCppProto(&_params) try handleCppErrors(&ret) return ProtobufMarshaller.fromCpp(ret) } - static func embeddedCppProtoToString(_ x: TestSuite.RecordWithEmbeddedCppProto) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(RecordWithEmbeddedCppProtoMarshaller.toCpp(x)) - var ret = djinni_generated.ProtoTests_embeddedCppProtoToString(¶ms) + public static func embeddedCppProtoToString(_ x: TestSuite.RecordWithEmbeddedCppProto) throws -> String { + var _params = djinni.swift.ParameterList() + _params.addValue(RecordWithEmbeddedCppProtoMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_embeddedCppProtoToString(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func stringToEmbeddedCppProto(_ x: String) throws -> TestSuite.RecordWithEmbeddedCppProto { - var params = djinni.swift.ParameterList() - params.addValue(StringMarshaller.toCpp(x)) - var ret = djinni_generated.ProtoTests_stringToEmbeddedCppProto(¶ms) + public static func stringToEmbeddedCppProto(_ x: String) throws -> TestSuite.RecordWithEmbeddedCppProto { + var _params = djinni.swift.ParameterList() + _params.addValue(StringMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringToEmbeddedCppProto(&_params) try handleCppErrors(&ret) return RecordWithEmbeddedCppProtoMarshaller.fromCpp(ret) } - static func protoListToStrings(_ x: Array) throws -> Array { - var params = djinni.swift.ParameterList() - params.addValue(ListMarshaller>.toCpp(x)) - var ret = djinni_generated.ProtoTests_protoListToStrings(¶ms) + public static func protoListToStrings(_ x: Array) throws -> Array { + var _params = djinni.swift.ParameterList() + _params.addValue(ListMarshaller>.toCpp(x)) + var ret = djinni_generated.ProtoTests_protoListToStrings(&_params) try handleCppErrors(&ret) return ListMarshaller.fromCpp(ret) } - static func stringsToProtoList(_ x: Array) throws -> Array { - var params = djinni.swift.ParameterList() - params.addValue(ListMarshaller.toCpp(x)) - var ret = djinni_generated.ProtoTests_stringsToProtoList(¶ms) + public static func stringsToProtoList(_ x: Array) throws -> Array { + var _params = djinni.swift.ParameterList() + _params.addValue(ListMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringsToProtoList(&_params) try handleCppErrors(&ret) return ListMarshaller>.fromCpp(ret) } - static func optionalProtoToString(_ x: Optional) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(OptionalMarshaller>.toCpp(x)) - var ret = djinni_generated.ProtoTests_optionalProtoToString(¶ms) + public static func optionalProtoToString(_ x: Optional) throws -> String { + var _params = djinni.swift.ParameterList() + _params.addValue(OptionalMarshaller>.toCpp(x)) + var ret = djinni_generated.ProtoTests_optionalProtoToString(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func stringToOptionalProto(_ x: String) throws -> Optional { - var params = djinni.swift.ParameterList() - params.addValue(StringMarshaller.toCpp(x)) - var ret = djinni_generated.ProtoTests_stringToOptionalProto(¶ms) + public static func stringToOptionalProto(_ x: String) throws -> Optional { + var _params = djinni.swift.ParameterList() + _params.addValue(StringMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringToOptionalProto(&_params) try handleCppErrors(&ret) return OptionalMarshaller>.fromCpp(ret) } - static func stringToProtoOutcome(_ x: String) throws -> Result { - var params = djinni.swift.ParameterList() - params.addValue(StringMarshaller.toCpp(x)) - var ret = djinni_generated.ProtoTests_stringToProtoOutcome(¶ms) + public static func stringToProtoOutcome(_ x: String) throws -> Result { + var _params = djinni.swift.ParameterList() + _params.addValue(StringMarshaller.toCpp(x)) + var ret = djinni_generated.ProtoTests_stringToProtoOutcome(&_params) try handleCppErrors(&ret) - return OutcomeMarshaller, I32Marshaller>.fromCpp(ret) + return DjinniSupport.OutcomeMarshaller, I32Marshaller>.fromCpp(ret) } } diff --git a/test-suite/generated-src/swift/RecordUsingExtendedRecord+Private.swift b/test-suite/generated-src/swift/RecordUsingExtendedRecord+Private.swift index a8fdedfd..2ca84baa 100644 --- a/test-suite/generated-src/swift/RecordUsingExtendedRecord+Private.swift +++ b/test-suite/generated-src/swift/RecordUsingExtendedRecord+Private.swift @@ -7,15 +7,15 @@ import Foundation import TestSuite import TestSuiteCxx -enum RecordUsingExtendedRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.RecordUsingExtendedRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum RecordUsingExtendedRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.RecordUsingExtendedRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let er = ExtendedRecordMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(er: er) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, ExtendedRecordMarshaller.toCpp(s.er)) return ret diff --git a/test-suite/generated-src/swift/RecordWithDerivings+Private.swift b/test-suite/generated-src/swift/RecordWithDerivings+Private.swift index d9fbbd89..5d77e861 100644 --- a/test-suite/generated-src/swift/RecordWithDerivings+Private.swift +++ b/test-suite/generated-src/swift/RecordWithDerivings+Private.swift @@ -7,9 +7,9 @@ import Foundation import TestSuite import TestSuiteCxx -enum RecordWithDerivingsMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.RecordWithDerivings - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum RecordWithDerivingsMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.RecordWithDerivings + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let eight = I8Marshaller.fromCpp(djinni.swift.getMember(p, 0)) let sixteen = I16Marshaller.fromCpp(djinni.swift.getMember(p, 1)) @@ -22,7 +22,7 @@ enum RecordWithDerivingsMarshaller: DjinniSupport.Marshaller { return SwiftType(eight: eight, sixteen: sixteen, thirtytwo: thirtytwo, sixtyfour: sixtyfour, fthirtytwo: fthirtytwo, fsixtyfour: fsixtyfour, d: d, s: s) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, I8Marshaller.toCpp(s.eight)) djinni.swift.addMember(&ret, I16Marshaller.toCpp(s.sixteen)) diff --git a/test-suite/generated-src/swift/RecordWithDurationAndDerivings+Private.swift b/test-suite/generated-src/swift/RecordWithDurationAndDerivings+Private.swift index 149a8ae2..8b328d9f 100644 --- a/test-suite/generated-src/swift/RecordWithDurationAndDerivings+Private.swift +++ b/test-suite/generated-src/swift/RecordWithDurationAndDerivings+Private.swift @@ -7,17 +7,17 @@ import Foundation import TestSuite import TestSuiteCxx -enum RecordWithDurationAndDerivingsMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.RecordWithDurationAndDerivings - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum RecordWithDurationAndDerivingsMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.RecordWithDurationAndDerivings + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in - let dt = DurationMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + let dt = TestSuite.DurationMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(dt: dt) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() - djinni.swift.addMember(&ret, DurationMarshaller.toCpp(s.dt)) + djinni.swift.addMember(&ret, TestSuite.DurationMarshaller.toCpp(s.dt)) return ret } } diff --git a/test-suite/generated-src/swift/RecordWithEmbeddedCppProto+Private.swift b/test-suite/generated-src/swift/RecordWithEmbeddedCppProto+Private.swift index b4ebe851..c39aa40d 100644 --- a/test-suite/generated-src/swift/RecordWithEmbeddedCppProto+Private.swift +++ b/test-suite/generated-src/swift/RecordWithEmbeddedCppProto+Private.swift @@ -8,15 +8,15 @@ import ProtobufTest import TestSuite import TestSuiteCxx -enum RecordWithEmbeddedCppProtoMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.RecordWithEmbeddedCppProto - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum RecordWithEmbeddedCppProtoMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.RecordWithEmbeddedCppProto + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let state = ProtobufMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(state: state) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, ProtobufMarshaller.toCpp(s.state)) return ret diff --git a/test-suite/generated-src/swift/RecordWithEmbeddedProto+Private.swift b/test-suite/generated-src/swift/RecordWithEmbeddedProto+Private.swift index 0409625d..56bddf95 100644 --- a/test-suite/generated-src/swift/RecordWithEmbeddedProto+Private.swift +++ b/test-suite/generated-src/swift/RecordWithEmbeddedProto+Private.swift @@ -8,15 +8,15 @@ import ProtobufTest import TestSuite import TestSuiteCxx -enum RecordWithEmbeddedProtoMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.RecordWithEmbeddedProto - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum RecordWithEmbeddedProtoMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.RecordWithEmbeddedProto + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let person = ProtobufMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(person: person) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, ProtobufMarshaller.toCpp(s.person)) return ret diff --git a/test-suite/generated-src/swift/RecordWithFlags+Private.swift b/test-suite/generated-src/swift/RecordWithFlags+Private.swift index 7f507716..f27754e7 100644 --- a/test-suite/generated-src/swift/RecordWithFlags+Private.swift +++ b/test-suite/generated-src/swift/RecordWithFlags+Private.swift @@ -7,15 +7,15 @@ import Foundation import TestSuite import TestSuiteCxx -enum RecordWithFlagsMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.RecordWithFlags - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum RecordWithFlagsMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.RecordWithFlags + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let access = AccessFlagsMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(access: access) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, AccessFlagsMarshaller.toCpp(s.access)) return ret diff --git a/test-suite/generated-src/swift/RecordWithNestedDerivings+Private.swift b/test-suite/generated-src/swift/RecordWithNestedDerivings+Private.swift index 8d3a46a3..a2f921fd 100644 --- a/test-suite/generated-src/swift/RecordWithNestedDerivings+Private.swift +++ b/test-suite/generated-src/swift/RecordWithNestedDerivings+Private.swift @@ -7,16 +7,16 @@ import Foundation import TestSuite import TestSuiteCxx -enum RecordWithNestedDerivingsMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.RecordWithNestedDerivings - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum RecordWithNestedDerivingsMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.RecordWithNestedDerivings + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let key = I32Marshaller.fromCpp(djinni.swift.getMember(p, 0)) let rec = RecordWithDerivingsMarshaller.fromCpp(djinni.swift.getMember(p, 1)) return SwiftType(key: key, rec: rec) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, I32Marshaller.toCpp(s.key)) djinni.swift.addMember(&ret, RecordWithDerivingsMarshaller.toCpp(s.rec)) diff --git a/test-suite/generated-src/swift/ReturnOne+Private.swift b/test-suite/generated-src/swift/ReturnOne+Private.swift index bf26cd44..6f69316d 100644 --- a/test-suite/generated-src/swift/ReturnOne+Private.swift +++ b/test-suite/generated-src/swift/ReturnOne+Private.swift @@ -11,26 +11,26 @@ import TestSuiteCxx final class ReturnOneCppProxy: DjinniSupport.CppProxy, TestSuite.ReturnOne { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func returnOne() throws -> Int8 { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.ReturnOne_returnOne(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.ReturnOne_returnOne(&_params) try handleCppErrors(&ret) return I8Marshaller.fromCpp(ret) } } -enum ReturnOneMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ReturnOne - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ReturnOneMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ReturnOne + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { ReturnOneCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class ReturnOne_statics { - static func getInstance() throws -> TestSuite.ReturnOne { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.ReturnOne_getInstance(¶ms) + public static func getInstance() throws -> TestSuite.ReturnOne { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.ReturnOne_getInstance(&_params) try handleCppErrors(&ret) return ReturnOneMarshaller.fromCpp(ret) } diff --git a/test-suite/generated-src/swift/ReturnTwo+Private.swift b/test-suite/generated-src/swift/ReturnTwo+Private.swift index 06fbf133..1040aa68 100644 --- a/test-suite/generated-src/swift/ReturnTwo+Private.swift +++ b/test-suite/generated-src/swift/ReturnTwo+Private.swift @@ -11,26 +11,26 @@ import TestSuiteCxx final class ReturnTwoCppProxy: DjinniSupport.CppProxy, TestSuite.ReturnTwo { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func returnTwo() throws -> Int8 { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.ReturnTwo_returnTwo(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.ReturnTwo_returnTwo(&_params) try handleCppErrors(&ret) return I8Marshaller.fromCpp(ret) } } -enum ReturnTwoMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ReturnTwo - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ReturnTwoMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ReturnTwo + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { ReturnTwoCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class ReturnTwo_statics { - static func getInstance() throws -> TestSuite.ReturnTwo { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.ReturnTwo_getInstance(¶ms) + public static func getInstance() throws -> TestSuite.ReturnTwo { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.ReturnTwo_getInstance(&_params) try handleCppErrors(&ret) return ReturnTwoMarshaller.fromCpp(ret) } diff --git a/test-suite/generated-src/swift/ReverseClientInterface+Private.swift b/test-suite/generated-src/swift/ReverseClientInterface+Private.swift index 90e74b99..9f24d723 100644 --- a/test-suite/generated-src/swift/ReverseClientInterface+Private.swift +++ b/test-suite/generated-src/swift/ReverseClientInterface+Private.swift @@ -10,42 +10,42 @@ import TestSuiteCxx final class ReverseClientInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.ReverseClientInterface { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func returnStr() throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.ReverseClientInterface_returnStr(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.ReverseClientInterface_returnStr(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } func methTakingInterface(_ i: TestSuite.ReverseClientInterface) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(ReverseClientInterfaceMarshaller.toCpp(i)) - var ret = djinni_generated.ReverseClientInterface_methTakingInterface(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(ReverseClientInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.ReverseClientInterface_methTakingInterface(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } func methTakingOptionalInterface(_ i: Optional) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(OptionalMarshaller.toCpp(i)) - var ret = djinni_generated.ReverseClientInterface_methTakingOptionalInterface(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(OptionalMarshaller.toCpp(i)) + var ret = djinni_generated.ReverseClientInterface_methTakingOptionalInterface(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } } -enum ReverseClientInterfaceMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ReverseClientInterface - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ReverseClientInterfaceMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ReverseClientInterface + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { ReverseClientInterfaceCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class ReverseClientInterface_statics { - static func create() throws -> TestSuite.ReverseClientInterface { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.ReverseClientInterface_create(¶ms) + public static func create() throws -> TestSuite.ReverseClientInterface { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.ReverseClientInterface_create(&_params) try handleCppErrors(&ret) return ReverseClientInterfaceMarshaller.fromCpp(ret) } diff --git a/test-suite/generated-src/swift/SampleInterface+Private.swift b/test-suite/generated-src/swift/SampleInterface+Private.swift index 11f2bfe4..7a215df5 100644 --- a/test-suite/generated-src/swift/SampleInterface+Private.swift +++ b/test-suite/generated-src/swift/SampleInterface+Private.swift @@ -14,12 +14,12 @@ import TestSuiteCxx final class SampleInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.SampleInterface { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } } -enum SampleInterfaceMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.SampleInterface - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum SampleInterfaceMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.SampleInterface + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { SampleInterfaceCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/SecondListener+Private.swift b/test-suite/generated-src/swift/SecondListener+Private.swift index be010122..4969555d 100644 --- a/test-suite/generated-src/swift/SecondListener+Private.swift +++ b/test-suite/generated-src/swift/SecondListener+Private.swift @@ -8,12 +8,12 @@ import TestSuite import TestSuiteCxx /** Used for ObjC multiple inheritance tests */ -enum SecondListenerMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.SecondListener - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum SecondListenerMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.SecondListener + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { fatalError("n/a") }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/SetRecord+Private.swift b/test-suite/generated-src/swift/SetRecord+Private.swift index 68f19674..41e002f2 100644 --- a/test-suite/generated-src/swift/SetRecord+Private.swift +++ b/test-suite/generated-src/swift/SetRecord+Private.swift @@ -7,16 +7,16 @@ import Foundation import TestSuite import TestSuiteCxx -enum SetRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.SetRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum SetRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.SetRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let set = SetMarshaller.fromCpp(djinni.swift.getMember(p, 0)) let iset = SetMarshaller.fromCpp(djinni.swift.getMember(p, 1)) return SwiftType(set: set, iset: iset) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, SetMarshaller.toCpp(s.set)) djinni.swift.addMember(&ret, SetMarshaller.toCpp(s.iset)) diff --git a/test-suite/generated-src/swift/SupportCopying+Private.swift b/test-suite/generated-src/swift/SupportCopying+Private.swift index 6dd09de5..2699d1c3 100644 --- a/test-suite/generated-src/swift/SupportCopying+Private.swift +++ b/test-suite/generated-src/swift/SupportCopying+Private.swift @@ -7,15 +7,15 @@ import Foundation import TestSuite import TestSuiteCxx -enum SupportCopyingMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.SupportCopying - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum SupportCopyingMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.SupportCopying + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let x = I32Marshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(x: x) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, I32Marshaller.toCpp(s.x)) return ret diff --git a/test-suite/generated-src/swift/TestArray+Private.swift b/test-suite/generated-src/swift/TestArray+Private.swift index 509d63f8..99cde923 100644 --- a/test-suite/generated-src/swift/TestArray+Private.swift +++ b/test-suite/generated-src/swift/TestArray+Private.swift @@ -10,41 +10,41 @@ import TestSuiteCxx final class TestArrayCppProxy: DjinniSupport.CppProxy, TestSuite.TestArray { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } } -enum TestArrayMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.TestArray - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum TestArrayMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.TestArray + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { TestArrayCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class TestArray_statics { - static func testStringArray(_ a: Array) throws -> Array { - var params = djinni.swift.ParameterList() - params.addValue(ArrayMarshaller.toCpp(a)) - var ret = djinni_generated.TestArray_testStringArray(¶ms) + public static func testStringArray(_ a: Array) throws -> Array { + var _params = djinni.swift.ParameterList() + _params.addValue(ArrayMarshaller.toCpp(a)) + var ret = djinni_generated.TestArray_testStringArray(&_params) try handleCppErrors(&ret) return ArrayMarshaller.fromCpp(ret) } - static func testIntArray(_ a: Array) throws -> Array { - var params = djinni.swift.ParameterList() - params.addValue(ArrayMarshaller.toCpp(a)) - var ret = djinni_generated.TestArray_testIntArray(¶ms) + public static func testIntArray(_ a: Array) throws -> Array { + var _params = djinni.swift.ParameterList() + _params.addValue(ArrayMarshaller.toCpp(a)) + var ret = djinni_generated.TestArray_testIntArray(&_params) try handleCppErrors(&ret) return ArrayMarshaller.fromCpp(ret) } - static func testRecordArray(_ a: Array) throws -> Array { - var params = djinni.swift.ParameterList() - params.addValue(ArrayMarshaller.toCpp(a)) - var ret = djinni_generated.TestArray_testRecordArray(¶ms) + public static func testRecordArray(_ a: Array) throws -> Array { + var _params = djinni.swift.ParameterList() + _params.addValue(ArrayMarshaller.toCpp(a)) + var ret = djinni_generated.TestArray_testRecordArray(&_params) try handleCppErrors(&ret) return ArrayMarshaller.fromCpp(ret) } - static func testArrayOfArray(_ a: Array>) throws -> Array> { - var params = djinni.swift.ParameterList() - params.addValue(ArrayMarshaller>.toCpp(a)) - var ret = djinni_generated.TestArray_testArrayOfArray(¶ms) + public static func testArrayOfArray(_ a: Array>) throws -> Array> { + var _params = djinni.swift.ParameterList() + _params.addValue(ArrayMarshaller>.toCpp(a)) + var ret = djinni_generated.TestArray_testArrayOfArray(&_params) try handleCppErrors(&ret) return ArrayMarshaller>.fromCpp(ret) } diff --git a/test-suite/generated-src/swift/TestDuration+Private.swift b/test-suite/generated-src/swift/TestDuration+Private.swift index 55ae27f9..91aeb8ce 100644 --- a/test-suite/generated-src/swift/TestDuration+Private.swift +++ b/test-suite/generated-src/swift/TestDuration+Private.swift @@ -10,153 +10,153 @@ import TestSuiteCxx final class TestDurationCppProxy: DjinniSupport.CppProxy, TestSuite.TestDuration { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } } -enum TestDurationMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.TestDuration - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum TestDurationMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.TestDuration + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { TestDurationCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class TestDuration_statics { - static func hoursString(_ dt: Duration) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(DurationMarshaller.toCpp(dt)) - var ret = djinni_generated.TestDuration_hoursString(¶ms) + public static func hoursString(_ dt: Duration) throws -> String { + var _params = djinni.swift.ParameterList() + _params.addValue(TestSuite.DurationMarshaller.toCpp(dt)) + var ret = djinni_generated.TestDuration_hoursString(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func minutesString(_ dt: Duration) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(DurationMarshaller.toCpp(dt)) - var ret = djinni_generated.TestDuration_minutesString(¶ms) + public static func minutesString(_ dt: Duration) throws -> String { + var _params = djinni.swift.ParameterList() + _params.addValue(TestSuite.DurationMarshaller.toCpp(dt)) + var ret = djinni_generated.TestDuration_minutesString(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func secondsString(_ dt: Duration) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(DurationMarshaller.toCpp(dt)) - var ret = djinni_generated.TestDuration_secondsString(¶ms) + public static func secondsString(_ dt: Duration) throws -> String { + var _params = djinni.swift.ParameterList() + _params.addValue(TestSuite.DurationMarshaller.toCpp(dt)) + var ret = djinni_generated.TestDuration_secondsString(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func millisString(_ dt: Duration) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(DurationMarshaller.toCpp(dt)) - var ret = djinni_generated.TestDuration_millisString(¶ms) + public static func millisString(_ dt: Duration) throws -> String { + var _params = djinni.swift.ParameterList() + _params.addValue(TestSuite.DurationMarshaller.toCpp(dt)) + var ret = djinni_generated.TestDuration_millisString(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func microsString(_ dt: Duration) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(DurationMarshaller.toCpp(dt)) - var ret = djinni_generated.TestDuration_microsString(¶ms) + public static func microsString(_ dt: Duration) throws -> String { + var _params = djinni.swift.ParameterList() + _params.addValue(TestSuite.DurationMarshaller.toCpp(dt)) + var ret = djinni_generated.TestDuration_microsString(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func nanosString(_ dt: Duration) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(DurationMarshaller.toCpp(dt)) - var ret = djinni_generated.TestDuration_nanosString(¶ms) + public static func nanosString(_ dt: Duration) throws -> String { + var _params = djinni.swift.ParameterList() + _params.addValue(TestSuite.DurationMarshaller.toCpp(dt)) + var ret = djinni_generated.TestDuration_nanosString(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func hours(_ count: Int32) throws -> Duration { - var params = djinni.swift.ParameterList() - params.addValue(I32Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_hours(¶ms) + public static func hours(_ count: Int32) throws -> Duration { + var _params = djinni.swift.ParameterList() + _params.addValue(I32Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_hours(&_params) try handleCppErrors(&ret) - return DurationMarshaller.fromCpp(ret) + return TestSuite.DurationMarshaller.fromCpp(ret) } - static func minutes(_ count: Int32) throws -> Duration { - var params = djinni.swift.ParameterList() - params.addValue(I32Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_minutes(¶ms) + public static func minutes(_ count: Int32) throws -> Duration { + var _params = djinni.swift.ParameterList() + _params.addValue(I32Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_minutes(&_params) try handleCppErrors(&ret) - return DurationMarshaller.fromCpp(ret) + return TestSuite.DurationMarshaller.fromCpp(ret) } - static func seconds(_ count: Int32) throws -> Duration { - var params = djinni.swift.ParameterList() - params.addValue(I32Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_seconds(¶ms) + public static func seconds(_ count: Int32) throws -> Duration { + var _params = djinni.swift.ParameterList() + _params.addValue(I32Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_seconds(&_params) try handleCppErrors(&ret) - return DurationMarshaller.fromCpp(ret) + return TestSuite.DurationMarshaller.fromCpp(ret) } - static func millis(_ count: Int32) throws -> Duration { - var params = djinni.swift.ParameterList() - params.addValue(I32Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_millis(¶ms) + public static func millis(_ count: Int32) throws -> Duration { + var _params = djinni.swift.ParameterList() + _params.addValue(I32Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_millis(&_params) try handleCppErrors(&ret) - return DurationMarshaller.fromCpp(ret) + return TestSuite.DurationMarshaller.fromCpp(ret) } - static func micros(_ count: Int32) throws -> Duration { - var params = djinni.swift.ParameterList() - params.addValue(I32Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_micros(¶ms) + public static func micros(_ count: Int32) throws -> Duration { + var _params = djinni.swift.ParameterList() + _params.addValue(I32Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_micros(&_params) try handleCppErrors(&ret) - return DurationMarshaller.fromCpp(ret) + return TestSuite.DurationMarshaller.fromCpp(ret) } - static func nanos(_ count: Int32) throws -> Duration { - var params = djinni.swift.ParameterList() - params.addValue(I32Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_nanos(¶ms) + public static func nanos(_ count: Int32) throws -> Duration { + var _params = djinni.swift.ParameterList() + _params.addValue(I32Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_nanos(&_params) try handleCppErrors(&ret) - return DurationMarshaller.fromCpp(ret) + return TestSuite.DurationMarshaller.fromCpp(ret) } - static func hoursf(_ count: Double) throws -> Duration { - var params = djinni.swift.ParameterList() - params.addValue(F64Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_hoursf(¶ms) + public static func hoursf(_ count: Double) throws -> Duration { + var _params = djinni.swift.ParameterList() + _params.addValue(F64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_hoursf(&_params) try handleCppErrors(&ret) - return DurationMarshaller.fromCpp(ret) + return TestSuite.DurationMarshaller.fromCpp(ret) } - static func minutesf(_ count: Double) throws -> Duration { - var params = djinni.swift.ParameterList() - params.addValue(F64Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_minutesf(¶ms) + public static func minutesf(_ count: Double) throws -> Duration { + var _params = djinni.swift.ParameterList() + _params.addValue(F64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_minutesf(&_params) try handleCppErrors(&ret) - return DurationMarshaller.fromCpp(ret) + return TestSuite.DurationMarshaller.fromCpp(ret) } - static func secondsf(_ count: Double) throws -> Duration { - var params = djinni.swift.ParameterList() - params.addValue(F64Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_secondsf(¶ms) + public static func secondsf(_ count: Double) throws -> Duration { + var _params = djinni.swift.ParameterList() + _params.addValue(F64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_secondsf(&_params) try handleCppErrors(&ret) - return DurationMarshaller.fromCpp(ret) + return TestSuite.DurationMarshaller.fromCpp(ret) } - static func millisf(_ count: Double) throws -> Duration { - var params = djinni.swift.ParameterList() - params.addValue(F64Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_millisf(¶ms) + public static func millisf(_ count: Double) throws -> Duration { + var _params = djinni.swift.ParameterList() + _params.addValue(F64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_millisf(&_params) try handleCppErrors(&ret) - return DurationMarshaller.fromCpp(ret) + return TestSuite.DurationMarshaller.fromCpp(ret) } - static func microsf(_ count: Double) throws -> Duration { - var params = djinni.swift.ParameterList() - params.addValue(F64Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_microsf(¶ms) + public static func microsf(_ count: Double) throws -> Duration { + var _params = djinni.swift.ParameterList() + _params.addValue(F64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_microsf(&_params) try handleCppErrors(&ret) - return DurationMarshaller.fromCpp(ret) + return TestSuite.DurationMarshaller.fromCpp(ret) } - static func nanosf(_ count: Double) throws -> Duration { - var params = djinni.swift.ParameterList() - params.addValue(F64Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_nanosf(¶ms) + public static func nanosf(_ count: Double) throws -> Duration { + var _params = djinni.swift.ParameterList() + _params.addValue(F64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_nanosf(&_params) try handleCppErrors(&ret) - return DurationMarshaller.fromCpp(ret) + return TestSuite.DurationMarshaller.fromCpp(ret) } - static func box(_ count: Int64) throws -> Optional { - var params = djinni.swift.ParameterList() - params.addValue(I64Marshaller.toCpp(count)) - var ret = djinni_generated.TestDuration_box(¶ms) + public static func box(_ count: Int64) throws -> Optional { + var _params = djinni.swift.ParameterList() + _params.addValue(I64Marshaller.toCpp(count)) + var ret = djinni_generated.TestDuration_box(&_params) try handleCppErrors(&ret) - return OptionalMarshaller>.fromCpp(ret) + return OptionalMarshaller>.fromCpp(ret) } - static func unbox(_ dt: Optional) throws -> Int64 { - var params = djinni.swift.ParameterList() - params.addValue(OptionalMarshaller>.toCpp(dt)) - var ret = djinni_generated.TestDuration_unbox(¶ms) + public static func unbox(_ dt: Optional) throws -> Int64 { + var _params = djinni.swift.ParameterList() + _params.addValue(OptionalMarshaller>.toCpp(dt)) + var ret = djinni_generated.TestDuration_unbox(&_params) try handleCppErrors(&ret) return I64Marshaller.fromCpp(ret) } diff --git a/test-suite/generated-src/swift/TestHelpers+Private.swift b/test-suite/generated-src/swift/TestHelpers+Private.swift index da7c0a3c..64e4605d 100644 --- a/test-suite/generated-src/swift/TestHelpers+Private.swift +++ b/test-suite/generated-src/swift/TestHelpers+Private.swift @@ -15,267 +15,267 @@ import TestSuiteCxx final class TestHelpersCppProxy: DjinniSupport.CppProxy, TestSuite.TestHelpers { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } } -enum TestHelpersMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.TestHelpers - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum TestHelpersMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.TestHelpers + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { TestHelpersCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class TestHelpers_statics { - static func getSetRecord() throws -> TestSuite.SetRecord { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_getSetRecord(¶ms) + public static func getSetRecord() throws -> TestSuite.SetRecord { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getSetRecord(&_params) try handleCppErrors(&ret) return SetRecordMarshaller.fromCpp(ret) } - static func checkSetRecord(_ rec: TestSuite.SetRecord) throws -> Bool { - var params = djinni.swift.ParameterList() - params.addValue(SetRecordMarshaller.toCpp(rec)) - var ret = djinni_generated.TestHelpers_checkSetRecord(¶ms) + public static func checkSetRecord(_ rec: TestSuite.SetRecord) throws -> Bool { + var _params = djinni.swift.ParameterList() + _params.addValue(SetRecordMarshaller.toCpp(rec)) + var ret = djinni_generated.TestHelpers_checkSetRecord(&_params) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } - static func getPrimitiveList() throws -> TestSuite.PrimitiveList { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_getPrimitiveList(¶ms) + public static func getPrimitiveList() throws -> TestSuite.PrimitiveList { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getPrimitiveList(&_params) try handleCppErrors(&ret) return PrimitiveListMarshaller.fromCpp(ret) } - static func checkPrimitiveList(_ pl: TestSuite.PrimitiveList) throws -> Bool { - var params = djinni.swift.ParameterList() - params.addValue(PrimitiveListMarshaller.toCpp(pl)) - var ret = djinni_generated.TestHelpers_checkPrimitiveList(¶ms) + public static func checkPrimitiveList(_ pl: TestSuite.PrimitiveList) throws -> Bool { + var _params = djinni.swift.ParameterList() + _params.addValue(PrimitiveListMarshaller.toCpp(pl)) + var ret = djinni_generated.TestHelpers_checkPrimitiveList(&_params) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } - static func getNestedCollection() throws -> TestSuite.NestedCollection { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_getNestedCollection(¶ms) + public static func getNestedCollection() throws -> TestSuite.NestedCollection { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getNestedCollection(&_params) try handleCppErrors(&ret) return NestedCollectionMarshaller.fromCpp(ret) } - static func checkNestedCollection(_ nc: TestSuite.NestedCollection) throws -> Bool { - var params = djinni.swift.ParameterList() - params.addValue(NestedCollectionMarshaller.toCpp(nc)) - var ret = djinni_generated.TestHelpers_checkNestedCollection(¶ms) + public static func checkNestedCollection(_ nc: TestSuite.NestedCollection) throws -> Bool { + var _params = djinni.swift.ParameterList() + _params.addValue(NestedCollectionMarshaller.toCpp(nc)) + var ret = djinni_generated.TestHelpers_checkNestedCollection(&_params) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } - static func getMap() throws -> Dictionary { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_getMap(¶ms) + public static func getMap() throws -> Dictionary { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getMap(&_params) try handleCppErrors(&ret) return MapMarshaller.fromCpp(ret) } - static func checkMap(_ m: Dictionary) throws -> Bool { - var params = djinni.swift.ParameterList() - params.addValue(MapMarshaller.toCpp(m)) - var ret = djinni_generated.TestHelpers_checkMap(¶ms) + public static func checkMap(_ m: Dictionary) throws -> Bool { + var _params = djinni.swift.ParameterList() + _params.addValue(MapMarshaller.toCpp(m)) + var ret = djinni_generated.TestHelpers_checkMap(&_params) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } - static func getEmptyMap() throws -> Dictionary { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_getEmptyMap(¶ms) + public static func getEmptyMap() throws -> Dictionary { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getEmptyMap(&_params) try handleCppErrors(&ret) return MapMarshaller.fromCpp(ret) } - static func checkEmptyMap(_ m: Dictionary) throws -> Bool { - var params = djinni.swift.ParameterList() - params.addValue(MapMarshaller.toCpp(m)) - var ret = djinni_generated.TestHelpers_checkEmptyMap(¶ms) + public static func checkEmptyMap(_ m: Dictionary) throws -> Bool { + var _params = djinni.swift.ParameterList() + _params.addValue(MapMarshaller.toCpp(m)) + var ret = djinni_generated.TestHelpers_checkEmptyMap(&_params) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } - static func getMapListRecord() throws -> TestSuite.MapListRecord { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_getMapListRecord(¶ms) + public static func getMapListRecord() throws -> TestSuite.MapListRecord { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getMapListRecord(&_params) try handleCppErrors(&ret) return MapListRecordMarshaller.fromCpp(ret) } - static func checkMapListRecord(_ m: TestSuite.MapListRecord) throws -> Bool { - var params = djinni.swift.ParameterList() - params.addValue(MapListRecordMarshaller.toCpp(m)) - var ret = djinni_generated.TestHelpers_checkMapListRecord(¶ms) + public static func checkMapListRecord(_ m: TestSuite.MapListRecord) throws -> Bool { + var _params = djinni.swift.ParameterList() + _params.addValue(MapListRecordMarshaller.toCpp(m)) + var ret = djinni_generated.TestHelpers_checkMapListRecord(&_params) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } - static func checkClientInterfaceAscii(_ i: TestSuite.ClientInterface) throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(ClientInterfaceMarshaller.toCpp(i)) - var ret = djinni_generated.TestHelpers_checkClientInterfaceAscii(¶ms) + public static func checkClientInterfaceAscii(_ i: TestSuite.ClientInterface) throws -> Void { + var _params = djinni.swift.ParameterList() + _params.addValue(ClientInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.TestHelpers_checkClientInterfaceAscii(&_params) try handleCppErrors(&ret) } - static func checkClientInterfaceNonascii(_ i: TestSuite.ClientInterface) throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(ClientInterfaceMarshaller.toCpp(i)) - var ret = djinni_generated.TestHelpers_checkClientInterfaceNonascii(¶ms) + public static func checkClientInterfaceNonascii(_ i: TestSuite.ClientInterface) throws -> Void { + var _params = djinni.swift.ParameterList() + _params.addValue(ClientInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.TestHelpers_checkClientInterfaceNonascii(&_params) try handleCppErrors(&ret) } - static func checkClientInterfaceArgs(_ i: TestSuite.ClientInterface) throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(ClientInterfaceMarshaller.toCpp(i)) - var ret = djinni_generated.TestHelpers_checkClientInterfaceArgs(¶ms) + public static func checkClientInterfaceArgs(_ i: TestSuite.ClientInterface) throws -> Void { + var _params = djinni.swift.ParameterList() + _params.addValue(ClientInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.TestHelpers_checkClientInterfaceArgs(&_params) try handleCppErrors(&ret) } - static func checkEnumMap(_ m: Dictionary) throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(MapMarshaller.toCpp(m)) - var ret = djinni_generated.TestHelpers_checkEnumMap(¶ms) + public static func checkEnumMap(_ m: Dictionary) throws -> Void { + var _params = djinni.swift.ParameterList() + _params.addValue(MapMarshaller.toCpp(m)) + var ret = djinni_generated.TestHelpers_checkEnumMap(&_params) try handleCppErrors(&ret) } - static func checkEnum(_ c: TestSuite.Color) throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(ColorMarshaller.toCpp(c)) - var ret = djinni_generated.TestHelpers_checkEnum(¶ms) + public static func checkEnum(_ c: TestSuite.Color) throws -> Void { + var _params = djinni.swift.ParameterList() + _params.addValue(ColorMarshaller.toCpp(c)) + var ret = djinni_generated.TestHelpers_checkEnum(&_params) try handleCppErrors(&ret) } - static func tokenId(_ t: Optional) throws -> Optional { - var params = djinni.swift.ParameterList() - params.addValue(OptionalMarshaller.toCpp(t)) - var ret = djinni_generated.TestHelpers_tokenId(¶ms) + public static func tokenId(_ t: Optional) throws -> Optional { + var _params = djinni.swift.ParameterList() + _params.addValue(OptionalMarshaller.toCpp(t)) + var ret = djinni_generated.TestHelpers_tokenId(&_params) try handleCppErrors(&ret) return OptionalMarshaller.fromCpp(ret) } - static func createCppToken() throws -> TestSuite.UserToken { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_createCppToken(¶ms) + public static func createCppToken() throws -> TestSuite.UserToken { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_createCppToken(&_params) try handleCppErrors(&ret) return UserTokenMarshaller.fromCpp(ret) } - static func checkCppToken(_ t: TestSuite.UserToken) throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(UserTokenMarshaller.toCpp(t)) - var ret = djinni_generated.TestHelpers_checkCppToken(¶ms) + public static func checkCppToken(_ t: TestSuite.UserToken) throws -> Void { + var _params = djinni.swift.ParameterList() + _params.addValue(UserTokenMarshaller.toCpp(t)) + var ret = djinni_generated.TestHelpers_checkCppToken(&_params) try handleCppErrors(&ret) } - static func cppTokenId(_ t: TestSuite.UserToken) throws -> Int64 { - var params = djinni.swift.ParameterList() - params.addValue(UserTokenMarshaller.toCpp(t)) - var ret = djinni_generated.TestHelpers_cppTokenId(¶ms) + public static func cppTokenId(_ t: TestSuite.UserToken) throws -> Int64 { + var _params = djinni.swift.ParameterList() + _params.addValue(UserTokenMarshaller.toCpp(t)) + var ret = djinni_generated.TestHelpers_cppTokenId(&_params) try handleCppErrors(&ret) return I64Marshaller.fromCpp(ret) } - static func checkTokenType(_ t: TestSuite.UserToken, type: String) throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(UserTokenMarshaller.toCpp(t)) - params.addValue(StringMarshaller.toCpp(type)) - var ret = djinni_generated.TestHelpers_checkTokenType(¶ms) + public static func checkTokenType(_ t: TestSuite.UserToken, type: String) throws -> Void { + var _params = djinni.swift.ParameterList() + _params.addValue(UserTokenMarshaller.toCpp(t)) + _params.addValue(StringMarshaller.toCpp(type)) + var ret = djinni_generated.TestHelpers_checkTokenType(&_params) try handleCppErrors(&ret) } - static func returnNone() throws -> Optional { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_returnNone(¶ms) + public static func returnNone() throws -> Optional { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_returnNone(&_params) try handleCppErrors(&ret) return OptionalMarshaller.fromCpp(ret) } - static func assortedPrimitivesId(_ i: TestSuite.AssortedPrimitives) throws -> TestSuite.AssortedPrimitives { - var params = djinni.swift.ParameterList() - params.addValue(AssortedPrimitivesMarshaller.toCpp(i)) - var ret = djinni_generated.TestHelpers_assortedPrimitivesId(¶ms) + public static func assortedPrimitivesId(_ i: TestSuite.AssortedPrimitives) throws -> TestSuite.AssortedPrimitives { + var _params = djinni.swift.ParameterList() + _params.addValue(AssortedPrimitivesMarshaller.toCpp(i)) + var ret = djinni_generated.TestHelpers_assortedPrimitivesId(&_params) try handleCppErrors(&ret) return AssortedPrimitivesMarshaller.fromCpp(ret) } - static func idBinary(_ b: Data) throws -> Data { - var params = djinni.swift.ParameterList() - params.addValue(BinaryMarshaller.toCpp(b)) - var ret = djinni_generated.TestHelpers_idBinary(¶ms) + public static func idBinary(_ b: Data) throws -> Data { + var _params = djinni.swift.ParameterList() + _params.addValue(BinaryMarshaller.toCpp(b)) + var ret = djinni_generated.TestHelpers_idBinary(&_params) try handleCppErrors(&ret) return BinaryMarshaller.fromCpp(ret) } - static func getAsyncResult() throws -> DJFuture { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_getAsyncResult(¶ms) + public static func getAsyncResult() throws -> DjinniSupport.DJFuture { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getAsyncResult(&_params) try handleCppErrors(&ret) - return FutureMarshaller.fromCpp(ret) + return DjinniSupport.FutureMarshaller.fromCpp(ret) } - static func futureRoundtrip(_ f: DJFuture) throws -> DJFuture { - var params = djinni.swift.ParameterList() - params.addValue(FutureMarshaller.toCpp(f)) - var ret = djinni_generated.TestHelpers_futureRoundtrip(¶ms) + public static func futureRoundtrip(_ f: DjinniSupport.DJFuture) throws -> DjinniSupport.DJFuture { + var _params = djinni.swift.ParameterList() + _params.addValue(DjinniSupport.FutureMarshaller.toCpp(f)) + var ret = djinni_generated.TestHelpers_futureRoundtrip(&_params) try handleCppErrors(&ret) - return FutureMarshaller.fromCpp(ret) + return DjinniSupport.FutureMarshaller.fromCpp(ret) } - static func asyncEarlyThrow() throws -> DJFuture { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_asyncEarlyThrow(¶ms) + public static func asyncEarlyThrow() throws -> DjinniSupport.DJFuture { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_asyncEarlyThrow(&_params) try handleCppErrors(&ret) - return FutureMarshaller.fromCpp(ret) + return DjinniSupport.FutureMarshaller.fromCpp(ret) } - static func voidAsyncMethod(_ f: DJFuture) throws -> DJFuture { - var params = djinni.swift.ParameterList() - params.addValue(FutureMarshaller.toCpp(f)) - var ret = djinni_generated.TestHelpers_voidAsyncMethod(¶ms) + public static func voidAsyncMethod(_ f: DjinniSupport.DJFuture) throws -> DjinniSupport.DJFuture { + var _params = djinni.swift.ParameterList() + _params.addValue(DjinniSupport.FutureMarshaller.toCpp(f)) + var ret = djinni_generated.TestHelpers_voidAsyncMethod(&_params) try handleCppErrors(&ret) - return FutureMarshaller.fromCpp(ret) + return DjinniSupport.FutureMarshaller.fromCpp(ret) } - static func addOneIfPresent(_ f: DJFuture>) throws -> DJFuture> { - var params = djinni.swift.ParameterList() - params.addValue(FutureMarshaller>.toCpp(f)) - var ret = djinni_generated.TestHelpers_addOneIfPresent(¶ms) + public static func addOneIfPresent(_ f: DjinniSupport.DJFuture>) throws -> DjinniSupport.DJFuture> { + var _params = djinni.swift.ParameterList() + _params.addValue(DjinniSupport.FutureMarshaller>.toCpp(f)) + var ret = djinni_generated.TestHelpers_addOneIfPresent(&_params) try handleCppErrors(&ret) - return FutureMarshaller>.fromCpp(ret) + return DjinniSupport.FutureMarshaller>.fromCpp(ret) } - static func returnExceptionString(_ f: DJFuture) throws -> DJFuture { - var params = djinni.swift.ParameterList() - params.addValue(FutureMarshaller.toCpp(f)) - var ret = djinni_generated.TestHelpers_returnExceptionString(¶ms) + public static func returnExceptionString(_ f: DjinniSupport.DJFuture) throws -> DjinniSupport.DJFuture { + var _params = djinni.swift.ParameterList() + _params.addValue(DjinniSupport.FutureMarshaller.toCpp(f)) + var ret = djinni_generated.TestHelpers_returnExceptionString(&_params) try handleCppErrors(&ret) - return FutureMarshaller.fromCpp(ret) + return DjinniSupport.FutureMarshaller.fromCpp(ret) } - static func checkAsyncInterface(_ i: TestSuite.AsyncInterface) throws -> DJFuture { - var params = djinni.swift.ParameterList() - params.addValue(AsyncInterfaceMarshaller.toCpp(i)) - var ret = djinni_generated.TestHelpers_checkAsyncInterface(¶ms) + public static func checkAsyncInterface(_ i: TestSuite.AsyncInterface) throws -> DjinniSupport.DJFuture { + var _params = djinni.swift.ParameterList() + _params.addValue(AsyncInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.TestHelpers_checkAsyncInterface(&_params) try handleCppErrors(&ret) - return FutureMarshaller.fromCpp(ret) + return DjinniSupport.FutureMarshaller.fromCpp(ret) } - static func checkAsyncComposition(_ i: TestSuite.AsyncInterface) throws -> DJFuture { - var params = djinni.swift.ParameterList() - params.addValue(AsyncInterfaceMarshaller.toCpp(i)) - var ret = djinni_generated.TestHelpers_checkAsyncComposition(¶ms) + public static func checkAsyncComposition(_ i: TestSuite.AsyncInterface) throws -> DjinniSupport.DJFuture { + var _params = djinni.swift.ParameterList() + _params.addValue(AsyncInterfaceMarshaller.toCpp(i)) + var ret = djinni_generated.TestHelpers_checkAsyncComposition(&_params) try handleCppErrors(&ret) - return FutureMarshaller.fromCpp(ret) + return DjinniSupport.FutureMarshaller.fromCpp(ret) } - static func getOptionalList() throws -> Array> { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_getOptionalList(¶ms) + public static func getOptionalList() throws -> Array> { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getOptionalList(&_params) try handleCppErrors(&ret) return ListMarshaller>.fromCpp(ret) } - static func checkOptionalList(_ ol: Array>) throws -> Bool { - var params = djinni.swift.ParameterList() - params.addValue(ListMarshaller>.toCpp(ol)) - var ret = djinni_generated.TestHelpers_checkOptionalList(¶ms) + public static func checkOptionalList(_ ol: Array>) throws -> Bool { + var _params = djinni.swift.ParameterList() + _params.addValue(ListMarshaller>.toCpp(ol)) + var ret = djinni_generated.TestHelpers_checkOptionalList(&_params) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } - static func getOptionalSet() throws -> Set> { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_getOptionalSet(¶ms) + public static func getOptionalSet() throws -> Set> { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getOptionalSet(&_params) try handleCppErrors(&ret) return SetMarshaller>.fromCpp(ret) } - static func checkOptionalSet(_ os: Set>) throws -> Bool { - var params = djinni.swift.ParameterList() - params.addValue(SetMarshaller>.toCpp(os)) - var ret = djinni_generated.TestHelpers_checkOptionalSet(¶ms) + public static func checkOptionalSet(_ os: Set>) throws -> Bool { + var _params = djinni.swift.ParameterList() + _params.addValue(SetMarshaller>.toCpp(os)) + var ret = djinni_generated.TestHelpers_checkOptionalSet(&_params) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } - static func getOptionalMap() throws -> Dictionary, Optional> { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestHelpers_getOptionalMap(¶ms) + public static func getOptionalMap() throws -> Dictionary, Optional> { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getOptionalMap(&_params) try handleCppErrors(&ret) return MapMarshaller, OptionalMarshaller>.fromCpp(ret) } - static func checkOptionalMap(_ om: Dictionary, Optional>) throws -> Bool { - var params = djinni.swift.ParameterList() - params.addValue(MapMarshaller, OptionalMarshaller>.toCpp(om)) - var ret = djinni_generated.TestHelpers_checkOptionalMap(¶ms) + public static func checkOptionalMap(_ om: Dictionary, Optional>) throws -> Bool { + var _params = djinni.swift.ParameterList() + _params.addValue(MapMarshaller, OptionalMarshaller>.toCpp(om)) + var ret = djinni_generated.TestHelpers_checkOptionalMap(&_params) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } diff --git a/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord+Private.swift b/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord+Private.swift index 5a3a122d..6cdb3f93 100644 --- a/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord+Private.swift +++ b/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord+Private.swift @@ -7,17 +7,17 @@ import Foundation import TestSuite import TestSuiteCxx -enum TestOptionalExternInterfaceRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.TestOptionalExternInterfaceRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum TestOptionalExternInterfaceRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.TestOptionalExternInterfaceRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in - let sampleInterface = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + let sampleInterface = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(sampleInterface: sampleInterface) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() - djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.sampleInterface)) + djinni.swift.addMember(&ret, OptionalMarshaller.toCpp(s.sampleInterface)) return ret } } diff --git a/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord.swift b/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord.swift index 19809406..5a4e87f9 100644 --- a/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord.swift +++ b/test-suite/generated-src/swift/TestOptionalExternInterfaceRecord.swift @@ -4,9 +4,9 @@ import Foundation public struct TestOptionalExternInterfaceRecord { - public var sampleInterface: Optional + public var sampleInterface: Optional - public init(sampleInterface: Optional) + public init(sampleInterface: Optional) { self.sampleInterface = sampleInterface } diff --git a/test-suite/generated-src/swift/TestOutcome+Private.swift b/test-suite/generated-src/swift/TestOutcome+Private.swift index ab1c423c..523d8a9e 100644 --- a/test-suite/generated-src/swift/TestOutcome+Private.swift +++ b/test-suite/generated-src/swift/TestOutcome+Private.swift @@ -10,65 +10,65 @@ import TestSuiteCxx final class TestOutcomeCppProxy: DjinniSupport.CppProxy, TestSuite.TestOutcome { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } } -enum TestOutcomeMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.TestOutcome - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum TestOutcomeMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.TestOutcome + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { TestOutcomeCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class TestOutcome_statics { - static func getSuccessOutcome() throws -> Result { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestOutcome_getSuccessOutcome(¶ms) + public static func getSuccessOutcome() throws -> Result { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestOutcome_getSuccessOutcome(&_params) try handleCppErrors(&ret) - return OutcomeMarshaller.fromCpp(ret) + return DjinniSupport.OutcomeMarshaller.fromCpp(ret) } - static func getErrorOutcome() throws -> Result { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestOutcome_getErrorOutcome(¶ms) + public static func getErrorOutcome() throws -> Result { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestOutcome_getErrorOutcome(&_params) try handleCppErrors(&ret) - return OutcomeMarshaller.fromCpp(ret) + return DjinniSupport.OutcomeMarshaller.fromCpp(ret) } - static func putSuccessOutcome(_ x: Result) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(OutcomeMarshaller.toCpp(x)) - var ret = djinni_generated.TestOutcome_putSuccessOutcome(¶ms) + public static func putSuccessOutcome(_ x: Result) throws -> String { + var _params = djinni.swift.ParameterList() + _params.addValue(DjinniSupport.OutcomeMarshaller.toCpp(x)) + var ret = djinni_generated.TestOutcome_putSuccessOutcome(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func putErrorOutcome(_ x: Result) throws -> Int32 { - var params = djinni.swift.ParameterList() - params.addValue(OutcomeMarshaller.toCpp(x)) - var ret = djinni_generated.TestOutcome_putErrorOutcome(¶ms) + public static func putErrorOutcome(_ x: Result) throws -> Int32 { + var _params = djinni.swift.ParameterList() + _params.addValue(DjinniSupport.OutcomeMarshaller.toCpp(x)) + var ret = djinni_generated.TestOutcome_putErrorOutcome(&_params) try handleCppErrors(&ret) return I32Marshaller.fromCpp(ret) } - static func getNestedSuccessOutcome() throws -> TestSuite.NestedOutcome { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestOutcome_getNestedSuccessOutcome(¶ms) + public static func getNestedSuccessOutcome() throws -> TestSuite.NestedOutcome { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestOutcome_getNestedSuccessOutcome(&_params) try handleCppErrors(&ret) return NestedOutcomeMarshaller.fromCpp(ret) } - static func getNestedErrorOutcome() throws -> TestSuite.NestedOutcome { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.TestOutcome_getNestedErrorOutcome(¶ms) + public static func getNestedErrorOutcome() throws -> TestSuite.NestedOutcome { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestOutcome_getNestedErrorOutcome(&_params) try handleCppErrors(&ret) return NestedOutcomeMarshaller.fromCpp(ret) } - static func putNestedSuccessOutcome(_ x: TestSuite.NestedOutcome) throws -> Int32 { - var params = djinni.swift.ParameterList() - params.addValue(NestedOutcomeMarshaller.toCpp(x)) - var ret = djinni_generated.TestOutcome_putNestedSuccessOutcome(¶ms) + public static func putNestedSuccessOutcome(_ x: TestSuite.NestedOutcome) throws -> Int32 { + var _params = djinni.swift.ParameterList() + _params.addValue(NestedOutcomeMarshaller.toCpp(x)) + var ret = djinni_generated.TestOutcome_putNestedSuccessOutcome(&_params) try handleCppErrors(&ret) return I32Marshaller.fromCpp(ret) } - static func putNestedErrorOutcome(_ x: TestSuite.NestedOutcome) throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(NestedOutcomeMarshaller.toCpp(x)) - var ret = djinni_generated.TestOutcome_putNestedErrorOutcome(¶ms) + public static func putNestedErrorOutcome(_ x: TestSuite.NestedOutcome) throws -> String { + var _params = djinni.swift.ParameterList() + _params.addValue(NestedOutcomeMarshaller.toCpp(x)) + var ret = djinni_generated.TestOutcome_putNestedErrorOutcome(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } diff --git a/test-suite/generated-src/swift/TestStaticMethodLanguage+Private.swift b/test-suite/generated-src/swift/TestStaticMethodLanguage+Private.swift index f319b2cb..eddfb115 100644 --- a/test-suite/generated-src/swift/TestStaticMethodLanguage+Private.swift +++ b/test-suite/generated-src/swift/TestStaticMethodLanguage+Private.swift @@ -10,12 +10,12 @@ import TestSuiteCxx final class TestStaticMethodLanguageCppProxy: DjinniSupport.CppProxy, TestSuite.TestStaticMethodLanguage { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } } -enum TestStaticMethodLanguageMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.TestStaticMethodLanguage - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum TestStaticMethodLanguageMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.TestStaticMethodLanguage + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { TestStaticMethodLanguageCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/ThrowingInterface+Private.swift b/test-suite/generated-src/swift/ThrowingInterface+Private.swift index bc876fa8..21d6d3d1 100644 --- a/test-suite/generated-src/swift/ThrowingInterface+Private.swift +++ b/test-suite/generated-src/swift/ThrowingInterface+Private.swift @@ -13,12 +13,12 @@ let throwingInterfaceMethods: Vtbl = [ }, ] -enum ThrowingInterfaceMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.ThrowingInterface - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum ThrowingInterfaceMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.ThrowingInterface + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { fatalError("n/a") }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { djinni_generated.ThrowingInterfaceSwiftProxy.make(ctxPtr(s, throwingInterfaceMethods), dispatcherProtocalCall)}) } } diff --git a/test-suite/generated-src/swift/UserToken+Private.swift b/test-suite/generated-src/swift/UserToken+Private.swift index 1022e051..8583a3ab 100644 --- a/test-suite/generated-src/swift/UserToken+Private.swift +++ b/test-suite/generated-src/swift/UserToken+Private.swift @@ -10,9 +10,9 @@ import TestSuiteCxx final class UserTokenCppProxy: DjinniSupport.CppProxy, TestSuite.UserToken { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func whoami() throws -> String { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.UserToken_whoami(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.UserToken_whoami(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } @@ -23,12 +23,12 @@ let userTokenMethods: Vtbl = [ }, ] -enum UserTokenMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.UserToken - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum UserTokenMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.UserToken + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { UserTokenCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { djinni_generated.UserTokenSwiftProxy.make(ctxPtr(s, userTokenMethods), dispatcherProtocalCall)}) } } diff --git a/test-suite/generated-src/swift/UsesSingleLanguageListeners+Private.swift b/test-suite/generated-src/swift/UsesSingleLanguageListeners+Private.swift index 5b4023f2..923f55d4 100644 --- a/test-suite/generated-src/swift/UsesSingleLanguageListeners+Private.swift +++ b/test-suite/generated-src/swift/UsesSingleLanguageListeners+Private.swift @@ -14,40 +14,40 @@ import TestSuiteCxx final class UsesSingleLanguageListenersCppProxy: DjinniSupport.CppProxy, TestSuite.UsesSingleLanguageListeners { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func callForObjC(_ l: TestSuite.ObjcOnlyListener) throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(ObjcOnlyListenerMarshaller.toCpp(l)) - var ret = djinni_generated.UsesSingleLanguageListeners_callForObjC(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(ObjcOnlyListenerMarshaller.toCpp(l)) + var ret = djinni_generated.UsesSingleLanguageListeners_callForObjC(&_params) try handleCppErrors(&ret) } func returnForObjC() throws -> TestSuite.ObjcOnlyListener { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.UsesSingleLanguageListeners_returnForObjC(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.UsesSingleLanguageListeners_returnForObjC(&_params) try handleCppErrors(&ret) return ObjcOnlyListenerMarshaller.fromCpp(ret) } func callForJava(_ l: TestSuite.JavaOnlyListener) throws -> Void { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(JavaOnlyListenerMarshaller.toCpp(l)) - var ret = djinni_generated.UsesSingleLanguageListeners_callForJava(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(JavaOnlyListenerMarshaller.toCpp(l)) + var ret = djinni_generated.UsesSingleLanguageListeners_callForJava(&_params) try handleCppErrors(&ret) } func returnForJava() throws -> TestSuite.JavaOnlyListener { - var params = djinni.swift.ParameterList() - params.addValue(inst) - var ret = djinni_generated.UsesSingleLanguageListeners_returnForJava(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.UsesSingleLanguageListeners_returnForJava(&_params) try handleCppErrors(&ret) return JavaOnlyListenerMarshaller.fromCpp(ret) } } -enum UsesSingleLanguageListenersMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.UsesSingleLanguageListeners - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum UsesSingleLanguageListenersMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.UsesSingleLanguageListeners + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { UsesSingleLanguageListenersCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/VarnameInterface+Private.swift b/test-suite/generated-src/swift/VarnameInterface+Private.swift index f18cab13..c158f511 100644 --- a/test-suite/generated-src/swift/VarnameInterface+Private.swift +++ b/test-suite/generated-src/swift/VarnameInterface+Private.swift @@ -10,28 +10,28 @@ import TestSuiteCxx final class VarnameInterfaceCppProxy: DjinniSupport.CppProxy, TestSuite.VarnameInterface { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } func Rmethod(_ RArg: TestSuite.VarnameRecord) throws -> TestSuite.VarnameRecord { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(VarnameRecordMarshaller.toCpp(RArg)) - var ret = djinni_generated.VarnameInterface_Rmethod(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(VarnameRecordMarshaller.toCpp(RArg)) + var ret = djinni_generated.VarnameInterface_Rmethod(&_params) try handleCppErrors(&ret) return VarnameRecordMarshaller.fromCpp(ret) } func Imethod(_ IArg: TestSuite.VarnameInterface) throws -> TestSuite.VarnameInterface { - var params = djinni.swift.ParameterList() - params.addValue(inst) - params.addValue(VarnameInterfaceMarshaller.toCpp(IArg)) - var ret = djinni_generated.VarnameInterface_Imethod(¶ms) + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + _params.addValue(VarnameInterfaceMarshaller.toCpp(IArg)) + var ret = djinni_generated.VarnameInterface_Imethod(&_params) try handleCppErrors(&ret) return VarnameInterfaceMarshaller.fromCpp(ret) } } -enum VarnameInterfaceMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.VarnameInterface - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum VarnameInterfaceMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.VarnameInterface + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { VarnameInterfaceCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } diff --git a/test-suite/generated-src/swift/VarnameRecord+Private.swift b/test-suite/generated-src/swift/VarnameRecord+Private.swift index 35312006..79758f5d 100644 --- a/test-suite/generated-src/swift/VarnameRecord+Private.swift +++ b/test-suite/generated-src/swift/VarnameRecord+Private.swift @@ -7,15 +7,15 @@ import Foundation import TestSuite import TestSuiteCxx -enum VarnameRecordMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.VarnameRecord - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum VarnameRecordMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.VarnameRecord + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let Field = I8Marshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(Field: Field) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, I8Marshaller.toCpp(s.Field)) return ret diff --git a/test-suite/generated-src/swift/Vec2+Private.swift b/test-suite/generated-src/swift/Vec2+Private.swift index 03154084..0fce6515 100644 --- a/test-suite/generated-src/swift/Vec2+Private.swift +++ b/test-suite/generated-src/swift/Vec2+Private.swift @@ -7,16 +7,16 @@ import Foundation import TestSuite import TestSuiteCxx -enum Vec2Marshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.Vec2 - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum Vec2Marshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.Vec2 + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let x = I32Marshaller.fromCpp(djinni.swift.getMember(p, 0)) let y = I32Marshaller.fromCpp(djinni.swift.getMember(p, 1)) return SwiftType(x: x, y: y) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, I32Marshaller.toCpp(s.x)) djinni.swift.addMember(&ret, I32Marshaller.toCpp(s.y)) diff --git a/test-suite/generated-src/swift/WcharTestHelpers+Private.swift b/test-suite/generated-src/swift/WcharTestHelpers+Private.swift index 40047e64..d89d5b72 100644 --- a/test-suite/generated-src/swift/WcharTestHelpers+Private.swift +++ b/test-suite/generated-src/swift/WcharTestHelpers+Private.swift @@ -10,39 +10,39 @@ import TestSuiteCxx final class WcharTestHelpersCppProxy: DjinniSupport.CppProxy, TestSuite.WcharTestHelpers { init(_ inst: djinni.swift.AnyValue) { super.init(inst:inst) } } -enum WcharTestHelpersMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.WcharTestHelpers - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum WcharTestHelpersMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.WcharTestHelpers + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return cppInterfaceToSwift(c, { WcharTestHelpersCppProxy(c) as SwiftType }) } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { return swiftInterfaceToCpp(s, { fatalError("n/a") }) } } public class WcharTestHelpers_statics { - static func getRecord() throws -> TestSuite.WcharTestRec { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.WcharTestHelpers_getRecord(¶ms) + public static func getRecord() throws -> TestSuite.WcharTestRec { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.WcharTestHelpers_getRecord(&_params) try handleCppErrors(&ret) return WcharTestRecMarshaller.fromCpp(ret) } - static func getString() throws -> String { - var params = djinni.swift.ParameterList() - var ret = djinni_generated.WcharTestHelpers_getString(¶ms) + public static func getString() throws -> String { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.WcharTestHelpers_getString(&_params) try handleCppErrors(&ret) return StringMarshaller.fromCpp(ret) } - static func checkString(_ str: String) throws -> Bool { - var params = djinni.swift.ParameterList() - params.addValue(StringMarshaller.toCpp(str)) - var ret = djinni_generated.WcharTestHelpers_checkString(¶ms) + public static func checkString(_ str: String) throws -> Bool { + var _params = djinni.swift.ParameterList() + _params.addValue(StringMarshaller.toCpp(str)) + var ret = djinni_generated.WcharTestHelpers_checkString(&_params) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } - static func checkRecord(_ rec: TestSuite.WcharTestRec) throws -> Bool { - var params = djinni.swift.ParameterList() - params.addValue(WcharTestRecMarshaller.toCpp(rec)) - var ret = djinni_generated.WcharTestHelpers_checkRecord(¶ms) + public static func checkRecord(_ rec: TestSuite.WcharTestRec) throws -> Bool { + var _params = djinni.swift.ParameterList() + _params.addValue(WcharTestRecMarshaller.toCpp(rec)) + var ret = djinni_generated.WcharTestHelpers_checkRecord(&_params) try handleCppErrors(&ret) return BoolMarshaller.fromCpp(ret) } diff --git a/test-suite/generated-src/swift/WcharTestRec+Private.swift b/test-suite/generated-src/swift/WcharTestRec+Private.swift index 46c55e19..4e4fb9ff 100644 --- a/test-suite/generated-src/swift/WcharTestRec+Private.swift +++ b/test-suite/generated-src/swift/WcharTestRec+Private.swift @@ -7,15 +7,15 @@ import Foundation import TestSuite import TestSuiteCxx -enum WcharTestRecMarshaller: DjinniSupport.Marshaller { - typealias SwiftType = TestSuite.WcharTestRec - static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { +public enum WcharTestRecMarshaller: DjinniSupport.Marshaller { + public typealias SwiftType = TestSuite.WcharTestRec + public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType { return withUnsafePointer(to: c) { p in let s = StringMarshaller.fromCpp(djinni.swift.getMember(p, 0)) return SwiftType(s: s) } } - static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { var ret = djinni.swift.makeCompositeValue() djinni.swift.addMember(&ret, StringMarshaller.toCpp(s.s)) return ret From be7eff9b57c50d56bf1c6e7376f970bbda19f7f3 Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 30 Aug 2024 12:44:19 +1000 Subject: [PATCH 65/68] revert the nonnull future get change because it prevents future --- support-lib/objc/DJFuture.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support-lib/objc/DJFuture.h b/support-lib/objc/DJFuture.h index be1faa8a..c456cfe5 100644 --- a/support-lib/objc/DJFuture.h +++ b/support-lib/objc/DJFuture.h @@ -25,7 +25,7 @@ // If the future is ready, then calling its `get` method will not block. - (BOOL) isReady; // Block and wait for the result (or exception). This can only be called once. -- (nonnull DJValue) get; +- (nullable DJValue) get; // Tell the future to Call the specified handler routine when it becomes // ready. Returns a new future that wraps the return value of the handler // routine. The current future becomes invalid after this call. @@ -40,7 +40,7 @@ - (nonnull DJFuture *)getFuture; // `setValue` or `setException` can only be called once on a promise. After // which the internal state becomes invalid. -- (void)setValue:(nonnull DJValue)val; +- (void)setValue:(nullable DJValue)val; // for NSNull* (void) - (void)setValue; - (void)setException:(nonnull NSException *)exception; From dd172fe80ff85bcd38c2208e6d5a61cab56aa049 Mon Sep 17 00:00:00 2001 From: Ivan Golub <1858309+ivan-golub@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:26:11 -0700 Subject: [PATCH 66/68] Remove -fcoroutines-ts clang++: error: unknown argument: '-fcoroutines-ts' is thrown with Xcode 16 --- .bazelrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelrc b/.bazelrc index bfda4099..a5a19b93 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1 +1 @@ -build --cxxopt=-std=c++17 --cxxopt=-fcoroutines-ts --host_cxxopt=-std=c++17 --host_cxxopt=-fcoroutines-ts --incompatible_java_common_parameters=false --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder --nouse_workers_with_dexbuilder +build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --host_cxxopt=-fcoroutines-ts --incompatible_java_common_parameters=false --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder --nouse_workers_with_dexbuilder From 3d3c46b733a35d429811eb0bd6d0e2a4dfe21b56 Mon Sep 17 00:00:00 2001 From: Ivan Golub <1858309+ivan-golub@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:28:19 -0700 Subject: [PATCH 67/68] Remove -fcoroutines-ts from host_cxxopt too --- .bazelrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelrc b/.bazelrc index a5a19b93..8b9d0d7d 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1 +1 @@ -build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --host_cxxopt=-fcoroutines-ts --incompatible_java_common_parameters=false --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder --nouse_workers_with_dexbuilder +build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --incompatible_java_common_parameters=false --define=android_dexmerger_tool=d8_dexmerger --define=android_incremental_dexing_tool=d8_dexbuilder --nouse_workers_with_dexbuilder From 82ba611c7b0177ed9964b6c454c878981b3df75d Mon Sep 17 00:00:00 2001 From: Li Feng Date: Wed, 9 Oct 2024 14:09:59 +1100 Subject: [PATCH 68/68] avoid swift keywords --- src/source/generator.scala | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/source/generator.scala b/src/source/generator.scala index 54844a27..e959adf2 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -187,6 +187,15 @@ package object generatorTools { private val underLowerStrict = (s: String) => s.toLowerCase private val underUpperStrict = (s: String) => s.split('_').map(leadingUpperStrict).mkString("_") + private val avoidKeywords = (keywords: List[String], converter: IdentConverter) => (s: String) => { + val ident = converter(s) + if (keywords.contains(ident)) + ident + "_" + else + ident + } + private val swiftKeywords = List("protocol") + val camelUpper = (s: String) => s.split("[-_]").map(firstUpper).mkString val camelLower = (s: String) => { val parts = s.split('_') @@ -201,7 +210,7 @@ package object generatorTools { val cppDefault = CppIdentStyle(camelUpper, camelUpper, camelUpper, underLower, underLower, underLower, underCaps, underCaps) val objcDefault = ObjcIdentStyle(camelUpper, camelUpper, camelLower, camelLower, camelLower, camelUpper, camelUpper) val jsDefault = JsIdentStyle(camelUpper, camelUpper, camelLower, camelLower, camelLower, underCaps, underCaps) - val swiftDefault = SwiftIdentStyle(camelUpper, camelUpper, camelLower, camelLower, camelLower, camelLower, camelLower) + val swiftDefault = SwiftIdentStyle(camelUpper, camelUpper, avoidKeywords(swiftKeywords, camelLower), avoidKeywords(swiftKeywords, camelLower), camelLower, camelLower, camelLower) val styles = Map( "FooBar" -> camelUpper,