Commit 6d79895c authored by Miro Knejp's avatar Miro Knejp Committed by Jacob Potter

Cleanup record constructor with function call writer

parent b4f335b9
...@@ -10,14 +10,11 @@ ...@@ -10,14 +10,11 @@
namespace textsort { namespace textsort {
struct ItemList final { struct ItemList final {
std::vector<std::string> items; std::vector<std::string> items;
ItemList(std::vector<std::string> items)
ItemList( : items(std::move(items))
std::vector<std::string> items) : {}
items(std::move(items)) {
}
}; };
} // namespace textsort } // namespace textsort
...@@ -18,7 +18,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -18,7 +18,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface TXSSortItems () @interface TXSSortItems ()
@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::textsort::SortItems>::Handle cppRef; @property (nonatomic, readonly) ::djinni::DbxCppWrapperCache<::textsort::SortItems>::Handle cppRef;
- (id)initWithCpp:(const std::shared_ptr<::textsort::SortItems>&)cppRef; - (id)initWithCpp:(const std::shared_ptr<::textsort::SortItems>&)cppRef;
...@@ -33,7 +33,7 @@ auto SortItems::toCpp(ObjcType objc) -> CppType ...@@ -33,7 +33,7 @@ auto SortItems::toCpp(ObjcType objc) -> CppType
auto SortItems::fromCpp(const CppType& cpp) -> ObjcType auto SortItems::fromCpp(const CppType& cpp) -> ObjcType
{ {
return !cpp ? nil : djinni::DbxCppWrapperCache<::textsort::SortItems>::getInstance()->get(cpp, [] (const auto& p) return !cpp ? nil : ::djinni::DbxCppWrapperCache<::textsort::SortItems>::getInstance()->get(cpp, [] (const auto& p)
{ {
return [[TXSSortItems alloc] initWithCpp:p]; return [[TXSSortItems alloc] initWithCpp:p];
}); });
......
...@@ -27,7 +27,7 @@ public: ...@@ -27,7 +27,7 @@ public:
auto TextboxListener::toCpp(ObjcType objc) -> CppType auto TextboxListener::toCpp(ObjcType objc) -> CppType
{ {
return objc ? djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr; return objc ? ::djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr;
} }
auto TextboxListener::fromCpp(const CppType& cpp) -> ObjcType auto TextboxListener::fromCpp(const CppType& cpp) -> ObjcType
......
...@@ -186,7 +186,6 @@ class CppGenerator(spec: Spec) extends Generator(spec) { ...@@ -186,7 +186,6 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
generateHppConstants(w, r.consts) generateHppConstants(w, r.consts)
// Field definitions. // Field definitions.
for (f <- r.fields) { for (f <- r.fields) {
w.wl
writeDoc(w, f.doc) writeDoc(w, f.doc)
w.wl(marshal.fieldType(f.ty) + " " + idCpp.field(f.ident) + ";") w.wl(marshal.fieldType(f.ty) + " " + idCpp.field(f.ident) + ";")
} }
...@@ -206,27 +205,13 @@ class CppGenerator(spec: Spec) extends Generator(spec) { ...@@ -206,27 +205,13 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
} }
// Constructor. // Constructor.
w.wl if(r.fields.nonEmpty) {
if (r.fields.nonEmpty) { writeAlignedCall(w, actualSelf + "(", r.fields, ")", f => marshal.fieldType(f.ty) + " " + idCpp.local(f.ident))
w.wl(actualSelf + "(").nestedN(2) { w.wl
val skipFirst = SkipFirst() val init = (f: Field) => idCpp.field(f.ident) + "(std::move(" + idCpp.local(f.ident) + "))"
for (f <- r.fields) { w.wl(": " + init(r.fields.head))
skipFirst { w.wl(",") } r.fields.tail.map(f => ", " + init(f)).foreach(w.wl)
w.w(marshal.fieldType(f.ty) + " " + idCpp.local(f.ident)) w.wl("{}")
}
w.wl(") :")
w.nested {
val skipFirst = SkipFirst()
for (f <- r.fields) {
skipFirst { w.wl(",") }
w.w(idCpp.field(f.ident) + "(std::move(" + idCpp.local(f.ident) + "))")
}
w.wl(" {")
}
}
w.wl("}")
} else {
w.wl(actualSelf + "() {};")
} }
if (r.ext.cpp) { if (r.ext.cpp) {
......
...@@ -8,42 +8,32 @@ ...@@ -8,42 +8,32 @@
#include <utility> #include <utility>
struct AssortedIntegers final { struct AssortedIntegers final {
int8_t eight; int8_t eight;
int16_t sixteen; int16_t sixteen;
int32_t thirtytwo; int32_t thirtytwo;
int64_t sixtyfour; int64_t sixtyfour;
std::experimental::optional<int8_t> o_eight; std::experimental::optional<int8_t> o_eight;
std::experimental::optional<int16_t> o_sixteen; std::experimental::optional<int16_t> o_sixteen;
std::experimental::optional<int32_t> o_thirtytwo; std::experimental::optional<int32_t> o_thirtytwo;
std::experimental::optional<int64_t> o_sixtyfour; std::experimental::optional<int64_t> o_sixtyfour;
bool operator==(const AssortedIntegers & other) const; bool operator==(const AssortedIntegers & other) const;
bool operator!=(const AssortedIntegers & other) const; bool operator!=(const AssortedIntegers & other) const;
AssortedIntegers(int8_t eight,
AssortedIntegers( int16_t sixteen,
int8_t eight, int32_t thirtytwo,
int16_t sixteen, int64_t sixtyfour,
int32_t thirtytwo, std::experimental::optional<int8_t> o_eight,
int64_t sixtyfour, std::experimental::optional<int16_t> o_sixteen,
std::experimental::optional<int8_t> o_eight, std::experimental::optional<int32_t> o_thirtytwo,
std::experimental::optional<int16_t> o_sixteen, std::experimental::optional<int64_t> o_sixtyfour)
std::experimental::optional<int32_t> o_thirtytwo, : eight(std::move(eight))
std::experimental::optional<int64_t> o_sixtyfour) : , sixteen(std::move(sixteen))
eight(std::move(eight)), , thirtytwo(std::move(thirtytwo))
sixteen(std::move(sixteen)), , sixtyfour(std::move(sixtyfour))
thirtytwo(std::move(thirtytwo)), , o_eight(std::move(o_eight))
sixtyfour(std::move(sixtyfour)), , o_sixteen(std::move(o_sixteen))
o_eight(std::move(o_eight)), , o_thirtytwo(std::move(o_thirtytwo))
o_sixteen(std::move(o_sixteen)), , o_sixtyfour(std::move(o_sixtyfour))
o_thirtytwo(std::move(o_thirtytwo)), {}
o_sixtyfour(std::move(o_sixtyfour)) {
}
}; };
...@@ -8,16 +8,12 @@ ...@@ -8,16 +8,12 @@
#include <utility> #include <utility>
struct ClientReturnedRecord final { struct ClientReturnedRecord final {
int64_t record_id; int64_t record_id;
std::string content; std::string content;
ClientReturnedRecord(int64_t record_id,
ClientReturnedRecord( std::string content)
int64_t record_id, : record_id(std::move(record_id))
std::string content) : , content(std::move(content))
record_id(std::move(record_id)), {}
content(std::move(content)) {
}
}; };
...@@ -27,16 +27,12 @@ struct Constants final { ...@@ -27,16 +27,12 @@ struct Constants final {
static const std::experimental::optional<int32_t> OPTIONAL_INTEGER_CONSTANT; static const std::experimental::optional<int32_t> OPTIONAL_INTEGER_CONSTANT;
static const Constants OBJECT_CONSTANT; static const Constants OBJECT_CONSTANT;
int32_t some_integer; int32_t some_integer;
std::string some_string; std::string some_string;
Constants(int32_t some_integer,
Constants( std::string some_string)
int32_t some_integer, : some_integer(std::move(some_integer))
std::string some_string) : , some_string(std::move(some_string))
some_integer(std::move(some_integer)), {}
some_string(std::move(some_string)) {
}
}; };
...@@ -7,12 +7,9 @@ ...@@ -7,12 +7,9 @@
#include <utility> #include <utility>
struct DateRecord final { struct DateRecord final {
std::chrono::system_clock::time_point created_at; std::chrono::system_clock::time_point created_at;
DateRecord(std::chrono::system_clock::time_point created_at)
DateRecord( : created_at(std::move(created_at))
std::chrono::system_clock::time_point created_at) : {}
created_at(std::move(created_at)) {
}
}; };
...@@ -9,12 +9,9 @@ ...@@ -9,12 +9,9 @@
#include <utility> #include <utility>
struct MapDateRecord final { struct MapDateRecord final {
std::unordered_map<std::string, std::chrono::system_clock::time_point> dates_by_id; std::unordered_map<std::string, std::chrono::system_clock::time_point> dates_by_id;
MapDateRecord(std::unordered_map<std::string, std::chrono::system_clock::time_point> dates_by_id)
MapDateRecord( : dates_by_id(std::move(dates_by_id))
std::unordered_map<std::string, std::chrono::system_clock::time_point> dates_by_id) : {}
dates_by_id(std::move(dates_by_id)) {
}
}; };
...@@ -10,12 +10,9 @@ ...@@ -10,12 +10,9 @@
#include <vector> #include <vector>
struct MapListRecord final { struct MapListRecord final {
std::vector<std::unordered_map<std::string, int64_t>> map_list; std::vector<std::unordered_map<std::string, int64_t>> map_list;
MapListRecord(std::vector<std::unordered_map<std::string, int64_t>> map_list)
MapListRecord( : map_list(std::move(map_list))
std::vector<std::unordered_map<std::string, int64_t>> map_list) : {}
map_list(std::move(map_list)) {
}
}; };
...@@ -9,12 +9,9 @@ ...@@ -9,12 +9,9 @@
#include <utility> #include <utility>
struct MapRecord final { struct MapRecord final {
std::unordered_map<std::string, int64_t> map; std::unordered_map<std::string, int64_t> map;
MapRecord(std::unordered_map<std::string, int64_t> map)
MapRecord( : map(std::move(map))
std::unordered_map<std::string, int64_t> map) : {}
map(std::move(map)) {
}
}; };
...@@ -9,12 +9,9 @@ ...@@ -9,12 +9,9 @@
#include <vector> #include <vector>
struct NestedCollection final { struct NestedCollection final {
std::vector<std::unordered_set<std::string>> set_list; std::vector<std::unordered_set<std::string>> set_list;
NestedCollection(std::vector<std::unordered_set<std::string>> set_list)
NestedCollection( : set_list(std::move(set_list))
std::vector<std::unordered_set<std::string>> set_list) : {}
set_list(std::move(set_list)) {
}
}; };
...@@ -8,12 +8,9 @@ ...@@ -8,12 +8,9 @@
#include <vector> #include <vector>
struct PrimitiveList final { struct PrimitiveList final {
std::vector<int64_t> list; std::vector<int64_t> list;
PrimitiveList(std::vector<int64_t> list)
PrimitiveList( : list(std::move(list))
std::vector<int64_t> list) : {}
list(std::move(list)) {
}
}; };
...@@ -8,9 +8,7 @@ ...@@ -8,9 +8,7 @@
#include <utility> #include <utility>
struct RecordWithDerivings final { struct RecordWithDerivings final {
int32_t key1; int32_t key1;
std::string key2; std::string key2;
bool operator==(const RecordWithDerivings & other) const; bool operator==(const RecordWithDerivings & other) const;
...@@ -19,11 +17,9 @@ struct RecordWithDerivings final { ...@@ -19,11 +17,9 @@ struct RecordWithDerivings final {
bool operator>(const RecordWithDerivings & other) const; bool operator>(const RecordWithDerivings & other) const;
bool operator<=(const RecordWithDerivings & other) const; bool operator<=(const RecordWithDerivings & other) const;
bool operator>=(const RecordWithDerivings & other) const; bool operator>=(const RecordWithDerivings & other) const;
RecordWithDerivings(int32_t key1,
RecordWithDerivings( std::string key2)
int32_t key1, : key1(std::move(key1))
std::string key2) : , key2(std::move(key2))
key1(std::move(key1)), {}
key2(std::move(key2)) {
}
}; };
...@@ -8,9 +8,7 @@ ...@@ -8,9 +8,7 @@
#include <utility> #include <utility>
struct RecordWithNestedDerivings final { struct RecordWithNestedDerivings final {
int32_t key; int32_t key;
RecordWithDerivings rec; RecordWithDerivings rec;
bool operator==(const RecordWithNestedDerivings & other) const; bool operator==(const RecordWithNestedDerivings & other) const;
...@@ -19,11 +17,9 @@ struct RecordWithNestedDerivings final { ...@@ -19,11 +17,9 @@ struct RecordWithNestedDerivings final {
bool operator>(const RecordWithNestedDerivings & other) const; bool operator>(const RecordWithNestedDerivings & other) const;
bool operator<=(const RecordWithNestedDerivings & other) const; bool operator<=(const RecordWithNestedDerivings & other) const;
bool operator>=(const RecordWithNestedDerivings & other) const; bool operator>=(const RecordWithNestedDerivings & other) const;
RecordWithNestedDerivings(int32_t key,
RecordWithNestedDerivings( RecordWithDerivings rec)
int32_t key, : key(std::move(key))
RecordWithDerivings rec) : , rec(std::move(rec))
key(std::move(key)), {}
rec(std::move(rec)) {
}
}; };
...@@ -8,12 +8,9 @@ ...@@ -8,12 +8,9 @@
#include <utility> #include <utility>
struct SetRecord final { struct SetRecord final {
std::unordered_set<std::string> set; std::unordered_set<std::string> set;
SetRecord(std::unordered_set<std::string> set)
SetRecord( : set(std::move(set))
std::unordered_set<std::string> set) : {}
set(std::move(set)) {
}
}; };
...@@ -30,7 +30,7 @@ public: ...@@ -30,7 +30,7 @@ public:
auto ClientInterface::toCpp(ObjcType objc) -> CppType auto ClientInterface::toCpp(ObjcType objc) -> CppType
{ {
return objc ? djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr; return objc ? ::djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr;
} }
auto ClientInterface::fromCpp(const CppType& cpp) -> ObjcType auto ClientInterface::fromCpp(const CppType& cpp) -> ObjcType
......
...@@ -16,7 +16,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -16,7 +16,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface DBCppException () @interface DBCppException ()
@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::CppException>::Handle cppRef; @property (nonatomic, readonly) ::djinni::DbxCppWrapperCache<::CppException>::Handle cppRef;
- (id)initWithCpp:(const std::shared_ptr<::CppException>&)cppRef; - (id)initWithCpp:(const std::shared_ptr<::CppException>&)cppRef;
...@@ -31,7 +31,7 @@ auto CppException::toCpp(ObjcType objc) -> CppType ...@@ -31,7 +31,7 @@ auto CppException::toCpp(ObjcType objc) -> CppType
auto CppException::fromCpp(const CppType& cpp) -> ObjcType auto CppException::fromCpp(const CppType& cpp) -> ObjcType
{ {
return !cpp ? nil : djinni::DbxCppWrapperCache<::CppException>::getInstance()->get(cpp, [] (const auto& p) return !cpp ? nil : ::djinni::DbxCppWrapperCache<::CppException>::getInstance()->get(cpp, [] (const auto& p)
{ {
return [[DBCppException alloc] initWithCpp:p]; return [[DBCppException alloc] initWithCpp:p];
}); });
......
...@@ -22,7 +22,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -22,7 +22,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface DBTestHelpers () @interface DBTestHelpers ()
@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::TestHelpers>::Handle cppRef; @property (nonatomic, readonly) ::djinni::DbxCppWrapperCache<::TestHelpers>::Handle cppRef;
- (id)initWithCpp:(const std::shared_ptr<::TestHelpers>&)cppRef; - (id)initWithCpp:(const std::shared_ptr<::TestHelpers>&)cppRef;
...@@ -37,7 +37,7 @@ auto TestHelpers::toCpp(ObjcType objc) -> CppType ...@@ -37,7 +37,7 @@ auto TestHelpers::toCpp(ObjcType objc) -> CppType
auto TestHelpers::fromCpp(const CppType& cpp) -> ObjcType auto TestHelpers::fromCpp(const CppType& cpp) -> ObjcType
{ {
return !cpp ? nil : djinni::DbxCppWrapperCache<::TestHelpers>::getInstance()->get(cpp, [] (const auto& p) return !cpp ? nil : ::djinni::DbxCppWrapperCache<::TestHelpers>::getInstance()->get(cpp, [] (const auto& p)
{ {
return [[DBTestHelpers alloc] initWithCpp:p]; return [[DBTestHelpers alloc] initWithCpp:p];
}); });
......
...@@ -14,7 +14,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -14,7 +14,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface DBToken () @interface DBToken ()
@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::Token>::Handle cppRef; @property (nonatomic, readonly) ::djinni::DbxCppWrapperCache<::Token>::Handle cppRef;
- (id)initWithCpp:(const std::shared_ptr<::Token>&)cppRef; - (id)initWithCpp:(const std::shared_ptr<::Token>&)cppRef;
...@@ -29,7 +29,7 @@ auto Token::toCpp(ObjcType objc) -> CppType ...@@ -29,7 +29,7 @@ auto Token::toCpp(ObjcType objc) -> CppType
auto Token::fromCpp(const CppType& cpp) -> ObjcType auto Token::fromCpp(const CppType& cpp) -> ObjcType
{ {
return !cpp ? nil : djinni::DbxCppWrapperCache<::Token>::getInstance()->get(cpp, [] (const auto& p) return !cpp ? nil : ::djinni::DbxCppWrapperCache<::Token>::getInstance()->get(cpp, [] (const auto& p)
{ {
return [[DBToken alloc] initWithCpp:p]; return [[DBToken alloc] initWithCpp:p];
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment