Repository navigation
Commit 896e16e
authored
Translate operators (#335)
This PR adds support for the following operators:
* arithmetic: `+, -, unary +, unary -, *, /, %, ++ prefix and postfix,
-- prefix and postfix`
* relational: `==, !=, >, <, >=, <=, <=>`
* logical: `!, &&, ||`
* bitwise: `~a, &, |, ^, <<, >>`
* assignment: `=, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=`
* member and pointer: `[] and static [], *, &, ->`
* other: `() and static (), , (comma), user defined conversion`
Not supported:
* `<<` for streams
* `a->*b` pointer to member
* `"a"_b` user defined literal
* `new`, `delete`
In Rust, operators are translated as `operator_call`, `operator_comma`,
etc. Operators that are cv or ref-qualified contain that information in
the name, for example `operator_call_const_volatile_rref`.
We support both method versions and free function versions of operators.
Furthermore, we also support static `operator[]` and static
`operator()`.
The following operators are used to generate Rust traits:
* `operator<` or `operator<=>` generate PartialOrd and Ord
* `operator==` or `operator<` or `operator<=>` are used for PartialEq
and Eq
* the operators are implemented on `Ptr<Self>` while the traits are
implemented on `Self`
I also added rules and tests for `operator<=>`. Since this is a C++20
feature, I had to change CMakeLists, rules/ and Cpp2RustTest.py in order
to compile everything related to `operator<=>` with `-std=c++20`.1 parent f99ddd3 commit 896e16e
82 files changed
Lines changed: 6283 additions & 232 deletions
File tree
- cpp2rust/converter
- models
- docs/src/rules
- rules
- compare
- src
- tests
- lit/lit/formats
- unit
- out
- refcount
- unsafe
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
156 | 165 | | |
157 | 166 | | |
158 | 167 | | |
159 | | - | |
160 | | - | |
| 168 | + | |
| 169 | + | |
161 | 170 | | |
162 | 171 | | |
163 | 172 | | |
| |||
0 commit comments