summaryrefslogtreecommitdiff
path: root/bindgen-integration/cpp/Test.cc
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-11-23 04:31:10 -0600
committerGitHub <noreply@github.com>2017-11-23 04:31:10 -0600
commit7c3584d7bc328a01ae5352e191f1fd41bb7fb1a9 (patch)
treeace279bfdbd625d446074c01b958d7b4d44c729a /bindgen-integration/cpp/Test.cc
parente3e6c730393f97daae93c2394d4af7bc9a5183b4 (diff)
parentf0e05310b43e88e541ed011d20994c02fdcc1a3a (diff)
Auto merge of #1158 - glyn:large-bitfield-units, r=emilio
Support bitfield allocation units larger than 64 bits Individual bitfields are still limited to at most 64 bits, but this restriction can be weakened when Rust supports `u128`. This implements issue #816. Usage notes: * Since common code is added to each generated binding, a program which uses more than one binding may need to work around the duplication by including each binding in its own module. * The values created by bitfield allocation unit constructors can be assigned directly to the corresponding struct fields with no need for transmutation. Implementation notes: `__BindgenBitfieldUnit` represents a bitfield allocation unit using a `Storage` type accessible as a slice of `u8`. The alignment of the unit is inherited from an `Align` type by virtue of the field: ``` align: [Align; 0], ``` The position of this field in the struct is irrelevant. It is assumed that the alignment of the `Storage` type is no larger than the alignment of the `Align` type, which will be true if the `Storage` type is, for example, an array of `u8`. This assumption is checked in a debug assertion. Although the double underscore (__) prefix is reserved for implementations of C++, there are precedents for this convention elsewhere in bindgen and so the convention is adopted here too. Acknowledgement: Thanks to @fitzgen for an initial implementation of `__BindgenBitfieldUnit` and code to integrate it into bindgen. r? @emilio
Diffstat (limited to 'bindgen-integration/cpp/Test.cc')
-rw-r--r--bindgen-integration/cpp/Test.cc45
1 files changed, 31 insertions, 14 deletions
diff --git a/bindgen-integration/cpp/Test.cc b/bindgen-integration/cpp/Test.cc
index f125109a..57c2186b 100644
--- a/bindgen-integration/cpp/Test.cc
+++ b/bindgen-integration/cpp/Test.cc
@@ -69,11 +69,11 @@ Date2::assert(unsigned short nWeekDay,
unsigned short nYear,
unsigned short byte)
{
- return this->nWeekDay == nWeekDay &&
- this->nMonthDay == nMonthDay &&
- this->nMonth == nMonth &&
- this->nYear == nYear &&
- this->byte == byte;
+ return this->nWeekDay == nWeekDay &&
+ this->nMonthDay == nMonthDay &&
+ this->nMonth == nMonth &&
+ this->nYear == nYear &&
+ this->byte == byte;
}
bool
@@ -83,11 +83,11 @@ Fifth::assert(unsigned short nWeekDay,
unsigned short nYear,
unsigned char byte)
{
- return this->nWeekDay == nWeekDay &&
- this->nMonthDay == nMonthDay &&
- this->nMonth == nMonth &&
- this->nYear == nYear &&
- this->byte == byte;
+ return this->nWeekDay == nWeekDay &&
+ this->nMonthDay == nMonthDay &&
+ this->nMonth == nMonth &&
+ this->nYear == nYear &&
+ this->byte == byte;
}
bool
@@ -95,10 +95,27 @@ Sixth::assert(unsigned char byte,
unsigned char nWeekDay,
unsigned char nMonth,
unsigned char nMonthDay) {
- return this->nWeekDay == nWeekDay &&
- this->nMonthDay == nMonthDay &&
- this->nMonth == nMonth &&
- this->byte == byte;
+ return this->nWeekDay == nWeekDay &&
+ this->nMonthDay == nMonthDay &&
+ this->nMonth == nMonth &&
+ this->byte == byte;
+};
+
+bool
+Seventh::assert(bool first,
+ int second,
+ unsigned short third,
+ unsigned int fourth,
+ unsigned short fifth,
+ bool sixth,
+ int seventh) {
+ return this->first_one_bit == first &&
+ this->second_thirty_bits == second &&
+ this->third_two_bits == third &&
+ this->fourth_thirty_bits == fourth &&
+ this->fifth_two_bits == fifth &&
+ this->sixth_one_bit == sixth &&
+ this->seventh_thirty_bits == seventh;
};
} // namespace bitfields