Cython: Omit per-variant tags in unions generated for Rust enums
The common `tag` should already be enough, al other tags are identical to it. In Cython case they only create noise because the declarations only introduce names and do not determine layouts.
This commit is contained in:
parent
522759e92b
commit
ca7a942ce5
@ -710,7 +710,7 @@ impl Source for Enum {
|
||||
}
|
||||
|
||||
// Emit fields for all variants with data.
|
||||
self.write_variant_fields(config, out);
|
||||
self.write_variant_fields(config, out, inline_tag_field);
|
||||
|
||||
// Close union of all variants with data, only in the non-inline tag scenario.
|
||||
// See the comment about Cython on `open_brace`.
|
||||
@ -940,7 +940,12 @@ impl Enum {
|
||||
}
|
||||
|
||||
/// Emit fields for all variants with data.
|
||||
fn write_variant_fields<F: Write>(&self, config: &Config, out: &mut SourceWriter<F>) {
|
||||
fn write_variant_fields<F: Write>(
|
||||
&self,
|
||||
config: &Config,
|
||||
out: &mut SourceWriter<F>,
|
||||
inline_tag_field: bool,
|
||||
) {
|
||||
let mut first = true;
|
||||
for variant in &self.variants {
|
||||
if let VariantBody::Body {
|
||||
@ -962,11 +967,15 @@ impl Enum {
|
||||
// by the corresponding C code. So we can inline the unnamed struct and get the
|
||||
// same observable result. Moreother we have to do it because Cython doesn't
|
||||
// support unnamed structs.
|
||||
// For the same reason with Cython we can omit per-variant tags (the first
|
||||
// field) to avoid extra noise, the main `tag` is enough in this case.
|
||||
if config.language != Language::Cython {
|
||||
out.write("struct");
|
||||
out.open_brace();
|
||||
}
|
||||
out.write_vertical_source_list(&body.fields, ListType::Cap(";"));
|
||||
let start_field =
|
||||
usize::from(inline_tag_field && config.language == Language::Cython);
|
||||
out.write_vertical_source_list(&body.fields[start_field..], ListType::Cap(";"));
|
||||
if config.language != Language::Cython {
|
||||
out.close_brace(true);
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ cdef extern from *:
|
||||
|
||||
ctypedef union F:
|
||||
F_Tag tag;
|
||||
F_Tag foo_tag;
|
||||
int16_t foo;
|
||||
Bar_Body bar;
|
||||
|
||||
|
@ -31,7 +31,6 @@ cdef extern from *:
|
||||
|
||||
cdef union F:
|
||||
F_Tag tag;
|
||||
F_Tag foo_tag;
|
||||
int16_t foo;
|
||||
Bar_Body bar;
|
||||
|
||||
|
@ -56,7 +56,6 @@ cdef extern from *:
|
||||
|
||||
ctypedef union K:
|
||||
K_Tag tag;
|
||||
K_Tag foo_tag;
|
||||
int16_t foo;
|
||||
K_Bar_Body bar;
|
||||
|
||||
|
@ -56,7 +56,6 @@ cdef extern from *:
|
||||
|
||||
cdef union K:
|
||||
K_Tag tag;
|
||||
K_Tag foo_tag;
|
||||
int16_t foo;
|
||||
K_Bar_Body bar;
|
||||
|
||||
|
@ -36,7 +36,6 @@ cdef extern from *:
|
||||
|
||||
ctypedef union F:
|
||||
F_Tag tag;
|
||||
F_Tag foo_tag;
|
||||
int16_t foo;
|
||||
Bar_Body bar;
|
||||
|
||||
|
@ -36,7 +36,6 @@ cdef extern from *:
|
||||
|
||||
cdef union F:
|
||||
F_Tag tag;
|
||||
F_Tag foo_tag;
|
||||
int16_t foo;
|
||||
Bar_Body bar;
|
||||
|
||||
|
@ -81,11 +81,8 @@ cdef extern from *:
|
||||
|
||||
ctypedef union Baz_i32:
|
||||
Baz_i32_Tag tag;
|
||||
Baz_i32_Tag polygon21_tag;
|
||||
Polygon_i32 polygon21;
|
||||
Baz_i32_Tag slice21_tag;
|
||||
OwnedSlice_i32 slice21;
|
||||
Baz_i32_Tag slice22_tag;
|
||||
OwnedSlice_i32 slice22;
|
||||
Slice23_Body_i32 slice23;
|
||||
Slice24_Body_i32 slice24;
|
||||
@ -98,9 +95,7 @@ cdef extern from *:
|
||||
|
||||
ctypedef union Taz:
|
||||
Taz_Tag tag;
|
||||
Taz_Tag taz1_tag;
|
||||
int32_t taz1;
|
||||
Taz_Tag taz3_tag;
|
||||
OwnedSlice_i32 taz3;
|
||||
|
||||
cdef enum:
|
||||
@ -110,7 +105,6 @@ cdef extern from *:
|
||||
|
||||
ctypedef union Tazz:
|
||||
Tazz_Tag tag;
|
||||
Tazz_Tag taz2_tag;
|
||||
int32_t taz2;
|
||||
|
||||
cdef enum:
|
||||
@ -120,7 +114,6 @@ cdef extern from *:
|
||||
|
||||
ctypedef union Tazzz:
|
||||
Tazzz_Tag tag;
|
||||
Tazzz_Tag taz5_tag;
|
||||
int32_t taz5;
|
||||
|
||||
cdef enum:
|
||||
@ -130,9 +123,7 @@ cdef extern from *:
|
||||
|
||||
ctypedef union Tazzzz:
|
||||
Tazzzz_Tag tag;
|
||||
Tazzzz_Tag taz6_tag;
|
||||
int32_t taz6;
|
||||
Tazzzz_Tag taz7_tag;
|
||||
uint32_t taz7;
|
||||
|
||||
cdef enum:
|
||||
@ -142,9 +133,7 @@ cdef extern from *:
|
||||
|
||||
ctypedef union Qux:
|
||||
Qux_Tag tag;
|
||||
Qux_Tag qux1_tag;
|
||||
int32_t qux1;
|
||||
Qux_Tag qux2_tag;
|
||||
uint32_t qux2;
|
||||
|
||||
void root(const Foo_u32 *a,
|
||||
|
@ -81,11 +81,8 @@ cdef extern from *:
|
||||
|
||||
cdef union Baz_i32:
|
||||
Baz_i32_Tag tag;
|
||||
Baz_i32_Tag polygon21_tag;
|
||||
Polygon_i32 polygon21;
|
||||
Baz_i32_Tag slice21_tag;
|
||||
OwnedSlice_i32 slice21;
|
||||
Baz_i32_Tag slice22_tag;
|
||||
OwnedSlice_i32 slice22;
|
||||
Slice23_Body_i32 slice23;
|
||||
Slice24_Body_i32 slice24;
|
||||
@ -98,9 +95,7 @@ cdef extern from *:
|
||||
|
||||
cdef union Taz:
|
||||
Taz_Tag tag;
|
||||
Taz_Tag taz1_tag;
|
||||
int32_t taz1;
|
||||
Taz_Tag taz3_tag;
|
||||
OwnedSlice_i32 taz3;
|
||||
|
||||
cdef enum:
|
||||
@ -110,7 +105,6 @@ cdef extern from *:
|
||||
|
||||
cdef union Tazz:
|
||||
Tazz_Tag tag;
|
||||
Tazz_Tag taz2_tag;
|
||||
int32_t taz2;
|
||||
|
||||
cdef enum:
|
||||
@ -120,7 +114,6 @@ cdef extern from *:
|
||||
|
||||
cdef union Tazzz:
|
||||
Tazzz_Tag tag;
|
||||
Tazzz_Tag taz5_tag;
|
||||
int32_t taz5;
|
||||
|
||||
cdef enum:
|
||||
@ -130,9 +123,7 @@ cdef extern from *:
|
||||
|
||||
cdef union Tazzzz:
|
||||
Tazzzz_Tag tag;
|
||||
Tazzzz_Tag taz6_tag;
|
||||
int32_t taz6;
|
||||
Tazzzz_Tag taz7_tag;
|
||||
uint32_t taz7;
|
||||
|
||||
cdef enum:
|
||||
@ -142,9 +133,7 @@ cdef extern from *:
|
||||
|
||||
cdef union Qux:
|
||||
Qux_Tag tag;
|
||||
Qux_Tag qux1_tag;
|
||||
int32_t qux1;
|
||||
Qux_Tag qux2_tag;
|
||||
uint32_t qux2;
|
||||
|
||||
void root(const Foo_u32 *a,
|
||||
|
@ -95,7 +95,6 @@ cdef extern from *:
|
||||
|
||||
ctypedef union G:
|
||||
G_Tag tag;
|
||||
G_Tag foo_tag;
|
||||
int16_t foo;
|
||||
Bar_Body bar;
|
||||
|
||||
|
@ -95,7 +95,6 @@ cdef extern from *:
|
||||
|
||||
cdef union G:
|
||||
G_Tag tag;
|
||||
G_Tag foo_tag;
|
||||
int16_t foo;
|
||||
Bar_Body bar;
|
||||
|
||||
|
@ -17,9 +17,7 @@ cdef extern from *:
|
||||
|
||||
ctypedef union Bar:
|
||||
Bar_Tag tag;
|
||||
Bar_Tag min_tag;
|
||||
Foo_Bar min;
|
||||
Bar_Tag max_tag;
|
||||
Foo_Bar max;
|
||||
|
||||
void root(Bar b);
|
||||
|
@ -17,9 +17,7 @@ cdef extern from *:
|
||||
|
||||
cdef union Bar:
|
||||
Bar_Tag tag;
|
||||
Bar_Tag min_tag;
|
||||
Foo_Bar min;
|
||||
Bar_Tag max_tag;
|
||||
Foo_Bar max;
|
||||
|
||||
void root(Bar b);
|
||||
|
@ -24,7 +24,6 @@ cdef extern from *:
|
||||
|
||||
ctypedef union PREFIX_AbsoluteFontWeight:
|
||||
PREFIX_AbsoluteFontWeight_Tag tag;
|
||||
PREFIX_AbsoluteFontWeight_Tag weight_tag;
|
||||
float weight;
|
||||
|
||||
void root(PREFIX_NamedLenArray x, PREFIX_ValuedLenArray y, PREFIX_AbsoluteFontWeight z);
|
||||
|
@ -24,7 +24,6 @@ cdef extern from *:
|
||||
|
||||
cdef union PREFIX_AbsoluteFontWeight:
|
||||
PREFIX_AbsoluteFontWeight_Tag tag;
|
||||
PREFIX_AbsoluteFontWeight_Tag weight_tag;
|
||||
float weight;
|
||||
|
||||
void root(PREFIX_NamedLenArray x, PREFIX_ValuedLenArray y, PREFIX_AbsoluteFontWeight z);
|
||||
|
@ -30,9 +30,7 @@ cdef extern from *:
|
||||
ctypedef union StyleFoo_i32:
|
||||
StyleFoo_i32_Tag tag;
|
||||
StyleFoo_Body_i32 foo;
|
||||
StyleFoo_i32_Tag bar_tag;
|
||||
int32_t bar;
|
||||
StyleFoo_i32_Tag baz_tag;
|
||||
StylePoint_i32 baz;
|
||||
|
||||
ctypedef enum StyleBar_i32_Tag:
|
||||
@ -83,9 +81,7 @@ cdef extern from *:
|
||||
|
||||
ctypedef union StyleBaz:
|
||||
StyleBaz_Tag tag;
|
||||
StyleBaz_Tag baz1_tag;
|
||||
StyleBar_u32 baz1;
|
||||
StyleBaz_Tag baz2_tag;
|
||||
StylePoint_i32 baz2;
|
||||
|
||||
cdef enum:
|
||||
|
@ -30,9 +30,7 @@ cdef extern from *:
|
||||
cdef union StyleFoo_i32:
|
||||
StyleFoo_i32_Tag tag;
|
||||
StyleFoo_Body_i32 foo;
|
||||
StyleFoo_i32_Tag bar_tag;
|
||||
int32_t bar;
|
||||
StyleFoo_i32_Tag baz_tag;
|
||||
StylePoint_i32 baz;
|
||||
|
||||
cdef enum StyleBar_i32_Tag:
|
||||
@ -83,9 +81,7 @@ cdef extern from *:
|
||||
|
||||
cdef union StyleBaz:
|
||||
StyleBaz_Tag tag;
|
||||
StyleBaz_Tag baz1_tag;
|
||||
StyleBar_u32 baz1;
|
||||
StyleBaz_Tag baz2_tag;
|
||||
StylePoint_i32 baz2;
|
||||
|
||||
cdef enum:
|
||||
|
Loading…
x
Reference in New Issue
Block a user