Skip to content

Commit f19aca1

Browse files
authored
Format rules (#528)
1 parent ec897e1 commit f19aca1

20 files changed

Lines changed: 95 additions & 122 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ find_program(CLANG_FORMAT NAMES clang-format-22 clang-format)
9090
find_program(RUFF NAMES ruff)
9191

9292
file(GLOB_RECURSE ALL_CXX_SOURCES
93-
cpp2rust/*.cpp cpp2rust/*.h tests/*.cpp tests/*.c)
93+
cpp2rust/*.cpp cpp2rust/*.h rules/*.cpp rules/*.c rules/*.h tests/*.cpp tests/*.c)
9494

9595
set(PYTHON_SOURCES ${PROJECT_SOURCE_DIR}/tests/lit/lit/formats/Cpp2RustTest.py)
9696

‎rules/algorithm/src.cpp‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ template <class T1, class T2> T1 f3(T1 first, T1 last, const T2 &value) {
1919
return std::find(first, last, value);
2020
}
2121

22-
template <typename T1, typename T2>
23-
void f6(T1 first, T1 last, T2 comp) {
22+
template <typename T1, typename T2> void f6(T1 first, T1 last, T2 comp) {
2423
return std::stable_sort(first, last, comp);
2524
}
2625

@@ -48,8 +47,7 @@ std::ostream_iterator<char> f13(std::string::iterator a0,
4847
return std::copy(a0, a1, a2);
4948
}
5049

51-
template <typename T1, typename T2>
52-
void f14(T1 *first, T1 *last, T2 comp) {
50+
template <typename T1, typename T2> void f14(T1 *first, T1 *last, T2 comp) {
5351
return std::stable_sort(first, last, comp);
5452
}
5553

‎rules/array/src.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
#include <array>
55

6-
template <typename T1, std::size_t T2>
7-
using t1 = std::array<T1, T2>;
6+
template <typename T1, std::size_t T2> using t1 = std::array<T1, T2>;
87

98
template <typename T1, std::size_t T2>
109
using t2 = typename std::array<T1, T2>::size_type;

‎rules/assert/src.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33

44
#include <assert.h>
55

6-
bool f1(bool condition) {
7-
return cpp2rust_assert_fail(condition);
8-
}
6+
bool f1(bool condition) { return cpp2rust_assert_fail(condition); }

‎rules/brotli/src.c‎

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,51 @@ BrotliEncoderMode f12() { return BROTLI_MODE_GENERIC; }
6262

6363
BrotliDecoderResult f13() { return BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT; }
6464

65-
BrotliDecoderErrorCode f14() { return BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE; }
66-
BrotliDecoderErrorCode f15() { return BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE; }
67-
BrotliDecoderErrorCode f16() { return BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET; }
68-
BrotliDecoderErrorCode f17() { return BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME; }
65+
BrotliDecoderErrorCode f14() {
66+
return BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE;
67+
}
68+
BrotliDecoderErrorCode f15() {
69+
return BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE;
70+
}
71+
BrotliDecoderErrorCode f16() {
72+
return BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET;
73+
}
74+
BrotliDecoderErrorCode f17() {
75+
return BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME;
76+
}
6977
BrotliDecoderErrorCode f18() { return BROTLI_DECODER_ERROR_FORMAT_CL_SPACE; }
70-
BrotliDecoderErrorCode f19() { return BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE; }
71-
BrotliDecoderErrorCode f20() { return BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT; }
72-
BrotliDecoderErrorCode f21() { return BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1; }
73-
BrotliDecoderErrorCode f22() { return BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2; }
78+
BrotliDecoderErrorCode f19() {
79+
return BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE;
80+
}
81+
BrotliDecoderErrorCode f20() {
82+
return BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT;
83+
}
84+
BrotliDecoderErrorCode f21() {
85+
return BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1;
86+
}
87+
BrotliDecoderErrorCode f22() {
88+
return BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2;
89+
}
7490
BrotliDecoderErrorCode f23() { return BROTLI_DECODER_ERROR_FORMAT_TRANSFORM; }
7591
BrotliDecoderErrorCode f24() { return BROTLI_DECODER_ERROR_FORMAT_DICTIONARY; }
7692
BrotliDecoderErrorCode f25() { return BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; }
7793
BrotliDecoderErrorCode f26() { return BROTLI_DECODER_ERROR_FORMAT_PADDING_1; }
7894
BrotliDecoderErrorCode f27() { return BROTLI_DECODER_ERROR_FORMAT_PADDING_2; }
7995
BrotliDecoderErrorCode f28() { return BROTLI_DECODER_ERROR_INVALID_ARGUMENTS; }
80-
BrotliDecoderErrorCode f29() { return BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES; }
96+
BrotliDecoderErrorCode f29() {
97+
return BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES;
98+
}
8199
BrotliDecoderErrorCode f30() { return BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS; }
82100
BrotliDecoderErrorCode f31() { return BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP; }
83-
BrotliDecoderErrorCode f32() { return BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1; }
84-
BrotliDecoderErrorCode f33() { return BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2; }
85-
BrotliDecoderErrorCode f34() { return BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES; }
101+
BrotliDecoderErrorCode f32() {
102+
return BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1;
103+
}
104+
BrotliDecoderErrorCode f33() {
105+
return BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2;
106+
}
107+
BrotliDecoderErrorCode f34() {
108+
return BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES;
109+
}
86110

87111
BrotliDecoderErrorCode f35(const BrotliDecoderState *state) {
88112
return BrotliDecoderGetErrorCode(state);

‎rules/builtin/src.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ unsigned long long f6(unsigned long long x) { return __builtin_bswap64(x); }
2424
int f7(unsigned long x) { return __builtin_ctzl(x); }
2525
int f8(unsigned long x) { return __builtin_popcountl(x); }
2626
int f12(long a, long b, long *r) { return __builtin_mul_overflow(a, b, r); }
27-
int f13(long long a, long long b, long long *r) { return __builtin_mul_overflow(a, b, r); }
27+
int f13(long long a, long long b, long long *r) {
28+
return __builtin_mul_overflow(a, b, r);
29+
}
2830
#if defined(__x86_64__) || defined(__i386__)
2931
void f11(void) { return __builtin_ia32_pause(); }
3032
#endif

‎rules/builtin/src.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
bool f9(long a, long b, long *r) { return __builtin_mul_overflow(a, b, r); }
55

6-
bool f10(long long a, long long b, long long *r) { return __builtin_mul_overflow(a, b, r); }
6+
bool f10(long long a, long long b, long long *r) {
7+
return __builtin_mul_overflow(a, b, r);
8+
}
79

810
bool f19() { return __builtin_is_constant_evaluated(); }

‎rules/cstring/src.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ size_t f7(const char *a0) { return strlen(a0); }
2222

2323
int f8(const char *a0, const char *a1) { return strcmp(a0, a1); }
2424

25-
int f9(const char *a0, const char *a1, size_t a2) { return strncmp(a0, a1, a2); }
25+
int f9(const char *a0, const char *a1, size_t a2) {
26+
return strncmp(a0, a1, a2);
27+
}
2628

2729
#ifndef __cplusplus
2830
void *f10(const void *a0, int a1, size_t a2) { return (memchr)(a0, a1, a2); }
@@ -54,11 +56,11 @@ int f27(const char *a0, const char *a1) { return strcasecmp(a0, a1); }
5456

5557
#if defined(__linux__)
5658
char *f28(int errnum, char *buf, size_t buflen) {
57-
return strerror_r(errnum, buf, buflen);
59+
return strerror_r(errnum, buf, buflen);
5860
}
5961
#elif defined(__APPLE__)
6062
int f28(int errnum, char *buf, size_t buflen) {
61-
return strerror_r(errnum, buf, buflen);
63+
return strerror_r(errnum, buf, buflen);
6264
}
6365
#else
6466
#error "Unsupported platform for strerror_r"

‎rules/cstring/src.cpp‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
const char *f6(const char *a0, int a1) { return strchr(a0, a1); }
77

8-
const void *f12(const void *a0, int a1, size_t a2) { return memchr(a0, a1, a2); }
8+
const void *f12(const void *a0, int a1, size_t a2) {
9+
return memchr(a0, a1, a2);
10+
}
911

1012
const char *f13(const char *a0, int a1) { return strrchr(a0, a1); }
1113

@@ -20,7 +22,9 @@ const char *f22(const char *a0, const char *a1) { return strpbrk(a0, a1); }
2022
char *f23(char *a0, const char *a1) { return strpbrk(a0, a1); }
2123

2224
#if defined(__linux__)
23-
const void *f25(const void *a0, int a1, size_t a2) { return memrchr(a0, a1, a2); }
25+
const void *f25(const void *a0, int a1, size_t a2) {
26+
return memrchr(a0, a1, a2);
27+
}
2428

2529
void *f26(void *a0, int a1, size_t a2) { return memrchr(a0, a1, a2); }
2630
#endif

‎rules/deque_cxx11/src.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ void f1(std::deque<T1> &o, Init<T1, Args> &&...args) {
1212
}
1313

1414
template <typename T1, typename... Args>
15-
void f2(std::deque<std::vector<T1>> &o,
16-
Init<std::vector<T1>, Args> &&...args) {
15+
void f2(std::deque<std::vector<T1>> &o, Init<std::vector<T1>, Args> &&...args) {
1716
return o.emplace_back(std::forward<Args>(args)...);
1817
}

0 commit comments

Comments
 (0)