Skip to content

Commit

Permalink
tests: Add a test for struct constants going through typedefs.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Jun 9, 2022
1 parent b4bf8c6 commit e0ebad2
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/expectations/const_generics_constant.both.c
@@ -0,0 +1,19 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#define FONT_WEIGHT_FRACTION_BITS 6

typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS {
uint16_t value;
} FixedPoint_FONT_WEIGHT_FRACTION_BITS;

typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;

typedef struct FontWeight {
FontWeightFixedPoint _0;
} FontWeight;
#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } }

void root(struct FontWeight w);
27 changes: 27 additions & 0 deletions tests/expectations/const_generics_constant.both.compat.c
@@ -0,0 +1,27 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#define FONT_WEIGHT_FRACTION_BITS 6

typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS {
uint16_t value;
} FixedPoint_FONT_WEIGHT_FRACTION_BITS;

typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;

typedef struct FontWeight {
FontWeightFixedPoint _0;
} FontWeight;
#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } }

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(struct FontWeight w);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
19 changes: 19 additions & 0 deletions tests/expectations/const_generics_constant.c
@@ -0,0 +1,19 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#define FONT_WEIGHT_FRACTION_BITS 6

typedef struct {
uint16_t value;
} FixedPoint_FONT_WEIGHT_FRACTION_BITS;

typedef FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;

typedef struct {
FontWeightFixedPoint _0;
} FontWeight;
#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } }

void root(FontWeight w);
27 changes: 27 additions & 0 deletions tests/expectations/const_generics_constant.compat.c
@@ -0,0 +1,27 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#define FONT_WEIGHT_FRACTION_BITS 6

typedef struct {
uint16_t value;
} FixedPoint_FONT_WEIGHT_FRACTION_BITS;

typedef FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;

typedef struct {
FontWeightFixedPoint _0;
} FontWeight;
#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } }

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(FontWeight w);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
25 changes: 25 additions & 0 deletions tests/expectations/const_generics_constant.cpp
@@ -0,0 +1,25 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

constexpr static const uint16_t FONT_WEIGHT_FRACTION_BITS = 6;

template<uint16_t FRACTION_BITS>
struct FixedPoint {
uint16_t value;
};

using FontWeightFixedPoint = FixedPoint<FONT_WEIGHT_FRACTION_BITS>;

struct FontWeight {
FontWeightFixedPoint _0;
};
constexpr static const FontWeight FontWeight_NORMAL = FontWeight{ /* ._0 = */ FontWeightFixedPoint{ /* .value = */ (400 << FONT_WEIGHT_FRACTION_BITS) } };

extern "C" {

void root(FontWeight w);

} // extern "C"
20 changes: 20 additions & 0 deletions tests/expectations/const_generics_constant.pyx
@@ -0,0 +1,20 @@
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list

cdef extern from *:

const uint16_t FONT_WEIGHT_FRACTION_BITS # = 6

ctypedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS:
uint16_t value;

ctypedef FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;

ctypedef struct FontWeight:
FontWeightFixedPoint _0;
const FontWeight FontWeight_NORMAL # = <FontWeight>{ <FontWeightFixedPoint>{ (400 << FONT_WEIGHT_FRACTION_BITS) } }

void root(FontWeight w);
19 changes: 19 additions & 0 deletions tests/expectations/const_generics_constant.tag.c
@@ -0,0 +1,19 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#define FONT_WEIGHT_FRACTION_BITS 6

struct FixedPoint_FONT_WEIGHT_FRACTION_BITS {
uint16_t value;
};

typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;

struct FontWeight {
FontWeightFixedPoint _0;
};
#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } }

void root(struct FontWeight w);
27 changes: 27 additions & 0 deletions tests/expectations/const_generics_constant.tag.compat.c
@@ -0,0 +1,27 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#define FONT_WEIGHT_FRACTION_BITS 6

struct FixedPoint_FONT_WEIGHT_FRACTION_BITS {
uint16_t value;
};

typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;

struct FontWeight {
FontWeightFixedPoint _0;
};
#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } }

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(struct FontWeight w);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
20 changes: 20 additions & 0 deletions tests/expectations/const_generics_constant.tag.pyx
@@ -0,0 +1,20 @@
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list

cdef extern from *:

const uint16_t FONT_WEIGHT_FRACTION_BITS # = 6

cdef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS:
uint16_t value;

ctypedef FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;

cdef struct FontWeight:
FontWeightFixedPoint _0;
const FontWeight FontWeight_NORMAL # = <FontWeight>{ <FontWeightFixedPoint>{ (400 << FONT_WEIGHT_FRACTION_BITS) } }

void root(FontWeight w);
18 changes: 18 additions & 0 deletions tests/rust/const_generics_constant.rs
@@ -0,0 +1,18 @@
#[repr(C)]
pub struct FixedPoint<const FRACTION_BITS: u16> {
value: u16,
}

pub const FONT_WEIGHT_FRACTION_BITS: u16 = 6;

pub type FontWeightFixedPoint = FixedPoint<FONT_WEIGHT_FRACTION_BITS>;

#[repr(C)]
pub struct FontWeight(FontWeightFixedPoint);

impl FontWeight {
pub const NORMAL: FontWeight = FontWeight(FontWeightFixedPoint { value: 400 << FONT_WEIGHT_FRACTION_BITS });
}

#[no_mangle]
pub extern "C" fn root(w: FontWeight) {}

0 comments on commit e0ebad2

Please sign in to comment.