Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ find_program(CLANG_FORMAT NAMES clang-format-22 clang-format)
find_program(RUFF NAMES ruff)

file(GLOB_RECURSE ALL_CXX_SOURCES
cpp2rust/*.cpp cpp2rust/*.h tests/*.cpp tests/*.c)
cpp2rust/*.cpp cpp2rust/*.h rules/*.cpp rules/*.c rules/*.h tests/*.cpp tests/*.c)

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

Expand Down
6 changes: 2 additions & 4 deletions rules/algorithm/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ template <class T1, class T2> T1 f3(T1 first, T1 last, const T2 &value) {
return std::find(first, last, value);
}

template <typename T1, typename T2>
void f6(T1 first, T1 last, T2 comp) {
template <typename T1, typename T2> void f6(T1 first, T1 last, T2 comp) {
return std::stable_sort(first, last, comp);
}

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

template <typename T1, typename T2>
void f14(T1 *first, T1 *last, T2 comp) {
template <typename T1, typename T2> void f14(T1 *first, T1 *last, T2 comp) {
return std::stable_sort(first, last, comp);
}

Expand Down
3 changes: 1 addition & 2 deletions rules/array/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

#include <array>

template <typename T1, std::size_t T2>
using t1 = std::array<T1, T2>;
template <typename T1, std::size_t T2> using t1 = std::array<T1, T2>;

template <typename T1, std::size_t T2>
using t2 = typename std::array<T1, T2>::size_type;
Expand Down
4 changes: 1 addition & 3 deletions rules/assert/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@

#include <assert.h>

bool f1(bool condition) {
return cpp2rust_assert_fail(condition);
}
bool f1(bool condition) { return cpp2rust_assert_fail(condition); }
48 changes: 36 additions & 12 deletions rules/brotli/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,51 @@ BrotliEncoderMode f12() { return BROTLI_MODE_GENERIC; }

BrotliDecoderResult f13() { return BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT; }

BrotliDecoderErrorCode f14() { return BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE; }
BrotliDecoderErrorCode f15() { return BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE; }
BrotliDecoderErrorCode f16() { return BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET; }
BrotliDecoderErrorCode f17() { return BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME; }
BrotliDecoderErrorCode f14() {
return BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE;
}
BrotliDecoderErrorCode f15() {
return BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE;
}
BrotliDecoderErrorCode f16() {
return BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET;
}
BrotliDecoderErrorCode f17() {
return BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME;
}
BrotliDecoderErrorCode f18() { return BROTLI_DECODER_ERROR_FORMAT_CL_SPACE; }
BrotliDecoderErrorCode f19() { return BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE; }
BrotliDecoderErrorCode f20() { return BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT; }
BrotliDecoderErrorCode f21() { return BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1; }
BrotliDecoderErrorCode f22() { return BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2; }
BrotliDecoderErrorCode f19() {
return BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE;
}
BrotliDecoderErrorCode f20() {
return BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT;
}
BrotliDecoderErrorCode f21() {
return BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1;
}
BrotliDecoderErrorCode f22() {
return BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2;
}
BrotliDecoderErrorCode f23() { return BROTLI_DECODER_ERROR_FORMAT_TRANSFORM; }
BrotliDecoderErrorCode f24() { return BROTLI_DECODER_ERROR_FORMAT_DICTIONARY; }
BrotliDecoderErrorCode f25() { return BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; }
BrotliDecoderErrorCode f26() { return BROTLI_DECODER_ERROR_FORMAT_PADDING_1; }
BrotliDecoderErrorCode f27() { return BROTLI_DECODER_ERROR_FORMAT_PADDING_2; }
BrotliDecoderErrorCode f28() { return BROTLI_DECODER_ERROR_INVALID_ARGUMENTS; }
BrotliDecoderErrorCode f29() { return BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES; }
BrotliDecoderErrorCode f29() {
return BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES;
}
BrotliDecoderErrorCode f30() { return BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS; }
BrotliDecoderErrorCode f31() { return BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP; }
BrotliDecoderErrorCode f32() { return BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1; }
BrotliDecoderErrorCode f33() { return BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2; }
BrotliDecoderErrorCode f34() { return BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES; }
BrotliDecoderErrorCode f32() {
return BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1;
}
BrotliDecoderErrorCode f33() {
return BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2;
}
BrotliDecoderErrorCode f34() {
return BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES;
}

BrotliDecoderErrorCode f35(const BrotliDecoderState *state) {
return BrotliDecoderGetErrorCode(state);
Expand Down
4 changes: 3 additions & 1 deletion rules/builtin/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ unsigned long long f6(unsigned long long x) { return __builtin_bswap64(x); }
int f7(unsigned long x) { return __builtin_ctzl(x); }
int f8(unsigned long x) { return __builtin_popcountl(x); }
int f12(long a, long b, long *r) { return __builtin_mul_overflow(a, b, r); }
int f13(long long a, long long b, long long *r) { return __builtin_mul_overflow(a, b, r); }
int f13(long long a, long long b, long long *r) {
return __builtin_mul_overflow(a, b, r);
}
#if defined(__x86_64__) || defined(__i386__)
void f11(void) { return __builtin_ia32_pause(); }
#endif
Expand Down
4 changes: 3 additions & 1 deletion rules/builtin/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

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

bool f10(long long a, long long b, long long *r) { return __builtin_mul_overflow(a, b, r); }
bool f10(long long a, long long b, long long *r) {
return __builtin_mul_overflow(a, b, r);
}

bool f19() { return __builtin_is_constant_evaluated(); }
8 changes: 5 additions & 3 deletions rules/cstring/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ size_t f7(const char *a0) { return strlen(a0); }

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

int f9(const char *a0, const char *a1, size_t a2) { return strncmp(a0, a1, a2); }
int f9(const char *a0, const char *a1, size_t a2) {
return strncmp(a0, a1, a2);
}

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

#if defined(__linux__)
char *f28(int errnum, char *buf, size_t buflen) {
return strerror_r(errnum, buf, buflen);
return strerror_r(errnum, buf, buflen);
}
#elif defined(__APPLE__)
int f28(int errnum, char *buf, size_t buflen) {
return strerror_r(errnum, buf, buflen);
return strerror_r(errnum, buf, buflen);
}
#else
#error "Unsupported platform for strerror_r"
Expand Down
8 changes: 6 additions & 2 deletions rules/cstring/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

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

const void *f12(const void *a0, int a1, size_t a2) { return memchr(a0, a1, a2); }
const void *f12(const void *a0, int a1, size_t a2) {
return memchr(a0, a1, a2);
}

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

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

#if defined(__linux__)
const void *f25(const void *a0, int a1, size_t a2) { return memrchr(a0, a1, a2); }
const void *f25(const void *a0, int a1, size_t a2) {
return memrchr(a0, a1, a2);
}

void *f26(void *a0, int a1, size_t a2) { return memrchr(a0, a1, a2); }
#endif
3 changes: 1 addition & 2 deletions rules/deque_cxx11/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ void f1(std::deque<T1> &o, Init<T1, Args> &&...args) {
}

template <typename T1, typename... Args>
void f2(std::deque<std::vector<T1>> &o,
Init<std::vector<T1>, Args> &&...args) {
void f2(std::deque<std::vector<T1>> &o, Init<std::vector<T1>, Args> &&...args) {
return o.emplace_back(std::forward<Args>(args)...);
}
16 changes: 4 additions & 12 deletions rules/eventfd/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@
#ifdef __linux__
#include <sys/eventfd.h>

int f1() {
return EFD_CLOEXEC;
}
int f1() { return EFD_CLOEXEC; }

int f2() {
return EFD_NONBLOCK;
}
int f2() { return EFD_NONBLOCK; }

int f3() {
return EFD_SEMAPHORE;
}
int f3() { return EFD_SEMAPHORE; }

int f4(unsigned int initval, int flags) {
return eventfd(initval, flags);
}
int f4(unsigned int initval, int flags) { return eventfd(initval, flags); }
#endif
10 changes: 3 additions & 7 deletions rules/ifaddrs/src.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#include <sys/types.h>
#include <ifaddrs.h>
#include <sys/types.h>

typedef struct ifaddrs t1;

int f1(struct ifaddrs **ifap) {
return getifaddrs(ifap);
}
int f1(struct ifaddrs **ifap) { return getifaddrs(ifap); }

void f2(struct ifaddrs *ifa) {
return freeifaddrs(ifa);
}
void f2(struct ifaddrs *ifa) { return freeifaddrs(ifa); }
3 changes: 1 addition & 2 deletions rules/initializer_list/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

template <typename T1> using t1 = std::initializer_list<T1>;

template <typename T1>
using t2 = typename std::initializer_list<T1>::size_type;
template <typename T1> using t2 = typename std::initializer_list<T1>::size_type;

template <typename T1>
typename std::initializer_list<T1>::size_type f1(std::initializer_list<T1> &o) {
Expand Down
24 changes: 6 additions & 18 deletions rules/ip/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@ typedef struct in_addr t2;
typedef struct sockaddr_in6 t3;
typedef struct in6_addr t4;

int f1() {
return IPPROTO_TCP;
}
int f1() { return IPPROTO_TCP; }

int f2() {
return IPPROTO_UDP;
}
int f2() { return IPPROTO_UDP; }

int f3() {
return IPPROTO_IP;
}
int f3() { return IPPROTO_IP; }

int f4() {
return IPPROTO_IPV6;
}
int f4() { return IPPROTO_IPV6; }

#if defined(__linux__)
int f5() {
return IPPROTO_MPTCP;
}
int f5() { return IPPROTO_MPTCP; }
#endif

int f6() {
return TCP_NODELAY;
}
int f6() { return TCP_NODELAY; }
3 changes: 1 addition & 2 deletions rules/pair/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ std::pair<T1, T2> &f14(std::pair<T1, T2> &dst, std::pair<T1, T2> &&src) {
return dst.operator=(std::move(src));
}

template <typename T1, typename T2>
const T1 &f15(std::pair<const T1, T2> &a0) {
template <typename T1, typename T2> const T1 &f15(std::pair<const T1, T2> &a0) {
return a0.first;
}

Expand Down
4 changes: 2 additions & 2 deletions rules/rustls/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ rustls_result f41(rustls_crypto_provider_builder **builder_out) {
rustls_result f42(rustls_crypto_provider_builder *builder,
const rustls_supported_ciphersuite *const *cipher_suites,
size_t cipher_suites_len) {
return rustls_crypto_provider_builder_set_cipher_suites(builder, cipher_suites,
cipher_suites_len);
return rustls_crypto_provider_builder_set_cipher_suites(
builder, cipher_suites, cipher_suites_len);
}
void f43(const rustls_crypto_provider *provider) {
return rustls_crypto_provider_free(provider);
Expand Down
49 changes: 14 additions & 35 deletions rules/socket/src.c
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
#undef _GNU_SOURCE
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>

typedef struct sockaddr t1;
typedef struct sockaddr_storage t2;
typedef struct sockaddr_un t3;

int f1() {
return MSG_NOSIGNAL;
}
int f1() { return MSG_NOSIGNAL; }

int f2() {
return SOCK_STREAM;
}
int f2() { return SOCK_STREAM; }

int f3() {
return SOCK_DGRAM;
}
int f3() { return SOCK_DGRAM; }

#ifdef __linux__
int f4() {
return SOCK_CLOEXEC;
}
int f4() { return SOCK_CLOEXEC; }

int f5() {
return SOCK_NONBLOCK;
}
int f5() { return SOCK_NONBLOCK; }
#endif

int f6(int domain, int type, int protocol) {
return socket(domain, type, protocol);
}

int f7(int sockfd, int level, int optname, const void *optval, socklen_t optlen) {
int f7(int sockfd, int level, int optname, const void *optval,
socklen_t optlen) {
return setsockopt(sockfd, level, optname, optval, optlen);
}

Expand Down Expand Up @@ -76,9 +67,7 @@ int f16(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
return bind(sockfd, addr, addrlen);
}

int f17(int sockfd, int backlog) {
return listen(sockfd, backlog);
}
int f17(int sockfd, int backlog) { return listen(sockfd, backlog); }

ssize_t f18(int sockfd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, socklen_t *addrlen) {
Expand All @@ -90,22 +79,12 @@ ssize_t f19(int sockfd, const void *buf, size_t len, int flags,
return sendto(sockfd, buf, len, flags, dest_addr, addrlen);
}

int f20() {
return AF_INET;
}
int f20() { return AF_INET; }

int f21() {
return AF_INET6;
}
int f21() { return AF_INET6; }

int f22() {
return SOL_SOCKET;
}
int f22() { return SOL_SOCKET; }

int f23() {
return SO_KEEPALIVE;
}
int f23() { return SO_KEEPALIVE; }

int f24() {
return SO_ERROR;
}
int f24() { return SO_ERROR; }
4 changes: 1 addition & 3 deletions rules/stdio/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ FILE *f20(int fd, const char *mode) { return fdopen(fd, mode); }

int (*f21)(char *, size_t, const char *, ...) = snprintf;

int f22(const char *a0, const char *a1) {
return rename(a0, a1);
}
int f22(const char *a0, const char *a1) { return rename(a0, a1); }

int f23(FILE *stream) { return getc(stream); }

Expand Down
Loading
Loading