Commit b38789e6 authored by Miro Knejp's avatar Miro Knejp

Pull include/import directives and forward declarations from Marshals

parent 9d1d6404
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
// This file generated by Djinni from example.djinni // This file generated by Djinni from example.djinni
#import "TXSItemList+Private.h" #import "TXSItemList+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
// AUTOGENERATED FILE - DO NOT MODIFY! // AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from example.djinni // This file generated by Djinni from example.djinni
#import "TXSItemList.h"
#import "TXSSortOrder.h" #import "TXSSortOrder.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class TXSItemList;
@class TXSSortItems; @class TXSSortItems;
@protocol TXSTextboxListener; @protocol TXSTextboxListener;
......
// AUTOGENERATED FILE - DO NOT MODIFY! // AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from example.djinni // This file generated by Djinni from example.djinni
#import "TXSItemList.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class TXSItemList;
@protocol TXSTextboxListener @protocol TXSTextboxListener
......
...@@ -39,49 +39,14 @@ class CppGenerator(spec: Spec) extends Generator(spec) { ...@@ -39,49 +39,14 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
def find(ty: TypeRef) { find(ty.resolved) } def find(ty: TypeRef) { find(ty.resolved) }
def find(tm: MExpr) { def find(tm: MExpr) {
tm.args.map(find).mkString("<", ", ", ">") tm.args.foreach(find)
find(tm.base) find(tm.base)
} }
def find(m: Meta) = m match { def find(m: Meta) = for(r <- marshal.references(m, name)) r match {
case o: MOpaque => case ImportRef(arg) => hpp.add("#include " + arg)
o match { case DeclRef(decl, Some(spec.cppNamespace)) => hppFwds.add(decl)
case p: MPrimitive => case DeclRef(_, _) =>
val n = p.idlName
if (n == "i8" || n == "i16" || n == "i32" || n == "i64") {
hpp.add("#include <cstdint>")
}
case MString =>
hpp.add("#include <string>")
case MDate =>
hpp.add("#include <chrono>")
case MBinary =>
hpp.add("#include <vector>")
hpp.add("#include <cstdint>")
case MOptional =>
hpp.add("#include " + spec.cppOptionalHeader)
case MList =>
hpp.add("#include <vector>")
case MSet =>
hpp.add("#include <unordered_set>")
case MMap =>
hpp.add("#include <unordered_map>")
}
case d: MDef =>
d.defType match {
case DEnum
| DRecord =>
if (d.name != name) {
hpp.add("#include " + q(spec.cppIncludePrefix + spec.cppFileIdentStyle(d.name) + "." + spec.cppHeaderExt))
}
case DInterface =>
hpp.add("#include <memory>")
if (d.name != name) {
hppFwds.add(s"class ${marshal.typename(d.name, d.body)};")
}
}
case p: MParam =>
} }
} }
override def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum) { override def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum) {
......
...@@ -32,6 +32,35 @@ class CppMarshal(spec: Spec) extends Marshal(spec) { ...@@ -32,6 +32,35 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
override def toCpp(tm: MExpr, expr: String): String = throw new AssertionError("cpp to cpp conversion") override def toCpp(tm: MExpr, expr: String): String = throw new AssertionError("cpp to cpp conversion")
override def fromCpp(tm: MExpr, expr: String): String = throw new AssertionError("cpp to cpp conversion") override def fromCpp(tm: MExpr, expr: String): String = throw new AssertionError("cpp to cpp conversion")
def references(m: Meta, exclude: String): Seq[SymbolReference] = m match {
case p: MPrimitive => p.idlName match {
case "i8" | "i16" | "i32" | "i64" => List(ImportRef("<cstdint>"))
case _ => List()
}
case MString => List(ImportRef("<string>"))
case MDate => List(ImportRef("<chrono>"))
case MBinary => List(ImportRef("<vector>"), ImportRef("<cstdint>"))
case MOptional => List(ImportRef(spec.cppOptionalHeader))
case MList => List(ImportRef("<vector>"))
case MSet => List(ImportRef("<unordered_set>"))
case MMap => List(ImportRef("<unordered_map>"))
case d: MDef => d.defType match {
case DEnum | DRecord =>
if (d.name != exclude) {
List(ImportRef(q(spec.cppIncludePrefix + spec.cppFileIdentStyle(d.name) + "." + spec.cppHeaderExt)))
} else {
List()
}
case DInterface =>
if (d.name != exclude) {
List(ImportRef("<memory>"), DeclRef(s"class ${typename(d.name, d.body)};", Some(spec.cppNamespace)))
} else {
List(ImportRef("<memory>"))
}
}
case p: MParam => List()
}
private def toCppType(ty: TypeRef, namespace: Option[String] = None): String = toCppType(ty.resolved, namespace) private def toCppType(ty: TypeRef, namespace: Option[String] = None): String = toCppType(ty.resolved, namespace)
private def toCppType(tm: MExpr, namespace: Option[String]): String = { private def toCppType(tm: MExpr, namespace: Option[String]): String = {
def base(m: Meta): String = m match { def base(m: Meta): String = m match {
......
...@@ -44,15 +44,12 @@ class JNIGenerator(spec: Spec) extends Generator(spec) { ...@@ -44,15 +44,12 @@ class JNIGenerator(spec: Spec) extends Generator(spec) {
def find(ty: TypeRef) { find(ty.resolved) } def find(ty: TypeRef) { find(ty.resolved) }
def find(tm: MExpr) { def find(tm: MExpr) {
tm.args.map(find).mkString("<", ", ", ">") tm.args.foreach(find)
find(tm.base) find(tm.base)
} }
def find(m: Meta) = m match { def find(m: Meta) = for(r <- jniMarshal.references(m, name)) r match {
case o: MOpaque => case ImportRef(arg) => jniCpp.add("#include " + arg)
jniCpp.add("#include " + q(spec.jniBaseLibIncludePrefix + "Marshal.hpp")) case _ =>
case d: MDef =>
jniCpp.add("#include " + q(spec.jniIncludePrefix + spec.jniFileIdentStyle(d.name) + "." + spec.cppHeaderExt))
case p: MParam =>
} }
} }
......
...@@ -33,6 +33,12 @@ class JNIMarshal(spec: Spec) extends Marshal(spec) { ...@@ -33,6 +33,12 @@ class JNIMarshal(spec: Spec) extends Marshal(spec) {
def helperClass(name: String) = spec.jniClassIdentStyle(name) def helperClass(name: String) = spec.jniClassIdentStyle(name)
private def helperClass(tm: MExpr) = helperName(tm) + helperTemplates(tm) private def helperClass(tm: MExpr) = helperName(tm) + helperTemplates(tm)
def references(m: Meta, exclude: String = ""): Seq[SymbolReference] = m match {
case o: MOpaque => List(ImportRef(q(spec.jniBaseLibIncludePrefix + "Marshal.hpp")))
case d: MDef => List(ImportRef(q(spec.jniIncludePrefix + spec.jniFileIdentStyle(d.name) + "." + spec.cppHeaderExt)))
case _ => List()
}
def toJniType(ty: TypeRef): String = toJniType(ty.resolved, false) def toJniType(ty: TypeRef): String = toJniType(ty.resolved, false)
def toJniType(m: MExpr, needRef: Boolean): String = m.base match { def toJniType(m: MExpr, needRef: Boolean): String = m.base match {
case p: MPrimitive => if (needRef) "jobject" else p.jniName case p: MPrimitive => if (needRef) "jobject" else p.jniName
......
...@@ -36,22 +36,11 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { ...@@ -36,22 +36,11 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
def find(ty: TypeRef) { find(ty.resolved) } def find(ty: TypeRef) { find(ty.resolved) }
def find(tm: MExpr) { def find(tm: MExpr) {
tm.args.map(find).mkString("<", ", ", ">") tm.args.foreach(find)
find(tm.base) find(tm.base)
} }
def find(m: Meta) = m match { def find(m: Meta) = for(r <- marshal.references(m)) r match {
case o: MOpaque => case ImportRef(arg) => java.add(arg)
o match {
case MList =>
java.add("java.util.ArrayList")
case MSet =>
java.add("java.util.HashSet")
case MMap =>
java.add("java.util.HashMap")
case MDate =>
java.add("java.util.Date")
case _ =>
}
case _ => case _ =>
} }
} }
......
...@@ -24,6 +24,18 @@ class JavaMarshal(spec: Spec) extends Marshal(spec) { ...@@ -24,6 +24,18 @@ class JavaMarshal(spec: Spec) extends Marshal(spec) {
override def toCpp(tm: MExpr, expr: String): String = throw new AssertionError("direct java to cpp conversion not possible") override def toCpp(tm: MExpr, expr: String): String = throw new AssertionError("direct java to cpp conversion not possible")
override def fromCpp(tm: MExpr, expr: String): String = throw new AssertionError("direct cpp to java conversion not possible") override def fromCpp(tm: MExpr, expr: String): String = throw new AssertionError("direct cpp to java conversion not possible")
def references(m: Meta): Seq[SymbolReference] = m match {
case o: MOpaque =>
o match {
case MList => List(ImportRef("java.util.ArrayList"))
case MSet => List(ImportRef("java.util.HashSet"))
case MMap => List(ImportRef("java.util.HashMap"))
case MDate => List(ImportRef("java.util.Date"))
case _ => List()
}
case _ => List()
}
private def toJavaType(tm: MExpr, packageName: Option[String]): String = { private def toJavaType(tm: MExpr, packageName: Option[String]): String = {
def f(tm: MExpr, needRef: Boolean): String = { def f(tm: MExpr, needRef: Boolean): String = {
tm.base match { tm.base match {
......
...@@ -36,32 +36,12 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -36,32 +36,12 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
def find(ty: TypeRef) { find(ty.resolved) } def find(ty: TypeRef) { find(ty.resolved) }
def find(tm: MExpr) { def find(tm: MExpr) {
tm.args.map(find).mkString("<", ",", ">") tm.args.foreach(find)
tm.base match { find(tm.base)
case o: MOpaque => }
header.add("#import <Foundation/Foundation.h>") def find(m: Meta) = for(r <- marshal.references(m)) r match {
case d: MDef => d.defType match { case ImportRef(arg) => header.add("#import " + arg)
case DEnum => case DeclRef(decl, _) => header.add(decl)
header.add("#import " + q(spec.objcIncludePrefix + headerName(d.name)))
case DInterface =>
header.add("#import <Foundation/Foundation.h>")
val ext = d.body.asInstanceOf[Interface].ext
if (ext.cpp) {
header.add("@class " + marshal.typename(tm) + ";")
body.add("#import " + q(spec.objcIncludePrefix + headerName(d.name)))
}
if (ext.objc) {
header.add("@protocol " + marshal.typename(tm) + ";")
body.add("#import " + q(spec.objcIncludePrefix + headerName(d.name)))
}
case DRecord =>
val r = d.body.asInstanceOf[Record]
val prefix = if (r.ext.objc) "../" else ""
header.add("@class " + marshal.typename(tm) + ";")
body.add("#import " + q(spec.objcIncludePrefix + prefix + headerName(d.name)))
}
case p: MParam =>
}
} }
} }
...@@ -71,7 +51,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -71,7 +51,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
refs.header.add("#import <Foundation/Foundation.h>") refs.header.add("#import <Foundation/Foundation.h>")
val self = marshal.typename(ident, e) val self = marshal.typename(ident, e)
writeObjcFile(headerName(ident), origin, refs.header, w => { writeObjcFile(marshal.headerName(ident), origin, refs.header, w => {
writeDoc(w, doc) writeDoc(w, doc)
w.wl(s"typedef NS_ENUM(NSInteger, $self)") w.wl(s"typedef NS_ENUM(NSInteger, $self)")
w.bracedSemi { w.bracedSemi {
...@@ -163,7 +143,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -163,7 +143,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
writeAlignedObjcCall(w, decl, method.params, "", p => (idObjc.field(p.ident), s"(${marshal.paramType(p.ty)})${idObjc.local(p.ident)}")) writeAlignedObjcCall(w, decl, method.params, "", p => (idObjc.field(p.ident), s"(${marshal.paramType(p.ty)})${idObjc.local(p.ident)}"))
} }
writeObjcFile(headerName(ident), origin, refs.header, w => { writeObjcFile(marshal.headerName(ident), origin, refs.header, w => {
writeDoc(w, doc) writeDoc(w, doc)
for (c <- i.consts) { for (c <- i.consts) {
writeDoc(w, c.doc) writeDoc(w, c.doc)
...@@ -205,7 +185,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -205,7 +185,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
val self = marshal.typename(objcName, r) val self = marshal.typename(objcName, r)
refs.header.add("#import <Foundation/Foundation.h>") refs.header.add("#import <Foundation/Foundation.h>")
refs.body.add("!#import " + q(spec.objcIncludePrefix + (if (r.ext.objc) "../" else "") + headerName(ident))) refs.body.add("!#import " + q(spec.objcIncludePrefix + (if (r.ext.objc) "../" else "") + marshal.headerName(ident)))
if (r.ext.objc) { if (r.ext.objc) {
refs.header.add(s"@class $noBaseSelf;") refs.header.add(s"@class $noBaseSelf;")
...@@ -218,7 +198,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -218,7 +198,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
case _ => false case _ => false
} }
writeObjcFile(headerName(objcName), origin, refs.header, w => { writeObjcFile(marshal.headerName(objcName), origin, refs.header, w => {
writeDoc(w, doc) writeDoc(w, doc)
w.wl(s"@interface $self : NSObject") w.wl(s"@interface $self : NSObject")
......
...@@ -43,6 +43,33 @@ class ObjcMarshal(spec: Spec) extends Marshal(spec) { ...@@ -43,6 +43,33 @@ class ObjcMarshal(spec: Spec) extends Marshal(spec) {
override def toCpp(tm: MExpr, expr: String): String = throw new AssertionError("direct objc to cpp conversion not possible") override def toCpp(tm: MExpr, expr: String): String = throw new AssertionError("direct objc to cpp conversion not possible")
override def fromCpp(tm: MExpr, expr: String): String = throw new AssertionError("direct cpp to objc conversion not possible") override def fromCpp(tm: MExpr, expr: String): String = throw new AssertionError("direct cpp to objc conversion not possible")
def references(m: Meta, exclude: String = ""): Seq[SymbolReference] = m match {
case o: MOpaque =>
List(ImportRef("<Foundation/Foundation.h>"))
case d: MDef => d.defType match {
case DEnum =>
List(ImportRef(q(spec.objcIncludePrefix + headerName(d.name))))
case DInterface =>
val ext = d.body.asInstanceOf[Interface].ext
if (ext.cpp) {
List(ImportRef("<Foundation/Foundation.h>"), DeclRef(s"@class ${typename(d.name, d.body)};", None))
}
else if (ext.objc) {
List(ImportRef("<Foundation/Foundation.h>"), DeclRef(s"@protocol ${typename(d.name, d.body)};", None))
}
else {
List()
}
case DRecord =>
val r = d.body.asInstanceOf[Record]
val prefix = if (r.ext.objc) "../" else ""
List(ImportRef(q(spec.objcIncludePrefix + prefix + headerName(d.name))))
}
case p: MParam => List()
}
def headerName(ident: String): String = idObjc.ty(ident) + "." + spec.objcHeaderExt
// Return value: (Type_Name, Is_Class_Or_Not) // Return value: (Type_Name, Is_Class_Or_Not)
def toObjcType(ty: TypeRef): (String, Boolean) = toObjcType(ty.resolved, false) def toObjcType(ty: TypeRef): (String, Boolean) = toObjcType(ty.resolved, false)
def toObjcType(ty: TypeRef, needRef: Boolean): (String, Boolean) = toObjcType(ty.resolved, needRef) def toObjcType(ty: TypeRef, needRef: Boolean): (String, Boolean) = toObjcType(ty.resolved, needRef)
......
...@@ -39,33 +39,12 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) { ...@@ -39,33 +39,12 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
def find(ty: TypeRef) { find(ty.resolved) } def find(ty: TypeRef) { find(ty.resolved) }
def find(tm: MExpr) { def find(tm: MExpr) {
tm.args.map(find).mkString("<", ",", ">") tm.args.foreach(find)
tm.base match { find(tm.base)
case o: MOpaque => }
header.add("#import <Foundation/Foundation.h>") def find(m: Meta) = for(r <- objcppMarshal.references(m)) r match {
body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIMarshal+Private.h")) case ImportRef(arg) => body.add("#import " + arg)
case d: MDef => d.defType match { case _ =>
case DEnum =>
header.add("#import " + q(spec.objcIncludePrefix + headerName(d.name)))
body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIMarshal+Private.h"))
case DInterface =>
val ext = d.body.asInstanceOf[Interface].ext
if (ext.cpp) {
header.add("@class " + objcMarshal.typename(tm) + ";")
body.add("#import " + q(spec.objcppIncludePrefix + privateHeaderName(d.name)))
}
if (ext.objc) {
header.add("@protocol " + objcMarshal.typename(tm) + ";")
body.add("#import " + q(spec.objcppIncludePrefix + privateHeaderName(d.name)))
}
case DRecord =>
val r = d.body.asInstanceOf[Record]
val objcName = d.name + (if (r.ext.objc) "_base" else "")
header.add("@class " + objcMarshal.typename(tm) + ";")
body.add("#import " + q(spec.objcppIncludePrefix + privateHeaderName(objcName)))
}
case p: MParam =>
}
} }
} }
...@@ -76,8 +55,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) { ...@@ -76,8 +55,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
} }
def headerName(ident: String): String = idObjc.ty(ident) + "." + spec.objcHeaderExt def headerName(ident: String): String = idObjc.ty(ident) + "." + spec.objcHeaderExt
def privateHeaderName(ident: String): String = idObjc.ty(ident) + "+Private." + spec.objcHeaderExt def privateBodyName(ident: String): String = idObjc.ty(ident) + "+Private." + spec.objcppExt
def bodyName(ident: String): String = idObjc.ty(ident) + "+Private." + spec.objcppExt
override def generateInterface(origin: String, ident: Ident, doc: Doc, typeParams: Seq[TypeParam], i: Interface) { override def generateInterface(origin: String, ident: Ident, doc: Doc, typeParams: Seq[TypeParam], i: Interface) {
val refs = new ObjcRefs() val refs = new ObjcRefs()
...@@ -106,7 +84,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) { ...@@ -106,7 +84,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
val helperClass = objcppMarshal.helperClass(ident) val helperClass = objcppMarshal.helperClass(ident)
writeObjcFile(privateHeaderName(ident.name), origin, refs.privHeader, w => { writeObjcFile(objcppMarshal.privateHeaderName(ident.name), origin, refs.privHeader, w => {
arcAssert(w) arcAssert(w)
w.wl w.wl
w.wl((if(i.ext.objc) "@protocol " else "@class ") + self + ";") w.wl((if(i.ext.objc) "@protocol " else "@class ") + self + ";")
...@@ -130,14 +108,14 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) { ...@@ -130,14 +108,14 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
}) })
if (i.ext.cpp) { if (i.ext.cpp) {
refs.body.add("!#import " + q(spec.objcppIncludePrefix + privateHeaderName(ident.name))) refs.body.add("!#import " + q(spec.objcppIncludePrefix + objcppMarshal.privateHeaderName(ident.name)))
refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJICppWrapperCache+Private.h")) refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJICppWrapperCache+Private.h"))
refs.body.add("#include <utility>") refs.body.add("#include <utility>")
refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIError.h")) refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIError.h"))
refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIDate.h")) refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIDate.h"))
refs.body.add("#include <exception>") refs.body.add("#include <exception>")
writeObjcFile(bodyName(ident.name), origin, refs.body, w => { writeObjcFile(privateBodyName(ident.name), origin, refs.body, w => {
arcAssert(w) arcAssert(w)
w.wl w.wl
w.wl(s"@interface $self ()") w.wl(s"@interface $self ()")
...@@ -192,9 +170,9 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) { ...@@ -192,9 +170,9 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
if (i.ext.objc) { if (i.ext.objc) {
val objcExtSelf = objcppMarshal.helperClass("objc_proxy") val objcExtSelf = objcppMarshal.helperClass("objc_proxy")
refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIObjcWrapperCache+Private.h")) refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIObjcWrapperCache+Private.h"))
refs.body.add("!#import " + q(spec.objcppIncludePrefix + privateHeaderName(ident.name))) refs.body.add("!#import " + q(spec.objcppIncludePrefix + objcppMarshal.privateHeaderName(ident.name)))
writeObjcFile(bodyName(ident.name), origin, refs.body, w => { writeObjcFile(privateBodyName(ident.name), origin, refs.body, w => {
arcAssert(w) arcAssert(w)
w.wl w.wl
wrapNamespace(w, spec.objcppNamespace, w => { wrapNamespace(w, spec.objcppNamespace, w => {
...@@ -246,22 +224,11 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) { ...@@ -246,22 +224,11 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
val self = objcMarshal.typename(objcName, r) val self = objcMarshal.typename(objcName, r)
val cppSelf = cppMarshal.fqTypename(ident, r) val cppSelf = cppMarshal.fqTypename(ident, r)
refs.header.add("#import <Foundation/Foundation.h>") refs.privHeader.add("!#import " + q(spec.objcppIncludeObjcPrefix + (if(r.ext.objc) "../" else "") + headerName(ident)))
refs.privHeader.add("!#include " + q(spec.objcppIncludeCppPrefix + (if(r.ext.cpp) "../" else "") + spec.cppFileIdentStyle(ident) + "." + spec.cppHeaderExt))
refs.privHeader.add("!#import " + q(spec.objcIncludePrefix + headerName(objcName)))
refs.privHeader.add("!#include " + q(spec.objcppIncludeCppPrefix + spec.cppFileIdentStyle(ident) + "." + spec.cppHeaderExt))
refs.body.add("#import <Foundation/Foundation.h>")
refs.body.add("#include <cassert>") refs.body.add("#include <cassert>")
refs.body.add("#include <utility>") refs.body.add("!#import " + q(spec.objcppIncludePrefix + objcppMarshal.privateHeaderName(objcName)))
refs.body.add("#include <vector>")
refs.body.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIDate.h"))
refs.body.add("!#import " + q(spec.objcppIncludePrefix + privateHeaderName(objcName)))
if (r.ext.objc) {
refs.body.add("#import " + q(spec.objcppIncludeObjcPrefix + "../" + headerName(ident)))
refs.header.add(s"@class ${objcMarshal.typename(ident, r)};")
}
def checkMutable(tm: MExpr): Boolean = tm.base match { def checkMutable(tm: MExpr): Boolean = tm.base match {
case MOptional => checkMutable(tm.args.head) case MOptional => checkMutable(tm.args.head)
...@@ -272,7 +239,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) { ...@@ -272,7 +239,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
val helperClass = objcppMarshal.helperClass(ident) val helperClass = objcppMarshal.helperClass(ident)
writeObjcFile(privateHeaderName(objcName), origin, refs.privHeader, w => { writeObjcFile(objcppMarshal.privateHeaderName(objcName), origin, refs.privHeader, w => {
arcAssert(w) arcAssert(w)
w.wl w.wl
w.wl(s"@class $noBaseSelf;") w.wl(s"@class $noBaseSelf;")
...@@ -291,7 +258,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) { ...@@ -291,7 +258,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
}) })
}) })
writeObjcFile(bodyName(objcName), origin, refs.body, w => { writeObjcFile(privateBodyName(objcName), origin, refs.body, w => {
wrapNamespace(w, spec.objcppNamespace, w => { wrapNamespace(w, spec.objcppNamespace, w => {
w.wl(s"auto $helperClass::toCpp(ObjcType obj) -> CppType") w.wl(s"auto $helperClass::toCpp(ObjcType obj) -> CppType")
w.braced { w.braced {
......
...@@ -32,8 +32,26 @@ class ObjcppMarshal(spec: Spec) extends Marshal(spec) { ...@@ -32,8 +32,26 @@ class ObjcppMarshal(spec: Spec) extends Marshal(spec) {
s"$helper::fromCpp($expr)" s"$helper::fromCpp($expr)"
} }
def references(m: Meta): Seq[SymbolReference] = m match {
case o: MOpaque =>
List(ImportRef(q(spec.objcBaseLibIncludePrefix + "DJIMarshal+Private.h")))
case d: MDef => d.defType match {
case DEnum =>
List(ImportRef(q(spec.objcBaseLibIncludePrefix + "DJIMarshal+Private.h")))
case DInterface =>
List(ImportRef(q(spec.objcppIncludePrefix + privateHeaderName(d.name))))
case DRecord =>
val r = d.body.asInstanceOf[Record]
val objcName = d.name + (if (r.ext.objc) "_base" else "")
List(ImportRef(q(spec.objcppIncludePrefix + privateHeaderName(objcName))))
}
case p: MParam => List()
}
def helperClass(name: String) = idCpp.ty(name) def helperClass(name: String) = idCpp.ty(name)
def privateHeaderName(ident: String): String = idObjc.ty(ident) + "+Private." + spec.objcHeaderExt
private def helperName(tm: MExpr): String = tm.base match { private def helperName(tm: MExpr): String = tm.base match {
case d: MDef => d.defType match { case d: MDef => d.defType match {
case DEnum => withNs(Some("djinni"), s"Enum<${cppMarshal.fqTypename(tm)}, ${objcMarshal.fqTypename(tm)}>") case DEnum => withNs(Some("djinni"), s"Enum<${cppMarshal.fqTypename(tm)}, ${objcMarshal.fqTypename(tm)}>")
......
...@@ -180,6 +180,10 @@ package object generatorTools { ...@@ -180,6 +180,10 @@ package object generatorTools {
case GenerateException(message) => Some(message) case GenerateException(message) => Some(message)
} }
} }
sealed abstract class SymbolReference
case class ImportRef(arg: String) extends SymbolReference // Already contains <> or "" in C contexts
case class DeclRef(decl: String, namespace: Option[String]) extends SymbolReference
} }
abstract class Generator(spec: Spec) abstract class Generator(spec: Spec)
......
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
// This file generated by Djinni from inttypes.djinni // This file generated by Djinni from inttypes.djinni
#import "DBAssortedIntegers+Private.h" #import "DBAssortedIntegers+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
// AUTOGENERATED FILE - DO NOT MODIFY! // AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from client_interface.djinni // This file generated by Djinni from client_interface.djinni
#import "DBClientReturnedRecord.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class DBClientReturnedRecord;
@protocol DBClientInterface @protocol DBClientInterface
......
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
// This file generated by Djinni from client_interface.djinni // This file generated by Djinni from client_interface.djinni
#import "DBClientReturnedRecord+Private.h" #import "DBClientReturnedRecord+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
...@@ -3,12 +3,8 @@ ...@@ -3,12 +3,8 @@
#import "DBConstants+Private.h" #import "DBConstants+Private.h"
#import "DBConstants+Private.h" #import "DBConstants+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
// AUTOGENERATED FILE - DO NOT MODIFY! // AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constants.djinni // This file generated by Djinni from constants.djinni
#import "DBConstants.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class DBConstants;
@interface DBConstants : NSObject @interface DBConstants : NSObject
- (nonnull id)initWithConstants:(nonnull DBConstants *)constants; - (nonnull id)initWithConstants:(nonnull DBConstants *)constants;
......
// AUTOGENERATED FILE - DO NOT MODIFY! // AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constants.djinni // This file generated by Djinni from constants.djinni
#import "DBConstants.h"
#import "DBConstants.h" #import "DBConstants.h"
#pragma clang diagnostic push #pragma clang diagnostic push
......
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
// This file generated by Djinni from date.djinni // This file generated by Djinni from date.djinni
#import "DBDateRecord+Private.h" #import "DBDateRecord+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
// This file generated by Djinni from date.djinni // This file generated by Djinni from date.djinni
#import "DBMapDateRecord+Private.h" #import "DBMapDateRecord+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
// This file generated by Djinni from map.djinni // This file generated by Djinni from map.djinni
#import "DBMapListRecord+Private.h" #import "DBMapListRecord+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
// This file generated by Djinni from map.djinni // This file generated by Djinni from map.djinni
#import "DBMapRecord+Private.h" #import "DBMapRecord+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
// This file generated by Djinni from nested_collection.djinni // This file generated by Djinni from nested_collection.djinni
#import "DBNestedCollection+Private.h" #import "DBNestedCollection+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
// This file generated by Djinni from primitive_list.djinni // This file generated by Djinni from primitive_list.djinni
#import "DBPrimitiveList+Private.h" #import "DBPrimitiveList+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
// This file generated by Djinni from derivings.djinni // This file generated by Djinni from derivings.djinni
#import "DBRecordWithDerivings+Private.h" #import "DBRecordWithDerivings+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
...@@ -3,12 +3,8 @@ ...@@ -3,12 +3,8 @@
#import "DBRecordWithNestedDerivings+Private.h" #import "DBRecordWithNestedDerivings+Private.h"
#import "DBRecordWithDerivings+Private.h" #import "DBRecordWithDerivings+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
// AUTOGENERATED FILE - DO NOT MODIFY! // AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from derivings.djinni // This file generated by Djinni from derivings.djinni
#import "DBRecordWithDerivings.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class DBRecordWithDerivings;
@interface DBRecordWithNestedDerivings : NSObject @interface DBRecordWithNestedDerivings : NSObject
- (nonnull id)initWithRecordWithNestedDerivings:(nonnull DBRecordWithNestedDerivings *)recordWithNestedDerivings; - (nonnull id)initWithRecordWithNestedDerivings:(nonnull DBRecordWithNestedDerivings *)recordWithNestedDerivings;
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// This file generated by Djinni from derivings.djinni // This file generated by Djinni from derivings.djinni
#import "DBRecordWithNestedDerivings.h" #import "DBRecordWithNestedDerivings.h"
#import "DBRecordWithDerivings.h"
@implementation DBRecordWithNestedDerivings @implementation DBRecordWithNestedDerivings
......
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
// This file generated by Djinni from set.djinni // This file generated by Djinni from set.djinni
#import "DBSetRecord+Private.h" #import "DBSetRecord+Private.h"
#import "DJIDate.h"
#import "DJIMarshal+Private.h" #import "DJIMarshal+Private.h"
#import <Foundation/Foundation.h>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
namespace djinni_generated { namespace djinni_generated {
......
// AUTOGENERATED FILE - DO NOT MODIFY! // AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from test.djinni // This file generated by Djinni from test.djinni
#import "DBAssortedIntegers.h"
#import "DBColor.h" #import "DBColor.h"
#import "DBMapListRecord.h"
#import "DBNestedCollection.h"
#import "DBPrimitiveList.h"
#import "DBSetRecord.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class DBAssortedIntegers;
@class DBMapListRecord;
@class DBNestedCollection;
@class DBPrimitiveList;
@class DBSetRecord;
@class DBToken; @class DBToken;
@protocol DBClientInterface; @protocol DBClientInterface;
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
A238CA9E1AF84B7100CDDCE5 /* DBRecordWithDerivings+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = A238CA861AF84B7100CDDCE5 /* DBRecordWithDerivings+Private.mm */; }; A238CA9E1AF84B7100CDDCE5 /* DBRecordWithDerivings+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = A238CA861AF84B7100CDDCE5 /* DBRecordWithDerivings+Private.mm */; };
A238CAA01AF84B7100CDDCE5 /* DBRecordWithNestedDerivings+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = A238CA881AF84B7100CDDCE5 /* DBRecordWithNestedDerivings+Private.mm */; }; A238CAA01AF84B7100CDDCE5 /* DBRecordWithNestedDerivings+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = A238CA881AF84B7100CDDCE5 /* DBRecordWithNestedDerivings+Private.mm */; };
A238CAA21AF84B7100CDDCE5 /* DBSetRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = A238CA8A1AF84B7100CDDCE5 /* DBSetRecord+Private.mm */; }; A238CAA21AF84B7100CDDCE5 /* DBSetRecord+Private.mm in Sources */ = {isa = PBXBuildFile; fileRef = A238CA8A1AF84B7100CDDCE5 /* DBSetRecord+Private.mm */; };
A239F37A1AF400C600DF27C8 /* DJIDate.mm in Sources */ = {isa = PBXBuildFile; fileRef = A239F3781AF400C600DF27C8 /* DJIDate.mm */; };
A24249731AF192FC003BF8F0 /* assorted_integers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A242495E1AF192FC003BF8F0 /* assorted_integers.cpp */; }; A24249731AF192FC003BF8F0 /* assorted_integers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A242495E1AF192FC003BF8F0 /* assorted_integers.cpp */; };
A24249741AF192FC003BF8F0 /* constants.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A24249631AF192FC003BF8F0 /* constants.cpp */; }; A24249741AF192FC003BF8F0 /* constants.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A24249631AF192FC003BF8F0 /* constants.cpp */; };
A24249751AF192FC003BF8F0 /* record_with_derivings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A242496C1AF192FC003BF8F0 /* record_with_derivings.cpp */; }; A24249751AF192FC003BF8F0 /* record_with_derivings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A242496C1AF192FC003BF8F0 /* record_with_derivings.cpp */; };
...@@ -531,7 +530,6 @@ ...@@ -531,7 +530,6 @@
A238CA9E1AF84B7100CDDCE5 /* DBRecordWithDerivings+Private.mm in Sources */, A238CA9E1AF84B7100CDDCE5 /* DBRecordWithDerivings+Private.mm in Sources */,
A24249751AF192FC003BF8F0 /* record_with_derivings.cpp in Sources */, A24249751AF192FC003BF8F0 /* record_with_derivings.cpp in Sources */,
A238CA901AF84B7100CDDCE5 /* DBConstants+Private.mm in Sources */, A238CA901AF84B7100CDDCE5 /* DBConstants+Private.mm in Sources */,
A239F37A1AF400C600DF27C8 /* DJIDate.mm in Sources */,
A248502A1AF96EBC00AFE907 /* DBMapDateRecord.mm in Sources */, A248502A1AF96EBC00AFE907 /* DBMapDateRecord.mm in Sources */,
A238CA8E1AF84B7100CDDCE5 /* DBClientReturnedRecord+Private.mm in Sources */, A238CA8E1AF84B7100CDDCE5 /* DBClientReturnedRecord+Private.mm in Sources */,
A24850261AF96EBC00AFE907 /* DBAssortedIntegers.mm in Sources */, A24850261AF96EBC00AFE907 /* DBAssortedIntegers.mm in Sources */,
......
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