Commit 917f459e authored by Kenton Varda's avatar Kenton Varda

Mass rename 'reference' -> 'pointer'. Been meaning to do this for a while --…

Mass rename 'reference' -> 'pointer'.  Been meaning to do this for a while -- all the documentation talks about 'pointers', not 'references'.
parent e550bee1
This diff is collapsed.
......@@ -656,13 +656,13 @@ struct PointerHelpers<DynamicStruct, Kind::UNKNOWN> {
// non-dynamic types PointerHelpers::get() takes a default value as the third argument, and we
// don't want people to accidentally be able to provide their own default value.
static DynamicStruct::Reader getDynamic(
StructReader reader, WireReferenceCount index, StructSchema schema);
StructReader reader, WirePointerCount index, StructSchema schema);
static DynamicStruct::Builder getDynamic(
StructBuilder builder, WireReferenceCount index, StructSchema schema);
StructBuilder builder, WirePointerCount index, StructSchema schema);
static void set(
StructBuilder builder, WireReferenceCount index, DynamicStruct::Reader value);
StructBuilder builder, WirePointerCount index, DynamicStruct::Reader value);
static DynamicStruct::Builder init(
StructBuilder builder, WireReferenceCount index, StructSchema schema);
StructBuilder builder, WirePointerCount index, StructSchema schema);
};
template <>
......@@ -671,13 +671,13 @@ struct PointerHelpers<DynamicList, Kind::UNKNOWN> {
// non-dynamic types PointerHelpers::get() takes a default value as the third argument, and we
// don't want people to accidentally be able to provide their own default value.
static DynamicList::Reader getDynamic(
StructReader reader, WireReferenceCount index, ListSchema schema);
StructReader reader, WirePointerCount index, ListSchema schema);
static DynamicList::Builder getDynamic(
StructBuilder builder, WireReferenceCount index, ListSchema schema);
StructBuilder builder, WirePointerCount index, ListSchema schema);
static void set(
StructBuilder builder, WireReferenceCount index, DynamicList::Reader value);
StructBuilder builder, WirePointerCount index, DynamicList::Reader value);
static DynamicList::Builder init(
StructBuilder builder, WireReferenceCount index, ListSchema schema, uint size);
StructBuilder builder, WirePointerCount index, ListSchema schema, uint size);
};
} // namespace internal
......
......@@ -40,64 +40,64 @@ namespace internal {
template <typename T>
struct PointerHelpers<T, Kind::STRUCT> {
static inline typename T::Reader get(StructReader reader, WireReferenceCount index,
static inline typename T::Reader get(StructReader reader, WirePointerCount index,
const word* defaultValue = nullptr) {
return typename T::Reader(reader.getStructField(index, defaultValue));
}
static inline typename T::Builder get(StructBuilder builder, WireReferenceCount index,
static inline typename T::Builder get(StructBuilder builder, WirePointerCount index,
const word* defaultValue = nullptr) {
return typename T::Builder(builder.getStructField(index, structSize<T>(), defaultValue));
}
static inline void set(StructBuilder builder, WireReferenceCount index,
static inline void set(StructBuilder builder, WirePointerCount index,
typename T::Reader value) {
// TODO(now): schemaless copy
CAPNPROTO_INLINE_PRECOND(false, "Not implemented: set() for struct fields.");
}
static inline typename T::Builder init(StructBuilder builder, WireReferenceCount index) {
static inline typename T::Builder init(StructBuilder builder, WirePointerCount index) {
return typename T::Builder(builder.initStructField(index, structSize<T>()));
}
};
template <typename T>
struct PointerHelpers<List<T>, Kind::LIST> {
static inline typename List<T>::Reader get(StructReader reader, WireReferenceCount index,
static inline typename List<T>::Reader get(StructReader reader, WirePointerCount index,
const word* defaultValue = nullptr) {
return typename List<T>::Reader(List<T>::getAsFieldOf(reader, index, defaultValue));
}
static inline typename List<T>::Builder get(StructBuilder builder, WireReferenceCount index,
static inline typename List<T>::Builder get(StructBuilder builder, WirePointerCount index,
const word* defaultValue = nullptr) {
return typename List<T>::Builder(List<T>::getAsFieldOf(builder, index, defaultValue));
}
static inline void set(StructBuilder builder, WireReferenceCount index,
static inline void set(StructBuilder builder, WirePointerCount index,
typename List<T>::Reader value) {
init(builder, index, value.size()).copyFrom(value);
}
static inline void set(StructBuilder builder, WireReferenceCount index,
static inline void set(StructBuilder builder, WirePointerCount index,
std::initializer_list<ReaderFor<T>> value) {
init(builder, index, value.size()).copyFrom(value);
}
static inline typename List<T>::Builder init(
StructBuilder builder, WireReferenceCount index, uint size) {
StructBuilder builder, WirePointerCount index, uint size) {
return typename List<T>::Builder(List<T>::initAsFieldOf(builder, index, size));
}
};
template <typename T>
struct PointerHelpers<T, Kind::BLOB> {
static inline typename T::Reader get(StructReader reader, WireReferenceCount index,
static inline typename T::Reader get(StructReader reader, WirePointerCount index,
const void* defaultValue = nullptr,
uint defaultBytes = 0) {
return reader.getBlobField<T>(index, defaultValue, defaultBytes * BYTES);
}
static inline typename T::Builder get(StructBuilder builder, WireReferenceCount index,
static inline typename T::Builder get(StructBuilder builder, WirePointerCount index,
const void* defaultValue = nullptr,
uint defaultBytes = 0) {
return builder.getBlobField<T>(index, defaultValue, defaultBytes * BYTES);
}
static inline void set(StructBuilder builder, WireReferenceCount index, typename T::Reader value) {
static inline void set(StructBuilder builder, WirePointerCount index, typename T::Reader value) {
builder.setBlobField<T>(index, value);
}
static inline typename T::Builder init(StructBuilder builder, WireReferenceCount index, uint size) {
static inline typename T::Builder init(StructBuilder builder, WirePointerCount index, uint size) {
return builder.initBlobField<T>(index, size * BYTES);
}
};
......@@ -114,7 +114,7 @@ struct PointerHelpers<TrustedMessage> {
// itself trusted. This hack is currently private. It is used to locate default values within
// encoded schemas.
static inline const word* get(StructReader reader, WireReferenceCount index) {
static inline const word* get(StructReader reader, WirePointerCount index) {
return reader.getTrustedPointer(index);
}
};
......@@ -177,7 +177,7 @@ inline constexpr uint64_t typeId() { return internal::TypeIdFor<T>::typeId; }
template <> struct KindOf<type> { static constexpr Kind kind = Kind::STRUCT; }; \
template <> struct StructSizeFor<type> { \
static constexpr StructSize value = StructSize( \
dataWordSize * WORDS, pointerCount * REFERENCES, FieldSize::preferredElementEncoding); \
dataWordSize * WORDS, pointerCount * POINTERS, FieldSize::preferredElementEncoding); \
}; \
template <> struct TypeIdFor<type> { static constexpr uint64_t typeId = 0x##id; }; \
template <> struct RawSchemaFor<type> { \
......
......@@ -40,7 +40,7 @@ namespace {
TEST(WireFormat, SimpleRawDataStruct) {
AlignedData<2> data = {{
// Struct ref, offset = 1, dataSize = 1, referenceCount = 0
// Struct ref, offset = 1, dataSize = 1, pointerCount = 0
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
// Content for the data segment.
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef
......@@ -103,7 +103,7 @@ static const AlignedData<2> STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT =
{{0,0,0,0,1,0,0,0, 0,0,0,0,0,0,0,0}};
static constexpr StructSize STRUCTLIST_ELEMENT_SIZE(
1 * WORDS, 1 * REFERENCES, FieldSize::INLINE_COMPOSITE);
1 * WORDS, 1 * POINTERS, FieldSize::INLINE_COMPOSITE);
static void setupStruct(StructBuilder builder) {
builder.setDataField<uint64_t>(0 * ELEMENTS, 0x1011121314151617ull);
......@@ -121,12 +121,12 @@ static void setupStruct(StructBuilder builder) {
{
StructBuilder subStruct = builder.initStructField(
0 * REFERENCES, StructSize(1 * WORDS, 0 * REFERENCES, FieldSize::EIGHT_BYTES));
0 * POINTERS, StructSize(1 * WORDS, 0 * POINTERS, FieldSize::EIGHT_BYTES));
subStruct.setDataField<uint32_t>(0 * ELEMENTS, 123);
}
{
ListBuilder list = builder.initListField(1 * REFERENCES, FieldSize::FOUR_BYTES, 3 * ELEMENTS);
ListBuilder list = builder.initListField(1 * POINTERS, FieldSize::FOUR_BYTES, 3 * ELEMENTS);
EXPECT_EQ(3 * ELEMENTS, list.size());
list.setDataElement<int32_t>(0 * ELEMENTS, 200);
list.setDataElement<int32_t>(1 * ELEMENTS, 201);
......@@ -135,19 +135,19 @@ static void setupStruct(StructBuilder builder) {
{
ListBuilder list = builder.initStructListField(
2 * REFERENCES, 4 * ELEMENTS, STRUCTLIST_ELEMENT_SIZE);
2 * POINTERS, 4 * ELEMENTS, STRUCTLIST_ELEMENT_SIZE);
EXPECT_EQ(4 * ELEMENTS, list.size());
for (int i = 0; i < 4; i++) {
StructBuilder element = list.getStructElement(i * ELEMENTS);
element.setDataField<int32_t>(0 * ELEMENTS, 300 + i);
element.initStructField(0 * REFERENCES,
StructSize(1 * WORDS, 0 * REFERENCES, FieldSize::EIGHT_BYTES))
element.initStructField(0 * POINTERS,
StructSize(1 * WORDS, 0 * POINTERS, FieldSize::EIGHT_BYTES))
.setDataField<int32_t>(0 * ELEMENTS, 400 + i);
}
}
{
ListBuilder list = builder.initListField(3 * REFERENCES, FieldSize::REFERENCE, 5 * ELEMENTS);
ListBuilder list = builder.initListField(3 * POINTERS, FieldSize::POINTER, 5 * ELEMENTS);
EXPECT_EQ(5 * ELEMENTS, list.size());
for (uint i = 0; i < 5; i++) {
ListBuilder element = list.initListElement(
......@@ -176,13 +176,13 @@ static void checkStruct(StructBuilder builder) {
{
StructBuilder subStruct = builder.getStructField(
0 * REFERENCES, StructSize(1 * WORDS, 0 * REFERENCES, FieldSize::EIGHT_BYTES),
0 * POINTERS, StructSize(1 * WORDS, 0 * POINTERS, FieldSize::EIGHT_BYTES),
SUBSTRUCT_DEFAULT.words);
EXPECT_EQ(123u, subStruct.getDataField<uint32_t>(0 * ELEMENTS));
}
{
ListBuilder list = builder.getListField(1 * REFERENCES, nullptr);
ListBuilder list = builder.getListField(1 * POINTERS, 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));
......@@ -190,21 +190,21 @@ static void checkStruct(StructBuilder builder) {
}
{
ListBuilder list = builder.getListField(2 * REFERENCES, nullptr);
ListBuilder list = builder.getListField(2 * POINTERS, nullptr);
ASSERT_EQ(4 * ELEMENTS, list.size());
for (int i = 0; i < 4; i++) {
StructBuilder element = list.getStructElement(i * ELEMENTS);
EXPECT_EQ(300 + i, element.getDataField<int32_t>(0 * ELEMENTS));
EXPECT_EQ(400 + i,
element.getStructField(0 * REFERENCES,
StructSize(1 * WORDS, 0 * REFERENCES, FieldSize::EIGHT_BYTES),
element.getStructField(0 * POINTERS,
StructSize(1 * WORDS, 0 * POINTERS, FieldSize::EIGHT_BYTES),
STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT.words)
.getDataField<int32_t>(0 * ELEMENTS));
}
}
{
ListBuilder list = builder.getListField(3 * REFERENCES, nullptr);
ListBuilder list = builder.getListField(3 * POINTERS, nullptr);
ASSERT_EQ(5 * ELEMENTS, list.size());
for (uint i = 0; i < 5; i++) {
ListBuilder element = list.getListElement(i * ELEMENTS);
......@@ -231,12 +231,12 @@ static void checkStruct(StructReader reader) {
EXPECT_FALSE(reader.getDataField<bool>(127 * ELEMENTS));
{
StructReader subStruct = reader.getStructField(0 * REFERENCES, SUBSTRUCT_DEFAULT.words);
StructReader subStruct = reader.getStructField(0 * POINTERS, SUBSTRUCT_DEFAULT.words);
EXPECT_EQ(123u, subStruct.getDataField<uint32_t>(0 * ELEMENTS));
}
{
ListReader list = reader.getListField(1 * REFERENCES, FieldSize::FOUR_BYTES, nullptr);
ListReader list = reader.getListField(1 * POINTERS, FieldSize::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));
......@@ -244,20 +244,20 @@ static void checkStruct(StructReader reader) {
}
{
ListReader list = reader.getListField(2 * REFERENCES, FieldSize::INLINE_COMPOSITE, nullptr);
ListReader list = reader.getListField(2 * POINTERS, FieldSize::INLINE_COMPOSITE, nullptr);
ASSERT_EQ(4 * ELEMENTS, list.size());
for (int i = 0; i < 4; i++) {
StructReader element = list.getStructElement(i * ELEMENTS);
EXPECT_EQ(300 + i, element.getDataField<int32_t>(0 * ELEMENTS));
EXPECT_EQ(400 + i,
element.getStructField(0 * REFERENCES, STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT.words)
element.getStructField(0 * POINTERS, STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT.words)
.getDataField<int32_t>(0 * ELEMENTS));
}
}
{
// TODO: Use valid default value.
ListReader list = reader.getListField(3 * REFERENCES, FieldSize::REFERENCE, nullptr);
ListReader list = reader.getListField(3 * POINTERS, FieldSize::POINTER, nullptr);
ASSERT_EQ(5 * ELEMENTS, list.size());
for (uint i = 0; i < 5; i++) {
ListReader element = list.getListElement(i * ELEMENTS, FieldSize::TWO_BYTES);
......@@ -276,11 +276,11 @@ TEST(WireFormat, StructRoundTrip_OneSegment) {
word* rootLocation = segment->allocate(1 * WORDS);
StructBuilder builder = StructBuilder::initRoot(
segment, rootLocation, StructSize(2 * WORDS, 4 * REFERENCES, FieldSize::INLINE_COMPOSITE));
segment, rootLocation, StructSize(2 * WORDS, 4 * POINTERS, FieldSize::INLINE_COMPOSITE));
setupStruct(builder);
// word count:
// 1 root reference
// 1 root pointer
// 6 root struct
// 1 sub message
// 2 3-element int32 list
......@@ -288,10 +288,10 @@ TEST(WireFormat, StructRoundTrip_OneSegment) {
// 1 tag
// 12 4x struct
// 1 data segment
// 1 reference segment
// 1 pointer segment
// 1 sub-struct
// 11 list list
// 5 references to sub-lists
// 5 pointers to sub-lists
// 6 sub-lists (4x 1 word, 1x 2 words)
// -----
// 34
......@@ -312,7 +312,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation) {
word* rootLocation = segment->allocate(1 * WORDS);
StructBuilder builder = StructBuilder::initRoot(
segment, rootLocation, StructSize(2 * WORDS, 4 * REFERENCES, FieldSize::INLINE_COMPOSITE));
segment, rootLocation, StructSize(2 * WORDS, 4 * POINTERS, FieldSize::INLINE_COMPOSITE));
setupStruct(builder);
// Verify that we made 15 segments.
......@@ -320,7 +320,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation) {
ASSERT_EQ(15u, segments.size());
// Check that each segment has the expected size. Recall that the first word of each segment will
// actually be a reference to the first thing allocated within that segment.
// actually be a pointer to the first thing allocated within that segment.
EXPECT_EQ( 1u, segments[ 0].size()); // root ref
EXPECT_EQ( 7u, segments[ 1].size()); // root struct
EXPECT_EQ( 2u, segments[ 2].size()); // sub-struct
......@@ -349,7 +349,7 @@ TEST(WireFormat, StructRoundTrip_MultipleSegmentsWithMultipleAllocations) {
word* rootLocation = segment->allocate(1 * WORDS);
StructBuilder builder = StructBuilder::initRoot(
segment, rootLocation, StructSize(2 * WORDS, 4 * REFERENCES, FieldSize::INLINE_COMPOSITE));
segment, rootLocation, StructSize(2 * WORDS, 4 * POINTERS, FieldSize::INLINE_COMPOSITE));
setupStruct(builder);
// Verify that we made 6 segments.
......
This diff is collapsed.
This diff is collapsed.
......@@ -94,22 +94,22 @@ template <typename T> struct FieldSizeForType {
kind<T>() == Kind::STRUCT ? FieldSize::INLINE_COMPOSITE :
// Everything else is a pointer.
FieldSize::REFERENCE;
FieldSize::POINTER;
};
// Void and bool are special.
template <> struct FieldSizeForType<Void> { static constexpr FieldSize value = FieldSize::VOID; };
template <> struct FieldSizeForType<bool> { static constexpr FieldSize value = FieldSize::BIT; };
// Lists and blobs are references, not structs.
// Lists and blobs are pointers, not structs.
template <typename T, bool b> struct FieldSizeForType<List<T, b>> {
static constexpr FieldSize value = FieldSize::REFERENCE;
static constexpr FieldSize value = FieldSize::POINTER;
};
template <> struct FieldSizeForType<Text> {
static constexpr FieldSize value = FieldSize::REFERENCE;
static constexpr FieldSize value = FieldSize::POINTER;
};
template <> struct FieldSizeForType<Data> {
static constexpr FieldSize value = FieldSize::REFERENCE;
static constexpr FieldSize value = FieldSize::POINTER;
};
template <typename T>
......@@ -265,15 +265,15 @@ private:
}
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
internal::StructBuilder& builder, WirePointerCount index, uint size) {
return builder.initListField(index, internal::FieldSizeForType<T>::value, size * ELEMENTS);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, const word* defaultValue) {
internal::StructBuilder& builder, WirePointerCount index, const word* defaultValue) {
return builder.getListField(index, defaultValue);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index, const word* defaultValue) {
internal::StructReader& reader, WirePointerCount index, const word* defaultValue) {
return reader.getListField(index, internal::FieldSizeForType<T>::value, defaultValue);
}
......@@ -351,15 +351,15 @@ private:
}
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
internal::StructBuilder& builder, WirePointerCount index, uint size) {
return builder.initStructListField(index, size * ELEMENTS, internal::structSize<T>());
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, const word* defaultValue) {
internal::StructBuilder& builder, WirePointerCount index, const word* defaultValue) {
return builder.getListField(index, defaultValue);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index, const word* defaultValue) {
internal::StructReader& reader, WirePointerCount index, const word* defaultValue) {
return reader.getListField(index, internal::FieldSize::INLINE_COMPOSITE, defaultValue);
}
......@@ -425,7 +425,7 @@ private:
inline static internal::ListBuilder initAsElementOf(
const internal::ListBuilder& builder, uint index, uint size) {
return builder.initListElement(
index * ELEMENTS, internal::FieldSize::REFERENCE, size * ELEMENTS);
index * ELEMENTS, internal::FieldSize::POINTER, size * ELEMENTS);
}
inline static internal::ListBuilder getAsElementOf(
const internal::ListBuilder& builder, uint index) {
......@@ -433,20 +433,20 @@ private:
}
inline static internal::ListReader getAsElementOf(
const internal::ListReader& reader, uint index) {
return reader.getListElement(index * ELEMENTS, internal::FieldSize::REFERENCE);
return reader.getListElement(index * ELEMENTS, internal::FieldSize::POINTER);
}
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return builder.initListField(index, internal::FieldSize::REFERENCE, size * ELEMENTS);
internal::StructBuilder& builder, WirePointerCount index, uint size) {
return builder.initListField(index, internal::FieldSize::POINTER, size * ELEMENTS);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, const word* defaultValue) {
internal::StructBuilder& builder, WirePointerCount index, const word* defaultValue) {
return builder.getListField(index, defaultValue);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index, const word* defaultValue) {
return reader.getListField(index, internal::FieldSize::REFERENCE, defaultValue);
internal::StructReader& reader, WirePointerCount index, const word* defaultValue) {
return reader.getListField(index, internal::FieldSize::POINTER, defaultValue);
}
template <typename U, Kind k>
......@@ -526,7 +526,7 @@ private:
inline static internal::ListBuilder initAsElementOf(
const internal::ListBuilder& builder, uint index, uint size) {
return builder.initListElement(
index * ELEMENTS, internal::FieldSize::REFERENCE, size * ELEMENTS);
index * ELEMENTS, internal::FieldSize::POINTER, size * ELEMENTS);
}
inline static internal::ListBuilder getAsElementOf(
const internal::ListBuilder& builder, uint index) {
......@@ -534,20 +534,20 @@ private:
}
inline static internal::ListReader getAsElementOf(
const internal::ListReader& reader, uint index) {
return reader.getListElement(index * ELEMENTS, internal::FieldSize::REFERENCE);
return reader.getListElement(index * ELEMENTS, internal::FieldSize::POINTER);
}
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return builder.initListField(index, internal::FieldSize::REFERENCE, size * ELEMENTS);
internal::StructBuilder& builder, WirePointerCount index, uint size) {
return builder.initListField(index, internal::FieldSize::POINTER, size * ELEMENTS);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, const word* defaultValue) {
internal::StructBuilder& builder, WirePointerCount index, const word* defaultValue) {
return builder.getListField(index, defaultValue);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index, const word* defaultValue) {
return reader.getListField(index, internal::FieldSize::REFERENCE, defaultValue);
internal::StructReader& reader, WirePointerCount index, const word* defaultValue) {
return reader.getListField(index, internal::FieldSize::POINTER, defaultValue);
}
template <typename U, Kind k>
......
......@@ -78,11 +78,11 @@ internal::SegmentBuilder* MessageBuilder::getRootSegment() {
new(arena()) internal::BuilderArena(this);
allocatedArena = true;
WordCount refSize = 1 * REFERENCES * WORDS_PER_REFERENCE;
internal::SegmentBuilder* segment = arena()->getSegmentWithAvailable(refSize);
WordCount ptrSize = 1 * POINTERS * WORDS_PER_POINTER;
internal::SegmentBuilder* segment = arena()->getSegmentWithAvailable(ptrSize);
CHECK(segment->getSegmentId() == internal::SegmentId(0),
"First allocated word of new arena was not in segment ID 0.");
word* location = segment->allocate(refSize);
word* location = segment->allocate(ptrSize);
CHECK(location == segment->getPtrUnchecked(0 * WORDS),
"First allocated word of new arena was not the first word in its segment.");
return segment;
......
......@@ -391,7 +391,7 @@ TEST(Packed, RoundTripAllZero) {
checkTestMessageAllZero(reader.getRoot<TestAllTypes>());
// Segment table packs to 2 bytes.
// Root reference packs to 3 bytes.
// Root pointer packs to 3 bytes.
// Content packs to 2 bytes (zero span).
EXPECT_LE(pipe.getData().size(), 7u);
}
......
......@@ -787,7 +787,7 @@ class word { uint64_t content; CAPNPROTO_DISALLOW_COPY(word); public: word() = d
static_assert(sizeof(byte) == 1, "uint8_t is not one byte?");
static_assert(sizeof(word) == 8, "uint64_t is not 8 bytes?");
namespace internal { class BitLabel; class ElementLabel; class WireReference; }
namespace internal { class BitLabel; class ElementLabel; class WirePointer; }
#ifndef CAPNPROTO_DEBUG_TYPES
#define CAPNPROTO_DEBUG_TYPES 1
......@@ -828,11 +828,11 @@ typedef Quantity<uint16_t, internal::ElementLabel> ElementCount16;
typedef Quantity<uint32_t, internal::ElementLabel> ElementCount32;
typedef Quantity<uint64_t, internal::ElementLabel> ElementCount64;
typedef Quantity<uint, internal::WireReference> WireReferenceCount;
typedef Quantity<uint8_t, internal::WireReference> WireReferenceCount8;
typedef Quantity<uint16_t, internal::WireReference> WireReferenceCount16;
typedef Quantity<uint32_t, internal::WireReference> WireReferenceCount32;
typedef Quantity<uint64_t, internal::WireReference> WireReferenceCount64;
typedef Quantity<uint, internal::WirePointer> WirePointerCount;
typedef Quantity<uint8_t, internal::WirePointer> WirePointerCount8;
typedef Quantity<uint16_t, internal::WirePointer> WirePointerCount16;
typedef Quantity<uint32_t, internal::WirePointer> WirePointerCount32;
typedef Quantity<uint64_t, internal::WirePointer> WirePointerCount64;
#else
......@@ -860,11 +860,11 @@ typedef uint16_t ElementCount16;
typedef uint32_t ElementCount32;
typedef uint64_t ElementCount64;
typedef uint WireReferenceCount;
typedef uint8_t WireReferenceCount8;
typedef uint16_t WireReferenceCount16;
typedef uint32_t WireReferenceCount32;
typedef uint64_t WireReferenceCount64;
typedef uint WirePointerCount;
typedef uint8_t WirePointerCount8;
typedef uint16_t WirePointerCount16;
typedef uint32_t WirePointerCount32;
typedef uint64_t WirePointerCount64;
#endif
......@@ -872,17 +872,17 @@ constexpr BitCount BITS = unit<BitCount>();
constexpr ByteCount BYTES = unit<ByteCount>();
constexpr WordCount WORDS = unit<WordCount>();
constexpr ElementCount ELEMENTS = unit<ElementCount>();
constexpr WireReferenceCount REFERENCES = unit<WireReferenceCount>();
constexpr WirePointerCount POINTERS = unit<WirePointerCount>();
constexpr auto BITS_PER_BYTE = 8 * BITS / BYTES;
constexpr auto BITS_PER_WORD = 64 * BITS / WORDS;
constexpr auto BYTES_PER_WORD = 8 * BYTES / WORDS;
constexpr auto BITS_PER_REFERENCE = 64 * BITS / REFERENCES;
constexpr auto BYTES_PER_REFERENCE = 8 * BYTES / REFERENCES;
constexpr auto WORDS_PER_REFERENCE = 1 * WORDS / REFERENCES;
constexpr auto BITS_PER_POINTER = 64 * BITS / POINTERS;
constexpr auto BYTES_PER_POINTER = 8 * BYTES / POINTERS;
constexpr auto WORDS_PER_POINTER = 1 * WORDS / POINTERS;
constexpr WordCount REFERENCE_SIZE_IN_WORDS = 1 * REFERENCES * WORDS_PER_REFERENCE;
constexpr WordCount POINTER_SIZE_IN_WORDS = 1 * POINTERS * WORDS_PER_POINTER;
template <typename T>
inline constexpr decltype(BYTES / ELEMENTS) bytesPerElement() {
......
......@@ -481,26 +481,26 @@ extractFieldNumbers decls = concat
data PackingState = PackingState
{ packingHoles :: Map.Map DataSize Integer
, packingDataSize :: Integer
, packingReferenceCount :: Integer
, packingPointerCount :: Integer
}
initialPackingState = PackingState Map.empty 0 0
packValue :: FieldSize -> PackingState -> (FieldOffset, PackingState)
packValue SizeVoid s = (VoidOffset, s)
packValue SizeReference s@(PackingState { packingReferenceCount = rc }) =
(PointerOffset rc, s { packingReferenceCount = rc + 1 })
packValue SizePointer s@(PackingState { packingPointerCount = rc }) =
(PointerOffset rc, s { packingPointerCount = rc + 1 })
packValue (SizeInlineComposite (DataSectionWords inlineDs) inlineRc)
s@(PackingState { packingDataSize = ds, packingReferenceCount = rc }) =
s@(PackingState { packingDataSize = ds, packingPointerCount = rc }) =
(InlineCompositeOffset ds rc (DataSectionWords inlineDs) inlineRc,
s { packingDataSize = ds + inlineDs
, packingReferenceCount = rc + inlineRc })
, packingPointerCount = rc + inlineRc })
packValue (SizeInlineComposite inlineDs inlineRc)
s@(PackingState { packingReferenceCount = rc }) = let
s@(PackingState { packingPointerCount = rc }) = let
size = (dataSectionAlignment inlineDs)
(offset, s2) = packData size s
in (InlineCompositeOffset offset rc inlineDs inlineRc,
s2 { packingReferenceCount = rc + inlineRc })
s2 { packingPointerCount = rc + inlineRc })
packValue (SizeData size) s = let (o, s2) = packData size s in (DataOffset size o, s2)
packData :: DataSize -> PackingState -> (Integer, PackingState)
......@@ -569,14 +569,14 @@ packUnionizedValue (SizeData size) (UnionPackingState (UnionSlot slotSize slotOf
Nothing -> packUnionizedValue (SizeData size)
(UnionPackingState (UnionSlot (DataSectionWords 0) 0) p) s
-- Pack reference when we don't have a reference slot.
packUnionizedValue SizeReference u@(UnionPackingState _ (UnionSlot 0 _)) s = let
(PointerOffset offset, s2) = packValue SizeReference s
-- Pack pointer when we don't have a pointer slot.
packUnionizedValue SizePointer u@(UnionPackingState _ (UnionSlot 0 _)) s = let
(PointerOffset offset, s2) = packValue SizePointer s
u2 = u { unionPointerSlot = UnionSlot 1 offset }
in (PointerOffset offset, u2, s2)
-- Pack reference when we already have a reference slot allocated.
packUnionizedValue SizeReference u@(UnionPackingState _ (UnionSlot _ offset)) s =
-- Pack pointer when we already have a pointer slot allocated.
packUnionizedValue SizePointer u@(UnionPackingState _ (UnionSlot _ offset)) s =
(PointerOffset offset, u, s)
-- Pack inline composite.
......@@ -621,14 +621,14 @@ packUnionizedValue (SizeInlineComposite dataSize pointerCount)
-- Pack the pointer section.
(pointerOffset, u3, s3)
| pointerCount <= pointerSlotSize = (pointerSlotOffset, u2, s2)
| pointerSlotOffset + pointerSlotSize == packingReferenceCount s2 =
| pointerSlotOffset + pointerSlotSize == packingPointerCount s2 =
(pointerSlotOffset,
u2 { unionPointerSlot = UnionSlot pointerCount pointerSlotOffset },
s2 { packingReferenceCount = pointerSlotOffset + pointerCount })
s2 { packingPointerCount = pointerSlotOffset + pointerCount })
| otherwise =
(packingReferenceCount s2,
u2 { unionPointerSlot = UnionSlot pointerCount (packingReferenceCount s2) },
s2 { packingReferenceCount = packingReferenceCount s2 + pointerCount })
(packingPointerCount s2,
u2 { unionPointerSlot = UnionSlot pointerCount (packingPointerCount s2) },
s2 { packingPointerCount = packingPointerCount s2 + pointerCount })
combinedOffset = InlineCompositeOffset
{ inlineCompositeDataOffset = dataOffset
......@@ -738,7 +738,7 @@ packFields fields unions = let
then dataSizeToSectionSize $ stripHolesFromFirstWord Size64 $ packingHoles finalState
else DataSectionWords $ packingDataSize finalState
in (dataSectionSize, packingReferenceCount finalState, Map.fromList packedItems)
in (dataSectionSize, packingPointerCount finalState, Map.fromList packedItems)
enforceFixed Nothing sizes = return sizes
enforceFixed (Just (Located pos (requestedDataSize, requestedPointerCount)))
......
......@@ -195,7 +195,7 @@ cxxFieldSizeString (SizeData Size8) = "BYTE";
cxxFieldSizeString (SizeData Size16) = "TWO_BYTES";
cxxFieldSizeString (SizeData Size32) = "FOUR_BYTES";
cxxFieldSizeString (SizeData Size64) = "EIGHT_BYTES";
cxxFieldSizeString SizeReference = "REFERENCE";
cxxFieldSizeString SizePointer = "POINTER";
cxxFieldSizeString (SizeInlineComposite _ _) = "INLINE_COMPOSITE";
fieldOffsetInteger VoidOffset = "0"
......@@ -207,7 +207,7 @@ fieldOffsetInteger (InlineCompositeOffset d p ds ps) = let
DataSectionWords _ -> d * 8
_ -> d * byteSize
in printf "%d * ::capnproto::BYTES, %d * ::capnproto::BYTES, \
\%d * ::capnproto::REFERENCES, %d * ::capnproto::REFERENCES" byteOffset byteSize p ps
\%d * ::capnproto::POINTERS, %d * ::capnproto::POINTERS" byteOffset byteSize p ps
isDefaultZero VoidDesc = True
isDefaultZero (BoolDesc b) = not b
......@@ -473,7 +473,7 @@ outerFileContext schemaNodes = fileContext where
context "structFields" = MuList $ map (fieldContext context) $ structFields desc
context "structUnions" = MuList $ map (unionContext context) $ structUnions desc
context "structDataSize" = MuVariable $ dataSectionWordSize $ structDataSize desc
context "structReferenceCount" = MuVariable $ structPointerCount desc
context "structPointerCount" = MuVariable $ structPointerCount desc
context "structPreferredListEncoding" = case (structDataSize desc, structPointerCount desc) of
(DataSectionWords 0, 0) -> MuVariable "VOID"
(DataSection1, 0) -> MuVariable "BIT"
......@@ -481,7 +481,7 @@ outerFileContext schemaNodes = fileContext where
(DataSection16, 0) -> MuVariable "TWO_BYTES"
(DataSection32, 0) -> MuVariable "FOUR_BYTES"
(DataSectionWords 1, 0) -> MuVariable "EIGHT_BYTES"
(DataSectionWords 0, 1) -> MuVariable "REFERENCE"
(DataSectionWords 0, 1) -> MuVariable "POINTER"
_ -> MuVariable "INLINE_COMPOSITE"
context "structNestedEnums" =
MuList $ map (enumContext context) [m | DescEnum m <- structMembers desc]
......
......@@ -272,12 +272,12 @@ dataSizeInBits Size64 = 64
data FieldSize = SizeVoid
| SizeData DataSize
| SizeReference
| SizePointer
| SizeInlineComposite DataSectionSize Integer
fieldSizeInBits SizeVoid = 0
fieldSizeInBits (SizeData d) = dataSizeInBits d
fieldSizeInBits SizeReference = 64
fieldSizeInBits SizePointer = 64
fieldSizeInBits (SizeInlineComposite ds pc) = dataSectionBits ds + pc * 64
data FieldOffset = VoidOffset
......@@ -293,7 +293,7 @@ data FieldOffset = VoidOffset
offsetToSize :: FieldOffset -> FieldSize
offsetToSize VoidOffset = SizeVoid
offsetToSize (DataOffset s _) = SizeData s
offsetToSize (PointerOffset _) = SizeReference
offsetToSize (PointerOffset _) = SizePointer
offsetToSize (InlineCompositeOffset _ _ d p) = SizeInlineComposite d p
fieldSize (BuiltinType BuiltinVoid) = SizeVoid
......@@ -308,15 +308,15 @@ fieldSize (BuiltinType BuiltinUInt32) = SizeData Size32
fieldSize (BuiltinType BuiltinUInt64) = SizeData Size64
fieldSize (BuiltinType BuiltinFloat32) = SizeData Size32
fieldSize (BuiltinType BuiltinFloat64) = SizeData Size64
fieldSize (BuiltinType BuiltinText) = SizeReference
fieldSize (BuiltinType BuiltinData) = SizeReference
fieldSize (BuiltinType BuiltinObject) = SizeReference
fieldSize (BuiltinType BuiltinText) = SizePointer
fieldSize (BuiltinType BuiltinData) = SizePointer
fieldSize (BuiltinType BuiltinObject) = SizePointer
fieldSize (EnumType _) = SizeData Size16
fieldSize (StructType _) = SizeReference
fieldSize (StructType _) = SizePointer
fieldSize (InlineStructType StructDesc { structDataSize = ds, structPointerCount = ps }) =
SizeInlineComposite ds ps
fieldSize (InterfaceType _) = SizeReference
fieldSize (ListType _) = SizeReference
fieldSize (InterfaceType _) = SizePointer
fieldSize (ListType _) = SizePointer
fieldSize (InlineListType element size) = let
minDataSectionForBits bits
| bits <= 0 = DataSectionWords 0
......@@ -328,12 +328,12 @@ fieldSize (InlineListType element size) = let
dataSection = case fieldSize element of
SizeVoid -> DataSectionWords 0
SizeData s -> minDataSectionForBits $ dataSizeInBits s * size
SizeReference -> DataSectionWords 0
SizePointer -> DataSectionWords 0
SizeInlineComposite ds _ -> minDataSectionForBits $ dataSectionBits ds * size
pointerCount = case fieldSize element of
SizeVoid -> 0
SizeData _ -> 0
SizeReference -> size
SizePointer -> size
SizeInlineComposite _ pc -> pc * size
in SizeInlineComposite dataSection pointerCount
fieldSize (InlineDataType size)
......
This diff is collapsed.
......@@ -113,7 +113,7 @@ namespace internal {
{{#typeStruct}}
CAPNPROTO_DECLARE_STRUCT(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}, {{structId}},
{{structDataSize}}, {{structReferenceCount}}, {{structPreferredListEncoding}});
{{structDataSize}}, {{structPointerCount}}, {{structPreferredListEncoding}});
{{#structNestedEnums}}
CAPNPROTO_DECLARE_ENUM(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}::{{enumName}}, {{enumId}});
......@@ -302,7 +302,7 @@ inline {{fieldType}}::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
"Must check which() before get()ing a union member.");
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<{{fieldType}}>::get(
_reader, {{fieldOffset}} * ::capnproto::REFERENCES{{#fieldDefaultBytes}},
_reader, {{fieldOffset}} * ::capnproto::POINTERS{{#fieldDefaultBytes}},
DEFAULT_{{fieldUpperCase}}.words{{#fieldIsBlob}}, {{defaultBlobSize}}{{/fieldIsBlob}}{{/fieldDefaultBytes}});
}
......@@ -312,7 +312,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}()
"Must check which() before get()ing a union member.");
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<{{fieldType}}>::get(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES{{#fieldDefaultBytes}},
_builder, {{fieldOffset}} * ::capnproto::POINTERS{{#fieldDefaultBytes}},
DEFAULT_{{fieldUpperCase}}.words{{#fieldIsBlob}}, {{defaultBlobSize}}{{/fieldIsBlob}}{{/fieldDefaultBytes}});
}
......@@ -322,7 +322,7 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}({{fieldType}}::Read
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}}
::capnproto::internal::PointerHelpers<{{fieldType}}>::set(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, value);
_builder, {{fieldOffset}} * ::capnproto::POINTERS, value);
}
{{#fieldIsList}}
......@@ -333,7 +333,7 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}(
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}}
::capnproto::internal::PointerHelpers<{{fieldType}}>::set(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, value);
_builder, {{fieldOffset}} * ::capnproto::POINTERS, value);
}
{{/fieldIsList}}
......@@ -344,7 +344,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<{{fieldType}}>::init(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, size);
_builder, {{fieldOffset}} * ::capnproto::POINTERS, size);
}
{{/fieldIsListOrBlob}}
......@@ -355,7 +355,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<{{fieldType}}>::init(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES);
_builder, {{fieldOffset}} * ::capnproto::POINTERS);
}
{{/fieldIsStruct}}
......@@ -370,7 +370,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
"Must check which() before get()ing a union member.");
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::get(
_reader, {{fieldOffset}} * ::capnproto::REFERENCES);
_reader, {{fieldOffset}} * ::capnproto::POINTERS);
}
template <typename T>
......@@ -380,7 +380,7 @@ inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() {
"Must check which() before get()ing a union member.");
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::get(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES);
_builder, {{fieldOffset}} * ::capnproto::POINTERS);
}
template <typename T, typename Param>
......@@ -390,7 +390,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}(Param&
"Must check which() before get()ing a union member.");
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::getDynamic(
_reader, {{fieldOffset}} * ::capnproto::REFERENCES, ::capnproto::forward<Param>(param));
_reader, {{fieldOffset}} * ::capnproto::POINTERS, ::capnproto::forward<Param>(param));
}
template <typename T, typename Param>
......@@ -400,7 +400,7 @@ inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}(Para
"Must check which() before get()ing a union member.");
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::getDynamic(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, ::capnproto::forward<Param>(param));
_builder, {{fieldOffset}} * ::capnproto::POINTERS, ::capnproto::forward<Param>(param));
}
template <typename T>
......@@ -410,7 +410,7 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}(typename T::Reader
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}}
::capnproto::internal::PointerHelpers<T>::set(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, value);
_builder, {{fieldOffset}} * ::capnproto::POINTERS, value);
}
template <typename T, typename... Params>
......@@ -420,7 +420,7 @@ inline typename T::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(Par
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::init(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, ::capnproto::forward<Params>(params)...);
_builder, {{fieldOffset}} * ::capnproto::POINTERS, ::capnproto::forward<Params>(params)...);
}
{{/fieldIsGenericObject}}
......
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