use the factories

This commit is contained in:
David Renshaw 2014-05-10 21:00:26 -04:00
parent 92ad93ffcb
commit b17e1aed61

View file

@ -21,7 +21,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This program is a code generator plugin for `capnp compile` which generates C++ code. // This program is a code generator plugin for `capnp compile` which generates java code.
#include <capnp/schema.capnp.h> #include <capnp/schema.capnp.h>
#include "capnp/serialize.h" #include "capnp/serialize.h"
@ -904,7 +904,7 @@ private:
} }
elementReaderType = kj::str( elementReaderType = kj::str(
typeName(typeBody.getList().getElementType()), typeName(typeBody.getList().getElementType()),
primitiveElement ? "" : interface ? "::Client" : "::Reader"); primitiveElement ? "" : interface ? "::Client" : ".Reader");
} }
@ -916,8 +916,14 @@ private:
spaces(indent), " }\n", spaces(indent), " }\n",
spaces(indent), " public ", type, ".Reader get", titleCase, "() {\n", spaces(indent), " public ", type, ".Reader get", titleCase, "() {\n",
spaces(indent), " return _reader.getPointerField(", offset, ").get", (kind == FieldKind::LIST ?
(kind == FieldKind::LIST ? "List" : (kind == FieldKind::BLOB ? "Text" : "Struct")), "();\n", // XXX kj::strTree(spaces(indent),
" return new ", type, ".Reader.new(_reader.getPointerField(",
offset, ").getList(), ", elementReaderType, ".factory);\n") :
(kind == FieldKind::BLOB ?
kj::strTree(spaces(indent), " return _reader.getPointerField(",
offset,".getText());\n") :
kj::strTree(spaces(indent), "Struct\n"))), // XXX
spaces(indent), " }\n", spaces(indent), " }\n",
"\n"), "\n"),
@ -1082,9 +1088,9 @@ private:
return kj::strTree(); return kj::strTree();
} }
}, },
spaces(indent), " };\n"), spaces(indent), " }\n"),
KJ_MAP(n, nestedTypeDecls) { return kj::mv(n); }, KJ_MAP(n, nestedTypeDecls) { return kj::mv(n); },
spaces(indent), "};\n" spaces(indent), "}\n"
"\n"), "\n"),
kj::strTree( kj::strTree(
@ -1393,7 +1399,7 @@ private:
KJ_MAP(e, enumerants) { KJ_MAP(e, enumerants) {
return kj::strTree(spaces(indent), " ", toUpperCase(e.getProto().getName()), ",\n"); return kj::strTree(spaces(indent), " ", toUpperCase(e.getProto().getName()), ",\n");
}, },
spaces(indent), "};\n" spaces(indent), "}\n"
"\n"), "\n"),
kj::strTree(), kj::strTree(),
@ -1487,7 +1493,7 @@ private:
} }
auto nodeTexts = KJ_MAP(nested, node.getNestedNodes()) { auto nodeTexts = KJ_MAP(nested, node.getNestedNodes()) {
return makeNodeText(namespacePrefix, "", nested.getName(), schemaLoader.get(nested.getId()), 0); return makeNodeText(namespacePrefix, "", nested.getName(), schemaLoader.get(nested.getId()), 1);
}; };
kj::String separator = kj::str("// ", kj::repeat('=', 87), "\n"); kj::String separator = kj::str("// ", kj::repeat('=', 87), "\n");
@ -1524,25 +1530,7 @@ private:
KJ_MAP(n, namespaceParts) { return kj::strTree("} // namespace\n"); }, "\n"), KJ_MAP(n, namespaceParts) { return kj::strTree("} // namespace\n"); }, "\n"),
kj::strTree( kj::strTree()
"// Generated by Cap'n Proto compiler, DO NOT EDIT\n"
"// source: ", baseName(displayName), "\n"
"\n"
"#include \"", baseName(displayName), ".h\"\n"
"\n"
"namespace capnp {\n"
"namespace schemas {\n",
KJ_MAP(n, nodeTexts) { return kj::mv(n.capnpSchemaDefs); },
"} // namespace schemas\n"
"namespace _ { // private\n",
KJ_MAP(n, nodeTexts) { return kj::mv(n.capnpPrivateDefs); },
"} // namespace _ (private)\n"
"} // namespace capnp\n",
sourceDefs.size() == 0 ? kj::strTree() : kj::strTree(
"\n", separator, "\n",
KJ_MAP(n, namespaceParts) { return kj::strTree("namespace ", n, " {\n"); }, "\n",
kj::mv(sourceDefs), "\n",
KJ_MAP(n, namespaceParts) { return kj::strTree("} // namespace\n"); }, "\n"))
}; };
} }