Skip to content

Commit

Permalink
fixes for snap client integration
Browse files Browse the repository at this point in the history
  • Loading branch information
li-feng-sc committed Aug 29, 2024
1 parent eedf683 commit 6e986dd
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/source/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ object Main {
var swiftIdentStyle = IdentStyle.swiftDefault
var swiftxxOutFolder: Option[File] = None
var swiftxxNamespace: String = "djinni_generated"
var swiftxxIncludePrefix: String = ""
var swiftxxBaseLibModule: String = "DjinniSupportCxx"
var swiftxxClassIdentStyleOptional: Option[IdentConverter] = None
var swiftxxFileIdentStyleOptional: Option[IdentConverter] = None
Expand Down Expand Up @@ -306,6 +307,8 @@ object Main {
.text("Swift module name (default: \"Module\").")
opt[File]("swiftxx-out").valueName("<out-folder>").foreach(x => swiftxxOutFolder = Some(x))
.text("The output folder for private Swift/C++ interop files (Generator disabled if unspecified).")
opt[String]("swiftxx-include-prefix").valueName("<prefix>").foreach(swiftxxIncludePrefix = _)
.text("The prefix for #includes of Swift C++ header files.")
opt[String]("swiftxx-include-cpp-prefix").valueName("<prefix>").foreach(swiftxxIncludeCppPrefix = _)
.text("The prefix for #includes of the main header files from Swift C++ files.")
opt[String]("swiftxx-base-lib-include-prefix").valueName("...").foreach(x => swiftxxBaseLibIncludePrefix = x)
Expand Down Expand Up @@ -522,6 +525,7 @@ object Main {
swiftModule,
swiftxxOutFolder,
swiftxxNamespace,
swiftxxIncludePrefix,
swiftxxBaseLibModule,
swiftxxClassIdentStyle,
swiftxxFileIdentStyle,
Expand Down
4 changes: 2 additions & 2 deletions src/source/SwiftGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) {

class SwiftRefs(name: String) {
var swiftImports = mutable.TreeSet[String]()
var privateImports = mutable.TreeSet[String]("DjinniSupport", "Foundation",spec.swiftxxBaseLibModule, spec.swiftModule, spec.swiftModule + "Cxx")
var privateImports = mutable.TreeSet[String]("DjinniSupport", "Foundation", spec.swiftxxBaseLibModule, spec.swiftModule, spec.swiftModule + "Cxx")
swiftImports.add("Foundation")
def find(ty: TypeRef) { find(ty.resolved) }
def find(tm: MExpr) {
Expand Down Expand Up @@ -326,7 +326,7 @@ class SwiftGenerator(spec: Spec) extends Generator(spec) {
if (!staticMethods.isEmpty) {
w.w(s"public class ${marshal.typename(ident, i)}_statics").braced {
for (m <- staticMethods) {
w.w(s"static func ${swiftMethodName(m.ident)}(")
w.w(s"public static func ${swiftMethodName(m.ident)}(")
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 {
Expand Down
4 changes: 2 additions & 2 deletions src/source/SwiftMarshal.scala
Original file line number Diff line number Diff line change
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.translatorModule + "." + e.swift.translator
case e: MExtern => e.swift.translator
case o => o match {
case p: MPrimitive => p.idlName match {
case "i8" => "I8Marshaller"
Expand All @@ -128,7 +128,7 @@ class SwiftMarshal(spec: Spec) extends Marshal(spec) {
case d: MDef => throw new AssertionError("unreachable")
case e: MExtern => throw new AssertionError("unreachable")
case p: MParam => throw new AssertionError("not applicable")
case MVoid => "VoidMarshaller"
case MVoid => "Void_Marshaller"
}
}
private def helperTemplates(tm: MExpr): String = {
Expand Down
4 changes: 2 additions & 2 deletions src/source/SwiftxxMarshal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class SwiftxxMarshal(spec: Spec) extends Marshal(spec) {
case _ => List()
}

def include(ident: String) = q(spec.swiftxxFileIdentStyle(ident) + "." + spec.cppHeaderExt)
def include(ident: String) = q(spec.swiftxxIncludePrefix + spec.swiftxxFileIdentStyle(ident) + "." + spec.cppHeaderExt)

def resolveExtSwiftxxHdr(path: String) = {
path.replaceAll("\\$", "");
path.replaceAll("\\$", spec.swiftxxBaseLibIncludePrefix);
}

def helperClass(name: String) = spec.swiftxxClassIdentStyle(name)
Expand Down
1 change: 1 addition & 0 deletions src/source/generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ package object generatorTools {
swiftModule: String,
swiftxxOutFolder: Option[File],
swiftxxNamespace: String,
swiftxxIncludePrefix: String,
swiftxxBaseLibModule: String,
swiftxxClassIdentStyle: IdentConverter,
swiftxxFileIdentStyle: IdentConverter,
Expand Down
2 changes: 1 addition & 1 deletion support-lib/swift/DJMarshal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public enum DateMarshaller: Marshaller {
}
}

public enum VoidMarshaller: Marshaller {
public enum Void_Marshaller: Marshaller {
public typealias SwiftType = Void
static public func fromCpp(_ v: djinni.swift.AnyValue) -> SwiftType {
return ()
Expand Down
4 changes: 2 additions & 2 deletions test-suite/generated-src/swift/TestHelpers+Private.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ public class TestHelpers_statics {
}
static func voidAsyncMethod(_ f: DJFuture<Void>) throws -> DJFuture<Void> {
var params = djinni.swift.ParameterList()
params.addValue(FutureMarshaller<VoidMarshaller>.toCpp(f))
params.addValue(FutureMarshaller<Void_Marshaller>.toCpp(f))
var ret = djinni_generated.TestHelpers_voidAsyncMethod(&params)
try handleCppErrors(&ret)
return FutureMarshaller<VoidMarshaller>.fromCpp(ret)
return FutureMarshaller<Void_Marshaller>.fromCpp(ret)
}
static func addOneIfPresent(_ f: DJFuture<Optional<Int32>>) throws -> DJFuture<Optional<Int32>> {
var params = djinni.swift.ParameterList()
Expand Down

0 comments on commit 6e986dd

Please sign in to comment.