diff --git a/README.md b/README.md index 22f1dc65..0c869452 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.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` The iOS example app are built with Xcode. Simply open the project in Xcode and it should work. @@ -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 - Omit optional parameters from record constructors - Records are default mutable across all platforms @@ -141,7 +141,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<>`. @@ -303,9 +304,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 diff --git a/WORKSPACE b/WORKSPACE index 25a1a4fc..cb090799 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -16,28 +16,25 @@ 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", - url = "https://github.com/bazelbuild/rules_apple/releases/download/{0}/rules_apple.{0}.tar.gz" - .format(build_bazel_rules_apple_version), + 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", - url = "https://github.com/bazelbuild/rules_swift/releases/download/{0}/rules_swift.{0}.tar.gz" - .format(build_bazel_rules_swift_version), + 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", - url = "https://github.com/bazelbuild/apple_support/releases/download/{0}/apple_support.{0}.tar.gz" - .format(build_bazel_apple_support_version), + sha256 = "c4bb2b7367c484382300aee75be598b92f847896fb31bbd22f3a2346adf66a80", + 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" @@ -50,13 +47,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/bzl/deps.bzl b/bzl/deps.bzl index f39e1185..722fb3d2 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.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 = "25224376205a54bb719fe7d97aeb9d8f5219c7ef668f426a5dab2da7db992842", + 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/BUILD b/examples/BUILD index 74a1b99c..c3bfeb72 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", @@ -20,6 +21,7 @@ cc_library( "//support-lib:djinni-support-common", ], alwayslink = 1, + visibility = ["//visibility:public"], ) # ------------------------------------------------------------------ @@ -53,7 +55,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",], ) @@ -99,3 +101,58 @@ 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", + 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-swift-bridge", + module_name = "TextSortBridge", + 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=TextSortCxx"], + visibility = ["//visibility:public"], +) 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/ItemList+Private.swift b/examples/generated-src/swift/ItemList+Private.swift new file mode 100644 index 00000000..5e3ff565 --- /dev/null +++ b/examples/generated-src/swift/ItemList+Private.swift @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TextSort +import TextSortCxx + +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) + } + } + 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/ItemList.swift b/examples/generated-src/swift/ItemList.swift new file mode 100644 index 00000000..a7a787b7 --- /dev/null +++ b/examples/generated-src/swift/ItemList.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +import Foundation + +public struct ItemList { + public var items: Array + + 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 new file mode 100644 index 00000000..eed2207a --- /dev/null +++ b/examples/generated-src/swift/SortItems+Private.swift @@ -0,0 +1,45 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +import DjinniSupport +import DjinniSupportCxx +import Foundation +import TextSort +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(&_params) + try handleCppErrors(&ret) + } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class SortItems_statics { + 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) + } + 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/SortItems.swift b/examples/generated-src/swift/SortItems.swift new file mode 100644 index 00000000..ee378fa8 --- /dev/null +++ b/examples/generated-src/swift/SortItems.swift @@ -0,0 +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: TextSort.SortOrder, items: TextSort.ItemList) throws -> Void +} diff --git a/examples/generated-src/swift/SortOrder+Private.swift b/examples/generated-src/swift/SortOrder+Private.swift new file mode 100644 index 00000000..31fdf7f4 --- /dev/null +++ b/examples/generated-src/swift/SortOrder+Private.swift @@ -0,0 +1,7 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +import DjinniSupport +import TextSort + +public typealias SortOrderMarshaller = DjinniSupport.EnumMarshaller diff --git a/examples/generated-src/swift/SortOrder.swift b/examples/generated-src/swift/SortOrder.swift new file mode 100644 index 00000000..5b5f84b4 --- /dev/null +++ b/examples/generated-src/swift/SortOrder.swift @@ -0,0 +1,8 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +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..ded4c8f9 --- /dev/null +++ b/examples/generated-src/swift/TextboxListener+Private.swift @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from example.djinni + +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)) + try inst.update(_items) + }, +] + +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") }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { djinni_generated.TextboxListenerSwiftProxy.make(ctxPtr(s, textboxListenerMethods), dispatcherProtocalCall)}) + } +} diff --git a/examples/generated-src/swift/TextboxListener.swift b/examples/generated-src/swift/TextboxListener.swift new file mode 100644 index 00000000..c0a97509 --- /dev/null +++ b/examples/generated-src/swift/TextboxListener.swift @@ -0,0 +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: TextSort.ItemList) throws -> Void +} 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..54d1734d --- /dev/null +++ b/examples/generated-src/swiftxx/SwiftSortItems.cpp @@ -0,0 +1,38 @@ +// 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) 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(std::move(_order), std::move(_items)); + return djinni::swift::makeVoidValue(); +} +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(std::move(_listener)); + return ::djinni_generated::SwiftSortItems::fromCpp(ret); +} +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(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/examples/generated-src/swiftxx/SwiftSortItems.hpp b/examples/generated-src/swiftxx/SwiftSortItems.hpp new file mode 100644 index 00000000..639daaf9 --- /dev/null +++ b/examples/generated-src/swiftxx/SwiftSortItems.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 "sort_items.hpp" + +namespace djinni_generated { + +using SwiftSortItems = djinni::swift::Interface<::textsort::SortItems>; + +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); + +} // 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..838a99ef --- /dev/null +++ b/examples/generated-src/swiftxx/SwiftTextboxListener.cpp @@ -0,0 +1,18 @@ +// 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 { + +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 new file mode 100644 index 00000000..2c731585 --- /dev/null +++ b/examples/generated-src/swiftxx/SwiftTextboxListener.hpp @@ -0,0 +1,20 @@ +// 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>; + +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 diff --git a/examples/ios/TextSort.xcodeproj/project.pbxproj b/examples/ios/TextSort.xcodeproj/project.pbxproj index ed799f19..0c025a7e 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 = 11.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 = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "Dropbox.${PRODUCT_NAME:rfc1034identifier}"; 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/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/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 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/Main.scala b/src/source/Main.scala index 429d8710..b7356bbb 100644 --- a/src/source/Main.scala +++ b/src/source/Main.scala @@ -111,6 +111,17 @@ 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 swiftxxIncludePrefix: String = "" + 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 @@ -290,6 +301,19 @@ 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).") + 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) + .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).") opt[String]("yaml-out-file").valueName("").foreach(x => yamlOutFile = Some(x)) @@ -328,6 +352,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 +379,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 +520,17 @@ object Main { composerClassIdentStyle, composerFileIdentStyle, composerTsOutFolder, + swiftOutFolder, + swiftIdentStyle, + swiftModule, + swiftxxOutFolder, + swiftxxNamespace, + swiftxxIncludePrefix, + swiftxxBaseLibModule, + swiftxxClassIdentStyle, + swiftxxFileIdentStyle, + swiftxxIncludeCppPrefix, + swiftxxBaseLibIncludePrefix, 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/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 new file mode 100644 index 00000000..5c25c22b --- /dev/null +++ b/src/source/SwiftGenerator.scala @@ -0,0 +1,348 @@ +/** + * 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 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 + if (refs.nonEmpty) { + refs.foreach(s => w.wl(s"import $s")) + 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) + }) + } + + 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 => { + 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 => { + w.wl(s"public 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 + } + } + + 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]() + 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) { + tm.args.foreach(find) + find(tm.base) + } + def find(m: Meta) = for(r <- marshal.references(m, name)) r match { + // 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 + } + } + + 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) + 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) + 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.fqFieldType(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, refs.privateImports, w => { + 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)" + 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("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) { + 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()") + } + } + } + }) + } + 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) + }) + 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 ${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)}") + } + } + }) + 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.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)}(") + 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)") + for (p <- m.params) { + 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)}(&_params)") + w.wl("try handleCppErrors(&ret)") + if (!m.ret.isEmpty) { + w.wl(s"return ${marshal.fromCpp(m.ret.get, "ret")}") + } + } + } + } + } + // 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.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) + } else { + w.wl(s"djinni.swift.setReturnValue(ret, try ${marshal.toCpp(m.ret.get, call)})") + } + } + w.wl("},") + } + } + w.wl("]") + w.wl + } + // Define the marshaller + 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("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})") + } + } + // Define static method stubs + 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"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 { + 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"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 new file mode 100644 index 00000000..325864d6 --- /dev/null +++ b/src/source/SwiftMarshal.scala @@ -0,0 +1,143 @@ +/** + * 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, 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, 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, Some(spec.swiftModule))) + + override def fieldType(tm: MExpr): String = toSwiftType(tm, None) + 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 MProtobuf(name, _, ProtobufMessage(_,_,_,_,Some(swift))) => List(ImportRef(swift.module), PrivateImportRef(swift.module)) + case d: MDef => List() + case e: MExtern => List(ImportRef(e.swift.module), PrivateImportRef(e.swift.translatorModule)) + 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 = { + 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 => 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 + } + 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 => 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) + 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 "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 => 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" + 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 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") + case p: MParam => throw new AssertionError("not applicable") + case MVoid => "Void_Marshaller" + } + } + 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..82285d90 --- /dev/null +++ b/src/source/SwiftxxGenerator.scala @@ -0,0 +1,195 @@ +/** + * 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.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 _ => + } + + 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, cppMarshal.maybeMove(member, f.ty))});") + } + 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.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) { + 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.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()}};") + } + }) + } + 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, cppMarshal.maybeMove(idCpp.local(p.ident), p.ty))});") + } + 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..f2d32672 --- /dev/null +++ b/src/source/SwiftxxMarshal.scala @@ -0,0 +1,102 @@ +/** + * 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() + case d: MDef => List(ImportRef(include(d.name))) + case e: MExtern => List(ImportRef(resolveExtSwiftxxHdr(e.swiftxx.header))) + case _ => List() + } + + def include(ident: String) = q(spec.swiftxxIncludePrefix + spec.swiftxxFileIdentStyle(ident) + "." + spec.cppHeaderExt) + + def resolveExtSwiftxxHdr(path: String) = { + path.replaceAll("\\$", spec.swiftxxBaseLibIncludePrefix); + } + + 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.swiftxx.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 => if (spec.cppUseWideStrings) "WString" else "String" + case MDate => "Date" + case MList => "List" + case MSet => "Set" + case MMap => "Map" + 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") + 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 => + 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/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 c61bdd87..1633a902 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,12 @@ 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))} + } + if (spec.swiftxxOutFolder.isDefined) { + w.wl("swiftxx:").nested {write(w, swiftxx(td))} + } } private def write(w: IndentWriter, m: Map[String, Any]) { @@ -122,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) { "" @@ -209,6 +217,17 @@ class YamlGenerator(spec: Spec) extends Generator(spec) { //, "generic" -> false ) + private def swift(td: TypeDecl) = Map[String, Any]( + "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? private def mexpr(td: TypeDecl) = MExpr(meta(td), List()) @@ -295,7 +314,16 @@ 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", "translator.module", ""), + getOptionalField(td, "swift", "generic", false)), + MExtern.Swiftxx( + getOptionalField(td, "swiftxx", "translator"), + getOptionalField(td, "swiftxx", "header")) ) private def nested(td: ExternTypeDecl, key: String) = { @@ -313,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 62e3d699..4849ec7e 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 } } @@ -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, Error = Value } } @@ -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 e7b01dd4..e959adf2 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -113,6 +113,17 @@ package object generatorTools { composerClassIdentStyle: IdentConverter, composerFileIdentStyle: IdentConverter, composerTsOutFolder: Option[File], + swiftOutFolder: Option[File], + swiftIdentStyle: SwiftIdentStyle, + swiftModule: String, + swiftxxOutFolder: Option[File], + swiftxxNamespace: String, + swiftxxIncludePrefix: String, + swiftxxBaseLibModule: String, + swiftxxClassIdentStyle: IdentConverter, + swiftxxFileIdentStyle: IdentConverter, + swiftxxIncludeCppPrefix: String, + swiftxxBaseLibIncludePrefix: String, outFileListWriter: Option[Writer], skipGeneration: Boolean, yamlOutFolder: Option[File], @@ -161,6 +172,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) => { @@ -173,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('_') @@ -187,6 +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, avoidKeywords(swiftKeywords, camelLower), avoidKeywords(swiftKeywords, camelLower), camelLower, camelLower, camelLower) val styles = Map( "FooBar" -> camelUpper, @@ -321,6 +345,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) @@ -336,6 +372,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 } @@ -381,6 +418,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 +533,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/meta.scala b/src/source/meta.scala index 2c21827f..89f09e1a 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,17 @@ object MExtern { module: String, // The module to import for the type generic: Boolean ) + case class Swift( + typename: String, + module: String, + translator: String, + translatorModule: 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/src/source/parser.scala b/src/source/parser.scala index 9be204cb..b854794e 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 @@ -145,6 +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 "error" => Record.DerivingType.Error case _ => return err( s"""Unrecognized deriving type "${ident.name}"""") }).toSet } @@ -371,6 +386,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 384ea200..e51c3093 100644 --- a/support-lib/BUILD +++ b/support-lib/BUILD @@ -1,5 +1,6 @@ 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", @@ -77,3 +78,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-swiftxx", + "@apple_swift_protobuf//:swift-protobuf" + ], + 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=DjinniSupportCxx"], + visibility = ["//visibility:public"], +) 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/cpp/Future.hpp b/support-lib/cpp/Future.hpp index fc2adffb..6e94152e 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 @@ -23,16 +25,22 @@ #include #include #include +#include + +#ifdef __has_include +#if __has_include() +#include +#endif +#endif -#ifdef __cpp_coroutines -#if __has_include() +#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; @@ -40,13 +48,18 @@ } #define DJINNI_FUTURE_HAS_COROUTINE_SUPPORT 1 #endif -#endif 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 @@ -55,7 +68,7 @@ template struct ValueHolder { using type = T; std::optional value; - T getValueUnsafe() const {return *value;} + T getValueUnsafe() {return std::move(*value);} }; template <> struct ValueHolder { @@ -110,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. @@ -216,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 @@ -232,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);} @@ -365,32 +384,62 @@ class Future { struct PromiseTypeBase { Promise _promise; + std::optional> _result{}; + + struct FinalAwaiter { + constexpr bool await_ready() const noexcept { + return false; + } + template + bool await_suspend(detail::CoroutineHandle

finished) const noexcept { + static_assert(std::is_convertible_v); + 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 @@ -414,7 +463,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/cpp/SharedFuture.hpp b/support-lib/cpp/SharedFuture.hpp new file mode 100644 index 00000000..938118ae --- /dev/null +++ b/support-lib/cpp/SharedFuture.hpp @@ -0,0 +1,162 @@ +/** + * 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" + +#if defined(DJINNI_FUTURE_HAS_COROUTINE_SUPPORT) + +#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 { + waitIgnoringExceptions().wait(); + } + + decltype(auto) get() const { + wait(); + 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 + 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 { + std::scoped_lock lock(_sharedStates->mutex); + return _sharedStates->storedValue.has_value(); + } + + decltype(auto) await_resume() const { + if (!*_sharedStates->storedValue) { + std::rethrow_exception(_sharedStates->storedValue->error()); + } + if constexpr (!std::is_void_v) { + return const_cast(_sharedStates->storedValue->value()); + } + } + + 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: + Future waitIgnoringExceptions() const { + try { + co_await *this; + } catch (...) { + // Ignore exceptions. + } + } + + struct SharedStates { + std::recursive_mutex mutex; + std::optional> 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); + try { + if constexpr (std::is_void_v) { + futureResult.get(); + sharedStates->storedValue.emplace(); + } else { + sharedStates->storedValue = futureResult.get(); + } + } catch (...) { + sharedStates->storedValue = make_unexpected(std::current_exception()); + } + 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 + +#endif diff --git a/support-lib/cpp/expected.hpp b/support-lib/cpp/expected.hpp index d3143fc7..0cd3c265 100644 --- a/support-lib/cpp/expected.hpp +++ b/support-lib/cpp/expected.hpp @@ -1,15 +1,45 @@ #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; +inline constexpr ::std::unexpect_t unexpect{}; + +} + +#else + #include "tl_expected.hpp" namespace djinni { using ::tl::unexpected; using ::tl::expected; +inline constexpr ::tl::unexpect_t unexpect{}; + +} + +#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)); } } diff --git a/support-lib/dataref.yaml b/support-lib/dataref.yaml index 9b404575..e32bf8c4 100644 --- a/support-lib/dataref.yaml +++ b/support-lib/dataref.yaml @@ -36,3 +36,12 @@ ts: composer: translator: '::djinni::composer::NativeDataRef' header: '"$DataRef_composer.hpp"' +swift: + 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 6edc19f7..8d9dea9e 100644 --- a/support-lib/dataview.yaml +++ b/support-lib/dataview.yaml @@ -36,3 +36,12 @@ ts: composer: translator: '::djinni::composer::NativeDataView' header: '"$DataView_composer.hpp"' +swift: + 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 b2c922ac..61286327 100644 --- a/support-lib/future.yaml +++ b/support-lib/future.yaml @@ -39,3 +39,12 @@ ts: composer: translator: '::djinni::composer::FutureAdaptor' header: '"$Future_composer.hpp"' +swift: + typename: 'DJFuture' + module: 'DjinniSupport' + translator: 'FutureMarshaller' + translator.module: 'DjinniSupport' + generic: true +swiftxx: + translator: '::djinni::swift::FutureAdaptor' + header: '"$Future_swift.hpp"' diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index 371c452f..b3d2e845 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,11 +319,16 @@ namespace djinni } } - static LocalRef fromCpp(JNIEnv* jniEnv, const OptionalType &c) - { - return c ? T::Boxed::fromCpp(jniEnv, *c) : LocalRef{}; + static LocalRef fromCpp(JNIEnv* jniEnv, const OptionalType& c) { + return c ? T::Boxed::fromCpp(jniEnv, *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 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/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) { diff --git a/support-lib/outcome.yaml b/support-lib/outcome.yaml index 5d859d7f..ae875e0a 100644 --- a/support-lib/outcome.yaml +++ b/support-lib/outcome.yaml @@ -39,3 +39,11 @@ ts: composer: translator: '::djinni::composer::Outcome' header: '"$Outcome_composer.hpp"' +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..5d52cd4f --- /dev/null +++ b/support-lib/swift/DJData.swift @@ -0,0 +1,39 @@ +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 { + 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 { + 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 { + 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 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) + } + } +} diff --git a/support-lib/swift/DJFuture.swift b/support-lib/swift/DJFuture.swift new file mode 100644 index 00000000..9ac37be0 --- /dev/null +++ b/support-lib/swift/DJFuture.swift @@ -0,0 +1,183 @@ +import DjinniSupportCxx +import Foundation + +// A custom Future<> type thanks to Logan Shire <@LoganShireSnapchat> +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 + + // 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 = [Token : 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 token = generateToken() + return try await withTaskCancellationHandler { + return try await withCheckedThrowingContinuation { continuation in + self.subscribe(token: token) { result in + continuation.resume(with: result) + } + } + } onCancel: { + self.cancel(token: token) + } + } + } + + public func getResult(subscription: @escaping Promise) -> Cancellable { + let token = generateToken() + self.subscribe(token: token, subscription: subscription) + return Cancellable { + self.cancel(token: token) + } + } + + // MARK: Private + + private func subscribe(token: Token, subscription: @escaping Promise) { + self.lock.lock() + defer { self.lock.unlock() } + + if let result = self.storedResult { + subscription(result) + return + } + + self.subscriptions[token] = subscription + } + + private func cancel(token: Token) { + self.lock.lock() + self.subscriptions[token] = nil + self.lock.unlock() + } +} + +// 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) { + 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)))) + } + } +} +// 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?) + -> Void { + let ctx = Unmanaged.fromOpaque(ptr!).takeRetainedValue() + let promiseHolder = ctx as! AbstractPromiseHolder + 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() +} + +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 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, error.wrapped) + djinni.swift.setFutureResult(&futureValue, &errorValue) + } + } + // 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/support-lib/swift/DJMarshal.swift b/support-lib/swift/DJMarshal.swift new file mode 100644 index 00000000..9dcf1f14 --- /dev/null +++ b/support-lib/swift/DJMarshal.swift @@ -0,0 +1,211 @@ +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 { + return SwiftType(rawValue: djinni.swift.I32.toCpp(v))! + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + 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 { + return SwiftType(exactly: djinni.swift.I32.toCpp(v))! + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + 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 { + return SwiftType(exactly: djinni.swift.I64.toCpp(v))! + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + 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 { + return T(djinni.swift.F64.toCpp(v)) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + 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 { + return djinni.swift.I32.toCpp(v) != 0 + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return djinni.swift.I32.fromCpp(s ? 1 : 0) + } +} +// Aliases for number types +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 Void_Marshaller: 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 + } +} + +// 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 { + 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..2ce143dc --- /dev/null +++ b/support-lib/swift/DJOutcome.swift @@ -0,0 +1,34 @@ +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 + 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..7019512a --- /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(serializedData: bin) + } else { + return T() + } + } + static public func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + let bin: Data = try! s.serializedData() + return BinaryMarshaller.toCpp(bin) + } +} diff --git a/support-lib/swift/DjinniSupport.swift b/support-lib/swift/DjinniSupport.swift new file mode 100644 index 00000000..379e90c2 --- /dev/null +++ b/support-lib/swift/DjinniSupport.swift @@ -0,0 +1,176 @@ +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] + +// 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 +} + +// 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 + init(inst: T, vtbl: Vtbl) { + self.inst = inst + self.vtbl = vtbl + } + 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 { + djinni.swift.setErrorValue(ret, error.wrapped) + } catch { + djinni.swift.setErrorMessage(ret, std.string(String(describing: error))) + } + } + 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?, // 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 } + 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) + } +} + +// 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 { + // 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. + // 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++ + // 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 +public func cppInterfaceToSwift(_ c: djinni.swift.AnyValue, + _ newProxyFunc: ()->I) -> I { + return withUnsafePointer(to: c) { p in + let info = djinni.swift.getInterfaceInfo(p) + // 1. Check the CppProxyCache + if let s = CppProxyCache.shared.mapPtrToProxy[info.cppPointer] { + return Unmanaged.fromOpaque(s).takeUnretainedValue() as! I + } + // 2. Check if c++ ptr exists in SwiftProxyCache + if let pctx = info.ctxPointer { + let ctx = Unmanaged.fromOpaque(pctx).takeUnretainedValue() as! GenericProtocolWrapperContext + return ctx.getInst() as! I + } + // 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 + } +} + +// 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: ()->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. 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() +} + +// Wraps C++ ErrorValue as a Swift throwable Error +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 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/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..8fa74d50 --- /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 new file mode 100644 index 00000000..93ab028d --- /dev/null +++ b/support-lib/swiftxx/Future_swift.hpp @@ -0,0 +1,107 @@ +#pragma once + +#include "djinni_support.hpp" +#include "../cpp/Future.hpp" + +namespace djinni::swift { + +// Swift function prototypes called by C++ +typedef void (*FutureCb)(void* ctx, AnyValue* result); +typedef void (*CleanupCb)(void* subscription); + +// 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 CppFutureHolder: AbstractCppFutureHolder { + using CppResType = typename RESULT::CppType; + djinni::Future future; + explicit CppFutureHolder(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) { + try { + auto v = getFutureResult(f); + cb(ctx, &v); + } catch (ErrorValue& e) { + AnyValue errorValue = e; + cb(ctx, &errorValue); + } + }); + } +}; + +// 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; + SwiftFutureHolder(CleanupCb cleanup) { + this->cleanup = cleanup; + this->future = std::make_shared>(promise.getFuture()); + } + ~SwiftFutureHolder() override { + cleanup(subscription); + } + void setValue(const AnyValue* futureValue) { + promise.setValue(*futureValue); + } +}; + +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) { + // 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); + } + // Acquire the holder for Swift future + auto swiftHolder = std::dynamic_pointer_cast(std::get(o)); + Promise p; + auto f = p.getFuture(); + // 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 { + setValue(p, res); + } + }); + return f; + } + 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 new file mode 100644 index 00000000..ca97a656 --- /dev/null +++ b/support-lib/swiftxx/djinni_support.cpp @@ -0,0 +1,120 @@ +#include "djinni_support.hpp" + +namespace djinni::swift { + +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 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) { + 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); +} + +AnyValue getMember(const ParameterList* v, size_t i) { + return v->getValue(i); +} + +void addMember(AnyValue* c, const AnyValue& v) { + auto composite = std::get(*c); + composite->addValue(v); +} + +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; +} + +AnyValue strongify(const WeakSwiftProxy& v) { + return {v.lock()}; +} + +InterfaceInfo getInterfaceInfo(const AnyValue* v) { + auto i = std::get(*v); + return {i.ptr.get(), i.sptr ? i.sptr->ctx() : nullptr }; +} + +AnyValue makeVoidValue() { + return VoidValue{}; +} + +bool isVoidValue(const AnyValue* c) { + return std::holds_alternative(*c); +} + + +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) +{} + +ProtocolWrapper::~ProtocolWrapper() { + _dispatcher(_ctx, -1, nullptr, nullptr); +} + +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 new file mode 100644 index 00000000..4056d536 --- /dev/null +++ b/support-lib/swiftxx/djinni_support.hpp @@ -0,0 +1,339 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace djinni::swift { +// -------- Intermediate data structure and functions to manipulate them from Swift +struct VoidValue{}; +// I32 covers bool, i8, i16, i32, enum +using I32Value = int32_t; +using I64Value = int64_t; +// double covers float too +using DoubleValue = double; +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 { + 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; + +struct OpaqueValue { + virtual ~OpaqueValue() = default; +}; +using OpaqueValuePtr = std::shared_ptr; + +using AnyValue = std::variant; + +struct CompositeValue { + virtual ~CompositeValue() = default; + std::vector _elems; + + 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(); } +}; + +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); +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; + 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; + 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) +template +struct Number { + using CppType = T; + static AnyValue fromCpp(T v) { + return {static_cast(v)}; + } + static T toCpp(const AnyValue& v) { + auto i = std::get(v); + return static_cast(i); + } +}; + +using Bool = Number; +using I8 = Number; +using I16 = Number; +using I32 = Number; +using I64 = Number; +using F32 = Number; +using F64 = Number; + +template +struct Enum { + using CppType = T; + static AnyValue fromCpp(T v) { + return {static_cast(v)}; + } + static T toCpp(const AnyValue& v) { + auto i = std::get(v); + return static_cast(i); + } +}; + +struct String { + using CppType = std::string; + static AnyValue fromCpp(const CppType& c) { + return c; + } + static CppType toCpp(const AnyValue& v) { + 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); + } +}; + +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; + } +}; + +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 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{}; + } else { + return T::toCpp(v); + } + } + template + static AnyValue fromCpp(const typename C::CppOptType& cppOpt) { + return cppOpt ? T::fromCppOpt(cppOpt) : makeVoidValue(); + } +}; + +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 makeBinaryValue(c.data(), c.size()); + } + static CppType toCpp(const AnyValue& v) { + return std::get(v); + } +}; + +class Void { +public: + using CppType = void; +}; + +template +struct Interface { + using CppType = std::shared_ptr; + 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}; + } +}; + +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/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); diff --git a/test-suite/BUILD b/test-suite/BUILD index fa6cb8dd..1ca43ba2 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( @@ -55,6 +56,7 @@ objc_library( copts = [ "-ObjC++", "-std=c++17", + "-fcoroutines-ts" ], srcs = glob([ "generated-src/objc/**/*.mm", @@ -191,3 +193,64 @@ sh_binary( data = glob(["handwritten-src/js/*.html", "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 = 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"], +) + +swift_library( + name = "test-swift-bridge", + module_name = "TestSuite", + srcs = glob([ + "generated-src/swift/*.swift", + swift_error_files, + swift_helper_files + ]), + copts = ["-cxx-interoperability-mode=default", "-Xcc", "-std=c++17",], + deps = [ + ":djinni-tests-common", + ":test-swiftxx", + "//support-lib:djinni-support-swift", + "//support-lib:djinni-support-swiftxx", + ":protobuf-test-swift" + ], + 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([ + "generated-src/swiftxx/*.cpp", + ]), + hdrs = glob([ + "generated-src/swiftxx/*.hpp", + ]), + includes = [ + "generated-src/swiftxx", + ".", + ], + deps = [ + ":djinni-tests-common", + "//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/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/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 dc0845f3..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; } @@ -82,7 +82,7 @@ Conflict = interface +c { } conflict_user = interface +c { Conflict(): Conflict; - conflict_arg(cs: set): bool; + conflict_arg(cs: list): bool; } # we need to test optional interface 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 82f10f38..185bb592 100644 --- a/test-suite/djinni/vendor/third-party/date.yaml +++ b/test-suite/djinni/vendor/third-party/date.yaml @@ -37,3 +37,10 @@ wasm: ts: typename: 'Date' module: '' +swift: + typename: 'Date' + translator: 'DateMarshaller' + 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 4a8b2d23..d931bd60 100644 --- a/test-suite/djinni/vendor/third-party/duration.yaml +++ b/test-suite/djinni/vendor/third-party/duration.yaml @@ -38,6 +38,13 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationMarshaller' + translator.module: 'TestSuite' +swiftxx: + translator: '::djinni::swift::Duration' + header: '"Duration-swift.hpp"' --- name: h typedef: 'record' @@ -74,6 +81,13 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationH' + translator.module: 'TestSuite' +swiftxx: + translator: '::djinni::swift::Duration_h' + header: '"Duration-swift.hpp"' --- name: min typedef: 'record' @@ -110,6 +124,13 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationMin' + translator.module: 'TestSuite' +swiftxx: + translator: '::djinni::swift::Duration_min' + header: '"Duration-swift.hpp"' --- name: s typedef: 'record' @@ -146,6 +167,13 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationS' + translator.module: 'TestSuite' +swiftxx: + translator: '::djinni::swift::Duration_s' + header: '"Duration-swift.hpp"' --- name: ms typedef: 'record' @@ -182,6 +210,13 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationMs' + translator.module: 'TestSuite' +swiftxx: + translator: '::djinni::swift::Duration_ms' + header: '"Duration-swift.hpp"' --- name: us typedef: 'record' @@ -218,6 +253,13 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationUs' + translator.module: 'TestSuite' +swiftxx: + translator: '::djinni::swift::Duration_us' + header: '"Duration-swift.hpp"' --- name: ns typedef: 'record' @@ -254,3 +296,10 @@ wasm: ts: typename: 'number' module: '' +swift: + typename: 'Duration' + translator: 'DurationNs' + translator.module: 'TestSuite' +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..4b9a1a82 --- /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 + +public 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..647b4657 --- /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 + +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)) + 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) + } + } + 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)) + 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..f4a86001 --- /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 = DjinniSupport.FutureMarshaller.fromCpp(djinni.swift.getMember(params, 0)) + djinni.swift.setReturnValue(ret, try DjinniSupport.FutureMarshaller.toCpp(inst.futureRoundtrip(_f))) + }, +] + +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") }) + } + 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 new file mode 100644 index 00000000..749fd1eb --- /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: 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 new file mode 100644 index 00000000..5399ffdd --- /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, 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, 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))) + }, + { inst, params, ret in + let _i = OptionalMarshaller.fromCpp(djinni.swift.getMember(params, 0)) + djinni.swift.setReturnValue(ret, try StringMarshaller.toCpp(inst.methTakingOptionalInterface(_i))) + }, +] + +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") }) + } + 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/ClientInterface.swift b/test-suite/generated-src/swift/ClientInterface.swift new file mode 100644 index 00000000..74a7f072 --- /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..9510131e --- /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 + +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)) + let misc = OptionalMarshaller.fromCpp(djinni.swift.getMember(p, 2)) + return SwiftType(recordId: recordId, content: content, misc: misc) + } + } + 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)) + 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..8c4d2207 --- /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 + +public 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..e889c093 --- /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) } +} +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 }) + } + public 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..0062fe83 --- /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(&_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(&_params) + try handleCppErrors(&ret) + return BoolMarshaller.fromCpp(ret) + } +} +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 }) + } + public 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..7a5d7f90 --- /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..3bc3f10b --- /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 + +public 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..4ff4d526 --- /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) } +} +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 }) + } + public 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..702ad583 --- /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 + +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) + } + } + 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)) + 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..207197d9 --- /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 + +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() + } + } + public 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..a41694ae --- /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 + +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() + } + } + public 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..983df413 --- /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(&_params) + try handleCppErrors(&ret) + } +} +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 }) + } + public 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..0275ec7d --- /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(&_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(&_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(&_params) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class CppException_statics { + 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/CppException.swift b/test-suite/generated-src/swift/CppException.swift new file mode 100644 index 00000000..08b1c0a5 --- /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..fb0f01f9 --- /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: 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(&_params) + try handleCppErrors(&ret) + return BinaryMarshaller.fromCpp(ret) + } + 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 -> Foundation.NSData { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.DataRefTest_generateData(&_params) + try handleCppErrors(&ret) + return DjinniSupport.DataRefMarshaller.fromCpp(ret) + } + func dataFromVec() throws -> Foundation.NSData { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.DataRefTest_dataFromVec(&_params) + try handleCppErrors(&ret) + return DjinniSupport.DataRefMarshaller.fromCpp(ret) + } + func dataFromStr() throws -> Foundation.NSData { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.DataRefTest_dataFromStr(&_params) + try handleCppErrors(&ret) + return DjinniSupport.DataRefMarshaller.fromCpp(ret) + } + 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 -> Foundation.NSData { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.DataRefTest_recvDataView(&_params) + try handleCppErrors(&ret) + return DjinniSupport.DataViewMarshaller.fromCpp(ret) + } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class DataRefTest_statics { + 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 new file mode 100644 index 00000000..7c87d637 --- /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: Foundation.NSData) throws -> Void + func retriveAsBin() throws -> Data + 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 new file mode 100644 index 00000000..9b437108 --- /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 + +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) + } + } + 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 new file mode 100644 index 00000000..d302a076 --- /dev/null +++ b/test-suite/generated-src/swift/DateRecord.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from date.djinni + +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..c1202c70 --- /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 + +public 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..21b1297e --- /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 + +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() + } + } + public 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..04e3cb5a --- /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(&_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(&_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(&_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(&_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(&_params) + try handleCppErrors(&ret) + return MapMarshaller.fromCpp(ret) + } +} +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 }) + } + public 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..91544e69 --- /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..61049fde --- /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 + +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)) + 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) + } + } + 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)) + 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..e714141d --- /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 + +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) + } + } + 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/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..df7401c6 --- /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: 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 TestSuite.ClientReturnedRecordMarshaller.fromCpp(ret) + } + 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 TestSuite.ColorMarshaller.fromCpp(ret) + } +} +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 }) + } + 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 new file mode 100644 index 00000000..aa4bed10 --- /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: 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 new file mode 100644 index 00000000..41a35029 --- /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 + +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") }) + } + 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 new file mode 100644 index 00000000..54098b6a --- /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: 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 new file mode 100644 index 00000000..c31201a5 --- /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 + +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 = TestSuite.RecordWithDerivingsMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + let e = TestSuite.ColorMarshaller.fromCpp(djinni.swift.getMember(p, 1)) + return SwiftType(member: member, e: e) + } + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + 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 new file mode 100644 index 00000000..07231672 --- /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: TestSuite.RecordWithDerivings + public var e: TestSuite.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 new file mode 100644 index 00000000..5148020b --- /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 */ +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") }) + } + public 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..c0d2c9d9 --- /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) } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class FlagRoundtrip_statics { + 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) + } + 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) + } + 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) + } + 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/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..7f402fce --- /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(&_params) + try handleCppErrors(&ret) + return ExtendedRecordMarshaller.fromCpp(ret) + } +} +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 }) + } + public 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..e2cdac54 --- /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..c0e8357a --- /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 + +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") }) + } + public 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..d07ce76d --- /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(&_params) + try handleCppErrors(&ret) + } + func callSecond() throws -> Void { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.ListenerCaller_callSecond(&_params) + try handleCppErrors(&ret) + } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class ListenerCaller_statics { + 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/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..3c0b083f --- /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 + +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) + } + } + 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 new file mode 100644 index 00000000..043dda69 --- /dev/null +++ b/test-suite/generated-src/swift/MapDateRecord.swift @@ -0,0 +1,13 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from date.djinni + +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..a025632e --- /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 + +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) + } + } + 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/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..06c4e566 --- /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 + +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) + } + } + 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)) + 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..6d65cb51 --- /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 + +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) + } + } + 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/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..c946149d --- /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 + +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 = DjinniSupport.OutcomeMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(o: o) + } + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, DjinniSupport.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..431dc77c --- /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 + +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") }) + } + public 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..7dfd79f6 --- /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 + +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) + } + } + 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/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..2c40543a --- /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) } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class ProtoTests_statics { + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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 DjinniSupport.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..2ca84baa --- /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 + +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) + } + } + 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/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..5d77e861 --- /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 + +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)) + 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) + } + } + 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)) + 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..8b328d9f --- /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 + +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 = TestSuite.DurationMarshaller.fromCpp(djinni.swift.getMember(p, 0)) + return SwiftType(dt: dt) + } + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + var ret = djinni.swift.makeCompositeValue() + djinni.swift.addMember(&ret, TestSuite.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..c39aa40d --- /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 + +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) + } + } + 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/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..56bddf95 --- /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 + +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) + } + } + 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/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..f27754e7 --- /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 + +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) + } + } + 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/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..a2f921fd --- /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 + +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) + } + } + 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)) + 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..6f69316d --- /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(&_params) + try handleCppErrors(&ret) + return I8Marshaller.fromCpp(ret) + } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class ReturnOne_statics { + 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/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..1040aa68 --- /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(&_params) + try handleCppErrors(&ret) + return I8Marshaller.fromCpp(ret) + } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class ReturnTwo_statics { + 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/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..9f24d723 --- /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(&_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(&_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(&_params) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class ReverseClientInterface_statics { + 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/ReverseClientInterface.swift b/test-suite/generated-src/swift/ReverseClientInterface.swift new file mode 100644 index 00000000..4a85a005 --- /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..7a215df5 --- /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) } +} +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 }) + } + public 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..4969555d --- /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 */ +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") }) + } + public 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..41e002f2 --- /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 + +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) + } + } + 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)) + 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..2699d1c3 --- /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 + +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) + } + } + 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/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..99cde923 --- /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) } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class TestArray_statics { + 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) + } + 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) + } + 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) + } + 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/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..91aeb8ce --- /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) } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class TestDuration_statics { + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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 TestSuite.DurationMarshaller.fromCpp(ret) + } + 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 TestSuite.DurationMarshaller.fromCpp(ret) + } + 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 TestSuite.DurationMarshaller.fromCpp(ret) + } + 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 TestSuite.DurationMarshaller.fromCpp(ret) + } + 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 TestSuite.DurationMarshaller.fromCpp(ret) + } + 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 TestSuite.DurationMarshaller.fromCpp(ret) + } + 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 TestSuite.DurationMarshaller.fromCpp(ret) + } + 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 TestSuite.DurationMarshaller.fromCpp(ret) + } + 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 TestSuite.DurationMarshaller.fromCpp(ret) + } + 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 TestSuite.DurationMarshaller.fromCpp(ret) + } + 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 TestSuite.DurationMarshaller.fromCpp(ret) + } + 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 TestSuite.DurationMarshaller.fromCpp(ret) + } + 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) + } + 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/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..64e4605d --- /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) } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class TestHelpers_statics { + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + public static func getAsyncResult() throws -> DjinniSupport.DJFuture { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_getAsyncResult(&_params) + try handleCppErrors(&ret) + return DjinniSupport.FutureMarshaller.fromCpp(ret) + } + 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 DjinniSupport.FutureMarshaller.fromCpp(ret) + } + public static func asyncEarlyThrow() throws -> DjinniSupport.DJFuture { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestHelpers_asyncEarlyThrow(&_params) + try handleCppErrors(&ret) + return DjinniSupport.FutureMarshaller.fromCpp(ret) + } + 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 DjinniSupport.FutureMarshaller.fromCpp(ret) + } + 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 DjinniSupport.FutureMarshaller>.fromCpp(ret) + } + 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 DjinniSupport.FutureMarshaller.fromCpp(ret) + } + 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 DjinniSupport.FutureMarshaller.fromCpp(ret) + } + 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 DjinniSupport.FutureMarshaller.fromCpp(ret) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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/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..6cdb3f93 --- /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 + +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)) + return SwiftType(sampleInterface: sampleInterface) + } + } + public 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..5a4e87f9 --- /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..523d8a9e --- /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) } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class TestOutcome_statics { + public static func getSuccessOutcome() throws -> Result { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestOutcome_getSuccessOutcome(&_params) + try handleCppErrors(&ret) + return DjinniSupport.OutcomeMarshaller.fromCpp(ret) + } + public static func getErrorOutcome() throws -> Result { + var _params = djinni.swift.ParameterList() + var ret = djinni_generated.TestOutcome_getErrorOutcome(&_params) + try handleCppErrors(&ret) + return DjinniSupport.OutcomeMarshaller.fromCpp(ret) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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) + } + 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/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..eddfb115 --- /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) } +} +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 }) + } + public 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..21d6d3d1 --- /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() + }, +] + +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") }) + } + 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/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..8583a3ab --- /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(&_params) + try handleCppErrors(&ret) + return StringMarshaller.fromCpp(ret) + } +} +let userTokenMethods: Vtbl = [ + { inst, params, ret in + djinni.swift.setReturnValue(ret, try StringMarshaller.toCpp(inst.whoami())) + }, +] + +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 }) + } + 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/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..923f55d4 --- /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(&_params) + try handleCppErrors(&ret) + } + func returnForObjC() throws -> TestSuite.ObjcOnlyListener { + 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(&_params) + try handleCppErrors(&ret) + } + func returnForJava() throws -> TestSuite.JavaOnlyListener { + var _params = djinni.swift.ParameterList() + _params.addValue(inst) + var ret = djinni_generated.UsesSingleLanguageListeners_returnForJava(&_params) + try handleCppErrors(&ret) + return JavaOnlyListenerMarshaller.fromCpp(ret) + } +} +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 }) + } + public 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..3209f748 --- /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..c158f511 --- /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(&_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(&_params) + try handleCppErrors(&ret) + return VarnameInterfaceMarshaller.fromCpp(ret) + } +} +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 }) + } + public 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..6d7bc842 --- /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..79758f5d --- /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 + +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) + } + } + 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/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..0fce6515 --- /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 + +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) + } + } + 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)) + 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..d89d5b72 --- /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) } +} +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 }) + } + public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue { + return swiftInterfaceToCpp(s, { fatalError("n/a") }) + } +} +public class WcharTestHelpers_statics { + 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) + } + 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) + } + 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) + } + 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/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..4e4fb9ff --- /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 + +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) + } + } + public 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/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", 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..e562b845 --- /dev/null +++ b/test-suite/handwritten-src/objc/tests/DBCppFutureTests.mm @@ -0,0 +1,102 @@ +#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 + +- (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 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..c0b5ae2f --- /dev/null +++ b/test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm @@ -0,0 +1,91 @@ +#import +#import + +#include "../../../support-lib/cpp/SharedFuture.hpp" + +@interface DBSharedFutureTest : XCTestCase +@end + +@implementation DBSharedFutureTest + +#ifdef DJINNI_FUTURE_HAS_COROUTINE_SUPPORT + +- (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.thenShared([](const auto& resolved) { return 2 * resolved.get(); }); + + intPromise.setValue(42); + XCTAssertEqual(transformedInt.get(), 84); + + // Also verify multiple consumers and chaining. + 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([](auto resolved) { return resolved.get().length(); }); + + XCTAssertEqual(transformedString.get(), std::string("42")); + XCTAssertEqual(futurePlusOneTimesTwo.get(), (42 + 1) * 2); + XCTAssertEqual(futureStringLen.get(), 2); + + XCTAssertEqual(futureInt.get(), 42); + + auto voidFuture = transformedString.thenShared([](auto) {}); + voidFuture.wait(); + + auto intFuture2 = voidFuture.thenShared([](auto) { return 43; }); + 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([](auto resolved) { return resolved.get(); }); + XCTAssertThrows(thenResult.get()); + + auto withExceptionHandling = futureInt.thenShared([](const auto& resolved) { + try { + return resolved.get(); + } catch (...) { + return -1; + } + }); + withExceptionHandling.wait(); + XCTAssertEqual(withExceptionHandling.get(), -1); +} + +#endif + +@end diff --git a/test-suite/handwritten-src/swift/ArrayTest.swift b/test-suite/handwritten-src/swift/ArrayTest.swift new file mode 100644 index 00000000..1dff6673 --- /dev/null +++ b/test-suite/handwritten-src/swift/ArrayTest.swift @@ -0,0 +1,22 @@ +import XCTest +@testable import TestSuite + +final class ArrayTest: XCTestCase { + func testArrays() throws { + let inputStrings = ["1", "2", "3"] + let expectedStrings = ["3", "2", "1"] + XCTAssertEqual(try TestArray_statics.testStringArray(inputStrings), expectedStrings) + + let inputIntegers: [Int32] = [1, 2, 3] + let expectedIntegers: [Int32] = [3, 2, 1] + 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(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(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..d4fc246b --- /dev/null +++ b/test-suite/handwritten-src/swift/AsyncTest.swift @@ -0,0 +1,114 @@ +import XCTest +import DjinniSupport +@testable import TestSuite + +final class AsyncTest: XCTestCase { + + class AsyncInterfaceImpl: AsyncInterface { + func futureRoundtrip(_ f: DJFuture) throws -> DJFuture { + var token: Cancellable? = nil + return DJFuture() { promise in + token = f.getResult { result in + switch result { + case .success(let value): + promise(.success(String(value))) + case .failure: + XCTFail() + } + token = withExtendedLifetime(token) {nil} + } + } + } + } + + 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 cancellable: Cancellable? = nil + let f2 = DJFuture() { promise in + 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") + cancellable = withExtendedLifetime(cancellable) {nil} + } + + func testVoidRoundtrip() async throws { + let f = DJFuture() { promise in + promise(.success(())) + } + let f1 = try TestHelpers_statics.voidAsyncMethod(f) + try await f1.value + } + + func testFutureRoundtripWithException() async throws { + var p: DJFuture.Promise? = nil + let f = DJFuture() { promise in + p = promise + } + var cancellable: Cancellable? = nil + let f2 = DJFuture() { promise in + cancellable = f.getResult { result in + switch result { + case .failure: + XCTFail() + case .success(_): + promise(.failure(DjinniError("123"))) + } + } + } + let f3 = try TestHelpers_statics.futureRoundtrip(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") + cancellable = withExtendedLifetime(cancellable){nil} + } + + func testFutureRoundtripBackwards() async throws { + let s = try await TestHelpers_statics.checkAsyncInterface(AsyncInterfaceImpl()).value + XCTAssertEqual(s, "36") + } + + func testFutureComposition() async throws { + let s = try await TestHelpers_statics.checkAsyncComposition(AsyncInterfaceImpl()).value + XCTAssertEqual(s, "42") + } + + func testOptionalFutureUnsetValue() async throws { + let input = DJFuture> { promise in + promise(.success(nil)) + } + let output = try await TestHelpers_statics.addOneIfPresent(input).value + XCTAssertNil(output) + } + + func testOptionalFutureSetValue() async throws { + let input = DJFuture> { promise in + promise(.success(10)) + } + 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 new file mode 100644 index 00000000..8380ecd2 --- /dev/null +++ b/test-suite/handwritten-src/swift/ClientInterfaceTest.swift @@ -0,0 +1,58 @@ +import XCTest +@testable import TestSuite + + +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(sClientInterface!) + } + + func testClientReturnUTF8() throws { + try TestHelpers_statics.checkClientInterfaceNonascii(sClientInterface!) + } + + func testClientInterfaceArgs() throws { + try TestHelpers_statics.checkClientInterfaceArgs(sClientInterface!) + } + + func testReverseClientInterfaceArgs() throws { + let i = try ReverseClientInterface_statics.create() + XCTAssertEqual(try i.methTakingInterface(i), "test") + XCTAssertEqual(try i.methTakingOptionalInterface(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..66d82fc3 --- /dev/null +++ b/test-suite/handwritten-src/swift/ConstantsTest.swift @@ -0,0 +1,15 @@ +import XCTest +import DjinniSupport +@testable import TestSuite + +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..112ae367 --- /dev/null +++ b/test-suite/handwritten-src/swift/CppExceptionTest.swift @@ -0,0 +1,29 @@ +import XCTest +import DjinniSupport +@testable import TestSuite + +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(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..ec76dac5 --- /dev/null +++ b/test-suite/handwritten-src/swift/DataTest.swift @@ -0,0 +1,54 @@ +import XCTest +import Foundation +@testable import TestSuite + +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(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(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(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..60756953 --- /dev/null +++ b/test-suite/handwritten-src/swift/DurationTest.swift @@ -0,0 +1,38 @@ +import XCTest +@testable import TestSuite + +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(.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(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(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(1), .seconds(1)) + XCTAssertNil(try TestDuration_statics.box(-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 new file mode 100644 index 00000000..2aedfe42 --- /dev/null +++ b/test-suite/handwritten-src/swift/EnumTest.swift @@ -0,0 +1,45 @@ +import XCTest +@testable import TestSuite + +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) + } + + 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)) + XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripAccessBoxed(flag)) + } + 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)) + XCTAssertEqual(flag, try FlagRoundtrip_statics.roundtripEmptyBoxed(flag)) + } + XCTAssertEqual(nil, try FlagRoundtrip_statics.roundtripEmptyBoxed(nil)) + } +} diff --git a/test-suite/handwritten-src/swift/MapRecordTest.swift b/test-suite/handwritten-src/swift/MapRecordTest.swift new file mode 100644 index 00000000..e7f09014 --- /dev/null +++ b/test-suite/handwritten-src/swift/MapRecordTest.swift @@ -0,0 +1,39 @@ +import XCTest +@testable import TestSuite + +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(["String1": 1, "String2": 2, "String3": 3])) + } + + func testEmptySwiftMapToCppMap() throws { + XCTAssertTrue(try TestHelpers_statics.checkEmptyMap([:])) + } + + func testSwiftMapListToCppMapList() throws { + let sMapList: [Dictionary] = [["String1": 1, "String2": 2, "String3": 3]] + XCTAssertTrue(try TestHelpers_statics.checkMapListRecord(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..0d101caf --- /dev/null +++ b/test-suite/handwritten-src/swift/NestedCollectionTest.swift @@ -0,0 +1,15 @@ +import XCTest +@testable import TestSuite + +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(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..7750ebe5 --- /dev/null +++ b/test-suite/handwritten-src/swift/OutcomeTest.swift @@ -0,0 +1,41 @@ +import XCTest +@testable import TestSuite + +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(.success("hello")), "hello"); + // construct error outcome in swift then pass to native and back + XCTAssertEqual(try TestOutcome_statics.putErrorOutcome(.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(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 new file mode 100644 index 00000000..ad6e5528 --- /dev/null +++ b/test-suite/handwritten-src/swift/PrimitiveListTest.swift @@ -0,0 +1,19 @@ +import XCTest +@testable import TestSuite + +final class PrimitivesListTest: XCTestCase { + + let swiftPrimitiveList: PrimitiveList = PrimitiveList(list: [1, 2, 3]) + + func testSwiftPrimitiveListToCpp() throws { + XCTAssertTrue(try TestHelpers_statics.checkPrimitiveList(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) + } +} diff --git a/test-suite/handwritten-src/swift/PrimitivesTest.swift b/test-suite/handwritten-src/swift/PrimitivesTest.swift new file mode 100644 index 00000000..0a25082a --- /dev/null +++ b/test-suite/handwritten-src/swift/PrimitivesTest.swift @@ -0,0 +1,10 @@ +import XCTest +@testable import TestSuite + +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(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..e0b57021 --- /dev/null +++ b/test-suite/handwritten-src/swift/ProtoTest.swift @@ -0,0 +1,60 @@ +import XCTest +@testable import ProtobufTest +@testable import TestSuite + +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(proto) + XCTAssertEqual(r[0], "tom") + XCTAssertEqual(r[1], "jerry") + } + + func testNativeToSwift() throws { + let names = ["tom", "jerry"] + 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([]) + let serialized: Data = try proto.serializedData() + 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(rec) + XCTAssertEqual(s, p.name) + let rec2 = try ProtoTests_statics.stringToEmbeddedProto(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(plist) + XCTAssertEqual(slist[0], "tom") + XCTAssertEqual(slist[1], "jerry") + + plist = try ProtoTests_statics.stringsToProtoList(slist) + XCTAssertEqual(plist[0].name, "tom") + XCTAssertEqual(plist[1].name, "jerry") + + let s = try ProtoTests_statics.optionalProtoToString(p1) + XCTAssertEqual(s, "tom") + let p = try ProtoTests_statics.stringToOptionalProto("tom") + XCTAssertEqual(p?.name, "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 new file mode 100644 index 00000000..c5afde12 --- /dev/null +++ b/test-suite/handwritten-src/swift/SetRecordTest.swift @@ -0,0 +1,19 @@ +import XCTest +@testable import TestSuite + +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(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..572d8726 --- /dev/null +++ b/test-suite/handwritten-src/swift/TokenTest.swift @@ -0,0 +1,46 @@ +import XCTest +@testable import TestSuite + +final class TokenTest: XCTestCase { + + class SwiftToken: UserToken { + func whoami() throws -> String { return "Swift" } + } + + func testTokens() throws { + let st = SwiftToken() + XCTAssertIdentical(try TestHelpers_statics.tokenId(st), st) + } + + func testNullToken() throws { + XCTAssertNil(try TestHelpers_statics.tokenId(nil)) + } + + func testCppToken() throws { + let ct = try TestHelpers_statics.createCppToken(); + XCTAssertIdentical(try TestHelpers_statics.tokenId(ct), ct) + try TestHelpers_statics.checkCppToken(ct) + } + + func testTokenType() throws { + try TestHelpers_statics.checkTokenType(SwiftToken(), type:"Swift") + try TestHelpers_statics.checkTokenType(TestHelpers_statics.createCppToken(), type:"C++"); + var threw = false + do { + try TestHelpers_statics.checkTokenType(SwiftToken(), type:"foo") + } catch { + threw = true + } + XCTAssertTrue(threw) + } + + func testNotCppToken() { + var threw = false + do { + try TestHelpers_statics.checkCppToken(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..2c8ccadd --- /dev/null +++ b/test-suite/handwritten-src/swift/WcharTest.swift @@ -0,0 +1,14 @@ +import XCTest +@testable import TestSuite + +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(STR2)) + XCTAssertTrue(try WcharTestHelpers_statics.checkRecord(WcharTestRec(s:STR1))) + } +} diff --git a/test-suite/run_djinni.sh b/test-suite/run_djinni.sh index 3623248d..b189fbd4 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" @@ -99,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_" \ @@ -135,6 +143,12 @@ fi --ts-out "$temp_out_relative/ts" \ --ts-module "test" \ \ + --swift-out "$temp_out_relative/swift" \ + --swift-module "TestSuite" \ + --swiftxx-out "$temp_out_relative/swiftxx" \ + --ident-swiftxx-class NativeFooBar \ + --ident-swiftxx-file NativeFooBar \ + \ --list-in-files "./generated-src/inFileList.txt" \ --list-out-files "./generated-src/outFileList.txt"\ \ @@ -298,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" \ ) @@ -318,6 +338,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"