Commit 5f07c032 authored by Kenton Varda's avatar Kenton Varda

Mass-rename capnp::_::FieldSize -> capnp::ElementSize.

parent 9c54bce6
......@@ -564,14 +564,14 @@ struct List<T, Kind::INTERFACE> {
private:
inline static _::ListBuilder initPointer(_::PointerBuilder builder, uint size) {
return builder.initList(_::FieldSize::POINTER, size * ELEMENTS);
return builder.initList(ElementSize::POINTER, size * ELEMENTS);
}
inline static _::ListBuilder getFromPointer(_::PointerBuilder builder, const word* defaultValue) {
return builder.getList(_::FieldSize::POINTER, defaultValue);
return builder.getList(ElementSize::POINTER, defaultValue);
}
inline static _::ListReader getFromPointer(
const _::PointerReader& reader, const word* defaultValue) {
return reader.getList(_::FieldSize::POINTER, defaultValue);
return reader.getList(ElementSize::POINTER, defaultValue);
}
template <typename U, Kind k>
......
......@@ -67,32 +67,32 @@ inline uint64_t bitCast<uint64_t, double>(double value) {
return result;
}
_::FieldSize elementSizeFor(schema::Type::Which elementType) {
ElementSize elementSizeFor(schema::Type::Which elementType) {
switch (elementType) {
case schema::Type::VOID: return _::FieldSize::VOID;
case schema::Type::BOOL: return _::FieldSize::BIT;
case schema::Type::INT8: return _::FieldSize::BYTE;
case schema::Type::INT16: return _::FieldSize::TWO_BYTES;
case schema::Type::INT32: return _::FieldSize::FOUR_BYTES;
case schema::Type::INT64: return _::FieldSize::EIGHT_BYTES;
case schema::Type::UINT8: return _::FieldSize::BYTE;
case schema::Type::UINT16: return _::FieldSize::TWO_BYTES;
case schema::Type::UINT32: return _::FieldSize::FOUR_BYTES;
case schema::Type::UINT64: return _::FieldSize::EIGHT_BYTES;
case schema::Type::FLOAT32: return _::FieldSize::FOUR_BYTES;
case schema::Type::FLOAT64: return _::FieldSize::EIGHT_BYTES;
case schema::Type::TEXT: return _::FieldSize::POINTER;
case schema::Type::DATA: return _::FieldSize::POINTER;
case schema::Type::LIST: return _::FieldSize::POINTER;
case schema::Type::ENUM: return _::FieldSize::TWO_BYTES;
case schema::Type::STRUCT: return _::FieldSize::INLINE_COMPOSITE;
case schema::Type::INTERFACE: return _::FieldSize::POINTER;
case schema::Type::VOID: return ElementSize::VOID;
case schema::Type::BOOL: return ElementSize::BIT;
case schema::Type::INT8: return ElementSize::BYTE;
case schema::Type::INT16: return ElementSize::TWO_BYTES;
case schema::Type::INT32: return ElementSize::FOUR_BYTES;
case schema::Type::INT64: return ElementSize::EIGHT_BYTES;
case schema::Type::UINT8: return ElementSize::BYTE;
case schema::Type::UINT16: return ElementSize::TWO_BYTES;
case schema::Type::UINT32: return ElementSize::FOUR_BYTES;
case schema::Type::UINT64: return ElementSize::EIGHT_BYTES;
case schema::Type::FLOAT32: return ElementSize::FOUR_BYTES;
case schema::Type::FLOAT64: return ElementSize::EIGHT_BYTES;
case schema::Type::TEXT: return ElementSize::POINTER;
case schema::Type::DATA: return ElementSize::POINTER;
case schema::Type::LIST: return ElementSize::POINTER;
case schema::Type::ENUM: return ElementSize::TWO_BYTES;
case schema::Type::STRUCT: return ElementSize::INLINE_COMPOSITE;
case schema::Type::INTERFACE: return ElementSize::POINTER;
case schema::Type::ANY_POINTER: KJ_FAIL_ASSERT("List(AnyPointer) not supported."); break;
}
// Unknown type. Treat it as zero-size.
return _::FieldSize::VOID;
return ElementSize::VOID;
}
inline _::StructSize structSizeFromSchema(StructSchema schema) {
......@@ -1293,15 +1293,15 @@ Orphan<DynamicValue> DynamicList::Builder::disown(uint index) {
case schema::Type::ENUM: {
auto result = Orphan<DynamicValue>(operator[](index), _::OrphanBuilder());
switch (elementSizeFor(schema.whichElementType())) {
case _::FieldSize::VOID: break;
case _::FieldSize::BIT: builder.setDataElement<bool>(index * ELEMENTS, false); break;
case _::FieldSize::BYTE: builder.setDataElement<uint8_t>(index * ELEMENTS, 0); break;
case _::FieldSize::TWO_BYTES: builder.setDataElement<uint16_t>(index * ELEMENTS, 0); break;
case _::FieldSize::FOUR_BYTES: builder.setDataElement<uint32_t>(index * ELEMENTS, 0); break;
case _::FieldSize::EIGHT_BYTES: builder.setDataElement<uint64_t>(index * ELEMENTS, 0);break;
case _::FieldSize::POINTER:
case _::FieldSize::INLINE_COMPOSITE:
case ElementSize::VOID: break;
case ElementSize::BIT: builder.setDataElement<bool>(index * ELEMENTS, false); break;
case ElementSize::BYTE: builder.setDataElement<uint8_t>(index * ELEMENTS, 0); break;
case ElementSize::TWO_BYTES: builder.setDataElement<uint16_t>(index * ELEMENTS, 0); break;
case ElementSize::FOUR_BYTES: builder.setDataElement<uint32_t>(index * ELEMENTS, 0); break;
case ElementSize::EIGHT_BYTES: builder.setDataElement<uint64_t>(index * ELEMENTS, 0);break;
case ElementSize::POINTER:
case ElementSize::INLINE_COMPOSITE:
KJ_UNREACHABLE;
}
return kj::mv(result);
......
......@@ -124,7 +124,7 @@ static void setupStruct(StructBuilder builder) {
{
ListBuilder list = builder.getPointerField(1 * POINTERS)
.initList(FieldSize::FOUR_BYTES, 3 * ELEMENTS);
.initList(ElementSize::FOUR_BYTES, 3 * ELEMENTS);
EXPECT_EQ(3 * ELEMENTS, list.size());
list.setDataElement<int32_t>(0 * ELEMENTS, 200);
list.setDataElement<int32_t>(1 * ELEMENTS, 201);
......@@ -146,11 +146,11 @@ static void setupStruct(StructBuilder builder) {
{
ListBuilder list = builder.getPointerField(3 * POINTERS)
.initList(FieldSize::POINTER, 5 * ELEMENTS);
.initList(ElementSize::POINTER, 5 * ELEMENTS);
EXPECT_EQ(5 * ELEMENTS, list.size());
for (uint i = 0; i < 5; i++) {
ListBuilder element = list.getPointerElement(i * ELEMENTS)
.initList(FieldSize::TWO_BYTES, (i + 1) * ELEMENTS);
.initList(ElementSize::TWO_BYTES, (i + 1) * ELEMENTS);
EXPECT_EQ((i + 1) * ELEMENTS, element.size());
for (uint j = 0; j <= i; j++) {
element.setDataElement<uint16_t>(j * ELEMENTS, 500 + j);
......@@ -181,7 +181,7 @@ static void checkStruct(StructBuilder builder) {
{
ListBuilder list = builder.getPointerField(1 * POINTERS)
.getList(FieldSize::FOUR_BYTES, nullptr);
.getList(ElementSize::FOUR_BYTES, nullptr);
ASSERT_EQ(3 * ELEMENTS, list.size());
EXPECT_EQ(200, list.getDataElement<int32_t>(0 * ELEMENTS));
EXPECT_EQ(201, list.getDataElement<int32_t>(1 * ELEMENTS));
......@@ -204,11 +204,11 @@ static void checkStruct(StructBuilder builder) {
}
{
ListBuilder list = builder.getPointerField(3 * POINTERS).getList(FieldSize::POINTER, nullptr);
ListBuilder list = builder.getPointerField(3 * POINTERS).getList(ElementSize::POINTER, nullptr);
ASSERT_EQ(5 * ELEMENTS, list.size());
for (uint i = 0; i < 5; i++) {
ListBuilder element = list.getPointerElement(i * ELEMENTS)
.getList(FieldSize::TWO_BYTES, nullptr);
.getList(ElementSize::TWO_BYTES, nullptr);
ASSERT_EQ((i + 1) * ELEMENTS, element.size());
for (uint j = 0; j <= i; j++) {
EXPECT_EQ(500u + j, element.getDataElement<uint16_t>(j * ELEMENTS));
......@@ -238,7 +238,7 @@ static void checkStruct(StructReader reader) {
}
{
ListReader list = reader.getPointerField(1 * POINTERS).getList(FieldSize::FOUR_BYTES, nullptr);
ListReader list = reader.getPointerField(1 * POINTERS).getList(ElementSize::FOUR_BYTES, nullptr);
ASSERT_EQ(3 * ELEMENTS, list.size());
EXPECT_EQ(200, list.getDataElement<int32_t>(0 * ELEMENTS));
EXPECT_EQ(201, list.getDataElement<int32_t>(1 * ELEMENTS));
......@@ -247,7 +247,7 @@ static void checkStruct(StructReader reader) {
{
ListReader list = reader.getPointerField(2 * POINTERS)
.getList(FieldSize::INLINE_COMPOSITE, nullptr);
.getList(ElementSize::INLINE_COMPOSITE, nullptr);
ASSERT_EQ(4 * ELEMENTS, list.size());
for (int i = 0; i < 4; i++) {
StructReader element = list.getStructElement(i * ELEMENTS);
......@@ -260,11 +260,11 @@ static void checkStruct(StructReader reader) {
}
{
ListReader list = reader.getPointerField(3 * POINTERS).getList(FieldSize::POINTER, nullptr);
ListReader list = reader.getPointerField(3 * POINTERS).getList(ElementSize::POINTER, nullptr);
ASSERT_EQ(5 * ELEMENTS, list.size());
for (uint i = 0; i < 5; i++) {
ListReader element = list.getPointerElement(i * ELEMENTS)
.getList(FieldSize::TWO_BYTES, nullptr);
.getList(ElementSize::TWO_BYTES, nullptr);
ASSERT_EQ((i + 1) * ELEMENTS, element.size());
for (uint j = 0; j <= i; j++) {
EXPECT_EQ(500u + j, element.getDataElement<uint16_t>(j * ELEMENTS));
......
This diff is collapsed.
......@@ -78,11 +78,6 @@ class BuilderArena;
// =============================================================================
using FieldSize = capnp::ElementSize;
// Legacy typedef.
//
// TODO(cleanup): Replace all uses.
typedef decltype(BITS / ELEMENTS) BitsPerElement;
typedef decltype(POINTERS / ELEMENTS) PointersPerElement;
......@@ -97,48 +92,48 @@ static constexpr BitsPerElement BITS_PER_ELEMENT_TABLE[8] = {
0 * BITS / ELEMENTS
};
inline constexpr BitsPerElement dataBitsPerElement(FieldSize size) {
inline constexpr BitsPerElement dataBitsPerElement(ElementSize size) {
return _::BITS_PER_ELEMENT_TABLE[static_cast<int>(size)];
}
inline constexpr PointersPerElement pointersPerElement(FieldSize size) {
return size == FieldSize::POINTER ? 1 * POINTERS / ELEMENTS : 0 * POINTERS / ELEMENTS;
inline constexpr PointersPerElement pointersPerElement(ElementSize size) {
return size == ElementSize::POINTER ? 1 * POINTERS / ELEMENTS : 0 * POINTERS / ELEMENTS;
}
template <size_t size> struct ElementSizeForByteSize;
template <> struct ElementSizeForByteSize<1> { static constexpr FieldSize value = FieldSize::BYTE; };
template <> struct ElementSizeForByteSize<2> { static constexpr FieldSize value = FieldSize::TWO_BYTES; };
template <> struct ElementSizeForByteSize<4> { static constexpr FieldSize value = FieldSize::FOUR_BYTES; };
template <> struct ElementSizeForByteSize<8> { static constexpr FieldSize value = FieldSize::EIGHT_BYTES; };
template <> struct ElementSizeForByteSize<1> { static constexpr ElementSize value = ElementSize::BYTE; };
template <> struct ElementSizeForByteSize<2> { static constexpr ElementSize value = ElementSize::TWO_BYTES; };
template <> struct ElementSizeForByteSize<4> { static constexpr ElementSize value = ElementSize::FOUR_BYTES; };
template <> struct ElementSizeForByteSize<8> { static constexpr ElementSize value = ElementSize::EIGHT_BYTES; };
template <typename T> struct ElementSizeForType {
static constexpr FieldSize value =
static constexpr ElementSize value =
// Primitive types that aren't special-cased below can be determined from sizeof().
CAPNP_KIND(T) == Kind::PRIMITIVE ? ElementSizeForByteSize<sizeof(T)>::value :
CAPNP_KIND(T) == Kind::ENUM ? FieldSize::TWO_BYTES :
CAPNP_KIND(T) == Kind::STRUCT ? FieldSize::INLINE_COMPOSITE :
CAPNP_KIND(T) == Kind::ENUM ? ElementSize::TWO_BYTES :
CAPNP_KIND(T) == Kind::STRUCT ? ElementSize::INLINE_COMPOSITE :
// Everything else is a pointer.
FieldSize::POINTER;
ElementSize::POINTER;
};
// Void and bool are special.
template <> struct ElementSizeForType<Void> { static constexpr FieldSize value = FieldSize::VOID; };
template <> struct ElementSizeForType<bool> { static constexpr FieldSize value = FieldSize::BIT; };
template <> struct ElementSizeForType<Void> { static constexpr ElementSize value = ElementSize::VOID; };
template <> struct ElementSizeForType<bool> { static constexpr ElementSize value = ElementSize::BIT; };
// Lists and blobs are pointers, not structs.
template <typename T, bool b> struct ElementSizeForType<List<T, b>> {
static constexpr FieldSize value = FieldSize::POINTER;
static constexpr ElementSize value = ElementSize::POINTER;
};
template <> struct ElementSizeForType<Text> {
static constexpr FieldSize value = FieldSize::POINTER;
static constexpr ElementSize value = ElementSize::POINTER;
};
template <> struct ElementSizeForType<Data> {
static constexpr FieldSize value = FieldSize::POINTER;
static constexpr ElementSize value = ElementSize::POINTER;
};
template <typename T>
inline constexpr FieldSize elementSizeForType() {
inline constexpr ElementSize elementSizeForType() {
return ElementSizeForType<T>::value;
}
......@@ -287,7 +282,7 @@ public:
bool isList();
StructBuilder getStruct(StructSize size, const word* defaultValue);
ListBuilder getList(FieldSize elementSize, const word* defaultValue);
ListBuilder getList(ElementSize elementSize, const word* defaultValue);
ListBuilder getStructList(StructSize elementSize, const word* defaultValue);
ListBuilder getListAnySize(const word* defaultValue);
template <typename T> typename T::Builder getBlob(const void* defaultValue,ByteCount defaultSize);
......@@ -299,7 +294,7 @@ public:
// simple byte array for blobs.
StructBuilder initStruct(StructSize size);
ListBuilder initList(FieldSize elementSize, ElementCount elementCount);
ListBuilder initList(ElementSize elementSize, ElementCount elementCount);
ListBuilder initStructList(ElementCount elementCount, StructSize size);
template <typename T> typename T::Builder initBlob(ByteCount size);
// Init methods: Initialize the pointer to a newly-allocated object, discarding the existing
......@@ -368,7 +363,7 @@ public:
bool isList() const;
StructReader getStruct(const word* defaultValue) const;
ListReader getList(FieldSize expectedElementSize, const word* defaultValue) const;
ListReader getList(ElementSize expectedElementSize, const word* defaultValue) const;
ListReader getListAnySize(const word* defaultValue) const;
template <typename T>
typename T::Reader getBlob(const void* defaultValue, ByteCount defaultSize) const;
......@@ -566,7 +561,7 @@ public:
inline word* getLocation() {
// Get the object's location.
if (elementSize == FieldSize::INLINE_COMPOSITE) {
if (elementSize == ElementSize::INLINE_COMPOSITE) {
return reinterpret_cast<word*>(ptr) - POINTER_SIZE_IN_WORDS;
} else {
return reinterpret_cast<word*>(ptr);
......@@ -616,14 +611,14 @@ private:
// The struct properties to use when interpreting the elements as structs. All lists can be
// interpreted as struct lists, so these are always filled in.
FieldSize elementSize;
// The element size as a FieldSize. This is only really needed to disambiguate INLINE_COMPOSITE
ElementSize elementSize;
// The element size as a ElementSize. This is only really needed to disambiguate INLINE_COMPOSITE
// from other types when the overall size is exactly zero or one words.
inline ListBuilder(SegmentBuilder* segment, void* ptr,
decltype(BITS / ELEMENTS) step, ElementCount size,
BitCount structDataSize, WirePointerCount structPointerCount,
FieldSize elementSize)
ElementSize elementSize)
: segment(segment), ptr(reinterpret_cast<byte*>(ptr)),
elementCount(size), step(step), structDataSize(structDataSize),
structPointerCount(structPointerCount), elementSize(elementSize) {}
......@@ -672,8 +667,8 @@ private:
// The struct properties to use when interpreting the elements as structs. All lists can be
// interpreted as struct lists, so these are always filled in.
FieldSize elementSize;
// The element size as a FieldSize. This is only really needed to disambiguate INLINE_COMPOSITE
ElementSize elementSize;
// The element size as a ElementSize. This is only really needed to disambiguate INLINE_COMPOSITE
// from other types when the overall size is exactly zero or one words.
int nestingLimit;
......@@ -683,7 +678,7 @@ private:
inline ListReader(SegmentReader* segment, const void* ptr,
ElementCount elementCount, decltype(BITS / ELEMENTS) step,
BitCount structDataSize, WirePointerCount structPointerCount,
FieldSize elementSize, int nestingLimit)
ElementSize elementSize, int nestingLimit)
: segment(segment), ptr(reinterpret_cast<const byte*>(ptr)), elementCount(elementCount),
step(step), structDataSize(structDataSize),
structPointerCount(structPointerCount), elementSize(elementSize),
......@@ -706,7 +701,7 @@ public:
static OrphanBuilder initStruct(BuilderArena* arena, StructSize size);
static OrphanBuilder initList(BuilderArena* arena, ElementCount elementCount,
FieldSize elementSize);
ElementSize elementSize);
static OrphanBuilder initStructList(BuilderArena* arena, ElementCount elementCount,
StructSize elementSize);
static OrphanBuilder initText(BuilderArena* arena, ByteCount size);
......@@ -732,7 +727,7 @@ public:
StructBuilder asStruct(StructSize size);
// Interpret as a struct, or throw an exception if not a struct.
ListBuilder asList(FieldSize elementSize);
ListBuilder asList(ElementSize elementSize);
// Interpret as a list, or throw an exception if not a list. elementSize cannot be
// INLINE_COMPOSITE -- use asStructList() instead.
......@@ -744,7 +739,7 @@ public:
// Interpret as a blob, or throw an exception if not a blob.
StructReader asStructReader(StructSize size) const;
ListReader asListReader(FieldSize elementSize) const;
ListReader asListReader(ElementSize elementSize) const;
#if !CAPNP_LITE
kj::Own<ClientHook> asCapability() const;
#endif // !CAPNP_LITE
......@@ -821,7 +816,7 @@ inline Data::Builder StructBuilder::getDataSectionAsBlob() {
inline _::ListBuilder StructBuilder::getPointerSectionAsList() {
return _::ListBuilder(segment, pointers, pointerCount * BITS_PER_POINTER / ELEMENTS,
pointerCount * (1 * ELEMENTS / POINTERS),
0 * BITS, 1 * POINTERS, FieldSize::POINTER);
0 * BITS, 1 * POINTERS, ElementSize::POINTER);
}
template <typename T>
......@@ -905,7 +900,7 @@ inline Data::Reader StructReader::getDataSectionAsBlob() {
inline _::ListReader StructReader::getPointerSectionAsList() {
return _::ListReader(segment, pointers, pointerCount * (1 * ELEMENTS / POINTERS),
pointerCount * BITS_PER_POINTER / ELEMENTS,
0 * BITS, 1 * POINTERS, FieldSize::POINTER, nestingLimit);
0 * BITS, 1 * POINTERS, ElementSize::POINTER, nestingLimit);
}
template <typename T>
......
......@@ -302,7 +302,7 @@ private:
}
inline static _::ListReader getFromPointer(
const _::PointerReader& reader, const word* defaultValue) {
return reader.getList(_::FieldSize::INLINE_COMPOSITE, defaultValue);
return reader.getList(ElementSize::INLINE_COMPOSITE, defaultValue);
}
template <typename U, Kind k>
......@@ -406,14 +406,14 @@ struct List<List<T>, Kind::LIST> {
private:
inline static _::ListBuilder initPointer(_::PointerBuilder builder, uint size) {
return builder.initList(_::FieldSize::POINTER, size * ELEMENTS);
return builder.initList(ElementSize::POINTER, size * ELEMENTS);
}
inline static _::ListBuilder getFromPointer(_::PointerBuilder builder, const word* defaultValue) {
return builder.getList(_::FieldSize::POINTER, defaultValue);
return builder.getList(ElementSize::POINTER, defaultValue);
}
inline static _::ListReader getFromPointer(
const _::PointerReader& reader, const word* defaultValue) {
return reader.getList(_::FieldSize::POINTER, defaultValue);
return reader.getList(ElementSize::POINTER, defaultValue);
}
template <typename U, Kind k>
......@@ -504,14 +504,14 @@ struct List<T, Kind::BLOB> {
private:
inline static _::ListBuilder initPointer(_::PointerBuilder builder, uint size) {
return builder.initList(_::FieldSize::POINTER, size * ELEMENTS);
return builder.initList(ElementSize::POINTER, size * ELEMENTS);
}
inline static _::ListBuilder getFromPointer(_::PointerBuilder builder, const word* defaultValue) {
return builder.getList(_::FieldSize::POINTER, defaultValue);
return builder.getList(ElementSize::POINTER, defaultValue);
}
inline static _::ListReader getFromPointer(
const _::PointerReader& reader, const word* defaultValue) {
return reader.getList(_::FieldSize::POINTER, defaultValue);
return reader.getList(ElementSize::POINTER, defaultValue);
}
template <typename U, Kind k>
......
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