Jacek Caban : widl: Added support for nameless structs and unions.
Alexandre Julliard
julliard at winehq.org
Mon May 14 14:26:03 CDT 2012
Module: wine
Branch: master
Commit: 76693d52c7b2d199df9d1f0e6051b2ffa333b8e1
URL: http://source.winehq.org/git/wine.git/?a=commit;h=76693d52c7b2d199df9d1f0e6051b2ffa333b8e1
Author: Jacek Caban <jacek at codeweavers.com>
Date: Sat May 12 16:13:57 2012 +0200
widl: Added support for nameless structs and unions.
---
include/winnt.h | 59 +++++++++++++++++++++++++++++++++++++------
tools/widl/header.c | 68 ++++++++++++++++++++++++++++++++++++++++++--------
tools/widl/parser.y | 4 +++
3 files changed, 111 insertions(+), 20 deletions(-)
diff --git a/include/winnt.h b/include/winnt.h
index ecac448..9bde031 100644
--- a/include/winnt.h
+++ b/include/winnt.h
@@ -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 */
diff --git a/tools/widl/header.c b/tools/widl/header.c
index 06c6f1e..0b2b9d5 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -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)
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index cd947e8..55b2df9 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -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;
More information about the wine-cvs
mailing list