a separate class for each PrimitiveList
This commit is contained in:
parent
da8d0d1f56
commit
ff931e2cac
4 changed files with 282 additions and 74 deletions
|
@ -273,18 +273,25 @@ private:
|
|||
auto elementType = type.getList().getElementType();
|
||||
switch (elementType.which()) {
|
||||
case schema::Type::VOID:
|
||||
return kj::strTree(" org.capnproto.PrimitiveList.Void");
|
||||
case schema::Type::BOOL:
|
||||
return kj::strTree(" org.capnproto.PrimitiveList.Boolean");
|
||||
case schema::Type::INT8:
|
||||
case schema::Type::INT16:
|
||||
case schema::Type::INT32:
|
||||
case schema::Type::INT64:
|
||||
case schema::Type::UINT8:
|
||||
return kj::strTree(" org.capnproto.PrimitiveList.Byte");
|
||||
case schema::Type::INT16:
|
||||
case schema::Type::UINT16:
|
||||
return kj::strTree(" org.capnproto.PrimitiveList.Short");
|
||||
case schema::Type::INT32:
|
||||
case schema::Type::UINT32:
|
||||
return kj::strTree(" org.capnproto.PrimitiveList.Int");
|
||||
case schema::Type::INT64:
|
||||
case schema::Type::UINT64:
|
||||
return kj::strTree(" org.capnproto.PrimitiveList.Long");
|
||||
case schema::Type::FLOAT32:
|
||||
return kj::strTree(" org.capnproto.PrimitiveList.Float");
|
||||
case schema::Type::FLOAT64:
|
||||
return kj::strTree(" org.capnproto.PrimitiveList");
|
||||
return kj::strTree(" org.capnproto.PrimitiveList.Double");
|
||||
case schema::Type::STRUCT:
|
||||
return kj::strTree(" org.capnproto.StructList");
|
||||
case schema::Type::TEXT:
|
||||
|
@ -979,9 +986,11 @@ private:
|
|||
|
||||
kj::String elementReaderType;
|
||||
kj::String elementBuilderType;
|
||||
kj::String builderFactoryType;
|
||||
kj::String readerFactoryType;
|
||||
kj::String builderFactoryArg = kj::str("");
|
||||
kj::String readerFactoryArg = kj::str("");
|
||||
kj::String fieldSize;
|
||||
kj::String readerClass = kj::str("Reader");
|
||||
kj::String builderClass = kj::str("Builder");
|
||||
bool isStructOrCapList = false;
|
||||
bool isStructList = false;
|
||||
if (kind == FieldKind::LIST) {
|
||||
|
@ -990,28 +999,43 @@ private:
|
|||
switch (typeBody.getList().getElementType().which()) {
|
||||
case schema::Type::VOID:
|
||||
primitiveElement = true;
|
||||
builderFactoryType = kj::str("org.capnproto.PrimitiveElementFactory.VOID");
|
||||
readerFactoryType = kj::str(builderFactoryType);
|
||||
fieldSize = kj::str("org.capnproto.FieldSize.VOID");
|
||||
break;
|
||||
case schema::Type::BOOL:
|
||||
case schema::Type::INT8:
|
||||
case schema::Type::INT16:
|
||||
case schema::Type::INT32:
|
||||
case schema::Type::INT64:
|
||||
case schema::Type::UINT8:
|
||||
case schema::Type::UINT16:
|
||||
case schema::Type::UINT32:
|
||||
case schema::Type::UINT64:
|
||||
case schema::Type::FLOAT32:
|
||||
case schema::Type::FLOAT64:
|
||||
builderFactoryType = kj::str("ord.capnproto.PrimitiveElementFactory.",
|
||||
toUpperCase(kj::str(typeName(typeBody.getList().getElementType()))));
|
||||
readerFactoryType = kj::str(builderFactoryType);
|
||||
primitiveElement = true;
|
||||
fieldSize = kj::str("org.capnproto.FieldSize.BIT");
|
||||
break;
|
||||
|
||||
case schema::Type::INT8:
|
||||
case schema::Type::UINT8:
|
||||
primitiveElement = true;
|
||||
fieldSize = kj::str("org.capnproto.FieldSize.BYTE");
|
||||
break;
|
||||
|
||||
|
||||
case schema::Type::INT16:
|
||||
case schema::Type::UINT16:
|
||||
primitiveElement = true;
|
||||
fieldSize = kj::str("org.capnproto.FieldSize.TWO_BYTES");
|
||||
break;
|
||||
|
||||
case schema::Type::INT32:
|
||||
case schema::Type::UINT32:
|
||||
case schema::Type::FLOAT32:
|
||||
primitiveElement = true;
|
||||
fieldSize = kj::str("org.capnproto.FieldSize.FOUR_BYTES");
|
||||
break;
|
||||
|
||||
case schema::Type::INT64:
|
||||
case schema::Type::UINT64:
|
||||
case schema::Type::FLOAT64:
|
||||
primitiveElement = true;
|
||||
fieldSize = kj::str("org.capnproto.FieldSize.EIGHT_BYTES");
|
||||
break;
|
||||
|
||||
case schema::Type::ENUM:
|
||||
primitiveElement = true;
|
||||
fieldSize = kj::str("org.capnproto.FieldSize.TWO_BYTES");
|
||||
break;
|
||||
|
||||
case schema::Type::TEXT:
|
||||
|
@ -1032,9 +1056,11 @@ private:
|
|||
isStructOrCapList = true;
|
||||
primitiveElement = false;
|
||||
elementReaderType = kj::str(typeName(typeBody.getList().getElementType()), ".Reader");
|
||||
readerClass = kj::str("Reader<", elementReaderType, ">");
|
||||
elementBuilderType = kj::str(typeName(typeBody.getList().getElementType()), ".Builder");
|
||||
readerFactoryType = kj::str(elementReaderType, ".factory"),
|
||||
builderFactoryType = kj::str(elementBuilderType, ".factory"),
|
||||
builderClass = kj::str("Builder<", elementBuilderType, ">");
|
||||
readerFactoryArg = kj::str(elementReaderType, ".factory,"),
|
||||
builderFactoryArg = kj::str(elementBuilderType, ".factory,"),
|
||||
fieldSize = kj::str(typeName(typeBody.getList().getElementType()),".STRUCT_SIZE.preferredListEncoding");
|
||||
break;
|
||||
}
|
||||
|
@ -1052,11 +1078,10 @@ private:
|
|||
spaces(indent), " return !_reader.getPointerField(", offset, ").isNull();\n",
|
||||
spaces(indent), " }\n",
|
||||
|
||||
spaces(indent), " public final ", type, ".Reader<", elementReaderType, ">",
|
||||
spaces(indent), " public final ", type, ".", readerClass,
|
||||
" get", titleCase, "() {\n",
|
||||
spaces(indent), " return new ", type, ".Reader<", elementReaderType, ">(\n",
|
||||
spaces(indent), " ", readerFactoryType, ",\n",
|
||||
spaces(indent), " _reader.getPointerField(", offset, ").getList(",
|
||||
spaces(indent), " return new ", type, ".", readerClass, "(\n",
|
||||
spaces(indent), " ", readerFactoryArg, "_reader.getPointerField(", offset, ").getList(",
|
||||
fieldSize, ")",
|
||||
");\n",
|
||||
spaces(indent), " }\n",
|
||||
|
@ -1067,18 +1092,17 @@ private:
|
|||
spaces(indent), " public final boolean has", titleCase, "() {\n",
|
||||
spaces(indent), " return !_builder.getPointerField(", offset, ").isNull();\n",
|
||||
spaces(indent), " }\n",
|
||||
spaces(indent), " public final ", type, ".Builder<",elementBuilderType, ">",
|
||||
spaces(indent), " public final ", type, ".", builderClass,
|
||||
" get", titleCase, "() {\n",
|
||||
spaces(indent), " throw new Error();\n",
|
||||
spaces(indent), " }\n",
|
||||
spaces(indent), " public final void set", titleCase, "(", type, ".Reader value) {\n",
|
||||
spaces(indent), " throw new Error();\n",
|
||||
spaces(indent), " }\n",
|
||||
spaces(indent), " public final ", type, ".Builder<", elementBuilderType,">",
|
||||
spaces(indent), " public final ", type, ".", builderClass,
|
||||
" init", titleCase, "(int size) {\n",
|
||||
spaces(indent), " return new ", type, ".Builder<", elementBuilderType, ">(\n",
|
||||
spaces(indent), " ", builderFactoryType, ",\n",
|
||||
spaces(indent), " _builder.getPointerField(", offset, ").init",
|
||||
spaces(indent), " return new ", type, ".", builderClass, "(\n",
|
||||
spaces(indent), " ", builderFactoryArg, "_builder.getPointerField(", offset, ").init",
|
||||
(isStructList ?
|
||||
kj::strTree("StructList(size,", typeName(typeBody.getList().getElementType()),".STRUCT_SIZE)") :
|
||||
kj::strTree("List(", fieldSize, ", size)")),
|
||||
|
|
|
@ -35,7 +35,17 @@ struct TestAllTypes {
|
|||
interfaceField @16 : Void; # TODO
|
||||
|
||||
voidList @17 : List(Void);
|
||||
# boolList @18 : List(Bool);
|
||||
boolList @18 : List(Bool);
|
||||
int8List @19 : List(Int8);
|
||||
int16List @20 : List(Int16);
|
||||
int32List @21 : List(Int32);
|
||||
int64List @22 : List(Int64);
|
||||
uInt8List @23 : List(UInt8);
|
||||
uInt16List @24 : List(UInt16);
|
||||
uInt32List @25 : List(UInt32);
|
||||
uInt64List @26 : List(UInt64);
|
||||
float32List @27 : List(Float32);
|
||||
float64List @28 : List(Float64);
|
||||
# ...
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package org.capnproto;
|
||||
|
||||
public interface PrimitiveElementFactory<T> {
|
||||
public T get(ListReader listReader, int index);
|
||||
|
||||
public static final PrimitiveElementFactory<Void> VOID = new PrimitiveElementFactoryVoid();
|
||||
// public static final PrimitiveElementFactory<boolean> BOOLEAN = new PrimitiveElementFactoryBoolean();
|
||||
}
|
||||
|
||||
|
||||
class PrimitiveElementFactoryVoid implements PrimitiveElementFactory<Void> {
|
||||
public Void get(ListReader listReader, int index) {
|
||||
return Void.VOID;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
argh, generics must be boxed.
|
||||
class PrimitiveElementFactoryBoolean implements PrimitiveElementFactory<boolean> {
|
||||
public boolean get(ListReader listReader, int index) {
|
||||
throw new Error("unimplemented");
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -1,12 +1,11 @@
|
|||
package org.capnproto;
|
||||
|
||||
public class PrimitiveList {
|
||||
public static final class Reader<T> {
|
||||
public static class Void {
|
||||
public static final class Reader {
|
||||
public final ListReader reader;
|
||||
public final PrimitiveElementFactory<T> factory;
|
||||
|
||||
public Reader(PrimitiveElementFactory<T> factory, ListReader reader) {
|
||||
this.factory = factory;
|
||||
public Reader(ListReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
|
@ -14,20 +13,219 @@ public class PrimitiveList {
|
|||
return this.reader.size();
|
||||
}
|
||||
|
||||
public T get(int index) {
|
||||
return this.factory.get(this.reader, index);
|
||||
public org.capnproto.Void get(int index) {
|
||||
return org.capnproto.Void.VOID;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Builder<T> {
|
||||
public static final class Builder {
|
||||
public final ListBuilder builder;
|
||||
public final PrimitiveElementFactory<T> factory;
|
||||
|
||||
public Builder(PrimitiveElementFactory<T> factory, ListBuilder builder) {
|
||||
this.factory = factory;
|
||||
public Builder(ListBuilder builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class Boolean {
|
||||
public static final class Reader {
|
||||
public final ListReader reader;
|
||||
|
||||
public Reader(ListReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.reader.size();
|
||||
}
|
||||
|
||||
public boolean get(int index) {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
public final ListBuilder builder;
|
||||
|
||||
public Builder(ListBuilder builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class Byte {
|
||||
public static final class Reader {
|
||||
public final ListReader reader;
|
||||
|
||||
public Reader(ListReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.reader.size();
|
||||
}
|
||||
|
||||
public byte get(int index) {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
public final ListBuilder builder;
|
||||
|
||||
public Builder(ListBuilder builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Short {
|
||||
public static final class Reader {
|
||||
public final ListReader reader;
|
||||
|
||||
public Reader(ListReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.reader.size();
|
||||
}
|
||||
|
||||
public short get(int index) {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
public final ListBuilder builder;
|
||||
|
||||
public Builder(ListBuilder builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Int {
|
||||
public static final class Reader {
|
||||
public final ListReader reader;
|
||||
|
||||
public Reader(ListReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.reader.size();
|
||||
}
|
||||
|
||||
public int get(int index) {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
public final ListBuilder builder;
|
||||
|
||||
public Builder(ListBuilder builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Float {
|
||||
public static final class Reader {
|
||||
public final ListReader reader;
|
||||
|
||||
public Reader(ListReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.reader.size();
|
||||
}
|
||||
|
||||
public float get(int index) {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
public final ListBuilder builder;
|
||||
|
||||
public Builder(ListBuilder builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class Long {
|
||||
public static final class Reader {
|
||||
public final ListReader reader;
|
||||
|
||||
public Reader(ListReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.reader.size();
|
||||
}
|
||||
|
||||
public long get(int index) {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
public final ListBuilder builder;
|
||||
|
||||
public Builder(ListBuilder builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Double {
|
||||
public static final class Reader {
|
||||
public final ListReader reader;
|
||||
|
||||
public Reader(ListReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.reader.size();
|
||||
}
|
||||
|
||||
public double get(int index) {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
public final ListBuilder builder;
|
||||
|
||||
public Builder(ListBuilder builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue