Skip to content

Commit 116a18c

Browse files
committed
tests: Add a test for struct constants going through typedefs.
1 parent fc98189 commit 116a18c

10 files changed

+221
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
#define FONT_WEIGHT_FRACTION_BITS 6
7+
8+
typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS {
9+
uint16_t value;
10+
} FixedPoint_FONT_WEIGHT_FRACTION_BITS;
11+
12+
typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;
13+
14+
typedef struct FontWeight {
15+
FontWeightFixedPoint _0;
16+
} FontWeight;
17+
#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } }
18+
19+
void root(struct FontWeight w);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
#define FONT_WEIGHT_FRACTION_BITS 6
7+
8+
typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS {
9+
uint16_t value;
10+
} FixedPoint_FONT_WEIGHT_FRACTION_BITS;
11+
12+
typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;
13+
14+
typedef struct FontWeight {
15+
FontWeightFixedPoint _0;
16+
} FontWeight;
17+
#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } }
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif // __cplusplus
22+
23+
void root(struct FontWeight w);
24+
25+
#ifdef __cplusplus
26+
} // extern "C"
27+
#endif // __cplusplus
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
#define FONT_WEIGHT_FRACTION_BITS 6
7+
8+
typedef struct {
9+
uint16_t value;
10+
} FixedPoint_FONT_WEIGHT_FRACTION_BITS;
11+
12+
typedef FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;
13+
14+
typedef struct {
15+
FontWeightFixedPoint _0;
16+
} FontWeight;
17+
#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } }
18+
19+
void root(FontWeight w);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
#define FONT_WEIGHT_FRACTION_BITS 6
7+
8+
typedef struct {
9+
uint16_t value;
10+
} FixedPoint_FONT_WEIGHT_FRACTION_BITS;
11+
12+
typedef FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;
13+
14+
typedef struct {
15+
FontWeightFixedPoint _0;
16+
} FontWeight;
17+
#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } }
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif // __cplusplus
22+
23+
void root(FontWeight w);
24+
25+
#ifdef __cplusplus
26+
} // extern "C"
27+
#endif // __cplusplus
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <cstdarg>
2+
#include <cstdint>
3+
#include <cstdlib>
4+
#include <ostream>
5+
#include <new>
6+
7+
constexpr static const uint16_t FONT_WEIGHT_FRACTION_BITS = 6;
8+
9+
template<uint16_t FRACTION_BITS>
10+
struct FixedPoint {
11+
uint16_t value;
12+
};
13+
14+
using FontWeightFixedPoint = FixedPoint<FONT_WEIGHT_FRACTION_BITS>;
15+
16+
struct FontWeight {
17+
FontWeightFixedPoint _0;
18+
};
19+
constexpr static const FontWeight FontWeight_NORMAL = FontWeight{ /* ._0 = */ FontWeightFixedPoint{ /* .value = */ (400 << FONT_WEIGHT_FRACTION_BITS) } };
20+
21+
extern "C" {
22+
23+
void root(FontWeight w);
24+
25+
} // extern "C"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
2+
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
3+
cdef extern from *:
4+
ctypedef bint bool
5+
ctypedef struct va_list
6+
7+
cdef extern from *:
8+
9+
const uint16_t FONT_WEIGHT_FRACTION_BITS # = 6
10+
11+
ctypedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS:
12+
uint16_t value;
13+
14+
ctypedef FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;
15+
16+
ctypedef struct FontWeight:
17+
FontWeightFixedPoint _0;
18+
const FontWeight FontWeight_NORMAL # = <FontWeight>{ <FontWeightFixedPoint>{ (400 << FONT_WEIGHT_FRACTION_BITS) } }
19+
20+
void root(FontWeight w);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
#define FONT_WEIGHT_FRACTION_BITS 6
7+
8+
struct FixedPoint_FONT_WEIGHT_FRACTION_BITS {
9+
uint16_t value;
10+
};
11+
12+
typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;
13+
14+
struct FontWeight {
15+
FontWeightFixedPoint _0;
16+
};
17+
#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } }
18+
19+
void root(struct FontWeight w);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
#define FONT_WEIGHT_FRACTION_BITS 6
7+
8+
struct FixedPoint_FONT_WEIGHT_FRACTION_BITS {
9+
uint16_t value;
10+
};
11+
12+
typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;
13+
14+
struct FontWeight {
15+
FontWeightFixedPoint _0;
16+
};
17+
#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } }
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif // __cplusplus
22+
23+
void root(struct FontWeight w);
24+
25+
#ifdef __cplusplus
26+
} // extern "C"
27+
#endif // __cplusplus
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
2+
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
3+
cdef extern from *:
4+
ctypedef bint bool
5+
ctypedef struct va_list
6+
7+
cdef extern from *:
8+
9+
const uint16_t FONT_WEIGHT_FRACTION_BITS # = 6
10+
11+
cdef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS:
12+
uint16_t value;
13+
14+
ctypedef FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint;
15+
16+
cdef struct FontWeight:
17+
FontWeightFixedPoint _0;
18+
const FontWeight FontWeight_NORMAL # = <FontWeight>{ <FontWeightFixedPoint>{ (400 << FONT_WEIGHT_FRACTION_BITS) } }
19+
20+
void root(FontWeight w);

tests/rust/const_generics_constant.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#[repr(C)]
2+
pub struct FixedPoint<const FRACTION_BITS: u16> {
3+
value: u16,
4+
}
5+
6+
pub const FONT_WEIGHT_FRACTION_BITS: u16 = 6;
7+
8+
pub type FontWeightFixedPoint = FixedPoint<FONT_WEIGHT_FRACTION_BITS>;
9+
10+
#[repr(C)]
11+
pub struct FontWeight(FontWeightFixedPoint);
12+
13+
impl FontWeight {
14+
pub const NORMAL: FontWeight = FontWeight(FontWeightFixedPoint { value: 400 << FONT_WEIGHT_FRACTION_BITS });
15+
}
16+
17+
#[no_mangle]
18+
pub extern "C" fn root(w: FontWeight) {}

0 commit comments

Comments
 (0)