STRUCT_SIZE
This commit is contained in:
parent
d3726d6118
commit
bb7a437ce2
2 changed files with 23 additions and 9 deletions
|
@ -3,7 +3,7 @@ package org.capnproto;
|
||||||
public final class StructSize {
|
public final class StructSize {
|
||||||
public final short data; // number of words in data section
|
public final short data; // number of words in data section
|
||||||
public final short pointers; // number of words in pointer section
|
public final short pointers; // number of words in pointer section
|
||||||
public final byte preferredListEncoding;
|
public final byte preferredListEncoding; // a FieldSize
|
||||||
|
|
||||||
public StructSize(short data, short pointers, byte preferredListEncoding) {
|
public StructSize(short data, short pointers, byte preferredListEncoding) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
|
|
@ -929,7 +929,11 @@ private:
|
||||||
" return new ", type, ".Reader<",
|
" return new ", type, ".Reader<",
|
||||||
elementReaderType,
|
elementReaderType,
|
||||||
">(_reader.getPointerField(",
|
">(_reader.getPointerField(",
|
||||||
offset, ").getList(org.capnproto.FieldSize.INLINE_COMPOSITE), ", elementReaderType, ".factory);\n") :
|
offset, ").getList(",
|
||||||
|
|
||||||
|
// XXX what about lists of non-structs?
|
||||||
|
typeName(typeBody.getList().getElementType()),".STRUCT_SIZE.preferredListEncoding), ",
|
||||||
|
elementReaderType, ".factory);\n") :
|
||||||
(kind == FieldKind::BLOB ?
|
(kind == FieldKind::BLOB ?
|
||||||
kj::strTree(spaces(indent), " return _reader.getPointerField(",
|
kj::strTree(spaces(indent), " return _reader.getPointerField(",
|
||||||
offset,").getText();\n") :
|
offset,").getText();\n") :
|
||||||
|
@ -1066,8 +1070,10 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
kj::StringTree makeBuilderDef(kj::StringPtr fullName, kj::StringPtr unqualifiedParentType,
|
kj::StringTree makeBuilderDef(kj::StringPtr fullName, kj::StringPtr unqualifiedParentType,
|
||||||
bool isUnion, kj::Array<kj::StringTree>&& methodDecls,
|
schema::Node::Struct::Reader structNode,
|
||||||
|
kj::Array<kj::StringTree>&& methodDecls,
|
||||||
int indent) {
|
int indent) {
|
||||||
|
bool isUnion = structNode.getDiscriminantCount() != 0;
|
||||||
return kj::strTree(
|
return kj::strTree(
|
||||||
spaces(indent), "public static final class Builder {\n",
|
spaces(indent), "public static final class Builder {\n",
|
||||||
spaces(indent), " public static class Factory implements org.capnproto.FromStructBuilder<Builder> {\n",
|
spaces(indent), " public static class Factory implements org.capnproto.FromStructBuilder<Builder> {\n",
|
||||||
|
@ -1075,7 +1081,7 @@ private:
|
||||||
spaces(indent), " return new Builder(builder);\n",
|
spaces(indent), " return new Builder(builder);\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public final org.capnproto.StructSize structSize() {\n",
|
spaces(indent), " public final org.capnproto.StructSize structSize() {\n",
|
||||||
spaces(indent), " throw new Error();\n",
|
spaces(indent), " return ", fullName, ".STRUCT_SIZE;\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public static final Factory factory = new Factory();\n",
|
spaces(indent), " public static final Factory factory = new Factory();\n",
|
||||||
|
@ -1094,19 +1100,27 @@ private:
|
||||||
|
|
||||||
auto structNode = proto.getStruct();
|
auto structNode = proto.getStruct();
|
||||||
uint discrimOffset = structNode.getDiscriminantOffset();
|
uint discrimOffset = structNode.getDiscriminantOffset();
|
||||||
|
structNode.getPointerCount();
|
||||||
|
|
||||||
return StructText {
|
return StructText {
|
||||||
kj::strTree(
|
kj::strTree(
|
||||||
" struct ", name, ";\n"),
|
" struct ", name, ";\n"),
|
||||||
|
|
||||||
kj::strTree(spaces(indent), "public static class ", name, " {\n",
|
kj::strTree(
|
||||||
|
spaces(indent), "public static class ", name, " {\n",
|
||||||
|
kj::strTree(
|
||||||
|
spaces(indent), " public static final org.capnproto.StructSize STRUCT_SIZE =\n",
|
||||||
|
spaces(indent), " new org.capnproto.StructSize((short)", structNode.getDataWordCount(),
|
||||||
|
",(short)", structNode.getPointerCount(),
|
||||||
|
", org.capnproto.FieldSize.", FIELD_SIZE_NAMES[(int)structNode.getPreferredListEncoding()], ");\n"),
|
||||||
|
|
||||||
kj::strTree(makeReaderDef(fullName, name, structNode.getDiscriminantCount() != 0,
|
kj::strTree(makeReaderDef(fullName, name, structNode.getDiscriminantCount() != 0,
|
||||||
structNode.getDiscriminantOffset(),
|
structNode.getDiscriminantOffset(),
|
||||||
KJ_MAP(f, fieldTexts) { return kj::mv(f.readerMethodDecls); },
|
KJ_MAP(f, fieldTexts) { return kj::mv(f.readerMethodDecls); },
|
||||||
indent + 1)),
|
|
||||||
makeBuilderDef(fullName, name, structNode.getDiscriminantCount() != 0,
|
|
||||||
KJ_MAP(f, fieldTexts) { return kj::mv(f.builderMethodDecls); },
|
|
||||||
indent + 1),
|
indent + 1),
|
||||||
|
makeBuilderDef(fullName, name, structNode,
|
||||||
|
KJ_MAP(f, fieldTexts) { return kj::mv(f.builderMethodDecls); },
|
||||||
|
indent + 1)),
|
||||||
|
|
||||||
structNode.getDiscriminantCount() == 0 ?
|
structNode.getDiscriminantCount() == 0 ?
|
||||||
kj::strTree() :
|
kj::strTree() :
|
||||||
|
|
Loading…
Reference in a new issue