From 98c6bd6c2151c5ce77a7c9a4aef65a06e47bbe5e Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Wed, 22 Jun 2016 16:01:25 -0700 Subject: [PATCH 01/39] Tweak contact info --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index b33f1e18e..ced65a077 100644 --- a/README.md +++ b/README.md @@ -428,7 +428,6 @@ Run `make test` to invoke the test suite, found in the test-suite subdirectory. * [Slides](https://bit.ly/djinnitalk2) and [video](https://bit.ly/djinnivideo2) from the CppCon 2015 about Djinni implementatino techniques, and the addition of Python. * You can see a [CppCon 2014 talk](https://www.youtube.com/watch?v=5AZMEm3rZ2Y) by app developers at Dropbox about their cross-platform experiences. - ## Authors - Kannan Goundan - Tony Grue @@ -439,5 +438,5 @@ Run `make test` to invoke the test suite, found in the test-suite subdirectory. - Andrew Twyman ## Contacts -- Jacob Potter - `djinni@j4cbo.com` - Andrew Twyman - `atwyman@dropbox.com` +- Jacob Potter - `djinni@j4cbo.com` From 85155c62145712b72e182f6c3d852401ea35d857 Mon Sep 17 00:00:00 2001 From: Danny Weinberg Date: Wed, 22 Jun 2016 15:39:48 -0700 Subject: [PATCH 02/39] Add an argument to JNI generation to allow for C++ headers for extended records to be in a separate location. --- src/source/JNIGenerator.scala | 12 +++++++++--- .../generated-src/jni/NativeExtendedRecord.hpp | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/source/JNIGenerator.scala b/src/source/JNIGenerator.scala index 20259a0ae..c36234ec0 100644 --- a/src/source/JNIGenerator.scala +++ b/src/source/JNIGenerator.scala @@ -35,11 +35,12 @@ class JNIGenerator(spec: Spec) extends Generator(spec) { def writeJniHppFile(name: String, origin: String, includes: Iterable[String], fwds: Iterable[String], f: IndentWriter => Unit, f2: IndentWriter => Unit = (w => {})) = writeHppFileGeneric(spec.jniHeaderOutFolder.get, spec.jniNamespace, spec.jniFileIdentStyle)(name, origin, includes, fwds, f, f2) - class JNIRefs(name: String) { + class JNIRefs(name: String, cppPrefixOverride: Option[String]=None) { var jniHpp = mutable.TreeSet[String]() var jniCpp = mutable.TreeSet[String]() - jniHpp.add("#include " + q(spec.jniIncludeCppPrefix + spec.cppFileIdentStyle(name) + "." + spec.cppHeaderExt)) + val cppPrefix = cppPrefixOverride.getOrElse(spec.jniIncludeCppPrefix) + jniHpp.add("#include " + q(cppPrefix + spec.cppFileIdentStyle(name) + "." + spec.cppHeaderExt)) jniHpp.add("#include " + q(spec.jniBaseLibIncludePrefix + "djinni_support.hpp")) spec.cppNnHeader match { case Some(nnHdr) => jniHpp.add("#include " + nnHdr) @@ -82,7 +83,12 @@ class JNIGenerator(spec: Spec) extends Generator(spec) { } override def generateRecord(origin: String, ident: Ident, doc: Doc, params: Seq[TypeParam], r: Record) { - val refs = new JNIRefs(ident.name) + val prefixOverride: Option[String] = if (r.ext.cpp) { + Some(spec.cppExtendedRecordIncludePrefix) + } else { + None + } + val refs = new JNIRefs(ident.name, prefixOverride) r.fields.foreach(f => refs.find(f.ty)) val jniHelper = jniMarshal.helperClass(ident) diff --git a/test-suite/generated-src/jni/NativeExtendedRecord.hpp b/test-suite/generated-src/jni/NativeExtendedRecord.hpp index 64ce0fc66..559316a40 100644 --- a/test-suite/generated-src/jni/NativeExtendedRecord.hpp +++ b/test-suite/generated-src/jni/NativeExtendedRecord.hpp @@ -3,8 +3,8 @@ #pragma once +#include "../../handwritten-src/cpp/extended_record.hpp" #include "djinni_support.hpp" -#include "extended_record.hpp" namespace djinni_generated { From 82f0751c3be428302ed8e9bd2fbf19b75fc51d35 Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Thu, 14 Jul 2016 17:11:18 +0300 Subject: [PATCH 03/39] c++ wide strings support --- src/source/CppMarshal.scala | 2 +- src/source/JNIMarshal.scala | 2 +- src/source/Main.scala | 4 +++ src/source/generator.scala | 1 + support-lib/jni/Marshal.hpp | 19 ++++++++++++ support-lib/jni/djinni_support.cpp | 23 ++++++++++++++ support-lib/jni/djinni_support.hpp | 3 ++ test-suite/djinni/wchar_test.djinni | 10 ++++++ .../cpp/wchar_test_helpers.cpp | 29 +++++++++++++++++ .../com/dropbox/djinni/test/AllTests.java | 1 + .../com/dropbox/djinni/test/WcharTest.java | 16 ++++++++++ test-suite/run_djinni.sh | 31 +++++++++++++++++++ 12 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 test-suite/djinni/wchar_test.djinni create mode 100644 test-suite/handwritten-src/cpp/wchar_test_helpers.cpp create mode 100644 test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java diff --git a/src/source/CppMarshal.scala b/src/source/CppMarshal.scala index 6304c47ca..fd991fa2d 100644 --- a/src/source/CppMarshal.scala +++ b/src/source/CppMarshal.scala @@ -145,7 +145,7 @@ class CppMarshal(spec: Spec) extends Marshal(spec) { } def base(m: Meta): String = m match { case p: MPrimitive => p.cName - case MString => "std::string" + case MString => if (spec.cppUseWideStrings) "std::wstring" else "std::string" case MDate => "std::chrono::system_clock::time_point" case MBinary => "std::vector" case MOptional => spec.cppOptionalTemplate diff --git a/src/source/JNIMarshal.scala b/src/source/JNIMarshal.scala index af6c2d52b..e9aaab342 100644 --- a/src/source/JNIMarshal.scala +++ b/src/source/JNIMarshal.scala @@ -98,7 +98,7 @@ class JNIMarshal(spec: Spec) extends Marshal(spec) { } case MOptional => "Optional" case MBinary => "Binary" - case MString => "String" + case MString => if (spec.cppUseWideStrings) "WString" else "String" case MDate => "Date" case MList => "List" case MSet => "Set" diff --git a/src/source/Main.scala b/src/source/Main.scala index 07ab15810..9b136caa9 100644 --- a/src/source/Main.scala +++ b/src/source/Main.scala @@ -35,6 +35,7 @@ object Main { var cppNnHeader: Option[String] = None var cppNnType: Option[String] = None var cppNnCheckExpression: Option[String] = None + var cppUseWideStrings: Boolean = false var javaOutFolder: Option[File] = None var javaPackage: Option[String] = None var javaCppException: Option[String] = None @@ -133,6 +134,8 @@ object Main { .text("The type to use for non-nullable pointers (as a substitute for std::shared_ptr)") opt[String]("cpp-nn-check-expression").valueName("
").foreach(x => cppNnCheckExpression = Some(x)) .text("The expression to use for building non-nullable pointers") + opt[Boolean]( "cpp-use-wide-strings").valueName("").foreach(x => cppUseWideStrings = x) + .text("Use wide strings in C++ code (default: false)") note("") opt[File]("jni-out").valueName("").foreach(x => jniOutFolder = Some(x)) .text("The folder for the JNI C++ output files (Generator disabled if unspecified).") @@ -293,6 +296,7 @@ object Main { cppNnHeader, cppNnType, cppNnCheckExpression, + cppUseWideStrings, jniOutFolder, jniHeaderOutFolder, jniIncludePrefix, diff --git a/src/source/generator.scala b/src/source/generator.scala index ea9876a4e..9629bab22 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -49,6 +49,7 @@ package object generatorTools { cppNnHeader: Option[String], cppNnType: Option[String], cppNnCheckExpression: Option[String], + cppUseWideStrings: Boolean, jniOutFolder: Option[File], jniHeaderOutFolder: Option[File], jniIncludePrefix: String, diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index c25b92487..8f257606b 100644 --- a/support-lib/jni/Marshal.hpp +++ b/support-lib/jni/Marshal.hpp @@ -178,6 +178,25 @@ namespace djinni } }; + struct WString + { + using CppType = std::wstring; + using JniType = jstring; + + using Boxed = WString; + + static CppType toCpp(JNIEnv* jniEnv, JniType j) + { + assert(j != nullptr); + return jniWStringFromString(jniEnv, j); + } + + static LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) + { + return {jniEnv, jniStringFromWString(jniEnv, c.c_str())}; + } + }; + struct Binary { using CppType = std::vector; diff --git a/support-lib/jni/djinni_support.cpp b/support-lib/jni/djinni_support.cpp index 8baad975a..d957aca27 100644 --- a/support-lib/jni/djinni_support.cpp +++ b/support-lib/jni/djinni_support.cpp @@ -371,6 +371,15 @@ jstring jniStringFromUTF8(JNIEnv * env, const std::string & str) { return res; } +jstring jniStringFromWString(JNIEnv * env, const std::wstring & str) { + + std::u16string utf16(str.begin(), str.end());; + jstring res = env->NewString( + reinterpret_cast(utf16.data()), utf16.length()); + DJINNI_ASSERT(res, env); + return res; +} + // UTF-16 decode helpers. static inline bool is_high_surrogate(char16_t c) { return (c >= 0xD800) && (c < 0xDC00); } static inline bool is_low_surrogate(char16_t c) { return (c >= 0xDC00) && (c < 0xE000); } @@ -441,6 +450,20 @@ std::string jniUTF8FromString(JNIEnv * env, const jstring jstr) { return out; } +std::wstring jniWStringFromString(JNIEnv * env, const jstring jstr) { + DJINNI_ASSERT(jstr, env); + const jsize length = env->GetStringLength(jstr); + jniExceptionCheck(env); + + const auto deleter = [env, jstr] (const jchar * c) { env->ReleaseStringChars(jstr, c); }; + std::unique_ptr ptr(env->GetStringChars(jstr, nullptr), + deleter); + + const char16_t* begin = reinterpret_cast(ptr.get()); + const char16_t* end = begin + length; + return std::wstring(begin, end); +} + DJINNI_WEAK_DEFINITION void jniSetPendingFromCurrent(JNIEnv * env, const char * ctx) noexcept { jniDefaultSetPendingFromCurrent(env, ctx); diff --git a/support-lib/jni/djinni_support.hpp b/support-lib/jni/djinni_support.hpp index 5d6ab6a86..a4fab781f 100644 --- a/support-lib/jni/djinni_support.hpp +++ b/support-lib/jni/djinni_support.hpp @@ -543,6 +543,9 @@ class JniLocalScope { jstring jniStringFromUTF8(JNIEnv * env, const std::string & str); std::string jniUTF8FromString(JNIEnv * env, const jstring jstr); +jstring jniStringFromWString(JNIEnv * env, const std::wstring & str); +std::wstring jniWStringFromString(JNIEnv * env, const jstring jstr); + class JniEnum { public: /* diff --git a/test-suite/djinni/wchar_test.djinni b/test-suite/djinni/wchar_test.djinni new file mode 100644 index 000000000..f08b62360 --- /dev/null +++ b/test-suite/djinni/wchar_test.djinni @@ -0,0 +1,10 @@ +wchar_test_rec = record { + s: string; +} + +wchar_test_helpers = interface +c { + static get_record() : wchar_test_rec; + static get_string() : string; + static check_string(s: string) : bool; + static check_record(r: wchar_test_rec) : bool; +} diff --git a/test-suite/handwritten-src/cpp/wchar_test_helpers.cpp b/test-suite/handwritten-src/cpp/wchar_test_helpers.cpp new file mode 100644 index 000000000..adc69e9b2 --- /dev/null +++ b/test-suite/handwritten-src/cpp/wchar_test_helpers.cpp @@ -0,0 +1,29 @@ +#include "wchar_test_helpers.hpp" +#include "wchar_test_rec.hpp" + +namespace testsuite { + +static const std::wstring str1 = L"some string with unicode \u263a symbol"; +static const std::wstring str2 = L"another string with unicode \u263b symbol"; + +WcharTestRec WcharTestHelpers::get_record() +{ + return WcharTestRec(str1); +} + +std::wstring WcharTestHelpers::get_string() +{ + return str2; +} + +bool WcharTestHelpers::check_string(const std::wstring & s) +{ + return s == str2; +} + +bool WcharTestHelpers::check_record(const WcharTestRec & r) +{ + return r.s == str1; +} + +} // namespace testsuite diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java index 56f90947b..b9239f958 100644 --- a/test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java @@ -22,6 +22,7 @@ public static Test suite() { mySuite.addTestSuite(TokenTest.class); mySuite.addTestSuite(DurationTest.class); mySuite.addTestSuite(MockRecordTest.class); + mySuite.addTestSuite(WcharTest.class); return mySuite; } diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java new file mode 100644 index 000000000..aa10c8d51 --- /dev/null +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java @@ -0,0 +1,16 @@ +package com.dropbox.djinni.test; + +import junit.framework.TestCase; + +public class WcharTest extends TestCase { + + private static final String STR1 = "some string with unicode \u263a symbol"; + private static final String STR2 = "another string with unicode \u263b symbol"; + + public void test() { + assertEquals(WcharTestHelpers.getRecord().getS(), STR1); + assertEquals(WcharTestHelpers.getString(), STR2); + assertEquals(WcharTestHelpers.checkString(STR2), true); + assertEquals(WcharTestHelpers.checkRecord(new WcharTestRec(STR1)), true); + } +} diff --git a/test-suite/run_djinni.sh b/test-suite/run_djinni.sh index 89ef14051..6f934dc5f 100755 --- a/test-suite/run_djinni.sh +++ b/test-suite/run_djinni.sh @@ -17,12 +17,14 @@ base_dir=$(cd "`dirname "$loc"`" && pwd) temp_out="$base_dir/djinni-output-temp" in="$base_dir/djinni/all.djinni" +wchar_in="$base_dir/djinni/wchar_test.djinni" # Relative version of in and temp_out are used for Djinni call below so that # generated lists of infiles/outfiles are not machine-dependent. This # is an artifact of the test suite, where we want the genereated files # to be in git for examination. in_relative="djinni/all.djinni" +wchar_in_relative="djinni/wchar_test.djinni" temp_out_relative="djinni-output-temp" cpp_out="$base_dir/generated-src/cpp" @@ -59,6 +61,35 @@ fi "$base_dir/../src/build" [ ! -e "$temp_out" ] || rm -r "$temp_out" (cd "$base_dir" && \ +"$base_dir/../src/run-assume-built" \ + --java-out "$temp_out_relative/java" \ + --java-package $java_package \ + --java-nullable-annotation "javax.annotation.CheckForNull" \ + --java-nonnull-annotation "javax.annotation.Nonnull" \ + --java-use-final-for-record false \ + --ident-java-field mFooBar \ + \ + --cpp-out "$temp_out_relative/cpp" \ + --cpp-namespace testsuite \ + --ident-cpp-enum-type foo_bar \ + --cpp-optional-template "std::experimental::optional" \ + --cpp-optional-header "" \ + --cpp-extended-record-include-prefix "../../handwritten-src/cpp/" \ + --cpp-use-wide-strings true \ + \ + --jni-out "$temp_out_relative/jni" \ + --ident-jni-class NativeFooBar \ + --ident-jni-file NativeFooBar \ + \ + --objc-out "$temp_out_relative/objc" \ + --objcpp-out "$temp_out_relative/objc" \ + --objc-type-prefix DB \ + \ + --yaml-out "$temp_out_relative/yaml" \ + --yaml-out-file "yaml-test.yaml" \ + --yaml-prefix "test_" \ + \ + --idl "$wchar_in_relative" && \ "$base_dir/../src/run-assume-built" \ --java-out "$temp_out_relative/java" \ --java-package $java_package \ From 209e2f2ee1741d509ad55cf9d84389a275536745 Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Fri, 15 Jul 2016 14:00:42 +0300 Subject: [PATCH 04/39] c++ wide strings support (objc) --- src/source/ObjcppMarshal.scala | 2 +- support-lib/objc/DJIMarshal+Private.h | 21 ++++++++++++ test-suite/djinni/wchar_test.djinni | 4 +-- .../handwritten-src/objc/tests/DBWcharTests.m | 33 +++++++++++++++++++ .../DjinniObjcTest.xcodeproj/project.pbxproj | 32 ++++++++++++++++++ 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 test-suite/handwritten-src/objc/tests/DBWcharTests.m diff --git a/src/source/ObjcppMarshal.scala b/src/source/ObjcppMarshal.scala index 8541cbc3e..c2307a27c 100644 --- a/src/source/ObjcppMarshal.scala +++ b/src/source/ObjcppMarshal.scala @@ -79,7 +79,7 @@ class ObjcppMarshal(spec: Spec) extends Marshal(spec) { case MOptional => "Optional" case MBinary => "Binary" case MDate => "Date" - case MString => "String" + case MString => if (spec.cppUseWideStrings) "WString" else "String" case MList => "List" case MSet => "Set" case MMap => "Map" diff --git a/support-lib/objc/DJIMarshal+Private.h b/support-lib/objc/DJIMarshal+Private.h index e7bac87ce..4510d77a6 100644 --- a/support-lib/objc/DJIMarshal+Private.h +++ b/support-lib/objc/DJIMarshal+Private.h @@ -118,6 +118,27 @@ struct String { } }; +struct WString { + using CppType = std::wstring; + using ObjcType = NSString*; + + using Boxed = WString; + + static CppType toCpp(ObjcType string) { + assert(string); + NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF32LE); + NSData* data = [string dataUsingEncoding:encoding]; + return std::wstring((wchar_t*)[data bytes], [data length] / sizeof (wchar_t)); + } + + static ObjcType fromCpp(const CppType& string) { + assert(string.size() <= std::numeric_limits::max()); + return [[NSString alloc] initWithBytes:string.data() + length:string.size() * sizeof(wchar_t) + encoding:NSUTF32LittleEndianStringEncoding]; + } +}; + struct Date { using CppType = std::chrono::system_clock::time_point; using ObjcType = NSDate*; diff --git a/test-suite/djinni/wchar_test.djinni b/test-suite/djinni/wchar_test.djinni index f08b62360..e8bfca675 100644 --- a/test-suite/djinni/wchar_test.djinni +++ b/test-suite/djinni/wchar_test.djinni @@ -5,6 +5,6 @@ wchar_test_rec = record { wchar_test_helpers = interface +c { static get_record() : wchar_test_rec; static get_string() : string; - static check_string(s: string) : bool; - static check_record(r: wchar_test_rec) : bool; + static check_string(str: string) : bool; + static check_record(rec: wchar_test_rec) : bool; } diff --git a/test-suite/handwritten-src/objc/tests/DBWcharTests.m b/test-suite/handwritten-src/objc/tests/DBWcharTests.m new file mode 100644 index 000000000..29fd9e946 --- /dev/null +++ b/test-suite/handwritten-src/objc/tests/DBWcharTests.m @@ -0,0 +1,33 @@ +#import +#import "DBWcharTestHelpers.h" +#import "DBWcharTestRec.h" +#import + +@interface DBWcharTests : XCTestCase + +@end + +@implementation DBWcharTests + +- (void)setUp +{ + [super setUp]; +} + +- (void)tearDown +{ + [super tearDown]; +} + +- (void)test +{ + NSString *str1 = @"some string with unicode \u263a symbol"; + NSString *str2 = @"another string with unicode \u263b symbol"; + + XCTAssertEqualObjects([[DBWcharTestHelpers getRecord] s], str1); + XCTAssertEqualObjects([DBWcharTestHelpers getString], str2); + XCTAssertTrue([DBWcharTestHelpers checkString:str2]); + XCTAssertTrue([DBWcharTestHelpers checkRecord:[[DBWcharTestRec alloc] initWithS:str1]]); +} + +@end diff --git a/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj b/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj index 3c3c76b7f..51a36732c 100644 --- a/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj +++ b/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 5AEA68151D38F4A40083D770 /* DBWcharTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 728E11201D37DE27005A554D /* DBWcharTests.m */; }; 650CA05A1C2AB48E007ADDDB /* DBListenerCaller+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = 650CA0571C2AB48E007ADDDB /* DBListenerCaller+Private.mm */; }; 650CA05E1C2AB5AB007ADDDB /* ListenerCaller.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 650CA05D1C2AB5AB007ADDDB /* ListenerCaller.cpp */; }; 650CA0601C2AB6DB007ADDDB /* DBMultipleInheritanceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 650CA05B1C2AB524007ADDDB /* DBMultipleInheritanceTests.m */; }; @@ -31,6 +32,10 @@ 65868B5F1989FE4200D60EEE /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65868B5E1989FE4200D60EEE /* UIKit.framework */; }; 65868B621989FE4200D60EEE /* libDjinniObjcTest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 65868B4A1989FE4200D60EEE /* libDjinniObjcTest.a */; }; 6D66A8A91A3B09F000B312E8 /* DBConstantTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6D66A8A81A3B09F000B312E8 /* DBConstantTests.mm */; }; + 728E111B1D37DE0B005A554D /* DBWcharTestHelpers+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = 728E11161D37DE0B005A554D /* DBWcharTestHelpers+Private.mm */; }; + 728E111C1D37DE0B005A554D /* DBWcharTestRec.mm in Sources */ = {isa = PBXBuildFile; fileRef = 728E11181D37DE0B005A554D /* DBWcharTestRec.mm */; }; + 728E111D1D37DE0B005A554D /* DBWcharTestRec+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = 728E111A1D37DE0B005A554D /* DBWcharTestRec+Private.mm */; }; + 728E111F1D37DE1C005A554D /* wchar_test_helpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 728E111E1D37DE1C005A554D /* wchar_test_helpers.cpp */; }; A20094101B06982F00EF8D9B /* DBTokenTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = A200940E1B0697D300EF8D9B /* DBTokenTests.mm */; }; A209B5791BBA2A0A0070C310 /* DBOptColorRecord.mm in Sources */ = {isa = PBXBuildFile; fileRef = A209B5761BBA2A0A0070C310 /* DBOptColorRecord.mm */; }; A209B57A1BBA2A0A0070C310 /* DBOptColorRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = A209B5781BBA2A0A0070C310 /* DBOptColorRecord+Private.mm */; }; @@ -182,6 +187,17 @@ 65868B5B1989FE4200D60EEE /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 65868B5E1989FE4200D60EEE /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; 6D66A8A81A3B09F000B312E8 /* DBConstantTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBConstantTests.mm; sourceTree = ""; }; + 728E11121D37DDFB005A554D /* wchar_test_helpers.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = wchar_test_helpers.hpp; sourceTree = ""; }; + 728E11131D37DDFB005A554D /* wchar_test_rec.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = wchar_test_rec.hpp; sourceTree = ""; }; + 728E11141D37DE0B005A554D /* DBWcharTestHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBWcharTestHelpers.h; sourceTree = ""; }; + 728E11151D37DE0B005A554D /* DBWcharTestHelpers+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBWcharTestHelpers+Private.h"; sourceTree = ""; }; + 728E11161D37DE0B005A554D /* DBWcharTestHelpers+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBWcharTestHelpers+Private.mm"; sourceTree = ""; }; + 728E11171D37DE0B005A554D /* DBWcharTestRec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBWcharTestRec.h; sourceTree = ""; }; + 728E11181D37DE0B005A554D /* DBWcharTestRec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBWcharTestRec.mm; sourceTree = ""; }; + 728E11191D37DE0B005A554D /* DBWcharTestRec+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBWcharTestRec+Private.h"; sourceTree = ""; }; + 728E111A1D37DE0B005A554D /* DBWcharTestRec+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBWcharTestRec+Private.mm"; sourceTree = ""; }; + 728E111E1D37DE1C005A554D /* wchar_test_helpers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wchar_test_helpers.cpp; sourceTree = ""; }; + 728E11201D37DE27005A554D /* DBWcharTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DBWcharTests.m; sourceTree = ""; }; A200940E1B0697D300EF8D9B /* DBTokenTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBTokenTests.mm; sourceTree = ""; }; A209B5751BBA2A0A0070C310 /* DBOptColorRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBOptColorRecord.h; sourceTree = ""; }; A209B5761BBA2A0A0070C310 /* DBOptColorRecord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBOptColorRecord.mm; sourceTree = ""; }; @@ -378,6 +394,7 @@ 6536CD7519A6C98800DD7715 /* handwritten-cpp */ = { isa = PBXGroup; children = ( + 728E111E1D37DE1C005A554D /* wchar_test_helpers.cpp */, B5E9C9391C1F9D9D0073C123 /* reverse_client_interface_impl.cpp */, B5E9C93A1C1F9D9D0073C123 /* reverse_client_interface_impl.hpp */, 6536CD7619A6C98800DD7715 /* cpp_exception_impl.cpp */, @@ -396,6 +413,7 @@ 6536CD7919A6C99800DD7715 /* Tests */ = { isa = PBXGroup; children = ( + 728E11201D37DE27005A554D /* DBWcharTests.m */, 6536CD7A19A6C99800DD7715 /* DBClientInterfaceTests.mm */, 6D66A8A81A3B09F000B312E8 /* DBConstantTests.mm */, 6536CD7B19A6C99800DD7715 /* DBCppExceptionTests.mm */, @@ -453,6 +471,13 @@ A24249181AF192E0003BF8F0 /* generated-objc */ = { isa = PBXGroup; children = ( + 728E11141D37DE0B005A554D /* DBWcharTestHelpers.h */, + 728E11151D37DE0B005A554D /* DBWcharTestHelpers+Private.h */, + 728E11161D37DE0B005A554D /* DBWcharTestHelpers+Private.mm */, + 728E11171D37DE0B005A554D /* DBWcharTestRec.h */, + 728E11181D37DE0B005A554D /* DBWcharTestRec.mm */, + 728E11191D37DE0B005A554D /* DBWcharTestRec+Private.h */, + 728E111A1D37DE0B005A554D /* DBWcharTestRec+Private.mm */, B5D8FC321C23E2F40045ADCF /* DBConstantRecord.h */, B5D8FC331C23E2F40045ADCF /* DBConstantRecord.mm */, B5D8FC341C23E2F40045ADCF /* DBConstantRecord+Private.h */, @@ -573,6 +598,8 @@ A242495D1AF192FC003BF8F0 /* generated-cpp */ = { isa = PBXGroup; children = ( + 728E11121D37DDFB005A554D /* wchar_test_helpers.hpp */, + 728E11131D37DDFB005A554D /* wchar_test_rec.hpp */, B5D8FC381C23E30D0045ADCF /* constant_record.hpp */, B5E9C93C1C1F9DCA0073C123 /* reverse_client_interface.hpp */, A209B57B1BBA2A180070C310 /* opt_color_record.hpp */, @@ -700,6 +727,7 @@ buildActionMask = 2147483647; files = ( A238CA981AF84B7100CDDCE5 /* DBMapRecord+Private.mm in Sources */, + 728E111B1D37DE0B005A554D /* DBWcharTestHelpers+Private.mm in Sources */, CFC5D9E81B1513E800BF2DF8 /* DBExternInterface1+Private.mm in Sources */, B5D8FC361C23E2F40045ADCF /* DBConstantRecord.mm in Sources */, A24850311AF96EBC00AFE907 /* DBSetRecord.mm in Sources */, @@ -744,6 +772,8 @@ A24249761AF192FC003BF8F0 /* record_with_nested_derivings.cpp in Sources */, CFC5DA081B1532F600BF2DF8 /* DBRecordWithDurationAndDerivings.mm in Sources */, A248502D1AF96EBC00AFE907 /* DBNestedCollection.mm in Sources */, + 728E111D1D37DE0B005A554D /* DBWcharTestRec+Private.mm in Sources */, + 728E111C1D37DE0B005A554D /* DBWcharTestRec.mm in Sources */, B5E9C93B1C1F9D9D0073C123 /* reverse_client_interface_impl.cpp in Sources */, CFC5D9D81B15106400BF2DF8 /* DBExternRecordWithDerivings+Private.mm in Sources */, A238CAA21AF84B7100CDDCE5 /* DBSetRecord+Private.mm in Sources */, @@ -763,6 +793,7 @@ A248502E1AF96EBC00AFE907 /* DBPrimitiveList.mm in Sources */, A209B57A1BBA2A0A0070C310 /* DBOptColorRecord+Private.mm in Sources */, B5D8FC371C23E2F40045ADCF /* DBConstantRecord+Private.mm in Sources */, + 728E111F1D37DE1C005A554D /* wchar_test_helpers.cpp in Sources */, A238CAA01AF84B7100CDDCE5 /* DBRecordWithNestedDerivings+Private.mm in Sources */, CFC5DA0A1B1532F600BF2DF8 /* DBRecordWithDurationAndDerivings+Private.mm in Sources */, ); @@ -772,6 +803,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5AEA68151D38F4A40083D770 /* DBWcharTests.m in Sources */, CFC5D9D11B15105100BF2DF8 /* extern_record_with_derivings.cpp in Sources */, 6D66A8A91A3B09F000B312E8 /* DBConstantTests.mm in Sources */, 6536CD9219A6C9A800DD7715 /* DBRecordWithDerivingsCppTests.mm in Sources */, From f3b6b315b031c0aea2c390534fbe5a5afd091d75 Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Mon, 18 Jul 2016 11:18:46 +0300 Subject: [PATCH 05/39] undefined behaviour fixed in the wstring encoding functions --- support-lib/jni/djinni_support.cpp | 65 ++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/support-lib/jni/djinni_support.cpp b/support-lib/jni/djinni_support.cpp index d957aca27..5883a1029 100644 --- a/support-lib/jni/djinni_support.cpp +++ b/support-lib/jni/djinni_support.cpp @@ -22,6 +22,7 @@ #include static_assert(sizeof(jlong) >= sizeof(void*), "must be able to fit a void* into a jlong"); +static_assert(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4, "wchar_t must be represented by UTF-16 or UTF-32 encoding"); namespace djinni { @@ -371,11 +372,37 @@ jstring jniStringFromUTF8(JNIEnv * env, const std::string & str) { return res; } -jstring jniStringFromWString(JNIEnv * env, const std::wstring & str) { +template +static std::u16string implWStringToUTF16(const std::wstring & str); + +template<> +inline std::u16string implWStringToUTF16<2>(const std::wstring & str) { + // case when wchar_t is represented by utf-16 encoding + return std::u16string(str.begin(), str.end()); +} + +template<> +inline std::u16string implWStringToUTF16<4>(const std::wstring & str) { + // case when wchar_t is represented by utf-32 encoding + std::u16string utf16; + utf16.reserve(str.size()); + for(size_t i = 0; i < str.size(); ++i) + utf16_encode(static_cast(str[i]), utf16); + return utf16; +} + +inline std::u16string wstringToUTF16(const std::wstring & str) { + // hide "defined but not used" warnings + (void)implWStringToUTF16<2>; + (void)implWStringToUTF16<4>; + return implWStringToUTF16(str); +} - std::u16string utf16(str.begin(), str.end());; +jstring jniStringFromWString(JNIEnv * env, const std::wstring & str) { + std::u16string utf16 = wstringToUTF16(str); + const size_t len = utf16.size(); jstring res = env->NewString( - reinterpret_cast(utf16.data()), utf16.length()); + reinterpret_cast(utf16.data()), len); DJINNI_ASSERT(res, env); return res; } @@ -450,6 +477,32 @@ std::string jniUTF8FromString(JNIEnv * env, const jstring jstr) { return out; } +template +static std::wstring implUTF16ToWString(const char16_t * data, size_t length); + +template<> +inline std::wstring implUTF16ToWString<2>(const char16_t * data, size_t length) { + // case when wchar_t is represented by utf-16 encoding + return std::wstring(data, data + length); +} + +template<> +inline std::wstring implUTF16ToWString<4>(const char16_t * data, size_t length) { + // case when wchar_t is represented by utf-32 encoding + std::wstring result; + result.reserve(length); + for (size_t i = 0; i < length; ) + result += static_cast(utf16_decode(data, i)); + return result; +} + +inline std::wstring UTF16ToWString(const char16_t * data, size_t length) { + // hide "defined but not used" warnings + (void)implUTF16ToWString<2>; + (void)implUTF16ToWString<4>; + return implUTF16ToWString(data, length); +} + std::wstring jniWStringFromString(JNIEnv * env, const jstring jstr) { DJINNI_ASSERT(jstr, env); const jsize length = env->GetStringLength(jstr); @@ -458,10 +511,8 @@ std::wstring jniWStringFromString(JNIEnv * env, const jstring jstr) { const auto deleter = [env, jstr] (const jchar * c) { env->ReleaseStringChars(jstr, c); }; std::unique_ptr ptr(env->GetStringChars(jstr, nullptr), deleter); - - const char16_t* begin = reinterpret_cast(ptr.get()); - const char16_t* end = begin + length; - return std::wstring(begin, end); + const char16_t* data = reinterpret_cast(ptr.get()); + return UTF16ToWString(data, length); } DJINNI_WEAK_DEFINITION From 236cd7f571c4cba7cc302d92ab5e88bf87740f16 Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Mon, 18 Jul 2016 11:40:51 +0300 Subject: [PATCH 06/39] improved wchar tests --- test-suite/handwritten-src/cpp/wchar_test_helpers.cpp | 4 ++-- .../java/com/dropbox/djinni/test/WcharTest.java | 4 ++-- test-suite/handwritten-src/objc/tests/DBWcharTests.m | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test-suite/handwritten-src/cpp/wchar_test_helpers.cpp b/test-suite/handwritten-src/cpp/wchar_test_helpers.cpp index adc69e9b2..4bb084d3e 100644 --- a/test-suite/handwritten-src/cpp/wchar_test_helpers.cpp +++ b/test-suite/handwritten-src/cpp/wchar_test_helpers.cpp @@ -3,8 +3,8 @@ namespace testsuite { -static const std::wstring str1 = L"some string with unicode \u263a symbol"; -static const std::wstring str2 = L"another string with unicode \u263b symbol"; +static const std::wstring str1 = L"some string with unicode \u263A, \U0001F4A9 symbols"; +static const std::wstring str2 = L"another string with unicode \u263B, \U0001F4A8 symbols"; WcharTestRec WcharTestHelpers::get_record() { diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java index aa10c8d51..35e4d4944 100644 --- a/test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java @@ -4,8 +4,8 @@ public class WcharTest extends TestCase { - private static final String STR1 = "some string with unicode \u263a symbol"; - private static final String STR2 = "another string with unicode \u263b symbol"; + private static final String STR1 = "some string with unicode \u263A, \uD83D\uDCA9 symbols"; + private static final String STR2 = "another string with unicode \u263B, \uD83D\uDCA8 symbols"; public void test() { assertEquals(WcharTestHelpers.getRecord().getS(), STR1); diff --git a/test-suite/handwritten-src/objc/tests/DBWcharTests.m b/test-suite/handwritten-src/objc/tests/DBWcharTests.m index 29fd9e946..48c58c73b 100644 --- a/test-suite/handwritten-src/objc/tests/DBWcharTests.m +++ b/test-suite/handwritten-src/objc/tests/DBWcharTests.m @@ -21,8 +21,8 @@ - (void)tearDown - (void)test { - NSString *str1 = @"some string with unicode \u263a symbol"; - NSString *str2 = @"another string with unicode \u263b symbol"; + NSString *str1 = @"some string with unicode \u263A, \U0001F4A9 symbols"; + NSString *str2 = @"another string with unicode \u263B, \U0001F4A8 symbols"; XCTAssertEqualObjects([[DBWcharTestHelpers getRecord] s], str1); XCTAssertEqualObjects([DBWcharTestHelpers getString], str2); From 1c6c5ec3bbadd09ea3d59243a5715d3fbb87516b Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Mon, 18 Jul 2016 11:55:59 +0300 Subject: [PATCH 07/39] created docker image with GCC6 (fedora 24) --- test-suite/java/docker/fedora_24/Dockerfile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test-suite/java/docker/fedora_24/Dockerfile diff --git a/test-suite/java/docker/fedora_24/Dockerfile b/test-suite/java/docker/fedora_24/Dockerfile new file mode 100644 index 000000000..f95a1a8f7 --- /dev/null +++ b/test-suite/java/docker/fedora_24/Dockerfile @@ -0,0 +1,19 @@ +FROM fedora:24 + +# Get Java 8 (64-bit) +RUN dnf install -y java-1.8.0-openjdk-devel + +# Get other build utils +RUN dnf install -y cmake wget tar make gcc-c++ + +# Select Java 8 +RUN echo 1 | update-alternatives --config java +RUN echo 1 | update-alternatives --config javac + +# Get modern ant +RUN yum install -y ant +ENV JAVA_HOME /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.92-5.b14.fc24.x86_64 + +VOLUME /opt/djinni +CMD /opt/djinni/test-suite/java/docker/build_and_run_tests.sh + From e12862a906c075a7e59d692d0a5db4696e42149a Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Tue, 19 Jul 2016 11:06:05 +0300 Subject: [PATCH 08/39] code-style --- support-lib/jni/djinni_support.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/support-lib/jni/djinni_support.cpp b/support-lib/jni/djinni_support.cpp index 5883a1029..116c61fa0 100644 --- a/support-lib/jni/djinni_support.cpp +++ b/support-lib/jni/djinni_support.cpp @@ -385,8 +385,8 @@ template<> inline std::u16string implWStringToUTF16<4>(const std::wstring & str) { // case when wchar_t is represented by utf-32 encoding std::u16string utf16; - utf16.reserve(str.size()); - for(size_t i = 0; i < str.size(); ++i) + utf16.reserve(str.length()); + for (size_t i = 0; i < str.length(); ++i) utf16_encode(static_cast(str[i]), utf16); return utf16; } @@ -400,9 +400,8 @@ inline std::u16string wstringToUTF16(const std::wstring & str) { jstring jniStringFromWString(JNIEnv * env, const std::wstring & str) { std::u16string utf16 = wstringToUTF16(str); - const size_t len = utf16.size(); jstring res = env->NewString( - reinterpret_cast(utf16.data()), len); + reinterpret_cast(utf16.data()), utf16.length()); DJINNI_ASSERT(res, env); return res; } @@ -511,7 +510,7 @@ std::wstring jniWStringFromString(JNIEnv * env, const jstring jstr) { const auto deleter = [env, jstr] (const jchar * c) { env->ReleaseStringChars(jstr, c); }; std::unique_ptr ptr(env->GetStringChars(jstr, nullptr), deleter); - const char16_t* data = reinterpret_cast(ptr.get()); + const char16_t * data = reinterpret_cast(ptr.get()); return UTF16ToWString(data, length); } From d7877cacf3441084073bcdf54b489769eef7c852 Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Tue, 26 Jul 2016 21:55:42 -0700 Subject: [PATCH 09/39] Remove stray c_str() to fix handling of embedded nulls --- support-lib/jni/Marshal.hpp | 2 +- test-suite/handwritten-src/cpp/test_helpers.cpp | 3 ++- .../java/com/dropbox/djinni/test/ClientInterfaceImpl.java | 2 +- test-suite/handwritten-src/objc/impl/DBClientInterfaceImpl.mm | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index d51b1865f..af44a079c 100644 --- a/support-lib/jni/Marshal.hpp +++ b/support-lib/jni/Marshal.hpp @@ -174,7 +174,7 @@ namespace djinni static LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) { - return {jniEnv, jniStringFromUTF8(jniEnv, c.c_str())}; + return {jniEnv, jniStringFromUTF8(jniEnv, c)}; } }; diff --git a/test-suite/handwritten-src/cpp/test_helpers.cpp b/test-suite/handwritten-src/cpp/test_helpers.cpp index db21f5b3d..873363d40 100644 --- a/test-suite/handwritten-src/cpp/test_helpers.cpp +++ b/test-suite/handwritten-src/cpp/test_helpers.cpp @@ -76,7 +76,8 @@ bool TestHelpers::check_map_list_record(const MapListRecord & rec) { } static const std::string HELLO_WORLD = "Hello World!"; -static const std::string NON_ASCII = "Non-ASCII / 非 ASCII 字符"; +static const std::string NON_ASCII("Non-ASCII /\0 非 ASCII 字符", + sizeof("Non-ASCII /\0 非 ASCII 字符")-1); void TestHelpers::check_client_interface_ascii(const std::shared_ptr & i) { ClientReturnedRecord cReturnedRecord = i->get_record(5, HELLO_WORLD, {}); diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/ClientInterfaceImpl.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/ClientInterfaceImpl.java index 48c9bcdb8..0049334e9 100644 --- a/test-suite/handwritten-src/java/com/dropbox/djinni/test/ClientInterfaceImpl.java +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/ClientInterfaceImpl.java @@ -5,7 +5,7 @@ public class ClientInterfaceImpl extends ClientInterface { @Override public ClientReturnedRecord getRecord(long id, String utf8string, String misc) { - if (!utf8string.equals("Non-ASCII / 非 ASCII 字符") && !utf8string.equals("Hello World!")) { + if (!utf8string.equals("Non-ASCII /\0 非 ASCII 字符") && !utf8string.equals("Hello World!")) { throw new RuntimeException("Unexpected string. Check UTF-8?"); } return new ClientReturnedRecord(id, utf8string, misc); diff --git a/test-suite/handwritten-src/objc/impl/DBClientInterfaceImpl.mm b/test-suite/handwritten-src/objc/impl/DBClientInterfaceImpl.mm index e91a88d8c..701b11c6c 100644 --- a/test-suite/handwritten-src/objc/impl/DBClientInterfaceImpl.mm +++ b/test-suite/handwritten-src/objc/impl/DBClientInterfaceImpl.mm @@ -2,7 +2,7 @@ #import "DBClientReturnedRecord+Private.h" static NSString *DBHelloWorld = @"Hello World!"; -static NSString *DBNonAscii = @"Non-ASCII / 非 ASCII 字符"; +static NSString *DBNonAscii = @"Non-ASCII /\0 非 ASCII 字符"; @implementation DBClientInterfaceImpl From 2903818a3d648c36f72ecd59a8a1764fe52bcd3a Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Wed, 27 Jul 2016 17:31:05 -0700 Subject: [PATCH 10/39] Fix enum compile issue in C++11 --- src/.idea/encodings.xml | 7 +- src/.idea/sbt.xml | 6 + src/.idea/vcs.xml | 1 - src/source/ObjcppGenerator.scala | 6 +- src/source/ObjcppMarshal.scala | 5 +- test-suite/djinni/enum.djinni | 16 +- .../generated-src/cpp/assorted_primitives.hpp | 2 +- .../generated-src/cpp/client_interface.hpp | 2 +- .../cpp/client_returned_record.hpp | 2 +- test-suite/generated-src/cpp/constants.hpp | 2 +- .../generated-src/cpp/constants_interface.hpp | 2 +- .../cpp/enum_usage_interface.hpp | 30 + .../generated-src/cpp/enum_usage_record.hpp | 35 + .../generated-src/cpp/opt_color_record.hpp | 20 - .../cpp/reverse_client_interface.hpp | 2 +- .../generated-src/cpp/test_duration.hpp | 2 +- test-suite/generated-src/cpp/test_helpers.hpp | 2 +- .../djinni/test/EnumUsageInterface.java | 92 ++ .../dropbox/djinni/test/EnumUsageRecord.java | 74 ++ .../dropbox/djinni/test/OptColorRecord.java | 31 - .../jni/NativeEnumUsageInterface.cpp | 122 +++ .../jni/NativeEnumUsageInterface.hpp | 54 ++ .../jni/NativeEnumUsageRecord.cpp | 37 + .../jni/NativeEnumUsageRecord.hpp | 36 + .../jni/NativeOptColorRecord.cpp | 29 - .../jni/NativeOptColorRecord.hpp | 32 - .../generated-src/objc/DBColor+Private.h | 6 + .../objc/DBEnumUsageInterface+Private.h | 31 + .../objc/DBEnumUsageInterface+Private.mm | 142 +++ .../generated-src/objc/DBEnumUsageInterface.h | 20 + ...+Private.h => DBEnumUsageRecord+Private.h} | 14 +- .../objc/DBEnumUsageRecord+Private.mm | 30 + .../generated-src/objc/DBEnumUsageRecord.h | 29 + .../generated-src/objc/DBEnumUsageRecord.mm | 43 + .../DBExternRecordWithDerivings+Private.mm | 2 +- .../objc/DBOptColorRecord+Private.mm | 21 - .../generated-src/objc/DBOptColorRecord.h | 13 - .../generated-src/objc/DBOptColorRecord.mm | 27 - .../objc/DBTestHelpers+Private.mm | 1 + test-suite/generated-src/outFileList.txt | 24 +- test-suite/handwritten-src/cpp/optional.hpp | 891 ++++++++++++++++++ test-suite/java/CMakeLists.txt | 2 +- .../DjinniObjcTest.xcodeproj/project.pbxproj | 104 +- test-suite/run_djinni.sh | 4 +- 44 files changed, 1826 insertions(+), 227 deletions(-) create mode 100644 test-suite/generated-src/cpp/enum_usage_interface.hpp create mode 100644 test-suite/generated-src/cpp/enum_usage_record.hpp delete mode 100644 test-suite/generated-src/cpp/opt_color_record.hpp create mode 100644 test-suite/generated-src/java/com/dropbox/djinni/test/EnumUsageInterface.java create mode 100644 test-suite/generated-src/java/com/dropbox/djinni/test/EnumUsageRecord.java delete mode 100644 test-suite/generated-src/java/com/dropbox/djinni/test/OptColorRecord.java create mode 100644 test-suite/generated-src/jni/NativeEnumUsageInterface.cpp create mode 100644 test-suite/generated-src/jni/NativeEnumUsageInterface.hpp create mode 100644 test-suite/generated-src/jni/NativeEnumUsageRecord.cpp create mode 100644 test-suite/generated-src/jni/NativeEnumUsageRecord.hpp delete mode 100644 test-suite/generated-src/jni/NativeOptColorRecord.cpp delete mode 100644 test-suite/generated-src/jni/NativeOptColorRecord.hpp create mode 100644 test-suite/generated-src/objc/DBColor+Private.h create mode 100644 test-suite/generated-src/objc/DBEnumUsageInterface+Private.h create mode 100644 test-suite/generated-src/objc/DBEnumUsageInterface+Private.mm create mode 100644 test-suite/generated-src/objc/DBEnumUsageInterface.h rename test-suite/generated-src/objc/{DBOptColorRecord+Private.h => DBEnumUsageRecord+Private.h} (59%) create mode 100644 test-suite/generated-src/objc/DBEnumUsageRecord+Private.mm create mode 100644 test-suite/generated-src/objc/DBEnumUsageRecord.h create mode 100644 test-suite/generated-src/objc/DBEnumUsageRecord.mm delete mode 100644 test-suite/generated-src/objc/DBOptColorRecord+Private.mm delete mode 100644 test-suite/generated-src/objc/DBOptColorRecord.h delete mode 100644 test-suite/generated-src/objc/DBOptColorRecord.mm create mode 100644 test-suite/handwritten-src/cpp/optional.hpp diff --git a/src/.idea/encodings.xml b/src/.idea/encodings.xml index e206d70d8..f75895965 100644 --- a/src/.idea/encodings.xml +++ b/src/.idea/encodings.xml @@ -1,5 +1,6 @@ - - - + + + + \ No newline at end of file diff --git a/src/.idea/sbt.xml b/src/.idea/sbt.xml index 86e0431a5..f79f3f84a 100644 --- a/src/.idea/sbt.xml +++ b/src/.idea/sbt.xml @@ -13,6 +13,12 @@ diff --git a/src/.idea/vcs.xml b/src/.idea/vcs.xml index 075f87f36..6c0b86358 100644 --- a/src/.idea/vcs.xml +++ b/src/.idea/vcs.xml @@ -1,7 +1,6 @@ - \ No newline at end of file diff --git a/src/source/ObjcppGenerator.scala b/src/source/ObjcppGenerator.scala index 64877ab0b..dfb5777cd 100644 --- a/src/source/ObjcppGenerator.scala +++ b/src/source/ObjcppGenerator.scala @@ -49,7 +49,11 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { private def arcAssert(w: IndentWriter) = w.wl("static_assert(__has_feature(objc_arc), " + q("Djinni requires ARC to be enabled for this file") + ");") override def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum) { - // No generation required + var imports = mutable.TreeSet[String]() + imports.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIMarshal+Private.h")) + imports.add("!#include " + q(spec.objcppIncludeCppPrefix + spec.cppFileIdentStyle(ident) + "." + spec.cppHeaderExt)) + + writeObjcFile(objcppMarshal.privateHeaderName(ident.name), origin, imports, w => {} ) } def headerName(ident: String): String = idObjc.ty(ident) + "." + spec.objcHeaderExt diff --git a/src/source/ObjcppMarshal.scala b/src/source/ObjcppMarshal.scala index 8541cbc3e..3f5a6569d 100644 --- a/src/source/ObjcppMarshal.scala +++ b/src/source/ObjcppMarshal.scala @@ -34,9 +34,7 @@ class ObjcppMarshal(spec: Spec) extends Marshal(spec) { case o: MOpaque => List(ImportRef(q(spec.objcBaseLibIncludePrefix + "DJIMarshal+Private.h"))) case d: MDef => d.defType match { - case DEnum => - List(ImportRef(q(spec.objcBaseLibIncludePrefix + "DJIMarshal+Private.h"))) - case DInterface => + case DEnum | DInterface => List(ImportRef(include(m))) case DRecord => val r = d.body.asInstanceOf[Record] @@ -49,7 +47,6 @@ class ObjcppMarshal(spec: Spec) extends Marshal(spec) { def include(m: Meta) = m match { case d: MDef => d.defType match { - case DEnum => q(spec.objcBaseLibIncludePrefix + "DJIMarshal+Private.h") case _ => q(spec.objcppIncludePrefix + privateHeaderName(d.name)) } case _ => throw new AssertionError("not applicable") diff --git a/test-suite/djinni/enum.djinni b/test-suite/djinni/enum.djinni index 03d1e0206..af56c695c 100644 --- a/test-suite/djinni/enum.djinni +++ b/test-suite/djinni/enum.djinni @@ -11,6 +11,18 @@ color = enum { violet; } -opt_color_record = record { - my_color: optional; +enum_usage_record = record { + e: color; + o: optional; + l: list; + s: set; + m: map; +} + +enum_usage_interface = interface +c +j +o { + e(e: color): color; + o(o: optional): optional; + l(l: list): list; + s(s: set): set; + m(m: map): map; } diff --git a/test-suite/generated-src/cpp/assorted_primitives.hpp b/test-suite/generated-src/cpp/assorted_primitives.hpp index caa67f80b..9db7274e5 100644 --- a/test-suite/generated-src/cpp/assorted_primitives.hpp +++ b/test-suite/generated-src/cpp/assorted_primitives.hpp @@ -3,8 +3,8 @@ #pragma once +#include "../../handwritten-src/cpp/optional.hpp" #include -#include #include namespace testsuite { diff --git a/test-suite/generated-src/cpp/client_interface.hpp b/test-suite/generated-src/cpp/client_interface.hpp index fa2c84410..0b35234cd 100644 --- a/test-suite/generated-src/cpp/client_interface.hpp +++ b/test-suite/generated-src/cpp/client_interface.hpp @@ -3,8 +3,8 @@ #pragma once +#include "../../handwritten-src/cpp/optional.hpp" #include -#include #include #include #include diff --git a/test-suite/generated-src/cpp/client_returned_record.hpp b/test-suite/generated-src/cpp/client_returned_record.hpp index ac18574e8..4252095e5 100644 --- a/test-suite/generated-src/cpp/client_returned_record.hpp +++ b/test-suite/generated-src/cpp/client_returned_record.hpp @@ -3,8 +3,8 @@ #pragma once +#include "../../handwritten-src/cpp/optional.hpp" #include -#include #include #include diff --git a/test-suite/generated-src/cpp/constants.hpp b/test-suite/generated-src/cpp/constants.hpp index edd7d5cfa..32b1a0283 100644 --- a/test-suite/generated-src/cpp/constants.hpp +++ b/test-suite/generated-src/cpp/constants.hpp @@ -3,9 +3,9 @@ #pragma once +#include "../../handwritten-src/cpp/optional.hpp" #include "constant_record.hpp" #include -#include #include #include diff --git a/test-suite/generated-src/cpp/constants_interface.hpp b/test-suite/generated-src/cpp/constants_interface.hpp index daa250edc..54a7d6c8c 100644 --- a/test-suite/generated-src/cpp/constants_interface.hpp +++ b/test-suite/generated-src/cpp/constants_interface.hpp @@ -3,8 +3,8 @@ #pragma once +#include "../../handwritten-src/cpp/optional.hpp" #include -#include #include namespace testsuite { diff --git a/test-suite/generated-src/cpp/enum_usage_interface.hpp b/test-suite/generated-src/cpp/enum_usage_interface.hpp new file mode 100644 index 000000000..a55e095f1 --- /dev/null +++ b/test-suite/generated-src/cpp/enum_usage_interface.hpp @@ -0,0 +1,30 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#pragma once + +#include "../../handwritten-src/cpp/optional.hpp" +#include +#include +#include + +namespace testsuite { + +enum class color; + +class EnumUsageInterface { +public: + virtual ~EnumUsageInterface() {} + + virtual color e(color e) = 0; + + virtual std::experimental::optional o(std::experimental::optional o) = 0; + + virtual std::vector l(const std::vector & l) = 0; + + virtual std::unordered_set s(const std::unordered_set & s) = 0; + + virtual std::unordered_map m(const std::unordered_map & m) = 0; +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/enum_usage_record.hpp b/test-suite/generated-src/cpp/enum_usage_record.hpp new file mode 100644 index 000000000..10d86ebe8 --- /dev/null +++ b/test-suite/generated-src/cpp/enum_usage_record.hpp @@ -0,0 +1,35 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#pragma once + +#include "../../handwritten-src/cpp/optional.hpp" +#include "color.hpp" +#include +#include +#include +#include + +namespace testsuite { + +struct EnumUsageRecord final { + color e; + std::experimental::optional o; + std::vector l; + std::unordered_set s; + std::unordered_map m; + + EnumUsageRecord(color e_, + std::experimental::optional o_, + std::vector l_, + std::unordered_set s_, + std::unordered_map m_) + : e(std::move(e_)) + , o(std::move(o_)) + , l(std::move(l_)) + , s(std::move(s_)) + , m(std::move(m_)) + {} +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/opt_color_record.hpp b/test-suite/generated-src/cpp/opt_color_record.hpp deleted file mode 100644 index b07746315..000000000 --- a/test-suite/generated-src/cpp/opt_color_record.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file generated by Djinni from enum.djinni - -#pragma once - -#include "color.hpp" -#include -#include - -namespace testsuite { - -struct OptColorRecord final { - std::experimental::optional my_color; - - OptColorRecord(std::experimental::optional my_color_) - : my_color(std::move(my_color_)) - {} -}; - -} // namespace testsuite diff --git a/test-suite/generated-src/cpp/reverse_client_interface.hpp b/test-suite/generated-src/cpp/reverse_client_interface.hpp index 372af04b4..955b912a5 100644 --- a/test-suite/generated-src/cpp/reverse_client_interface.hpp +++ b/test-suite/generated-src/cpp/reverse_client_interface.hpp @@ -3,7 +3,7 @@ #pragma once -#include +#include "../../handwritten-src/cpp/optional.hpp" #include #include diff --git a/test-suite/generated-src/cpp/test_duration.hpp b/test-suite/generated-src/cpp/test_duration.hpp index 1010e7c7f..028fc5d06 100644 --- a/test-suite/generated-src/cpp/test_duration.hpp +++ b/test-suite/generated-src/cpp/test_duration.hpp @@ -3,9 +3,9 @@ #pragma once +#include "../../handwritten-src/cpp/optional.hpp" #include #include -#include #include namespace testsuite { diff --git a/test-suite/generated-src/cpp/test_helpers.hpp b/test-suite/generated-src/cpp/test_helpers.hpp index 849fb1b5c..df09e2439 100644 --- a/test-suite/generated-src/cpp/test_helpers.hpp +++ b/test-suite/generated-src/cpp/test_helpers.hpp @@ -3,8 +3,8 @@ #pragma once +#include "../../handwritten-src/cpp/optional.hpp" #include -#include #include #include #include diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/EnumUsageInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/EnumUsageInterface.java new file mode 100644 index 000000000..dcb1322db --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/EnumUsageInterface.java @@ -0,0 +1,92 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +package com.dropbox.djinni.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +public abstract class EnumUsageInterface { + @Nonnull + public abstract Color e(@Nonnull Color e); + + @CheckForNull + public abstract Color o(@CheckForNull Color o); + + @Nonnull + public abstract ArrayList l(@Nonnull ArrayList l); + + @Nonnull + public abstract HashSet s(@Nonnull HashSet s); + + @Nonnull + public abstract HashMap m(@Nonnull HashMap m); + + private static final class CppProxy extends EnumUsageInterface + { + private final long nativeRef; + private final AtomicBoolean destroyed = new AtomicBoolean(false); + + private CppProxy(long nativeRef) + { + if (nativeRef == 0) throw new RuntimeException("nativeRef is zero"); + this.nativeRef = nativeRef; + } + + private native void nativeDestroy(long nativeRef); + public void destroy() + { + boolean destroyed = this.destroyed.getAndSet(true); + if (!destroyed) nativeDestroy(this.nativeRef); + } + protected void finalize() throws java.lang.Throwable + { + destroy(); + super.finalize(); + } + + @Override + public Color e(Color e) + { + assert !this.destroyed.get() : "trying to use a destroyed object"; + return native_e(this.nativeRef, e); + } + private native Color native_e(long _nativeRef, Color e); + + @Override + public Color o(Color o) + { + assert !this.destroyed.get() : "trying to use a destroyed object"; + return native_o(this.nativeRef, o); + } + private native Color native_o(long _nativeRef, Color o); + + @Override + public ArrayList l(ArrayList l) + { + assert !this.destroyed.get() : "trying to use a destroyed object"; + return native_l(this.nativeRef, l); + } + private native ArrayList native_l(long _nativeRef, ArrayList l); + + @Override + public HashSet s(HashSet s) + { + assert !this.destroyed.get() : "trying to use a destroyed object"; + return native_s(this.nativeRef, s); + } + private native HashSet native_s(long _nativeRef, HashSet s); + + @Override + public HashMap m(HashMap m) + { + assert !this.destroyed.get() : "trying to use a destroyed object"; + return native_m(this.nativeRef, m); + } + private native HashMap native_m(long _nativeRef, HashMap m); + } +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/EnumUsageRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/EnumUsageRecord.java new file mode 100644 index 000000000..5d52bbde2 --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/EnumUsageRecord.java @@ -0,0 +1,74 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +package com.dropbox.djinni.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +public class EnumUsageRecord { + + + /*package*/ final Color mE; + + /*package*/ final Color mO; + + /*package*/ final ArrayList mL; + + /*package*/ final HashSet mS; + + /*package*/ final HashMap mM; + + public EnumUsageRecord( + @Nonnull Color e, + @CheckForNull Color o, + @Nonnull ArrayList l, + @Nonnull HashSet s, + @Nonnull HashMap m) { + this.mE = e; + this.mO = o; + this.mL = l; + this.mS = s; + this.mM = m; + } + + @Nonnull + public Color getE() { + return mE; + } + + @CheckForNull + public Color getO() { + return mO; + } + + @Nonnull + public ArrayList getL() { + return mL; + } + + @Nonnull + public HashSet getS() { + return mS; + } + + @Nonnull + public HashMap getM() { + return mM; + } + + @Override + public String toString() { + return "EnumUsageRecord{" + + "mE=" + mE + + "," + "mO=" + mO + + "," + "mL=" + mL + + "," + "mS=" + mS + + "," + "mM=" + mM + + "}"; + } + +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/OptColorRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/OptColorRecord.java deleted file mode 100644 index 0f84baeee..000000000 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/OptColorRecord.java +++ /dev/null @@ -1,31 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file generated by Djinni from enum.djinni - -package com.dropbox.djinni.test; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -public class OptColorRecord { - - - /*package*/ final Color mMyColor; - - public OptColorRecord( - @CheckForNull Color myColor) { - this.mMyColor = myColor; - } - - @CheckForNull - public Color getMyColor() { - return mMyColor; - } - - @Override - public String toString() { - return "OptColorRecord{" + - "mMyColor=" + mMyColor + - "}"; - } - -} diff --git a/test-suite/generated-src/jni/NativeEnumUsageInterface.cpp b/test-suite/generated-src/jni/NativeEnumUsageInterface.cpp new file mode 100644 index 000000000..4e84735d3 --- /dev/null +++ b/test-suite/generated-src/jni/NativeEnumUsageInterface.cpp @@ -0,0 +1,122 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#include "NativeEnumUsageInterface.hpp" // my header +#include "Marshal.hpp" +#include "NativeColor.hpp" + +namespace djinni_generated { + +NativeEnumUsageInterface::NativeEnumUsageInterface() : ::djinni::JniInterface<::testsuite::EnumUsageInterface, NativeEnumUsageInterface>("com/dropbox/djinni/test/EnumUsageInterface$CppProxy") {} + +NativeEnumUsageInterface::~NativeEnumUsageInterface() = default; + +NativeEnumUsageInterface::JavaProxy::JavaProxy(JniType j) : Handle(::djinni::jniGetThreadEnv(), j) { } + +NativeEnumUsageInterface::JavaProxy::~JavaProxy() = default; + +::testsuite::color NativeEnumUsageInterface::JavaProxy::e(::testsuite::color c_e) { + auto jniEnv = ::djinni::jniGetThreadEnv(); + ::djinni::JniLocalScope jscope(jniEnv, 10); + const auto& data = ::djinni::JniClass<::djinni_generated::NativeEnumUsageInterface>::get(); + auto jret = jniEnv->CallObjectMethod(Handle::get().get(), data.method_e, + ::djinni::get(::djinni_generated::NativeColor::fromCpp(jniEnv, c_e))); + ::djinni::jniExceptionCheck(jniEnv); + return ::djinni_generated::NativeColor::toCpp(jniEnv, jret); +} +std::experimental::optional<::testsuite::color> NativeEnumUsageInterface::JavaProxy::o(std::experimental::optional<::testsuite::color> c_o) { + auto jniEnv = ::djinni::jniGetThreadEnv(); + ::djinni::JniLocalScope jscope(jniEnv, 10); + const auto& data = ::djinni::JniClass<::djinni_generated::NativeEnumUsageInterface>::get(); + auto jret = jniEnv->CallObjectMethod(Handle::get().get(), data.method_o, + ::djinni::get(::djinni::Optional::fromCpp(jniEnv, c_o))); + ::djinni::jniExceptionCheck(jniEnv); + return ::djinni::Optional::toCpp(jniEnv, jret); +} +std::vector<::testsuite::color> NativeEnumUsageInterface::JavaProxy::l(const std::vector<::testsuite::color> & c_l) { + auto jniEnv = ::djinni::jniGetThreadEnv(); + ::djinni::JniLocalScope jscope(jniEnv, 10); + const auto& data = ::djinni::JniClass<::djinni_generated::NativeEnumUsageInterface>::get(); + auto jret = jniEnv->CallObjectMethod(Handle::get().get(), data.method_l, + ::djinni::get(::djinni::List<::djinni_generated::NativeColor>::fromCpp(jniEnv, c_l))); + ::djinni::jniExceptionCheck(jniEnv); + return ::djinni::List<::djinni_generated::NativeColor>::toCpp(jniEnv, jret); +} +std::unordered_set<::testsuite::color> NativeEnumUsageInterface::JavaProxy::s(const std::unordered_set<::testsuite::color> & c_s) { + auto jniEnv = ::djinni::jniGetThreadEnv(); + ::djinni::JniLocalScope jscope(jniEnv, 10); + const auto& data = ::djinni::JniClass<::djinni_generated::NativeEnumUsageInterface>::get(); + auto jret = jniEnv->CallObjectMethod(Handle::get().get(), data.method_s, + ::djinni::get(::djinni::Set<::djinni_generated::NativeColor>::fromCpp(jniEnv, c_s))); + ::djinni::jniExceptionCheck(jniEnv); + return ::djinni::Set<::djinni_generated::NativeColor>::toCpp(jniEnv, jret); +} +std::unordered_map<::testsuite::color, ::testsuite::color> NativeEnumUsageInterface::JavaProxy::m(const std::unordered_map<::testsuite::color, ::testsuite::color> & c_m) { + auto jniEnv = ::djinni::jniGetThreadEnv(); + ::djinni::JniLocalScope jscope(jniEnv, 10); + const auto& data = ::djinni::JniClass<::djinni_generated::NativeEnumUsageInterface>::get(); + auto jret = jniEnv->CallObjectMethod(Handle::get().get(), data.method_m, + ::djinni::get(::djinni::Map<::djinni_generated::NativeColor, ::djinni_generated::NativeColor>::fromCpp(jniEnv, c_m))); + ::djinni::jniExceptionCheck(jniEnv); + return ::djinni::Map<::djinni_generated::NativeColor, ::djinni_generated::NativeColor>::toCpp(jniEnv, jret); +} + +CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_EnumUsageInterface_00024CppProxy_nativeDestroy(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + delete reinterpret_cast<::djinni::CppProxyHandle<::testsuite::EnumUsageInterface>*>(nativeRef); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, ) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_EnumUsageInterface_00024CppProxy_native_1e(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_e) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::EnumUsageInterface>(nativeRef); + auto r = ref->e(::djinni_generated::NativeColor::toCpp(jniEnv, j_e)); + return ::djinni::release(::djinni_generated::NativeColor::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_EnumUsageInterface_00024CppProxy_native_1o(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_o) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::EnumUsageInterface>(nativeRef); + auto r = ref->o(::djinni::Optional::toCpp(jniEnv, j_o)); + return ::djinni::release(::djinni::Optional::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_EnumUsageInterface_00024CppProxy_native_1l(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_l) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::EnumUsageInterface>(nativeRef); + auto r = ref->l(::djinni::List<::djinni_generated::NativeColor>::toCpp(jniEnv, j_l)); + return ::djinni::release(::djinni::List<::djinni_generated::NativeColor>::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_EnumUsageInterface_00024CppProxy_native_1s(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_s) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::EnumUsageInterface>(nativeRef); + auto r = ref->s(::djinni::Set<::djinni_generated::NativeColor>::toCpp(jniEnv, j_s)); + return ::djinni::release(::djinni::Set<::djinni_generated::NativeColor>::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_EnumUsageInterface_00024CppProxy_native_1m(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_m) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::EnumUsageInterface>(nativeRef); + auto r = ref->m(::djinni::Map<::djinni_generated::NativeColor, ::djinni_generated::NativeColor>::toCpp(jniEnv, j_m)); + return ::djinni::release(::djinni::Map<::djinni_generated::NativeColor, ::djinni_generated::NativeColor>::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeEnumUsageInterface.hpp b/test-suite/generated-src/jni/NativeEnumUsageInterface.hpp new file mode 100644 index 000000000..9710b002b --- /dev/null +++ b/test-suite/generated-src/jni/NativeEnumUsageInterface.hpp @@ -0,0 +1,54 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "enum_usage_interface.hpp" + +namespace djinni_generated { + +class NativeEnumUsageInterface final : ::djinni::JniInterface<::testsuite::EnumUsageInterface, NativeEnumUsageInterface> { +public: + using CppType = std::shared_ptr<::testsuite::EnumUsageInterface>; + using CppOptType = std::shared_ptr<::testsuite::EnumUsageInterface>; + using JniType = jobject; + + using Boxed = NativeEnumUsageInterface; + + ~NativeEnumUsageInterface(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j) { return ::djinni::JniClass::get()._fromJava(jniEnv, j); } + static ::djinni::LocalRef fromCppOpt(JNIEnv* jniEnv, const CppOptType& c) { return {jniEnv, ::djinni::JniClass::get()._toJava(jniEnv, c)}; } + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) { return fromCppOpt(jniEnv, c); } + +private: + NativeEnumUsageInterface(); + friend ::djinni::JniClass; + friend ::djinni::JniInterface<::testsuite::EnumUsageInterface, NativeEnumUsageInterface>; + + class JavaProxy final : ::djinni::JavaProxyHandle, public ::testsuite::EnumUsageInterface + { + public: + JavaProxy(JniType j); + ~JavaProxy(); + + ::testsuite::color e(::testsuite::color e) override; + std::experimental::optional<::testsuite::color> o(std::experimental::optional<::testsuite::color> o) override; + std::vector<::testsuite::color> l(const std::vector<::testsuite::color> & l) override; + std::unordered_set<::testsuite::color> s(const std::unordered_set<::testsuite::color> & s) override; + std::unordered_map<::testsuite::color, ::testsuite::color> m(const std::unordered_map<::testsuite::color, ::testsuite::color> & m) override; + + private: + friend ::djinni::JniInterface<::testsuite::EnumUsageInterface, ::djinni_generated::NativeEnumUsageInterface>; + }; + + const ::djinni::GlobalRef clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/EnumUsageInterface") }; + const jmethodID method_e { ::djinni::jniGetMethodID(clazz.get(), "e", "(Lcom/dropbox/djinni/test/Color;)Lcom/dropbox/djinni/test/Color;") }; + const jmethodID method_o { ::djinni::jniGetMethodID(clazz.get(), "o", "(Lcom/dropbox/djinni/test/Color;)Lcom/dropbox/djinni/test/Color;") }; + const jmethodID method_l { ::djinni::jniGetMethodID(clazz.get(), "l", "(Ljava/util/ArrayList;)Ljava/util/ArrayList;") }; + const jmethodID method_s { ::djinni::jniGetMethodID(clazz.get(), "s", "(Ljava/util/HashSet;)Ljava/util/HashSet;") }; + const jmethodID method_m { ::djinni::jniGetMethodID(clazz.get(), "m", "(Ljava/util/HashMap;)Ljava/util/HashMap;") }; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeEnumUsageRecord.cpp b/test-suite/generated-src/jni/NativeEnumUsageRecord.cpp new file mode 100644 index 000000000..0460969ac --- /dev/null +++ b/test-suite/generated-src/jni/NativeEnumUsageRecord.cpp @@ -0,0 +1,37 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#include "NativeEnumUsageRecord.hpp" // my header +#include "Marshal.hpp" +#include "NativeColor.hpp" + +namespace djinni_generated { + +NativeEnumUsageRecord::NativeEnumUsageRecord() = default; + +NativeEnumUsageRecord::~NativeEnumUsageRecord() = default; + +auto NativeEnumUsageRecord::fromCpp(JNIEnv* jniEnv, const CppType& c) -> ::djinni::LocalRef { + const auto& data = ::djinni::JniClass::get(); + auto r = ::djinni::LocalRef{jniEnv->NewObject(data.clazz.get(), data.jconstructor, + ::djinni::get(::djinni_generated::NativeColor::fromCpp(jniEnv, c.e)), + ::djinni::get(::djinni::Optional::fromCpp(jniEnv, c.o)), + ::djinni::get(::djinni::List<::djinni_generated::NativeColor>::fromCpp(jniEnv, c.l)), + ::djinni::get(::djinni::Set<::djinni_generated::NativeColor>::fromCpp(jniEnv, c.s)), + ::djinni::get(::djinni::Map<::djinni_generated::NativeColor, ::djinni_generated::NativeColor>::fromCpp(jniEnv, c.m)))}; + ::djinni::jniExceptionCheck(jniEnv); + return r; +} + +auto NativeEnumUsageRecord::toCpp(JNIEnv* jniEnv, JniType j) -> CppType { + ::djinni::JniLocalScope jscope(jniEnv, 6); + assert(j != nullptr); + const auto& data = ::djinni::JniClass::get(); + return {::djinni_generated::NativeColor::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mE)), + ::djinni::Optional::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mO)), + ::djinni::List<::djinni_generated::NativeColor>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mL)), + ::djinni::Set<::djinni_generated::NativeColor>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mS)), + ::djinni::Map<::djinni_generated::NativeColor, ::djinni_generated::NativeColor>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mM))}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeEnumUsageRecord.hpp b/test-suite/generated-src/jni/NativeEnumUsageRecord.hpp new file mode 100644 index 000000000..fbc3bbfbd --- /dev/null +++ b/test-suite/generated-src/jni/NativeEnumUsageRecord.hpp @@ -0,0 +1,36 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "enum_usage_record.hpp" + +namespace djinni_generated { + +class NativeEnumUsageRecord final { +public: + using CppType = ::testsuite::EnumUsageRecord; + using JniType = jobject; + + using Boxed = NativeEnumUsageRecord; + + ~NativeEnumUsageRecord(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j); + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c); + +private: + NativeEnumUsageRecord(); + friend ::djinni::JniClass; + + const ::djinni::GlobalRef clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/EnumUsageRecord") }; + const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "", "(Lcom/dropbox/djinni/test/Color;Lcom/dropbox/djinni/test/Color;Ljava/util/ArrayList;Ljava/util/HashSet;Ljava/util/HashMap;)V") }; + const jfieldID field_mE { ::djinni::jniGetFieldID(clazz.get(), "mE", "Lcom/dropbox/djinni/test/Color;") }; + const jfieldID field_mO { ::djinni::jniGetFieldID(clazz.get(), "mO", "Lcom/dropbox/djinni/test/Color;") }; + const jfieldID field_mL { ::djinni::jniGetFieldID(clazz.get(), "mL", "Ljava/util/ArrayList;") }; + const jfieldID field_mS { ::djinni::jniGetFieldID(clazz.get(), "mS", "Ljava/util/HashSet;") }; + const jfieldID field_mM { ::djinni::jniGetFieldID(clazz.get(), "mM", "Ljava/util/HashMap;") }; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeOptColorRecord.cpp b/test-suite/generated-src/jni/NativeOptColorRecord.cpp deleted file mode 100644 index d351766ed..000000000 --- a/test-suite/generated-src/jni/NativeOptColorRecord.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file generated by Djinni from enum.djinni - -#include "NativeOptColorRecord.hpp" // my header -#include "Marshal.hpp" -#include "NativeColor.hpp" - -namespace djinni_generated { - -NativeOptColorRecord::NativeOptColorRecord() = default; - -NativeOptColorRecord::~NativeOptColorRecord() = default; - -auto NativeOptColorRecord::fromCpp(JNIEnv* jniEnv, const CppType& c) -> ::djinni::LocalRef { - const auto& data = ::djinni::JniClass::get(); - auto r = ::djinni::LocalRef{jniEnv->NewObject(data.clazz.get(), data.jconstructor, - ::djinni::get(::djinni::Optional::fromCpp(jniEnv, c.my_color)))}; - ::djinni::jniExceptionCheck(jniEnv); - return r; -} - -auto NativeOptColorRecord::toCpp(JNIEnv* jniEnv, JniType j) -> CppType { - ::djinni::JniLocalScope jscope(jniEnv, 2); - assert(j != nullptr); - const auto& data = ::djinni::JniClass::get(); - return {::djinni::Optional::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mMyColor))}; -} - -} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeOptColorRecord.hpp b/test-suite/generated-src/jni/NativeOptColorRecord.hpp deleted file mode 100644 index c01c9f83e..000000000 --- a/test-suite/generated-src/jni/NativeOptColorRecord.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file generated by Djinni from enum.djinni - -#pragma once - -#include "djinni_support.hpp" -#include "opt_color_record.hpp" - -namespace djinni_generated { - -class NativeOptColorRecord final { -public: - using CppType = ::testsuite::OptColorRecord; - using JniType = jobject; - - using Boxed = NativeOptColorRecord; - - ~NativeOptColorRecord(); - - static CppType toCpp(JNIEnv* jniEnv, JniType j); - static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c); - -private: - NativeOptColorRecord(); - friend ::djinni::JniClass; - - const ::djinni::GlobalRef clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/OptColorRecord") }; - const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "", "(Lcom/dropbox/djinni/test/Color;)V") }; - const jfieldID field_mMyColor { ::djinni::jniGetFieldID(clazz.get(), "mMyColor", "Lcom/dropbox/djinni/test/Color;") }; -}; - -} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBColor+Private.h b/test-suite/generated-src/objc/DBColor+Private.h new file mode 100644 index 000000000..018fa9ff0 --- /dev/null +++ b/test-suite/generated-src/objc/DBColor+Private.h @@ -0,0 +1,6 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#include "color.hpp" +#import "DJIMarshal+Private.h" + diff --git a/test-suite/generated-src/objc/DBEnumUsageInterface+Private.h b/test-suite/generated-src/objc/DBEnumUsageInterface+Private.h new file mode 100644 index 000000000..80debb368 --- /dev/null +++ b/test-suite/generated-src/objc/DBEnumUsageInterface+Private.h @@ -0,0 +1,31 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#include "enum_usage_interface.hpp" +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@protocol DBEnumUsageInterface; + +namespace djinni_generated { + +class EnumUsageInterface +{ +public: + using CppType = std::shared_ptr<::testsuite::EnumUsageInterface>; + using CppOptType = std::shared_ptr<::testsuite::EnumUsageInterface>; + using ObjcType = id; + + using Boxed = EnumUsageInterface; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCppOpt(const CppOptType& cpp); + static ObjcType fromCpp(const CppType& cpp) { return fromCppOpt(cpp); } + +private: + class ObjcProxy; +}; + +} // namespace djinni_generated + diff --git a/test-suite/generated-src/objc/DBEnumUsageInterface+Private.mm b/test-suite/generated-src/objc/DBEnumUsageInterface+Private.mm new file mode 100644 index 000000000..b6f61b1dc --- /dev/null +++ b/test-suite/generated-src/objc/DBEnumUsageInterface+Private.mm @@ -0,0 +1,142 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#import "DBEnumUsageInterface+Private.h" +#import "DBEnumUsageInterface.h" +#import "DBColor+Private.h" +#import "DJICppWrapperCache+Private.h" +#import "DJIError.h" +#import "DJIMarshal+Private.h" +#import "DJIObjcWrapperCache+Private.h" +#include +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@interface DBEnumUsageInterfaceCppProxy : NSObject + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::EnumUsageInterface>&)cppRef; + +@end + +@implementation DBEnumUsageInterfaceCppProxy { + ::djinni::CppProxyCache::Handle> _cppRefHandle; +} + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::EnumUsageInterface>&)cppRef +{ + if (self = [super init]) { + _cppRefHandle.assign(cppRef); + } + return self; +} + +- (DBColor)e:(DBColor)e { + try { + auto r = _cppRefHandle.get()->e(::djinni::Enum<::testsuite::color, DBColor>::toCpp(e)); + return ::djinni::Enum<::testsuite::color, DBColor>::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +- (nullable NSNumber *)o:(nullable NSNumber *)o { + try { + auto r = _cppRefHandle.get()->o(::djinni::Optional>::toCpp(o)); + return ::djinni::Optional>::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +- (nonnull NSArray *)l:(nonnull NSArray *)l { + try { + auto r = _cppRefHandle.get()->l(::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(l)); + return ::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +- (nonnull NSSet *)s:(nonnull NSSet *)s { + try { + auto r = _cppRefHandle.get()->s(::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(s)); + return ::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +- (nonnull NSDictionary *)m:(nonnull NSDictionary *)m { + try { + auto r = _cppRefHandle.get()->m(::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::toCpp(m)); + return ::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +namespace djinni_generated { + +class EnumUsageInterface::ObjcProxy final +: public ::testsuite::EnumUsageInterface +, public ::djinni::ObjcProxyCache::Handle +{ +public: + using Handle::Handle; + ::testsuite::color e(::testsuite::color c_e) override + { + @autoreleasepool { + auto r = [Handle::get() e:(::djinni::Enum<::testsuite::color, DBColor>::fromCpp(c_e))]; + return ::djinni::Enum<::testsuite::color, DBColor>::toCpp(r); + } + } + std::experimental::optional<::testsuite::color> o(std::experimental::optional<::testsuite::color> c_o) override + { + @autoreleasepool { + auto r = [Handle::get() o:(::djinni::Optional>::fromCpp(c_o))]; + return ::djinni::Optional>::toCpp(r); + } + } + std::vector<::testsuite::color> l(const std::vector<::testsuite::color> & c_l) override + { + @autoreleasepool { + auto r = [Handle::get() l:(::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(c_l))]; + return ::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(r); + } + } + std::unordered_set<::testsuite::color> s(const std::unordered_set<::testsuite::color> & c_s) override + { + @autoreleasepool { + auto r = [Handle::get() s:(::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(c_s))]; + return ::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(r); + } + } + std::unordered_map<::testsuite::color, ::testsuite::color> m(const std::unordered_map<::testsuite::color, ::testsuite::color> & c_m) override + { + @autoreleasepool { + auto r = [Handle::get() m:(::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(c_m))]; + return ::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::toCpp(r); + } + } +}; + +} // namespace djinni_generated + +namespace djinni_generated { + +auto EnumUsageInterface::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + if ([(id)objc isKindOfClass:[DBEnumUsageInterfaceCppProxy class]]) { + return ((DBEnumUsageInterfaceCppProxy*)objc)->_cppRefHandle.get(); + } + return ::djinni::get_objc_proxy(objc); +} + +auto EnumUsageInterface::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + if (auto cppPtr = dynamic_cast(cpp.get())) { + return cppPtr->Handle::get(); + } + return ::djinni::get_cpp_proxy(cpp); +} + +} // namespace djinni_generated + +@end diff --git a/test-suite/generated-src/objc/DBEnumUsageInterface.h b/test-suite/generated-src/objc/DBEnumUsageInterface.h new file mode 100644 index 000000000..b1dea8045 --- /dev/null +++ b/test-suite/generated-src/objc/DBEnumUsageInterface.h @@ -0,0 +1,20 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#import "DBColor.h" +#import + + +@protocol DBEnumUsageInterface + +- (DBColor)e:(DBColor)e; + +- (nullable NSNumber *)o:(nullable NSNumber *)o; + +- (nonnull NSArray *)l:(nonnull NSArray *)l; + +- (nonnull NSSet *)s:(nonnull NSSet *)s; + +- (nonnull NSDictionary *)m:(nonnull NSDictionary *)m; + +@end diff --git a/test-suite/generated-src/objc/DBOptColorRecord+Private.h b/test-suite/generated-src/objc/DBEnumUsageRecord+Private.h similarity index 59% rename from test-suite/generated-src/objc/DBOptColorRecord+Private.h rename to test-suite/generated-src/objc/DBEnumUsageRecord+Private.h index 91b0fdd87..49168caca 100644 --- a/test-suite/generated-src/objc/DBOptColorRecord+Private.h +++ b/test-suite/generated-src/objc/DBEnumUsageRecord+Private.h @@ -1,21 +1,21 @@ // AUTOGENERATED FILE - DO NOT MODIFY! // This file generated by Djinni from enum.djinni -#import "DBOptColorRecord.h" -#include "opt_color_record.hpp" +#import "DBEnumUsageRecord.h" +#include "enum_usage_record.hpp" static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); -@class DBOptColorRecord; +@class DBEnumUsageRecord; namespace djinni_generated { -struct OptColorRecord +struct EnumUsageRecord { - using CppType = ::testsuite::OptColorRecord; - using ObjcType = DBOptColorRecord*; + using CppType = ::testsuite::EnumUsageRecord; + using ObjcType = DBEnumUsageRecord*; - using Boxed = OptColorRecord; + using Boxed = EnumUsageRecord; static CppType toCpp(ObjcType objc); static ObjcType fromCpp(const CppType& cpp); diff --git a/test-suite/generated-src/objc/DBEnumUsageRecord+Private.mm b/test-suite/generated-src/objc/DBEnumUsageRecord+Private.mm new file mode 100644 index 000000000..2f21a3b69 --- /dev/null +++ b/test-suite/generated-src/objc/DBEnumUsageRecord+Private.mm @@ -0,0 +1,30 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#import "DBEnumUsageRecord+Private.h" +#import "DBColor+Private.h" +#import "DJIMarshal+Private.h" +#include + +namespace djinni_generated { + +auto EnumUsageRecord::toCpp(ObjcType obj) -> CppType +{ + assert(obj); + return {::djinni::Enum<::testsuite::color, DBColor>::toCpp(obj.e), + ::djinni::Optional>::toCpp(obj.o), + ::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(obj.l), + ::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(obj.s), + ::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::toCpp(obj.m)}; +} + +auto EnumUsageRecord::fromCpp(const CppType& cpp) -> ObjcType +{ + return [[DBEnumUsageRecord alloc] initWithE:(::djinni::Enum<::testsuite::color, DBColor>::fromCpp(cpp.e)) + o:(::djinni::Optional>::fromCpp(cpp.o)) + l:(::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(cpp.l)) + s:(::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(cpp.s)) + m:(::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(cpp.m))]; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBEnumUsageRecord.h b/test-suite/generated-src/objc/DBEnumUsageRecord.h new file mode 100644 index 000000000..cbc7f0952 --- /dev/null +++ b/test-suite/generated-src/objc/DBEnumUsageRecord.h @@ -0,0 +1,29 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#import "DBColor.h" +#import + +@interface DBEnumUsageRecord : NSObject +- (nonnull instancetype)initWithE:(DBColor)e + o:(nullable NSNumber *)o + l:(nonnull NSArray *)l + s:(nonnull NSSet *)s + m:(nonnull NSDictionary *)m; ++ (nonnull instancetype)enumUsageRecordWithE:(DBColor)e + o:(nullable NSNumber *)o + l:(nonnull NSArray *)l + s:(nonnull NSSet *)s + m:(nonnull NSDictionary *)m; + +@property (nonatomic, readonly) DBColor e; + +@property (nonatomic, readonly, nullable) NSNumber * o; + +@property (nonatomic, readonly, nonnull) NSArray * l; + +@property (nonatomic, readonly, nonnull) NSSet * s; + +@property (nonatomic, readonly, nonnull) NSDictionary * m; + +@end diff --git a/test-suite/generated-src/objc/DBEnumUsageRecord.mm b/test-suite/generated-src/objc/DBEnumUsageRecord.mm new file mode 100644 index 000000000..94a311561 --- /dev/null +++ b/test-suite/generated-src/objc/DBEnumUsageRecord.mm @@ -0,0 +1,43 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from enum.djinni + +#import "DBEnumUsageRecord.h" + + +@implementation DBEnumUsageRecord + +- (nonnull instancetype)initWithE:(DBColor)e + o:(nullable NSNumber *)o + l:(nonnull NSArray *)l + s:(nonnull NSSet *)s + m:(nonnull NSDictionary *)m +{ + if (self = [super init]) { + _e = e; + _o = o; + _l = [l copy]; + _s = [s copy]; + _m = [m copy]; + } + return self; +} + ++ (nonnull instancetype)enumUsageRecordWithE:(DBColor)e + o:(nullable NSNumber *)o + l:(nonnull NSArray *)l + s:(nonnull NSSet *)s + m:(nonnull NSDictionary *)m +{ + return [[self alloc] initWithE:e + o:o + l:l + s:s + m:m]; +} + +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@ %p e:%@ o:%@ l:%@ s:%@ m:%@>", self.class, (void *)self, @(self.e), self.o, self.l, self.s, self.m]; +} + +@end diff --git a/test-suite/generated-src/objc/DBExternRecordWithDerivings+Private.mm b/test-suite/generated-src/objc/DBExternRecordWithDerivings+Private.mm index 6d3cd729d..cbb9559c9 100644 --- a/test-suite/generated-src/objc/DBExternRecordWithDerivings+Private.mm +++ b/test-suite/generated-src/objc/DBExternRecordWithDerivings+Private.mm @@ -2,8 +2,8 @@ // This file generated by Djinni from yaml-test.djinni #import "DBExternRecordWithDerivings+Private.h" +#import "DBColor+Private.h" #import "DBRecordWithDerivings+Private.h" -#import "DJIMarshal+Private.h" #include namespace djinni_generated { diff --git a/test-suite/generated-src/objc/DBOptColorRecord+Private.mm b/test-suite/generated-src/objc/DBOptColorRecord+Private.mm deleted file mode 100644 index 1ab0d4a09..000000000 --- a/test-suite/generated-src/objc/DBOptColorRecord+Private.mm +++ /dev/null @@ -1,21 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file generated by Djinni from enum.djinni - -#import "DBOptColorRecord+Private.h" -#import "DJIMarshal+Private.h" -#include - -namespace djinni_generated { - -auto OptColorRecord::toCpp(ObjcType obj) -> CppType -{ - assert(obj); - return {::djinni::Optional>::toCpp(obj.myColor)}; -} - -auto OptColorRecord::fromCpp(const CppType& cpp) -> ObjcType -{ - return [[DBOptColorRecord alloc] initWithMyColor:(::djinni::Optional>::fromCpp(cpp.my_color))]; -} - -} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBOptColorRecord.h b/test-suite/generated-src/objc/DBOptColorRecord.h deleted file mode 100644 index a8e16a476..000000000 --- a/test-suite/generated-src/objc/DBOptColorRecord.h +++ /dev/null @@ -1,13 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file generated by Djinni from enum.djinni - -#import "DBColor.h" -#import - -@interface DBOptColorRecord : NSObject -- (nonnull instancetype)initWithMyColor:(nullable NSNumber *)myColor; -+ (nonnull instancetype)optColorRecordWithMyColor:(nullable NSNumber *)myColor; - -@property (nonatomic, readonly, nullable) NSNumber * myColor; - -@end diff --git a/test-suite/generated-src/objc/DBOptColorRecord.mm b/test-suite/generated-src/objc/DBOptColorRecord.mm deleted file mode 100644 index c2643beda..000000000 --- a/test-suite/generated-src/objc/DBOptColorRecord.mm +++ /dev/null @@ -1,27 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file generated by Djinni from enum.djinni - -#import "DBOptColorRecord.h" - - -@implementation DBOptColorRecord - -- (nonnull instancetype)initWithMyColor:(nullable NSNumber *)myColor -{ - if (self = [super init]) { - _myColor = myColor; - } - return self; -} - -+ (nonnull instancetype)optColorRecordWithMyColor:(nullable NSNumber *)myColor -{ - return [[self alloc] initWithMyColor:myColor]; -} - -- (NSString *)description -{ - return [NSString stringWithFormat:@"<%@ %p myColor:%@>", self.class, (void *)self, self.myColor]; -} - -@end diff --git a/test-suite/generated-src/objc/DBTestHelpers+Private.mm b/test-suite/generated-src/objc/DBTestHelpers+Private.mm index f51065b7f..ff419ad94 100644 --- a/test-suite/generated-src/objc/DBTestHelpers+Private.mm +++ b/test-suite/generated-src/objc/DBTestHelpers+Private.mm @@ -5,6 +5,7 @@ #import "DBTestHelpers.h" #import "DBAssortedPrimitives+Private.h" #import "DBClientInterface+Private.h" +#import "DBColor+Private.h" #import "DBMapListRecord+Private.h" #import "DBNestedCollection+Private.h" #import "DBPrimitiveList+Private.h" diff --git a/test-suite/generated-src/outFileList.txt b/test-suite/generated-src/outFileList.txt index d6b91678e..b14ab5afc 100644 --- a/test-suite/generated-src/outFileList.txt +++ b/test-suite/generated-src/outFileList.txt @@ -27,7 +27,8 @@ djinni-output-temp/cpp/Conflict.hpp djinni-output-temp/cpp/conflict_user.hpp djinni-output-temp/cpp/user_token.hpp djinni-output-temp/cpp/color.hpp -djinni-output-temp/cpp/opt_color_record.hpp +djinni-output-temp/cpp/enum_usage_record.hpp +djinni-output-temp/cpp/enum_usage_interface.hpp djinni-output-temp/cpp/client_returned_record.hpp djinni-output-temp/cpp/client_interface.hpp djinni-output-temp/cpp/reverse_client_interface.hpp @@ -64,7 +65,8 @@ djinni-output-temp/java/Conflict.java djinni-output-temp/java/ConflictUser.java djinni-output-temp/java/UserToken.java djinni-output-temp/java/Color.java -djinni-output-temp/java/OptColorRecord.java +djinni-output-temp/java/EnumUsageRecord.java +djinni-output-temp/java/EnumUsageInterface.java djinni-output-temp/java/ClientReturnedRecord.java djinni-output-temp/java/ClientInterface.java djinni-output-temp/java/ReverseClientInterface.java @@ -121,8 +123,10 @@ djinni-output-temp/jni/NativeConflictUser.cpp djinni-output-temp/jni/NativeUserToken.hpp djinni-output-temp/jni/NativeUserToken.cpp djinni-output-temp/jni/NativeColor.hpp -djinni-output-temp/jni/NativeOptColorRecord.hpp -djinni-output-temp/jni/NativeOptColorRecord.cpp +djinni-output-temp/jni/NativeEnumUsageRecord.hpp +djinni-output-temp/jni/NativeEnumUsageRecord.cpp +djinni-output-temp/jni/NativeEnumUsageInterface.hpp +djinni-output-temp/jni/NativeEnumUsageInterface.cpp djinni-output-temp/jni/NativeClientReturnedRecord.hpp djinni-output-temp/jni/NativeClientReturnedRecord.cpp djinni-output-temp/jni/NativeClientInterface.hpp @@ -177,8 +181,9 @@ djinni-output-temp/objc/DBConflict.h djinni-output-temp/objc/DBConflictUser.h djinni-output-temp/objc/DBUserToken.h djinni-output-temp/objc/DBColor.h -djinni-output-temp/objc/DBOptColorRecord.h -djinni-output-temp/objc/DBOptColorRecord.mm +djinni-output-temp/objc/DBEnumUsageRecord.h +djinni-output-temp/objc/DBEnumUsageRecord.mm +djinni-output-temp/objc/DBEnumUsageInterface.h djinni-output-temp/objc/DBClientReturnedRecord.h djinni-output-temp/objc/DBClientReturnedRecord.mm djinni-output-temp/objc/DBClientInterface.h @@ -242,8 +247,11 @@ djinni-output-temp/objc/DBConflictUser+Private.h djinni-output-temp/objc/DBConflictUser+Private.mm djinni-output-temp/objc/DBUserToken+Private.h djinni-output-temp/objc/DBUserToken+Private.mm -djinni-output-temp/objc/DBOptColorRecord+Private.h -djinni-output-temp/objc/DBOptColorRecord+Private.mm +djinni-output-temp/objc/DBColor+Private.h +djinni-output-temp/objc/DBEnumUsageRecord+Private.h +djinni-output-temp/objc/DBEnumUsageRecord+Private.mm +djinni-output-temp/objc/DBEnumUsageInterface+Private.h +djinni-output-temp/objc/DBEnumUsageInterface+Private.mm djinni-output-temp/objc/DBClientReturnedRecord+Private.h djinni-output-temp/objc/DBClientReturnedRecord+Private.mm djinni-output-temp/objc/DBClientInterface+Private.h diff --git a/test-suite/handwritten-src/cpp/optional.hpp b/test-suite/handwritten-src/cpp/optional.hpp new file mode 100644 index 000000000..bf6ea67cd --- /dev/null +++ b/test-suite/handwritten-src/cpp/optional.hpp @@ -0,0 +1,891 @@ +// Copyright (C) 2011 - 2012 Andrzej Krzemienski. +// +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0, as follows: +// +// Boost Software License - Version 1.0 - August 17th, 2003 +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// The idea and interface is based on Boost.Optional library +// authored by Fernando Luis Cacciola Carballal + +# ifndef ___OPTIONAL_HPP___ +# define ___OPTIONAL_HPP___ + +# include +# include +# include +# include +# include +# include +# include + +# define REQUIRES(...) typename enable_if<__VA_ARGS__::value, bool>::type = false + +# if defined __clang__ +# if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9) +# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 +# else +# define OPTIONAL_HAS_THIS_RVALUE_REFS 0 +# endif +# else +# define OPTIONAL_HAS_THIS_RVALUE_REFS 0 +# endif + + +namespace std{ + +namespace experimental{ + + +// 20.5.4, optional for object types +template class optional; + +// 20.5.5, optional for lvalue reference types +template class optional; + + +// workaround: std utility functions aren't constexpr yet +template inline constexpr T&& constexpr_forward(typename std::remove_reference::type& t) noexcept +{ + return static_cast(t); +} + +template inline constexpr T&& constexpr_forward(typename std::remove_reference::type&& t) noexcept +{ + static_assert(!std::is_lvalue_reference::value, "!!"); + return static_cast(t); +} + +template inline constexpr typename std::remove_reference::type&& constexpr_move(T&& t) noexcept +{ + return static_cast::type&&>(t); +} + +template inline constexpr _Ty * constexpr_addressof(_Ty& _Val) +{ + return ((_Ty *) &(char&)_Val); +} + + +#if defined NDEBUG +# define ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR) +#else +# define ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([]{assert(#CHECK && false);}(), (EXPR))) +#endif + + +template +struct has_overloaded_addressof +{ + template + static constexpr bool has_overload(...) { return false; } + + template ().operator&()) > + static constexpr bool has_overload(bool) { return true; } + + constexpr static bool value = has_overload(true); +}; + + + +template )> +constexpr T* static_addressof(T& ref) +{ + return &ref; +} + +template )> +T* static_addressof(T& ref) +{ + return std::addressof(ref); +} + + + +template +struct is_not_optional +{ + constexpr static bool value = true; +}; + +template +struct is_not_optional> +{ + constexpr static bool value = false; +}; + + +constexpr struct trivial_init_t{} trivial_init{}; + + +// 20.5.6, In-place construction +constexpr struct in_place_t{} in_place{}; + + +// 20.5.7, Disengaged state indicator +struct nullopt_t +{ + struct init{}; + constexpr nullopt_t(init){}; +}; +constexpr nullopt_t nullopt{nullopt_t::init()}; + + +// 20.5.8, class bad_optional_access +class bad_optional_access : public logic_error { +public: + explicit bad_optional_access(const string& what_arg) : logic_error{what_arg} {} + explicit bad_optional_access(const char* what_arg) : logic_error{what_arg} {} +}; + + +template +union storage_t +{ + unsigned char dummy_; + T value_; + + constexpr storage_t( trivial_init_t ) noexcept : dummy_() {}; + + template + constexpr storage_t( Args&&... args ) : value_(constexpr_forward(args)...) {} + + ~storage_t(){} +}; + + +template +union constexpr_storage_t +{ + unsigned char dummy_; + T value_; + + constexpr constexpr_storage_t( trivial_init_t ) noexcept : dummy_() {}; + + template + constexpr constexpr_storage_t( Args&&... args ) : value_(constexpr_forward(args)...) {} + + ~constexpr_storage_t() = default; +}; + + +constexpr struct only_set_initialized_t{} only_set_initialized{}; + + +template +struct optional_base +{ + bool init_; + storage_t storage_; + + constexpr optional_base() noexcept : init_(false), storage_(trivial_init) {}; + + constexpr explicit optional_base(only_set_initialized_t, bool init) noexcept : init_(init), storage_(trivial_init) {}; + + explicit constexpr optional_base(const T& v) : init_(true), storage_(v) {} + + explicit constexpr optional_base(T&& v) : init_(true), storage_(constexpr_move(v)) {} + + template explicit optional_base(in_place_t, Args&&... args) + : init_(true), storage_(constexpr_forward(args)...) {} + + template >)> + explicit optional_base(in_place_t, std::initializer_list il, Args&&... args) + : init_(true), storage_(il, std::forward(args)...) {} + + ~optional_base() { if (init_) storage_.value_.T::~T(); } +}; + + +template +struct constexpr_optional_base +{ + bool init_; + constexpr_storage_t storage_; + + constexpr constexpr_optional_base() noexcept : init_(false), storage_(trivial_init) {}; + + constexpr explicit constexpr_optional_base(only_set_initialized_t, bool init) noexcept : init_(init), storage_(trivial_init) {}; + + explicit constexpr constexpr_optional_base(const T& v) : init_(true), storage_(v) {} + + explicit constexpr constexpr_optional_base(T&& v) : init_(true), storage_(constexpr_move(v)) {} + + template explicit constexpr constexpr_optional_base(in_place_t, Args&&... args) + : init_(true), storage_(constexpr_forward(args)...) {} + + template >)> + explicit constexpr_optional_base(in_place_t, std::initializer_list il, Args&&... args) + : init_(true), storage_(il, std::forward(args)...) {} + + ~constexpr_optional_base() = default; +}; + +template +using OptionalBase = typename std::conditional< + std::is_trivially_destructible::value, + constexpr_optional_base, + optional_base +>::type; + +template +constexpr bool is_nothrow_swappable_() { + using std::swap; + return noexcept(swap(std::declval(), std::declval())); +} + +template +class optional : private OptionalBase +{ + static_assert( !std::is_same::type, nullopt_t>::value, "bad T" ); + static_assert( !std::is_same::type, in_place_t>::value, "bad T" ); + + + constexpr bool initialized() const noexcept { return OptionalBase::init_; } + T* dataptr() { return std::addressof(OptionalBase::storage_.value_); } + constexpr const T* dataptr() const { return static_addressof(OptionalBase::storage_.value_); } + +# if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 + constexpr const T& contained_val() const& { return OptionalBase::storage_.value_; } + T& contained_val() & { return OptionalBase::storage_.value_; } + T&& contained_val() && { return std::move(OptionalBase::storage_.value_); } +# else + constexpr const T& contained_val() const { return OptionalBase::storage_.value_; } + T& contained_val() { return OptionalBase::storage_.value_; } +# endif + + void clear() noexcept { + if (initialized()) dataptr()->T::~T(); + OptionalBase::init_ = false; + } + + template + void initialize(Args&&... args) noexcept(noexcept(T(std::forward(args)...))) + { + assert(!OptionalBase::init_); + new (dataptr()) T(std::forward(args)...); + OptionalBase::init_ = true; + } + + template + void initialize(std::initializer_list il, Args&&... args) noexcept(noexcept(T(il, std::forward(args)...))) + { + assert(!OptionalBase::init_); + new (dataptr()) T(il, std::forward(args)...); + OptionalBase::init_ = true; + } + +public: + typedef T value_type; + + // 20.5.5.1, constructors + constexpr optional() noexcept : OptionalBase() {}; + constexpr optional(nullopt_t) noexcept : OptionalBase() {}; + + optional(const optional& rhs) + : OptionalBase(only_set_initialized, rhs.initialized()) + { + if (rhs.initialized()) new (dataptr()) T(*rhs); + } + + optional(optional&& rhs) noexcept(std::is_nothrow_move_constructible::value) + : OptionalBase(only_set_initialized, rhs.initialized()) + { + if (rhs.initialized()) new (dataptr()) T(std::move(*rhs)); + } + + constexpr optional(const T& v) : OptionalBase(v) {} + + constexpr optional(T&& v) : OptionalBase(constexpr_move(v)) {} + + template + constexpr explicit optional(in_place_t, Args&&... args) + : OptionalBase(in_place_t{}, constexpr_forward(args)...) {} + + template >)> + explicit optional(in_place_t, std::initializer_list il, Args&&... args) + : OptionalBase(in_place_t{}, il, constexpr_forward(args)...) {} + + // 20.5.4.2 Destructor + ~optional() = default; + + // 20.5.4.3, assignment + optional& operator=(nullopt_t) noexcept + { + clear(); + return *this; + } + + optional& operator=(const optional& rhs) + { + if (initialized() == true && rhs.initialized() == false) clear(); + else if (initialized() == false && rhs.initialized() == true) initialize(*rhs); + else if (initialized() == true && rhs.initialized() == true) contained_val() = *rhs; + return *this; + } + + optional& operator=(optional&& rhs) + noexcept(std::is_nothrow_move_assignable::value && std::is_nothrow_move_constructible::value) + { + if (initialized() == true && rhs.initialized() == false) clear(); + else if (initialized() == false && rhs.initialized() == true) initialize(std::move(*rhs)); + else if (initialized() == true && rhs.initialized() == true) contained_val() = std::move(*rhs); + return *this; + } + + template + auto operator=(U&& v) + -> typename enable_if + < + is_same::type, T>::value, + optional& + >::type + { + if (initialized()) { contained_val() = std::forward(v); } + else { initialize(std::forward(v)); } + return *this; + } + + + template + optional& emplace(Args&&... args) + { + clear(); + initialize(std::forward(args)...); + return *this; + } + + template + optional& emplace(initializer_list il, Args&&... args) + { + clear(); + initialize(il, std::forward(args)...); + return *this; + } + + // 20.5.4.4 Swap + void swap(optional& rhs) noexcept(is_nothrow_move_constructible::value && is_nothrow_swappable_()) + { + if (initialized() == true && rhs.initialized() == false) { rhs.initialize(std::move(**this)); clear(); } + else if (initialized() == false && rhs.initialized() == true) { initialize(std::move(*rhs)); rhs.clear(); } + else if (initialized() == true && rhs.initialized() == true) { using std::swap; swap(**this, *rhs); } + } + + // 20.5.4.5 Observers + constexpr T const* operator ->() const { + return ASSERTED_EXPRESSION(initialized(), dataptr()); + } + + T* operator ->() { + assert (initialized()); + return dataptr(); + } + + constexpr T const& operator *() const { + return ASSERTED_EXPRESSION(initialized(), contained_val()); + } + + T& operator *() { + assert (initialized()); + return contained_val(); + } + + constexpr T const& value() const { + return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val()); + } + + T& value() { + return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val()); + } + + constexpr explicit operator bool() const noexcept { return initialized(); } + +# if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 + + template + constexpr T value_or(V&& v) const& + { + return *this ? **this : static_cast(constexpr_forward(v)); + } + + template + T value_or(V&& v) && + { + return *this ? std::move(const_cast&>(*this).contained_val()) : static_cast(constexpr_forward(v)); + } + +# else + + template + constexpr T value_or(V&& v) const + { + return *this ? **this : static_cast(constexpr_forward(v)); + } + +# endif + +}; + + +template +class optional +{ + static_assert( !std::is_same::value, "bad T" ); + static_assert( !std::is_same::value, "bad T" ); + T* ref; + +public: + + // 20.5.5.1, construction/destruction + constexpr optional() noexcept : ref(nullptr) {} + + constexpr optional(nullopt_t) noexcept : ref(nullptr) {} + + constexpr optional(T& v) noexcept : ref(static_addressof(v)) {} + + optional(T&&) = delete; + + constexpr optional(const optional& rhs) noexcept : ref(rhs.ref) {} + + explicit constexpr optional(in_place_t, T& v) noexcept : ref(static_addressof(v)) {} + + explicit optional(in_place_t, T&&) = delete; + + ~optional() = default; + + // 20.5.5.2, mutation + optional& operator=(nullopt_t) noexcept { + ref = nullptr; + return *this; + } + + // optional& operator=(const optional& rhs) noexcept { + // ref = rhs.ref; + // return *this; + // } + + // optional& operator=(optional&& rhs) noexcept { + // ref = rhs.ref; + // return *this; + // } + + template + auto operator=(U&& rhs) noexcept + -> typename enable_if + < + is_same::type, optional>::value, + optional& + >::type + { + ref = rhs.ref; + return *this; + } + + template + auto operator=(U&& rhs) noexcept + -> typename enable_if + < + !is_same::type, optional>::value, + optional& + >::type + = delete; + + optional& emplace(T& v) noexcept { + ref = static_addressof(v); + return *this; + } + + optional& emplace(T&&) = delete; + + + void swap(optional& rhs) noexcept + { + std::swap(ref, rhs.ref); + } + + // 20.5.5.3, observers + constexpr T* operator->() const { + return ASSERTED_EXPRESSION(ref, ref); + } + + constexpr T& operator*() const { + return ASSERTED_EXPRESSION(ref, *ref); + } + + constexpr T& value() const { + return ref ? *ref : (throw bad_optional_access("bad optional access"), *ref); + } + + explicit constexpr operator bool() const noexcept { + return ref != nullptr; + } + + template + constexpr typename decay::type value_or(V&& v) const + { + return *this ? **this : static_cast::type>(constexpr_forward(v)); + } +}; + + +template +class optional +{ + static_assert( sizeof(T) == 0, "optional rvalue referencs disallowed" ); +}; + + +// 20.5.8, Relational operators +template constexpr bool operator==(const optional& x, const optional& y) +{ + return bool(x) != bool(y) ? false : bool(x) == false ? true : *x == *y; +} + +template constexpr bool operator!=(const optional& x, const optional& y) +{ + return !(x == y); +} + +template constexpr bool operator<(const optional& x, const optional& y) +{ + return (!y) ? false : (!x) ? true : *x < *y; +} + +template constexpr bool operator>(const optional& x, const optional& y) +{ + return (y < x); +} + +template constexpr bool operator<=(const optional& x, const optional& y) +{ + return !(y < x); +} + +template constexpr bool operator>=(const optional& x, const optional& y) +{ + return !(x < y); +} + + +// 20.5.9 Comparison with nullopt +template constexpr bool operator==(const optional& x, nullopt_t) noexcept +{ + return (!x); +} + +template constexpr bool operator==(nullopt_t, const optional& x) noexcept +{ + return (!x); +} + +template constexpr bool operator!=(const optional& x, nullopt_t) noexcept +{ + return bool(x); +} + +template constexpr bool operator!=(nullopt_t, const optional& x) noexcept +{ + return bool(x); +} + +template constexpr bool operator<(const optional&, nullopt_t) noexcept +{ + return false; +} + +template constexpr bool operator<(nullopt_t, const optional& x) noexcept +{ + return bool(x); +} + +template constexpr bool operator<=(const optional& x, nullopt_t) noexcept +{ + return (!x); +} + +template constexpr bool operator<=(nullopt_t, const optional&) noexcept +{ + return true; +} + +template constexpr bool operator>(const optional& x, nullopt_t) noexcept +{ + return bool(x); +} + +template constexpr bool operator>(nullopt_t, const optional&) noexcept +{ + return false; +} + +template constexpr bool operator>=(const optional&, nullopt_t) noexcept +{ + return true; +} + +template constexpr bool operator>=(nullopt_t, const optional& x) noexcept +{ + return (!x); +} + + + +// 20.5.10, Comparison with T +template constexpr bool operator==(const optional& x, const T& v) +{ + return bool(x) ? *x == v : false; +} + +template constexpr bool operator==(const T& v, const optional& x) +{ + return bool(x) ? v == *x : false; +} + +template constexpr bool operator!=(const optional& x, const T& v) +{ + return bool(x) ? *x != v : true; +} + +template constexpr bool operator!=(const T& v, const optional& x) +{ + return bool(x) ? v != *x : true; +} + +template constexpr bool operator<(const optional& x, const T& v) +{ + return bool(x) ? *x < v : true; +} + +template constexpr bool operator>(const T& v, const optional& x) +{ + return bool(x) ? v > *x : true; +} + +template constexpr bool operator>(const optional& x, const T& v) +{ + return bool(x) ? *x > v : false; +} + +template constexpr bool operator<(const T& v, const optional& x) +{ + return bool(x) ? v < *x : false; +} + +template constexpr bool operator>=(const optional& x, const T& v) +{ + return bool(x) ? *x >= v : false; +} + +template constexpr bool operator<=(const T& v, const optional& x) +{ + return bool(x) ? v <= *x : false; +} + +template constexpr bool operator<=(const optional& x, const T& v) +{ + return bool(x) ? *x <= v : true; +} + +template constexpr bool operator>=(const T& v, const optional& x) +{ + return bool(x) ? v >= *x : true; +} + + +// Comparison of optionsl with T +template constexpr bool operator==(const optional& x, const T& v) +{ + return bool(x) ? *x == v : false; +} + +template constexpr bool operator==(const T& v, const optional& x) +{ + return bool(x) ? v == *x : false; +} + +template constexpr bool operator!=(const optional& x, const T& v) +{ + return bool(x) ? *x != v : true; +} + +template constexpr bool operator!=(const T& v, const optional& x) +{ + return bool(x) ? v != *x : true; +} + +template constexpr bool operator<(const optional& x, const T& v) +{ + return bool(x) ? *x < v : true; +} + +template constexpr bool operator>(const T& v, const optional& x) +{ + return bool(x) ? v > *x : true; +} + +template constexpr bool operator>(const optional& x, const T& v) +{ + return bool(x) ? *x > v : false; +} + +template constexpr bool operator<(const T& v, const optional& x) +{ + return bool(x) ? v < *x : false; +} + +template constexpr bool operator>=(const optional& x, const T& v) +{ + return bool(x) ? *x >= v : false; +} + +template constexpr bool operator<=(const T& v, const optional& x) +{ + return bool(x) ? v <= *x : false; +} + +template constexpr bool operator<=(const optional& x, const T& v) +{ + return bool(x) ? *x <= v : true; +} + +template constexpr bool operator>=(const T& v, const optional& x) +{ + return bool(x) ? v >= *x : true; +} + +// Comparison of optionsl with T +template constexpr bool operator==(const optional& x, const T& v) +{ + return bool(x) ? *x == v : false; +} + +template constexpr bool operator==(const T& v, const optional& x) +{ + return bool(x) ? v == *x : false; +} + +template constexpr bool operator!=(const optional& x, const T& v) +{ + return bool(x) ? *x != v : true; +} + +template constexpr bool operator!=(const T& v, const optional& x) +{ + return bool(x) ? v != *x : true; +} + +template constexpr bool operator<(const optional& x, const T& v) +{ + return bool(x) ? *x < v : true; +} + +template constexpr bool operator>(const T& v, const optional& x) +{ + return bool(x) ? v > *x : true; +} + +template constexpr bool operator>(const optional& x, const T& v) +{ + return bool(x) ? *x > v : false; +} + +template constexpr bool operator<(const T& v, const optional& x) +{ + return bool(x) ? v < *x : false; +} + +template constexpr bool operator>=(const optional& x, const T& v) +{ + return bool(x) ? *x >= v : false; +} + +template constexpr bool operator<=(const T& v, const optional& x) +{ + return bool(x) ? v <= *x : false; +} + +template constexpr bool operator<=(const optional& x, const T& v) +{ + return bool(x) ? *x <= v : true; +} + +template constexpr bool operator>=(const T& v, const optional& x) +{ + return bool(x) ? v >= *x : true; +} + + +// 20.5.12 Specialized algorithms +template +void swap(optional& x, optional& y) noexcept(noexcept(x.swap(y))) +{ + x.swap(y); +} + + +template +constexpr optional::type> make_optional(T&& v) +{ + return optional::type>(constexpr_forward(v)); +} + +template +constexpr optional make_optional(reference_wrapper v) +{ + return optional(v.get()); +} + + +} // namespace experimental +} // namespace std + +namespace std +{ + template + struct hash> + { + typedef typename hash::result_type result_type; + typedef std::experimental::optional argument_type; + + constexpr result_type operator()(argument_type const& arg) const { + return arg ? std::hash{}(*arg) : result_type{}; + } + }; + + template + struct hash> + { + typedef typename hash::result_type result_type; + typedef std::experimental::optional argument_type; + + constexpr result_type operator()(argument_type const& arg) const { + return arg ? std::hash{}(*arg) : result_type{}; + } + }; +} + + + +# endif //___OPTIONAL_HPP___ diff --git a/test-suite/java/CMakeLists.txt b/test-suite/java/CMakeLists.txt index 1bb317296..4466cd21e 100644 --- a/test-suite/java/CMakeLists.txt +++ b/test-suite/java/CMakeLists.txt @@ -37,7 +37,7 @@ file( ../generated-src/cpp/*.cpp ../handwritten-src/cpp/*.cpp) -set(test_suite_common_flags "-g -Wall -Werror -std=c++1y") +set(test_suite_common_flags "-g -Wall -Werror -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${test_suite_common_flags}") if(UNIX OR APPLE) diff --git a/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj b/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj index 3c3c76b7f..1357a7d16 100644 --- a/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj +++ b/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj @@ -32,8 +32,6 @@ 65868B621989FE4200D60EEE /* libDjinniObjcTest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 65868B4A1989FE4200D60EEE /* libDjinniObjcTest.a */; }; 6D66A8A91A3B09F000B312E8 /* DBConstantTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6D66A8A81A3B09F000B312E8 /* DBConstantTests.mm */; }; A20094101B06982F00EF8D9B /* DBTokenTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = A200940E1B0697D300EF8D9B /* DBTokenTests.mm */; }; - A209B5791BBA2A0A0070C310 /* DBOptColorRecord.mm in Sources */ = {isa = PBXBuildFile; fileRef = A209B5761BBA2A0A0070C310 /* DBOptColorRecord.mm */; }; - A209B57A1BBA2A0A0070C310 /* DBOptColorRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = A209B5781BBA2A0A0070C310 /* DBOptColorRecord+Private.mm */; }; A238CA8E1AF84B7100CDDCE5 /* DBClientReturnedRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = A238CA761AF84B7100CDDCE5 /* DBClientReturnedRecord+Private.mm */; }; A238CA901AF84B7100CDDCE5 /* DBConstants+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = A238CA781AF84B7100CDDCE5 /* DBConstants+Private.mm */; }; A238CA921AF84B7100CDDCE5 /* DBDateRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = A238CA7A1AF84B7100CDDCE5 /* DBDateRecord+Private.mm */; }; @@ -72,6 +70,16 @@ B5D8FC371C23E2F40045ADCF /* DBConstantRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5D8FC351C23E2F40045ADCF /* DBConstantRecord+Private.mm */; }; B5E9C93B1C1F9D9D0073C123 /* reverse_client_interface_impl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5E9C9391C1F9D9D0073C123 /* reverse_client_interface_impl.cpp */; }; B5E9C9401C1F9E9E0073C123 /* DBReverseClientInterface+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5E9C93F1C1F9E9E0073C123 /* DBReverseClientInterface+Private.mm */; }; + B5F06A6D1D497396005BE736 /* extended_record_base.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5F06A681D497396005BE736 /* extended_record_base.cpp */; }; + B5F06A851D4973BD005BE736 /* DBConflict+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5F06A701D4973BD005BE736 /* DBConflict+Private.mm */; }; + B5F06A861D4973BD005BE736 /* DBConflictUser+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5F06A731D4973BD005BE736 /* DBConflictUser+Private.mm */; }; + B5F06A891D4973BD005BE736 /* DBExtendedRecord.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5F06A791D4973BD005BE736 /* DBExtendedRecord.mm */; }; + B5F06A8A1D4973BD005BE736 /* DBExtendedRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5F06A7B1D4973BD005BE736 /* DBExtendedRecord+Private.mm */; }; + B5F06A8C1D4973BD005BE736 /* DBObjcOnlyListener+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5F06A811D4973BD005BE736 /* DBObjcOnlyListener+Private.mm */; }; + B5F06A9A1D497A66005BE736 /* extended_record.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5F06A971D497A66005BE736 /* extended_record.cpp */; }; + B5F06AA51D4987EF005BE736 /* DBEnumUsageInterface+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5F06AA01D4987EF005BE736 /* DBEnumUsageInterface+Private.mm */; }; + B5F06AA61D4987EF005BE736 /* DBEnumUsageRecord.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5F06AA21D4987EF005BE736 /* DBEnumUsageRecord.mm */; }; + B5F06AA71D4987EF005BE736 /* DBEnumUsageRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5F06AA41D4987EF005BE736 /* DBEnumUsageRecord+Private.mm */; }; CFAED8751B54291900E3B8A3 /* DBEmptyRecord.mm in Sources */ = {isa = PBXBuildFile; fileRef = CFAED8721B54291900E3B8A3 /* DBEmptyRecord.mm */; }; CFAED8761B54291900E3B8A3 /* DBEmptyRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = CFAED8741B54291900E3B8A3 /* DBEmptyRecord+Private.mm */; }; CFC5D9D01B15105100BF2DF8 /* extern_record_with_derivings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CFC5D9CE1B15105100BF2DF8 /* extern_record_with_derivings.cpp */; }; @@ -183,11 +191,6 @@ 65868B5E1989FE4200D60EEE /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; 6D66A8A81A3B09F000B312E8 /* DBConstantTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBConstantTests.mm; sourceTree = ""; }; A200940E1B0697D300EF8D9B /* DBTokenTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBTokenTests.mm; sourceTree = ""; }; - A209B5751BBA2A0A0070C310 /* DBOptColorRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBOptColorRecord.h; sourceTree = ""; }; - A209B5761BBA2A0A0070C310 /* DBOptColorRecord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBOptColorRecord.mm; sourceTree = ""; }; - A209B5771BBA2A0A0070C310 /* DBOptColorRecord+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBOptColorRecord+Private.h"; sourceTree = ""; }; - A209B5781BBA2A0A0070C310 /* DBOptColorRecord+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBOptColorRecord+Private.mm"; sourceTree = ""; }; - A209B57B1BBA2A180070C310 /* opt_color_record.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = opt_color_record.hpp; sourceTree = ""; }; A238CA761AF84B7100CDDCE5 /* DBClientReturnedRecord+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBClientReturnedRecord+Private.mm"; sourceTree = ""; }; A238CA781AF84B7100CDDCE5 /* DBConstants+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBConstants+Private.mm"; sourceTree = ""; }; A238CA7A1AF84B7100CDDCE5 /* DBDateRecord+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBDateRecord+Private.mm"; sourceTree = ""; }; @@ -281,6 +284,39 @@ B5E9C93D1C1F9E9E0073C123 /* DBReverseClientInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBReverseClientInterface.h; sourceTree = ""; }; B5E9C93E1C1F9E9E0073C123 /* DBReverseClientInterface+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBReverseClientInterface+Private.h"; sourceTree = ""; }; B5E9C93F1C1F9E9E0073C123 /* DBReverseClientInterface+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBReverseClientInterface+Private.mm"; sourceTree = ""; }; + B5F06A651D497396005BE736 /* conflict_user.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = conflict_user.hpp; sourceTree = ""; }; + B5F06A661D497396005BE736 /* Conflict.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Conflict.hpp; sourceTree = ""; }; + B5F06A681D497396005BE736 /* extended_record_base.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = extended_record_base.cpp; sourceTree = ""; }; + B5F06A691D497396005BE736 /* extended_record_base.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = extended_record_base.hpp; sourceTree = ""; }; + B5F06A6A1D497396005BE736 /* java_only_listener.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = java_only_listener.hpp; sourceTree = ""; }; + B5F06A6B1D497396005BE736 /* objc_only_listener.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = objc_only_listener.hpp; sourceTree = ""; }; + B5F06A6C1D497396005BE736 /* uses_single_language_listeners.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = uses_single_language_listeners.hpp; sourceTree = ""; }; + B5F06A6E1D4973BD005BE736 /* DBConflict.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBConflict.h; sourceTree = ""; }; + B5F06A6F1D4973BD005BE736 /* DBConflict+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBConflict+Private.h"; sourceTree = ""; }; + B5F06A701D4973BD005BE736 /* DBConflict+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBConflict+Private.mm"; sourceTree = ""; }; + B5F06A711D4973BD005BE736 /* DBConflictUser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBConflictUser.h; sourceTree = ""; }; + B5F06A721D4973BD005BE736 /* DBConflictUser+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBConflictUser+Private.h"; sourceTree = ""; }; + B5F06A731D4973BD005BE736 /* DBConflictUser+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBConflictUser+Private.mm"; sourceTree = ""; }; + B5F06A781D4973BD005BE736 /* DBExtendedRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBExtendedRecord.h; sourceTree = ""; }; + B5F06A791D4973BD005BE736 /* DBExtendedRecord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBExtendedRecord.mm; sourceTree = ""; }; + B5F06A7A1D4973BD005BE736 /* DBExtendedRecord+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBExtendedRecord+Private.h"; sourceTree = ""; }; + B5F06A7B1D4973BD005BE736 /* DBExtendedRecord+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBExtendedRecord+Private.mm"; sourceTree = ""; }; + B5F06A7F1D4973BD005BE736 /* DBObjcOnlyListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBObjcOnlyListener.h; sourceTree = ""; }; + B5F06A801D4973BD005BE736 /* DBObjcOnlyListener+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBObjcOnlyListener+Private.h"; sourceTree = ""; }; + B5F06A811D4973BD005BE736 /* DBObjcOnlyListener+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBObjcOnlyListener+Private.mm"; sourceTree = ""; }; + B5F06A971D497A66005BE736 /* extended_record.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = extended_record.cpp; sourceTree = ""; }; + B5F06A981D497A66005BE736 /* extended_record.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = extended_record.hpp; sourceTree = ""; }; + B5F06A991D497A66005BE736 /* optional.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = optional.hpp; sourceTree = ""; }; + B5F06A9B1D4987C7005BE736 /* enum_usage_interface.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = enum_usage_interface.hpp; sourceTree = ""; }; + B5F06A9C1D4987C7005BE736 /* enum_usage_record.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = enum_usage_record.hpp; sourceTree = ""; }; + B5F06A9D1D4987EF005BE736 /* DBColor+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBColor+Private.h"; sourceTree = ""; }; + B5F06A9E1D4987EF005BE736 /* DBEnumUsageInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBEnumUsageInterface.h; sourceTree = ""; }; + B5F06A9F1D4987EF005BE736 /* DBEnumUsageInterface+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBEnumUsageInterface+Private.h"; sourceTree = ""; }; + B5F06AA01D4987EF005BE736 /* DBEnumUsageInterface+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBEnumUsageInterface+Private.mm"; sourceTree = ""; }; + B5F06AA11D4987EF005BE736 /* DBEnumUsageRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBEnumUsageRecord.h; sourceTree = ""; }; + B5F06AA21D4987EF005BE736 /* DBEnumUsageRecord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBEnumUsageRecord.mm; sourceTree = ""; }; + B5F06AA31D4987EF005BE736 /* DBEnumUsageRecord+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBEnumUsageRecord+Private.h"; sourceTree = ""; }; + B5F06AA41D4987EF005BE736 /* DBEnumUsageRecord+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBEnumUsageRecord+Private.mm"; sourceTree = ""; }; CFAED8711B54291900E3B8A3 /* DBEmptyRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBEmptyRecord.h; sourceTree = ""; }; CFAED8721B54291900E3B8A3 /* DBEmptyRecord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBEmptyRecord.mm; sourceTree = ""; }; CFAED8731B54291900E3B8A3 /* DBEmptyRecord+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBEmptyRecord+Private.h"; sourceTree = ""; }; @@ -378,6 +414,9 @@ 6536CD7519A6C98800DD7715 /* handwritten-cpp */ = { isa = PBXGroup; children = ( + B5F06A971D497A66005BE736 /* extended_record.cpp */, + B5F06A981D497A66005BE736 /* extended_record.hpp */, + B5F06A991D497A66005BE736 /* optional.hpp */, B5E9C9391C1F9D9D0073C123 /* reverse_client_interface_impl.cpp */, B5E9C93A1C1F9D9D0073C123 /* reverse_client_interface_impl.hpp */, 6536CD7619A6C98800DD7715 /* cpp_exception_impl.cpp */, @@ -453,6 +492,27 @@ A24249181AF192E0003BF8F0 /* generated-objc */ = { isa = PBXGroup; children = ( + B5F06A9D1D4987EF005BE736 /* DBColor+Private.h */, + B5F06A9E1D4987EF005BE736 /* DBEnumUsageInterface.h */, + B5F06A9F1D4987EF005BE736 /* DBEnumUsageInterface+Private.h */, + B5F06AA01D4987EF005BE736 /* DBEnumUsageInterface+Private.mm */, + B5F06AA11D4987EF005BE736 /* DBEnumUsageRecord.h */, + B5F06AA21D4987EF005BE736 /* DBEnumUsageRecord.mm */, + B5F06AA31D4987EF005BE736 /* DBEnumUsageRecord+Private.h */, + B5F06AA41D4987EF005BE736 /* DBEnumUsageRecord+Private.mm */, + B5F06A6E1D4973BD005BE736 /* DBConflict.h */, + B5F06A6F1D4973BD005BE736 /* DBConflict+Private.h */, + B5F06A701D4973BD005BE736 /* DBConflict+Private.mm */, + B5F06A711D4973BD005BE736 /* DBConflictUser.h */, + B5F06A721D4973BD005BE736 /* DBConflictUser+Private.h */, + B5F06A731D4973BD005BE736 /* DBConflictUser+Private.mm */, + B5F06A781D4973BD005BE736 /* DBExtendedRecord.h */, + B5F06A791D4973BD005BE736 /* DBExtendedRecord.mm */, + B5F06A7A1D4973BD005BE736 /* DBExtendedRecord+Private.h */, + B5F06A7B1D4973BD005BE736 /* DBExtendedRecord+Private.mm */, + B5F06A7F1D4973BD005BE736 /* DBObjcOnlyListener.h */, + B5F06A801D4973BD005BE736 /* DBObjcOnlyListener+Private.h */, + B5F06A811D4973BD005BE736 /* DBObjcOnlyListener+Private.mm */, B5D8FC321C23E2F40045ADCF /* DBConstantRecord.h */, B5D8FC331C23E2F40045ADCF /* DBConstantRecord.mm */, B5D8FC341C23E2F40045ADCF /* DBConstantRecord+Private.h */, @@ -460,10 +520,6 @@ B5E9C93D1C1F9E9E0073C123 /* DBReverseClientInterface.h */, B5E9C93E1C1F9E9E0073C123 /* DBReverseClientInterface+Private.h */, B5E9C93F1C1F9E9E0073C123 /* DBReverseClientInterface+Private.mm */, - A209B5751BBA2A0A0070C310 /* DBOptColorRecord.h */, - A209B5761BBA2A0A0070C310 /* DBOptColorRecord.mm */, - A209B5771BBA2A0A0070C310 /* DBOptColorRecord+Private.h */, - A209B5781BBA2A0A0070C310 /* DBOptColorRecord+Private.mm */, B52DA5641B103F6D005CE75F /* DBAssortedPrimitives.h */, B52DA5651B103F6D005CE75F /* DBAssortedPrimitives.mm */, B52DA5661B103F6D005CE75F /* DBAssortedPrimitives+Private.h */, @@ -573,9 +629,17 @@ A242495D1AF192FC003BF8F0 /* generated-cpp */ = { isa = PBXGroup; children = ( + B5F06A9B1D4987C7005BE736 /* enum_usage_interface.hpp */, + B5F06A9C1D4987C7005BE736 /* enum_usage_record.hpp */, + B5F06A651D497396005BE736 /* conflict_user.hpp */, + B5F06A661D497396005BE736 /* Conflict.hpp */, + B5F06A681D497396005BE736 /* extended_record_base.cpp */, + B5F06A691D497396005BE736 /* extended_record_base.hpp */, + B5F06A6A1D497396005BE736 /* java_only_listener.hpp */, + B5F06A6B1D497396005BE736 /* objc_only_listener.hpp */, + B5F06A6C1D497396005BE736 /* uses_single_language_listeners.hpp */, B5D8FC381C23E30D0045ADCF /* constant_record.hpp */, B5E9C93C1C1F9DCA0073C123 /* reverse_client_interface.hpp */, - A209B57B1BBA2A180070C310 /* opt_color_record.hpp */, B52DA56C1B103FBE005CE75F /* assorted_primitives.cpp */, B52DA56D1B103FBE005CE75F /* assorted_primitives.hpp */, A24249601AF192FC003BF8F0 /* client_interface.hpp */, @@ -699,6 +763,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + B5F06AA61D4987EF005BE736 /* DBEnumUsageRecord.mm in Sources */, A238CA981AF84B7100CDDCE5 /* DBMapRecord+Private.mm in Sources */, CFC5D9E81B1513E800BF2DF8 /* DBExternInterface1+Private.mm in Sources */, B5D8FC361C23E2F40045ADCF /* DBConstantRecord.mm in Sources */, @@ -713,6 +778,7 @@ A24850291AF96EBC00AFE907 /* DBDateRecord.mm in Sources */, A278D45319BA3601006FD937 /* test_helpers.cpp in Sources */, 6551684C1C4050A4003682A4 /* DBReturnOne+Private.mm in Sources */, + B5F06AA51D4987EF005BE736 /* DBEnumUsageInterface+Private.mm in Sources */, CFFD588D1B019E79001E10B6 /* DBCppException+Private.mm in Sources */, A238CA921AF84B7100CDDCE5 /* DBDateRecord+Private.mm in Sources */, A248502B1AF96EBC00AFE907 /* DBMapListRecord.mm in Sources */, @@ -722,11 +788,11 @@ CFF89B931B5D2CC7007F6EC2 /* date_record.cpp in Sources */, A24850301AF96EBC00AFE907 /* DBRecordWithNestedDerivings.mm in Sources */, CFFD58B11B041BD9001E10B6 /* DBConstantsInterface.mm in Sources */, - A209B5791BBA2A0A0070C310 /* DBOptColorRecord.mm in Sources */, B52DA56E1B103FC5005CE75F /* assorted_primitives.cpp in Sources */, CFFD58B31B041BD9001E10B6 /* DBConstantsInterface+Private.mm in Sources */, CFC5D9FC1B152E4300BF2DF8 /* TranslateDuration.cpp in Sources */, A248502F1AF96EBC00AFE907 /* DBRecordWithDerivings.mm in Sources */, + B5F06A851D4973BD005BE736 /* DBConflict+Private.mm in Sources */, A24249741AF192FC003BF8F0 /* constants.cpp in Sources */, CFFD588B1B019E79001E10B6 /* DBClientInterface+Private.mm in Sources */, B52DA5691B103F72005CE75F /* DBAssortedPrimitives.mm in Sources */, @@ -736,14 +802,17 @@ CFAED8751B54291900E3B8A3 /* DBEmptyRecord.mm in Sources */, A238CA9A1AF84B7100CDDCE5 /* DBNestedCollection+Private.mm in Sources */, CFFD58911B019E79001E10B6 /* DBUserToken+Private.mm in Sources */, + B5F06A9A1D497A66005BE736 /* extended_record.cpp in Sources */, A2CB54B419BA6E6000A9E600 /* DJIError.mm in Sources */, B5E9C9401C1F9E9E0073C123 /* DBReverseClientInterface+Private.mm in Sources */, + B5F06A891D4973BD005BE736 /* DBExtendedRecord.mm in Sources */, A238CA961AF84B7100CDDCE5 /* DBMapListRecord+Private.mm in Sources */, A238CA9C1AF84B7100CDDCE5 /* DBPrimitiveList+Private.mm in Sources */, 650CA05A1C2AB48E007ADDDB /* DBListenerCaller+Private.mm in Sources */, A24249761AF192FC003BF8F0 /* record_with_nested_derivings.cpp in Sources */, CFC5DA081B1532F600BF2DF8 /* DBRecordWithDurationAndDerivings.mm in Sources */, A248502D1AF96EBC00AFE907 /* DBNestedCollection.mm in Sources */, + B5F06A861D4973BD005BE736 /* DBConflictUser+Private.mm in Sources */, B5E9C93B1C1F9D9D0073C123 /* reverse_client_interface_impl.cpp in Sources */, CFC5D9D81B15106400BF2DF8 /* DBExternRecordWithDerivings+Private.mm in Sources */, A238CAA21AF84B7100CDDCE5 /* DBSetRecord+Private.mm in Sources */, @@ -757,11 +826,14 @@ CFC5DA011B15318B00BF2DF8 /* DBTestDuration+Private.mm in Sources */, 650CA05E1C2AB5AB007ADDDB /* ListenerCaller.cpp in Sources */, A248502A1AF96EBC00AFE907 /* DBMapDateRecord.mm in Sources */, + B5F06A6D1D497396005BE736 /* extended_record_base.cpp in Sources */, A238CA8E1AF84B7100CDDCE5 /* DBClientReturnedRecord+Private.mm in Sources */, + B5F06A8A1D4973BD005BE736 /* DBExtendedRecord+Private.mm in Sources */, 6551684D1C4050A4003682A4 /* DBReturnTwo+Private.mm in Sources */, + B5F06AA71D4987EF005BE736 /* DBEnumUsageRecord+Private.mm in Sources */, B52DA56B1B103F75005CE75F /* DBAssortedPrimitives+Private.mm in Sources */, A248502E1AF96EBC00AFE907 /* DBPrimitiveList.mm in Sources */, - A209B57A1BBA2A0A0070C310 /* DBOptColorRecord+Private.mm in Sources */, + B5F06A8C1D4973BD005BE736 /* DBObjcOnlyListener+Private.mm in Sources */, B5D8FC371C23E2F40045ADCF /* DBConstantRecord+Private.mm in Sources */, A238CAA01AF84B7100CDDCE5 /* DBRecordWithNestedDerivings+Private.mm in Sources */, CFC5DA0A1B1532F600BF2DF8 /* DBRecordWithDurationAndDerivings+Private.mm in Sources */, @@ -833,7 +905,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; @@ -877,7 +949,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; diff --git a/test-suite/run_djinni.sh b/test-suite/run_djinni.sh index 89ef14051..62628240b 100755 --- a/test-suite/run_djinni.sh +++ b/test-suite/run_djinni.sh @@ -71,7 +71,7 @@ fi --cpp-namespace testsuite \ --ident-cpp-enum-type foo_bar \ --cpp-optional-template "std::experimental::optional" \ - --cpp-optional-header "" \ + --cpp-optional-header "\"../../handwritten-src/cpp/optional.hpp\"" \ --cpp-extended-record-include-prefix "../../handwritten-src/cpp/" \ \ --jni-out "$temp_out_relative/jni" \ @@ -102,7 +102,7 @@ cp "$base_dir/djinni/yaml-test.djinni" "$temp_out/yaml" --cpp-out "$temp_out/cpp" \ --ident-cpp-enum-type foo_bar \ --cpp-optional-template "std::experimental::optional" \ - --cpp-optional-header "" \ + --cpp-optional-header "\"../../handwritten-src/cpp/optional.hpp\"" \ \ --jni-out "$temp_out/jni" \ --ident-jni-class NativeFooBar \ From c12d6c052060ffb1ecdd61d528856d3473f76b2e Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Thu, 28 Jul 2016 12:15:17 +0300 Subject: [PATCH 11/39] Fixed bug with processing \U+0000 symbol. Added tests --- support-lib/jni/Marshal.hpp | 2 +- support-lib/jni/djinni_support.cpp | 6 +++--- test-suite/handwritten-src/cpp/wchar_test_helpers.cpp | 3 ++- .../java/com/dropbox/djinni/test/WcharTest.java | 2 +- test-suite/handwritten-src/objc/tests/DBWcharTests.m | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/support-lib/jni/Marshal.hpp b/support-lib/jni/Marshal.hpp index 8f257606b..0bfcec186 100644 --- a/support-lib/jni/Marshal.hpp +++ b/support-lib/jni/Marshal.hpp @@ -193,7 +193,7 @@ namespace djinni static LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) { - return {jniEnv, jniStringFromWString(jniEnv, c.c_str())}; + return {jniEnv, jniStringFromWString(jniEnv, c)}; } }; diff --git a/support-lib/jni/djinni_support.cpp b/support-lib/jni/djinni_support.cpp index 116c61fa0..01220a2b5 100644 --- a/support-lib/jni/djinni_support.cpp +++ b/support-lib/jni/djinni_support.cpp @@ -413,7 +413,7 @@ static inline bool is_low_surrogate(char16_t c) { return (c >= 0xDC00) && (c < /* * Like utf8_decode_check, but for UTF-16. */ -static offset_pt utf16_decode_check(const std::u16string & str, std::u16string::size_type i) { +static offset_pt utf16_decode_check(const char16_t * str, std::u16string::size_type i) { if (is_high_surrogate(str[i]) && is_low_surrogate(str[i+1])) { // High surrogate followed by low surrogate char32_t pt = (((str[i] - 0xD800) << 10) | (str[i+1] - 0xDC00)) + 0x10000; @@ -426,7 +426,7 @@ static offset_pt utf16_decode_check(const std::u16string & str, std::u16string:: } } -static char32_t utf16_decode(const std::u16string & str, std::u16string::size_type & i) { +static char32_t utf16_decode(const char16_t * str, std::u16string::size_type & i) { offset_pt res = utf16_decode_check(str, i); if (res.offset < 0) { i += 1; @@ -472,7 +472,7 @@ std::string jniUTF8FromString(JNIEnv * env, const jstring jstr) { std::string out; out.reserve(str.length() * 3 / 2); // estimate for (std::u16string::size_type i = 0; i < str.length(); ) - utf8_encode(utf16_decode(str, i), out); + utf8_encode(utf16_decode(str.data(), i), out); return out; } diff --git a/test-suite/handwritten-src/cpp/wchar_test_helpers.cpp b/test-suite/handwritten-src/cpp/wchar_test_helpers.cpp index 4bb084d3e..8d4d8a208 100644 --- a/test-suite/handwritten-src/cpp/wchar_test_helpers.cpp +++ b/test-suite/handwritten-src/cpp/wchar_test_helpers.cpp @@ -3,7 +3,8 @@ namespace testsuite { -static const std::wstring str1 = L"some string with unicode \u263A, \U0001F4A9 symbols"; +static const wchar_t s1[] = L"some string with unicode \u0000, \u263A, \U0001F4A9 symbols"; +static const std::wstring str1(s1, sizeof(s1) / sizeof(*s1) - 1); static const std::wstring str2 = L"another string with unicode \u263B, \U0001F4A8 symbols"; WcharTestRec WcharTestHelpers::get_record() diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java index 35e4d4944..50bf06741 100644 --- a/test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java @@ -4,7 +4,7 @@ public class WcharTest extends TestCase { - private static final String STR1 = "some string with unicode \u263A, \uD83D\uDCA9 symbols"; + private static final String STR1 = "some string with unicode \u0000, \u263A, \uD83D\uDCA9 symbols"; private static final String STR2 = "another string with unicode \u263B, \uD83D\uDCA8 symbols"; public void test() { diff --git a/test-suite/handwritten-src/objc/tests/DBWcharTests.m b/test-suite/handwritten-src/objc/tests/DBWcharTests.m index 48c58c73b..c40715b81 100644 --- a/test-suite/handwritten-src/objc/tests/DBWcharTests.m +++ b/test-suite/handwritten-src/objc/tests/DBWcharTests.m @@ -21,7 +21,7 @@ - (void)tearDown - (void)test { - NSString *str1 = @"some string with unicode \u263A, \U0001F4A9 symbols"; + NSString *str1 = @"some string with unicode \u0000, \u263A, \U0001F4A9 symbols"; NSString *str2 = @"another string with unicode \u263B, \U0001F4A8 symbols"; XCTAssertEqualObjects([[DBWcharTestHelpers getRecord] s], str1); From 3a08ac1edffda84a234f9cd8e5cb4ec6bcef10bd Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Thu, 28 Jul 2016 13:33:02 +0300 Subject: [PATCH 12/39] Fix compilation for ios --- test-suite/handwritten-src/objc/tests/DBWcharTests.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-suite/handwritten-src/objc/tests/DBWcharTests.m b/test-suite/handwritten-src/objc/tests/DBWcharTests.m index c40715b81..3f0ad7874 100644 --- a/test-suite/handwritten-src/objc/tests/DBWcharTests.m +++ b/test-suite/handwritten-src/objc/tests/DBWcharTests.m @@ -21,7 +21,7 @@ - (void)tearDown - (void)test { - NSString *str1 = @"some string with unicode \u0000, \u263A, \U0001F4A9 symbols"; + NSString *str1 = @"some string with unicode \0, \u263A, \U0001F4A9 symbols"; NSString *str2 = @"another string with unicode \u263B, \U0001F4A8 symbols"; XCTAssertEqualObjects([[DBWcharTestHelpers getRecord] s], str1); From 2a896c73b6003ebf44f984d452e753cc75d15bed Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Wed, 27 Jul 2016 19:16:15 -0700 Subject: [PATCH 13/39] Fix compilation of single_language_interfaces in ObjC --- src/source/ObjcMarshal.scala | 4 +-- src/source/ObjcppGenerator.scala | 17 ++++++--- support-lib/objc/DJIError.h | 6 ++++ support-lib/objc/DJIError.mm | 5 +++ .../djinni/single_language_interfaces.djinni | 2 ++ .../cpp/uses_single_language_listeners.hpp | 4 +++ .../test/UsesSingleLanguageListeners.java | 22 ++++++++++++ .../jni/NativeUsesSingleLanguageListeners.cpp | 36 +++++++++++++++++++ .../jni/NativeUsesSingleLanguageListeners.hpp | 4 +++ .../objc/DBJavaOnlyListener+Private.mm | 6 ++-- .../DBUsesSingleLanguageListeners+Private.mm | 30 +++++++++++++++- .../objc/DBUsesSingleLanguageListeners.h | 8 +++-- .../DjinniObjcTest.xcodeproj/project.pbxproj | 30 ++++++++++++++++ 13 files changed, 163 insertions(+), 11 deletions(-) diff --git a/src/source/ObjcMarshal.scala b/src/source/ObjcMarshal.scala index a6c7d44b4..66edc49fa 100644 --- a/src/source/ObjcMarshal.scala +++ b/src/source/ObjcMarshal.scala @@ -58,7 +58,7 @@ class ObjcMarshal(spec: Spec) extends Marshal(spec) { List(ImportRef(include(d.name))) case DInterface => val ext = d.body.asInstanceOf[Interface].ext - if (ext.cpp && !ext.objc) { + if (!ext.objc) { List(ImportRef(""), DeclRef(s"@class ${typename(d.name, d.body)};", None)) } else { @@ -119,7 +119,7 @@ class ObjcMarshal(spec: Spec) extends Marshal(spec) { case DRecord => (idObjc.ty(d.name), true) case DInterface => val ext = d.body.asInstanceOf[Interface].ext - if (ext.cpp && !ext.objc) + if (!ext.objc) (idObjc.ty(d.name), true) else (s"id<${idObjc.ty(d.name)}>", false) diff --git a/src/source/ObjcppGenerator.scala b/src/source/ObjcppGenerator.scala index 64877ab0b..6fbe1bd59 100644 --- a/src/source/ObjcppGenerator.scala +++ b/src/source/ObjcppGenerator.scala @@ -73,6 +73,7 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { refs.privHeader.add("#include ") refs.privHeader.add("!#include " + q(spec.objcppIncludeCppPrefix + spec.cppFileIdentStyle(ident) + "." + spec.cppHeaderExt)) refs.body.add("!#import " + q(spec.objcppIncludeObjcPrefix + headerName(ident))) + refs.body.add("!#import " + q(spec.objcppIncludePrefix + objcppMarshal.privateHeaderName(ident.name))) spec.cppNnHeader match { case Some(nnHdr) => refs.privHeader.add("#include " + nnHdr) @@ -120,7 +121,6 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { }) if (i.ext.cpp) { - refs.body.add("!#import " + q(spec.objcppIncludePrefix + objcppMarshal.privateHeaderName(ident.name))) refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJICppWrapperCache+Private.h")) refs.body.add("#include ") refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIError.h")) @@ -129,7 +129,10 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { if (i.ext.objc) { refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIObjcWrapperCache+Private.h")) - refs.body.add("!#import " + q(spec.objcppIncludePrefix + objcppMarshal.privateHeaderName(ident.name))) + } + + if (!i.ext.cpp && !i.ext.objc) { + refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIError.h")) } writeObjcFile(privateBodyName(ident.name), origin, refs.body, w => { @@ -249,7 +252,7 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { // we don't have to do any casting at all, just access cppRef directly. w.wl("return " + nnCheck("objc->_cppRefHandle.get()") + ";") //w.wl(s"return ${spec.cppNnCheckExpression.getOrElse("")}(objc->_cppRefHandle.get());") - } else { + } else if (i.ext.cpp || i.ext.objc) { // ObjC only, or ObjC and C++. if (i.ext.cpp) { // If it could be implemented in C++, we might have to unwrap a proxy object. @@ -260,6 +263,9 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { } val getProxyExpr = s"::djinni::get_objc_proxy(objc)" w.wl(s"return ${nnCheck(getProxyExpr)};") + } else { + // Neither ObjC nor C++. Unusable, but generate compilable code. + w.wl("DJINNI_UNIMPLEMENTED(@\"Interface not implementable in any language.\");") } } w.wl @@ -272,7 +278,7 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { // ObjC only. In this case we *must* unwrap a proxy object - the dynamic_cast will // throw bad_cast if we gave it something of the wrong type. w.wl(s"return dynamic_cast(*cpp).Handle::get();") - } else { + } else if (i.ext.objc || i.ext.cpp) { // C++ only, or C++ and ObjC. if (i.ext.objc) { // If it could be implemented in ObjC, we might have to unwrap a proxy object. @@ -281,6 +287,9 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { } } w.wl(s"return ::djinni::get_cpp_proxy<$objcSelf>(cpp);") + } else { + // Neither ObjC nor C++. Unusable, but generate compilable code. + w.wl("DJINNI_UNIMPLEMENTED(@\"Interface not implementable in any language.\");") } } }) diff --git a/support-lib/objc/DJIError.h b/support-lib/objc/DJIError.h index 68810b4e2..eeaa90ed8 100644 --- a/support-lib/objc/DJIError.h +++ b/support-lib/objc/DJIError.h @@ -18,11 +18,17 @@ namespace djinni { +// Throws an exception for an unimplemented method call. +[[noreturn]] void throwUnimplemented(const char * ctx, NSString * msg); + // Helper function for exception translation. Do not call directly! [[noreturn]] void throwNSExceptionFromCurrent(const char * ctx); } // namespace djinni +#define DJINNI_UNIMPLEMENTED(msg) \ + ::djinni::throwUnimplemented(__PRETTY_FUNCTION__, msg); + #define DJINNI_TRANSLATE_EXCEPTIONS() \ catch (const std::exception & e) { \ ::djinni::throwNSExceptionFromCurrent(__PRETTY_FUNCTION__); \ diff --git a/support-lib/objc/DJIError.mm b/support-lib/objc/DJIError.mm index 672ef358f..4be648097 100644 --- a/support-lib/objc/DJIError.mm +++ b/support-lib/objc/DJIError.mm @@ -21,6 +21,11 @@ namespace djinni { +[[noreturn]] __attribute__((weak)) void throwUnimplemented(const char * /*ctx*/, NSString * message) { + [NSException raise:NSInternalInconsistencyException format:@"Unimplemented: %@", message]; + __builtin_unreachable(); +} + [[noreturn]] __attribute__((weak)) void throwNSExceptionFromCurrent(const char * /*ctx*/) { try { throw; diff --git a/test-suite/djinni/single_language_interfaces.djinni b/test-suite/djinni/single_language_interfaces.djinni index a72445e7d..0f6095790 100644 --- a/test-suite/djinni/single_language_interfaces.djinni +++ b/test-suite/djinni/single_language_interfaces.djinni @@ -5,5 +5,7 @@ java_only_listener = interface +j {} # on references to interfaces they don't need. uses_single_language_listeners = interface +o +j +c { callForObjC(l: objc_only_listener); + returnForObjC(): objc_only_listener; callForJava(l: java_only_listener); + returnForJava(): java_only_listener; } diff --git a/test-suite/generated-src/cpp/uses_single_language_listeners.hpp b/test-suite/generated-src/cpp/uses_single_language_listeners.hpp index 082c6dc2b..fd20afee2 100644 --- a/test-suite/generated-src/cpp/uses_single_language_listeners.hpp +++ b/test-suite/generated-src/cpp/uses_single_language_listeners.hpp @@ -20,7 +20,11 @@ class UsesSingleLanguageListeners { virtual void callForObjC(const std::shared_ptr & l) = 0; + virtual std::shared_ptr returnForObjC() = 0; + virtual void callForJava(const std::shared_ptr & l) = 0; + + virtual std::shared_ptr returnForJava() = 0; }; } // namespace testsuite diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/UsesSingleLanguageListeners.java b/test-suite/generated-src/java/com/dropbox/djinni/test/UsesSingleLanguageListeners.java index dbe872699..719afba3c 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/UsesSingleLanguageListeners.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/UsesSingleLanguageListeners.java @@ -14,8 +14,14 @@ public abstract class UsesSingleLanguageListeners { public abstract void callForObjC(@CheckForNull ObjcOnlyListener l); + @CheckForNull + public abstract ObjcOnlyListener returnForObjC(); + public abstract void callForJava(@CheckForNull JavaOnlyListener l); + @CheckForNull + public abstract JavaOnlyListener returnForJava(); + private static final class CppProxy extends UsesSingleLanguageListeners { private final long nativeRef; @@ -47,6 +53,14 @@ public void callForObjC(ObjcOnlyListener l) } private native void native_callForObjC(long _nativeRef, ObjcOnlyListener l); + @Override + public ObjcOnlyListener returnForObjC() + { + assert !this.destroyed.get() : "trying to use a destroyed object"; + return native_returnForObjC(this.nativeRef); + } + private native ObjcOnlyListener native_returnForObjC(long _nativeRef); + @Override public void callForJava(JavaOnlyListener l) { @@ -54,5 +68,13 @@ public void callForJava(JavaOnlyListener l) native_callForJava(this.nativeRef, l); } private native void native_callForJava(long _nativeRef, JavaOnlyListener l); + + @Override + public JavaOnlyListener returnForJava() + { + assert !this.destroyed.get() : "trying to use a destroyed object"; + return native_returnForJava(this.nativeRef); + } + private native JavaOnlyListener native_returnForJava(long _nativeRef); } } diff --git a/test-suite/generated-src/jni/NativeUsesSingleLanguageListeners.cpp b/test-suite/generated-src/jni/NativeUsesSingleLanguageListeners.cpp index 9ccb1d199..dd909ac1b 100644 --- a/test-suite/generated-src/jni/NativeUsesSingleLanguageListeners.cpp +++ b/test-suite/generated-src/jni/NativeUsesSingleLanguageListeners.cpp @@ -23,6 +23,14 @@ void NativeUsesSingleLanguageListeners::JavaProxy::callForObjC(const std::shared ::djinni::get(::djinni_generated::NativeObjcOnlyListener::fromCpp(jniEnv, c_l))); ::djinni::jniExceptionCheck(jniEnv); } +std::shared_ptr<::testsuite::ObjcOnlyListener> NativeUsesSingleLanguageListeners::JavaProxy::returnForObjC() { + auto jniEnv = ::djinni::jniGetThreadEnv(); + ::djinni::JniLocalScope jscope(jniEnv, 10); + const auto& data = ::djinni::JniClass<::djinni_generated::NativeUsesSingleLanguageListeners>::get(); + auto jret = jniEnv->CallObjectMethod(Handle::get().get(), data.method_returnForObjC); + ::djinni::jniExceptionCheck(jniEnv); + return ::djinni_generated::NativeObjcOnlyListener::toCpp(jniEnv, jret); +} void NativeUsesSingleLanguageListeners::JavaProxy::callForJava(const std::shared_ptr<::testsuite::JavaOnlyListener> & c_l) { auto jniEnv = ::djinni::jniGetThreadEnv(); ::djinni::JniLocalScope jscope(jniEnv, 10); @@ -31,6 +39,14 @@ void NativeUsesSingleLanguageListeners::JavaProxy::callForJava(const std::shared ::djinni::get(::djinni_generated::NativeJavaOnlyListener::fromCpp(jniEnv, c_l))); ::djinni::jniExceptionCheck(jniEnv); } +std::shared_ptr<::testsuite::JavaOnlyListener> NativeUsesSingleLanguageListeners::JavaProxy::returnForJava() { + auto jniEnv = ::djinni::jniGetThreadEnv(); + ::djinni::JniLocalScope jscope(jniEnv, 10); + const auto& data = ::djinni::JniClass<::djinni_generated::NativeUsesSingleLanguageListeners>::get(); + auto jret = jniEnv->CallObjectMethod(Handle::get().get(), data.method_returnForJava); + ::djinni::jniExceptionCheck(jniEnv); + return ::djinni_generated::NativeJavaOnlyListener::toCpp(jniEnv, jret); +} CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_UsesSingleLanguageListeners_00024CppProxy_nativeDestroy(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef) { @@ -49,6 +65,16 @@ CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_UsesSingleLanguageListeners } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, ) } +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_UsesSingleLanguageListeners_00024CppProxy_native_1returnForObjC(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::UsesSingleLanguageListeners>(nativeRef); + auto r = ref->returnForObjC(); + return ::djinni::release(::djinni_generated::NativeObjcOnlyListener::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_UsesSingleLanguageListeners_00024CppProxy_native_1callForJava(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_l) { try { @@ -58,4 +84,14 @@ CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_UsesSingleLanguageListeners } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, ) } +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_UsesSingleLanguageListeners_00024CppProxy_native_1returnForJava(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::UsesSingleLanguageListeners>(nativeRef); + auto r = ref->returnForJava(); + return ::djinni::release(::djinni_generated::NativeJavaOnlyListener::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + } // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeUsesSingleLanguageListeners.hpp b/test-suite/generated-src/jni/NativeUsesSingleLanguageListeners.hpp index 86b30aaf5..75c639c79 100644 --- a/test-suite/generated-src/jni/NativeUsesSingleLanguageListeners.hpp +++ b/test-suite/generated-src/jni/NativeUsesSingleLanguageListeners.hpp @@ -34,7 +34,9 @@ class NativeUsesSingleLanguageListeners final : ::djinni::JniInterface<::testsui ~JavaProxy(); void callForObjC(const std::shared_ptr<::testsuite::ObjcOnlyListener> & l) override; + std::shared_ptr<::testsuite::ObjcOnlyListener> returnForObjC() override; void callForJava(const std::shared_ptr<::testsuite::JavaOnlyListener> & l) override; + std::shared_ptr<::testsuite::JavaOnlyListener> returnForJava() override; private: friend ::djinni::JniInterface<::testsuite::UsesSingleLanguageListeners, ::djinni_generated::NativeUsesSingleLanguageListeners>; @@ -42,7 +44,9 @@ class NativeUsesSingleLanguageListeners final : ::djinni::JniInterface<::testsui const ::djinni::GlobalRef clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/UsesSingleLanguageListeners") }; const jmethodID method_callForObjC { ::djinni::jniGetMethodID(clazz.get(), "callForObjC", "(Lcom/dropbox/djinni/test/ObjcOnlyListener;)V") }; + const jmethodID method_returnForObjC { ::djinni::jniGetMethodID(clazz.get(), "returnForObjC", "()Lcom/dropbox/djinni/test/ObjcOnlyListener;") }; const jmethodID method_callForJava { ::djinni::jniGetMethodID(clazz.get(), "callForJava", "(Lcom/dropbox/djinni/test/JavaOnlyListener;)V") }; + const jmethodID method_returnForJava { ::djinni::jniGetMethodID(clazz.get(), "returnForJava", "()Lcom/dropbox/djinni/test/JavaOnlyListener;") }; }; } // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBJavaOnlyListener+Private.mm b/test-suite/generated-src/objc/DBJavaOnlyListener+Private.mm index d9d73715c..13d0d710d 100644 --- a/test-suite/generated-src/objc/DBJavaOnlyListener+Private.mm +++ b/test-suite/generated-src/objc/DBJavaOnlyListener+Private.mm @@ -1,7 +1,9 @@ // AUTOGENERATED FILE - DO NOT MODIFY! // This file generated by Djinni from single_language_interfaces.djinni +#import "DBJavaOnlyListener+Private.h" #import "DBJavaOnlyListener.h" +#import "DJIError.h" static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); @@ -12,7 +14,7 @@ if (!objc) { return nullptr; } - return ::djinni::get_objc_proxy(objc); + DJINNI_UNIMPLEMENTED(@"Interface not implementable in any language."); } auto JavaOnlyListener::fromCppOpt(const CppOptType& cpp) -> ObjcType @@ -20,7 +22,7 @@ if (!cpp) { return nil; } - return ::djinni::get_cpp_proxy(cpp); + DJINNI_UNIMPLEMENTED(@"Interface not implementable in any language."); } } // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBUsesSingleLanguageListeners+Private.mm b/test-suite/generated-src/objc/DBUsesSingleLanguageListeners+Private.mm index fbf6bed7c..f0c16ffbf 100644 --- a/test-suite/generated-src/objc/DBUsesSingleLanguageListeners+Private.mm +++ b/test-suite/generated-src/objc/DBUsesSingleLanguageListeners+Private.mm @@ -37,12 +37,26 @@ - (void)callForObjC:(nullable id)l { } DJINNI_TRANSLATE_EXCEPTIONS() } -- (void)callForJava:(nullable id)l { +- (nullable id)returnForObjC { + try { + auto r = _cppRefHandle.get()->returnForObjC(); + return ::djinni_generated::ObjcOnlyListener::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +- (void)callForJava:(nullable DBJavaOnlyListener *)l { try { _cppRefHandle.get()->callForJava(::djinni_generated::JavaOnlyListener::toCpp(l)); } DJINNI_TRANSLATE_EXCEPTIONS() } +- (nullable DBJavaOnlyListener *)returnForJava { + try { + auto r = _cppRefHandle.get()->returnForJava(); + return ::djinni_generated::JavaOnlyListener::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + namespace djinni_generated { class UsesSingleLanguageListeners::ObjcProxy final @@ -57,12 +71,26 @@ void callForObjC(const std::shared_ptr<::testsuite::ObjcOnlyListener> & c_l) ove [Handle::get() callForObjC:(::djinni_generated::ObjcOnlyListener::fromCpp(c_l))]; } } + std::shared_ptr<::testsuite::ObjcOnlyListener> returnForObjC() override + { + @autoreleasepool { + auto r = [Handle::get() returnForObjC]; + return ::djinni_generated::ObjcOnlyListener::toCpp(r); + } + } void callForJava(const std::shared_ptr<::testsuite::JavaOnlyListener> & c_l) override { @autoreleasepool { [Handle::get() callForJava:(::djinni_generated::JavaOnlyListener::fromCpp(c_l))]; } } + std::shared_ptr<::testsuite::JavaOnlyListener> returnForJava() override + { + @autoreleasepool { + auto r = [Handle::get() returnForJava]; + return ::djinni_generated::JavaOnlyListener::toCpp(r); + } + } }; } // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBUsesSingleLanguageListeners.h b/test-suite/generated-src/objc/DBUsesSingleLanguageListeners.h index e36040803..cb2bf2278 100644 --- a/test-suite/generated-src/objc/DBUsesSingleLanguageListeners.h +++ b/test-suite/generated-src/objc/DBUsesSingleLanguageListeners.h @@ -2,7 +2,7 @@ // This file generated by Djinni from single_language_interfaces.djinni #import -@protocol DBJavaOnlyListener; +@class DBJavaOnlyListener; @protocol DBObjcOnlyListener; @@ -14,6 +14,10 @@ - (void)callForObjC:(nullable id)l; -- (void)callForJava:(nullable id)l; +- (nullable id)returnForObjC; + +- (void)callForJava:(nullable DBJavaOnlyListener *)l; + +- (nullable DBJavaOnlyListener *)returnForJava; @end diff --git a/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj b/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj index 3c3c76b7f..d80348e33 100644 --- a/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj +++ b/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj @@ -72,6 +72,9 @@ B5D8FC371C23E2F40045ADCF /* DBConstantRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5D8FC351C23E2F40045ADCF /* DBConstantRecord+Private.mm */; }; B5E9C93B1C1F9D9D0073C123 /* reverse_client_interface_impl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5E9C9391C1F9D9D0073C123 /* reverse_client_interface_impl.cpp */; }; B5E9C9401C1F9E9E0073C123 /* DBReverseClientInterface+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5E9C93F1C1F9E9E0073C123 /* DBReverseClientInterface+Private.mm */; }; + B5F06AB11D499379005BE736 /* DBUsesSingleLanguageListeners+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5F06AA81D499379005BE736 /* DBUsesSingleLanguageListeners+Private.mm */; }; + B5F06AB21D499379005BE736 /* DBObjcOnlyListener+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5F06AAB1D499379005BE736 /* DBObjcOnlyListener+Private.mm */; }; + B5F06AB31D499379005BE736 /* DBJavaOnlyListener+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5F06AAE1D499379005BE736 /* DBJavaOnlyListener+Private.mm */; }; CFAED8751B54291900E3B8A3 /* DBEmptyRecord.mm in Sources */ = {isa = PBXBuildFile; fileRef = CFAED8721B54291900E3B8A3 /* DBEmptyRecord.mm */; }; CFAED8761B54291900E3B8A3 /* DBEmptyRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = CFAED8741B54291900E3B8A3 /* DBEmptyRecord+Private.mm */; }; CFC5D9D01B15105100BF2DF8 /* extern_record_with_derivings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CFC5D9CE1B15105100BF2DF8 /* extern_record_with_derivings.cpp */; }; @@ -281,6 +284,18 @@ B5E9C93D1C1F9E9E0073C123 /* DBReverseClientInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBReverseClientInterface.h; sourceTree = ""; }; B5E9C93E1C1F9E9E0073C123 /* DBReverseClientInterface+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBReverseClientInterface+Private.h"; sourceTree = ""; }; B5E9C93F1C1F9E9E0073C123 /* DBReverseClientInterface+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBReverseClientInterface+Private.mm"; sourceTree = ""; }; + B5F06AA81D499379005BE736 /* DBUsesSingleLanguageListeners+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBUsesSingleLanguageListeners+Private.mm"; sourceTree = ""; }; + B5F06AA91D499379005BE736 /* DBUsesSingleLanguageListeners+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBUsesSingleLanguageListeners+Private.h"; sourceTree = ""; }; + B5F06AAA1D499379005BE736 /* DBUsesSingleLanguageListeners.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBUsesSingleLanguageListeners.h; sourceTree = ""; }; + B5F06AAB1D499379005BE736 /* DBObjcOnlyListener+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBObjcOnlyListener+Private.mm"; sourceTree = ""; }; + B5F06AAC1D499379005BE736 /* DBObjcOnlyListener+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBObjcOnlyListener+Private.h"; sourceTree = ""; }; + B5F06AAD1D499379005BE736 /* DBObjcOnlyListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBObjcOnlyListener.h; sourceTree = ""; }; + B5F06AAE1D499379005BE736 /* DBJavaOnlyListener+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBJavaOnlyListener+Private.mm"; sourceTree = ""; }; + B5F06AAF1D499379005BE736 /* DBJavaOnlyListener+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBJavaOnlyListener+Private.h"; sourceTree = ""; }; + B5F06AB01D499379005BE736 /* DBJavaOnlyListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBJavaOnlyListener.h; sourceTree = ""; }; + B5F06AB41D49950C005BE736 /* uses_single_language_listeners.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = uses_single_language_listeners.hpp; sourceTree = ""; }; + B5F06AB51D49950C005BE736 /* objc_only_listener.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = objc_only_listener.hpp; sourceTree = ""; }; + B5F06AB61D49950C005BE736 /* java_only_listener.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = java_only_listener.hpp; sourceTree = ""; }; CFAED8711B54291900E3B8A3 /* DBEmptyRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBEmptyRecord.h; sourceTree = ""; }; CFAED8721B54291900E3B8A3 /* DBEmptyRecord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBEmptyRecord.mm; sourceTree = ""; }; CFAED8731B54291900E3B8A3 /* DBEmptyRecord+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBEmptyRecord+Private.h"; sourceTree = ""; }; @@ -453,6 +468,15 @@ A24249181AF192E0003BF8F0 /* generated-objc */ = { isa = PBXGroup; children = ( + B5F06AA81D499379005BE736 /* DBUsesSingleLanguageListeners+Private.mm */, + B5F06AA91D499379005BE736 /* DBUsesSingleLanguageListeners+Private.h */, + B5F06AAA1D499379005BE736 /* DBUsesSingleLanguageListeners.h */, + B5F06AAB1D499379005BE736 /* DBObjcOnlyListener+Private.mm */, + B5F06AAC1D499379005BE736 /* DBObjcOnlyListener+Private.h */, + B5F06AAD1D499379005BE736 /* DBObjcOnlyListener.h */, + B5F06AAE1D499379005BE736 /* DBJavaOnlyListener+Private.mm */, + B5F06AAF1D499379005BE736 /* DBJavaOnlyListener+Private.h */, + B5F06AB01D499379005BE736 /* DBJavaOnlyListener.h */, B5D8FC321C23E2F40045ADCF /* DBConstantRecord.h */, B5D8FC331C23E2F40045ADCF /* DBConstantRecord.mm */, B5D8FC341C23E2F40045ADCF /* DBConstantRecord+Private.h */, @@ -573,6 +597,9 @@ A242495D1AF192FC003BF8F0 /* generated-cpp */ = { isa = PBXGroup; children = ( + B5F06AB41D49950C005BE736 /* uses_single_language_listeners.hpp */, + B5F06AB51D49950C005BE736 /* objc_only_listener.hpp */, + B5F06AB61D49950C005BE736 /* java_only_listener.hpp */, B5D8FC381C23E30D0045ADCF /* constant_record.hpp */, B5E9C93C1C1F9DCA0073C123 /* reverse_client_interface.hpp */, A209B57B1BBA2A180070C310 /* opt_color_record.hpp */, @@ -707,6 +734,7 @@ 655168421C404B81003682A4 /* DBFirstListener+Private.mm in Sources */, A24850271AF96EBC00AFE907 /* DBClientReturnedRecord.mm in Sources */, CFC5D9D61B15106400BF2DF8 /* DBExternRecordWithDerivings.mm in Sources */, + B5F06AB31D499379005BE736 /* DBJavaOnlyListener+Private.mm in Sources */, CFC5DA0E1B15330000BF2DF8 /* record_with_duration_and_derivings.cpp in Sources */, A238CA941AF84B7100CDDCE5 /* DBMapDateRecord+Private.mm in Sources */, CFFD588F1B019E79001E10B6 /* DBTestHelpers+Private.mm in Sources */, @@ -730,10 +758,12 @@ A24249741AF192FC003BF8F0 /* constants.cpp in Sources */, CFFD588B1B019E79001E10B6 /* DBClientInterface+Private.mm in Sources */, B52DA5691B103F72005CE75F /* DBAssortedPrimitives.mm in Sources */, + B5F06AB21D499379005BE736 /* DBObjcOnlyListener+Private.mm in Sources */, A24850281AF96EBC00AFE907 /* DBConstants.mm in Sources */, 655168431C404B81003682A4 /* DBSecondListener+Private.mm in Sources */, CFFD58B71B041BFD001E10B6 /* constants_interface.cpp in Sources */, CFAED8751B54291900E3B8A3 /* DBEmptyRecord.mm in Sources */, + B5F06AB11D499379005BE736 /* DBUsesSingleLanguageListeners+Private.mm in Sources */, A238CA9A1AF84B7100CDDCE5 /* DBNestedCollection+Private.mm in Sources */, CFFD58911B019E79001E10B6 /* DBUserToken+Private.mm in Sources */, A2CB54B419BA6E6000A9E600 /* DJIError.mm in Sources */, From 40b02bf606bb12975cf283f29effe3b09093679b Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Tue, 2 Aug 2016 08:41:10 +0300 Subject: [PATCH 14/39] check the representation of wchar_t only if they're used --- support-lib/jni/djinni_support.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/support-lib/jni/djinni_support.cpp b/support-lib/jni/djinni_support.cpp index 01220a2b5..31d7438a4 100644 --- a/support-lib/jni/djinni_support.cpp +++ b/support-lib/jni/djinni_support.cpp @@ -22,7 +22,6 @@ #include static_assert(sizeof(jlong) >= sizeof(void*), "must be able to fit a void* into a jlong"); -static_assert(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4, "wchar_t must be represented by UTF-16 or UTF-32 encoding"); namespace djinni { @@ -373,7 +372,10 @@ jstring jniStringFromUTF8(JNIEnv * env, const std::string & str) { } template -static std::u16string implWStringToUTF16(const std::wstring & str); +static std::u16string implWStringToUTF16(const std::wstring & str) +{ + static_assert(wcharTypeSize == 2 || wcharTypeSize == 4, "wchar_t must be represented by UTF-16 or UTF-32 encoding"); +} template<> inline std::u16string implWStringToUTF16<2>(const std::wstring & str) { From fe000c8dca6e06ea6c811d1e3fef85fcde5acb64 Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Tue, 2 Aug 2016 08:44:22 +0300 Subject: [PATCH 15/39] added generated source files --- .../generated-src/cpp/wchar_test_helpers.hpp | 25 ++++++ .../generated-src/cpp/wchar_test_rec.hpp | 19 +++++ .../dropbox/djinni/test/WcharTestHelpers.java | 44 ++++++++++ .../com/dropbox/djinni/test/WcharTestRec.java | 31 +++++++ .../jni/NativeWcharTestHelpers.cpp | 59 ++++++++++++++ .../jni/NativeWcharTestHelpers.hpp | 32 ++++++++ .../generated-src/jni/NativeWcharTestRec.cpp | 28 +++++++ .../generated-src/jni/NativeWcharTestRec.hpp | 32 ++++++++ .../objc/DBWcharTestHelpers+Private.h | 31 +++++++ .../objc/DBWcharTestHelpers+Private.mm | 81 +++++++++++++++++++ .../generated-src/objc/DBWcharTestHelpers.h | 18 +++++ .../objc/DBWcharTestRec+Private.h | 24 ++++++ .../objc/DBWcharTestRec+Private.mm | 21 +++++ .../generated-src/objc/DBWcharTestRec.h | 12 +++ .../generated-src/objc/DBWcharTestRec.mm | 27 +++++++ 15 files changed, 484 insertions(+) create mode 100644 test-suite/generated-src/cpp/wchar_test_helpers.hpp create mode 100644 test-suite/generated-src/cpp/wchar_test_rec.hpp create mode 100644 test-suite/generated-src/java/com/dropbox/djinni/test/WcharTestHelpers.java create mode 100644 test-suite/generated-src/java/com/dropbox/djinni/test/WcharTestRec.java create mode 100644 test-suite/generated-src/jni/NativeWcharTestHelpers.cpp create mode 100644 test-suite/generated-src/jni/NativeWcharTestHelpers.hpp create mode 100644 test-suite/generated-src/jni/NativeWcharTestRec.cpp create mode 100644 test-suite/generated-src/jni/NativeWcharTestRec.hpp create mode 100644 test-suite/generated-src/objc/DBWcharTestHelpers+Private.h create mode 100644 test-suite/generated-src/objc/DBWcharTestHelpers+Private.mm create mode 100644 test-suite/generated-src/objc/DBWcharTestHelpers.h create mode 100644 test-suite/generated-src/objc/DBWcharTestRec+Private.h create mode 100644 test-suite/generated-src/objc/DBWcharTestRec+Private.mm create mode 100644 test-suite/generated-src/objc/DBWcharTestRec.h create mode 100644 test-suite/generated-src/objc/DBWcharTestRec.mm diff --git a/test-suite/generated-src/cpp/wchar_test_helpers.hpp b/test-suite/generated-src/cpp/wchar_test_helpers.hpp new file mode 100644 index 000000000..bb585677a --- /dev/null +++ b/test-suite/generated-src/cpp/wchar_test_helpers.hpp @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#pragma once + +#include + +namespace testsuite { + +struct WcharTestRec; + +class WcharTestHelpers { +public: + virtual ~WcharTestHelpers() {} + + static WcharTestRec get_record(); + + static std::wstring get_string(); + + static bool check_string(const std::wstring & str); + + static bool check_record(const WcharTestRec & rec); +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/wchar_test_rec.hpp b/test-suite/generated-src/cpp/wchar_test_rec.hpp new file mode 100644 index 000000000..23a732dd6 --- /dev/null +++ b/test-suite/generated-src/cpp/wchar_test_rec.hpp @@ -0,0 +1,19 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#pragma once + +#include +#include + +namespace testsuite { + +struct WcharTestRec final { + std::wstring s; + + WcharTestRec(std::wstring s_) + : s(std::move(s_)) + {} +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/WcharTestHelpers.java b/test-suite/generated-src/java/com/dropbox/djinni/test/WcharTestHelpers.java new file mode 100644 index 000000000..eecbbd107 --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/WcharTestHelpers.java @@ -0,0 +1,44 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +package com.dropbox.djinni.test; + +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +public abstract class WcharTestHelpers { + @Nonnull + public static native WcharTestRec getRecord(); + + @Nonnull + public static native String getString(); + + public static native boolean checkString(@Nonnull String str); + + public static native boolean checkRecord(@Nonnull WcharTestRec rec); + + private static final class CppProxy extends WcharTestHelpers + { + private final long nativeRef; + private final AtomicBoolean destroyed = new AtomicBoolean(false); + + private CppProxy(long nativeRef) + { + if (nativeRef == 0) throw new RuntimeException("nativeRef is zero"); + this.nativeRef = nativeRef; + } + + private native void nativeDestroy(long nativeRef); + public void destroy() + { + boolean destroyed = this.destroyed.getAndSet(true); + if (!destroyed) nativeDestroy(this.nativeRef); + } + protected void finalize() throws java.lang.Throwable + { + destroy(); + super.finalize(); + } + } +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/WcharTestRec.java b/test-suite/generated-src/java/com/dropbox/djinni/test/WcharTestRec.java new file mode 100644 index 000000000..4b064cbc1 --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/WcharTestRec.java @@ -0,0 +1,31 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +package com.dropbox.djinni.test; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +public class WcharTestRec { + + + /*package*/ final String mS; + + public WcharTestRec( + @Nonnull String s) { + this.mS = s; + } + + @Nonnull + public String getS() { + return mS; + } + + @Override + public String toString() { + return "WcharTestRec{" + + "mS=" + mS + + "}"; + } + +} diff --git a/test-suite/generated-src/jni/NativeWcharTestHelpers.cpp b/test-suite/generated-src/jni/NativeWcharTestHelpers.cpp new file mode 100644 index 000000000..19dd54fae --- /dev/null +++ b/test-suite/generated-src/jni/NativeWcharTestHelpers.cpp @@ -0,0 +1,59 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#include "NativeWcharTestHelpers.hpp" // my header +#include "Marshal.hpp" +#include "NativeWcharTestRec.hpp" + +namespace djinni_generated { + +NativeWcharTestHelpers::NativeWcharTestHelpers() : ::djinni::JniInterface<::testsuite::WcharTestHelpers, NativeWcharTestHelpers>("com/dropbox/djinni/test/WcharTestHelpers$CppProxy") {} + +NativeWcharTestHelpers::~NativeWcharTestHelpers() = default; + + +CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_WcharTestHelpers_00024CppProxy_nativeDestroy(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + delete reinterpret_cast<::djinni::CppProxyHandle<::testsuite::WcharTestHelpers>*>(nativeRef); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, ) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_WcharTestHelpers_getRecord(JNIEnv* jniEnv, jobject /*this*/) +{ + try { + DJINNI_FUNCTION_PROLOGUE0(jniEnv); + auto r = ::testsuite::WcharTestHelpers::get_record(); + return ::djinni::release(::djinni_generated::NativeWcharTestRec::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +CJNIEXPORT jstring JNICALL Java_com_dropbox_djinni_test_WcharTestHelpers_getString(JNIEnv* jniEnv, jobject /*this*/) +{ + try { + DJINNI_FUNCTION_PROLOGUE0(jniEnv); + auto r = ::testsuite::WcharTestHelpers::get_string(); + return ::djinni::release(::djinni::WString::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +CJNIEXPORT jboolean JNICALL Java_com_dropbox_djinni_test_WcharTestHelpers_checkString(JNIEnv* jniEnv, jobject /*this*/, jstring j_str) +{ + try { + DJINNI_FUNCTION_PROLOGUE0(jniEnv); + auto r = ::testsuite::WcharTestHelpers::check_string(::djinni::WString::toCpp(jniEnv, j_str)); + return ::djinni::release(::djinni::Bool::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +CJNIEXPORT jboolean JNICALL Java_com_dropbox_djinni_test_WcharTestHelpers_checkRecord(JNIEnv* jniEnv, jobject /*this*/, jobject j_rec) +{ + try { + DJINNI_FUNCTION_PROLOGUE0(jniEnv); + auto r = ::testsuite::WcharTestHelpers::check_record(::djinni_generated::NativeWcharTestRec::toCpp(jniEnv, j_rec)); + return ::djinni::release(::djinni::Bool::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeWcharTestHelpers.hpp b/test-suite/generated-src/jni/NativeWcharTestHelpers.hpp new file mode 100644 index 000000000..922c4ee5a --- /dev/null +++ b/test-suite/generated-src/jni/NativeWcharTestHelpers.hpp @@ -0,0 +1,32 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "wchar_test_helpers.hpp" + +namespace djinni_generated { + +class NativeWcharTestHelpers final : ::djinni::JniInterface<::testsuite::WcharTestHelpers, NativeWcharTestHelpers> { +public: + using CppType = std::shared_ptr<::testsuite::WcharTestHelpers>; + using CppOptType = std::shared_ptr<::testsuite::WcharTestHelpers>; + using JniType = jobject; + + using Boxed = NativeWcharTestHelpers; + + ~NativeWcharTestHelpers(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j) { return ::djinni::JniClass::get()._fromJava(jniEnv, j); } + static ::djinni::LocalRef fromCppOpt(JNIEnv* jniEnv, const CppOptType& c) { return {jniEnv, ::djinni::JniClass::get()._toJava(jniEnv, c)}; } + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) { return fromCppOpt(jniEnv, c); } + +private: + NativeWcharTestHelpers(); + friend ::djinni::JniClass; + friend ::djinni::JniInterface<::testsuite::WcharTestHelpers, NativeWcharTestHelpers>; + +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeWcharTestRec.cpp b/test-suite/generated-src/jni/NativeWcharTestRec.cpp new file mode 100644 index 000000000..ee981e5b2 --- /dev/null +++ b/test-suite/generated-src/jni/NativeWcharTestRec.cpp @@ -0,0 +1,28 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#include "NativeWcharTestRec.hpp" // my header +#include "Marshal.hpp" + +namespace djinni_generated { + +NativeWcharTestRec::NativeWcharTestRec() = default; + +NativeWcharTestRec::~NativeWcharTestRec() = default; + +auto NativeWcharTestRec::fromCpp(JNIEnv* jniEnv, const CppType& c) -> ::djinni::LocalRef { + const auto& data = ::djinni::JniClass::get(); + auto r = ::djinni::LocalRef{jniEnv->NewObject(data.clazz.get(), data.jconstructor, + ::djinni::get(::djinni::WString::fromCpp(jniEnv, c.s)))}; + ::djinni::jniExceptionCheck(jniEnv); + return r; +} + +auto NativeWcharTestRec::toCpp(JNIEnv* jniEnv, JniType j) -> CppType { + ::djinni::JniLocalScope jscope(jniEnv, 2); + assert(j != nullptr); + const auto& data = ::djinni::JniClass::get(); + return {::djinni::WString::toCpp(jniEnv, (jstring)jniEnv->GetObjectField(j, data.field_mS))}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeWcharTestRec.hpp b/test-suite/generated-src/jni/NativeWcharTestRec.hpp new file mode 100644 index 000000000..efa42ef40 --- /dev/null +++ b/test-suite/generated-src/jni/NativeWcharTestRec.hpp @@ -0,0 +1,32 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "wchar_test_rec.hpp" + +namespace djinni_generated { + +class NativeWcharTestRec final { +public: + using CppType = ::testsuite::WcharTestRec; + using JniType = jobject; + + using Boxed = NativeWcharTestRec; + + ~NativeWcharTestRec(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j); + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c); + +private: + NativeWcharTestRec(); + friend ::djinni::JniClass; + + const ::djinni::GlobalRef clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/WcharTestRec") }; + const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "", "(Ljava/lang/String;)V") }; + const jfieldID field_mS { ::djinni::jniGetFieldID(clazz.get(), "mS", "Ljava/lang/String;") }; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBWcharTestHelpers+Private.h b/test-suite/generated-src/objc/DBWcharTestHelpers+Private.h new file mode 100644 index 000000000..94292faaa --- /dev/null +++ b/test-suite/generated-src/objc/DBWcharTestHelpers+Private.h @@ -0,0 +1,31 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#include "wchar_test_helpers.hpp" +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBWcharTestHelpers; + +namespace djinni_generated { + +class WcharTestHelpers +{ +public: + using CppType = std::shared_ptr<::testsuite::WcharTestHelpers>; + using CppOptType = std::shared_ptr<::testsuite::WcharTestHelpers>; + using ObjcType = DBWcharTestHelpers*; + + using Boxed = WcharTestHelpers; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCppOpt(const CppOptType& cpp); + static ObjcType fromCpp(const CppType& cpp) { return fromCppOpt(cpp); } + +private: + class ObjcProxy; +}; + +} // namespace djinni_generated + diff --git a/test-suite/generated-src/objc/DBWcharTestHelpers+Private.mm b/test-suite/generated-src/objc/DBWcharTestHelpers+Private.mm new file mode 100644 index 000000000..1818ad77b --- /dev/null +++ b/test-suite/generated-src/objc/DBWcharTestHelpers+Private.mm @@ -0,0 +1,81 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#import "DBWcharTestHelpers+Private.h" +#import "DBWcharTestHelpers.h" +#import "DBWcharTestRec+Private.h" +#import "DJICppWrapperCache+Private.h" +#import "DJIError.h" +#import "DJIMarshal+Private.h" +#include +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@interface DBWcharTestHelpers () + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::WcharTestHelpers>&)cppRef; + +@end + +@implementation DBWcharTestHelpers { + ::djinni::CppProxyCache::Handle> _cppRefHandle; +} + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::WcharTestHelpers>&)cppRef +{ + if (self = [super init]) { + _cppRefHandle.assign(cppRef); + } + return self; +} + ++ (nonnull DBWcharTestRec *)getRecord { + try { + auto r = ::testsuite::WcharTestHelpers::get_record(); + return ::djinni_generated::WcharTestRec::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + ++ (nonnull NSString *)getString { + try { + auto r = ::testsuite::WcharTestHelpers::get_string(); + return ::djinni::WString::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + ++ (BOOL)checkString:(nonnull NSString *)str { + try { + auto r = ::testsuite::WcharTestHelpers::check_string(::djinni::WString::toCpp(str)); + return ::djinni::Bool::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + ++ (BOOL)checkRecord:(nonnull DBWcharTestRec *)rec { + try { + auto r = ::testsuite::WcharTestHelpers::check_record(::djinni_generated::WcharTestRec::toCpp(rec)); + return ::djinni::Bool::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +namespace djinni_generated { + +auto WcharTestHelpers::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + return objc->_cppRefHandle.get(); +} + +auto WcharTestHelpers::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + return ::djinni::get_cpp_proxy(cpp); +} + +} // namespace djinni_generated + +@end diff --git a/test-suite/generated-src/objc/DBWcharTestHelpers.h b/test-suite/generated-src/objc/DBWcharTestHelpers.h new file mode 100644 index 000000000..781158f20 --- /dev/null +++ b/test-suite/generated-src/objc/DBWcharTestHelpers.h @@ -0,0 +1,18 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#import "DBWcharTestRec.h" +#import + + +@interface DBWcharTestHelpers : NSObject + ++ (nonnull DBWcharTestRec *)getRecord; + ++ (nonnull NSString *)getString; + ++ (BOOL)checkString:(nonnull NSString *)str; + ++ (BOOL)checkRecord:(nonnull DBWcharTestRec *)rec; + +@end diff --git a/test-suite/generated-src/objc/DBWcharTestRec+Private.h b/test-suite/generated-src/objc/DBWcharTestRec+Private.h new file mode 100644 index 000000000..0ca19f149 --- /dev/null +++ b/test-suite/generated-src/objc/DBWcharTestRec+Private.h @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#import "DBWcharTestRec.h" +#include "wchar_test_rec.hpp" + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBWcharTestRec; + +namespace djinni_generated { + +struct WcharTestRec +{ + using CppType = ::testsuite::WcharTestRec; + using ObjcType = DBWcharTestRec*; + + using Boxed = WcharTestRec; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCpp(const CppType& cpp); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBWcharTestRec+Private.mm b/test-suite/generated-src/objc/DBWcharTestRec+Private.mm new file mode 100644 index 000000000..9d7f2e979 --- /dev/null +++ b/test-suite/generated-src/objc/DBWcharTestRec+Private.mm @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#import "DBWcharTestRec+Private.h" +#import "DJIMarshal+Private.h" +#include + +namespace djinni_generated { + +auto WcharTestRec::toCpp(ObjcType obj) -> CppType +{ + assert(obj); + return {::djinni::WString::toCpp(obj.s)}; +} + +auto WcharTestRec::fromCpp(const CppType& cpp) -> ObjcType +{ + return [[DBWcharTestRec alloc] initWithS:(::djinni::WString::fromCpp(cpp.s))]; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBWcharTestRec.h b/test-suite/generated-src/objc/DBWcharTestRec.h new file mode 100644 index 000000000..2a652e147 --- /dev/null +++ b/test-suite/generated-src/objc/DBWcharTestRec.h @@ -0,0 +1,12 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#import + +@interface DBWcharTestRec : NSObject +- (nonnull instancetype)initWithS:(nonnull NSString *)s; ++ (nonnull instancetype)wcharTestRecWithS:(nonnull NSString *)s; + +@property (nonatomic, readonly, nonnull) NSString * s; + +@end diff --git a/test-suite/generated-src/objc/DBWcharTestRec.mm b/test-suite/generated-src/objc/DBWcharTestRec.mm new file mode 100644 index 000000000..c06ef0d9e --- /dev/null +++ b/test-suite/generated-src/objc/DBWcharTestRec.mm @@ -0,0 +1,27 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from wchar_test.djinni + +#import "DBWcharTestRec.h" + + +@implementation DBWcharTestRec + +- (nonnull instancetype)initWithS:(nonnull NSString *)s +{ + if (self = [super init]) { + _s = [s copy]; + } + return self; +} + ++ (nonnull instancetype)wcharTestRecWithS:(nonnull NSString *)s +{ + return [[self alloc] initWithS:s]; +} + +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@ %p s:%@>", self.class, (void *)self, self.s]; +} + +@end From 342062eed76268d335f35a63463ee733e6caa1e7 Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Tue, 2 Aug 2016 08:55:04 +0300 Subject: [PATCH 16/39] check the representation of wchar_t only if they're used --- support-lib/jni/djinni_support.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/support-lib/jni/djinni_support.cpp b/support-lib/jni/djinni_support.cpp index 31d7438a4..d3f414395 100644 --- a/support-lib/jni/djinni_support.cpp +++ b/support-lib/jni/djinni_support.cpp @@ -479,7 +479,10 @@ std::string jniUTF8FromString(JNIEnv * env, const jstring jstr) { } template -static std::wstring implUTF16ToWString(const char16_t * data, size_t length); +static std::wstring implUTF16ToWString(const char16_t * data, size_t length) +{ + static_assert(wcharTypeSize == 2 || wcharTypeSize == 4, "wchar_t must be represented by UTF-16 or UTF-32 encoding"); +} template<> inline std::wstring implUTF16ToWString<2>(const char16_t * data, size_t length) { From c375e73d044aa151e89d61237b9de7b7391bed40 Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Tue, 2 Aug 2016 09:43:30 +0300 Subject: [PATCH 17/39] Improved wchar <-> NSString codec in the objective-c implementation. Added static_assert to verify assumptions --- support-lib/objc/DJIMarshal+Private.h | 32 ++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/support-lib/objc/DJIMarshal+Private.h b/support-lib/objc/DJIMarshal+Private.h index 4510d77a6..eb1f57d7c 100644 --- a/support-lib/objc/DJIMarshal+Private.h +++ b/support-lib/objc/DJIMarshal+Private.h @@ -118,6 +118,32 @@ struct String { } }; +template +static CFStringEncoding getWCharEncoding() +{ + static_assert(wcharTypeSize == 2 || wcharTypeSize == 4, "wchar_t must be represented by UTF-16 or UTF-32 encoding"); +} + +template<> +inline CFStringEncoding getWCharEncoding<2>() { + // case when wchar_t is represented by utf-16 encoding +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) + return NSUTF16BigEndianStringEncoding; +#else + return NSUTF16LittleEndianStringEncoding; +#endif +} + +template<> +inline CFStringEncoding getWCharEncoding<4>() { + // case when wchar_t is represented by utf-32 encoding +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) + return NSUTF32BigEndianStringEncoding; +#else + return NSUTF32LittleEndianStringEncoding; +#endif +} + struct WString { using CppType = std::wstring; using ObjcType = NSString*; @@ -126,7 +152,7 @@ struct WString { static CppType toCpp(ObjcType string) { assert(string); - NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF32LE); + NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(getWCharEncoding()); NSData* data = [string dataUsingEncoding:encoding]; return std::wstring((wchar_t*)[data bytes], [data length] / sizeof (wchar_t)); } @@ -134,8 +160,8 @@ struct WString { static ObjcType fromCpp(const CppType& string) { assert(string.size() <= std::numeric_limits::max()); return [[NSString alloc] initWithBytes:string.data() - length:string.size() * sizeof(wchar_t) - encoding:NSUTF32LittleEndianStringEncoding]; + length:string.size() * sizeof(wchar_t) + encoding:getWCharEncoding()]; } }; From b753eff6f88f8b46ccbb548858444e558f25fed1 Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Wed, 3 Aug 2016 15:36:02 -0700 Subject: [PATCH 18/39] Add missing return to silence warning --- support-lib/jni/djinni_support.cpp | 2 ++ support-lib/objc/DJIMarshal+Private.h | 1 + 2 files changed, 3 insertions(+) diff --git a/support-lib/jni/djinni_support.cpp b/support-lib/jni/djinni_support.cpp index 1b5e02522..fe3bbd824 100644 --- a/support-lib/jni/djinni_support.cpp +++ b/support-lib/jni/djinni_support.cpp @@ -375,6 +375,7 @@ template static std::u16string implWStringToUTF16(const std::wstring & str) { static_assert(wcharTypeSize == 2 || wcharTypeSize == 4, "wchar_t must be represented by UTF-16 or UTF-32 encoding"); + return {}; // unreachable } template<> @@ -482,6 +483,7 @@ template static std::wstring implUTF16ToWString(const char16_t * data, size_t length) { static_assert(wcharTypeSize == 2 || wcharTypeSize == 4, "wchar_t must be represented by UTF-16 or UTF-32 encoding"); + return {}; // unreachable } template<> diff --git a/support-lib/objc/DJIMarshal+Private.h b/support-lib/objc/DJIMarshal+Private.h index eb1f57d7c..5d600b33d 100644 --- a/support-lib/objc/DJIMarshal+Private.h +++ b/support-lib/objc/DJIMarshal+Private.h @@ -122,6 +122,7 @@ template static CFStringEncoding getWCharEncoding() { static_assert(wcharTypeSize == 2 || wcharTypeSize == 4, "wchar_t must be represented by UTF-16 or UTF-32 encoding"); + return {}; // unreachable } template<> From cb083019fa7026c474d065207111998dd29dc5f5 Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Thu, 4 Aug 2016 09:04:49 +0300 Subject: [PATCH 19/39] Workaround for bug #264 --- support-lib/jni/djinni_support.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/support-lib/jni/djinni_support.cpp b/support-lib/jni/djinni_support.cpp index fe3bbd824..000b6e906 100644 --- a/support-lib/jni/djinni_support.cpp +++ b/support-lib/jni/djinni_support.cpp @@ -372,25 +372,25 @@ jstring jniStringFromUTF8(JNIEnv * env, const std::string & str) { } template -static std::u16string implWStringToUTF16(const std::wstring & str) +static std::u16string implWStringToUTF16(std::wstring::const_iterator, std::wstring::const_iterator) { static_assert(wcharTypeSize == 2 || wcharTypeSize == 4, "wchar_t must be represented by UTF-16 or UTF-32 encoding"); return {}; // unreachable } template<> -inline std::u16string implWStringToUTF16<2>(const std::wstring & str) { +inline std::u16string implWStringToUTF16<2>(std::wstring::const_iterator begin, std::wstring::const_iterator end) { // case when wchar_t is represented by utf-16 encoding - return std::u16string(str.begin(), str.end()); + return std::u16string(begin, end); } template<> -inline std::u16string implWStringToUTF16<4>(const std::wstring & str) { +inline std::u16string implWStringToUTF16<4>(std::wstring::const_iterator begin, std::wstring::const_iterator end) { // case when wchar_t is represented by utf-32 encoding std::u16string utf16; - utf16.reserve(str.length()); - for (size_t i = 0; i < str.length(); ++i) - utf16_encode(static_cast(str[i]), utf16); + utf16.reserve(std::distance(begin, end)); + for(; begin != end; ++begin) + utf16_encode(static_cast(*begin), utf16); return utf16; } @@ -398,7 +398,7 @@ inline std::u16string wstringToUTF16(const std::wstring & str) { // hide "defined but not used" warnings (void)implWStringToUTF16<2>; (void)implWStringToUTF16<4>; - return implWStringToUTF16(str); + return implWStringToUTF16(str.cbegin(), str.cend()); } jstring jniStringFromWString(JNIEnv * env, const std::wstring & str) { From 32c36c28142cdafa0ca74c9c8edb3e734069c3bb Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Thu, 4 Aug 2016 17:12:09 +0300 Subject: [PATCH 20/39] fix #262 --- src/source/ObjcppGenerator.scala | 13 ++++++++++--- src/source/generator.scala | 4 +++- .../generated-src/jni/NativeClientInterface.cpp | 1 - test-suite/generated-src/jni/NativeCppException.cpp | 1 - .../generated-src/jni/NativeListenerCaller.cpp | 1 - test-suite/generated-src/jni/NativeReturnOne.cpp | 1 - test-suite/generated-src/jni/NativeReturnTwo.cpp | 1 - .../jni/NativeReverseClientInterface.cpp | 1 - .../generated-src/objc/DBClientInterface+Private.mm | 1 - .../generated-src/objc/DBCppException+Private.mm | 1 - .../generated-src/objc/DBExtendedRecord+Private.mm | 1 - .../generated-src/objc/DBListenerCaller+Private.mm | 1 - .../generated-src/objc/DBReturnOne+Private.mm | 1 - .../generated-src/objc/DBReturnTwo+Private.mm | 1 - .../objc/DBReverseClientInterface+Private.mm | 1 - 15 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/source/ObjcppGenerator.scala b/src/source/ObjcppGenerator.scala index 6fbe1bd59..2e28ce8fb 100644 --- a/src/source/ObjcppGenerator.scala +++ b/src/source/ObjcppGenerator.scala @@ -375,9 +375,16 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { w.wl("// This file generated by Djinni from " + origin) w.wl if (refs.nonEmpty) { - // Ignore the ! in front of each line; used to put own headers to the top - // according to Objective-C style guide - refs.foreach(s => w.wl(if (s.charAt(0) == '!') s.substring(1) else s)) + var included = mutable.TreeSet[String](); + for (s <- refs) { + // Ignore the ! in front of each line; used to put own headers to the top + // according to Objective-C style guide + val include = if (s.charAt(0) == '!') s.substring(1) else s + if (!included.contains(include)) { + included += include + w.wl(include) + } + } w.wl } f(w) diff --git a/src/source/generator.scala b/src/source/generator.scala index 9629bab22..f044337fe 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -309,7 +309,9 @@ abstract class Generator(spec: Spec) w.wl val myHeader = q(includePrefix + fileIdentStyle(name) + "." + spec.cppHeaderExt) w.wl(s"#include $myHeader // my header") - includes.foreach(w.wl(_)) + val myHeaderInclude = s"#include $myHeader" + for (include <- includes if include != myHeaderInclude) + w.wl(include) w.wl wrapNamespace(w, namespace, f) }) diff --git a/test-suite/generated-src/jni/NativeClientInterface.cpp b/test-suite/generated-src/jni/NativeClientInterface.cpp index 3c7ac5f86..16f9c9b5f 100644 --- a/test-suite/generated-src/jni/NativeClientInterface.cpp +++ b/test-suite/generated-src/jni/NativeClientInterface.cpp @@ -3,7 +3,6 @@ #include "NativeClientInterface.hpp" // my header #include "Marshal.hpp" -#include "NativeClientInterface.hpp" #include "NativeClientReturnedRecord.hpp" namespace djinni_generated { diff --git a/test-suite/generated-src/jni/NativeCppException.cpp b/test-suite/generated-src/jni/NativeCppException.cpp index c5a724f34..dc7cfe0a1 100644 --- a/test-suite/generated-src/jni/NativeCppException.cpp +++ b/test-suite/generated-src/jni/NativeCppException.cpp @@ -3,7 +3,6 @@ #include "NativeCppException.hpp" // my header #include "Marshal.hpp" -#include "NativeCppException.hpp" namespace djinni_generated { diff --git a/test-suite/generated-src/jni/NativeListenerCaller.cpp b/test-suite/generated-src/jni/NativeListenerCaller.cpp index c8b10f0d2..ea5b2de3e 100644 --- a/test-suite/generated-src/jni/NativeListenerCaller.cpp +++ b/test-suite/generated-src/jni/NativeListenerCaller.cpp @@ -3,7 +3,6 @@ #include "NativeListenerCaller.hpp" // my header #include "NativeFirstListener.hpp" -#include "NativeListenerCaller.hpp" #include "NativeSecondListener.hpp" namespace djinni_generated { diff --git a/test-suite/generated-src/jni/NativeReturnOne.cpp b/test-suite/generated-src/jni/NativeReturnOne.cpp index bd5fdb3cb..8b2690b53 100644 --- a/test-suite/generated-src/jni/NativeReturnOne.cpp +++ b/test-suite/generated-src/jni/NativeReturnOne.cpp @@ -3,7 +3,6 @@ #include "NativeReturnOne.hpp" // my header #include "Marshal.hpp" -#include "NativeReturnOne.hpp" namespace djinni_generated { diff --git a/test-suite/generated-src/jni/NativeReturnTwo.cpp b/test-suite/generated-src/jni/NativeReturnTwo.cpp index 2c3f5cb3f..0697e2983 100644 --- a/test-suite/generated-src/jni/NativeReturnTwo.cpp +++ b/test-suite/generated-src/jni/NativeReturnTwo.cpp @@ -3,7 +3,6 @@ #include "NativeReturnTwo.hpp" // my header #include "Marshal.hpp" -#include "NativeReturnTwo.hpp" namespace djinni_generated { diff --git a/test-suite/generated-src/jni/NativeReverseClientInterface.cpp b/test-suite/generated-src/jni/NativeReverseClientInterface.cpp index 16cbef876..013ab8e14 100644 --- a/test-suite/generated-src/jni/NativeReverseClientInterface.cpp +++ b/test-suite/generated-src/jni/NativeReverseClientInterface.cpp @@ -3,7 +3,6 @@ #include "NativeReverseClientInterface.hpp" // my header #include "Marshal.hpp" -#include "NativeReverseClientInterface.hpp" namespace djinni_generated { diff --git a/test-suite/generated-src/objc/DBClientInterface+Private.mm b/test-suite/generated-src/objc/DBClientInterface+Private.mm index 95f1bfad9..c20cab485 100644 --- a/test-suite/generated-src/objc/DBClientInterface+Private.mm +++ b/test-suite/generated-src/objc/DBClientInterface+Private.mm @@ -3,7 +3,6 @@ #import "DBClientInterface+Private.h" #import "DBClientInterface.h" -#import "DBClientInterface+Private.h" #import "DBClientReturnedRecord+Private.h" #import "DJIMarshal+Private.h" #import "DJIObjcWrapperCache+Private.h" diff --git a/test-suite/generated-src/objc/DBCppException+Private.mm b/test-suite/generated-src/objc/DBCppException+Private.mm index d64717f03..67107cd35 100644 --- a/test-suite/generated-src/objc/DBCppException+Private.mm +++ b/test-suite/generated-src/objc/DBCppException+Private.mm @@ -3,7 +3,6 @@ #import "DBCppException+Private.h" #import "DBCppException.h" -#import "DBCppException+Private.h" #import "DJICppWrapperCache+Private.h" #import "DJIError.h" #import "DJIMarshal+Private.h" diff --git a/test-suite/generated-src/objc/DBExtendedRecord+Private.mm b/test-suite/generated-src/objc/DBExtendedRecord+Private.mm index ab10e1f25..69413f8d6 100644 --- a/test-suite/generated-src/objc/DBExtendedRecord+Private.mm +++ b/test-suite/generated-src/objc/DBExtendedRecord+Private.mm @@ -1,7 +1,6 @@ // AUTOGENERATED FILE - DO NOT MODIFY! // This file generated by Djinni from extended_record.djinni -#import "DBExtendedRecord+Private.h" #import "DBExtendedRecord+Private.h" #import "DJIMarshal+Private.h" #include diff --git a/test-suite/generated-src/objc/DBListenerCaller+Private.mm b/test-suite/generated-src/objc/DBListenerCaller+Private.mm index 855fe17c5..cd412b48a 100644 --- a/test-suite/generated-src/objc/DBListenerCaller+Private.mm +++ b/test-suite/generated-src/objc/DBListenerCaller+Private.mm @@ -4,7 +4,6 @@ #import "DBListenerCaller+Private.h" #import "DBListenerCaller.h" #import "DBFirstListener+Private.h" -#import "DBListenerCaller+Private.h" #import "DBSecondListener+Private.h" #import "DJICppWrapperCache+Private.h" #import "DJIError.h" diff --git a/test-suite/generated-src/objc/DBReturnOne+Private.mm b/test-suite/generated-src/objc/DBReturnOne+Private.mm index ebacf8025..780c2ed8b 100644 --- a/test-suite/generated-src/objc/DBReturnOne+Private.mm +++ b/test-suite/generated-src/objc/DBReturnOne+Private.mm @@ -3,7 +3,6 @@ #import "DBReturnOne+Private.h" #import "DBReturnOne.h" -#import "DBReturnOne+Private.h" #import "DJICppWrapperCache+Private.h" #import "DJIError.h" #import "DJIMarshal+Private.h" diff --git a/test-suite/generated-src/objc/DBReturnTwo+Private.mm b/test-suite/generated-src/objc/DBReturnTwo+Private.mm index ca6201a39..90e1b189e 100644 --- a/test-suite/generated-src/objc/DBReturnTwo+Private.mm +++ b/test-suite/generated-src/objc/DBReturnTwo+Private.mm @@ -3,7 +3,6 @@ #import "DBReturnTwo+Private.h" #import "DBReturnTwo.h" -#import "DBReturnTwo+Private.h" #import "DJICppWrapperCache+Private.h" #import "DJIError.h" #import "DJIMarshal+Private.h" diff --git a/test-suite/generated-src/objc/DBReverseClientInterface+Private.mm b/test-suite/generated-src/objc/DBReverseClientInterface+Private.mm index 391059729..714f34936 100644 --- a/test-suite/generated-src/objc/DBReverseClientInterface+Private.mm +++ b/test-suite/generated-src/objc/DBReverseClientInterface+Private.mm @@ -3,7 +3,6 @@ #import "DBReverseClientInterface+Private.h" #import "DBReverseClientInterface.h" -#import "DBReverseClientInterface+Private.h" #import "DJICppWrapperCache+Private.h" #import "DJIError.h" #import "DJIMarshal+Private.h" From a2a52e24302059912eea68a814cbf6b0fa624532 Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Thu, 4 Aug 2016 11:57:01 -0700 Subject: [PATCH 21/39] Add comment explaining workaround. --- support-lib/jni/djinni_support.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/support-lib/jni/djinni_support.cpp b/support-lib/jni/djinni_support.cpp index 000b6e906..e3a9ff515 100644 --- a/support-lib/jni/djinni_support.cpp +++ b/support-lib/jni/djinni_support.cpp @@ -398,6 +398,8 @@ inline std::u16string wstringToUTF16(const std::wstring & str) { // hide "defined but not used" warnings (void)implWStringToUTF16<2>; (void)implWStringToUTF16<4>; + // Note: The template helper operates on iterators to work around a compiler issue we saw on Mac. + // It triggered undefined symbols if wstring methods were called directly in the template function. return implWStringToUTF16(str.cbegin(), str.cend()); } From f4ce76016ddd1a06243b2db4218345536e5e9793 Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Thu, 28 Jul 2016 18:34:32 -0700 Subject: [PATCH 22/39] Cleanups to bash script --- test-suite/run_djinni.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test-suite/run_djinni.sh b/test-suite/run_djinni.sh index 6f934dc5f..a97bb7157 100755 --- a/test-suite/run_djinni.sh +++ b/test-suite/run_djinni.sh @@ -57,8 +57,10 @@ elif [ $# -eq 1 ]; then exit fi -# Build Djinni. +# Build Djinni "$base_dir/../src/build" + +# Run Djinni generation [ ! -e "$temp_out" ] || rm -r "$temp_out" (cd "$base_dir" && \ "$base_dir/../src/run-assume-built" \ @@ -125,27 +127,29 @@ fi # Make sure we can parse back our own generated YAML file cp "$base_dir/djinni/yaml-test.djinni" "$temp_out/yaml" +(cd "$base_dir" && \ "$base_dir/../src/run-assume-built" \ - --java-out "$temp_out/java" \ + --java-out "$temp_out_relative/java" \ --java-package $java_package \ --ident-java-field mFooBar \ \ - --cpp-out "$temp_out/cpp" \ + --cpp-out "$temp_out_relative/cpp" \ --ident-cpp-enum-type foo_bar \ --cpp-optional-template "std::experimental::optional" \ --cpp-optional-header "" \ \ - --jni-out "$temp_out/jni" \ + --jni-out "$temp_out_relative/jni" \ --ident-jni-class NativeFooBar \ --ident-jni-file NativeFooBar \ \ - --objc-out "$temp_out/objc" \ - --objcpp-out "$temp_out/objc" \ + --objc-out "$temp_out_relative/objc" \ + --objcpp-out "$temp_out_relative/objc" \ --objc-type-prefix DB \ \ - --idl "$temp_out/yaml/yaml-test.djinni" + --idl "$temp_out_relative/yaml/yaml-test.djinni" \ +) -# Copy changes from "$temp_output" to final dir. +# Copy changes from "$temp_out" to final dir. mirror() { local prefix="$1" ; shift From f2b3079540317630422e281a48c3f54ba9130afc Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Thu, 4 Aug 2016 18:42:33 -0700 Subject: [PATCH 23/39] Clean up redundant code --- src/source/ObjcppMarshal.scala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/source/ObjcppMarshal.scala b/src/source/ObjcppMarshal.scala index 3f5a6569d..342e95e82 100644 --- a/src/source/ObjcppMarshal.scala +++ b/src/source/ObjcppMarshal.scala @@ -46,9 +46,7 @@ class ObjcppMarshal(spec: Spec) extends Marshal(spec) { } def include(m: Meta) = m match { - case d: MDef => d.defType match { - case _ => q(spec.objcppIncludePrefix + privateHeaderName(d.name)) - } + case d: MDef => q(spec.objcppIncludePrefix + privateHeaderName(d.name)) case _ => throw new AssertionError("not applicable") } From 20356700d43f16111dd610c12366a7dfc8a24e31 Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Thu, 4 Aug 2016 18:45:01 -0700 Subject: [PATCH 24/39] Re-generate example --- example/generated-src/objc/TXSSortItems+Private.mm | 2 +- example/generated-src/objc/TXSSortOrder+Private.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 example/generated-src/objc/TXSSortOrder+Private.h diff --git a/example/generated-src/objc/TXSSortItems+Private.mm b/example/generated-src/objc/TXSSortItems+Private.mm index 548b73c3b..e9a564527 100644 --- a/example/generated-src/objc/TXSSortItems+Private.mm +++ b/example/generated-src/objc/TXSSortItems+Private.mm @@ -5,9 +5,9 @@ #import "TXSSortItems.h" #import "DJICppWrapperCache+Private.h" #import "DJIError.h" -#import "DJIMarshal+Private.h" #import "TXSItemList+Private.h" #import "TXSSortItems+Private.h" +#import "TXSSortOrder+Private.h" #import "TXSTextboxListener+Private.h" #include #include diff --git a/example/generated-src/objc/TXSSortOrder+Private.h b/example/generated-src/objc/TXSSortOrder+Private.h new file mode 100644 index 000000000..df2a08421 --- /dev/null +++ b/example/generated-src/objc/TXSSortOrder+Private.h @@ -0,0 +1,6 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from example.djinni + +#include "sort_order.hpp" +#import "DJIMarshal+Private.h" + From f0bd26929afd0a58bf5156ea2de6a21ed40570ec Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Thu, 4 Aug 2016 20:31:23 -0700 Subject: [PATCH 25/39] Re-generate example --- example/generated-src/jni/NativeSortItems.cpp | 1 - example/generated-src/objc/TXSSortItems+Private.mm | 1 - 2 files changed, 2 deletions(-) diff --git a/example/generated-src/jni/NativeSortItems.cpp b/example/generated-src/jni/NativeSortItems.cpp index d612062bb..03162cc5e 100644 --- a/example/generated-src/jni/NativeSortItems.cpp +++ b/example/generated-src/jni/NativeSortItems.cpp @@ -3,7 +3,6 @@ #include "NativeSortItems.hpp" // my header #include "NativeItemList.hpp" -#include "NativeSortItems.hpp" #include "NativeSortOrder.hpp" #include "NativeTextboxListener.hpp" diff --git a/example/generated-src/objc/TXSSortItems+Private.mm b/example/generated-src/objc/TXSSortItems+Private.mm index e9a564527..cde25def2 100644 --- a/example/generated-src/objc/TXSSortItems+Private.mm +++ b/example/generated-src/objc/TXSSortItems+Private.mm @@ -6,7 +6,6 @@ #import "DJICppWrapperCache+Private.h" #import "DJIError.h" #import "TXSItemList+Private.h" -#import "TXSSortItems+Private.h" #import "TXSSortOrder+Private.h" #import "TXSTextboxListener+Private.h" #include From 5d99b8f3ed019d870b7947af7566d3cf2755ba08 Mon Sep 17 00:00:00 2001 From: Xianwen Chen Date: Thu, 4 Aug 2016 22:46:29 +0100 Subject: [PATCH 26/39] Fix no member named 'invalid_argument' in namespace 'std' --- .../objc/TXSSortItems+Private.mm | 78 +++++++++++++++++ .../objc/TXSTextboxListener+Private.mm | 48 +++++++++++ .../objc/TXSSortItems+Private.mm | 1 + .../objc/TXSTextboxListener+Private.mm | 1 + src/source/ObjcppGenerator.scala | 3 + .../generated-src/objc/DBClass1+Private.mm | 84 +++++++++++++++++++ .../objc/DBInnerClass+Private.mm | 49 +++++++++++ .../generated-src/objc/DBClass2+Private.mm | 60 +++++++++++++ .../objc/DBClientInterface+Private.mm | 1 + .../generated-src/objc/DBConflict+Private.mm | 1 + .../objc/DBConflictUser+Private.mm | 1 + .../objc/DBConstantsInterface+Private.mm | 1 + .../objc/DBCppException+Private.mm | 1 + .../objc/DBEnumUsageInterface+Private.mm | 1 + .../objc/DBExternInterface1+Private.mm | 1 + .../objc/DBExternInterface2+Private.mm | 1 + .../objc/DBFirstListener+Private.mm | 1 + .../objc/DBJavaOnlyListener+Private.mm | 1 + .../objc/DBListenerCaller+Private.mm | 1 + .../objc/DBObjcOnlyListener+Private.mm | 1 + .../generated-src/objc/DBReturnOne+Private.mm | 1 + .../generated-src/objc/DBReturnTwo+Private.mm | 1 + .../objc/DBReverseClientInterface+Private.mm | 1 + .../objc/DBSecondListener+Private.mm | 1 + .../objc/DBTestDuration+Private.mm | 1 + .../objc/DBTestHelpers+Private.mm | 1 + .../generated-src/objc/DBUserToken+Private.mm | 1 + .../DBUsesSingleLanguageListeners+Private.mm | 1 + .../objc/DBWcharTestHelpers+Private.mm | 1 + 29 files changed, 345 insertions(+) create mode 100644 example-with-packages/textsort/generated-src/objc/TXSSortItems+Private.mm create mode 100644 example-with-packages/textsort/generated-src/objc/TXSTextboxListener+Private.mm create mode 100644 test-suite/djinni-packages/package1/generated-src/objc/DBClass1+Private.mm create mode 100644 test-suite/djinni-packages/package1/generated-src/objc/DBInnerClass+Private.mm create mode 100644 test-suite/djinni-packages/package2/generated-src/objc/DBClass2+Private.mm diff --git a/example-with-packages/textsort/generated-src/objc/TXSSortItems+Private.mm b/example-with-packages/textsort/generated-src/objc/TXSSortItems+Private.mm new file mode 100644 index 000000000..a58450028 --- /dev/null +++ b/example-with-packages/textsort/generated-src/objc/TXSSortItems+Private.mm @@ -0,0 +1,78 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from textsort.djinni + +#import "TXSSortItems+Private.h" +#import "TXSSortItems.h" +#import "DJICppWrapperCache+Private.h" +#import "DJIError.h" +#import "DJIMarshal+Private.h" +#import "TXSSortItems+Private.h" +#import "TXSTextboxListener+Private.h" +#import "collections/generated-src/objc/TXSItemList+Private.h" +#include +#include +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@interface TXSSortItems () + +- (id)initWithCpp:(const std::shared_ptr<::textsort::SortItems>&)cppRef; + +@end + +@implementation TXSSortItems { + ::djinni::CppProxyCache::Handle> _cppRefHandle; +} + +- (id)initWithCpp:(const std::shared_ptr<::textsort::SortItems>&)cppRef +{ + if (self = [super init]) { + _cppRefHandle.assign(cppRef); + } + return self; +} + +- (void)sort:(TXSSortOrder)order + items:(nonnull TXSItemList *)items { + try { + _cppRefHandle.get()->sort(::djinni::Enum<::textsort::sort_order, TXSSortOrder>::toCpp(order), + ::djinni_generated::ItemList::toCpp(items)); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + ++ (nullable TXSSortItems *)createWithListener:(nullable id)listener { + try { + auto r = ::textsort::SortItems::create_with_listener(::djinni_generated::TextboxListener::toCpp(listener)); + return ::djinni_generated::SortItems::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + ++ (nonnull TXSItemList *)runSort:(nonnull TXSItemList *)items { + try { + auto r = ::textsort::SortItems::run_sort(::djinni_generated::ItemList::toCpp(items)); + return ::djinni_generated::ItemList::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +namespace djinni_generated { + +auto SortItems::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + return objc->_cppRefHandle.get(); +} + +auto SortItems::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + return ::djinni::get_cpp_proxy(cpp); +} + +} // namespace djinni_generated + +@end diff --git a/example-with-packages/textsort/generated-src/objc/TXSTextboxListener+Private.mm b/example-with-packages/textsort/generated-src/objc/TXSTextboxListener+Private.mm new file mode 100644 index 000000000..3d5c06c96 --- /dev/null +++ b/example-with-packages/textsort/generated-src/objc/TXSTextboxListener+Private.mm @@ -0,0 +1,48 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from textsort.djinni + +#import "TXSTextboxListener+Private.h" +#import "TXSTextboxListener.h" +#import "DJIObjcWrapperCache+Private.h" +#import "collections/generated-src/objc/TXSItemList+Private.h" +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +namespace djinni_generated { + +class TextboxListener::ObjcProxy final +: public ::textsort::TextboxListener +, public ::djinni::ObjcProxyCache::Handle +{ +public: + using Handle::Handle; + void update(const ::collections::ItemList & c_items) override + { + @autoreleasepool { + [Handle::get() update:(::djinni_generated::ItemList::fromCpp(c_items))]; + } + } +}; + +} // namespace djinni_generated + +namespace djinni_generated { + +auto TextboxListener::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + return ::djinni::get_objc_proxy(objc); +} + +auto TextboxListener::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + return dynamic_cast(*cpp).Handle::get(); +} + +} // namespace djinni_generated diff --git a/example/generated-src/objc/TXSSortItems+Private.mm b/example/generated-src/objc/TXSSortItems+Private.mm index cde25def2..26e1bf977 100644 --- a/example/generated-src/objc/TXSSortItems+Private.mm +++ b/example/generated-src/objc/TXSSortItems+Private.mm @@ -9,6 +9,7 @@ #import "TXSSortOrder+Private.h" #import "TXSTextboxListener+Private.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/example/generated-src/objc/TXSTextboxListener+Private.mm b/example/generated-src/objc/TXSTextboxListener+Private.mm index 655983807..18ef89465 100644 --- a/example/generated-src/objc/TXSTextboxListener+Private.mm +++ b/example/generated-src/objc/TXSTextboxListener+Private.mm @@ -5,6 +5,7 @@ #import "TXSTextboxListener.h" #import "DJIObjcWrapperCache+Private.h" #import "TXSItemList+Private.h" +#include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/src/source/ObjcppGenerator.scala b/src/source/ObjcppGenerator.scala index ba5029550..45fb9d951 100644 --- a/src/source/ObjcppGenerator.scala +++ b/src/source/ObjcppGenerator.scala @@ -130,6 +130,9 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIError.h")) refs.body.add("#include ") } + if (!spec.cppNnType.isEmpty || !spec.cppNnCheckExpression.nonEmpty) { + refs.body.add("#include ") + } if (i.ext.objc) { refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIObjcWrapperCache+Private.h")) diff --git a/test-suite/djinni-packages/package1/generated-src/objc/DBClass1+Private.mm b/test-suite/djinni-packages/package1/generated-src/objc/DBClass1+Private.mm new file mode 100644 index 000000000..5c93d591a --- /dev/null +++ b/test-suite/djinni-packages/package1/generated-src/objc/DBClass1+Private.mm @@ -0,0 +1,84 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from class1.djinni + +#import "DBClass1+Private.h" +#import "DBClass1.h" +#import "DBClass1+Private.h" +#import "DBInnerClass+Private.h" +#import "DJICppWrapperCache+Private.h" +#import "DJIError.h" +#import "DJIMarshal+Private.h" +#import "djinni-packages/package2/generated-src/objc/DBClass2+Private.h" +#include +#include +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@interface DBClass1 () + +- (id)initWithCpp:(const std::shared_ptr<::package1::Class1>&)cppRef; + +@end + +@implementation DBClass1 { + ::djinni::CppProxyCache::Handle> _cppRefHandle; +} + +- (id)initWithCpp:(const std::shared_ptr<::package1::Class1>&)cppRef +{ + if (self = [super init]) { + _cppRefHandle.assign(cppRef); + } + return self; +} + +- (nonnull NSString *)getName { + try { + auto r = _cppRefHandle.get()->get_name(); + return ::djinni::String::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +- (nonnull NSString *)getInnerClassName { + try { + auto r = _cppRefHandle.get()->get_inner_class_name(); + return ::djinni::String::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +- (nullable DBClass2 *)getClass2 { + try { + auto r = _cppRefHandle.get()->get_class2(); + return ::djinni_generated::Class2::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + ++ (nullable DBClass1 *)createWithInnerClass:(nullable id)innerClass { + try { + auto r = ::package1::Class1::create_with_inner_class(::djinni_generated::InnerClass::toCpp(innerClass)); + return ::djinni_generated::Class1::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +namespace djinni_generated { + +auto Class1::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + return objc->_cppRefHandle.get(); +} + +auto Class1::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + return ::djinni::get_cpp_proxy(cpp); +} + +} // namespace djinni_generated + +@end diff --git a/test-suite/djinni-packages/package1/generated-src/objc/DBInnerClass+Private.mm b/test-suite/djinni-packages/package1/generated-src/objc/DBInnerClass+Private.mm new file mode 100644 index 000000000..16d8b3132 --- /dev/null +++ b/test-suite/djinni-packages/package1/generated-src/objc/DBInnerClass+Private.mm @@ -0,0 +1,49 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from inner_class.djinni + +#import "DBInnerClass+Private.h" +#import "DBInnerClass.h" +#import "DJIMarshal+Private.h" +#import "DJIObjcWrapperCache+Private.h" +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +namespace djinni_generated { + +class InnerClass::ObjcProxy final +: public ::package1::InnerClass +, public ::djinni::ObjcProxyCache::Handle +{ +public: + using Handle::Handle; + std::string get_name() override + { + @autoreleasepool { + auto r = [Handle::get() getName]; + return ::djinni::String::toCpp(r); + } + } +}; + +} // namespace djinni_generated + +namespace djinni_generated { + +auto InnerClass::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + return ::djinni::get_objc_proxy(objc); +} + +auto InnerClass::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + return dynamic_cast(*cpp).Handle::get(); +} + +} // namespace djinni_generated diff --git a/test-suite/djinni-packages/package2/generated-src/objc/DBClass2+Private.mm b/test-suite/djinni-packages/package2/generated-src/objc/DBClass2+Private.mm new file mode 100644 index 000000000..9fd132d5f --- /dev/null +++ b/test-suite/djinni-packages/package2/generated-src/objc/DBClass2+Private.mm @@ -0,0 +1,60 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from class2.djinni + +#import "DBClass2+Private.h" +#import "DBClass2.h" +#import "DJICppWrapperCache+Private.h" +#import "DJIError.h" +#import "DJIMarshal+Private.h" +#include +#include +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@interface DBClass2 () + +- (id)initWithCpp:(const std::shared_ptr<::package2::Class2>&)cppRef; + +@end + +@implementation DBClass2 { + ::djinni::CppProxyCache::Handle> _cppRefHandle; +} + +- (id)initWithCpp:(const std::shared_ptr<::package2::Class2>&)cppRef +{ + if (self = [super init]) { + _cppRefHandle.assign(cppRef); + } + return self; +} + +- (nonnull NSString *)getName { + try { + auto r = _cppRefHandle.get()->get_name(); + return ::djinni::String::fromCpp(r); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +namespace djinni_generated { + +auto Class2::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + return objc->_cppRefHandle.get(); +} + +auto Class2::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + return ::djinni::get_cpp_proxy(cpp); +} + +} // namespace djinni_generated + +@end diff --git a/test-suite/generated-src/objc/DBClientInterface+Private.mm b/test-suite/generated-src/objc/DBClientInterface+Private.mm index c20cab485..47cfc1f07 100644 --- a/test-suite/generated-src/objc/DBClientInterface+Private.mm +++ b/test-suite/generated-src/objc/DBClientInterface+Private.mm @@ -6,6 +6,7 @@ #import "DBClientReturnedRecord+Private.h" #import "DJIMarshal+Private.h" #import "DJIObjcWrapperCache+Private.h" +#include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBConflict+Private.mm b/test-suite/generated-src/objc/DBConflict+Private.mm index 46d0b9459..4f4d7dae5 100644 --- a/test-suite/generated-src/objc/DBConflict+Private.mm +++ b/test-suite/generated-src/objc/DBConflict+Private.mm @@ -6,6 +6,7 @@ #import "DJICppWrapperCache+Private.h" #import "DJIError.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBConflictUser+Private.mm b/test-suite/generated-src/objc/DBConflictUser+Private.mm index a17ed6909..7b3cf7864 100644 --- a/test-suite/generated-src/objc/DBConflictUser+Private.mm +++ b/test-suite/generated-src/objc/DBConflictUser+Private.mm @@ -8,6 +8,7 @@ #import "DJIError.h" #import "DJIMarshal+Private.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBConstantsInterface+Private.mm b/test-suite/generated-src/objc/DBConstantsInterface+Private.mm index 28d34f0cd..f6e7db467 100644 --- a/test-suite/generated-src/objc/DBConstantsInterface+Private.mm +++ b/test-suite/generated-src/objc/DBConstantsInterface+Private.mm @@ -8,6 +8,7 @@ #import "DJIError.h" #import "DJIMarshal+Private.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBCppException+Private.mm b/test-suite/generated-src/objc/DBCppException+Private.mm index 67107cd35..2a9509a6a 100644 --- a/test-suite/generated-src/objc/DBCppException+Private.mm +++ b/test-suite/generated-src/objc/DBCppException+Private.mm @@ -7,6 +7,7 @@ #import "DJIError.h" #import "DJIMarshal+Private.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBEnumUsageInterface+Private.mm b/test-suite/generated-src/objc/DBEnumUsageInterface+Private.mm index b6f61b1dc..3e02c5fdb 100644 --- a/test-suite/generated-src/objc/DBEnumUsageInterface+Private.mm +++ b/test-suite/generated-src/objc/DBEnumUsageInterface+Private.mm @@ -9,6 +9,7 @@ #import "DJIMarshal+Private.h" #import "DJIObjcWrapperCache+Private.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBExternInterface1+Private.mm b/test-suite/generated-src/objc/DBExternInterface1+Private.mm index 34c07564c..5d07fec08 100644 --- a/test-suite/generated-src/objc/DBExternInterface1+Private.mm +++ b/test-suite/generated-src/objc/DBExternInterface1+Private.mm @@ -8,6 +8,7 @@ #import "DJICppWrapperCache+Private.h" #import "DJIError.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBExternInterface2+Private.mm b/test-suite/generated-src/objc/DBExternInterface2+Private.mm index 6e3c4e461..010b4de3f 100644 --- a/test-suite/generated-src/objc/DBExternInterface2+Private.mm +++ b/test-suite/generated-src/objc/DBExternInterface2+Private.mm @@ -6,6 +6,7 @@ #import "DBExternRecordWithDerivings+Private.h" #import "DBTestHelpers+Private.h" #import "DJIObjcWrapperCache+Private.h" +#include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBFirstListener+Private.mm b/test-suite/generated-src/objc/DBFirstListener+Private.mm index 6e1a33b39..be17c49e7 100644 --- a/test-suite/generated-src/objc/DBFirstListener+Private.mm +++ b/test-suite/generated-src/objc/DBFirstListener+Private.mm @@ -4,6 +4,7 @@ #import "DBFirstListener+Private.h" #import "DBFirstListener.h" #import "DJIObjcWrapperCache+Private.h" +#include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBJavaOnlyListener+Private.mm b/test-suite/generated-src/objc/DBJavaOnlyListener+Private.mm index 13d0d710d..bfce2c889 100644 --- a/test-suite/generated-src/objc/DBJavaOnlyListener+Private.mm +++ b/test-suite/generated-src/objc/DBJavaOnlyListener+Private.mm @@ -4,6 +4,7 @@ #import "DBJavaOnlyListener+Private.h" #import "DBJavaOnlyListener.h" #import "DJIError.h" +#include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBListenerCaller+Private.mm b/test-suite/generated-src/objc/DBListenerCaller+Private.mm index cd412b48a..3fa3bed22 100644 --- a/test-suite/generated-src/objc/DBListenerCaller+Private.mm +++ b/test-suite/generated-src/objc/DBListenerCaller+Private.mm @@ -8,6 +8,7 @@ #import "DJICppWrapperCache+Private.h" #import "DJIError.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBObjcOnlyListener+Private.mm b/test-suite/generated-src/objc/DBObjcOnlyListener+Private.mm index 3002520f6..184ec1c7a 100644 --- a/test-suite/generated-src/objc/DBObjcOnlyListener+Private.mm +++ b/test-suite/generated-src/objc/DBObjcOnlyListener+Private.mm @@ -4,6 +4,7 @@ #import "DBObjcOnlyListener+Private.h" #import "DBObjcOnlyListener.h" #import "DJIObjcWrapperCache+Private.h" +#include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBReturnOne+Private.mm b/test-suite/generated-src/objc/DBReturnOne+Private.mm index 780c2ed8b..4ed9355de 100644 --- a/test-suite/generated-src/objc/DBReturnOne+Private.mm +++ b/test-suite/generated-src/objc/DBReturnOne+Private.mm @@ -7,6 +7,7 @@ #import "DJIError.h" #import "DJIMarshal+Private.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBReturnTwo+Private.mm b/test-suite/generated-src/objc/DBReturnTwo+Private.mm index 90e1b189e..e5adc266d 100644 --- a/test-suite/generated-src/objc/DBReturnTwo+Private.mm +++ b/test-suite/generated-src/objc/DBReturnTwo+Private.mm @@ -7,6 +7,7 @@ #import "DJIError.h" #import "DJIMarshal+Private.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBReverseClientInterface+Private.mm b/test-suite/generated-src/objc/DBReverseClientInterface+Private.mm index 714f34936..7b797255a 100644 --- a/test-suite/generated-src/objc/DBReverseClientInterface+Private.mm +++ b/test-suite/generated-src/objc/DBReverseClientInterface+Private.mm @@ -7,6 +7,7 @@ #import "DJIError.h" #import "DJIMarshal+Private.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBSecondListener+Private.mm b/test-suite/generated-src/objc/DBSecondListener+Private.mm index 83ed60720..15ce58f3f 100644 --- a/test-suite/generated-src/objc/DBSecondListener+Private.mm +++ b/test-suite/generated-src/objc/DBSecondListener+Private.mm @@ -4,6 +4,7 @@ #import "DBSecondListener+Private.h" #import "DBSecondListener.h" #import "DJIObjcWrapperCache+Private.h" +#include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBTestDuration+Private.mm b/test-suite/generated-src/objc/DBTestDuration+Private.mm index b0d597746..ec7cb521e 100644 --- a/test-suite/generated-src/objc/DBTestDuration+Private.mm +++ b/test-suite/generated-src/objc/DBTestDuration+Private.mm @@ -8,6 +8,7 @@ #import "DJIMarshal+Private.h" #import "Duration-objc.hpp" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBTestHelpers+Private.mm b/test-suite/generated-src/objc/DBTestHelpers+Private.mm index ff419ad94..432c2066a 100644 --- a/test-suite/generated-src/objc/DBTestHelpers+Private.mm +++ b/test-suite/generated-src/objc/DBTestHelpers+Private.mm @@ -15,6 +15,7 @@ #import "DJIError.h" #import "DJIMarshal+Private.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBUserToken+Private.mm b/test-suite/generated-src/objc/DBUserToken+Private.mm index 51e8c012d..eacac79ab 100644 --- a/test-suite/generated-src/objc/DBUserToken+Private.mm +++ b/test-suite/generated-src/objc/DBUserToken+Private.mm @@ -8,6 +8,7 @@ #import "DJIMarshal+Private.h" #import "DJIObjcWrapperCache+Private.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBUsesSingleLanguageListeners+Private.mm b/test-suite/generated-src/objc/DBUsesSingleLanguageListeners+Private.mm index f0c16ffbf..0092fc936 100644 --- a/test-suite/generated-src/objc/DBUsesSingleLanguageListeners+Private.mm +++ b/test-suite/generated-src/objc/DBUsesSingleLanguageListeners+Private.mm @@ -9,6 +9,7 @@ #import "DJIError.h" #import "DJIObjcWrapperCache+Private.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); diff --git a/test-suite/generated-src/objc/DBWcharTestHelpers+Private.mm b/test-suite/generated-src/objc/DBWcharTestHelpers+Private.mm index 1818ad77b..7d9dc594f 100644 --- a/test-suite/generated-src/objc/DBWcharTestHelpers+Private.mm +++ b/test-suite/generated-src/objc/DBWcharTestHelpers+Private.mm @@ -8,6 +8,7 @@ #import "DJIError.h" #import "DJIMarshal+Private.h" #include +#include #include static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); From ebda4a203a0958a9ee717aa7f8b8f3fccac76cf5 Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Fri, 5 Aug 2016 17:08:52 -0700 Subject: [PATCH 27/39] Don't crash on leading/trailing underscores in names. Also don't conflict with arguments named "r". --- .../objc/TXSSortItems+Private.mm | 8 +- src/source/ObjcppGenerator.scala | 8 +- src/source/generator.scala | 2 +- test-suite/djinni/common.djinni | 1 + test-suite/djinni/varnames.djinni | 11 +++ .../generated-src/cpp/_varname_interface_.hpp | 21 +++++ .../generated-src/cpp/_varname_record_.hpp | 24 ++++++ test-suite/generated-src/inFileList.txt | 1 + .../dropbox/djinni/test/VarnameInterface.java | 56 +++++++++++++ .../dropbox/djinni/test/VarnameRecord.java | 35 ++++++++ .../jni/NativeVarnameInterface.cpp | 42 ++++++++++ .../jni/NativeVarnameInterface.hpp | 32 ++++++++ .../generated-src/jni/NativeVarnameRecord.cpp | 28 +++++++ .../generated-src/jni/NativeVarnameRecord.hpp | 32 ++++++++ .../objc/DBClientInterface+Private.mm | 28 +++---- .../objc/DBConflictUser+Private.mm | 8 +- .../objc/DBCppException+Private.mm | 8 +- .../objc/DBEnumUsageInterface+Private.mm | 40 +++++----- .../objc/DBExternInterface1+Private.mm | 4 +- .../objc/DBExternInterface2+Private.mm | 4 +- .../objc/DBListenerCaller+Private.mm | 6 +- .../generated-src/objc/DBReturnOne+Private.mm | 8 +- .../generated-src/objc/DBReturnTwo+Private.mm | 8 +- .../objc/DBReverseClientInterface+Private.mm | 16 ++-- .../objc/DBTestDuration+Private.mm | 80 +++++++++---------- .../objc/DBTestHelpers+Private.mm | 72 ++++++++--------- .../generated-src/objc/DBUserToken+Private.mm | 8 +- .../DBUsesSingleLanguageListeners+Private.mm | 16 ++-- .../objc/DBVarnameInterface+Private.h | 31 +++++++ .../objc/DBVarnameInterface+Private.mm | 67 ++++++++++++++++ .../generated-src/objc/DBVarnameInterface.h | 15 ++++ .../objc/DBVarnameRecord+Private.h | 24 ++++++ .../objc/DBVarnameRecord+Private.mm | 21 +++++ .../generated-src/objc/DBVarnameRecord.h | 17 ++++ .../generated-src/objc/DBVarnameRecord.mm | 27 +++++++ .../objc/DBWcharTestHelpers+Private.mm | 16 ++-- test-suite/generated-src/outFileList.txt | 15 ++++ .../DjinniObjcTest.xcodeproj/project.pbxproj | 24 ++++++ 38 files changed, 694 insertions(+), 170 deletions(-) create mode 100644 test-suite/djinni/varnames.djinni create mode 100644 test-suite/generated-src/cpp/_varname_interface_.hpp create mode 100644 test-suite/generated-src/cpp/_varname_record_.hpp create mode 100644 test-suite/generated-src/java/com/dropbox/djinni/test/VarnameInterface.java create mode 100644 test-suite/generated-src/java/com/dropbox/djinni/test/VarnameRecord.java create mode 100644 test-suite/generated-src/jni/NativeVarnameInterface.cpp create mode 100644 test-suite/generated-src/jni/NativeVarnameInterface.hpp create mode 100644 test-suite/generated-src/jni/NativeVarnameRecord.cpp create mode 100644 test-suite/generated-src/jni/NativeVarnameRecord.hpp create mode 100644 test-suite/generated-src/objc/DBVarnameInterface+Private.h create mode 100644 test-suite/generated-src/objc/DBVarnameInterface+Private.mm create mode 100644 test-suite/generated-src/objc/DBVarnameInterface.h create mode 100644 test-suite/generated-src/objc/DBVarnameRecord+Private.h create mode 100644 test-suite/generated-src/objc/DBVarnameRecord+Private.mm create mode 100644 test-suite/generated-src/objc/DBVarnameRecord.h create mode 100644 test-suite/generated-src/objc/DBVarnameRecord.mm diff --git a/example/generated-src/objc/TXSSortItems+Private.mm b/example/generated-src/objc/TXSSortItems+Private.mm index 26e1bf977..9368ce974 100644 --- a/example/generated-src/objc/TXSSortItems+Private.mm +++ b/example/generated-src/objc/TXSSortItems+Private.mm @@ -42,15 +42,15 @@ - (void)sort:(TXSSortOrder)order + (nullable TXSSortItems *)createWithListener:(nullable id)listener { try { - auto r = ::textsort::SortItems::create_with_listener(::djinni_generated::TextboxListener::toCpp(listener)); - return ::djinni_generated::SortItems::fromCpp(r); + auto objcpp_result_ = ::textsort::SortItems::create_with_listener(::djinni_generated::TextboxListener::toCpp(listener)); + return ::djinni_generated::SortItems::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull TXSItemList *)runSort:(nonnull TXSItemList *)items { try { - auto r = ::textsort::SortItems::run_sort(::djinni_generated::ItemList::toCpp(items)); - return ::djinni_generated::ItemList::fromCpp(r); + auto objcpp_result_ = ::textsort::SortItems::run_sort(::djinni_generated::ItemList::toCpp(items)); + return ::djinni_generated::ItemList::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/src/source/ObjcppGenerator.scala b/src/source/ObjcppGenerator.scala index 45fb9d951..57e47dcc0 100644 --- a/src/source/ObjcppGenerator.scala +++ b/src/source/ObjcppGenerator.scala @@ -187,12 +187,12 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { } } }) - val ret = m.ret.fold("")(_ => "auto r = ") + val ret = m.ret.fold("")(_ => "auto objcpp_result_ = ") val call = ret + (if (!m.static) "_cppRefHandle.get()->" else cppSelf + "::") + idCpp.method(m.ident) + "(" writeAlignedCall(w, call, m.params, ")", p => objcppMarshal.toCpp(p.ty, idObjc.local(p.ident.name))) w.wl(";") - m.ret.fold()(r => w.wl(s"return ${objcppMarshal.fromCpp(r, "r")};")) + m.ret.fold()(r => w.wl(s"return ${objcppMarshal.fromCpp(r, "objcpp_result_")};")) } } } @@ -217,7 +217,7 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { val params = m.params.map(p => cppMarshal.fqParamType(p.ty) + " c_" + idCpp.local(p.ident)) w.wl(s"$ret ${idCpp.method(m.ident)}${params.mkString("(", ", ", ")")} override").braced { w.w("@autoreleasepool").braced { - val ret = m.ret.fold("")(_ => "auto r = ") + val ret = m.ret.fold("")(_ => "auto objcpp_result_ = ") val call = s"[Handle::get() ${idObjc.method(m.ident)}" writeAlignedObjcCall(w, ret + call, m.params, "]", p => (idObjc.field(p.ident), s"(${objcppMarshal.fromCpp(p.ty, "c_" + idCpp.local(p.ident))})")) w.wl(";") @@ -233,7 +233,7 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { w.wl(s"""throw std::invalid_argument("$exceptionReason");""") } } - w.wl(s"return ${objcppMarshal.toCpp(ty, "r")};") + w.wl(s"return ${objcppMarshal.toCpp(ty, "objcpp_result_")};") }) } } diff --git a/src/source/generator.scala b/src/source/generator.scala index f044337fe..d3e726636 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -83,7 +83,7 @@ package object generatorTools { if (s.isEmpty) s else ", " + s } def q(s: String) = '"' + s + '"' - def firstUpper(token: String) = token.charAt(0).toUpper + token.substring(1) + def firstUpper(token: String) = if (token.isEmpty()) token else token.charAt(0).toUpper + token.substring(1) type IdentConverter = String => String diff --git a/test-suite/djinni/common.djinni b/test-suite/djinni/common.djinni index 61075cb0d..5c165f605 100644 --- a/test-suite/djinni/common.djinni +++ b/test-suite/djinni/common.djinni @@ -13,3 +13,4 @@ @import "multiple_inheritance.djinni" @import "single_language_interfaces.djinni" @import "extended_record.djinni" +@import "varnames.djinni" diff --git a/test-suite/djinni/varnames.djinni b/test-suite/djinni/varnames.djinni new file mode 100644 index 000000000..6d1f3e3e7 --- /dev/null +++ b/test-suite/djinni/varnames.djinni @@ -0,0 +1,11 @@ +# 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. +_varname_record_ = record { + _field_: i8; +} + +_varname_interface_ = interface +c { + _rmethod_(r: _varname_record_): _varname_record_; + _imethod_(i: _varname_interface_): _varname_interface_; +} diff --git a/test-suite/generated-src/cpp/_varname_interface_.hpp b/test-suite/generated-src/cpp/_varname_interface_.hpp new file mode 100644 index 000000000..4a3fd4ef3 --- /dev/null +++ b/test-suite/generated-src/cpp/_varname_interface_.hpp @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#pragma once + +#include + +namespace testsuite { + +struct VarnameRecord; + +class VarnameInterface { +public: + virtual ~VarnameInterface() {} + + virtual VarnameRecord _rmethod_(const VarnameRecord & r) = 0; + + virtual std::shared_ptr _imethod_(const std::shared_ptr & i) = 0; +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/_varname_record_.hpp b/test-suite/generated-src/cpp/_varname_record_.hpp new file mode 100644 index 000000000..83d01393c --- /dev/null +++ b/test-suite/generated-src/cpp/_varname_record_.hpp @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#pragma once + +#include +#include + +namespace testsuite { + +/** + * 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. + */ +struct VarnameRecord final { + int8_t _field_; + + VarnameRecord(int8_t _field__) + : _field_(std::move(_field__)) + {} +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/inFileList.txt b/test-suite/generated-src/inFileList.txt index 6cd5682fe..4b273f4ab 100644 --- a/test-suite/generated-src/inFileList.txt +++ b/test-suite/generated-src/inFileList.txt @@ -15,6 +15,7 @@ djinni/constants.djinni djinni/multiple_inheritance.djinni djinni/single_language_interfaces.djinni djinni/extended_record.djinni +djinni/varnames.djinni djinni/date.djinni djinni/date.yaml djinni/duration.djinni diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameInterface.java new file mode 100644 index 000000000..826b4265e --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameInterface.java @@ -0,0 +1,56 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +package com.dropbox.djinni.test; + +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +public abstract class VarnameInterface { + @Nonnull + public abstract VarnameRecord Rmethod(@Nonnull VarnameRecord r); + + @CheckForNull + public abstract VarnameInterface Imethod(@CheckForNull VarnameInterface i); + + private static final class CppProxy extends VarnameInterface + { + private final long nativeRef; + private final AtomicBoolean destroyed = new AtomicBoolean(false); + + private CppProxy(long nativeRef) + { + if (nativeRef == 0) throw new RuntimeException("nativeRef is zero"); + this.nativeRef = nativeRef; + } + + private native void nativeDestroy(long nativeRef); + public void destroy() + { + boolean destroyed = this.destroyed.getAndSet(true); + if (!destroyed) nativeDestroy(this.nativeRef); + } + protected void finalize() throws java.lang.Throwable + { + destroy(); + super.finalize(); + } + + @Override + public VarnameRecord Rmethod(VarnameRecord r) + { + assert !this.destroyed.get() : "trying to use a destroyed object"; + return native_Rmethod(this.nativeRef, r); + } + private native VarnameRecord native_Rmethod(long _nativeRef, VarnameRecord r); + + @Override + public VarnameInterface Imethod(VarnameInterface i) + { + assert !this.destroyed.get() : "trying to use a destroyed object"; + return native_Imethod(this.nativeRef, i); + } + private native VarnameInterface native_Imethod(long _nativeRef, VarnameInterface i); + } +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameRecord.java new file mode 100644 index 000000000..19a0a898d --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameRecord.java @@ -0,0 +1,35 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +package com.dropbox.djinni.test; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +/** + * 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 class VarnameRecord { + + + /*package*/ final byte mField; + + public VarnameRecord( + byte Field) { + this.mField = Field; + } + + public byte getField() { + return mField; + } + + @Override + public String toString() { + return "VarnameRecord{" + + "mField=" + mField + + "}"; + } + +} diff --git a/test-suite/generated-src/jni/NativeVarnameInterface.cpp b/test-suite/generated-src/jni/NativeVarnameInterface.cpp new file mode 100644 index 000000000..4e85cb678 --- /dev/null +++ b/test-suite/generated-src/jni/NativeVarnameInterface.cpp @@ -0,0 +1,42 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#include "NativeVarnameInterface.hpp" // my header +#include "NativeVarnameRecord.hpp" + +namespace djinni_generated { + +NativeVarnameInterface::NativeVarnameInterface() : ::djinni::JniInterface<::testsuite::VarnameInterface, NativeVarnameInterface>("com/dropbox/djinni/test/VarnameInterface$CppProxy") {} + +NativeVarnameInterface::~NativeVarnameInterface() = default; + + +CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_VarnameInterface_00024CppProxy_nativeDestroy(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + delete reinterpret_cast<::djinni::CppProxyHandle<::testsuite::VarnameInterface>*>(nativeRef); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, ) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_VarnameInterface_00024CppProxy_native_1Rmethod(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_r) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::VarnameInterface>(nativeRef); + auto r = ref->_rmethod_(::djinni_generated::NativeVarnameRecord::toCpp(jniEnv, j_r)); + return ::djinni::release(::djinni_generated::NativeVarnameRecord::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_VarnameInterface_00024CppProxy_native_1Imethod(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_i) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::VarnameInterface>(nativeRef); + auto r = ref->_imethod_(::djinni_generated::NativeVarnameInterface::toCpp(jniEnv, j_i)); + return ::djinni::release(::djinni_generated::NativeVarnameInterface::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeVarnameInterface.hpp b/test-suite/generated-src/jni/NativeVarnameInterface.hpp new file mode 100644 index 000000000..1b2845cab --- /dev/null +++ b/test-suite/generated-src/jni/NativeVarnameInterface.hpp @@ -0,0 +1,32 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#pragma once + +#include "_varname_interface_.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +class NativeVarnameInterface final : ::djinni::JniInterface<::testsuite::VarnameInterface, NativeVarnameInterface> { +public: + using CppType = std::shared_ptr<::testsuite::VarnameInterface>; + using CppOptType = std::shared_ptr<::testsuite::VarnameInterface>; + using JniType = jobject; + + using Boxed = NativeVarnameInterface; + + ~NativeVarnameInterface(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j) { return ::djinni::JniClass::get()._fromJava(jniEnv, j); } + static ::djinni::LocalRef fromCppOpt(JNIEnv* jniEnv, const CppOptType& c) { return {jniEnv, ::djinni::JniClass::get()._toJava(jniEnv, c)}; } + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) { return fromCppOpt(jniEnv, c); } + +private: + NativeVarnameInterface(); + friend ::djinni::JniClass; + friend ::djinni::JniInterface<::testsuite::VarnameInterface, NativeVarnameInterface>; + +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeVarnameRecord.cpp b/test-suite/generated-src/jni/NativeVarnameRecord.cpp new file mode 100644 index 000000000..4d3e34293 --- /dev/null +++ b/test-suite/generated-src/jni/NativeVarnameRecord.cpp @@ -0,0 +1,28 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#include "NativeVarnameRecord.hpp" // my header +#include "Marshal.hpp" + +namespace djinni_generated { + +NativeVarnameRecord::NativeVarnameRecord() = default; + +NativeVarnameRecord::~NativeVarnameRecord() = default; + +auto NativeVarnameRecord::fromCpp(JNIEnv* jniEnv, const CppType& c) -> ::djinni::LocalRef { + const auto& data = ::djinni::JniClass::get(); + auto r = ::djinni::LocalRef{jniEnv->NewObject(data.clazz.get(), data.jconstructor, + ::djinni::get(::djinni::I8::fromCpp(jniEnv, c._field_)))}; + ::djinni::jniExceptionCheck(jniEnv); + return r; +} + +auto NativeVarnameRecord::toCpp(JNIEnv* jniEnv, JniType j) -> CppType { + ::djinni::JniLocalScope jscope(jniEnv, 2); + assert(j != nullptr); + const auto& data = ::djinni::JniClass::get(); + return {::djinni::I8::toCpp(jniEnv, jniEnv->GetByteField(j, data.field_mField))}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeVarnameRecord.hpp b/test-suite/generated-src/jni/NativeVarnameRecord.hpp new file mode 100644 index 000000000..0462273b7 --- /dev/null +++ b/test-suite/generated-src/jni/NativeVarnameRecord.hpp @@ -0,0 +1,32 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#pragma once + +#include "_varname_record_.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +class NativeVarnameRecord final { +public: + using CppType = ::testsuite::VarnameRecord; + using JniType = jobject; + + using Boxed = NativeVarnameRecord; + + ~NativeVarnameRecord(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j); + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c); + +private: + NativeVarnameRecord(); + friend ::djinni::JniClass; + + const ::djinni::GlobalRef clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/VarnameRecord") }; + const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "", "(B)V") }; + const jfieldID field_mField { ::djinni::jniGetFieldID(clazz.get(), "mField", "B") }; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBClientInterface+Private.mm b/test-suite/generated-src/objc/DBClientInterface+Private.mm index 47cfc1f07..3593ff4fc 100644 --- a/test-suite/generated-src/objc/DBClientInterface+Private.mm +++ b/test-suite/generated-src/objc/DBClientInterface+Private.mm @@ -21,40 +21,40 @@ ::testsuite::ClientReturnedRecord get_record(int64_t c_record_id, const std::string & c_utf8string, const std::experimental::optional & c_misc) override { @autoreleasepool { - auto r = [Handle::get() getRecord:(::djinni::I64::fromCpp(c_record_id)) - utf8string:(::djinni::String::fromCpp(c_utf8string)) - misc:(::djinni::Optional::fromCpp(c_misc))]; - return ::djinni_generated::ClientReturnedRecord::toCpp(r); + auto objcpp_result_ = [Handle::get() getRecord:(::djinni::I64::fromCpp(c_record_id)) + utf8string:(::djinni::String::fromCpp(c_utf8string)) + misc:(::djinni::Optional::fromCpp(c_misc))]; + return ::djinni_generated::ClientReturnedRecord::toCpp(objcpp_result_); } } double identifier_check(const std::vector & c_data, int32_t c_r, int64_t c_jret) override { @autoreleasepool { - auto r = [Handle::get() identifierCheck:(::djinni::Binary::fromCpp(c_data)) - r:(::djinni::I32::fromCpp(c_r)) - jret:(::djinni::I64::fromCpp(c_jret))]; - return ::djinni::F64::toCpp(r); + auto objcpp_result_ = [Handle::get() identifierCheck:(::djinni::Binary::fromCpp(c_data)) + r:(::djinni::I32::fromCpp(c_r)) + jret:(::djinni::I64::fromCpp(c_jret))]; + return ::djinni::F64::toCpp(objcpp_result_); } } std::string return_str() override { @autoreleasepool { - auto r = [Handle::get() returnStr]; - return ::djinni::String::toCpp(r); + auto objcpp_result_ = [Handle::get() returnStr]; + return ::djinni::String::toCpp(objcpp_result_); } } std::string meth_taking_interface(const std::shared_ptr<::testsuite::ClientInterface> & c_i) override { @autoreleasepool { - auto r = [Handle::get() methTakingInterface:(::djinni_generated::ClientInterface::fromCpp(c_i))]; - return ::djinni::String::toCpp(r); + auto objcpp_result_ = [Handle::get() methTakingInterface:(::djinni_generated::ClientInterface::fromCpp(c_i))]; + return ::djinni::String::toCpp(objcpp_result_); } } std::string meth_taking_optional_interface(const std::shared_ptr<::testsuite::ClientInterface> & c_i) override { @autoreleasepool { - auto r = [Handle::get() methTakingOptionalInterface:(::djinni::Optional::fromCpp(c_i))]; - return ::djinni::String::toCpp(r); + auto objcpp_result_ = [Handle::get() methTakingOptionalInterface:(::djinni::Optional::fromCpp(c_i))]; + return ::djinni::String::toCpp(objcpp_result_); } } }; diff --git a/test-suite/generated-src/objc/DBConflictUser+Private.mm b/test-suite/generated-src/objc/DBConflictUser+Private.mm index 7b3cf7864..937934de1 100644 --- a/test-suite/generated-src/objc/DBConflictUser+Private.mm +++ b/test-suite/generated-src/objc/DBConflictUser+Private.mm @@ -33,15 +33,15 @@ - (id)initWithCpp:(const std::shared_ptr<::testsuite::ConflictUser>&)cppRef - (nullable DBConflict *)Conflict { try { - auto r = _cppRefHandle.get()->Conflict(); - return ::djinni_generated::Conflict::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->Conflict(); + return ::djinni_generated::Conflict::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } - (BOOL)conflictArg:(nonnull NSSet *)cs { try { - auto r = _cppRefHandle.get()->conflict_arg(::djinni::Set<::djinni_generated::Conflict>::toCpp(cs)); - return ::djinni::Bool::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->conflict_arg(::djinni::Set<::djinni_generated::Conflict>::toCpp(cs)); + return ::djinni::Bool::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/test-suite/generated-src/objc/DBCppException+Private.mm b/test-suite/generated-src/objc/DBCppException+Private.mm index 2a9509a6a..6d068a92e 100644 --- a/test-suite/generated-src/objc/DBCppException+Private.mm +++ b/test-suite/generated-src/objc/DBCppException+Private.mm @@ -32,15 +32,15 @@ - (id)initWithCpp:(const std::shared_ptr<::testsuite::CppException>&)cppRef - (int32_t)throwAnException { try { - auto r = _cppRefHandle.get()->throw_an_exception(); - return ::djinni::I32::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->throw_an_exception(); + return ::djinni::I32::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nullable DBCppException *)get { try { - auto r = ::testsuite::CppException::get(); - return ::djinni_generated::CppException::fromCpp(r); + auto objcpp_result_ = ::testsuite::CppException::get(); + return ::djinni_generated::CppException::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/test-suite/generated-src/objc/DBEnumUsageInterface+Private.mm b/test-suite/generated-src/objc/DBEnumUsageInterface+Private.mm index 3e02c5fdb..460b43183 100644 --- a/test-suite/generated-src/objc/DBEnumUsageInterface+Private.mm +++ b/test-suite/generated-src/objc/DBEnumUsageInterface+Private.mm @@ -34,36 +34,36 @@ - (id)initWithCpp:(const std::shared_ptr<::testsuite::EnumUsageInterface>&)cppRe - (DBColor)e:(DBColor)e { try { - auto r = _cppRefHandle.get()->e(::djinni::Enum<::testsuite::color, DBColor>::toCpp(e)); - return ::djinni::Enum<::testsuite::color, DBColor>::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->e(::djinni::Enum<::testsuite::color, DBColor>::toCpp(e)); + return ::djinni::Enum<::testsuite::color, DBColor>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } - (nullable NSNumber *)o:(nullable NSNumber *)o { try { - auto r = _cppRefHandle.get()->o(::djinni::Optional>::toCpp(o)); - return ::djinni::Optional>::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->o(::djinni::Optional>::toCpp(o)); + return ::djinni::Optional>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } - (nonnull NSArray *)l:(nonnull NSArray *)l { try { - auto r = _cppRefHandle.get()->l(::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(l)); - return ::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->l(::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(l)); + return ::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } - (nonnull NSSet *)s:(nonnull NSSet *)s { try { - auto r = _cppRefHandle.get()->s(::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(s)); - return ::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->s(::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(s)); + return ::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } - (nonnull NSDictionary *)m:(nonnull NSDictionary *)m { try { - auto r = _cppRefHandle.get()->m(::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::toCpp(m)); - return ::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->m(::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::toCpp(m)); + return ::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } @@ -78,36 +78,36 @@ - (nullable NSNumber *)o:(nullable NSNumber *)o { ::testsuite::color e(::testsuite::color c_e) override { @autoreleasepool { - auto r = [Handle::get() e:(::djinni::Enum<::testsuite::color, DBColor>::fromCpp(c_e))]; - return ::djinni::Enum<::testsuite::color, DBColor>::toCpp(r); + auto objcpp_result_ = [Handle::get() e:(::djinni::Enum<::testsuite::color, DBColor>::fromCpp(c_e))]; + return ::djinni::Enum<::testsuite::color, DBColor>::toCpp(objcpp_result_); } } std::experimental::optional<::testsuite::color> o(std::experimental::optional<::testsuite::color> c_o) override { @autoreleasepool { - auto r = [Handle::get() o:(::djinni::Optional>::fromCpp(c_o))]; - return ::djinni::Optional>::toCpp(r); + auto objcpp_result_ = [Handle::get() o:(::djinni::Optional>::fromCpp(c_o))]; + return ::djinni::Optional>::toCpp(objcpp_result_); } } std::vector<::testsuite::color> l(const std::vector<::testsuite::color> & c_l) override { @autoreleasepool { - auto r = [Handle::get() l:(::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(c_l))]; - return ::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(r); + auto objcpp_result_ = [Handle::get() l:(::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(c_l))]; + return ::djinni::List<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(objcpp_result_); } } std::unordered_set<::testsuite::color> s(const std::unordered_set<::testsuite::color> & c_s) override { @autoreleasepool { - auto r = [Handle::get() s:(::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(c_s))]; - return ::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(r); + auto objcpp_result_ = [Handle::get() s:(::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(c_s))]; + return ::djinni::Set<::djinni::Enum<::testsuite::color, DBColor>>::toCpp(objcpp_result_); } } std::unordered_map<::testsuite::color, ::testsuite::color> m(const std::unordered_map<::testsuite::color, ::testsuite::color> & c_m) override { @autoreleasepool { - auto r = [Handle::get() m:(::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(c_m))]; - return ::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::toCpp(r); + auto objcpp_result_ = [Handle::get() m:(::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::fromCpp(c_m))]; + return ::djinni::Map<::djinni::Enum<::testsuite::color, DBColor>, ::djinni::Enum<::testsuite::color, DBColor>>::toCpp(objcpp_result_); } } }; diff --git a/test-suite/generated-src/objc/DBExternInterface1+Private.mm b/test-suite/generated-src/objc/DBExternInterface1+Private.mm index 5d07fec08..6a85c6f8b 100644 --- a/test-suite/generated-src/objc/DBExternInterface1+Private.mm +++ b/test-suite/generated-src/objc/DBExternInterface1+Private.mm @@ -33,8 +33,8 @@ - (id)initWithCpp:(const std::shared_ptr<::ExternInterface1>&)cppRef - (nonnull DBClientReturnedRecord *)foo:(nullable id)i { try { - auto r = _cppRefHandle.get()->foo(::djinni_generated::ClientInterface::toCpp(i)); - return ::djinni_generated::ClientReturnedRecord::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->foo(::djinni_generated::ClientInterface::toCpp(i)); + return ::djinni_generated::ClientReturnedRecord::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/test-suite/generated-src/objc/DBExternInterface2+Private.mm b/test-suite/generated-src/objc/DBExternInterface2+Private.mm index 010b4de3f..38608286b 100644 --- a/test-suite/generated-src/objc/DBExternInterface2+Private.mm +++ b/test-suite/generated-src/objc/DBExternInterface2+Private.mm @@ -21,8 +21,8 @@ ::ExternRecordWithDerivings foo(const std::shared_ptr<::testsuite::TestHelpers> & c_i) override { @autoreleasepool { - auto r = [Handle::get() foo:(::djinni_generated::TestHelpers::fromCpp(c_i))]; - return ::djinni_generated::ExternRecordWithDerivings::toCpp(r); + auto objcpp_result_ = [Handle::get() foo:(::djinni_generated::TestHelpers::fromCpp(c_i))]; + return ::djinni_generated::ExternRecordWithDerivings::toCpp(objcpp_result_); } } }; diff --git a/test-suite/generated-src/objc/DBListenerCaller+Private.mm b/test-suite/generated-src/objc/DBListenerCaller+Private.mm index 3fa3bed22..b403438af 100644 --- a/test-suite/generated-src/objc/DBListenerCaller+Private.mm +++ b/test-suite/generated-src/objc/DBListenerCaller+Private.mm @@ -34,9 +34,9 @@ - (id)initWithCpp:(const std::shared_ptr<::testsuite::ListenerCaller>&)cppRef + (nullable DBListenerCaller *)init:(nullable id)firstL secondL:(nullable id)secondL { try { - auto r = ::testsuite::ListenerCaller::init(::djinni_generated::FirstListener::toCpp(firstL), - ::djinni_generated::SecondListener::toCpp(secondL)); - return ::djinni_generated::ListenerCaller::fromCpp(r); + auto objcpp_result_ = ::testsuite::ListenerCaller::init(::djinni_generated::FirstListener::toCpp(firstL), + ::djinni_generated::SecondListener::toCpp(secondL)); + return ::djinni_generated::ListenerCaller::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/test-suite/generated-src/objc/DBReturnOne+Private.mm b/test-suite/generated-src/objc/DBReturnOne+Private.mm index 4ed9355de..1b363b5c6 100644 --- a/test-suite/generated-src/objc/DBReturnOne+Private.mm +++ b/test-suite/generated-src/objc/DBReturnOne+Private.mm @@ -32,15 +32,15 @@ - (id)initWithCpp:(const std::shared_ptr<::testsuite::ReturnOne>&)cppRef + (nullable DBReturnOne *)getInstance { try { - auto r = ::testsuite::ReturnOne::get_instance(); - return ::djinni_generated::ReturnOne::fromCpp(r); + auto objcpp_result_ = ::testsuite::ReturnOne::get_instance(); + return ::djinni_generated::ReturnOne::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } - (int8_t)returnOne { try { - auto r = _cppRefHandle.get()->return_one(); - return ::djinni::I8::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->return_one(); + return ::djinni::I8::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/test-suite/generated-src/objc/DBReturnTwo+Private.mm b/test-suite/generated-src/objc/DBReturnTwo+Private.mm index e5adc266d..1050fb043 100644 --- a/test-suite/generated-src/objc/DBReturnTwo+Private.mm +++ b/test-suite/generated-src/objc/DBReturnTwo+Private.mm @@ -32,15 +32,15 @@ - (id)initWithCpp:(const std::shared_ptr<::testsuite::ReturnTwo>&)cppRef + (nullable DBReturnTwo *)getInstance { try { - auto r = ::testsuite::ReturnTwo::get_instance(); - return ::djinni_generated::ReturnTwo::fromCpp(r); + auto objcpp_result_ = ::testsuite::ReturnTwo::get_instance(); + return ::djinni_generated::ReturnTwo::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } - (int8_t)returnTwo { try { - auto r = _cppRefHandle.get()->return_two(); - return ::djinni::I8::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->return_two(); + return ::djinni::I8::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/test-suite/generated-src/objc/DBReverseClientInterface+Private.mm b/test-suite/generated-src/objc/DBReverseClientInterface+Private.mm index 7b797255a..9e5fd500f 100644 --- a/test-suite/generated-src/objc/DBReverseClientInterface+Private.mm +++ b/test-suite/generated-src/objc/DBReverseClientInterface+Private.mm @@ -32,29 +32,29 @@ - (id)initWithCpp:(const std::shared_ptr<::testsuite::ReverseClientInterface>&)c - (nonnull NSString *)returnStr { try { - auto r = _cppRefHandle.get()->return_str(); - return ::djinni::String::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->return_str(); + return ::djinni::String::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } - (nonnull NSString *)methTakingInterface:(nullable DBReverseClientInterface *)i { try { - auto r = _cppRefHandle.get()->meth_taking_interface(::djinni_generated::ReverseClientInterface::toCpp(i)); - return ::djinni::String::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->meth_taking_interface(::djinni_generated::ReverseClientInterface::toCpp(i)); + return ::djinni::String::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } - (nonnull NSString *)methTakingOptionalInterface:(nullable DBReverseClientInterface *)i { try { - auto r = _cppRefHandle.get()->meth_taking_optional_interface(::djinni::Optional::toCpp(i)); - return ::djinni::String::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->meth_taking_optional_interface(::djinni::Optional::toCpp(i)); + return ::djinni::String::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nullable DBReverseClientInterface *)create { try { - auto r = ::testsuite::ReverseClientInterface::create(); - return ::djinni_generated::ReverseClientInterface::fromCpp(r); + auto objcpp_result_ = ::testsuite::ReverseClientInterface::create(); + return ::djinni_generated::ReverseClientInterface::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/test-suite/generated-src/objc/DBTestDuration+Private.mm b/test-suite/generated-src/objc/DBTestDuration+Private.mm index ec7cb521e..4f374d52b 100644 --- a/test-suite/generated-src/objc/DBTestDuration+Private.mm +++ b/test-suite/generated-src/objc/DBTestDuration+Private.mm @@ -33,141 +33,141 @@ - (id)initWithCpp:(const std::shared_ptr<::testsuite::TestDuration>&)cppRef + (nonnull NSString *)hoursString:(NSTimeInterval)dt { try { - auto r = ::testsuite::TestDuration::hoursString(::djinni::Duration<::djinni::I32, ::djinni::Duration_h>::toCpp(dt)); - return ::djinni::String::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::hoursString(::djinni::Duration<::djinni::I32, ::djinni::Duration_h>::toCpp(dt)); + return ::djinni::String::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull NSString *)minutesString:(NSTimeInterval)dt { try { - auto r = ::testsuite::TestDuration::minutesString(::djinni::Duration<::djinni::I32, ::djinni::Duration_min>::toCpp(dt)); - return ::djinni::String::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::minutesString(::djinni::Duration<::djinni::I32, ::djinni::Duration_min>::toCpp(dt)); + return ::djinni::String::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull NSString *)secondsString:(NSTimeInterval)dt { try { - auto r = ::testsuite::TestDuration::secondsString(::djinni::Duration<::djinni::I32, ::djinni::Duration_s>::toCpp(dt)); - return ::djinni::String::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::secondsString(::djinni::Duration<::djinni::I32, ::djinni::Duration_s>::toCpp(dt)); + return ::djinni::String::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull NSString *)millisString:(NSTimeInterval)dt { try { - auto r = ::testsuite::TestDuration::millisString(::djinni::Duration<::djinni::I32, ::djinni::Duration_ms>::toCpp(dt)); - return ::djinni::String::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::millisString(::djinni::Duration<::djinni::I32, ::djinni::Duration_ms>::toCpp(dt)); + return ::djinni::String::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull NSString *)microsString:(NSTimeInterval)dt { try { - auto r = ::testsuite::TestDuration::microsString(::djinni::Duration<::djinni::I32, ::djinni::Duration_us>::toCpp(dt)); - return ::djinni::String::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::microsString(::djinni::Duration<::djinni::I32, ::djinni::Duration_us>::toCpp(dt)); + return ::djinni::String::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull NSString *)nanosString:(NSTimeInterval)dt { try { - auto r = ::testsuite::TestDuration::nanosString(::djinni::Duration<::djinni::I32, ::djinni::Duration_ns>::toCpp(dt)); - return ::djinni::String::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::nanosString(::djinni::Duration<::djinni::I32, ::djinni::Duration_ns>::toCpp(dt)); + return ::djinni::String::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (NSTimeInterval)hours:(int32_t)count { try { - auto r = ::testsuite::TestDuration::hours(::djinni::I32::toCpp(count)); - return ::djinni::Duration<::djinni::I32, ::djinni::Duration_h>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::hours(::djinni::I32::toCpp(count)); + return ::djinni::Duration<::djinni::I32, ::djinni::Duration_h>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (NSTimeInterval)minutes:(int32_t)count { try { - auto r = ::testsuite::TestDuration::minutes(::djinni::I32::toCpp(count)); - return ::djinni::Duration<::djinni::I32, ::djinni::Duration_min>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::minutes(::djinni::I32::toCpp(count)); + return ::djinni::Duration<::djinni::I32, ::djinni::Duration_min>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (NSTimeInterval)seconds:(int32_t)count { try { - auto r = ::testsuite::TestDuration::seconds(::djinni::I32::toCpp(count)); - return ::djinni::Duration<::djinni::I32, ::djinni::Duration_s>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::seconds(::djinni::I32::toCpp(count)); + return ::djinni::Duration<::djinni::I32, ::djinni::Duration_s>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (NSTimeInterval)millis:(int32_t)count { try { - auto r = ::testsuite::TestDuration::millis(::djinni::I32::toCpp(count)); - return ::djinni::Duration<::djinni::I32, ::djinni::Duration_ms>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::millis(::djinni::I32::toCpp(count)); + return ::djinni::Duration<::djinni::I32, ::djinni::Duration_ms>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (NSTimeInterval)micros:(int32_t)count { try { - auto r = ::testsuite::TestDuration::micros(::djinni::I32::toCpp(count)); - return ::djinni::Duration<::djinni::I32, ::djinni::Duration_us>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::micros(::djinni::I32::toCpp(count)); + return ::djinni::Duration<::djinni::I32, ::djinni::Duration_us>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (NSTimeInterval)nanos:(int32_t)count { try { - auto r = ::testsuite::TestDuration::nanos(::djinni::I32::toCpp(count)); - return ::djinni::Duration<::djinni::I32, ::djinni::Duration_ns>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::nanos(::djinni::I32::toCpp(count)); + return ::djinni::Duration<::djinni::I32, ::djinni::Duration_ns>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (NSTimeInterval)hoursf:(double)count { try { - auto r = ::testsuite::TestDuration::hoursf(::djinni::F64::toCpp(count)); - return ::djinni::Duration<::djinni::F64, ::djinni::Duration_h>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::hoursf(::djinni::F64::toCpp(count)); + return ::djinni::Duration<::djinni::F64, ::djinni::Duration_h>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (NSTimeInterval)minutesf:(double)count { try { - auto r = ::testsuite::TestDuration::minutesf(::djinni::F64::toCpp(count)); - return ::djinni::Duration<::djinni::F64, ::djinni::Duration_min>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::minutesf(::djinni::F64::toCpp(count)); + return ::djinni::Duration<::djinni::F64, ::djinni::Duration_min>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (NSTimeInterval)secondsf:(double)count { try { - auto r = ::testsuite::TestDuration::secondsf(::djinni::F64::toCpp(count)); - return ::djinni::Duration<::djinni::F64, ::djinni::Duration_s>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::secondsf(::djinni::F64::toCpp(count)); + return ::djinni::Duration<::djinni::F64, ::djinni::Duration_s>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (NSTimeInterval)millisf:(double)count { try { - auto r = ::testsuite::TestDuration::millisf(::djinni::F64::toCpp(count)); - return ::djinni::Duration<::djinni::F64, ::djinni::Duration_ms>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::millisf(::djinni::F64::toCpp(count)); + return ::djinni::Duration<::djinni::F64, ::djinni::Duration_ms>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (NSTimeInterval)microsf:(double)count { try { - auto r = ::testsuite::TestDuration::microsf(::djinni::F64::toCpp(count)); - return ::djinni::Duration<::djinni::F64, ::djinni::Duration_us>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::microsf(::djinni::F64::toCpp(count)); + return ::djinni::Duration<::djinni::F64, ::djinni::Duration_us>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (NSTimeInterval)nanosf:(double)count { try { - auto r = ::testsuite::TestDuration::nanosf(::djinni::F64::toCpp(count)); - return ::djinni::Duration<::djinni::F64, ::djinni::Duration_ns>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::nanosf(::djinni::F64::toCpp(count)); + return ::djinni::Duration<::djinni::F64, ::djinni::Duration_ns>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nullable NSNumber *)box:(int64_t)count { try { - auto r = ::testsuite::TestDuration::box(::djinni::I64::toCpp(count)); - return ::djinni::Optional>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::box(::djinni::I64::toCpp(count)); + return ::djinni::Optional>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (int64_t)unbox:(nullable NSNumber *)dt { try { - auto r = ::testsuite::TestDuration::unbox(::djinni::Optional>::toCpp(dt)); - return ::djinni::I64::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestDuration::unbox(::djinni::Optional>::toCpp(dt)); + return ::djinni::I64::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/test-suite/generated-src/objc/DBTestHelpers+Private.mm b/test-suite/generated-src/objc/DBTestHelpers+Private.mm index 432c2066a..eab020b8b 100644 --- a/test-suite/generated-src/objc/DBTestHelpers+Private.mm +++ b/test-suite/generated-src/objc/DBTestHelpers+Private.mm @@ -40,85 +40,85 @@ - (id)initWithCpp:(const std::shared_ptr<::testsuite::TestHelpers>&)cppRef + (nonnull DBSetRecord *)getSetRecord { try { - auto r = ::testsuite::TestHelpers::get_set_record(); - return ::djinni_generated::SetRecord::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::get_set_record(); + return ::djinni_generated::SetRecord::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (BOOL)checkSetRecord:(nonnull DBSetRecord *)rec { try { - auto r = ::testsuite::TestHelpers::check_set_record(::djinni_generated::SetRecord::toCpp(rec)); - return ::djinni::Bool::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::check_set_record(::djinni_generated::SetRecord::toCpp(rec)); + return ::djinni::Bool::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull DBPrimitiveList *)getPrimitiveList { try { - auto r = ::testsuite::TestHelpers::get_primitive_list(); - return ::djinni_generated::PrimitiveList::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::get_primitive_list(); + return ::djinni_generated::PrimitiveList::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (BOOL)checkPrimitiveList:(nonnull DBPrimitiveList *)pl { try { - auto r = ::testsuite::TestHelpers::check_primitive_list(::djinni_generated::PrimitiveList::toCpp(pl)); - return ::djinni::Bool::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::check_primitive_list(::djinni_generated::PrimitiveList::toCpp(pl)); + return ::djinni::Bool::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull DBNestedCollection *)getNestedCollection { try { - auto r = ::testsuite::TestHelpers::get_nested_collection(); - return ::djinni_generated::NestedCollection::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::get_nested_collection(); + return ::djinni_generated::NestedCollection::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (BOOL)checkNestedCollection:(nonnull DBNestedCollection *)nc { try { - auto r = ::testsuite::TestHelpers::check_nested_collection(::djinni_generated::NestedCollection::toCpp(nc)); - return ::djinni::Bool::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::check_nested_collection(::djinni_generated::NestedCollection::toCpp(nc)); + return ::djinni::Bool::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull NSDictionary *)getMap { try { - auto r = ::testsuite::TestHelpers::get_map(); - return ::djinni::Map<::djinni::String, ::djinni::I64>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::get_map(); + return ::djinni::Map<::djinni::String, ::djinni::I64>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (BOOL)checkMap:(nonnull NSDictionary *)m { try { - auto r = ::testsuite::TestHelpers::check_map(::djinni::Map<::djinni::String, ::djinni::I64>::toCpp(m)); - return ::djinni::Bool::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::check_map(::djinni::Map<::djinni::String, ::djinni::I64>::toCpp(m)); + return ::djinni::Bool::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull NSDictionary *)getEmptyMap { try { - auto r = ::testsuite::TestHelpers::get_empty_map(); - return ::djinni::Map<::djinni::String, ::djinni::I64>::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::get_empty_map(); + return ::djinni::Map<::djinni::String, ::djinni::I64>::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (BOOL)checkEmptyMap:(nonnull NSDictionary *)m { try { - auto r = ::testsuite::TestHelpers::check_empty_map(::djinni::Map<::djinni::String, ::djinni::I64>::toCpp(m)); - return ::djinni::Bool::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::check_empty_map(::djinni::Map<::djinni::String, ::djinni::I64>::toCpp(m)); + return ::djinni::Bool::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull DBMapListRecord *)getMapListRecord { try { - auto r = ::testsuite::TestHelpers::get_map_list_record(); - return ::djinni_generated::MapListRecord::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::get_map_list_record(); + return ::djinni_generated::MapListRecord::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (BOOL)checkMapListRecord:(nonnull DBMapListRecord *)m { try { - auto r = ::testsuite::TestHelpers::check_map_list_record(::djinni_generated::MapListRecord::toCpp(m)); - return ::djinni::Bool::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::check_map_list_record(::djinni_generated::MapListRecord::toCpp(m)); + return ::djinni::Bool::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } @@ -154,15 +154,15 @@ + (void)checkEnum:(DBColor)c { + (nullable id)tokenId:(nullable id)t { try { - auto r = ::testsuite::TestHelpers::token_id(::djinni_generated::UserToken::toCpp(t)); - return ::djinni_generated::UserToken::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::token_id(::djinni_generated::UserToken::toCpp(t)); + return ::djinni_generated::UserToken::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nullable id)createCppToken { try { - auto r = ::testsuite::TestHelpers::create_cpp_token(); - return ::djinni_generated::UserToken::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::create_cpp_token(); + return ::djinni_generated::UserToken::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } @@ -174,8 +174,8 @@ + (void)checkCppToken:(nullable id)t { + (int64_t)cppTokenId:(nullable id)t { try { - auto r = ::testsuite::TestHelpers::cpp_token_id(::djinni_generated::UserToken::toCpp(t)); - return ::djinni::I64::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::cpp_token_id(::djinni_generated::UserToken::toCpp(t)); + return ::djinni::I64::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } @@ -189,22 +189,22 @@ + (void)checkTokenType:(nullable id)t + (nullable NSNumber *)returnNone { try { - auto r = ::testsuite::TestHelpers::return_none(); - return ::djinni::Optional::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::return_none(); + return ::djinni::Optional::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull DBAssortedPrimitives *)assortedPrimitivesId:(nonnull DBAssortedPrimitives *)i { try { - auto r = ::testsuite::TestHelpers::assorted_primitives_id(::djinni_generated::AssortedPrimitives::toCpp(i)); - return ::djinni_generated::AssortedPrimitives::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::assorted_primitives_id(::djinni_generated::AssortedPrimitives::toCpp(i)); + return ::djinni_generated::AssortedPrimitives::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull NSData *)idBinary:(nonnull NSData *)b { try { - auto r = ::testsuite::TestHelpers::id_binary(::djinni::Binary::toCpp(b)); - return ::djinni::Binary::fromCpp(r); + auto objcpp_result_ = ::testsuite::TestHelpers::id_binary(::djinni::Binary::toCpp(b)); + return ::djinni::Binary::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/test-suite/generated-src/objc/DBUserToken+Private.mm b/test-suite/generated-src/objc/DBUserToken+Private.mm index eacac79ab..d22c729fd 100644 --- a/test-suite/generated-src/objc/DBUserToken+Private.mm +++ b/test-suite/generated-src/objc/DBUserToken+Private.mm @@ -33,8 +33,8 @@ - (id)initWithCpp:(const std::shared_ptr<::testsuite::UserToken>&)cppRef - (nonnull NSString *)whoami { try { - auto r = _cppRefHandle.get()->whoami(); - return ::djinni::String::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->whoami(); + return ::djinni::String::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } @@ -49,8 +49,8 @@ - (nonnull NSString *)whoami { std::string whoami() override { @autoreleasepool { - auto r = [Handle::get() whoami]; - return ::djinni::String::toCpp(r); + auto objcpp_result_ = [Handle::get() whoami]; + return ::djinni::String::toCpp(objcpp_result_); } } }; diff --git a/test-suite/generated-src/objc/DBUsesSingleLanguageListeners+Private.mm b/test-suite/generated-src/objc/DBUsesSingleLanguageListeners+Private.mm index 0092fc936..8f26c375f 100644 --- a/test-suite/generated-src/objc/DBUsesSingleLanguageListeners+Private.mm +++ b/test-suite/generated-src/objc/DBUsesSingleLanguageListeners+Private.mm @@ -40,8 +40,8 @@ - (void)callForObjC:(nullable id)l { - (nullable id)returnForObjC { try { - auto r = _cppRefHandle.get()->returnForObjC(); - return ::djinni_generated::ObjcOnlyListener::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->returnForObjC(); + return ::djinni_generated::ObjcOnlyListener::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } @@ -53,8 +53,8 @@ - (void)callForJava:(nullable DBJavaOnlyListener *)l { - (nullable DBJavaOnlyListener *)returnForJava { try { - auto r = _cppRefHandle.get()->returnForJava(); - return ::djinni_generated::JavaOnlyListener::fromCpp(r); + auto objcpp_result_ = _cppRefHandle.get()->returnForJava(); + return ::djinni_generated::JavaOnlyListener::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } @@ -75,8 +75,8 @@ void callForObjC(const std::shared_ptr<::testsuite::ObjcOnlyListener> & c_l) ove std::shared_ptr<::testsuite::ObjcOnlyListener> returnForObjC() override { @autoreleasepool { - auto r = [Handle::get() returnForObjC]; - return ::djinni_generated::ObjcOnlyListener::toCpp(r); + auto objcpp_result_ = [Handle::get() returnForObjC]; + return ::djinni_generated::ObjcOnlyListener::toCpp(objcpp_result_); } } void callForJava(const std::shared_ptr<::testsuite::JavaOnlyListener> & c_l) override @@ -88,8 +88,8 @@ void callForJava(const std::shared_ptr<::testsuite::JavaOnlyListener> & c_l) ove std::shared_ptr<::testsuite::JavaOnlyListener> returnForJava() override { @autoreleasepool { - auto r = [Handle::get() returnForJava]; - return ::djinni_generated::JavaOnlyListener::toCpp(r); + auto objcpp_result_ = [Handle::get() returnForJava]; + return ::djinni_generated::JavaOnlyListener::toCpp(objcpp_result_); } } }; diff --git a/test-suite/generated-src/objc/DBVarnameInterface+Private.h b/test-suite/generated-src/objc/DBVarnameInterface+Private.h new file mode 100644 index 000000000..ce03e6180 --- /dev/null +++ b/test-suite/generated-src/objc/DBVarnameInterface+Private.h @@ -0,0 +1,31 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#include "_varname_interface_.hpp" +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBVarnameInterface; + +namespace djinni_generated { + +class VarnameInterface +{ +public: + using CppType = std::shared_ptr<::testsuite::VarnameInterface>; + using CppOptType = std::shared_ptr<::testsuite::VarnameInterface>; + using ObjcType = DBVarnameInterface*; + + using Boxed = VarnameInterface; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCppOpt(const CppOptType& cpp); + static ObjcType fromCpp(const CppType& cpp) { return fromCppOpt(cpp); } + +private: + class ObjcProxy; +}; + +} // namespace djinni_generated + diff --git a/test-suite/generated-src/objc/DBVarnameInterface+Private.mm b/test-suite/generated-src/objc/DBVarnameInterface+Private.mm new file mode 100644 index 000000000..fd3d78307 --- /dev/null +++ b/test-suite/generated-src/objc/DBVarnameInterface+Private.mm @@ -0,0 +1,67 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#import "DBVarnameInterface+Private.h" +#import "DBVarnameInterface.h" +#import "DBVarnameRecord+Private.h" +#import "DJICppWrapperCache+Private.h" +#import "DJIError.h" +#include +#include +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@interface DBVarnameInterface () + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::VarnameInterface>&)cppRef; + +@end + +@implementation DBVarnameInterface { + ::djinni::CppProxyCache::Handle> _cppRefHandle; +} + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::VarnameInterface>&)cppRef +{ + if (self = [super init]) { + _cppRefHandle.assign(cppRef); + } + return self; +} + +- (nonnull DBVarnameRecord *)Rmethod:(nonnull DBVarnameRecord *)r { + try { + auto objcpp_result_ = _cppRefHandle.get()->_rmethod_(::djinni_generated::VarnameRecord::toCpp(r)); + return ::djinni_generated::VarnameRecord::fromCpp(objcpp_result_); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +- (nullable DBVarnameInterface *)Imethod:(nullable DBVarnameInterface *)i { + try { + auto objcpp_result_ = _cppRefHandle.get()->_imethod_(::djinni_generated::VarnameInterface::toCpp(i)); + return ::djinni_generated::VarnameInterface::fromCpp(objcpp_result_); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +namespace djinni_generated { + +auto VarnameInterface::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + return objc->_cppRefHandle.get(); +} + +auto VarnameInterface::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + return ::djinni::get_cpp_proxy(cpp); +} + +} // namespace djinni_generated + +@end diff --git a/test-suite/generated-src/objc/DBVarnameInterface.h b/test-suite/generated-src/objc/DBVarnameInterface.h new file mode 100644 index 000000000..45df732cd --- /dev/null +++ b/test-suite/generated-src/objc/DBVarnameInterface.h @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#import "DBVarnameRecord.h" +#import +@class DBVarnameInterface; + + +@interface DBVarnameInterface : NSObject + +- (nonnull DBVarnameRecord *)Rmethod:(nonnull DBVarnameRecord *)r; + +- (nullable DBVarnameInterface *)Imethod:(nullable DBVarnameInterface *)i; + +@end diff --git a/test-suite/generated-src/objc/DBVarnameRecord+Private.h b/test-suite/generated-src/objc/DBVarnameRecord+Private.h new file mode 100644 index 000000000..b1c1ee563 --- /dev/null +++ b/test-suite/generated-src/objc/DBVarnameRecord+Private.h @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#import "DBVarnameRecord.h" +#include "_varname_record_.hpp" + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBVarnameRecord; + +namespace djinni_generated { + +struct VarnameRecord +{ + using CppType = ::testsuite::VarnameRecord; + using ObjcType = DBVarnameRecord*; + + using Boxed = VarnameRecord; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCpp(const CppType& cpp); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBVarnameRecord+Private.mm b/test-suite/generated-src/objc/DBVarnameRecord+Private.mm new file mode 100644 index 000000000..fd1325418 --- /dev/null +++ b/test-suite/generated-src/objc/DBVarnameRecord+Private.mm @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#import "DBVarnameRecord+Private.h" +#import "DJIMarshal+Private.h" +#include + +namespace djinni_generated { + +auto VarnameRecord::toCpp(ObjcType obj) -> CppType +{ + assert(obj); + return {::djinni::I8::toCpp(obj.Field)}; +} + +auto VarnameRecord::fromCpp(const CppType& cpp) -> ObjcType +{ + return [[DBVarnameRecord alloc] initWithField:(::djinni::I8::fromCpp(cpp._field_))]; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBVarnameRecord.h b/test-suite/generated-src/objc/DBVarnameRecord.h new file mode 100644 index 000000000..5c20f1175 --- /dev/null +++ b/test-suite/generated-src/objc/DBVarnameRecord.h @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#import + +/** + * 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. + */ +@interface DBVarnameRecord : NSObject +- (nonnull instancetype)initWithField:(int8_t)Field; ++ (nonnull instancetype)VarnameRecordWithField:(int8_t)Field; + +@property (nonatomic, readonly) int8_t Field; + +@end diff --git a/test-suite/generated-src/objc/DBVarnameRecord.mm b/test-suite/generated-src/objc/DBVarnameRecord.mm new file mode 100644 index 000000000..4cd8f7244 --- /dev/null +++ b/test-suite/generated-src/objc/DBVarnameRecord.mm @@ -0,0 +1,27 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from varnames.djinni + +#import "DBVarnameRecord.h" + + +@implementation DBVarnameRecord + +- (nonnull instancetype)initWithField:(int8_t)Field +{ + if (self = [super init]) { + _Field = Field; + } + return self; +} + ++ (nonnull instancetype)VarnameRecordWithField:(int8_t)Field +{ + return [[self alloc] initWithField:Field]; +} + +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@ %p Field:%@>", self.class, (void *)self, @(self.Field)]; +} + +@end diff --git a/test-suite/generated-src/objc/DBWcharTestHelpers+Private.mm b/test-suite/generated-src/objc/DBWcharTestHelpers+Private.mm index 7d9dc594f..36936a5af 100644 --- a/test-suite/generated-src/objc/DBWcharTestHelpers+Private.mm +++ b/test-suite/generated-src/objc/DBWcharTestHelpers+Private.mm @@ -33,29 +33,29 @@ - (id)initWithCpp:(const std::shared_ptr<::testsuite::WcharTestHelpers>&)cppRef + (nonnull DBWcharTestRec *)getRecord { try { - auto r = ::testsuite::WcharTestHelpers::get_record(); - return ::djinni_generated::WcharTestRec::fromCpp(r); + auto objcpp_result_ = ::testsuite::WcharTestHelpers::get_record(); + return ::djinni_generated::WcharTestRec::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (nonnull NSString *)getString { try { - auto r = ::testsuite::WcharTestHelpers::get_string(); - return ::djinni::WString::fromCpp(r); + auto objcpp_result_ = ::testsuite::WcharTestHelpers::get_string(); + return ::djinni::WString::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (BOOL)checkString:(nonnull NSString *)str { try { - auto r = ::testsuite::WcharTestHelpers::check_string(::djinni::WString::toCpp(str)); - return ::djinni::Bool::fromCpp(r); + auto objcpp_result_ = ::testsuite::WcharTestHelpers::check_string(::djinni::WString::toCpp(str)); + return ::djinni::Bool::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } + (BOOL)checkRecord:(nonnull DBWcharTestRec *)rec { try { - auto r = ::testsuite::WcharTestHelpers::check_record(::djinni_generated::WcharTestRec::toCpp(rec)); - return ::djinni::Bool::fromCpp(r); + auto objcpp_result_ = ::testsuite::WcharTestHelpers::check_record(::djinni_generated::WcharTestRec::toCpp(rec)); + return ::djinni::Bool::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/test-suite/generated-src/outFileList.txt b/test-suite/generated-src/outFileList.txt index b14ab5afc..3f28125dc 100644 --- a/test-suite/generated-src/outFileList.txt +++ b/test-suite/generated-src/outFileList.txt @@ -4,6 +4,8 @@ djinni-output-temp/cpp/record_with_duration_and_derivings.cpp djinni-output-temp/cpp/date_record.hpp djinni-output-temp/cpp/date_record.cpp djinni-output-temp/cpp/map_date_record.hpp +djinni-output-temp/cpp/_varname_record_.hpp +djinni-output-temp/cpp/_varname_interface_.hpp djinni-output-temp/cpp/extended_record_base.hpp djinni-output-temp/cpp/extended_record_base.cpp djinni-output-temp/cpp/objc_only_listener.hpp @@ -46,6 +48,8 @@ djinni-output-temp/java/TestDuration.java djinni-output-temp/java/RecordWithDurationAndDerivings.java djinni-output-temp/java/DateRecord.java djinni-output-temp/java/MapDateRecord.java +djinni-output-temp/java/VarnameRecord.java +djinni-output-temp/java/VarnameInterface.java djinni-output-temp/java/ExtendedRecord.java djinni-output-temp/java/ObjcOnlyListener.java djinni-output-temp/java/JavaOnlyListener.java @@ -86,6 +90,10 @@ djinni-output-temp/jni/NativeDateRecord.hpp djinni-output-temp/jni/NativeDateRecord.cpp djinni-output-temp/jni/NativeMapDateRecord.hpp djinni-output-temp/jni/NativeMapDateRecord.cpp +djinni-output-temp/jni/NativeVarnameRecord.hpp +djinni-output-temp/jni/NativeVarnameRecord.cpp +djinni-output-temp/jni/NativeVarnameInterface.hpp +djinni-output-temp/jni/NativeVarnameInterface.cpp djinni-output-temp/jni/NativeExtendedRecord.hpp djinni-output-temp/jni/NativeExtendedRecord.cpp djinni-output-temp/jni/NativeObjcOnlyListener.hpp @@ -156,6 +164,9 @@ djinni-output-temp/objc/DBDateRecord.h djinni-output-temp/objc/DBDateRecord.mm djinni-output-temp/objc/DBMapDateRecord.h djinni-output-temp/objc/DBMapDateRecord.mm +djinni-output-temp/objc/DBVarnameRecord.h +djinni-output-temp/objc/DBVarnameRecord.mm +djinni-output-temp/objc/DBVarnameInterface.h djinni-output-temp/objc/DBExtendedRecord.h djinni-output-temp/objc/DBExtendedRecord.mm djinni-output-temp/objc/DBObjcOnlyListener.h @@ -211,6 +222,10 @@ djinni-output-temp/objc/DBDateRecord+Private.h djinni-output-temp/objc/DBDateRecord+Private.mm djinni-output-temp/objc/DBMapDateRecord+Private.h djinni-output-temp/objc/DBMapDateRecord+Private.mm +djinni-output-temp/objc/DBVarnameRecord+Private.h +djinni-output-temp/objc/DBVarnameRecord+Private.mm +djinni-output-temp/objc/DBVarnameInterface+Private.h +djinni-output-temp/objc/DBVarnameInterface+Private.mm djinni-output-temp/objc/DBExtendedRecord+Private.h djinni-output-temp/objc/DBExtendedRecord+Private.mm djinni-output-temp/objc/DBObjcOnlyListener+Private.h diff --git a/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj b/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj index 1d31c7064..d4e54ea11 100644 --- a/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj +++ b/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj @@ -67,6 +67,9 @@ B5153F9A1D54284100012654 /* DBJavaOnlyListener+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5153F971D54284100012654 /* DBJavaOnlyListener+Private.mm */; }; B51911181D542A7000772DFE /* DBWcharTestHelpers+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B51911151D542A7000772DFE /* DBWcharTestHelpers+Private.mm */; }; B519111B1D542B0700772DFE /* wchar_test_helpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B519111A1D542B0700772DFE /* wchar_test_helpers.cpp */; }; + B51911501D555EE900772DFE /* DBVarnameRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B51911491D555EE900772DFE /* DBVarnameRecord+Private.mm */; }; + B51911511D555EE900772DFE /* DBVarnameRecord.mm in Sources */ = {isa = PBXBuildFile; fileRef = B519114B1D555EE900772DFE /* DBVarnameRecord.mm */; }; + B51911521D555EE900772DFE /* DBVarnameInterface+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B519114D1D555EE900772DFE /* DBVarnameInterface+Private.mm */; }; B52DA5681B103F72005CE75F /* DBAssortedPrimitives.mm in Sources */ = {isa = PBXBuildFile; fileRef = B52DA5651B103F6D005CE75F /* DBAssortedPrimitives.mm */; }; B52DA5691B103F72005CE75F /* DBAssortedPrimitives.mm in Sources */ = {isa = PBXBuildFile; fileRef = B52DA5651B103F6D005CE75F /* DBAssortedPrimitives.mm */; }; B52DA56A1B103F75005CE75F /* DBAssortedPrimitives+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B52DA5671B103F6D005CE75F /* DBAssortedPrimitives+Private.mm */; }; @@ -290,6 +293,15 @@ B51911171D542A7000772DFE /* DBWcharTestHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBWcharTestHelpers.h; sourceTree = ""; }; B51911191D542AEC00772DFE /* wchar_test_helpers.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = wchar_test_helpers.hpp; sourceTree = ""; }; B519111A1D542B0700772DFE /* wchar_test_helpers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wchar_test_helpers.cpp; sourceTree = ""; }; + B51911471D555EDC00772DFE /* _varname_record_.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = _varname_record_.hpp; sourceTree = ""; }; + B51911481D555EDC00772DFE /* _varname_interface_.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = _varname_interface_.hpp; sourceTree = ""; }; + B51911491D555EE900772DFE /* DBVarnameRecord+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBVarnameRecord+Private.mm"; sourceTree = ""; }; + B519114A1D555EE900772DFE /* DBVarnameRecord+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBVarnameRecord+Private.h"; sourceTree = ""; }; + B519114B1D555EE900772DFE /* DBVarnameRecord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBVarnameRecord.mm; sourceTree = ""; }; + B519114C1D555EE900772DFE /* DBVarnameRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBVarnameRecord.h; sourceTree = ""; }; + B519114D1D555EE900772DFE /* DBVarnameInterface+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBVarnameInterface+Private.mm"; sourceTree = ""; }; + B519114E1D555EE900772DFE /* DBVarnameInterface+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBVarnameInterface+Private.h"; sourceTree = ""; }; + B519114F1D555EE900772DFE /* DBVarnameInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBVarnameInterface.h; sourceTree = ""; }; B52DA5641B103F6D005CE75F /* DBAssortedPrimitives.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DBAssortedPrimitives.h; sourceTree = ""; }; B52DA5651B103F6D005CE75F /* DBAssortedPrimitives.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DBAssortedPrimitives.mm; sourceTree = ""; }; B52DA5661B103F6D005CE75F /* DBAssortedPrimitives+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "DBAssortedPrimitives+Private.h"; sourceTree = ""; }; @@ -518,6 +530,13 @@ A24249181AF192E0003BF8F0 /* generated-objc */ = { isa = PBXGroup; children = ( + B51911491D555EE900772DFE /* DBVarnameRecord+Private.mm */, + B519114A1D555EE900772DFE /* DBVarnameRecord+Private.h */, + B519114B1D555EE900772DFE /* DBVarnameRecord.mm */, + B519114C1D555EE900772DFE /* DBVarnameRecord.h */, + B519114D1D555EE900772DFE /* DBVarnameInterface+Private.mm */, + B519114E1D555EE900772DFE /* DBVarnameInterface+Private.h */, + B519114F1D555EE900772DFE /* DBVarnameInterface.h */, B51911151D542A7000772DFE /* DBWcharTestHelpers+Private.mm */, B51911161D542A7000772DFE /* DBWcharTestHelpers+Private.h */, B51911171D542A7000772DFE /* DBWcharTestHelpers.h */, @@ -668,6 +687,8 @@ A242495D1AF192FC003BF8F0 /* generated-cpp */ = { isa = PBXGroup; children = ( + B51911471D555EDC00772DFE /* _varname_record_.hpp */, + B51911481D555EDC00772DFE /* _varname_interface_.hpp */, B51911191D542AEC00772DFE /* wchar_test_helpers.hpp */, B5153F871D54282C00012654 /* wchar_test_rec.hpp */, B5F06A9B1D4987C7005BE736 /* enum_usage_interface.hpp */, @@ -819,6 +840,7 @@ A24850291AF96EBC00AFE907 /* DBDateRecord.mm in Sources */, A278D45319BA3601006FD937 /* test_helpers.cpp in Sources */, 6551684C1C4050A4003682A4 /* DBReturnOne+Private.mm in Sources */, + B51911501D555EE900772DFE /* DBVarnameRecord+Private.mm in Sources */, B5F06AA51D4987EF005BE736 /* DBEnumUsageInterface+Private.mm in Sources */, CFFD588D1B019E79001E10B6 /* DBCppException+Private.mm in Sources */, A238CA921AF84B7100CDDCE5 /* DBDateRecord+Private.mm in Sources */, @@ -832,6 +854,7 @@ B52DA56E1B103FC5005CE75F /* assorted_primitives.cpp in Sources */, CFFD58B31B041BD9001E10B6 /* DBConstantsInterface+Private.mm in Sources */, CFC5D9FC1B152E4300BF2DF8 /* TranslateDuration.cpp in Sources */, + B51911511D555EE900772DFE /* DBVarnameRecord.mm in Sources */, A248502F1AF96EBC00AFE907 /* DBRecordWithDerivings.mm in Sources */, B5F06A851D4973BD005BE736 /* DBConflict+Private.mm in Sources */, A24249741AF192FC003BF8F0 /* constants.cpp in Sources */, @@ -865,6 +888,7 @@ CFC5D9D01B15105100BF2DF8 /* extern_record_with_derivings.cpp in Sources */, B51911181D542A7000772DFE /* DBWcharTestHelpers+Private.mm in Sources */, A238CA901AF84B7100CDDCE5 /* DBConstants+Private.mm in Sources */, + B51911521D555EE900772DFE /* DBVarnameInterface+Private.mm in Sources */, CFC5D9EA1B1513E800BF2DF8 /* DBExternInterface2+Private.mm in Sources */, CFC5DA011B15318B00BF2DF8 /* DBTestDuration+Private.mm in Sources */, 650CA05E1C2AB5AB007ADDDB /* ListenerCaller.cpp in Sources */, From fa3a568e4a855dbe97c4d5ec46d72c32c28e5f15 Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Fri, 5 Aug 2016 17:27:53 -0700 Subject: [PATCH 28/39] Tweak new test case --- test-suite/djinni/varnames.djinni | 4 ++-- .../generated-src/cpp/_varname_interface_.hpp | 4 ++-- .../dropbox/djinni/test/VarnameInterface.java | 16 ++++++++-------- .../generated-src/jni/NativeVarnameInterface.cpp | 8 ++++---- .../objc/DBVarnameInterface+Private.mm | 8 ++++---- .../generated-src/objc/DBVarnameInterface.h | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/test-suite/djinni/varnames.djinni b/test-suite/djinni/varnames.djinni index 6d1f3e3e7..5b3e5e567 100644 --- a/test-suite/djinni/varnames.djinni +++ b/test-suite/djinni/varnames.djinni @@ -6,6 +6,6 @@ _varname_record_ = record { } _varname_interface_ = interface +c { - _rmethod_(r: _varname_record_): _varname_record_; - _imethod_(i: _varname_interface_): _varname_interface_; + _rmethod_(_r_arg_: _varname_record_): _varname_record_; + _imethod_(_i_arg_: _varname_interface_): _varname_interface_; } diff --git a/test-suite/generated-src/cpp/_varname_interface_.hpp b/test-suite/generated-src/cpp/_varname_interface_.hpp index 4a3fd4ef3..dddbfffad 100644 --- a/test-suite/generated-src/cpp/_varname_interface_.hpp +++ b/test-suite/generated-src/cpp/_varname_interface_.hpp @@ -13,9 +13,9 @@ class VarnameInterface { public: virtual ~VarnameInterface() {} - virtual VarnameRecord _rmethod_(const VarnameRecord & r) = 0; + virtual VarnameRecord _rmethod_(const VarnameRecord & _r_arg_) = 0; - virtual std::shared_ptr _imethod_(const std::shared_ptr & i) = 0; + virtual std::shared_ptr _imethod_(const std::shared_ptr & _i_arg_) = 0; }; } // namespace testsuite diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameInterface.java index 826b4265e..57b016f5d 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameInterface.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameInterface.java @@ -9,10 +9,10 @@ public abstract class VarnameInterface { @Nonnull - public abstract VarnameRecord Rmethod(@Nonnull VarnameRecord r); + public abstract VarnameRecord Rmethod(@Nonnull VarnameRecord RArg); @CheckForNull - public abstract VarnameInterface Imethod(@CheckForNull VarnameInterface i); + public abstract VarnameInterface Imethod(@CheckForNull VarnameInterface IArg); private static final class CppProxy extends VarnameInterface { @@ -38,19 +38,19 @@ protected void finalize() throws java.lang.Throwable } @Override - public VarnameRecord Rmethod(VarnameRecord r) + public VarnameRecord Rmethod(VarnameRecord RArg) { assert !this.destroyed.get() : "trying to use a destroyed object"; - return native_Rmethod(this.nativeRef, r); + return native_Rmethod(this.nativeRef, RArg); } - private native VarnameRecord native_Rmethod(long _nativeRef, VarnameRecord r); + private native VarnameRecord native_Rmethod(long _nativeRef, VarnameRecord RArg); @Override - public VarnameInterface Imethod(VarnameInterface i) + public VarnameInterface Imethod(VarnameInterface IArg) { assert !this.destroyed.get() : "trying to use a destroyed object"; - return native_Imethod(this.nativeRef, i); + return native_Imethod(this.nativeRef, IArg); } - private native VarnameInterface native_Imethod(long _nativeRef, VarnameInterface i); + private native VarnameInterface native_Imethod(long _nativeRef, VarnameInterface IArg); } } diff --git a/test-suite/generated-src/jni/NativeVarnameInterface.cpp b/test-suite/generated-src/jni/NativeVarnameInterface.cpp index 4e85cb678..ff5eb5038 100644 --- a/test-suite/generated-src/jni/NativeVarnameInterface.cpp +++ b/test-suite/generated-src/jni/NativeVarnameInterface.cpp @@ -19,22 +19,22 @@ CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_VarnameInterface_00024CppPr } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, ) } -CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_VarnameInterface_00024CppProxy_native_1Rmethod(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_r) +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_VarnameInterface_00024CppProxy_native_1Rmethod(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_RArg) { try { DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::VarnameInterface>(nativeRef); - auto r = ref->_rmethod_(::djinni_generated::NativeVarnameRecord::toCpp(jniEnv, j_r)); + auto r = ref->_rmethod_(::djinni_generated::NativeVarnameRecord::toCpp(jniEnv, j_RArg)); return ::djinni::release(::djinni_generated::NativeVarnameRecord::fromCpp(jniEnv, r)); } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) } -CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_VarnameInterface_00024CppProxy_native_1Imethod(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_i) +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_VarnameInterface_00024CppProxy_native_1Imethod(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_IArg) { try { DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::VarnameInterface>(nativeRef); - auto r = ref->_imethod_(::djinni_generated::NativeVarnameInterface::toCpp(jniEnv, j_i)); + auto r = ref->_imethod_(::djinni_generated::NativeVarnameInterface::toCpp(jniEnv, j_IArg)); return ::djinni::release(::djinni_generated::NativeVarnameInterface::fromCpp(jniEnv, r)); } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) } diff --git a/test-suite/generated-src/objc/DBVarnameInterface+Private.mm b/test-suite/generated-src/objc/DBVarnameInterface+Private.mm index fd3d78307..fca3a07d1 100644 --- a/test-suite/generated-src/objc/DBVarnameInterface+Private.mm +++ b/test-suite/generated-src/objc/DBVarnameInterface+Private.mm @@ -30,16 +30,16 @@ - (id)initWithCpp:(const std::shared_ptr<::testsuite::VarnameInterface>&)cppRef return self; } -- (nonnull DBVarnameRecord *)Rmethod:(nonnull DBVarnameRecord *)r { +- (nonnull DBVarnameRecord *)Rmethod:(nonnull DBVarnameRecord *)RArg { try { - auto objcpp_result_ = _cppRefHandle.get()->_rmethod_(::djinni_generated::VarnameRecord::toCpp(r)); + auto objcpp_result_ = _cppRefHandle.get()->_rmethod_(::djinni_generated::VarnameRecord::toCpp(RArg)); return ::djinni_generated::VarnameRecord::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } -- (nullable DBVarnameInterface *)Imethod:(nullable DBVarnameInterface *)i { +- (nullable DBVarnameInterface *)Imethod:(nullable DBVarnameInterface *)IArg { try { - auto objcpp_result_ = _cppRefHandle.get()->_imethod_(::djinni_generated::VarnameInterface::toCpp(i)); + auto objcpp_result_ = _cppRefHandle.get()->_imethod_(::djinni_generated::VarnameInterface::toCpp(IArg)); return ::djinni_generated::VarnameInterface::fromCpp(objcpp_result_); } DJINNI_TRANSLATE_EXCEPTIONS() } diff --git a/test-suite/generated-src/objc/DBVarnameInterface.h b/test-suite/generated-src/objc/DBVarnameInterface.h index 45df732cd..ec27c0279 100644 --- a/test-suite/generated-src/objc/DBVarnameInterface.h +++ b/test-suite/generated-src/objc/DBVarnameInterface.h @@ -8,8 +8,8 @@ @interface DBVarnameInterface : NSObject -- (nonnull DBVarnameRecord *)Rmethod:(nonnull DBVarnameRecord *)r; +- (nonnull DBVarnameRecord *)Rmethod:(nonnull DBVarnameRecord *)RArg; -- (nullable DBVarnameInterface *)Imethod:(nullable DBVarnameInterface *)i; +- (nullable DBVarnameInterface *)Imethod:(nullable DBVarnameInterface *)IArg; @end From fd141ea68f1f7ddbf55e5fc0705eae0856037f4c Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Fri, 5 Aug 2016 18:38:32 -0700 Subject: [PATCH 29/39] Missed case from "r" variable fix --- src/source/ObjcppGenerator.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/source/ObjcppGenerator.scala b/src/source/ObjcppGenerator.scala index 57e47dcc0..ab0263f5d 100644 --- a/src/source/ObjcppGenerator.scala +++ b/src/source/ObjcppGenerator.scala @@ -229,7 +229,7 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) { writeObjcFuncDecl(m, new IndentWriter(stringWriter)) val singleLineFunctionDecl = stringWriter.toString.replaceAll("\n *", " ") val exceptionReason = s"Got unexpected null return value from function $objcSelf $singleLineFunctionDecl" - w.w(s"if (r == nil)").braced { + w.w(s"if (objcpp_result_ == nil)").braced { w.wl(s"""throw std::invalid_argument("$exceptionReason");""") } } From 6c9fc367b8ddfe563c03602d2e2749fac4d8ca44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20von=20Franqu=C3=A9?= Date: Thu, 28 Jul 2016 09:55:55 +0200 Subject: [PATCH 30/39] Added --java-class-access-modifier command line option --- src/source/JavaGenerator.scala | 9 +++++---- src/source/Main.scala | 4 ++++ src/source/generator.scala | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/source/JavaGenerator.scala b/src/source/JavaGenerator.scala index 6a51c58f4..fe4a12b8b 100644 --- a/src/source/JavaGenerator.scala +++ b/src/source/JavaGenerator.scala @@ -29,6 +29,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { val javaAnnotationHeader = spec.javaAnnotation.map(pkg => '@' + pkg.split("\\.").last) val javaNullableAnnotation = spec.javaNullableAnnotation.map(pkg => '@' + pkg.split("\\.").last) val javaNonnullAnnotation = spec.javaNonnullAnnotation.map(pkg => '@' + pkg.split("\\.").last) + val javaClassAccessModifierString = JavaAccessModifier.getCodeGenerationString(spec.javaClassAccessModifier) val marshal = new JavaMarshal(spec) class JavaRefs() { @@ -109,7 +110,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { writeJavaFile(ident, origin, refs.java, w => { writeDoc(w, doc) javaAnnotationHeader.foreach(w.wl) - w.w(s"public enum ${marshal.typename(ident, e)}").braced { + w.w(s"${javaClassAccessModifierString}enum ${marshal.typename(ident, e)}").braced { for (o <- e.options) { writeDoc(w, o.doc) w.wl(idJava.enum(o.ident) + ",") @@ -139,7 +140,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { writeDoc(w, doc) javaAnnotationHeader.foreach(w.wl) - w.w(s"public abstract class $javaClass$typeParamList").braced { + w.w(s"${javaClassAccessModifierString}abstract class $javaClass$typeParamList").braced { val skipFirst = SkipFirst() generateJavaConstants(w, i.consts) @@ -212,7 +213,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { r.fields.foreach(f => refs.find(f.ty)) val javaName = if (r.ext.java) (ident.name + "_base") else ident.name - val javaFinal = if (!r.ext.java && spec.javaUseFinalForRecord) " final" else "" + val javaFinal = if (!r.ext.java && spec.javaUseFinalForRecord) "final" else "" writeJavaFile(javaName, origin, refs.java, w => { writeDoc(w, doc) @@ -225,7 +226,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { } else { "" } - w.w(s"public$javaFinal class ${self + javaTypeParams(params)}$comparableFlag").braced { + w.w(s"${javaClassAccessModifierString}$javaFinal class ${self + javaTypeParams(params)}$comparableFlag").braced { w.wl generateJavaConstants(w, r.consts) // Field definitions. diff --git a/src/source/Main.scala b/src/source/Main.scala index 9b136caa9..a05ec9811 100644 --- a/src/source/Main.scala +++ b/src/source/Main.scala @@ -38,6 +38,7 @@ object Main { var cppUseWideStrings: Boolean = false var javaOutFolder: Option[File] = None var javaPackage: Option[String] = None + var javaClassAccessModifier: JavaAccessModifier.Value = JavaAccessModifier.Public var javaCppException: Option[String] = None var javaAnnotation: Option[String] = None var javaNullableAnnotation: Option[String] = None @@ -99,6 +100,8 @@ object Main { .text("The output for the Java files (Generator disabled if unspecified).") opt[String]("java-package").valueName("...").foreach(x => javaPackage = Some(x)) .text("The package name to use for generated Java classes.") + opt[JavaAccessModifier.Value]("java-class-access-modifier").valueName("").foreach(x => javaClassAccessModifier = x) + .text("The access modifier to use for generated Java classes (default: public).") opt[String]("java-cpp-exception").valueName("").foreach(x => javaCppException = Some(x)) .text("The type for translated C++ exceptions in Java (default: java.lang.RuntimeException that is not checked)") opt[String]("java-annotation").valueName("").foreach(x => javaAnnotation = Some(x)) @@ -277,6 +280,7 @@ object Main { val outSpec = Spec( javaOutFolder, javaPackage, + javaClassAccessModifier, javaIdentStyle, javaCppException, javaAnnotation, diff --git a/src/source/generator.scala b/src/source/generator.scala index d3e726636..49725c730 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -30,6 +30,7 @@ package object generatorTools { case class Spec( javaOutFolder: Option[File], javaPackage: Option[String], + javaClassAccessModifier: JavaAccessModifier.Value, javaIdentStyle: JavaIdentStyle, javaCppException: Option[String], javaAnnotation: Option[String], @@ -138,6 +139,22 @@ package object generatorTools { } } + object JavaAccessModifier extends Enumeration { + val Public = Value("public") + val Protected = Value("protected") + val Package = Value("package") + + def getCodeGenerationString(javaAccessModifier: JavaAccessModifier.Value): String = { + javaAccessModifier match { + case Public => "public " + case Protected => "protected " + case Package => "" + } + } + + } + implicit val javaAccessModifierReads: scopt.Read[JavaAccessModifier.Value] = scopt.Read.reads(JavaAccessModifier withName _) + final case class SkipFirst() { private var first = true From fb00ce1c990593026332a0df033d06da6d27cbc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20von=20Franqu=C3=A9?= Date: Mon, 8 Aug 2016 12:27:56 +0200 Subject: [PATCH 31/39] Removed 'protected' from valid java class access modifiers --- src/source/JavaGenerator.scala | 4 ++-- src/source/Main.scala | 2 +- src/source/generator.scala | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/source/JavaGenerator.scala b/src/source/JavaGenerator.scala index fe4a12b8b..d97299a63 100644 --- a/src/source/JavaGenerator.scala +++ b/src/source/JavaGenerator.scala @@ -213,7 +213,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { r.fields.foreach(f => refs.find(f.ty)) val javaName = if (r.ext.java) (ident.name + "_base") else ident.name - val javaFinal = if (!r.ext.java && spec.javaUseFinalForRecord) "final" else "" + val javaFinal = if (!r.ext.java && spec.javaUseFinalForRecord) "final " else "" writeJavaFile(javaName, origin, refs.java, w => { writeDoc(w, doc) @@ -226,7 +226,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { } else { "" } - w.w(s"${javaClassAccessModifierString}$javaFinal class ${self + javaTypeParams(params)}$comparableFlag").braced { + w.w(s"${javaClassAccessModifierString}${javaFinal}class ${self + javaTypeParams(params)}$comparableFlag").braced { w.wl generateJavaConstants(w, r.consts) // Field definitions. diff --git a/src/source/Main.scala b/src/source/Main.scala index a05ec9811..8932bb7a4 100644 --- a/src/source/Main.scala +++ b/src/source/Main.scala @@ -100,7 +100,7 @@ object Main { .text("The output for the Java files (Generator disabled if unspecified).") opt[String]("java-package").valueName("...").foreach(x => javaPackage = Some(x)) .text("The package name to use for generated Java classes.") - opt[JavaAccessModifier.Value]("java-class-access-modifier").valueName("").foreach(x => javaClassAccessModifier = x) + opt[JavaAccessModifier.Value]("java-class-access-modifier").valueName("").foreach(x => javaClassAccessModifier = x) .text("The access modifier to use for generated Java classes (default: public).") opt[String]("java-cpp-exception").valueName("").foreach(x => javaCppException = Some(x)) .text("The type for translated C++ exceptions in Java (default: java.lang.RuntimeException that is not checked)") diff --git a/src/source/generator.scala b/src/source/generator.scala index 49725c730..b14564076 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -141,14 +141,12 @@ package object generatorTools { object JavaAccessModifier extends Enumeration { val Public = Value("public") - val Protected = Value("protected") val Package = Value("package") def getCodeGenerationString(javaAccessModifier: JavaAccessModifier.Value): String = { javaAccessModifier match { case Public => "public " - case Protected => "protected " - case Package => "" + case Package => "/*package*/ " } } From b1a71fd34e1c1af2107cf32070fc86dfacb9b3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20von=20Franqu=C3=A9?= Date: Mon, 8 Aug 2016 15:44:25 +0200 Subject: [PATCH 32/39] Updated sample to use non-default java class access modifier --- example/generated-src/java/com/dropbox/textsort/ItemList.java | 2 +- example/generated-src/java/com/dropbox/textsort/SortItems.java | 2 +- example/generated-src/java/com/dropbox/textsort/SortOrder.java | 2 +- .../java/com/dropbox/textsort/TextboxListener.java | 2 +- example/run_djinni.sh | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/example/generated-src/java/com/dropbox/textsort/ItemList.java b/example/generated-src/java/com/dropbox/textsort/ItemList.java index 41aa543eb..900eaa377 100644 --- a/example/generated-src/java/com/dropbox/textsort/ItemList.java +++ b/example/generated-src/java/com/dropbox/textsort/ItemList.java @@ -7,7 +7,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public final class ItemList { +/*package*/ final class ItemList { /*package*/ final ArrayList mItems; diff --git a/example/generated-src/java/com/dropbox/textsort/SortItems.java b/example/generated-src/java/com/dropbox/textsort/SortItems.java index 51de474ee..beeef710c 100644 --- a/example/generated-src/java/com/dropbox/textsort/SortItems.java +++ b/example/generated-src/java/com/dropbox/textsort/SortItems.java @@ -7,7 +7,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public abstract class SortItems { +/*package*/ abstract class SortItems { /** For the iOS / Android demo */ public abstract void sort(@Nonnull SortOrder order, @Nonnull ItemList items); diff --git a/example/generated-src/java/com/dropbox/textsort/SortOrder.java b/example/generated-src/java/com/dropbox/textsort/SortOrder.java index 28ceb785e..906b9a171 100644 --- a/example/generated-src/java/com/dropbox/textsort/SortOrder.java +++ b/example/generated-src/java/com/dropbox/textsort/SortOrder.java @@ -6,7 +6,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public enum SortOrder { +/*package*/ enum SortOrder { ASCENDING, DESCENDING, RANDOM, diff --git a/example/generated-src/java/com/dropbox/textsort/TextboxListener.java b/example/generated-src/java/com/dropbox/textsort/TextboxListener.java index 231f15c08..d67afe271 100644 --- a/example/generated-src/java/com/dropbox/textsort/TextboxListener.java +++ b/example/generated-src/java/com/dropbox/textsort/TextboxListener.java @@ -6,6 +6,6 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -public abstract class TextboxListener { +/*package*/ abstract class TextboxListener { public abstract void update(@Nonnull ItemList items); } diff --git a/example/run_djinni.sh b/example/run_djinni.sh index 61a4e4b04..334d8beeb 100755 --- a/example/run_djinni.sh +++ b/example/run_djinni.sh @@ -53,6 +53,7 @@ fi "$base_dir/../src/run-assume-built" \ --java-out "$temp_out/java" \ --java-package $java_package \ + --java-class-access-modifier "package" \ --java-nullable-annotation "javax.annotation.CheckForNull" \ --java-nonnull-annotation "javax.annotation.Nonnull" \ --ident-java-field mFooBar \ From 53236b6cde0476a47b851429a55bf5e95edd2c30 Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Tue, 9 Aug 2016 15:28:27 -0700 Subject: [PATCH 33/39] Remove stray generated files from a cherry-pick. --- .../objc/TXSSortItems+Private.mm | 78 ----------------- .../objc/TXSTextboxListener+Private.mm | 48 ----------- .../generated-src/objc/DBClass1+Private.mm | 84 ------------------- .../objc/DBInnerClass+Private.mm | 49 ----------- .../generated-src/objc/DBClass2+Private.mm | 60 ------------- 5 files changed, 319 deletions(-) delete mode 100644 example-with-packages/textsort/generated-src/objc/TXSSortItems+Private.mm delete mode 100644 example-with-packages/textsort/generated-src/objc/TXSTextboxListener+Private.mm delete mode 100644 test-suite/djinni-packages/package1/generated-src/objc/DBClass1+Private.mm delete mode 100644 test-suite/djinni-packages/package1/generated-src/objc/DBInnerClass+Private.mm delete mode 100644 test-suite/djinni-packages/package2/generated-src/objc/DBClass2+Private.mm diff --git a/example-with-packages/textsort/generated-src/objc/TXSSortItems+Private.mm b/example-with-packages/textsort/generated-src/objc/TXSSortItems+Private.mm deleted file mode 100644 index a58450028..000000000 --- a/example-with-packages/textsort/generated-src/objc/TXSSortItems+Private.mm +++ /dev/null @@ -1,78 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file generated by Djinni from textsort.djinni - -#import "TXSSortItems+Private.h" -#import "TXSSortItems.h" -#import "DJICppWrapperCache+Private.h" -#import "DJIError.h" -#import "DJIMarshal+Private.h" -#import "TXSSortItems+Private.h" -#import "TXSTextboxListener+Private.h" -#import "collections/generated-src/objc/TXSItemList+Private.h" -#include -#include -#include - -static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); - -@interface TXSSortItems () - -- (id)initWithCpp:(const std::shared_ptr<::textsort::SortItems>&)cppRef; - -@end - -@implementation TXSSortItems { - ::djinni::CppProxyCache::Handle> _cppRefHandle; -} - -- (id)initWithCpp:(const std::shared_ptr<::textsort::SortItems>&)cppRef -{ - if (self = [super init]) { - _cppRefHandle.assign(cppRef); - } - return self; -} - -- (void)sort:(TXSSortOrder)order - items:(nonnull TXSItemList *)items { - try { - _cppRefHandle.get()->sort(::djinni::Enum<::textsort::sort_order, TXSSortOrder>::toCpp(order), - ::djinni_generated::ItemList::toCpp(items)); - } DJINNI_TRANSLATE_EXCEPTIONS() -} - -+ (nullable TXSSortItems *)createWithListener:(nullable id)listener { - try { - auto r = ::textsort::SortItems::create_with_listener(::djinni_generated::TextboxListener::toCpp(listener)); - return ::djinni_generated::SortItems::fromCpp(r); - } DJINNI_TRANSLATE_EXCEPTIONS() -} - -+ (nonnull TXSItemList *)runSort:(nonnull TXSItemList *)items { - try { - auto r = ::textsort::SortItems::run_sort(::djinni_generated::ItemList::toCpp(items)); - return ::djinni_generated::ItemList::fromCpp(r); - } DJINNI_TRANSLATE_EXCEPTIONS() -} - -namespace djinni_generated { - -auto SortItems::toCpp(ObjcType objc) -> CppType -{ - if (!objc) { - return nullptr; - } - return objc->_cppRefHandle.get(); -} - -auto SortItems::fromCppOpt(const CppOptType& cpp) -> ObjcType -{ - if (!cpp) { - return nil; - } - return ::djinni::get_cpp_proxy(cpp); -} - -} // namespace djinni_generated - -@end diff --git a/example-with-packages/textsort/generated-src/objc/TXSTextboxListener+Private.mm b/example-with-packages/textsort/generated-src/objc/TXSTextboxListener+Private.mm deleted file mode 100644 index 3d5c06c96..000000000 --- a/example-with-packages/textsort/generated-src/objc/TXSTextboxListener+Private.mm +++ /dev/null @@ -1,48 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file generated by Djinni from textsort.djinni - -#import "TXSTextboxListener+Private.h" -#import "TXSTextboxListener.h" -#import "DJIObjcWrapperCache+Private.h" -#import "collections/generated-src/objc/TXSItemList+Private.h" -#include - -static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); - -namespace djinni_generated { - -class TextboxListener::ObjcProxy final -: public ::textsort::TextboxListener -, public ::djinni::ObjcProxyCache::Handle -{ -public: - using Handle::Handle; - void update(const ::collections::ItemList & c_items) override - { - @autoreleasepool { - [Handle::get() update:(::djinni_generated::ItemList::fromCpp(c_items))]; - } - } -}; - -} // namespace djinni_generated - -namespace djinni_generated { - -auto TextboxListener::toCpp(ObjcType objc) -> CppType -{ - if (!objc) { - return nullptr; - } - return ::djinni::get_objc_proxy(objc); -} - -auto TextboxListener::fromCppOpt(const CppOptType& cpp) -> ObjcType -{ - if (!cpp) { - return nil; - } - return dynamic_cast(*cpp).Handle::get(); -} - -} // namespace djinni_generated diff --git a/test-suite/djinni-packages/package1/generated-src/objc/DBClass1+Private.mm b/test-suite/djinni-packages/package1/generated-src/objc/DBClass1+Private.mm deleted file mode 100644 index 5c93d591a..000000000 --- a/test-suite/djinni-packages/package1/generated-src/objc/DBClass1+Private.mm +++ /dev/null @@ -1,84 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file generated by Djinni from class1.djinni - -#import "DBClass1+Private.h" -#import "DBClass1.h" -#import "DBClass1+Private.h" -#import "DBInnerClass+Private.h" -#import "DJICppWrapperCache+Private.h" -#import "DJIError.h" -#import "DJIMarshal+Private.h" -#import "djinni-packages/package2/generated-src/objc/DBClass2+Private.h" -#include -#include -#include - -static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); - -@interface DBClass1 () - -- (id)initWithCpp:(const std::shared_ptr<::package1::Class1>&)cppRef; - -@end - -@implementation DBClass1 { - ::djinni::CppProxyCache::Handle> _cppRefHandle; -} - -- (id)initWithCpp:(const std::shared_ptr<::package1::Class1>&)cppRef -{ - if (self = [super init]) { - _cppRefHandle.assign(cppRef); - } - return self; -} - -- (nonnull NSString *)getName { - try { - auto r = _cppRefHandle.get()->get_name(); - return ::djinni::String::fromCpp(r); - } DJINNI_TRANSLATE_EXCEPTIONS() -} - -- (nonnull NSString *)getInnerClassName { - try { - auto r = _cppRefHandle.get()->get_inner_class_name(); - return ::djinni::String::fromCpp(r); - } DJINNI_TRANSLATE_EXCEPTIONS() -} - -- (nullable DBClass2 *)getClass2 { - try { - auto r = _cppRefHandle.get()->get_class2(); - return ::djinni_generated::Class2::fromCpp(r); - } DJINNI_TRANSLATE_EXCEPTIONS() -} - -+ (nullable DBClass1 *)createWithInnerClass:(nullable id)innerClass { - try { - auto r = ::package1::Class1::create_with_inner_class(::djinni_generated::InnerClass::toCpp(innerClass)); - return ::djinni_generated::Class1::fromCpp(r); - } DJINNI_TRANSLATE_EXCEPTIONS() -} - -namespace djinni_generated { - -auto Class1::toCpp(ObjcType objc) -> CppType -{ - if (!objc) { - return nullptr; - } - return objc->_cppRefHandle.get(); -} - -auto Class1::fromCppOpt(const CppOptType& cpp) -> ObjcType -{ - if (!cpp) { - return nil; - } - return ::djinni::get_cpp_proxy(cpp); -} - -} // namespace djinni_generated - -@end diff --git a/test-suite/djinni-packages/package1/generated-src/objc/DBInnerClass+Private.mm b/test-suite/djinni-packages/package1/generated-src/objc/DBInnerClass+Private.mm deleted file mode 100644 index 16d8b3132..000000000 --- a/test-suite/djinni-packages/package1/generated-src/objc/DBInnerClass+Private.mm +++ /dev/null @@ -1,49 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file generated by Djinni from inner_class.djinni - -#import "DBInnerClass+Private.h" -#import "DBInnerClass.h" -#import "DJIMarshal+Private.h" -#import "DJIObjcWrapperCache+Private.h" -#include - -static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); - -namespace djinni_generated { - -class InnerClass::ObjcProxy final -: public ::package1::InnerClass -, public ::djinni::ObjcProxyCache::Handle -{ -public: - using Handle::Handle; - std::string get_name() override - { - @autoreleasepool { - auto r = [Handle::get() getName]; - return ::djinni::String::toCpp(r); - } - } -}; - -} // namespace djinni_generated - -namespace djinni_generated { - -auto InnerClass::toCpp(ObjcType objc) -> CppType -{ - if (!objc) { - return nullptr; - } - return ::djinni::get_objc_proxy(objc); -} - -auto InnerClass::fromCppOpt(const CppOptType& cpp) -> ObjcType -{ - if (!cpp) { - return nil; - } - return dynamic_cast(*cpp).Handle::get(); -} - -} // namespace djinni_generated diff --git a/test-suite/djinni-packages/package2/generated-src/objc/DBClass2+Private.mm b/test-suite/djinni-packages/package2/generated-src/objc/DBClass2+Private.mm deleted file mode 100644 index 9fd132d5f..000000000 --- a/test-suite/djinni-packages/package2/generated-src/objc/DBClass2+Private.mm +++ /dev/null @@ -1,60 +0,0 @@ -// AUTOGENERATED FILE - DO NOT MODIFY! -// This file generated by Djinni from class2.djinni - -#import "DBClass2+Private.h" -#import "DBClass2.h" -#import "DJICppWrapperCache+Private.h" -#import "DJIError.h" -#import "DJIMarshal+Private.h" -#include -#include -#include - -static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); - -@interface DBClass2 () - -- (id)initWithCpp:(const std::shared_ptr<::package2::Class2>&)cppRef; - -@end - -@implementation DBClass2 { - ::djinni::CppProxyCache::Handle> _cppRefHandle; -} - -- (id)initWithCpp:(const std::shared_ptr<::package2::Class2>&)cppRef -{ - if (self = [super init]) { - _cppRefHandle.assign(cppRef); - } - return self; -} - -- (nonnull NSString *)getName { - try { - auto r = _cppRefHandle.get()->get_name(); - return ::djinni::String::fromCpp(r); - } DJINNI_TRANSLATE_EXCEPTIONS() -} - -namespace djinni_generated { - -auto Class2::toCpp(ObjcType objc) -> CppType -{ - if (!objc) { - return nullptr; - } - return objc->_cppRefHandle.get(); -} - -auto Class2::fromCppOpt(const CppOptType& cpp) -> ObjcType -{ - if (!cpp) { - return nil; - } - return ::djinni::get_cpp_proxy(cpp); -} - -} // namespace djinni_generated - -@end From 6c869e1f6ea7b2c48395268ee12f12015aa7d1d0 Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Tue, 9 Aug 2016 20:23:30 -0700 Subject: [PATCH 34/39] Fix use of extended record include prefix --- src/source/CppMarshal.scala | 23 ++++--- test-suite/djinni/extended_record.djinni | 13 +++- .../cpp/interface_using_extended_record.cpp | 14 ++++ .../cpp/interface_using_extended_record.hpp | 20 ++++++ .../cpp/record_using_extended_record.cpp | 12 ++++ .../cpp/record_using_extended_record.hpp | 21 ++++++ .../test/InterfaceUsingExtendedRecord.java | 50 ++++++++++++++ .../test/RecordUsingExtendedRecord.java | 36 ++++++++++ .../NativeInterfaceUsingExtendedRecord.cpp | 33 +++++++++ .../NativeInterfaceUsingExtendedRecord.hpp | 32 +++++++++ .../jni/NativeRecordUsingExtendedRecord.cpp | 28 ++++++++ .../jni/NativeRecordUsingExtendedRecord.hpp | 32 +++++++++ .../DBInterfaceUsingExtendedRecord+Private.h | 31 +++++++++ .../DBInterfaceUsingExtendedRecord+Private.mm | 68 +++++++++++++++++++ .../objc/DBInterfaceUsingExtendedRecord.h | 14 ++++ .../objc/DBInterfaceUsingExtendedRecord.mm | 5 ++ .../DBRecordUsingExtendedRecord+Private.h | 24 +++++++ .../DBRecordUsingExtendedRecord+Private.mm | 21 ++++++ .../objc/DBRecordUsingExtendedRecord.h | 16 +++++ .../objc/DBRecordUsingExtendedRecord.mm | 33 +++++++++ test-suite/generated-src/outFileList.txt | 18 +++++ .../handwritten-src/cpp/extended_record.cpp | 8 +-- .../DjinniObjcTest.xcodeproj/project.pbxproj | 36 ++++++++++ 23 files changed, 572 insertions(+), 16 deletions(-) create mode 100644 test-suite/generated-src/cpp/interface_using_extended_record.cpp create mode 100644 test-suite/generated-src/cpp/interface_using_extended_record.hpp create mode 100644 test-suite/generated-src/cpp/record_using_extended_record.cpp create mode 100644 test-suite/generated-src/cpp/record_using_extended_record.hpp create mode 100644 test-suite/generated-src/java/com/dropbox/djinni/test/InterfaceUsingExtendedRecord.java create mode 100644 test-suite/generated-src/java/com/dropbox/djinni/test/RecordUsingExtendedRecord.java create mode 100644 test-suite/generated-src/jni/NativeInterfaceUsingExtendedRecord.cpp create mode 100644 test-suite/generated-src/jni/NativeInterfaceUsingExtendedRecord.hpp create mode 100644 test-suite/generated-src/jni/NativeRecordUsingExtendedRecord.cpp create mode 100644 test-suite/generated-src/jni/NativeRecordUsingExtendedRecord.hpp create mode 100644 test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord+Private.h create mode 100644 test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord+Private.mm create mode 100644 test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord.h create mode 100644 test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord.mm create mode 100644 test-suite/generated-src/objc/DBRecordUsingExtendedRecord+Private.h create mode 100644 test-suite/generated-src/objc/DBRecordUsingExtendedRecord+Private.mm create mode 100644 test-suite/generated-src/objc/DBRecordUsingExtendedRecord.h create mode 100644 test-suite/generated-src/objc/DBRecordUsingExtendedRecord.mm diff --git a/src/source/CppMarshal.scala b/src/source/CppMarshal.scala index fd991fa2d..2279c00b5 100644 --- a/src/source/CppMarshal.scala +++ b/src/source/CppMarshal.scala @@ -59,18 +59,18 @@ class CppMarshal(spec: Spec) extends Marshal(spec) { case MList => List(ImportRef("")) case MSet => List(ImportRef("")) case MMap => List(ImportRef("")) - case d: MDef => d.defType match { - case DRecord => + case d: MDef => d.body match { + case r: Record => if (d.name != exclude) { if (forwardDeclareOnly) { List(DeclRef(s"struct ${typename(d.name, d.body)};", Some(spec.cppNamespace))) } else { - List(ImportRef(include(d.name))) + List(ImportRef(include(d.name, r.ext.cpp))) } } else { List() } - case DEnum => + case e: Enum => if (d.name != exclude) { if (forwardDeclareOnly) { List(DeclRef(s"enum class ${typename(d.name, d.body)};", Some(spec.cppNamespace))) @@ -80,7 +80,7 @@ class CppMarshal(spec: Spec) extends Marshal(spec) { } else { List() } - case DInterface => + case i: Interface => val base = if (d.name != exclude) { List(ImportRef(""), DeclRef(s"class ${typename(d.name, d.body)};", Some(spec.cppNamespace))) } else { @@ -106,14 +106,14 @@ class CppMarshal(spec: Spec) extends Marshal(spec) { List() } else { m match { - case d: MDef => d.defType match { - case DRecord => + case d: MDef => d.body match { + case r: Record => if (d.name != exclude) { - List(ImportRef(include(d.name))) + List(ImportRef(include(d.name, r.ext.cpp))) } else { List() } - case DEnum => + case e: Enum => if (d.name != exclude) { List(ImportRef(include(d.name))) } else { @@ -126,7 +126,10 @@ class CppMarshal(spec: Spec) extends Marshal(spec) { } } - def include(ident: String): String = q(spec.cppIncludePrefix + spec.cppFileIdentStyle(ident) + "." + spec.cppHeaderExt) + def include(ident: String, isExtendedRecord: Boolean = false): String = { + val prefix = if (isExtendedRecord) spec.cppExtendedRecordIncludePrefix else spec.cppIncludePrefix + q(prefix + spec.cppFileIdentStyle (ident) + "." + spec.cppHeaderExt) + } private def toCppType(ty: TypeRef, namespace: Option[String] = None, scopeSymbols: Seq[String] = Seq()): String = toCppType(ty.resolved, namespace, scopeSymbols) diff --git a/test-suite/djinni/extended_record.djinni b/test-suite/djinni/extended_record.djinni index 2647713a6..4ccd7b031 100644 --- a/test-suite/djinni/extended_record.djinni +++ b/test-suite/djinni/extended_record.djinni @@ -1,6 +1,15 @@ - # Extended record extended_record = record +c { foo: bool; - const extended_record_const: extended_record = {foo=true}; + const extended_record_const: extended_record = { foo = true }; +} + +record_using_extended_record = record { + er: extended_record; + const cr: record_using_extended_record = {er = { foo = false } }; +} + +interface_using_extended_record = interface +c { + meth(er: extended_record): extended_record; + const cr: record_using_extended_record = {er = { foo = false } }; } diff --git a/test-suite/generated-src/cpp/interface_using_extended_record.cpp b/test-suite/generated-src/cpp/interface_using_extended_record.cpp new file mode 100644 index 000000000..56d8bee71 --- /dev/null +++ b/test-suite/generated-src/cpp/interface_using_extended_record.cpp @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#include "interface_using_extended_record.hpp" // my header +#include "../../handwritten-src/cpp/extended_record.hpp" +#include "record_using_extended_record.hpp" + +namespace testsuite { + +RecordUsingExtendedRecord const InterfaceUsingExtendedRecord::CR = RecordUsingExtendedRecord( + ExtendedRecord( + false /* foo */ ) /* er */ ); + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/interface_using_extended_record.hpp b/test-suite/generated-src/cpp/interface_using_extended_record.hpp new file mode 100644 index 000000000..043d23ef2 --- /dev/null +++ b/test-suite/generated-src/cpp/interface_using_extended_record.hpp @@ -0,0 +1,20 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#pragma once + +namespace testsuite { + +struct ExtendedRecord; +struct RecordUsingExtendedRecord; + +class InterfaceUsingExtendedRecord { +public: + virtual ~InterfaceUsingExtendedRecord() {} + + static RecordUsingExtendedRecord const CR; + + virtual ExtendedRecord meth(const ExtendedRecord & er) = 0; +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/record_using_extended_record.cpp b/test-suite/generated-src/cpp/record_using_extended_record.cpp new file mode 100644 index 000000000..a1e8ea524 --- /dev/null +++ b/test-suite/generated-src/cpp/record_using_extended_record.cpp @@ -0,0 +1,12 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#include "record_using_extended_record.hpp" // my header + +namespace testsuite { + +RecordUsingExtendedRecord const RecordUsingExtendedRecord::CR = RecordUsingExtendedRecord( + ExtendedRecord( + false /* foo */ ) /* er */ ); + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/record_using_extended_record.hpp b/test-suite/generated-src/cpp/record_using_extended_record.hpp new file mode 100644 index 000000000..fb9b35ff4 --- /dev/null +++ b/test-suite/generated-src/cpp/record_using_extended_record.hpp @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#pragma once + +#include "../../handwritten-src/cpp/extended_record.hpp" +#include + +namespace testsuite { + +struct RecordUsingExtendedRecord final { + + static RecordUsingExtendedRecord const CR; + ExtendedRecord er; + + RecordUsingExtendedRecord(ExtendedRecord er_) + : er(std::move(er_)) + {} +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/InterfaceUsingExtendedRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/InterfaceUsingExtendedRecord.java new file mode 100644 index 000000000..682ae0cd5 --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/InterfaceUsingExtendedRecord.java @@ -0,0 +1,50 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +package com.dropbox.djinni.test; + +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +public abstract class InterfaceUsingExtendedRecord { + @Nonnull + public static final RecordUsingExtendedRecord CR = new RecordUsingExtendedRecord( + new ExtendedRecord( + false /* mFoo */ ) /* mEr */ ); + + @Nonnull + public abstract ExtendedRecord meth(@Nonnull ExtendedRecord er); + + private static final class CppProxy extends InterfaceUsingExtendedRecord + { + private final long nativeRef; + private final AtomicBoolean destroyed = new AtomicBoolean(false); + + private CppProxy(long nativeRef) + { + if (nativeRef == 0) throw new RuntimeException("nativeRef is zero"); + this.nativeRef = nativeRef; + } + + private native void nativeDestroy(long nativeRef); + public void destroy() + { + boolean destroyed = this.destroyed.getAndSet(true); + if (!destroyed) nativeDestroy(this.nativeRef); + } + protected void finalize() throws java.lang.Throwable + { + destroy(); + super.finalize(); + } + + @Override + public ExtendedRecord meth(ExtendedRecord er) + { + assert !this.destroyed.get() : "trying to use a destroyed object"; + return native_meth(this.nativeRef, er); + } + private native ExtendedRecord native_meth(long _nativeRef, ExtendedRecord er); + } +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordUsingExtendedRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordUsingExtendedRecord.java new file mode 100644 index 000000000..e313bf7af --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordUsingExtendedRecord.java @@ -0,0 +1,36 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +package com.dropbox.djinni.test; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +public class RecordUsingExtendedRecord { + + @Nonnull + public static final RecordUsingExtendedRecord CR = new RecordUsingExtendedRecord( + new ExtendedRecord( + false /* mFoo */ ) /* mEr */ ); + + + /*package*/ final ExtendedRecord mEr; + + public RecordUsingExtendedRecord( + @Nonnull ExtendedRecord er) { + this.mEr = er; + } + + @Nonnull + public ExtendedRecord getEr() { + return mEr; + } + + @Override + public String toString() { + return "RecordUsingExtendedRecord{" + + "mEr=" + mEr + + "}"; + } + +} diff --git a/test-suite/generated-src/jni/NativeInterfaceUsingExtendedRecord.cpp b/test-suite/generated-src/jni/NativeInterfaceUsingExtendedRecord.cpp new file mode 100644 index 000000000..2a3620f08 --- /dev/null +++ b/test-suite/generated-src/jni/NativeInterfaceUsingExtendedRecord.cpp @@ -0,0 +1,33 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#include "NativeInterfaceUsingExtendedRecord.hpp" // my header +#include "NativeExtendedRecord.hpp" +#include "NativeRecordUsingExtendedRecord.hpp" + +namespace djinni_generated { + +NativeInterfaceUsingExtendedRecord::NativeInterfaceUsingExtendedRecord() : ::djinni::JniInterface<::testsuite::InterfaceUsingExtendedRecord, NativeInterfaceUsingExtendedRecord>("com/dropbox/djinni/test/InterfaceUsingExtendedRecord$CppProxy") {} + +NativeInterfaceUsingExtendedRecord::~NativeInterfaceUsingExtendedRecord() = default; + + +CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_InterfaceUsingExtendedRecord_00024CppProxy_nativeDestroy(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + delete reinterpret_cast<::djinni::CppProxyHandle<::testsuite::InterfaceUsingExtendedRecord>*>(nativeRef); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, ) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_InterfaceUsingExtendedRecord_00024CppProxy_native_1meth(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef, jobject j_er) +{ + try { + DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef); + const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::InterfaceUsingExtendedRecord>(nativeRef); + auto r = ref->meth(::djinni_generated::NativeExtendedRecord::toCpp(jniEnv, j_er)); + return ::djinni::release(::djinni_generated::NativeExtendedRecord::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeInterfaceUsingExtendedRecord.hpp b/test-suite/generated-src/jni/NativeInterfaceUsingExtendedRecord.hpp new file mode 100644 index 000000000..dc20f6f82 --- /dev/null +++ b/test-suite/generated-src/jni/NativeInterfaceUsingExtendedRecord.hpp @@ -0,0 +1,32 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "interface_using_extended_record.hpp" + +namespace djinni_generated { + +class NativeInterfaceUsingExtendedRecord final : ::djinni::JniInterface<::testsuite::InterfaceUsingExtendedRecord, NativeInterfaceUsingExtendedRecord> { +public: + using CppType = std::shared_ptr<::testsuite::InterfaceUsingExtendedRecord>; + using CppOptType = std::shared_ptr<::testsuite::InterfaceUsingExtendedRecord>; + using JniType = jobject; + + using Boxed = NativeInterfaceUsingExtendedRecord; + + ~NativeInterfaceUsingExtendedRecord(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j) { return ::djinni::JniClass::get()._fromJava(jniEnv, j); } + static ::djinni::LocalRef fromCppOpt(JNIEnv* jniEnv, const CppOptType& c) { return {jniEnv, ::djinni::JniClass::get()._toJava(jniEnv, c)}; } + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) { return fromCppOpt(jniEnv, c); } + +private: + NativeInterfaceUsingExtendedRecord(); + friend ::djinni::JniClass; + friend ::djinni::JniInterface<::testsuite::InterfaceUsingExtendedRecord, NativeInterfaceUsingExtendedRecord>; + +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeRecordUsingExtendedRecord.cpp b/test-suite/generated-src/jni/NativeRecordUsingExtendedRecord.cpp new file mode 100644 index 000000000..05713778b --- /dev/null +++ b/test-suite/generated-src/jni/NativeRecordUsingExtendedRecord.cpp @@ -0,0 +1,28 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#include "NativeRecordUsingExtendedRecord.hpp" // my header +#include "NativeExtendedRecord.hpp" + +namespace djinni_generated { + +NativeRecordUsingExtendedRecord::NativeRecordUsingExtendedRecord() = default; + +NativeRecordUsingExtendedRecord::~NativeRecordUsingExtendedRecord() = default; + +auto NativeRecordUsingExtendedRecord::fromCpp(JNIEnv* jniEnv, const CppType& c) -> ::djinni::LocalRef { + const auto& data = ::djinni::JniClass::get(); + auto r = ::djinni::LocalRef{jniEnv->NewObject(data.clazz.get(), data.jconstructor, + ::djinni::get(::djinni_generated::NativeExtendedRecord::fromCpp(jniEnv, c.er)))}; + ::djinni::jniExceptionCheck(jniEnv); + return r; +} + +auto NativeRecordUsingExtendedRecord::toCpp(JNIEnv* jniEnv, JniType j) -> CppType { + ::djinni::JniLocalScope jscope(jniEnv, 2); + assert(j != nullptr); + const auto& data = ::djinni::JniClass::get(); + return {::djinni_generated::NativeExtendedRecord::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mEr))}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeRecordUsingExtendedRecord.hpp b/test-suite/generated-src/jni/NativeRecordUsingExtendedRecord.hpp new file mode 100644 index 000000000..d295f5cb0 --- /dev/null +++ b/test-suite/generated-src/jni/NativeRecordUsingExtendedRecord.hpp @@ -0,0 +1,32 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "record_using_extended_record.hpp" + +namespace djinni_generated { + +class NativeRecordUsingExtendedRecord final { +public: + using CppType = ::testsuite::RecordUsingExtendedRecord; + using JniType = jobject; + + using Boxed = NativeRecordUsingExtendedRecord; + + ~NativeRecordUsingExtendedRecord(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j); + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c); + +private: + NativeRecordUsingExtendedRecord(); + friend ::djinni::JniClass; + + const ::djinni::GlobalRef clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/RecordUsingExtendedRecord") }; + const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "", "(Lcom/dropbox/djinni/test/ExtendedRecord;)V") }; + const jfieldID field_mEr { ::djinni::jniGetFieldID(clazz.get(), "mEr", "Lcom/dropbox/djinni/test/ExtendedRecord;") }; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord+Private.h b/test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord+Private.h new file mode 100644 index 000000000..4153b353c --- /dev/null +++ b/test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord+Private.h @@ -0,0 +1,31 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#include "interface_using_extended_record.hpp" +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBInterfaceUsingExtendedRecord; + +namespace djinni_generated { + +class InterfaceUsingExtendedRecord +{ +public: + using CppType = std::shared_ptr<::testsuite::InterfaceUsingExtendedRecord>; + using CppOptType = std::shared_ptr<::testsuite::InterfaceUsingExtendedRecord>; + using ObjcType = DBInterfaceUsingExtendedRecord*; + + using Boxed = InterfaceUsingExtendedRecord; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCppOpt(const CppOptType& cpp); + static ObjcType fromCpp(const CppType& cpp) { return fromCppOpt(cpp); } + +private: + class ObjcProxy; +}; + +} // namespace djinni_generated + diff --git a/test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord+Private.mm b/test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord+Private.mm new file mode 100644 index 000000000..20048f849 --- /dev/null +++ b/test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord+Private.mm @@ -0,0 +1,68 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#import "DBInterfaceUsingExtendedRecord+Private.h" +#import "DBInterfaceUsingExtendedRecord.h" +#import "DBExtendedRecord+Private.h" +#import "DBRecordUsingExtendedRecord+Private.h" +#import "DJICppWrapperCache+Private.h" +#import "DJIError.h" +#include +#include +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@interface DBInterfaceUsingExtendedRecord () + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::InterfaceUsingExtendedRecord>&)cppRef; + +@end + +@implementation DBInterfaceUsingExtendedRecord { + ::djinni::CppProxyCache::Handle> _cppRefHandle; +} + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::InterfaceUsingExtendedRecord>&)cppRef +{ + if (self = [super init]) { + _cppRefHandle.assign(cppRef); + } + return self; +} + +- (nonnull DBExtendedRecord *)meth:(nonnull DBExtendedRecord *)er { + try { + auto objcpp_result_ = _cppRefHandle.get()->meth(::djinni_generated::ExtendedRecord::toCpp(er)); + return ::djinni_generated::ExtendedRecord::fromCpp(objcpp_result_); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + ++ (DBRecordUsingExtendedRecord * __nonnull)cr +{ + static DBRecordUsingExtendedRecord * const s_cr = [[DBRecordUsingExtendedRecord alloc] initWithEr:[[DBExtendedRecord alloc] initWithFoo:NO]]; + return s_cr; +} + + +namespace djinni_generated { + +auto InterfaceUsingExtendedRecord::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + return objc->_cppRefHandle.get(); +} + +auto InterfaceUsingExtendedRecord::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + return ::djinni::get_cpp_proxy(cpp); +} + +} // namespace djinni_generated + +@end diff --git a/test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord.h b/test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord.h new file mode 100644 index 000000000..db6d69a2b --- /dev/null +++ b/test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord.h @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#import "DBExtendedRecord.h" +#import "DBRecordUsingExtendedRecord.h" +#import + + +@interface DBInterfaceUsingExtendedRecord : NSObject + +- (nonnull DBExtendedRecord *)meth:(nonnull DBExtendedRecord *)er; + ++ (DBRecordUsingExtendedRecord * __nonnull)cr; +@end diff --git a/test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord.mm b/test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord.mm new file mode 100644 index 000000000..56cf13802 --- /dev/null +++ b/test-suite/generated-src/objc/DBInterfaceUsingExtendedRecord.mm @@ -0,0 +1,5 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#import "DBInterfaceUsingExtendedRecord.h" + diff --git a/test-suite/generated-src/objc/DBRecordUsingExtendedRecord+Private.h b/test-suite/generated-src/objc/DBRecordUsingExtendedRecord+Private.h new file mode 100644 index 000000000..153a0f343 --- /dev/null +++ b/test-suite/generated-src/objc/DBRecordUsingExtendedRecord+Private.h @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#import "DBRecordUsingExtendedRecord.h" +#include "record_using_extended_record.hpp" + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBRecordUsingExtendedRecord; + +namespace djinni_generated { + +struct RecordUsingExtendedRecord +{ + using CppType = ::testsuite::RecordUsingExtendedRecord; + using ObjcType = DBRecordUsingExtendedRecord*; + + using Boxed = RecordUsingExtendedRecord; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCpp(const CppType& cpp); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBRecordUsingExtendedRecord+Private.mm b/test-suite/generated-src/objc/DBRecordUsingExtendedRecord+Private.mm new file mode 100644 index 000000000..991c855bb --- /dev/null +++ b/test-suite/generated-src/objc/DBRecordUsingExtendedRecord+Private.mm @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#import "DBRecordUsingExtendedRecord+Private.h" +#import "DBExtendedRecord+Private.h" +#include + +namespace djinni_generated { + +auto RecordUsingExtendedRecord::toCpp(ObjcType obj) -> CppType +{ + assert(obj); + return {::djinni_generated::ExtendedRecord::toCpp(obj.er)}; +} + +auto RecordUsingExtendedRecord::fromCpp(const CppType& cpp) -> ObjcType +{ + return [[DBRecordUsingExtendedRecord alloc] initWithEr:(::djinni_generated::ExtendedRecord::fromCpp(cpp.er))]; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBRecordUsingExtendedRecord.h b/test-suite/generated-src/objc/DBRecordUsingExtendedRecord.h new file mode 100644 index 000000000..c62deea4a --- /dev/null +++ b/test-suite/generated-src/objc/DBRecordUsingExtendedRecord.h @@ -0,0 +1,16 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#import "DBExtendedRecord.h" +#import "DBRecordUsingExtendedRecord.h" +#import + +@interface DBRecordUsingExtendedRecord : NSObject +- (nonnull instancetype)initWithEr:(nonnull DBExtendedRecord *)er; ++ (nonnull instancetype)recordUsingExtendedRecordWithEr:(nonnull DBExtendedRecord *)er; + ++ (DBRecordUsingExtendedRecord * __nonnull)cr; +@property (nonatomic, readonly, nonnull) DBExtendedRecord * er; + +@end + diff --git a/test-suite/generated-src/objc/DBRecordUsingExtendedRecord.mm b/test-suite/generated-src/objc/DBRecordUsingExtendedRecord.mm new file mode 100644 index 000000000..82e3e5e7b --- /dev/null +++ b/test-suite/generated-src/objc/DBRecordUsingExtendedRecord.mm @@ -0,0 +1,33 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file generated by Djinni from extended_record.djinni + +#import "DBRecordUsingExtendedRecord.h" + + +@implementation DBRecordUsingExtendedRecord + +- (nonnull instancetype)initWithEr:(nonnull DBExtendedRecord *)er +{ + if (self = [super init]) { + _er = er; + } + return self; +} + ++ (nonnull instancetype)recordUsingExtendedRecordWithEr:(nonnull DBExtendedRecord *)er +{ + return [[self alloc] initWithEr:er]; +} + ++ (DBRecordUsingExtendedRecord * __nonnull)cr +{ + static DBRecordUsingExtendedRecord * const s_cr = [[DBRecordUsingExtendedRecord alloc] initWithEr:[[DBExtendedRecord alloc] initWithFoo:NO]]; + return s_cr; +} + +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@ %p er:%@>", self.class, (void *)self, self.er]; +} + +@end diff --git a/test-suite/generated-src/outFileList.txt b/test-suite/generated-src/outFileList.txt index 3f28125dc..0229246a0 100644 --- a/test-suite/generated-src/outFileList.txt +++ b/test-suite/generated-src/outFileList.txt @@ -8,6 +8,10 @@ djinni-output-temp/cpp/_varname_record_.hpp djinni-output-temp/cpp/_varname_interface_.hpp djinni-output-temp/cpp/extended_record_base.hpp djinni-output-temp/cpp/extended_record_base.cpp +djinni-output-temp/cpp/record_using_extended_record.hpp +djinni-output-temp/cpp/record_using_extended_record.cpp +djinni-output-temp/cpp/interface_using_extended_record.hpp +djinni-output-temp/cpp/interface_using_extended_record.cpp djinni-output-temp/cpp/objc_only_listener.hpp djinni-output-temp/cpp/java_only_listener.hpp djinni-output-temp/cpp/uses_single_language_listeners.hpp @@ -51,6 +55,8 @@ djinni-output-temp/java/MapDateRecord.java djinni-output-temp/java/VarnameRecord.java djinni-output-temp/java/VarnameInterface.java djinni-output-temp/java/ExtendedRecord.java +djinni-output-temp/java/RecordUsingExtendedRecord.java +djinni-output-temp/java/InterfaceUsingExtendedRecord.java djinni-output-temp/java/ObjcOnlyListener.java djinni-output-temp/java/JavaOnlyListener.java djinni-output-temp/java/UsesSingleLanguageListeners.java @@ -96,6 +102,10 @@ djinni-output-temp/jni/NativeVarnameInterface.hpp djinni-output-temp/jni/NativeVarnameInterface.cpp djinni-output-temp/jni/NativeExtendedRecord.hpp djinni-output-temp/jni/NativeExtendedRecord.cpp +djinni-output-temp/jni/NativeRecordUsingExtendedRecord.hpp +djinni-output-temp/jni/NativeRecordUsingExtendedRecord.cpp +djinni-output-temp/jni/NativeInterfaceUsingExtendedRecord.hpp +djinni-output-temp/jni/NativeInterfaceUsingExtendedRecord.cpp djinni-output-temp/jni/NativeObjcOnlyListener.hpp djinni-output-temp/jni/NativeObjcOnlyListener.cpp djinni-output-temp/jni/NativeJavaOnlyListener.hpp @@ -169,6 +179,10 @@ djinni-output-temp/objc/DBVarnameRecord.mm djinni-output-temp/objc/DBVarnameInterface.h djinni-output-temp/objc/DBExtendedRecord.h djinni-output-temp/objc/DBExtendedRecord.mm +djinni-output-temp/objc/DBRecordUsingExtendedRecord.h +djinni-output-temp/objc/DBRecordUsingExtendedRecord.mm +djinni-output-temp/objc/DBInterfaceUsingExtendedRecord.h +djinni-output-temp/objc/DBInterfaceUsingExtendedRecord.mm djinni-output-temp/objc/DBObjcOnlyListener.h djinni-output-temp/objc/DBJavaOnlyListener.h djinni-output-temp/objc/DBUsesSingleLanguageListeners.h @@ -228,6 +242,10 @@ djinni-output-temp/objc/DBVarnameInterface+Private.h djinni-output-temp/objc/DBVarnameInterface+Private.mm djinni-output-temp/objc/DBExtendedRecord+Private.h djinni-output-temp/objc/DBExtendedRecord+Private.mm +djinni-output-temp/objc/DBRecordUsingExtendedRecord+Private.h +djinni-output-temp/objc/DBRecordUsingExtendedRecord+Private.mm +djinni-output-temp/objc/DBInterfaceUsingExtendedRecord+Private.h +djinni-output-temp/objc/DBInterfaceUsingExtendedRecord+Private.mm djinni-output-temp/objc/DBObjcOnlyListener+Private.h djinni-output-temp/objc/DBObjcOnlyListener+Private.mm djinni-output-temp/objc/DBJavaOnlyListener+Private.h diff --git a/test-suite/handwritten-src/cpp/extended_record.cpp b/test-suite/handwritten-src/cpp/extended_record.cpp index e342e71e2..9bfc93ae8 100644 --- a/test-suite/handwritten-src/cpp/extended_record.cpp +++ b/test-suite/handwritten-src/cpp/extended_record.cpp @@ -1,9 +1,9 @@ - - #include "extended_record.hpp" +// Validate these generated headers are compilable. +#include "record_using_extended_record.hpp" +#include "interface_using_extended_record.hpp" + using namespace testsuite; ExtendedRecord::ExtendedRecord() : ExtendedRecordBase(true) {} - - diff --git a/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj b/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj index d4e54ea11..498d67c09 100644 --- a/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj +++ b/test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj @@ -76,6 +76,12 @@ B52DA56B1B103F75005CE75F /* DBAssortedPrimitives+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B52DA5671B103F6D005CE75F /* DBAssortedPrimitives+Private.mm */; }; B52DA56E1B103FC5005CE75F /* assorted_primitives.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B52DA56C1B103FBE005CE75F /* assorted_primitives.cpp */; }; B52DA5701B104025005CE75F /* DBPrimitivesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B52DA56F1B104025005CE75F /* DBPrimitivesTests.m */; }; + B58B16AF1D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B58B16A81D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord+Private.mm */; }; + B58B16B01D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord.mm in Sources */ = {isa = PBXBuildFile; fileRef = B58B16AA1D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord.mm */; }; + B58B16B11D5AC9BC00EF92B5 /* DBInterfaceUsingExtendedRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B58B16AC1D5AC9BC00EF92B5 /* DBInterfaceUsingExtendedRecord+Private.mm */; }; + B58B16B41D5AD55B00EF92B5 /* record_using_extended_record.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B58B16B21D5AD55B00EF92B5 /* record_using_extended_record.cpp */; }; + B58B16B51D5AD55B00EF92B5 /* interface_using_extended_record.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B58B16B31D5AD55B00EF92B5 /* interface_using_extended_record.cpp */; }; + B58B16B71D5AD56600EF92B5 /* DBInterfaceUsingExtendedRecord.mm in Sources */ = {isa = PBXBuildFile; fileRef = B58B16B61D5AD56600EF92B5 /* DBInterfaceUsingExtendedRecord.mm */; }; B5D8FC361C23E2F40045ADCF /* DBConstantRecord.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5D8FC331C23E2F40045ADCF /* DBConstantRecord.mm */; }; B5D8FC371C23E2F40045ADCF /* DBConstantRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5D8FC351C23E2F40045ADCF /* DBConstantRecord+Private.mm */; }; B5E9C93B1C1F9D9D0073C123 /* reverse_client_interface_impl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5E9C9391C1F9D9D0073C123 /* reverse_client_interface_impl.cpp */; }; @@ -309,6 +315,18 @@ B52DA56C1B103FBE005CE75F /* assorted_primitives.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = assorted_primitives.cpp; sourceTree = ""; }; B52DA56D1B103FBE005CE75F /* assorted_primitives.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = assorted_primitives.hpp; sourceTree = ""; }; B52DA56F1B104025005CE75F /* DBPrimitivesTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DBPrimitivesTests.m; sourceTree = ""; }; + B58B16A61D5AC9AD00EF92B5 /* record_using_extended_record.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = record_using_extended_record.hpp; sourceTree = ""; }; + B58B16A71D5AC9AD00EF92B5 /* interface_using_extended_record.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = interface_using_extended_record.hpp; sourceTree = ""; }; + B58B16A81D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBRecordUsingExtendedRecord+Private.mm"; sourceTree = ""; }; + B58B16A91D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBRecordUsingExtendedRecord+Private.h"; sourceTree = ""; }; + B58B16AA1D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBRecordUsingExtendedRecord.mm; sourceTree = ""; }; + B58B16AB1D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBRecordUsingExtendedRecord.h; sourceTree = ""; }; + B58B16AC1D5AC9BC00EF92B5 /* DBInterfaceUsingExtendedRecord+Private.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "DBInterfaceUsingExtendedRecord+Private.mm"; sourceTree = ""; }; + B58B16AD1D5AC9BC00EF92B5 /* DBInterfaceUsingExtendedRecord+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBInterfaceUsingExtendedRecord+Private.h"; sourceTree = ""; }; + B58B16AE1D5AC9BC00EF92B5 /* DBInterfaceUsingExtendedRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBInterfaceUsingExtendedRecord.h; sourceTree = ""; }; + B58B16B21D5AD55B00EF92B5 /* record_using_extended_record.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = record_using_extended_record.cpp; sourceTree = ""; }; + B58B16B31D5AD55B00EF92B5 /* interface_using_extended_record.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = interface_using_extended_record.cpp; sourceTree = ""; }; + B58B16B61D5AD56600EF92B5 /* DBInterfaceUsingExtendedRecord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBInterfaceUsingExtendedRecord.mm; sourceTree = ""; }; B5D8FC321C23E2F40045ADCF /* DBConstantRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBConstantRecord.h; sourceTree = ""; }; B5D8FC331C23E2F40045ADCF /* DBConstantRecord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBConstantRecord.mm; sourceTree = ""; }; B5D8FC341C23E2F40045ADCF /* DBConstantRecord+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBConstantRecord+Private.h"; sourceTree = ""; }; @@ -530,6 +548,14 @@ A24249181AF192E0003BF8F0 /* generated-objc */ = { isa = PBXGroup; children = ( + B58B16B61D5AD56600EF92B5 /* DBInterfaceUsingExtendedRecord.mm */, + B58B16A81D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord+Private.mm */, + B58B16A91D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord+Private.h */, + B58B16AA1D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord.mm */, + B58B16AB1D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord.h */, + B58B16AC1D5AC9BC00EF92B5 /* DBInterfaceUsingExtendedRecord+Private.mm */, + B58B16AD1D5AC9BC00EF92B5 /* DBInterfaceUsingExtendedRecord+Private.h */, + B58B16AE1D5AC9BC00EF92B5 /* DBInterfaceUsingExtendedRecord.h */, B51911491D555EE900772DFE /* DBVarnameRecord+Private.mm */, B519114A1D555EE900772DFE /* DBVarnameRecord+Private.h */, B519114B1D555EE900772DFE /* DBVarnameRecord.mm */, @@ -687,6 +713,10 @@ A242495D1AF192FC003BF8F0 /* generated-cpp */ = { isa = PBXGroup; children = ( + B58B16B21D5AD55B00EF92B5 /* record_using_extended_record.cpp */, + B58B16B31D5AD55B00EF92B5 /* interface_using_extended_record.cpp */, + B58B16A61D5AC9AD00EF92B5 /* record_using_extended_record.hpp */, + B58B16A71D5AC9AD00EF92B5 /* interface_using_extended_record.hpp */, B51911471D555EDC00772DFE /* _varname_record_.hpp */, B51911481D555EDC00772DFE /* _varname_interface_.hpp */, B51911191D542AEC00772DFE /* wchar_test_helpers.hpp */, @@ -844,6 +874,7 @@ B5F06AA51D4987EF005BE736 /* DBEnumUsageInterface+Private.mm in Sources */, CFFD588D1B019E79001E10B6 /* DBCppException+Private.mm in Sources */, A238CA921AF84B7100CDDCE5 /* DBDateRecord+Private.mm in Sources */, + B58B16AF1D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord+Private.mm in Sources */, A248502B1AF96EBC00AFE907 /* DBMapListRecord.mm in Sources */, 6536CD7819A6C98800DD7715 /* cpp_exception_impl.cpp in Sources */, A248502C1AF96EBC00AFE907 /* DBMapRecord.mm in Sources */, @@ -856,6 +887,7 @@ CFC5D9FC1B152E4300BF2DF8 /* TranslateDuration.cpp in Sources */, B51911511D555EE900772DFE /* DBVarnameRecord.mm in Sources */, A248502F1AF96EBC00AFE907 /* DBRecordWithDerivings.mm in Sources */, + B58B16B51D5AD55B00EF92B5 /* interface_using_extended_record.cpp in Sources */, B5F06A851D4973BD005BE736 /* DBConflict+Private.mm in Sources */, A24249741AF192FC003BF8F0 /* constants.cpp in Sources */, CFFD588B1B019E79001E10B6 /* DBClientInterface+Private.mm in Sources */, @@ -870,6 +902,8 @@ B5F06A9A1D497A66005BE736 /* extended_record.cpp in Sources */, A2CB54B419BA6E6000A9E600 /* DJIError.mm in Sources */, B5E9C9401C1F9E9E0073C123 /* DBReverseClientInterface+Private.mm in Sources */, + B58B16B41D5AD55B00EF92B5 /* record_using_extended_record.cpp in Sources */, + B58B16B11D5AC9BC00EF92B5 /* DBInterfaceUsingExtendedRecord+Private.mm in Sources */, B5F06A891D4973BD005BE736 /* DBExtendedRecord.mm in Sources */, A238CA961AF84B7100CDDCE5 /* DBMapListRecord+Private.mm in Sources */, A238CA9C1AF84B7100CDDCE5 /* DBPrimitiveList+Private.mm in Sources */, @@ -886,6 +920,7 @@ 6551684F1C40511C003682A4 /* return_one_two.cpp in Sources */, A24249751AF192FC003BF8F0 /* record_with_derivings.cpp in Sources */, CFC5D9D01B15105100BF2DF8 /* extern_record_with_derivings.cpp in Sources */, + B58B16B71D5AD56600EF92B5 /* DBInterfaceUsingExtendedRecord.mm in Sources */, B51911181D542A7000772DFE /* DBWcharTestHelpers+Private.mm in Sources */, A238CA901AF84B7100CDDCE5 /* DBConstants+Private.mm in Sources */, B51911521D555EE900772DFE /* DBVarnameInterface+Private.mm in Sources */, @@ -904,6 +939,7 @@ A248502E1AF96EBC00AFE907 /* DBPrimitiveList.mm in Sources */, B5F06A8C1D4973BD005BE736 /* DBObjcOnlyListener+Private.mm in Sources */, B5153F961D54283700012654 /* DBUsesSingleLanguageListeners+Private.mm in Sources */, + B58B16B01D5AC9BC00EF92B5 /* DBRecordUsingExtendedRecord.mm in Sources */, B5D8FC371C23E2F40045ADCF /* DBConstantRecord+Private.mm in Sources */, B519111B1D542B0700772DFE /* wchar_test_helpers.cpp in Sources */, A238CAA01AF84B7100CDDCE5 /* DBRecordWithNestedDerivings+Private.mm in Sources */, From 7300e57a00c8faf08975390dcf2644d74f0f7281 Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Fri, 19 Aug 2016 13:16:02 +0300 Subject: [PATCH 35/39] Fixed import guard when using relative file paths --- src/source/parser.scala | 24 +++++++++++++++--------- test-suite/djinni/common.djinni | 1 + test-suite/djinni/relative_paths.djinni | 3 +++ test-suite/generated-src/inFileList.txt | 1 + 4 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 test-suite/djinni/relative_paths.djinni diff --git a/src/source/parser.scala b/src/source/parser.scala index 0b1c6cea5..a7f06841f 100644 --- a/src/source/parser.scala +++ b/src/source/parser.scala @@ -266,31 +266,37 @@ def parseExternFile(externFile: File, inFileListWriter: Option[Writer]) : Seq[Ty } } +def normalizePath(path: File) : File = { + return new File(java.nio.file.Paths.get(path.toString()).normalize().toString()) +} + def parseFile(idlFile: File, inFileListWriter: Option[Writer]): Seq[TypeDecl] = { + val normalizedIdlFile = normalizePath(idlFile) if (inFileListWriter.isDefined) { - inFileListWriter.get.write(idlFile + "\n") + inFileListWriter.get.write(normalizedIdlFile + "\n") } - visitedFiles.add(idlFile) - fileStack.push(idlFile) - val fin = new FileInputStream(idlFile) + visitedFiles.add(normalizedIdlFile) + fileStack.push(normalizedIdlFile) + val fin = new FileInputStream(normalizedIdlFile) try { - parse(idlFile.getName, new InputStreamReader(fin, "UTF-8")) match { + parse(normalizedIdlFile.getName, new InputStreamReader(fin, "UTF-8")) match { case Left(err) => System.err.println(err) System.exit(1); return null; case Right(idl) => { var types = idl.typeDecls idl.imports.foreach(x => { - if (fileStack.contains(x.file)) { + val normalized = normalizePath(x.file) + if (fileStack.contains(normalized)) { throw new AssertionError("Circular import detected!") } - if (!visitedFiles.contains(x.file)) { + if (!visitedFiles.contains(normalized)) { x match { case IdlFileRef(file) => - types = parseFile(file, inFileListWriter) ++ types + types = parseFile(normalized, inFileListWriter) ++ types case ExternFileRef(file) => - types = parseExternFile(file, inFileListWriter) ++ types + types = parseExternFile(normalized, inFileListWriter) ++ types } } }) diff --git a/test-suite/djinni/common.djinni b/test-suite/djinni/common.djinni index 5c165f605..dc2e71bf3 100644 --- a/test-suite/djinni/common.djinni +++ b/test-suite/djinni/common.djinni @@ -14,3 +14,4 @@ @import "single_language_interfaces.djinni" @import "extended_record.djinni" @import "varnames.djinni" +@import "relative_paths.djinni" diff --git a/test-suite/djinni/relative_paths.djinni b/test-suite/djinni/relative_paths.djinni new file mode 100644 index 000000000..5833fa8c4 --- /dev/null +++ b/test-suite/djinni/relative_paths.djinni @@ -0,0 +1,3 @@ +@import "./date.djinni" +@import "../djinni/date.djinni" +@extern "./date.yaml" diff --git a/test-suite/generated-src/inFileList.txt b/test-suite/generated-src/inFileList.txt index 4b273f4ab..c2f69d2c8 100644 --- a/test-suite/generated-src/inFileList.txt +++ b/test-suite/generated-src/inFileList.txt @@ -16,6 +16,7 @@ djinni/multiple_inheritance.djinni djinni/single_language_interfaces.djinni djinni/extended_record.djinni djinni/varnames.djinni +djinni/relative_paths.djinni djinni/date.djinni djinni/date.yaml djinni/duration.djinni From 5f37cfe29ac30e406708dd848d4c072297514988 Mon Sep 17 00:00:00 2001 From: Aleksey Konovalov Date: Tue, 23 Aug 2016 18:52:12 +0300 Subject: [PATCH 36/39] Fixed crash in the case where the parameters "--list-in-files" and "--list-out-files" contain only the names of files --- src/source/Main.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/source/Main.scala b/src/source/Main.scala index 8932bb7a4..790988def 100644 --- a/src/source/Main.scala +++ b/src/source/Main.scala @@ -241,7 +241,8 @@ object Main { // Parse IDL file. System.out.println("Parsing...") val inFileListWriter = if (inFileListPath.isDefined) { - createFolder("input file list", inFileListPath.get.getParentFile) + if (inFileListPath.get.getParentFile != null) + createFolder("input file list", inFileListPath.get.getParentFile) Some(new BufferedWriter(new FileWriter(inFileListPath.get))) } else { None @@ -271,7 +272,8 @@ object Main { System.out.println("Generating...") val outFileListWriter = if (outFileListPath.isDefined) { - createFolder("output file list", outFileListPath.get.getParentFile) + if (outFileListPath.get.getParentFile != null) + createFolder("output file list", outFileListPath.get.getParentFile) Some(new BufferedWriter(new FileWriter(outFileListPath.get))) } else { None From a9f61c683773cd19252bfb72d343b3740e6f5d5b Mon Sep 17 00:00:00 2001 From: Stephan Jaetzold Date: Wed, 19 Oct 2016 18:19:18 +0200 Subject: [PATCH 37/39] Set minimum compatible IDEA API version to 139. The plugin does not work with 131 only. --- intellij-plugin/META-INF/plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intellij-plugin/META-INF/plugin.xml b/intellij-plugin/META-INF/plugin.xml index c07649316..89e0d5f1f 100644 --- a/intellij-plugin/META-INF/plugin.xml +++ b/intellij-plugin/META-INF/plugin.xml @@ -29,7 +29,7 @@ - + From 2c0a5be7084b01c3f5f06a897c77f5b101a42e69 Mon Sep 17 00:00:00 2001 From: Stephan Jaetzold Date: Fri, 21 Oct 2016 14:06:48 +0200 Subject: [PATCH 38/39] Update intellij plugin description to include license text. Make the github project be the vendor. --- intellij-plugin/META-INF/plugin.xml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/intellij-plugin/META-INF/plugin.xml b/intellij-plugin/META-INF/plugin.xml index 89e0d5f1f..c4ad46c21 100644 --- a/intellij-plugin/META-INF/plugin.xml +++ b/intellij-plugin/META-INF/plugin.xml @@ -15,12 +15,28 @@ --> com.dropbox.djinni.ideaplugin - Djinni interface definition language file support + Djinni IDL file support 0.8 - Dropbox + Dropbox Djinni Github Project License + Copyright 2015-2016 Dropbox, 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. + ]]>
Date: Thu, 10 Nov 2016 17:24:04 -0500 Subject: [PATCH 39/39] Update ios version in Make targets to 10.1. --- Makefile | 2 +- test-suite/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e905f185d..c16901d75 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ example_ios: ./build_ios/example/libtextsort.xcodeproj -scheme TextSort \ -configuration 'Debug' \ -sdk iphonesimulator \ - -destination 'platform=iOS Simulator,name=iPhone 6s,OS=9.3' + -destination 'platform=iOS Simulator,name=iPhone 6s,OS=10.1' # this target implicitly depends on GypAndroid.mk since gradle will try to make it example_android: GypAndroid.mk diff --git a/test-suite/Makefile b/test-suite/Makefile index d73141764..3e1dabe26 100644 --- a/test-suite/Makefile +++ b/test-suite/Makefile @@ -6,7 +6,7 @@ djinni: ./run_djinni.sh objc: djinni - cd objc; xcodebuild -sdk iphonesimulator -project DjinniObjcTest.xcodeproj -scheme DjinniObjcTest test -destination 'platform=iOS Simulator,name=iPhone 6s,OS=9.3' + cd objc; xcodebuild -sdk iphonesimulator -project DjinniObjcTest.xcodeproj -scheme DjinniObjcTest test -destination 'platform=iOS Simulator,name=iPhone 6s,OS=10.1' java: djinni cd java && ant compile test