Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/source/ComposerGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 _ =>
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 => {}))
}

Expand All @@ -189,19 +189,19 @@ 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;")
}
}), (w => {}))
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 => {
Expand All @@ -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)}),")
Expand Down Expand Up @@ -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;")
Expand All @@ -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<Valdi::ValueTypedProxyObject> js) : ComposerProxyBase(js) {}")
w.w(s"struct ValdiProxy: $cls, ::djinni::valdi::ValdiProxyBase").bracedSemi {
w.wl("ValdiProxy(Valdi::Ref<Valdi::ValueTypedProxyObject> 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 => {
Expand Down Expand Up @@ -320,10 +320,10 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
w.w(s"Ref<ValueTypedProxyObject> $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<djinni::composer::DjinniCppProxyObject<CppType::element_type>>(o, c);")
w.wl("return makeShared<djinni::valdi::DjinniCppProxyObject<CppType::element_type>>(o, c);")
}
}
//value schema
Expand All @@ -345,22 +345,22 @@ 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 {
w.wl("static auto ref = ValueSchema::typeReference(ValueSchemaTypeReference::named(schemaName()));")
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(","))
Expand Down Expand Up @@ -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)}),""")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/source/ast.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/

#include "../cpp/DataRef.hpp"
#include "DataRef_composer.hpp"
#include "DataRef_valdi.hpp"
#include <variant>

namespace djinni::composer {
namespace djinni::valdi {

struct ComposerDataObject: Valdi::ComposerObject {
COMPOSER_CLASS_HEADER(ComposerDataObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::ValueTypedArray>(Valdi::kDefaultTypedArrayType, buf);
return Valdi::Value(arr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 RESULT>
class FutureAdaptor
Expand All @@ -29,13 +29,13 @@ class FutureAdaptor

public:
using CppType = Future<CppResType>;
using ComposerType = Valdi::Value;
using ValdiType = Valdi::Value;

using Boxed = FutureAdaptor;

using NativePromiseType = Promise<CppResType>;

static CppType toCpp(ComposerType o)
static CppType toCpp(ValdiType o)
{
auto composerPromise = castOrNull<Valdi::Promise>(o.getComposerObject());
auto cppPromise = Valdi::makeShared<Promise<CppResType>>();
Expand All @@ -54,7 +54,7 @@ class FutureAdaptor
return cppFuture;
}

static ComposerType fromCpp(CppType c)
static ValdiType fromCpp(CppType c)
{
auto composerPromise = Valdi::makeShared<Valdi::ResolvablePromise>();
c.then([composerPromise] (Future<CppResType> f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 RESULT, class ERROR>
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<ResultCppType, ErrorCppType>;
using ComposerType = Valdi::Value;
using ValdiType = Valdi::Value;
using Boxed = Outcome;

static CppType toCpp(ComposerType v)
static CppType toCpp(ValdiType v)
{
auto outcomeCpp = castOrNull<Valdi::ComposerOutcome>(v.getComposerObject());
if (outcomeCpp->error.isUndefined()) {
Expand All @@ -43,7 +43,7 @@ class Outcome
}
}

static ComposerType fromCpp(const CppType& c)
static ValdiType fromCpp(const CppType& c)
{
auto outcomeCpp = Valdi::makeShared<Valdi::ComposerOutcome>();
if (c.has_value()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ComposerProxyId, std::weak_ptr<ComposerProxyBase>> jsProxyCache;
std::unordered_map<ValdiProxyId, std::weak_ptr<ValdiProxyBase>> jsProxyCache;
std::unordered_map<void*, CppProxyCacheEntry> cppProxyCache;
std::mutex jsProxyCacheMutex;
std::mutex cppProxyCacheMutex;
Expand Down Expand Up @@ -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>();
bytes->assignData(c.data(), c.size());
auto va = makeShared<ValueTypedArray>(TypedArrayType::Uint8Array, bytes);
Expand All @@ -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<int64_t>(v.toDouble()));
return CppType(std::chrono::duration_cast<std::chrono::system_clock::duration>(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<std::chrono::milliseconds>(c.time_since_epoch());
return Valdi::Value(static_cast<double>(millisecondsSinceEpoch.count()));
}
Expand Down
Loading