diff --git a/Cargo.toml b/Cargo.toml index 5bc4455c35a64da8588907f261908837b14caf49..039d567f396c08deac48b1041707abf9dd466ae9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ description = "A tool for generating C bindings to Rust code." keywords = ["bindings", "ffi", "code-generation"] categories = ["external-ffi-bindings", "development-tools::ffi"] repository = "https://github.com/eqrion/cbindgen/" -exclude = ["test.py", "compile-tests/**"] +exclude = ["test.py", "tests/**"] [badges] travis-ci = { repository = "eqrion/cbindgen" } diff --git a/test.py b/test.py index dca32d6b4e217ed264c0eee1bc11f4ff729893cd..1d52a20c4823f6300cd0743f1639f6418572862b 100755 --- a/test.py +++ b/test.py @@ -32,22 +32,22 @@ def gcc(src): if gcc_bin == None: gcc_bin = 'gcc' - subprocess.check_output([gcc_bin, "-D", "DEFINED", "-c", src, "-o", "compile-tests/tmp.o"]) - os.remove("compile-tests/tmp.o") + subprocess.check_output([gcc_bin, "-D", "DEFINED", "-c", src, "-o", "tests/expectations/tmp.o"]) + os.remove("tests/expectations/tmp.o") def gxx(src): gxx_bin = os.environ.get('CXX') if gxx_bin == None: gxx_bin = 'g++' - subprocess.check_output([gxx_bin, "-D", "DEFINED", "-std=c++11", "-c", src, "-o", "compile-tests/tmp.o"]) - os.remove("compile-tests/tmp.o") + subprocess.check_output([gxx_bin, "-D", "DEFINED", "-std=c++11", "-c", src, "-o", "tests/expectations/tmp.o"]) + os.remove("tests/expectations/tmp.o") -def run_compile_test(rust_src, leave_output, c): +def run_compile_test(rust_src, c): if c: - out = rust_src.replace(".rs", ".c") + out = os.path.join('tests/expectations/', os.path.basename(rust_src).replace(".rs", ".c")) else: - out = rust_src.replace(".rs", ".cpp") + out = os.path.join('tests/expectations/', os.path.basename(rust_src).replace(".rs", ".cpp")) config = rust_src.replace(".rs", ".toml") if not os.path.exists(config): @@ -61,11 +61,7 @@ def run_compile_test(rust_src, leave_output, c): else: gxx(out) - if not leave_output: - os.remove(out) except subprocess.CalledProcessError: - if not leave_output and os.path.exists(out): - os.remove(out) return False return True @@ -75,28 +71,30 @@ if not build_cbindgen(): args = sys.argv[1:] files = [x for x in args if not x.startswith("-")] -flags = [x for x in args if x.startswith("-")] - -leave_output = False -c = False - -for flag in flags: - if flag == "-l": - leave_output = True - elif flag == "-c": - c = True tests = [] if len(files) == 0: - tests = glob.glob("compile-tests/*.rs") + tests = glob.glob("tests/rust/*.rs") else: tests = files num_pass = 0 num_fail = 0 +# C + +for test in tests: + if run_compile_test(test, True): + num_pass += 1 + print("Pass - %s" % test) + else: + num_fail += 1 + print("Fail - %s" % test) + +# C++ + for test in tests: - if run_compile_test(test, leave_output, c): + if run_compile_test(test, False): num_pass += 1 print("Pass - %s" % test) else: diff --git a/tests/expectations/alias.c b/tests/expectations/alias.c new file mode 100644 index 0000000000000000000000000000000000000000..307b4c7cfd88dbdc20081fa1976c82f7a0d000c4 --- /dev/null +++ b/tests/expectations/alias.c @@ -0,0 +1,36 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +enum Status { + Ok = 0, + Err = 1, +}; +typedef uint32_t Status; + +typedef struct { + int32_t a; + float b; +} Dep; + +typedef struct { + int32_t a; + int32_t b; + Dep c; +} Foo_i32; + +typedef Foo_i32 IntFoo; + +typedef struct { + double a; + double b; + Dep c; +} Foo_f64; + +typedef Foo_f64 DoubleFoo; + +typedef int32_t Unit; + +typedef Status SpecialStatus; + +void root(IntFoo x, DoubleFoo y, Unit z, SpecialStatus w); diff --git a/tests/expectations/alias.cpp b/tests/expectations/alias.cpp new file mode 100644 index 0000000000000000000000000000000000000000..63848e548456ed930f21b1ba9305fb67bfe9c365 --- /dev/null +++ b/tests/expectations/alias.cpp @@ -0,0 +1,51 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +enum class Status : uint32_t { + Ok = 0, + Err = 1, +}; + +struct Dep { + int32_t a; + float b; +}; + +struct Foo_i32 { + int32_t a; + int32_t b; + Dep c; +}; + +typedef Foo_i32 IntFoo; + +struct Foo_f64 { + double a; + double b; + Dep c; +}; + +typedef Foo_f64 DoubleFoo; + +typedef int32_t Unit; + +typedef Status SpecialStatus; + +void root(IntFoo x, DoubleFoo y, Unit z, SpecialStatus w); + +} // extern "C" + +template<typename X> +struct Foo; + +template<> +struct Foo<double> : public Foo_f64 { + +}; + +template<> +struct Foo<int32_t> : public Foo_i32 { + +}; diff --git a/tests/expectations/annotation.c b/tests/expectations/annotation.c new file mode 100644 index 0000000000000000000000000000000000000000..69102b0e23bfd7d56b9b9153ee2c3fed3406abc1 --- /dev/null +++ b/tests/expectations/annotation.c @@ -0,0 +1,20 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +enum C { + X = 2, + Y = 3, +}; +typedef uint32_t C; + +typedef struct { + int32_t m0; +} A; + +typedef struct { + int32_t x; + float y; +} B; + +void root(A x, B y, C z); diff --git a/tests/expectations/annotation.cpp b/tests/expectations/annotation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..011549738f32cb459c5d2af5ff10047056bc6e1c --- /dev/null +++ b/tests/expectations/annotation.cpp @@ -0,0 +1,29 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +enum class C : uint32_t { + X = 2, + Y = 3, +}; + +struct A { + int32_t m0; + + bool operator<(const A& other) const { + return m0 < other.m0; + } + bool operator<=(const A& other) const { + return m0 <= other.m0; + } +}; + +struct B { + int32_t x; + float y; +}; + +void root(A x, B y, C z); + +} // extern "C" diff --git a/tests/expectations/cdecl.c b/tests/expectations/cdecl.c new file mode 100644 index 0000000000000000000000000000000000000000..5f4225cbddf1059a04e324e2e42a56aadeaa562a --- /dev/null +++ b/tests/expectations/cdecl.c @@ -0,0 +1,35 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +typedef void (*A)(); + +typedef void (*B)(); + +typedef bool (*C)(int32_t, int32_t); + +typedef bool (*(*D)(int32_t))(float); + +typedef int32_t (*(*E)())[16]; + +typedef const int32_t *F; + +typedef const int32_t *const *G; + +typedef int32_t *const *H; + +typedef int32_t (*I)[16]; + +typedef double (**J)(float); + +typedef int32_t K[16]; + +typedef const int32_t *L[16]; + +typedef bool (*M[16])(int32_t, int32_t); + +typedef void (*N[16])(int32_t, int32_t); + +void (*O())(); + +void root(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n); diff --git a/tests/expectations/cdecl.cpp b/tests/expectations/cdecl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ffdc54fa2c0cea3959d35dc474598a9bab15bb58 --- /dev/null +++ b/tests/expectations/cdecl.cpp @@ -0,0 +1,38 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +typedef void (*A)(); + +typedef void (*B)(); + +typedef bool (*C)(int32_t, int32_t); + +typedef bool (*(*D)(int32_t))(float); + +typedef int32_t (*(*E)())[16]; + +typedef const int32_t *F; + +typedef const int32_t *const *G; + +typedef int32_t *const *H; + +typedef int32_t (*I)[16]; + +typedef double (**J)(float); + +typedef int32_t K[16]; + +typedef const int32_t *L[16]; + +typedef bool (*M[16])(int32_t, int32_t); + +typedef void (*N[16])(int32_t, int32_t); + +void (*O())(); + +void root(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n); + +} // extern "C" diff --git a/tests/expectations/cfg-2.c b/tests/expectations/cfg-2.c new file mode 100644 index 0000000000000000000000000000000000000000..bc36f844559e8a0058e19daf51d320619f96817b --- /dev/null +++ b/tests/expectations/cfg-2.c @@ -0,0 +1,27 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +#if (defined(NOT_DEFINED) || defined(DEFINED)) +typedef struct { + int32_t x; +} Foo; +#endif + +#if defined(NOT_DEFINED) +typedef struct { + Foo y; +} Bar; +#endif + +#if defined(DEFINED) +typedef struct { + Foo z; +} Bar; +#endif + +typedef struct { + Bar w; +} Root; + +void root(Root a); diff --git a/tests/expectations/cfg-2.cpp b/tests/expectations/cfg-2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..44b493f303bb06de314fe39f684a7f6082607026 --- /dev/null +++ b/tests/expectations/cfg-2.cpp @@ -0,0 +1,30 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +#if (defined(NOT_DEFINED) || defined(DEFINED)) +struct Foo { + int32_t x; +}; +#endif + +#if defined(NOT_DEFINED) +struct Bar { + Foo y; +}; +#endif + +#if defined(DEFINED) +struct Bar { + Foo z; +}; +#endif + +struct Root { + Bar w; +}; + +void root(Root a); + +} // extern "C" diff --git a/tests/expectations/cfg.c b/tests/expectations/cfg.c new file mode 100644 index 0000000000000000000000000000000000000000..7f008c6fb6a77d483fc14333fd5d034026d31622 --- /dev/null +++ b/tests/expectations/cfg.c @@ -0,0 +1,45 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +#if (defined(PLATFORM_WIN) || defined(M_32)) +enum BarType { + A = 0, + B = 1, + C = 2, +}; +typedef uint32_t BarType; +#endif + +#if (defined(PLATFORM_UNIX) && defined(X11)) +enum FooType { + A = 0, + B = 1, + C = 2, +}; +typedef uint32_t FooType; +#endif + +#if (defined(PLATFORM_UNIX) && defined(X11)) +typedef struct { + FooType ty; + int32_t x; + float y; +} FooHandle; +#endif + +#if (defined(PLATFORM_WIN) || defined(M_32)) +typedef struct { + BarType ty; + int32_t x; + float y; +} BarHandle; +#endif + +#if (defined(PLATFORM_UNIX) && defined(X11)) +void root(FooHandle a); +#endif + +#if (defined(PLATFORM_WIN) || defined(M_32)) +void root(BarHandle a); +#endif diff --git a/tests/expectations/cfg.cpp b/tests/expectations/cfg.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c21480e3d2644c3e3c7b22321ebb01d64139cc9b --- /dev/null +++ b/tests/expectations/cfg.cpp @@ -0,0 +1,46 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +#if (defined(PLATFORM_WIN) || defined(M_32)) +enum class BarType : uint32_t { + A = 0, + B = 1, + C = 2, +}; +#endif + +#if (defined(PLATFORM_UNIX) && defined(X11)) +enum class FooType : uint32_t { + A = 0, + B = 1, + C = 2, +}; +#endif + +#if (defined(PLATFORM_UNIX) && defined(X11)) +struct FooHandle { + FooType ty; + int32_t x; + float y; +}; +#endif + +#if (defined(PLATFORM_WIN) || defined(M_32)) +struct BarHandle { + BarType ty; + int32_t x; + float y; +}; +#endif + +#if (defined(PLATFORM_UNIX) && defined(X11)) +void root(FooHandle a); +#endif + +#if (defined(PLATFORM_WIN) || defined(M_32)) +void root(BarHandle a); +#endif + +} // extern "C" diff --git a/tests/expectations/constant.c b/tests/expectations/constant.c new file mode 100644 index 0000000000000000000000000000000000000000..52c555b7c23763e55482af06fd1655d00c442aa7 --- /dev/null +++ b/tests/expectations/constant.c @@ -0,0 +1,15 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +#define BAR u8"hello world" + +#define FOO 10 + +#define ZOM 3.14 + +typedef struct { + int32_t x[FOO]; +} Foo; + +void root(Foo x); diff --git a/tests/expectations/constant.cpp b/tests/expectations/constant.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9000e0e5bbad1d02c8c74bee2ea0c7d110ac34a7 --- /dev/null +++ b/tests/expectations/constant.cpp @@ -0,0 +1,18 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +static const char* BAR = u8"hello world"; + +static const int32_t FOO = 10; + +static const float ZOM = 3.14; + +struct Foo { + int32_t x[FOO]; +}; + +void root(Foo x); + +} // extern "C" diff --git a/tests/expectations/enum.c b/tests/expectations/enum.c new file mode 100644 index 0000000000000000000000000000000000000000..109972ae67dbacd4609b02e49206618c4e328b7b --- /dev/null +++ b/tests/expectations/enum.c @@ -0,0 +1,48 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +enum A { + a1 = 0, + a2 = 2, + a3 = 3, + a4 = 5, +}; +typedef uint32_t A; + +enum B { + b1 = 0, + b2 = 2, + b3 = 3, + b4 = 5, +}; +typedef uint16_t B; + +enum C { + c1 = 0, + c2 = 2, + c3 = 3, + c4 = 5, +}; +typedef uint8_t C; + +enum D { + d1 = 0, + d2 = 2, + d3 = 3, + d4 = 5, +}; +typedef uintptr_t D; + +enum E { + e1 = 0, + e2 = 2, + e3 = 3, + e4 = 5, +}; +typedef intptr_t E; + +struct Opaque; +typedef struct Opaque Opaque; + +void root(Opaque *o, A a, B b, C c, D d, E e); diff --git a/tests/expectations/enum.cpp b/tests/expectations/enum.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a51af59680088932e77a19629303fef087bf88e4 --- /dev/null +++ b/tests/expectations/enum.cpp @@ -0,0 +1,45 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +enum class A : uint32_t { + a1 = 0, + a2 = 2, + a3 = 3, + a4 = 5, +}; + +enum class B : uint16_t { + b1 = 0, + b2 = 2, + b3 = 3, + b4 = 5, +}; + +enum class C : uint8_t { + c1 = 0, + c2 = 2, + c3 = 3, + c4 = 5, +}; + +enum class D : uintptr_t { + d1 = 0, + d2 = 2, + d3 = 3, + d4 = 5, +}; + +enum class E : intptr_t { + e1 = 0, + e2 = 2, + e3 = 3, + e4 = 5, +}; + +struct Opaque; + +void root(Opaque *o, A a, B b, C c, D d, E e); + +} // extern "C" diff --git a/tests/expectations/euclid.c b/tests/expectations/euclid.c new file mode 100644 index 0000000000000000000000000000000000000000..1a79e4a09384ce8995a66ead69809d1d60348009 --- /dev/null +++ b/tests/expectations/euclid.c @@ -0,0 +1,132 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +typedef struct { + float _0; +} TypedLength_f32__UnknownUnit; + +typedef struct { + float _0; +} TypedLength_f32__LayoutUnit; + +typedef struct { + float _0; +} Length_f32; + +typedef TypedLength_f32__LayoutUnit LayoutLength; + +typedef struct { + float top; + float right; + float bottom; + float left; +} TypedSideOffsets2D_f32__UnknownUnit; + +typedef struct { + float top; + float right; + float bottom; + float left; +} TypedSideOffsets2D_f32__LayoutUnit; + +typedef struct { + float top; + float right; + float bottom; + float left; +} SideOffsets2D_f32; + +typedef TypedSideOffsets2D_f32__LayoutUnit LayoutSideOffsets2D; + +typedef struct { + float width; + float height; +} TypedSize2D_f32__UnknownUnit; + +typedef struct { + float width; + float height; +} TypedSize2D_f32__LayoutUnit; + +typedef struct { + float width; + float height; +} Size2D_f32; + +typedef TypedSize2D_f32__LayoutUnit LayoutSize2D; + +typedef struct { + float x; + float y; +} TypedPoint2D_f32__UnknownUnit; + +typedef struct { + float x; + float y; +} TypedPoint2D_f32__LayoutUnit; + +typedef struct { + float x; + float y; +} Point2D_f32; + +typedef TypedPoint2D_f32__LayoutUnit LayoutPoint2D; + +typedef struct { + TypedPoint2D_f32__UnknownUnit origin; + TypedSize2D_f32__UnknownUnit size; +} TypedRect_f32__UnknownUnit; + +typedef struct { + TypedPoint2D_f32__LayoutUnit origin; + TypedSize2D_f32__LayoutUnit size; +} TypedRect_f32__LayoutUnit; + +typedef struct { + TypedPoint2D_f32__UnknownUnit origin; + TypedSize2D_f32__UnknownUnit size; +} Rect_f32; + +typedef TypedRect_f32__LayoutUnit LayoutRect; + +typedef struct { + float m11; + float m12; + float m21; + float m22; + float m31; + float m32; +} TypedTransform2D_f32__UnknownUnit__LayoutUnit; + +typedef struct { + float m11; + float m12; + float m21; + float m22; + float m31; + float m32; +} TypedTransform2D_f32__LayoutUnit__UnknownUnit; + +void root(TypedLength_f32__UnknownUnit length_a, + TypedLength_f32__LayoutUnit length_b, + Length_f32 length_c, + LayoutLength length_d, + TypedSideOffsets2D_f32__UnknownUnit side_offsets_a, + TypedSideOffsets2D_f32__LayoutUnit side_offsets_b, + SideOffsets2D_f32 side_offsets_c, + LayoutSideOffsets2D side_offsets_d, + TypedSize2D_f32__UnknownUnit size_a, + TypedSize2D_f32__LayoutUnit size_b, + Size2D_f32 size_c, + LayoutSize2D size_d, + TypedPoint2D_f32__UnknownUnit point_a, + TypedPoint2D_f32__LayoutUnit point_b, + Point2D_f32 point_c, + LayoutPoint2D point_d, + TypedRect_f32__UnknownUnit rect_a, + TypedRect_f32__LayoutUnit rect_b, + Rect_f32 rect_c, + LayoutRect rect_d, + TypedTransform2D_f32__UnknownUnit__LayoutUnit transform_a, + TypedTransform2D_f32__LayoutUnit__UnknownUnit transform_b); diff --git a/tests/expectations/euclid.cpp b/tests/expectations/euclid.cpp new file mode 100644 index 0000000000000000000000000000000000000000..56e65d1c799058bf61a6d6605793ed7395f3eb59 --- /dev/null +++ b/tests/expectations/euclid.cpp @@ -0,0 +1,257 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +struct LayoutUnit; + +struct UnknownUnit; + +struct TypedLength_f32__UnknownUnit { + float _0; +}; + +struct TypedLength_f32__LayoutUnit { + float _0; +}; + +struct Length_f32 { + float _0; +}; + +typedef TypedLength_f32__LayoutUnit LayoutLength; + +struct TypedSideOffsets2D_f32__UnknownUnit { + float top; + float right; + float bottom; + float left; +}; + +struct TypedSideOffsets2D_f32__LayoutUnit { + float top; + float right; + float bottom; + float left; +}; + +struct SideOffsets2D_f32 { + float top; + float right; + float bottom; + float left; +}; + +typedef TypedSideOffsets2D_f32__LayoutUnit LayoutSideOffsets2D; + +struct TypedSize2D_f32__UnknownUnit { + float width; + float height; +}; + +struct TypedSize2D_f32__LayoutUnit { + float width; + float height; +}; + +struct Size2D_f32 { + float width; + float height; +}; + +typedef TypedSize2D_f32__LayoutUnit LayoutSize2D; + +struct TypedPoint2D_f32__UnknownUnit { + float x; + float y; +}; + +struct TypedPoint2D_f32__LayoutUnit { + float x; + float y; +}; + +struct Point2D_f32 { + float x; + float y; +}; + +typedef TypedPoint2D_f32__LayoutUnit LayoutPoint2D; + +struct TypedRect_f32__UnknownUnit { + TypedPoint2D_f32__UnknownUnit origin; + TypedSize2D_f32__UnknownUnit size; +}; + +struct TypedRect_f32__LayoutUnit { + TypedPoint2D_f32__LayoutUnit origin; + TypedSize2D_f32__LayoutUnit size; +}; + +struct Rect_f32 { + TypedPoint2D_f32__UnknownUnit origin; + TypedSize2D_f32__UnknownUnit size; +}; + +typedef TypedRect_f32__LayoutUnit LayoutRect; + +struct TypedTransform2D_f32__UnknownUnit__LayoutUnit { + float m11; + float m12; + float m21; + float m22; + float m31; + float m32; +}; + +struct TypedTransform2D_f32__LayoutUnit__UnknownUnit { + float m11; + float m12; + float m21; + float m22; + float m31; + float m32; +}; + +void root(TypedLength_f32__UnknownUnit length_a, + TypedLength_f32__LayoutUnit length_b, + Length_f32 length_c, + LayoutLength length_d, + TypedSideOffsets2D_f32__UnknownUnit side_offsets_a, + TypedSideOffsets2D_f32__LayoutUnit side_offsets_b, + SideOffsets2D_f32 side_offsets_c, + LayoutSideOffsets2D side_offsets_d, + TypedSize2D_f32__UnknownUnit size_a, + TypedSize2D_f32__LayoutUnit size_b, + Size2D_f32 size_c, + LayoutSize2D size_d, + TypedPoint2D_f32__UnknownUnit point_a, + TypedPoint2D_f32__LayoutUnit point_b, + Point2D_f32 point_c, + LayoutPoint2D point_d, + TypedRect_f32__UnknownUnit rect_a, + TypedRect_f32__LayoutUnit rect_b, + Rect_f32 rect_c, + LayoutRect rect_d, + TypedTransform2D_f32__UnknownUnit__LayoutUnit transform_a, + TypedTransform2D_f32__LayoutUnit__UnknownUnit transform_b); + +} // extern "C" + +template<typename T> +struct Length; + +template<> +struct Length<float> : public Length_f32 { + +}; + +template<typename T> +struct Point2D; + +template<> +struct Point2D<float> : public Point2D_f32 { + +}; + +template<typename T> +struct Rect; + +template<> +struct Rect<float> : public Rect_f32 { + +}; + +template<typename T> +struct SideOffsets2D; + +template<> +struct SideOffsets2D<float> : public SideOffsets2D_f32 { + +}; + +template<typename T> +struct Size2D; + +template<> +struct Size2D<float> : public Size2D_f32 { + +}; + +template<typename T, typename Unit> +struct TypedLength; + +template<> +struct TypedLength<float, LayoutUnit> : public TypedLength_f32__LayoutUnit { + +}; + +template<> +struct TypedLength<float, UnknownUnit> : public TypedLength_f32__UnknownUnit { + +}; + +template<typename T, typename U> +struct TypedPoint2D; + +template<> +struct TypedPoint2D<float, LayoutUnit> : public TypedPoint2D_f32__LayoutUnit { + +}; + +template<> +struct TypedPoint2D<float, UnknownUnit> : public TypedPoint2D_f32__UnknownUnit { + +}; + +template<typename T, typename U> +struct TypedRect; + +template<> +struct TypedRect<float, LayoutUnit> : public TypedRect_f32__LayoutUnit { + +}; + +template<> +struct TypedRect<float, UnknownUnit> : public TypedRect_f32__UnknownUnit { + +}; + +template<typename T, typename U> +struct TypedSideOffsets2D; + +template<> +struct TypedSideOffsets2D<float, LayoutUnit> : public TypedSideOffsets2D_f32__LayoutUnit { + +}; + +template<> +struct TypedSideOffsets2D<float, UnknownUnit> : public TypedSideOffsets2D_f32__UnknownUnit { + +}; + +template<typename T, typename U> +struct TypedSize2D; + +template<> +struct TypedSize2D<float, LayoutUnit> : public TypedSize2D_f32__LayoutUnit { + +}; + +template<> +struct TypedSize2D<float, UnknownUnit> : public TypedSize2D_f32__UnknownUnit { + +}; + +template<typename T, typename Src, typename Dst> +struct TypedTransform2D; + +template<> +struct TypedTransform2D<float, UnknownUnit, LayoutUnit> : public TypedTransform2D_f32__UnknownUnit__LayoutUnit { + +}; + +template<> +struct TypedTransform2D<float, LayoutUnit, UnknownUnit> : public TypedTransform2D_f32__LayoutUnit__UnknownUnit { + +}; diff --git a/tests/expectations/extern-2.c b/tests/expectations/extern-2.c new file mode 100644 index 0000000000000000000000000000000000000000..0b98a01df96c65e29f7cdb667365aadd1586b40c --- /dev/null +++ b/tests/expectations/extern-2.c @@ -0,0 +1,7 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +void first(); + +void second(); diff --git a/tests/expectations/extern-2.cpp b/tests/expectations/extern-2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c32a373bd84bfbe7c843403d297083096e86870f --- /dev/null +++ b/tests/expectations/extern-2.cpp @@ -0,0 +1,10 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +void first(); + +void second(); + +} // extern "C" diff --git a/tests/expectations/extern.c b/tests/expectations/extern.c new file mode 100644 index 0000000000000000000000000000000000000000..94d136eef43c085cfeee604258e34f2f671606b6 --- /dev/null +++ b/tests/expectations/extern.c @@ -0,0 +1,12 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +typedef struct { + int32_t x; + float y; +} Normal; + +extern void bar(Normal a); + +extern int32_t foo(); diff --git a/tests/expectations/extern.cpp b/tests/expectations/extern.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd2c8394da48347e2c0ff7d2689cb6b22128a4b9 --- /dev/null +++ b/tests/expectations/extern.cpp @@ -0,0 +1,15 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +struct Normal { + int32_t x; + float y; +}; + +extern void bar(Normal a); + +extern int32_t foo(); + +} // extern "C" diff --git a/tests/expectations/monomorph-1.c b/tests/expectations/monomorph-1.c new file mode 100644 index 0000000000000000000000000000000000000000..d269ba2e053a24b4a5efb5deb3b9ba51d93a9d1a --- /dev/null +++ b/tests/expectations/monomorph-1.c @@ -0,0 +1,43 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +struct Bar_Bar_f32; +typedef struct Bar_Bar_f32 Bar_Bar_f32; + +struct Bar_Foo_f32; +typedef struct Bar_Foo_f32 Bar_Foo_f32; + +struct Bar_f32; +typedef struct Bar_f32 Bar_f32; + +typedef struct { + const int32_t *data; +} Foo_i32; + +typedef struct { + const float *data; +} Foo_f32; + +typedef struct { + const Bar_f32 *data; +} Foo_Bar_f32; + +typedef struct { + const Foo_f32 *a; + const float *b; +} Tuple_Foo_f32_____f32; + +typedef struct { + const float *a; + const float *b; +} Indirection_f32; + +void root(Foo_i32 a, + Foo_f32 b, + Bar_f32 c, + Foo_Bar_f32 d, + Bar_Foo_f32 e, + Bar_Bar_f32 f, + Tuple_Foo_f32_____f32 g, + Indirection_f32 h); diff --git a/tests/expectations/monomorph-1.cpp b/tests/expectations/monomorph-1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dae1add24cd920496e6c4e2b6321b9b2d9caaf3f --- /dev/null +++ b/tests/expectations/monomorph-1.cpp @@ -0,0 +1,77 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +struct Bar_Bar_f32; + +struct Bar_Foo_f32; + +struct Bar_f32; + +struct Foo_i32 { + const int32_t *data; +}; + +struct Foo_f32 { + const float *data; +}; + +struct Foo_Bar_f32 { + const Bar_f32 *data; +}; + +struct Tuple_Foo_f32_____f32 { + const Foo_f32 *a; + const float *b; +}; + +struct Indirection_f32 { + const float *a; + const float *b; +}; + +void root(Foo_i32 a, + Foo_f32 b, + Bar_f32 c, + Foo_Bar_f32 d, + Bar_Foo_f32 e, + Bar_Bar_f32 f, + Tuple_Foo_f32_____f32 g, + Indirection_f32 h); + +} // extern "C" + +template<typename T> +struct Foo; + +template<> +struct Foo<int32_t> : public Foo_i32 { + +}; + +template<> +struct Foo<float> : public Foo_f32 { + +}; + +template<> +struct Foo<Bar_f32> : public Foo_Bar_f32 { + +}; + +template<typename T> +struct Indirection; + +template<> +struct Indirection<float> : public Indirection_f32 { + +}; + +template<typename T, typename E> +struct Tuple; + +template<> +struct Tuple<Foo_f32, float> : public Tuple_Foo_f32_____f32 { + +}; diff --git a/tests/expectations/monomorph-2.c b/tests/expectations/monomorph-2.c new file mode 100644 index 0000000000000000000000000000000000000000..fa44ab2a00e24743194c8a291fff19980d298718 --- /dev/null +++ b/tests/expectations/monomorph-2.c @@ -0,0 +1,23 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +struct A; +typedef struct A A; + +struct B; +typedef struct B B; + +typedef struct { + B *members; + size_t count; +} List_B; + +typedef struct { + A *members; + size_t count; +} List_A; + +void bar(List_B b); + +void foo(List_A a); diff --git a/tests/expectations/monomorph-2.cpp b/tests/expectations/monomorph-2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b458a90f28020ae7432932b5ee3cab7953c47f02 --- /dev/null +++ b/tests/expectations/monomorph-2.cpp @@ -0,0 +1,37 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +struct A; + +struct B; + +struct List_B { + B *members; + size_t count; +}; + +struct List_A { + A *members; + size_t count; +}; + +void bar(List_B b); + +void foo(List_A a); + +} // extern "C" + +template<typename T> +struct List; + +template<> +struct List<B> : public List_B { + +}; + +template<> +struct List<A> : public List_A { + +}; diff --git a/tests/expectations/monomorph-3.c b/tests/expectations/monomorph-3.c new file mode 100644 index 0000000000000000000000000000000000000000..2c5bb4b57f761e6e528759225de55fcbb0653a9c --- /dev/null +++ b/tests/expectations/monomorph-3.c @@ -0,0 +1,43 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +struct Bar_Bar_f32; +typedef struct Bar_Bar_f32 Bar_Bar_f32; + +struct Bar_Foo_f32; +typedef struct Bar_Foo_f32 Bar_Foo_f32; + +struct Bar_f32; +typedef struct Bar_f32 Bar_f32; + +typedef union { + const int32_t *data; +} Foo_i32; + +typedef union { + const float *data; +} Foo_f32; + +typedef union { + const Bar_f32 *data; +} Foo_Bar_f32; + +typedef union { + const Foo_f32 *a; + const float *b; +} Tuple_Foo_f32_____f32; + +typedef union { + const float *a; + const float *b; +} Indirection_f32; + +void root(Foo_i32 a, + Foo_f32 b, + Bar_f32 c, + Foo_Bar_f32 d, + Bar_Foo_f32 e, + Bar_Bar_f32 f, + Tuple_Foo_f32_____f32 g, + Indirection_f32 h); diff --git a/tests/expectations/monomorph-3.cpp b/tests/expectations/monomorph-3.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e3974ffa4838c05c6f696efb18e5a76427da71b8 --- /dev/null +++ b/tests/expectations/monomorph-3.cpp @@ -0,0 +1,43 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +struct Bar_Bar_f32; + +struct Bar_Foo_f32; + +struct Bar_f32; + +union Foo_i32 { + const int32_t *data; +}; + +union Foo_f32 { + const float *data; +}; + +union Foo_Bar_f32 { + const Bar_f32 *data; +}; + +union Tuple_Foo_f32_____f32 { + const Foo_f32 *a; + const float *b; +}; + +union Indirection_f32 { + const float *a; + const float *b; +}; + +void root(Foo_i32 a, + Foo_f32 b, + Bar_f32 c, + Foo_Bar_f32 d, + Bar_Foo_f32 e, + Bar_Bar_f32 f, + Tuple_Foo_f32_____f32 g, + Indirection_f32 h); + +} // extern "C" diff --git a/tests/expectations/simplify-option-ptr.c b/tests/expectations/simplify-option-ptr.c new file mode 100644 index 0000000000000000000000000000000000000000..404c25e2b9b04b6345557187bc9d2793112c2cdf --- /dev/null +++ b/tests/expectations/simplify-option-ptr.c @@ -0,0 +1,20 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +struct Opaque; +typedef struct Opaque Opaque; + +typedef struct { + const Opaque *x; + Opaque *y; + void (*z)(); +} Foo; + +typedef union { + const Opaque *x; + Opaque *y; + void (*z)(); +} Bar; + +void root(const Opaque *a, Opaque *b, Foo c, Bar d); diff --git a/tests/expectations/simplify-option-ptr.cpp b/tests/expectations/simplify-option-ptr.cpp new file mode 100644 index 0000000000000000000000000000000000000000..926c56ae2ab4bfeaab5555f808bb09c7c12e7ff0 --- /dev/null +++ b/tests/expectations/simplify-option-ptr.cpp @@ -0,0 +1,22 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +struct Opaque; + +struct Foo { + const Opaque *x; + Opaque *y; + void (*z)(); +}; + +union Bar { + const Opaque *x; + Opaque *y; + void (*z)(); +}; + +void root(const Opaque *a, Opaque *b, Foo c, Bar d); + +} // extern "C" diff --git a/tests/expectations/static.c b/tests/expectations/static.c new file mode 100644 index 0000000000000000000000000000000000000000..2266aa28e5d6d4911c972153f3634746a6241bea --- /dev/null +++ b/tests/expectations/static.c @@ -0,0 +1,20 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +struct Bar; +typedef struct Bar Bar; + +typedef struct { + +} Foo; + +extern const Bar BAR; + +extern Foo FOO; + +extern const int32_t NUMBER; + +extern const char* STRING; + +void root(); diff --git a/tests/expectations/static.cpp b/tests/expectations/static.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b92be9d1b39e79b9b39cf6229129c7a2631b87a --- /dev/null +++ b/tests/expectations/static.cpp @@ -0,0 +1,22 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +struct Bar; + +struct Foo { + +}; + +extern const Bar BAR; + +extern Foo FOO; + +extern const int32_t NUMBER; + +extern const char* STRING; + +void root(); + +} // extern "C" diff --git a/tests/expectations/std_lib.c b/tests/expectations/std_lib.c new file mode 100644 index 0000000000000000000000000000000000000000..8def5ba11051928c115efbe10f4743e0cf6b62da --- /dev/null +++ b/tests/expectations/std_lib.c @@ -0,0 +1,14 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +struct Option_i32; +typedef struct Option_i32 Option_i32; + +struct Result_i32__String; +typedef struct Result_i32__String Result_i32__String; + +struct Vec_String; +typedef struct Vec_String Vec_String; + +void root(const Vec_String *a, const Option_i32 *b, const Result_i32__String *c); diff --git a/tests/expectations/std_lib.cpp b/tests/expectations/std_lib.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db4aae91090f261543f1ea141ed7b8aef4eb6d49 --- /dev/null +++ b/tests/expectations/std_lib.cpp @@ -0,0 +1,14 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +struct Option_i32; + +struct Result_i32__String; + +struct Vec_String; + +void root(const Vec_String *a, const Option_i32 *b, const Result_i32__String *c); + +} // extern "C" diff --git a/tests/expectations/struct.c b/tests/expectations/struct.c new file mode 100644 index 0000000000000000000000000000000000000000..677a9ace25be6ab5ebc5ba1fd73966bcc792ef9a --- /dev/null +++ b/tests/expectations/struct.c @@ -0,0 +1,28 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +struct Opaque; +typedef struct Opaque Opaque; + +typedef struct { + int32_t x; + float y; +} Normal; + +typedef struct { + int32_t x; + float y; +} NormalWithZST; + +typedef struct { + int32_t m0; + float m1; +} TupleRenamed; + +typedef struct { + int32_t x; + float y; +} TupleNamed; + +void root(Opaque *a, Normal b, NormalWithZST c, TupleRenamed d, TupleNamed e); diff --git a/tests/expectations/struct.cpp b/tests/expectations/struct.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dfa6724e482b5c8df7cde882bcb55e6bd1172064 --- /dev/null +++ b/tests/expectations/struct.cpp @@ -0,0 +1,30 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +struct Opaque; + +struct Normal { + int32_t x; + float y; +}; + +struct NormalWithZST { + int32_t x; + float y; +}; + +struct TupleRenamed { + int32_t m0; + float m1; +}; + +struct TupleNamed { + int32_t x; + float y; +}; + +void root(Opaque *a, Normal b, NormalWithZST c, TupleRenamed d, TupleNamed e); + +} // extern "C" diff --git a/tests/expectations/typedef.c b/tests/expectations/typedef.c new file mode 100644 index 0000000000000000000000000000000000000000..1e2dbf9f5b2c601a08c9970ae19e3c7dfca9a659 --- /dev/null +++ b/tests/expectations/typedef.c @@ -0,0 +1,10 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +typedef struct { + int32_t x; + int32_t y; +} IntFoo_i32; + +void root(IntFoo_i32 a); diff --git a/tests/expectations/typedef.cpp b/tests/expectations/typedef.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ca4cc789e6eac3d1a0ba36dad5fae4e648adc192 --- /dev/null +++ b/tests/expectations/typedef.cpp @@ -0,0 +1,21 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +struct IntFoo_i32 { + int32_t x; + int32_t y; +}; + +void root(IntFoo_i32 a); + +} // extern "C" + +template<typename T> +struct IntFoo; + +template<> +struct IntFoo<int32_t> : public IntFoo_i32 { + +}; diff --git a/tests/expectations/union.c b/tests/expectations/union.c new file mode 100644 index 0000000000000000000000000000000000000000..07e1035c98aea751de4c964d488c56d4bd2179e0 --- /dev/null +++ b/tests/expectations/union.c @@ -0,0 +1,18 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +struct Opaque; +typedef struct Opaque Opaque; + +typedef union { + int32_t x; + float y; +} Normal; + +typedef union { + int32_t x; + float y; +} NormalWithZST; + +void root(Opaque *a, Normal b, NormalWithZST c); diff --git a/tests/expectations/union.cpp b/tests/expectations/union.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bc80bf6331566a48e5d9ef9114e596be6a75fc9e --- /dev/null +++ b/tests/expectations/union.cpp @@ -0,0 +1,20 @@ +#include <cstdint> +#include <cstdlib> + +extern "C" { + +struct Opaque; + +union Normal { + int32_t x; + float y; +}; + +union NormalWithZST { + int32_t x; + float y; +}; + +void root(Opaque *a, Normal b, NormalWithZST c); + +} // extern "C" diff --git a/compile-tests/alias.rs b/tests/rust/alias.rs similarity index 100% rename from compile-tests/alias.rs rename to tests/rust/alias.rs diff --git a/compile-tests/annotation.rs b/tests/rust/annotation.rs similarity index 100% rename from compile-tests/annotation.rs rename to tests/rust/annotation.rs diff --git a/compile-tests/cdecl.rs b/tests/rust/cdecl.rs similarity index 100% rename from compile-tests/cdecl.rs rename to tests/rust/cdecl.rs diff --git a/compile-tests/cfg-2.rs b/tests/rust/cfg-2.rs similarity index 100% rename from compile-tests/cfg-2.rs rename to tests/rust/cfg-2.rs diff --git a/compile-tests/cfg-2.toml b/tests/rust/cfg-2.toml similarity index 100% rename from compile-tests/cfg-2.toml rename to tests/rust/cfg-2.toml diff --git a/compile-tests/cfg.rs b/tests/rust/cfg.rs similarity index 100% rename from compile-tests/cfg.rs rename to tests/rust/cfg.rs diff --git a/compile-tests/cfg.toml b/tests/rust/cfg.toml similarity index 100% rename from compile-tests/cfg.toml rename to tests/rust/cfg.toml diff --git a/compile-tests/constant.rs b/tests/rust/constant.rs similarity index 100% rename from compile-tests/constant.rs rename to tests/rust/constant.rs diff --git a/compile-tests/enum.rs b/tests/rust/enum.rs similarity index 100% rename from compile-tests/enum.rs rename to tests/rust/enum.rs diff --git a/compile-tests/euclid.rs b/tests/rust/euclid.rs similarity index 100% rename from compile-tests/euclid.rs rename to tests/rust/euclid.rs diff --git a/compile-tests/extern-2.rs b/tests/rust/extern-2.rs similarity index 100% rename from compile-tests/extern-2.rs rename to tests/rust/extern-2.rs diff --git a/compile-tests/extern.rs b/tests/rust/extern.rs similarity index 100% rename from compile-tests/extern.rs rename to tests/rust/extern.rs diff --git a/compile-tests/monomorph-1.rs b/tests/rust/monomorph-1.rs similarity index 100% rename from compile-tests/monomorph-1.rs rename to tests/rust/monomorph-1.rs diff --git a/compile-tests/monomorph-1.toml b/tests/rust/monomorph-1.toml similarity index 100% rename from compile-tests/monomorph-1.toml rename to tests/rust/monomorph-1.toml diff --git a/compile-tests/monomorph-2.rs b/tests/rust/monomorph-2.rs similarity index 100% rename from compile-tests/monomorph-2.rs rename to tests/rust/monomorph-2.rs diff --git a/compile-tests/monomorph-3.rs b/tests/rust/monomorph-3.rs similarity index 100% rename from compile-tests/monomorph-3.rs rename to tests/rust/monomorph-3.rs diff --git a/compile-tests/monomorph-3.toml b/tests/rust/monomorph-3.toml similarity index 100% rename from compile-tests/monomorph-3.toml rename to tests/rust/monomorph-3.toml diff --git a/compile-tests/simplify-option-ptr.rs b/tests/rust/simplify-option-ptr.rs similarity index 100% rename from compile-tests/simplify-option-ptr.rs rename to tests/rust/simplify-option-ptr.rs diff --git a/compile-tests/static.rs b/tests/rust/static.rs similarity index 100% rename from compile-tests/static.rs rename to tests/rust/static.rs diff --git a/compile-tests/std_lib.rs b/tests/rust/std_lib.rs similarity index 100% rename from compile-tests/std_lib.rs rename to tests/rust/std_lib.rs diff --git a/compile-tests/struct.rs b/tests/rust/struct.rs similarity index 100% rename from compile-tests/struct.rs rename to tests/rust/struct.rs diff --git a/compile-tests/typedef.rs b/tests/rust/typedef.rs similarity index 100% rename from compile-tests/typedef.rs rename to tests/rust/typedef.rs diff --git a/compile-tests/union.rs b/tests/rust/union.rs similarity index 100% rename from compile-tests/union.rs rename to tests/rust/union.rs