enumeration: simplify standard types in variants.

Fixes #745
This commit is contained in:
Emilio Cobos Álvarez
2022-03-31 22:05:21 +02:00
parent aeb81934d1
commit 09284108eb
13 changed files with 327 additions and 9 deletions
+12
View File
@@ -240,6 +240,12 @@ impl EnumVariant {
}
}
fn simplify_standard_types(&mut self, config: &Config) {
if let VariantBody::Body { ref mut body, .. } = self.body {
body.simplify_standard_types(config);
}
}
fn add_dependencies(&self, library: &Library, out: &mut Dependencies) {
if let VariantBody::Body { ref body, .. } = self.body {
body.add_dependencies(library, out);
@@ -1525,4 +1531,10 @@ impl Enum {
}
}
}
pub fn simplify_standard_types(&mut self, config: &Config) {
for variant in &mut self.variants {
variant.simplify_standard_types(config);
}
}
}
+3
View File
@@ -380,6 +380,9 @@ impl Library {
self.structs.for_all_items_mut(|x| {
x.simplify_standard_types(config);
});
self.enums.for_all_items_mut(|x| {
x.simplify_standard_types(config);
});
self.unions.for_all_items_mut(|x| {
x.simplify_standard_types(config);
});
+33 -1
View File
@@ -1,3 +1,17 @@
#if 0
''' '
#endif
#ifdef __cplusplus
template <typename T>
using Box = T*;
#endif
#if 0
' '''
#endif
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
@@ -173,6 +187,23 @@ typedef struct P {
};
} P;
typedef enum Q_Tag {
Ok,
Err,
} Q_Tag;
typedef struct Q {
Q_Tag tag;
union {
struct {
uint32_t *ok;
};
struct {
uint32_t err;
};
};
} Q;
void root(struct Opaque *opaque,
A a,
B b,
@@ -189,7 +220,8 @@ void root(struct Opaque *opaque,
M m,
enum N n,
O o,
struct P p);
struct P p,
struct Q q);
#if 0
''' '
+33 -1
View File
@@ -1,3 +1,17 @@
#if 0
''' '
#endif
#ifdef __cplusplus
template <typename T>
using Box = T*;
#endif
#if 0
' '''
#endif
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
@@ -239,6 +253,23 @@ typedef struct P {
};
} P;
typedef enum Q_Tag {
Ok,
Err,
} Q_Tag;
typedef struct Q {
Q_Tag tag;
union {
struct {
uint32_t *ok;
};
struct {
uint32_t err;
};
};
} Q;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
@@ -259,7 +290,8 @@ void root(struct Opaque *opaque,
M m,
enum N n,
O o,
struct P p);
struct P p,
struct Q q);
#ifdef __cplusplus
} // extern "C"
+33 -1
View File
@@ -1,3 +1,17 @@
#if 0
''' '
#endif
#ifdef __cplusplus
template <typename T>
using Box = T*;
#endif
#if 0
' '''
#endif
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
@@ -173,6 +187,23 @@ typedef struct {
};
} P;
typedef enum {
Ok,
Err,
} Q_Tag;
typedef struct {
Q_Tag tag;
union {
struct {
uint32_t *ok;
};
struct {
uint32_t err;
};
};
} Q;
void root(Opaque *opaque,
A a,
B b,
@@ -189,7 +220,8 @@ void root(Opaque *opaque,
M m,
N n,
O o,
P p);
P p,
Q q);
#if 0
''' '
+33 -1
View File
@@ -1,3 +1,17 @@
#if 0
''' '
#endif
#ifdef __cplusplus
template <typename T>
using Box = T*;
#endif
#if 0
' '''
#endif
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
@@ -239,6 +253,23 @@ typedef struct {
};
} P;
typedef enum {
Ok,
Err,
} Q_Tag;
typedef struct {
Q_Tag tag;
union {
struct {
uint32_t *ok;
};
struct {
uint32_t err;
};
};
} Q;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
@@ -259,7 +290,8 @@ void root(Opaque *opaque,
M m,
N n,
O o,
P p);
P p,
Q q);
#ifdef __cplusplus
} // extern "C"
+37 -1
View File
@@ -1,3 +1,17 @@
#if 0
''' '
#endif
#ifdef __cplusplus
template <typename T>
using Box = T*;
#endif
#if 0
' '''
#endif
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
@@ -173,6 +187,27 @@ struct P {
};
};
struct Q {
enum class Tag {
Ok,
Err,
};
struct Ok_Body {
Box<uint32_t> _0;
};
struct Err_Body {
uint32_t _0;
};
Tag tag;
union {
Ok_Body ok;
Err_Body err;
};
};
extern "C" {
void root(Opaque *opaque,
@@ -191,7 +226,8 @@ void root(Opaque *opaque,
M m,
N n,
O o,
P p);
P p,
Q q);
} // extern "C"
+25 -1
View File
@@ -1,3 +1,17 @@
#if 0
''' '
#endif
#ifdef __cplusplus
template <typename T>
using Box = T*;
#endif
#if 0
' '''
#endif
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 *:
@@ -142,6 +156,15 @@ cdef extern from *:
uint8_t p0;
P1_Body p1;
ctypedef enum Q_Tag:
Ok,
Err,
ctypedef struct Q:
Q_Tag tag;
uint32_t *ok;
uint32_t err;
void root(Opaque *opaque,
A a,
B b,
@@ -158,7 +181,8 @@ cdef extern from *:
M m,
N n,
O o,
P p);
P p,
Q q);
#if 0
''' '
+33 -1
View File
@@ -1,3 +1,17 @@
#if 0
''' '
#endif
#ifdef __cplusplus
template <typename T>
using Box = T*;
#endif
#if 0
' '''
#endif
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
@@ -173,6 +187,23 @@ struct P {
};
};
enum Q_Tag {
Ok,
Err,
};
struct Q {
enum Q_Tag tag;
union {
struct {
uint32_t *ok;
};
struct {
uint32_t err;
};
};
};
void root(struct Opaque *opaque,
A a,
B b,
@@ -189,7 +220,8 @@ void root(struct Opaque *opaque,
M m,
enum N n,
O o,
struct P p);
struct P p,
struct Q q);
#if 0
''' '
+33 -1
View File
@@ -1,3 +1,17 @@
#if 0
''' '
#endif
#ifdef __cplusplus
template <typename T>
using Box = T*;
#endif
#if 0
' '''
#endif
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
@@ -239,6 +253,23 @@ struct P {
};
};
enum Q_Tag {
Ok,
Err,
};
struct Q {
enum Q_Tag tag;
union {
struct {
uint32_t *ok;
};
struct {
uint32_t err;
};
};
};
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
@@ -259,7 +290,8 @@ void root(struct Opaque *opaque,
M m,
enum N n,
O o,
struct P p);
struct P p,
struct Q q);
#ifdef __cplusplus
} // extern "C"
+25 -1
View File
@@ -1,3 +1,17 @@
#if 0
''' '
#endif
#ifdef __cplusplus
template <typename T>
using Box = T*;
#endif
#if 0
' '''
#endif
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 *:
@@ -142,6 +156,15 @@ cdef extern from *:
uint8_t p0;
P1_Body p1;
cdef enum Q_Tag:
Ok,
Err,
cdef struct Q:
Q_Tag tag;
uint32_t *ok;
uint32_t err;
void root(Opaque *opaque,
A a,
B b,
@@ -158,7 +181,8 @@ cdef extern from *:
M m,
N n,
O o,
P p);
P p,
Q q);
#if 0
''' '
+7
View File
@@ -127,6 +127,12 @@ enum P {
P1(u8, u8, u8),
}
#[repr(C)]
enum Q {
Ok(Box<u32>),
Err(u32),
}
#[no_mangle]
pub extern "C" fn root(
opaque: *mut Opaque,
@@ -146,5 +152,6 @@ pub extern "C" fn root(
n: N,
o: O,
p: P,
q: Q,
) {
}
+20
View File
@@ -1,3 +1,18 @@
header = """
#if 0
''' '
#endif
#ifdef __cplusplus
template <typename T>
using Box = T*;
#endif
#if 0
' '''
#endif
"""
trailer = """
#if 0
''' '
@@ -15,5 +30,10 @@ static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P");
#endif
"""
[export]
exclude = [
"Box",
]
[export.rename]
"I" = "ExI"