don't write out empty structs

"struct { } foo" is not valid ISO C99; while gcc/clang/icc support it,
other compilers and tools don't (e.g. pycparser)
This commit is contained in:
David Lamparter 2016-04-06 14:18:29 -03:00
parent 90c3473406
commit e9df12b387

View file

@ -878,6 +878,18 @@ static void define_group(struct strings *s, struct node *n, const char *group_na
/* named union is where all group members are in the union */ /* named union is where all group members are in the union */
int named_union = (group_name && ulen == flen && ulen > 0); int named_union = (group_name && ulen == flen && ulen > 0);
int named_struct = (group_name && !named_union); int named_struct = (group_name && !named_union);
int empty = 1;
for (f = n->fields; f < n->fields + flen; f++) {
decode_value(&f->v, f->f.slot.type, f->f.slot.defaultValue, NULL);
if (f->v.t.which != Type__void)
empty = 0;
}
if (named_struct && empty) {
str_addf(&s->decl, "%s/* struct { -empty- } %s; */\n", s->dtab.str, group_name);
return;
}
if (named_struct) { if (named_struct) {
str_addf(&s->decl, "%sstruct {\n", s->dtab.str); str_addf(&s->decl, "%sstruct {\n", s->dtab.str);
@ -888,10 +900,6 @@ static void define_group(struct strings *s, struct node *n, const char *group_na
str_addf(&s->var, "%s.", group_name); str_addf(&s->var, "%s.", group_name);
} }
for (f = n->fields; f < n->fields + flen; f++) {
decode_value(&f->v, f->f.slot.type, f->f.slot.defaultValue, NULL);
}
/* fields before the union members */ /* fields before the union members */
for (f = n->fields; f < n->fields + flen && !in_union(f); f++) { for (f = n->fields; f < n->fields + flen && !in_union(f); f++) {
define_field(s, f); define_field(s, f);