diff --git a/src/source/ComposerGenerator.scala b/src/source/ComposerGenerator.scala index 602eb70b..f8475e5e 100644 --- a/src/source/ComposerGenerator.scala +++ b/src/source/ComposerGenerator.scala @@ -34,7 +34,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { val nameParts = jsClass.split("""\.""") val ns = nameParts.dropRight(1).mkString(".") val cls = nameParts.takeRight(1).last - return Seq(ns, cls).map( e=> s"""djinni::composer::CTS{"$e"}""").mkString(", ") + return Seq(ns, cls).map( e=> s"""djinni::valdi::CTS{"$e"}""").mkString(", ") } class ComposerRefs(name: String, cppPrefixOverride: Option[String]=None) { @@ -44,7 +44,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { val cppPrefix = cppPrefixOverride.getOrElse(spec.composerIncludeCppPrefix) hpp.add("#include " + q(cppPrefix + spec.cppFileIdentStyle(name) + "." + spec.cppHeaderExt)) - hpp.add("#include " + q(spec.composerBaseLibIncludePrefix + "djinni_composer.hpp")) + hpp.add("#include " + q(spec.composerBaseLibIncludePrefix + "djinni_valdi.hpp")) spec.cppNnHeader match { case Some(nnHdr) => hpp.add("#include " + nnHdr) case _ => @@ -78,7 +78,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { def helperName(tm: MExpr): String = tm.base match { case d: MDef => withNs(Some(helperNamespace()), helperClass(d.name)) case e: MExtern => e.composer.translator - case o => withNs(Some("djinni::composer"), o match { + case o => withNs(Some("djinni::valdi"), o match { case p: MPrimitive => p.idlName match { case "i8" => "I8" case "i16" => "I16" @@ -174,7 +174,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { // val fullyQualifiedName = withWasmNamespace(idJs.ty(ident)) val fullyQualifiedName = idJs.ty(ident) writeHppFileGeneric(spec.composerOutFolder.get, helperNamespace(), composerFilenameStyle)(ident.name, origin, refs.hpp, Nil, (w => { - w.wl(s"using $helper = ::djinni::composer::Enum<$cls>;") + w.wl(s"using $helper = ::djinni::valdi::Enum<$cls>;") }), (w => {})) } @@ -189,11 +189,11 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { writeHppFileGeneric(spec.composerOutFolder.get, helperNamespace(), composerFilenameStyle)(ident.name, origin, refs.hpp, Nil, (w => { w.wl(s"struct $helper").bracedSemi { w.wl(s"using CppType = $cls;") - w.wl("using ComposerType = Valdi:: Value;") + w.wl("using ValdiType = Valdi:: Value;") w.wl(s"using Boxed = $helper;") w.wl - w.wl("static CppType toCpp(const ComposerType& v);") - w.wl("static ComposerType fromCpp(const CppType& c);") + w.wl("static CppType toCpp(const ValdiType& v);") + w.wl("static ValdiType fromCpp(const CppType& c);") w.wl w.wl("static const Valdi::ValueSchema& schema() noexcept;") } @@ -201,7 +201,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { writeCppFileGeneric(spec.composerOutFolder.get, helperNamespace(), composerFilenameStyle, spec.composerIncludePrefix) (ident.name, origin, refs.cpp, (w => { w.wl("using namespace Valdi;") w.wl - w.w(s"auto $helper::toCpp(const ComposerType& v) -> CppType").braced { + w.w(s"auto $helper::toCpp(const ValdiType& v) -> CppType").braced { w.wl("auto o = v.getTypedObjectRef();") var nextIdx = 0; writeAlignedCall(w, "return {", r.fields, "}", f => { @@ -211,7 +211,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { }) w.wl(";") } - w.w(s"auto $helper::fromCpp(const CppType& c) -> ComposerType").braced { + w.w(s"auto $helper::fromCpp(const CppType& c) -> ValdiType").braced { w.wl("auto o = ValueTypedObject::make(schema().getClassRef(),").bracedEnd(");"){ for (f <- r.fields) { w.wl(s"${helperClass(f.ty.resolved)}::Boxed::fromCpp(${cppMarshal.maybeMove("c." + idCpp.field(f.ident), f.ty)}),") @@ -245,7 +245,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { val cls = withNs(Some(spec.cppNamespace), idCpp.ty(ident)) val helper = helperClass(ident) writeHppFileGeneric(spec.composerOutFolder.get, helperNamespace(), composerFilenameStyle)(ident.name, origin, refs.hpp, Nil, (w => { - w.w(s"struct $helper : ::djinni::composer::JsInterface<$cls, $helper>").bracedSemi { + w.w(s"struct $helper : ::djinni::valdi::JsInterface<$cls, $helper>").bracedSemi { w.wl("static void registerSchema(bool resolve) noexcept;") w.wl("static const Valdi::ValueSchema& schemaRef() noexcept;") w.wl("static const Valdi::ValueSchema& schema() noexcept;") @@ -257,8 +257,8 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { // js proxy if (i.ext.js) { - w.w(s"struct ComposerProxy: $cls, ::djinni::composer::ComposerProxyBase").bracedSemi { - w.wl("ComposerProxy(Valdi::Ref js) : ComposerProxyBase(js) {}") + w.w(s"struct ValdiProxy: $cls, ::djinni::valdi::ValdiProxyBase").bracedSemi { + w.wl("ValdiProxy(Valdi::Ref js) : ValdiProxyBase(js) {}") for (m <- i.methods.filter(m => !m.static)) { w.w(s"${cppMarshal.fqReturnType(m.ret)} ${idCpp.method(m.ident)}(") w.w(m.params.map(p => { @@ -320,10 +320,10 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { w.w(s"Ref $helper::toComposer(const CppOptType& c)").braced{ w.w("auto o = ValueTypedObject::make(schema().getClassRef(),").bracedEnd(");") { for (m <- i.methods.filter(m => !m.static)) { - w.wl(s"""djinni::composer::tsFunc<${exceptionHandlingTraits(m)}>(std::bind(shim::${idCpp.method(m.ident)}, c, _1)),""") + w.wl(s"""djinni::valdi::tsFunc<${exceptionHandlingTraits(m)}>(std::bind(shim::${idCpp.method(m.ident)}, c, _1)),""") } } - w.wl("return makeShared>(o, c);") + w.wl("return makeShared>(o, c);") } } //value schema @@ -345,7 +345,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { w.wl(s"${t}::registerSchema(resolve);") } w.wl("static bool flag[2] = {false, false};") - w.wl("if (std::exchange(flag[resolve ? 1 : 0], true) == false) { djinni::composer::registerSchemaImpl(unresolvedSchema(), resolve); }") + w.wl("if (std::exchange(flag[resolve ? 1 : 0], true) == false) { djinni::valdi::registerSchemaImpl(unresolvedSchema(), resolve); }") } // type reference w.w(s"const ValueSchema& $helper::schemaRef() noexcept").braced { @@ -353,14 +353,14 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { w.wl("return ref;") } w.w(s"const ValueSchema& $helper::schema() noexcept").braced { - w.wl(s"static auto schema = djinni::composer::getResolvedSchema<$helper>(schemaName());") + w.wl(s"static auto schema = djinni::valdi::getResolvedSchema<$helper>(schemaName());") w.wl("return schema;") } // js proxy if (i.ext.js) { var idx = 0 for (m <- i.methods.filter(m => !m.static)) { - w.w(s"${cppMarshal.fqReturnType(m.ret)} $helper::ComposerProxy::${idCpp.method(m.ident)}(") + w.w(s"${cppMarshal.fqReturnType(m.ret)} $helper::ValdiProxy::${idCpp.method(m.ident)}(") w.w(m.params.map(p => { s"${cppMarshal.fqParamType(p.ty)} ${idCpp.local(p.ident)}" }).mkString(",")) @@ -395,10 +395,10 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) { } } } - w.wl(s"auto staticSchema = djinni::composer::resolveSchema(unresolvedStaticSchema, [] { registerSchema(false); registerSchema(true);} );") + w.wl(s"auto staticSchema = djinni::valdi::resolveSchema(unresolvedStaticSchema, [] { registerSchema(false); registerSchema(true);} );") w.w(s"""(*m)[STRING_LITERAL("${idJs.ty(ident)}")] = Value(ValueTypedObject::make(staticSchema.getClassRef(),""").bracedEnd("));") { for (m <- staticMethods) { - w.wl(s"""djinni::composer::tsFunc<${exceptionHandlingTraits(m)}>(shim::${idCpp.method(m.ident)}),""") + w.wl(s"""djinni::valdi::tsFunc<${exceptionHandlingTraits(m)}>(shim::${idCpp.method(m.ident)}),""") } } } diff --git a/src/source/ast.scala b/src/source/ast.scala index 4849ec7e..771e3b0a 100644 --- a/src/source/ast.scala +++ b/src/source/ast.scala @@ -51,7 +51,7 @@ case class InternTypeDecl(override val ident: Ident, override val params: Seq[Ty case class ExternTypeDecl(override val ident: Ident, override val params: Seq[TypeParam], override val body: TypeDef, properties: Map[String, Any], override val origin: String) extends TypeDecl case class ProtobufTypeDecl(override val ident: Ident, override val params: Seq[TypeParam], override val body: TypeDef, override val origin: String) extends TypeDecl -// `Ext.js` is shared by both wasm and composer +// `Ext.js` is shared by both wasm and valdi case class Ext(java: Boolean, cpp: Boolean, objc: Boolean, js: Boolean, swift: Boolean) { def any(): Boolean = { java || cpp || objc || js || swift diff --git a/support-lib/composer/DataRef_composer.cpp b/support-lib/composer/DataRef_valdi.cpp similarity index 98% rename from support-lib/composer/DataRef_composer.cpp rename to support-lib/composer/DataRef_valdi.cpp index 68000dc8..0103ace1 100644 --- a/support-lib/composer/DataRef_composer.cpp +++ b/support-lib/composer/DataRef_valdi.cpp @@ -15,10 +15,10 @@ */ #include "../cpp/DataRef.hpp" -#include "DataRef_composer.hpp" +#include "DataRef_valdi.hpp" #include -namespace djinni::composer { +namespace djinni::valdi { struct ComposerDataObject: Valdi::ComposerObject { COMPOSER_CLASS_HEADER(ComposerDataObject); diff --git a/support-lib/composer/DataRef_composer.hpp b/support-lib/composer/DataRef_valdi.hpp similarity index 80% rename from support-lib/composer/DataRef_composer.hpp rename to support-lib/composer/DataRef_valdi.hpp index 1399a58c..1744d636 100644 --- a/support-lib/composer/DataRef_composer.hpp +++ b/support-lib/composer/DataRef_valdi.hpp @@ -16,18 +16,18 @@ #pragma once -#include "djinni_composer.hpp" +#include "djinni_valdi.hpp" #include "../cpp/DataRef.hpp" -namespace djinni::composer { +namespace djinni::valdi { struct NativeDataRef { using CppType = DataRef; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = NativeDataRef; - static CppType toCpp(const ComposerType& v); - static ComposerType fromCpp(const CppType& c); + static CppType toCpp(const ValdiType& v); + static ValdiType fromCpp(const CppType& c); static const Valdi::ValueSchema& schema(); }; diff --git a/support-lib/composer/DataView_composer.hpp b/support-lib/composer/DataView_valdi.hpp similarity index 86% rename from support-lib/composer/DataView_composer.hpp rename to support-lib/composer/DataView_valdi.hpp index 50940b20..34fdc053 100644 --- a/support-lib/composer/DataView_composer.hpp +++ b/support-lib/composer/DataView_valdi.hpp @@ -16,23 +16,23 @@ #pragma once -#include "djinni_composer.hpp" +#include "djinni_valdi.hpp" #include "../cpp/DataView.hpp" -namespace djinni::composer { +namespace djinni::valdi { struct NativeDataView { using CppType = DataView; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = NativeDataView; - static CppType toCpp(const ComposerType& v) { + static CppType toCpp(const ValdiType& v) { auto arr = v.getTypedArrayRef(); const auto& buf = arr->getBuffer(); return DataView(buf.data(), buf.size()); } - static ComposerType fromCpp(const CppType& c) { + static ValdiType fromCpp(const CppType& c) { Valdi::BytesView buf(nullptr, c.buf(), c.len()); auto arr = Valdi::makeShared(Valdi::kDefaultTypedArrayType, buf); return Valdi::Value(arr); diff --git a/support-lib/composer/Future_composer.hpp b/support-lib/composer/Future_valdi.hpp similarity index 94% rename from support-lib/composer/Future_composer.hpp rename to support-lib/composer/Future_valdi.hpp index a187fb57..529a1008 100644 --- a/support-lib/composer/Future_composer.hpp +++ b/support-lib/composer/Future_valdi.hpp @@ -16,11 +16,11 @@ #pragma once -#include "djinni_composer.hpp" +#include "djinni_valdi.hpp" #include "../cpp/Future.hpp" #include "composer_core/cpp/Utils/ResolvablePromise.hpp" -namespace djinni::composer { +namespace djinni::valdi { template class FutureAdaptor @@ -29,13 +29,13 @@ class FutureAdaptor public: using CppType = Future; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = FutureAdaptor; using NativePromiseType = Promise; - static CppType toCpp(ComposerType o) + static CppType toCpp(ValdiType o) { auto composerPromise = castOrNull(o.getComposerObject()); auto cppPromise = Valdi::makeShared>(); @@ -54,7 +54,7 @@ class FutureAdaptor return cppFuture; } - static ComposerType fromCpp(CppType c) + static ValdiType fromCpp(CppType c) { auto composerPromise = Valdi::makeShared(); c.then([composerPromise] (Future f) { diff --git a/support-lib/composer/Outcome_composer.hpp b/support-lib/composer/Outcome_valdi.hpp similarity index 84% rename from support-lib/composer/Outcome_composer.hpp rename to support-lib/composer/Outcome_valdi.hpp index 576fa3cc..fd788ace 100644 --- a/support-lib/composer/Outcome_composer.hpp +++ b/support-lib/composer/Outcome_valdi.hpp @@ -16,24 +16,24 @@ #pragma once -#include "djinni_composer.hpp" +#include "djinni_valdi.hpp" #include "../cpp/expected.hpp" -namespace djinni::composer { +namespace djinni::valdi { template class Outcome { using ResultCppType = typename RESULT::CppType; using ErrorCppType = typename ERROR::CppType; - using ResultComposerType = typename RESULT::Boxed::ComposerType; - using ErrorComposerType = typename ERROR::Boxed::ComposerType; + using ResultValdiType = typename RESULT::Boxed::ValdiType; + using ErrorValdiType = typename ERROR::Boxed::ValdiType; public: using CppType = expected; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = Outcome; - static CppType toCpp(ComposerType v) + static CppType toCpp(ValdiType v) { auto outcomeCpp = castOrNull(v.getComposerObject()); if (outcomeCpp->error.isUndefined()) { @@ -43,7 +43,7 @@ class Outcome } } - static ComposerType fromCpp(const CppType& c) + static ValdiType fromCpp(const CppType& c) { auto outcomeCpp = Valdi::makeShared(); if (c.has_value()) { diff --git a/support-lib/composer/djinni_composer.cpp b/support-lib/composer/djinni_valdi.cpp similarity index 87% rename from support-lib/composer/djinni_composer.cpp rename to support-lib/composer/djinni_valdi.cpp index 597a818a..5d3eb249 100644 --- a/support-lib/composer/djinni_composer.cpp +++ b/support-lib/composer/djinni_valdi.cpp @@ -14,15 +14,15 @@ * limitations under the License. */ -#include "djinni_composer.hpp" +#include "djinni_valdi.hpp" #include "composer_core/cpp/Utils/ValueTypedArray.hpp" -namespace djinni::composer { +namespace djinni::valdi { using namespace Valdi; -std::unordered_map> jsProxyCache; +std::unordered_map> jsProxyCache; std::unordered_map cppProxyCache; std::mutex jsProxyCacheMutex; std::mutex cppProxyCacheMutex; @@ -54,13 +54,13 @@ void registerSchemaImpl(const ValueSchema& schema, bool resolve) noexcept { } } -Binary::CppType Binary::toCpp(const Binary::ComposerType& v) noexcept { +Binary::CppType Binary::toCpp(const Binary::ValdiType& v) noexcept { auto a = v.getTypedArrayRef(); auto buffer = a->getBuffer(); return CppType(buffer.begin(), buffer.end()); } -Binary::ComposerType Binary::fromCpp(const Binary::CppType& c) noexcept { +Binary::ValdiType Binary::fromCpp(const Binary::CppType& c) noexcept { auto bytes = makeShared(); bytes->assignData(c.data(), c.size()); auto va = makeShared(TypedArrayType::Uint8Array, bytes); @@ -72,12 +72,12 @@ const ValueSchema& Binary::schema() noexcept { return schema; } -Date::CppType Date::toCpp(const Date::ComposerType& v) noexcept { +Date::CppType Date::toCpp(const Date::ValdiType& v) noexcept { auto millisecondsSinceEpoch = std::chrono::milliseconds(static_cast(v.toDouble())); return CppType(std::chrono::duration_cast(millisecondsSinceEpoch)); } -Date::ComposerType Date::fromCpp(const Date::CppType& c) noexcept { +Date::ValdiType Date::fromCpp(const Date::CppType& c) noexcept { auto millisecondsSinceEpoch = std::chrono::duration_cast(c.time_since_epoch()); return Valdi::Value(static_cast(millisecondsSinceEpoch.count())); } diff --git a/support-lib/composer/djinni_composer.hpp b/support-lib/composer/djinni_valdi.hpp similarity index 86% rename from support-lib/composer/djinni_composer.hpp rename to support-lib/composer/djinni_valdi.hpp index 43719e4d..62168b77 100644 --- a/support-lib/composer/djinni_composer.hpp +++ b/support-lib/composer/djinni_valdi.hpp @@ -40,7 +40,7 @@ #include #include -namespace djinni::composer { +namespace djinni::valdi { // -------- Helper functions and classes class JsException : public std::runtime_error { @@ -117,15 +117,15 @@ template class Primitive { public: using CppType = T; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = Primitive; - static CppType toCpp(const ComposerType& v) noexcept { + static CppType toCpp(const ValdiType& v) noexcept { return static_cast(v.to()); } - static ComposerType fromCpp(const CppType& c) noexcept { - return ComposerType(static_cast(c)); + static ValdiType fromCpp(const CppType& c) noexcept { + return ValdiType(static_cast(c)); } static const Valdi::ValueSchema& schema() noexcept { static auto schema = Valdi::ValueSchema::primitiveType(); @@ -151,11 +151,11 @@ class WString { using Utf16Converter = std::wstring_convert>; public: using CppType = std::wstring; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = WString; - static CppType toCpp(const ComposerType& v) { + static CppType toCpp(const ValdiType& v) { if (v.isInternedString()) { auto utf8str = v.toStringBox().toStringView(); return Utf8Converter{}.from_bytes(utf8str.data(), utf8str.data() + utf8str.size()); @@ -170,8 +170,8 @@ class WString { } } } - static ComposerType fromCpp(const CppType& c) { - return ComposerType(Utf8Converter{}.to_bytes(c)); + static ValdiType fromCpp(const CppType& c) { + return ValdiType(Utf8Converter{}.to_bytes(c)); } static const Valdi::ValueSchema& schema() noexcept { static auto schema = Valdi::ValueSchema::string(); @@ -183,22 +183,22 @@ class WString { class Binary { public: using CppType = std::vector; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = Binary; - static CppType toCpp(const ComposerType& j) noexcept; - static ComposerType fromCpp(const CppType& c) noexcept; + static CppType toCpp(const ValdiType& j) noexcept; + static ValdiType fromCpp(const CppType& c) noexcept; static const Valdi::ValueSchema& schema() noexcept ; }; class Date { public: using CppType = std::chrono::system_clock::time_point; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = Date; - static CppType toCpp(const ComposerType& v) noexcept; - static ComposerType fromCpp(const CppType& c) noexcept; + static CppType toCpp(const ValdiType& v) noexcept; + static ValdiType fromCpp(const CppType& c) noexcept; static const Valdi::ValueSchema& schema() noexcept; }; @@ -209,24 +209,24 @@ struct Optional { template static typename C::CppOptType opt_type(typename C::CppOptType*); using CppType = decltype(opt_type(nullptr)); - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = Optional; - static CppType toCpp(const ComposerType& j) { + static CppType toCpp(const ValdiType& j) { if (j.isUndefined() || j.isNull()) { return CppType{}; } else { return T::Boxed::toCpp(j); } } - static ComposerType fromCpp(const OptionalType& c) { + static ValdiType fromCpp(const OptionalType& c) { return c ? T::Boxed::fromCpp(*c) : Valdi::Value::undefined(); } - static ComposerType fromCpp(OptionalType&& c) { + static ValdiType fromCpp(OptionalType&& c) { return c ? T::Boxed::fromCpp(std::move(*c)) : Valdi::Value::undefined(); } template - static ComposerType fromCpp(const typename C::CppOptType& cppOpt) { + static ValdiType fromCpp(const typename C::CppOptType& cppOpt) { return T::Boxed::fromCppOpt(cppOpt); } static const Valdi::ValueSchema& schema() noexcept { @@ -238,11 +238,11 @@ struct Optional { template class List { using ECppType = typename T::CppType; - using EComposerType = typename T::Boxed::ComposerType; + using EValdiType = typename T::Boxed::ValdiType; public: using CppType = std::vector; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = List; static const Valdi::ValueSchema& schema() noexcept { @@ -250,7 +250,7 @@ class List { return schema; } - static CppType toCpp(const ComposerType& v) { + static CppType toCpp(const ValdiType& v) { CppType c; const auto* a = v.getArray(); if (a != nullptr) { @@ -261,7 +261,7 @@ class List { } return c; } - static ComposerType fromCpp(const CppType& c) { + static ValdiType fromCpp(const CppType& c) { auto newArray = Valdi::ValueArray::make(c.size()); for (size_t i = 0; i < c.size(); ++i) { (*newArray)[i] = T::Boxed::fromCpp(c[i]); @@ -273,13 +273,13 @@ class List { template class Set { using ECppType = typename T::CppType; - using EComposerType = typename T::Boxed::ComposerType; + using EValdiType = typename T::Boxed::ValdiType; public: using CppType = std::unordered_set; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = Set; - static CppType toCpp(const ComposerType& v) { + static CppType toCpp(const ValdiType& v) { auto es6set = castOrNull(v.getComposerObject()); CppType cppSet; for (auto i = es6set->entries.begin(); i != es6set->entries.end(); i++) { @@ -287,7 +287,7 @@ class Set { } return cppSet; } - static ComposerType fromCpp(const CppType& c) { + static ValdiType fromCpp(const CppType& c) { auto es6set = Valdi::makeShared(); for (const auto& k: c) { es6set->entries.push_back(T::fromCpp(k)); @@ -304,14 +304,14 @@ template class Map { using CppKeyType = typename Key::CppType; using CppValueType = typename Value::CppType; - using ComposerKeyType = typename Key::Boxed::ComposerType; - using ComposerValueType = typename Value::Boxed::ComposerType; + using ComposerKeyType = typename Key::Boxed::ValdiType; + using ComposerValueType = typename Value::Boxed::ValdiType; public: using CppType = std::unordered_map; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = Map; - static CppType toCpp(const ComposerType& v) { + static CppType toCpp(const ValdiType& v) { auto es6map = castOrNull(v.getComposerObject()); CppType cppMap; for (auto i = es6map->entries.begin(); i != es6map->entries.end();) { @@ -321,7 +321,7 @@ class Map { } return cppMap; } - static ComposerType fromCpp(const CppType& c) { + static ValdiType fromCpp(const CppType& c) { auto es6Map = Valdi::makeShared(); for (const auto& [k, v]: c) { es6Map->entries.push_back(Key::fromCpp(k)); @@ -338,7 +338,7 @@ class Map { class Void { public: using CppType = void; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = Void; static const Valdi::ValueSchema& schema() noexcept { static auto schema = Valdi::ValueSchema::untyped(); @@ -354,10 +354,10 @@ template class Protobuf { public: using CppType = CppProto; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = Protobuf; - static CppType toCpp(ComposerType v) + static CppType toCpp(ValdiType v) { auto array = v.getTypedArrayRef(); auto buffer = array->getBuffer(); @@ -366,7 +366,7 @@ class Protobuf { return ret; } - static ComposerType fromCpp(const CppType& c) + static ValdiType fromCpp(const CppType& c) { std::vector cbuf(c.ByteSizeLong()); c.SerializeToArray(cbuf.data(), static_cast(cbuf.size())); @@ -386,13 +386,13 @@ class Protobuf { template struct Array { using CppType = std::vector; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = Array; - static CppType toCpp(const ComposerType& v) { + static CppType toCpp(const ValdiType& v) { return List::toCpp(v); } - static ComposerType fromCpp(const CppType& c) { + static ValdiType fromCpp(const CppType& c) { return List::fromCpp(c); } @@ -404,11 +404,11 @@ struct Array { template > struct PrimitiveArray { using CppType = std::vector; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = PrimitiveArray; using CppElemType = typename T::CppType; - static CppType toCpp(const ComposerType& v) noexcept { + static CppType toCpp(const ValdiType& v) noexcept { auto arr = v.getTypedArrayRef(); const auto* bytes = arr->getBuffer().data(); const auto byteSize = arr->getBuffer().size(); @@ -416,7 +416,7 @@ struct PrimitiveArray { const auto typedSize = byteSize / sizeof(CppElemType); return CppType(typedData, typedData + typedSize); } - static ComposerType fromCpp(const CppType& c) noexcept { + static ValdiType fromCpp(const CppType& c) noexcept { auto bytes = Valdi::makeShared(); bytes->assignData(reinterpret_cast(c.data()), c.size() * sizeof(CppElemType)); auto arr = Valdi::makeShared(U::getArrayType(), bytes); @@ -463,26 +463,26 @@ struct Array : PrimitiveArray { }; // -------- Interface support -using ComposerProxyId = uint32_t; +using ValdiProxyId = uint32_t; struct CppProxyCacheEntry { Valdi::Weak ref; int count; }; -class ComposerProxyBase; -extern std::unordered_map> jsProxyCache; +class ValdiProxyBase; +extern std::unordered_map> jsProxyCache; extern std::unordered_map cppProxyCache; extern std::mutex jsProxyCacheMutex; extern std::mutex cppProxyCacheMutex; -class ComposerProxyBase { +class ValdiProxyBase { protected: Valdi::Ref _js; std::vector> _methods; public: - ComposerProxyBase(Valdi::Ref js) + ValdiProxyBase(Valdi::Ref js) : _js(js), _methods(_js->getTypedObject()->getPropertiesSize()) {} - virtual ~ComposerProxyBase() { + virtual ~ValdiProxyBase() { std::lock_guard lk(jsProxyCacheMutex); jsProxyCache.erase(_js->getId()); } @@ -536,17 +536,17 @@ class JsInterface { public: using CppType = std::shared_ptr; using CppOptType = std::shared_ptr; - using ComposerType = Valdi::Value; + using ValdiType = Valdi::Value; using Boxed = Self; - static CppType toCpp(const ComposerType& v) { + static CppType toCpp(const ValdiType& v) { return _fromJs(v); } - static ComposerType fromCppOpt(const CppOptType& c) { + static ValdiType fromCppOpt(const CppOptType& c) { return {_toJs(c)}; } - static ComposerType fromCpp(const CppType& c) { - ::djinni::composer::checkForNull(c.get(), typeid(Self).name()); + static ValdiType fromCpp(const CppType& c) { + ::djinni::valdi::checkForNull(c.get(), typeid(Self).name()); return fromCppOpt(c); } @@ -559,23 +559,23 @@ class JsInterface { } }; template - struct GetOrCreateJsProxy> { + struct GetOrCreateJsProxy> { std::shared_ptr operator()(const Valdi::Value& js) noexcept { auto proxy = js.getTypedProxyObjectRef(); auto obj = proxy->getTypedObject(); std::lock_guard lk(jsProxyCacheMutex); // check prsence of proxy id in js object - ComposerProxyId id = proxy->getId(); + ValdiProxyId id = proxy->getId(); auto i = jsProxyCache.find(id); if (i != jsProxyCache.end()) { auto strongProxyRef = i->second.lock(); if (strongProxyRef != nullptr) { - return std::dynamic_pointer_cast(strongProxyRef); + return std::dynamic_pointer_cast(strongProxyRef); } } // not found or cache entry expired // create new js proxy and store it in cache - auto newproxy = std::make_shared(proxy); + auto newproxy = std::make_shared(proxy); jsProxyCache.emplace(id, newproxy); return newproxy; } @@ -634,7 +634,7 @@ class JsInterface { if (c == nullptr) { // null object return Valdi::Value::undefined(); - } else if (auto* p = dynamic_cast(c.get())) { + } else if (auto* p = dynamic_cast(c.get())) { // unwrap existing js proxy return Valdi::Value(p->getProxy()); } else { diff --git a/support-lib/dataref.yaml b/support-lib/dataref.yaml index e32bf8c4..c062a75e 100644 --- a/support-lib/dataref.yaml +++ b/support-lib/dataref.yaml @@ -34,8 +34,8 @@ ts: typename: 'Uint8Array' module: '' composer: - translator: '::djinni::composer::NativeDataRef' - header: '"$DataRef_composer.hpp"' + translator: '::djinni::valdi::NativeDataRef' + header: '"$DataRef_valdi.hpp"' swift: typename: 'NSData' module: 'Foundation' diff --git a/support-lib/dataview.yaml b/support-lib/dataview.yaml index 8d9dea9e..8dc0a2b6 100644 --- a/support-lib/dataview.yaml +++ b/support-lib/dataview.yaml @@ -34,8 +34,8 @@ ts: typename: 'Uint8Array' module: '' composer: - translator: '::djinni::composer::NativeDataView' - header: '"$DataView_composer.hpp"' + translator: '::djinni::valdi::NativeDataView' + header: '"$DataView_valdi.hpp"' swift: typename: 'NSData' module: 'Foundation' diff --git a/support-lib/future.yaml b/support-lib/future.yaml index 61286327..67643711 100644 --- a/support-lib/future.yaml +++ b/support-lib/future.yaml @@ -37,8 +37,8 @@ ts: module: '' generic: true composer: - translator: '::djinni::composer::FutureAdaptor' - header: '"$Future_composer.hpp"' + translator: '::djinni::valdi::FutureAdaptor' + header: '"$Future_valdi.hpp"' swift: typename: 'DJFuture' module: 'DjinniSupport' diff --git a/support-lib/outcome.yaml b/support-lib/outcome.yaml index ae875e0a..a7e57990 100644 --- a/support-lib/outcome.yaml +++ b/support-lib/outcome.yaml @@ -37,8 +37,8 @@ ts: module: '@djinni_support/Outcome' generic: true composer: - translator: '::djinni::composer::Outcome' - header: '"$Outcome_composer.hpp"' + translator: '::djinni::valdi::Outcome' + header: '"$Outcome_valdi.hpp"' swift: typename: 'Result' generic: true