Commit de33baaf authored by Kenton Varda's avatar Kenton Varda

Simplify more after removing inline types.

parent 7197456b
...@@ -102,7 +102,8 @@ static const AlignedData<2> SUBSTRUCT_DEFAULT = {{0,0,0,0,1,0,0,0, 0,0,0,0,0,0, ...@@ -102,7 +102,8 @@ static const AlignedData<2> SUBSTRUCT_DEFAULT = {{0,0,0,0,1,0,0,0, 0,0,0,0,0,0,
static const AlignedData<2> STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT = static const AlignedData<2> STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT =
{{0,0,0,0,1,0,0,0, 0,0,0,0,0,0,0,0}}; {{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, 8 * BYTES); static constexpr StructSize STRUCTLIST_ELEMENT_SIZE(
1 * WORDS, 1 * REFERENCES, FieldSize::INLINE_COMPOSITE);
static void setupStruct(StructBuilder builder) { static void setupStruct(StructBuilder builder) {
builder.setDataField<uint64_t>(0 * ELEMENTS, 0x1011121314151617ull); builder.setDataField<uint64_t>(0 * ELEMENTS, 0x1011121314151617ull);
...@@ -120,7 +121,7 @@ static void setupStruct(StructBuilder builder) { ...@@ -120,7 +121,7 @@ static void setupStruct(StructBuilder builder) {
{ {
StructBuilder subStruct = builder.initStructField( StructBuilder subStruct = builder.initStructField(
0 * REFERENCES, StructSize(1 * WORDS, 0 * REFERENCES, 8 * BYTES)); 0 * REFERENCES, StructSize(1 * WORDS, 0 * REFERENCES, FieldSize::EIGHT_BYTES));
subStruct.setDataField<uint32_t>(0 * ELEMENTS, 123); subStruct.setDataField<uint32_t>(0 * ELEMENTS, 123);
} }
...@@ -139,7 +140,8 @@ static void setupStruct(StructBuilder builder) { ...@@ -139,7 +140,8 @@ static void setupStruct(StructBuilder builder) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
StructBuilder element = list.getStructElement(i * ELEMENTS, STRUCTLIST_ELEMENT_SIZE); StructBuilder element = list.getStructElement(i * ELEMENTS, STRUCTLIST_ELEMENT_SIZE);
element.setDataField<int32_t>(0 * ELEMENTS, 300 + i); element.setDataField<int32_t>(0 * ELEMENTS, 300 + i);
element.initStructField(0 * REFERENCES, StructSize(1 * WORDS, 0 * REFERENCES, 8 * BYTES)) element.initStructField(0 * REFERENCES,
StructSize(1 * WORDS, 0 * REFERENCES, FieldSize::EIGHT_BYTES))
.setDataField<int32_t>(0 * ELEMENTS, 400 + i); .setDataField<int32_t>(0 * ELEMENTS, 400 + i);
} }
} }
...@@ -174,7 +176,8 @@ static void checkStruct(StructBuilder builder) { ...@@ -174,7 +176,8 @@ static void checkStruct(StructBuilder builder) {
{ {
StructBuilder subStruct = builder.getStructField( StructBuilder subStruct = builder.getStructField(
0 * REFERENCES, StructSize(1 * WORDS, 0 * REFERENCES, 8 * BYTES), SUBSTRUCT_DEFAULT.words); 0 * REFERENCES, StructSize(1 * WORDS, 0 * REFERENCES, FieldSize::EIGHT_BYTES),
SUBSTRUCT_DEFAULT.words);
EXPECT_EQ(123u, subStruct.getDataField<uint32_t>(0 * ELEMENTS)); EXPECT_EQ(123u, subStruct.getDataField<uint32_t>(0 * ELEMENTS));
} }
...@@ -193,7 +196,8 @@ static void checkStruct(StructBuilder builder) { ...@@ -193,7 +196,8 @@ static void checkStruct(StructBuilder builder) {
StructBuilder element = list.getStructElement(i * ELEMENTS, STRUCTLIST_ELEMENT_SIZE); StructBuilder element = list.getStructElement(i * ELEMENTS, STRUCTLIST_ELEMENT_SIZE);
EXPECT_EQ(300 + i, element.getDataField<int32_t>(0 * ELEMENTS)); EXPECT_EQ(300 + i, element.getDataField<int32_t>(0 * ELEMENTS));
EXPECT_EQ(400 + i, EXPECT_EQ(400 + i,
element.getStructField(0 * REFERENCES, StructSize(1 * WORDS, 0 * REFERENCES, 8 * BYTES), element.getStructField(0 * REFERENCES,
StructSize(1 * WORDS, 0 * REFERENCES, FieldSize::EIGHT_BYTES),
STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT.words) STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT.words)
.getDataField<int32_t>(0 * ELEMENTS)); .getDataField<int32_t>(0 * ELEMENTS));
} }
...@@ -272,7 +276,7 @@ TEST(WireFormat, StructRoundTrip_OneSegment) { ...@@ -272,7 +276,7 @@ TEST(WireFormat, StructRoundTrip_OneSegment) {
word* rootLocation = segment->allocate(1 * WORDS); word* rootLocation = segment->allocate(1 * WORDS);
StructBuilder builder = StructBuilder::initRoot( StructBuilder builder = StructBuilder::initRoot(
segment, rootLocation, StructSize(2 * WORDS, 4 * REFERENCES, 16 * BYTES)); segment, rootLocation, StructSize(2 * WORDS, 4 * REFERENCES, FieldSize::INLINE_COMPOSITE));
setupStruct(builder); setupStruct(builder);
// word count: // word count:
...@@ -308,7 +312,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation) { ...@@ -308,7 +312,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation) {
word* rootLocation = segment->allocate(1 * WORDS); word* rootLocation = segment->allocate(1 * WORDS);
StructBuilder builder = StructBuilder::initRoot( StructBuilder builder = StructBuilder::initRoot(
segment, rootLocation, StructSize(2 * WORDS, 4 * REFERENCES, 16 * BYTES)); segment, rootLocation, StructSize(2 * WORDS, 4 * REFERENCES, FieldSize::INLINE_COMPOSITE));
setupStruct(builder); setupStruct(builder);
// Verify that we made 15 segments. // Verify that we made 15 segments.
...@@ -345,7 +349,7 @@ TEST(WireFormat, StructRoundTrip_MultipleSegmentsWithMultipleAllocations) { ...@@ -345,7 +349,7 @@ TEST(WireFormat, StructRoundTrip_MultipleSegmentsWithMultipleAllocations) {
word* rootLocation = segment->allocate(1 * WORDS); word* rootLocation = segment->allocate(1 * WORDS);
StructBuilder builder = StructBuilder::initRoot( StructBuilder builder = StructBuilder::initRoot(
segment, rootLocation, StructSize(2 * WORDS, 4 * REFERENCES, 16 * BYTES)); segment, rootLocation, StructSize(2 * WORDS, 4 * REFERENCES, FieldSize::INLINE_COMPOSITE));
setupStruct(builder); setupStruct(builder);
// Verify that we made 6 segments. // Verify that we made 6 segments.
......
This diff is collapsed.
This diff is collapsed.
...@@ -353,6 +353,15 @@ public: ...@@ -353,6 +353,15 @@ public:
unit1PerUnit2 / other.unit1PerUnit2); unit1PerUnit2 / other.unit1PerUnit2);
} }
template <typename OtherNumber>
inline decltype(Number(1) / OtherNumber(1))
operator/(UnitRatio<OtherNumber, Unit1, Unit2> other) const {
return unit1PerUnit2 / other.unit1PerUnit2;
}
inline bool operator==(UnitRatio other) const { return unit1PerUnit2 == other.unit1PerUnit2; }
inline bool operator!=(UnitRatio other) const { return unit1PerUnit2 != other.unit1PerUnit2; }
private: private:
Number unit1PerUnit2; Number unit1PerUnit2;
......
...@@ -379,8 +379,16 @@ structContext parent desc = mkStrContext context where ...@@ -379,8 +379,16 @@ structContext parent desc = mkStrContext context where
context "structFields" = MuList $ map (fieldContext context) $ structFields desc context "structFields" = MuList $ map (fieldContext context) $ structFields desc
context "structUnions" = MuList $ map (unionContext context) $ structUnions desc context "structUnions" = MuList $ map (unionContext context) $ structUnions desc
context "structDataSize" = MuVariable $ dataSectionWordSize $ structDataSize desc context "structDataSize" = MuVariable $ dataSectionWordSize $ structDataSize desc
context "structDataBytes" = MuVariable (div (dataSectionBits (structDataSize desc)) 8)
context "structReferenceCount" = MuVariable $ structPointerCount desc context "structReferenceCount" = MuVariable $ structPointerCount desc
context "structPreferredListEncoding" = case (structDataSize desc, structPointerCount desc) of
(DataSectionWords 0, 0) -> MuVariable "VOID"
(DataSection1, 0) -> MuVariable "BYTE"
(DataSection8, 0) -> MuVariable "BYTE"
(DataSection16, 0) -> MuVariable "TWO_BYTES"
(DataSection32, 0) -> MuVariable "FOUR_BYTES"
(DataSectionWords 1, 0) -> MuVariable "EIGHT_BYTES"
(DataSectionWords 0, 1) -> MuVariable "REFERENCE"
_ -> MuVariable "INLINE_COMPOSITE"
context "structNestedEnums" = context "structNestedEnums" =
MuList $ map (enumContext context) [m | DescEnum m <- structMembers desc] MuList $ map (enumContext context) [m | DescEnum m <- structMembers desc]
context "structNestedStructs" = context "structNestedStructs" =
......
...@@ -68,9 +68,10 @@ struct {{typeFullName}} { ...@@ -68,9 +68,10 @@ struct {{typeFullName}} {
{{/structNestedEnums}} {{/structNestedEnums}}
static constexpr ::capnproto::internal::StructSize STRUCT_SIZE = static constexpr ::capnproto::internal::StructSize STRUCT_SIZE =
::capnproto::internal::StructSize({{structDataSize}} * ::capnproto::WORDS, ::capnproto::internal::StructSize(
{{structReferenceCount}} * ::capnproto::REFERENCES, {{structDataSize}} * ::capnproto::WORDS,
{{structDataBytes}} * ::capnproto::BYTES); {{structReferenceCount}} * ::capnproto::REFERENCES,
::capnproto::internal::FieldSize::{{structPreferredListEncoding}});
{{/typeStruct}} {{/typeStruct}}
{{#typeUnion}} {{#typeUnion}}
......
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