Commit da4ef208 authored by Jacob Potter's avatar Jacob Potter

Forward-declare interface crossreferences. Fixes #4

parent 127fa967
...@@ -4,11 +4,12 @@ ...@@ -4,11 +4,12 @@
#pragma once #pragma once
#include "item_list.hpp" #include "item_list.hpp"
#include "textbox_listener.hpp"
#include <memory> #include <memory>
namespace textsort { namespace textsort {
class TextboxListener;
class SortItems { class SortItems {
public: public:
virtual ~SortItems() {} virtual ~SortItems() {}
......
#pragma once #pragma once
#include "sort_items.hpp" #include "sort_items.hpp"
#include "textbox_listener.hpp"
namespace textsort { namespace textsort {
......
...@@ -31,6 +31,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) { ...@@ -31,6 +31,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
class CppRefs(name: String) { class CppRefs(name: String) {
var hpp = mutable.TreeSet[String]() var hpp = mutable.TreeSet[String]()
var hppFwds = mutable.TreeSet[String]()
var cpp = mutable.TreeSet[String]() var cpp = mutable.TreeSet[String]()
def find(ty: TypeRef) { find(ty.resolved) } def find(ty: TypeRef) { find(ty.resolved) }
...@@ -61,14 +62,17 @@ class CppGenerator(spec: Spec) extends Generator(spec) { ...@@ -61,14 +62,17 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
hpp.add("#include <unordered_map>") hpp.add("#include <unordered_map>")
} }
case d: MDef => case d: MDef =>
if (d.name != name) {
hpp.add("#include " + q(spec.cppIncludePrefix + spec.cppFileIdentStyle(d.name) + "." + spec.cppHeaderExt))
}
d.defType match { d.defType match {
case DEnum => case DEnum
case DRecord => | DRecord =>
if (d.name != name) {
hpp.add("#include " + q(spec.cppIncludePrefix + spec.cppFileIdentStyle(d.name) + "." + spec.cppHeaderExt))
}
case DInterface => case DInterface =>
hpp.add("#include <memory>") hpp.add("#include <memory>")
if (d.name != name) {
hppFwds.add(s"class ${idCpp.ty(d.name)};")
}
} }
case p: MParam => case p: MParam =>
} }
...@@ -79,7 +83,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) { ...@@ -79,7 +83,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
val refs = new CppRefs(ident.name) val refs = new CppRefs(ident.name)
val self = idCpp.enumType(ident) val self = idCpp.enumType(ident)
writeHppFile(ident, origin, refs.hpp, w => { writeHppFile(ident, origin, refs.hpp, refs.hppFwds, w => {
w.w(s"enum class $self : int").bracedSemi { w.w(s"enum class $self : int").bracedSemi {
for (o <- e.options) { for (o <- e.options) {
writeDoc(w, o.doc) writeDoc(w, o.doc)
...@@ -206,7 +210,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) { ...@@ -206,7 +210,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
} }
} }
writeHppFile(cppName, origin, refs.hpp, writeCppPrototype) writeHppFile(cppName, origin, refs.hpp, refs.hppFwds, writeCppPrototype)
if (r.consts.nonEmpty || r.derivingTypes.nonEmpty) { if (r.consts.nonEmpty || r.derivingTypes.nonEmpty) {
writeCppFile(cppName, origin, refs.cpp, w => { writeCppFile(cppName, origin, refs.cpp, w => {
...@@ -274,7 +278,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) { ...@@ -274,7 +278,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
val self = idCpp.ty(ident) val self = idCpp.ty(ident)
writeHppFile(ident, origin, refs.hpp, w => { writeHppFile(ident, origin, refs.hpp, refs.hppFwds, w => {
writeDoc(w, doc) writeDoc(w, doc)
writeCppTypeParams(w, typeParams) writeCppTypeParams(w, typeParams)
w.w(s"class $self").bracedSemi { w.w(s"class $self").bracedSemi {
......
...@@ -58,7 +58,7 @@ class JNIGenerator(spec: Spec) extends Generator(spec) { ...@@ -58,7 +58,7 @@ class JNIGenerator(spec: Spec) extends Generator(spec) {
val selfQ = withNs(spec.cppNamespace, self) val selfQ = withNs(spec.cppNamespace, self)
val jniClassName = spec.jniClassIdentStyle(ident) val jniClassName = spec.jniClassIdentStyle(ident)
writeJniHppFile(ident, origin, Iterable.concat(refs.jniHpp, refs.jniCpp), w => { writeJniHppFile(ident, origin, Iterable.concat(refs.jniHpp, refs.jniCpp), Nil, w => {
w.w(s"class $jniClassName final : djinni::JniEnum").bracedSemi { w.w(s"class $jniClassName final : djinni::JniEnum").bracedSemi {
w.wlOutdent("public:") w.wlOutdent("public:")
w.wl(s"using CppType = $selfQ;") w.wl(s"using CppType = $selfQ;")
...@@ -349,7 +349,7 @@ class JNIGenerator(spec: Spec) extends Generator(spec) { ...@@ -349,7 +349,7 @@ class JNIGenerator(spec: Spec) extends Generator(spec) {
def writeJniFiles(origin: String, allInHeader: Boolean, ident: Ident, refs: JNIRefs, writeProto: IndentWriter => Unit, writeBody: IndentWriter => Unit) { def writeJniFiles(origin: String, allInHeader: Boolean, ident: Ident, refs: JNIRefs, writeProto: IndentWriter => Unit, writeBody: IndentWriter => Unit) {
if (allInHeader) { if (allInHeader) {
// Template class. Write both parts to .hpp. // Template class. Write both parts to .hpp.
writeJniHppFile(ident, origin, Iterable.concat(refs.jniHpp, refs.jniCpp), w => { writeJniHppFile(ident, origin, Iterable.concat(refs.jniHpp, refs.jniCpp), Nil, w => {
writeProto(w) writeProto(w)
w.wl w.wl
writeBody(w) writeBody(w)
...@@ -357,7 +357,7 @@ class JNIGenerator(spec: Spec) extends Generator(spec) { ...@@ -357,7 +357,7 @@ class JNIGenerator(spec: Spec) extends Generator(spec) {
} }
else { else {
// Write prototype to .hpp and body to .cpp // Write prototype to .hpp and body to .cpp
writeJniHppFile(ident, origin, refs.jniHpp, writeProto) writeJniHppFile(ident, origin, refs.jniHpp, Nil, writeProto)
writeJniCppFile(ident, origin, refs.jniCpp, writeBody) writeJniCppFile(ident, origin, refs.jniCpp, writeBody)
} }
} }
......
...@@ -219,7 +219,7 @@ abstract class Generator(spec: Spec) ...@@ -219,7 +219,7 @@ abstract class Generator(spec: Spec)
} }
} }
def writeHppFileGeneric(folder: File, namespace: Option[String], fileIdentStyle: IdentConverter)(name: String, origin: String, includes: Iterable[String], f: IndentWriter => Unit) { def writeHppFileGeneric(folder: File, namespace: Option[String], fileIdentStyle: IdentConverter)(name: String, origin: String, includes: Iterable[String], fwds: Iterable[String], f: IndentWriter => Unit) {
createFile(folder, fileIdentStyle(name) + "." + spec.cppHeaderExt, (w: IndentWriter) => { createFile(folder, fileIdentStyle(name) + "." + spec.cppHeaderExt, (w: IndentWriter) => {
w.wl("// AUTOGENERATED FILE - DO NOT MODIFY!") w.wl("// AUTOGENERATED FILE - DO NOT MODIFY!")
w.wl("// This file generated by Djinni from " + origin) w.wl("// This file generated by Djinni from " + origin)
...@@ -227,10 +227,18 @@ abstract class Generator(spec: Spec) ...@@ -227,10 +227,18 @@ abstract class Generator(spec: Spec)
w.wl("#pragma once") w.wl("#pragma once")
if (includes.nonEmpty) { if (includes.nonEmpty) {
w.wl w.wl
includes.foreach(w.wl(_)) includes.foreach(w.wl)
} }
w.wl w.wl
wrapNamespace(w, namespace, f) wrapNamespace(w, namespace,
(w: IndentWriter) => {
if (fwds.nonEmpty) {
fwds.foreach(w.wl)
w.wl
}
f(w)
}
)
}) })
} }
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#pragma once #pragma once
#include "client_interface.hpp"
#include "map_list_record.hpp" #include "map_list_record.hpp"
#include "nested_collection.hpp" #include "nested_collection.hpp"
#include "primitive_list.hpp" #include "primitive_list.hpp"
...@@ -14,6 +13,8 @@ ...@@ -14,6 +13,8 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
class ClientInterface;
class TestHelpers { class TestHelpers {
public: public:
virtual ~TestHelpers() {} virtual ~TestHelpers() {}
......
#include "test_helpers.hpp" #include "test_helpers.hpp"
#include "client_returned_record.hpp"
#include "client_interface.hpp"
#include <exception> #include <exception>
SetRecord TestHelpers::get_set_record() { SetRecord TestHelpers::get_set_record() {
......
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