Commit 76693d52 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

widl: Added support for nameless structs and unions.

parent 935418cb
......@@ -245,26 +245,67 @@ extern "C" {
#define DUMMYUNIONNAME8 u8
#endif /* !defined(NONAMELESSUNION) */
#ifndef __C89_NAMELESS
# if !defined(__WINESRC__) && !defined(WINE_NO_NAMELESS_EXTENSION)
# ifdef __GNUC__
/* Anonymous structs support starts with gcc 2.96/g++ 2.95 */
# if (__GNUC__ > 2) || ((__GNUC__ == 2) && ((__GNUC_MINOR__ > 95) || ((__GNUC_MINOR__ == 95) && defined(__cplusplus))))
# define __C89_NAMELESS __extension__
# endif
# elif defined(_MSC_VER)
# define __C89_NAMELESS
#undef __C89_NAMELESS
#undef __C89_NAMELESSSTRUCTNAME
#undef __C89_NAMELESSSTRUCTNAME1
#undef __C89_NAMELESSSTRUCTNAME2
#undef __C89_NAMELESSSTRUCTNAME3
#undef __C89_NAMELESSSTRUCTNAME4
#undef __C89_NAMELESSSTRUCTNAME5
#undef __C89_NAMELESSUNIONNAME
#undef __C89_NAMELESSUNIONNAME1
#undef __C89_NAMELESSUNIONNAME2
#undef __C89_NAMELESSUNIONNAME3
#undef __C89_NAMELESSUNIONNAME4
#undef __C89_NAMELESSUNIONNAME5
#undef __C89_NAMELESSUNIONNAME6
#undef __C89_NAMELESSUNIONNAME7
#undef __C89_NAMELESSUNIONNAME8
#if !defined(__WINESRC__) && !defined(WINE_NO_NAMELESS_EXTENSION)
# ifdef __GNUC__
/* Anonymous structs support starts with gcc 2.96/g++ 2.95 */
# if (__GNUC__ > 2) || ((__GNUC__ == 2) && ((__GNUC_MINOR__ > 95) || ((__GNUC_MINOR__ == 95) && defined(__cplusplus))))
# define __C89_NAMELESS __extension__
# endif
# elif defined(_MSC_VER)
# define __C89_NAMELESS
# endif
#endif
#ifdef __C89_NAMELESS
# define __C89_NAMELESSSTRUCTNAME
# define __C89_NAMELESSSTRUCTNAME1
# define __C89_NAMELESSSTRUCTNAME2
# define __C89_NAMELESSSTRUCTNAME3
# define __C89_NAMELESSSTRUCTNAME4
# define __C89_NAMELESSSTRUCTNAME5
# define __C89_NAMELESSUNIONNAME
# define __C89_NAMELESSUNIONNAME1
# define __C89_NAMELESSUNIONNAME2
# define __C89_NAMELESSUNIONNAME3
# define __C89_NAMELESSUNIONNAME4
# define __C89_NAMELESSUNIONNAME5
# define __C89_NAMELESSUNIONNAME6
# define __C89_NAMELESSUNIONNAME7
# define __C89_NAMELESSUNIONNAME8
#else
# define __C89_NAMELESS
# define __C89_NAMELESSSTRUCTNAME DUMMYSTRUCTNAME
# define __C89_NAMELESSSTRUCTNAME1 DUMMYSTRUCTNAME1
# define __C89_NAMELESSSTRUCTNAME2 DUMMYSTRUCTNAME2
# define __C89_NAMELESSSTRUCTNAME3 DUMMYSTRUCTNAME3
# define __C89_NAMELESSSTRUCTNAME4 DUMMYSTRUCTNAME4
# define __C89_NAMELESSSTRUCTNAME5 DUMMYSTRUCTNAME5
# define __C89_NAMELESSUNIONNAME DUMMYUNIONNAME
# define __C89_NAMELESSUNIONNAME1 DUMMYUNIONNAME1
# define __C89_NAMELESSUNIONNAME2 DUMMYUNIONNAME2
# define __C89_NAMELESSUNIONNAME3 DUMMYUNIONNAME3
# define __C89_NAMELESSUNIONNAME4 DUMMYUNIONNAME4
# define __C89_NAMELESSUNIONNAME5 DUMMYUNIONNAME5
# define __C89_NAMELESSUNIONNAME6 DUMMYUNIONNAME6
# define __C89_NAMELESSUNIONNAME7 DUMMYUNIONNAME7
# define __C89_NAMELESSUNIONNAME8 DUMMYUNIONNAME8
#endif
/* C99 restrict support */
......
......@@ -167,21 +167,67 @@ const char *get_name(const var_t *v)
return buffer;
}
static void write_field(FILE *h, var_t *v)
{
if (!v) return;
if (v->type) {
indent(h, 0);
write_type_def_or_decl(h, v->type, TRUE, v->name);
fprintf(h, ";\n");
}
}
static void write_fields(FILE *h, var_list_t *fields)
{
unsigned nameless_struct_cnt = 0, nameless_struct_i = 0, nameless_union_cnt = 0, nameless_union_i = 0;
const char *name;
char buf[32];
var_t *v;
if (!fields) return;
LIST_FOR_EACH_ENTRY( v, fields, var_t, entry ) write_field(h, v);
LIST_FOR_EACH_ENTRY( v, fields, var_t, entry ) {
if (!v || !v->type) continue;
switch(type_get_type_detect_alias(v->type)) {
case TYPE_STRUCT:
case TYPE_ENCAPSULATED_UNION:
nameless_struct_cnt++;
break;
case TYPE_UNION:
nameless_union_cnt++;
break;
default:
;
}
}
LIST_FOR_EACH_ENTRY( v, fields, var_t, entry ) {
if (!v || !v->type) continue;
indent(h, 0);
name = v->name;
switch(type_get_type_detect_alias(v->type)) {
case TYPE_STRUCT:
case TYPE_ENCAPSULATED_UNION:
if(!v->name) {
fprintf(h, "__C89_NAMELESS ");
if(nameless_struct_cnt == 1) {
name = "__C89_NAMELESSSTRUCTNAME";
}else if(nameless_struct_i < 5 /* # of supporting macros */) {
sprintf(buf, "__C89_NAMELESSSTRUCTNAME%d", ++nameless_struct_i);
name = buf;
}
}
break;
case TYPE_UNION:
if(!v->name) {
fprintf(h, "__C89_NAMELESS ");
if(nameless_union_cnt == 1) {
name = "__C89_NAMELESSUNIONNAME";
}else if(nameless_union_i < 8 /* # of supporting macros */ ) {
sprintf(buf, "__C89_NAMELESSUNIONNAME%d", ++nameless_union_i);
name = buf;
}
}
break;
default:
;
}
write_type_def_or_decl(h, v->type, TRUE, name);
fprintf(h, ";\n");
}
}
static void write_enums(FILE *h, var_list_t *enums)
......
......@@ -740,6 +740,10 @@ s_field: m_attributes decl_spec declarator { $$ = declare_var(check_field_attrs
$2, $3, FALSE);
free($3);
}
| m_attributes structdef { var_t *v = make_var(NULL);
v->type = $2; v->attrs = $1;
$$ = v;
}
;
funcdef: declaration { $$ = $1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment