Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
li-feng-sc committed Aug 15, 2024
1 parent 9c687a2 commit eedf683
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
32 changes: 16 additions & 16 deletions src/source/SwiftGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) {
}
})
writeSwiftPrivateFile(ident, origin, List[String]("DjinniSupport", spec.swiftModule), w => {
w.wl(s"typealias ${marshal.typename(ident, e)}Marshaller = DjinniSupport.EnumMarshaller<${marshal.typename(ident, e)}>")
w.wl(s"public typealias ${marshal.typename(ident, e)}Marshaller = DjinniSupport.EnumMarshaller<${marshal.typename(ident, e)}>")
})
}

Expand Down Expand Up @@ -206,9 +206,9 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) {
}
})
writeSwiftPrivateFile(ident, origin, refs.privateImports, w => {
w.w(s"enum ${marshal.typename(ident, r)}Marshaller: DjinniSupport.Marshaller").braced {
w.wl(s"typealias SwiftType = ${marshal.fqTypename(ident, r)}")
w.w("static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced {
w.w(s"public enum ${marshal.typename(ident, r)}Marshaller: DjinniSupport.Marshaller").braced {
w.wl(s"public typealias SwiftType = ${marshal.fqTypename(ident, r)}")
w.w("public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced {
w.wl("return withUnsafePointer(to: c) { p in").nested {
for ((f, i) <- r.fields.view.zipWithIndex) {
val swiftExp = s"djinni.swift.getMember(p, $i)"
Expand All @@ -219,7 +219,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) {
}
w.wl("}")
}
w.w("static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced {
w.w("public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced {
if (r.fields.nonEmpty) {
w.wl("var ret = djinni.swift.makeCompositeValue()")
for (f <- r.fields) {
Expand Down Expand Up @@ -267,12 +267,12 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) {
if (m.params.nonEmpty) { w.w("_ ") }
w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.fqParamType(p.ty)}").mkString(", "))
w.w(s") throws -> ${marshal.fqReturnType(m.ret)}").braced {
w.wl("var params = djinni.swift.ParameterList()")
w.wl("params.addValue(inst)")
w.wl("var _params = djinni.swift.ParameterList()")
w.wl("_params.addValue(inst)")
for (p <- m.params) {
w.wl(s"params.addValue(${marshal.toCpp(p.ty, idSwift.local(p.ident))})")
w.wl(s"_params.addValue(${marshal.toCpp(p.ty, idSwift.local(p.ident))})")
}
w.wl(s"var ret = ${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(&params)")
w.wl(s"var ret = ${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(&_params)")
w.wl("try handleCppErrors(&ret)")
if (!m.ret.isEmpty) {
w.wl(s"return ${marshal.fromCpp(m.ret.get, "ret")}")
Expand Down Expand Up @@ -310,13 +310,13 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) {
w.wl
}
// Define the marshaller
w.w(s"enum ${marshal.typename(ident, i)}Marshaller: DjinniSupport.Marshaller").braced {
w.wl(s"typealias SwiftType = ${marshal.fqTypename(ident, i)}")
w.w("static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced {
w.w(s"public enum ${marshal.typename(ident, i)}Marshaller: DjinniSupport.Marshaller").braced {
w.wl(s"public typealias SwiftType = ${marshal.fqTypename(ident, i)}")
w.w("public static func fromCpp(_ c: djinni.swift.AnyValue) -> SwiftType").braced {
val newProxyBlock = if (i.ext.cpp) {s"{ ${marshal.typename(ident, i)}CppProxy(c) as SwiftType }"} else {"{ fatalError(\"n/a\") }"}
w.wl(s"return cppInterfaceToSwift(c, ${newProxyBlock})")
}
w.w("static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced {
w.w("public static func toCpp(_ s: SwiftType) -> djinni.swift.AnyValue").braced {
val newProxyBlock = if (i.ext.swift) {s"{ ${spec.swiftxxNamespace}.$swiftProxyClassName.make(ctxPtr(s, ${swiftProxyVtbl}), dispatcherProtocalCall)}"} else {"{ fatalError(\"n/a\") }"}
w.wl(s"return swiftInterfaceToCpp(s, ${newProxyBlock})")
}
Expand All @@ -330,11 +330,11 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) {
if (m.params.nonEmpty) { w.w("_ ") }
w.w(m.params.map(p => s"${idSwift.local(p.ident)}: ${marshal.fqParamType(p.ty)}").mkString(", "))
w.w(s") throws -> ${marshal.fqReturnType(m.ret)}").braced {
w.wl("var params = djinni.swift.ParameterList()")
w.wl("var _params = djinni.swift.ParameterList()")
for (p <- m.params) {
w.wl(s"params.addValue(${marshal.toCpp(p.ty, idSwift.local(p.ident))})")
w.wl(s"_params.addValue(${marshal.toCpp(p.ty, idSwift.local(p.ident))})")
}
w.wl(s"var ret = ${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(&params)")
w.wl(s"var ret = ${spec.swiftxxNamespace}.${marshal.typename(ident, i)}_${idSwift.method(m.ident)}(&_params)")
w.wl("try handleCppErrors(&ret)")
if (!m.ret.isEmpty) {
w.wl(s"return ${marshal.fromCpp(m.ret.get, "ret")}")
Expand Down
4 changes: 2 additions & 2 deletions src/source/SwiftMarshal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) {
case MOptional => throw new AssertionError("nested optional?")
case m => s"Optional<${f(arg)}>"
}
case e: MExtern => e.swift.typename + (if (e.swift.generic) args(tm) else "")
case e: MExtern => e.swift.module + "." + e.swift.typename + (if (e.swift.generic) args(tm) else "")
case p: MProtobuf => p.body.swift match {
case Some(o) => o.prefix + p.name
case None => p.name
Expand Down Expand Up @@ -102,7 +102,7 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) {
private def helperClass(tm: MExpr): String = helperName(tm) + helperTemplates(tm)
def helperName(tm: MExpr): String = tm.base match {
case d: MDef => helperClass(d.name)
case e: MExtern => e.swift.translator
case e: MExtern => e.swift.translatorModule + "." + e.swift.translator
case o => o match {
case p: MPrimitive => p.idlName match {
case "i8" => "I8Marshaller"
Expand Down
2 changes: 1 addition & 1 deletion src/source/YamlGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class YamlGenerator(spec: Spec) extends Generator(spec) {
)

private def typeDef(td: TypeDecl) = {
def ext(e: Ext): String = (if(e.cpp) " +c" else "") + (if(e.objc) " +o" else "") + (if(e.java) " +j" else "") + (if(e.js) " +w" else "")
def ext(e: Ext): String = (if(e.cpp) " +c" else "") + (if(e.objc) " +o" else "") + (if(e.java) " +j" else "") + (if(e.js) " +w" else "") + (if(e.swift) " +sw" else "")
def deriving(r: Record) = {
if(r.derivingTypes.isEmpty) {
""
Expand Down

0 comments on commit eedf683

Please sign in to comment.