Support SAFEARRAY(type) Syntax in MIDL

Dan Hipschman dsh at linux.ucla.edu
Mon Jul 17 18:56:55 CDT 2006


This adds support for the "SAFEARRAY(type)" syntax supported by MIDL.
"SAFEARRAY(foo)" translates to "SAFEARRAY *" in the generated files.
"SAFEARRAY" is still allowed as an identifier.  The special syntax is
used only where the identifier "SAFEARRAY" is followed by a "(".  This
seems to be the way MIDL does it.

ChangeLog:
* Add support for "SAFEARRAY(type)" syntax
---
 tools/widl/header.c    |    1 +
 tools/widl/parser.l    |    1 +
 tools/widl/parser.y    |   11 +++++++++++
 tools/widl/widltypes.h |    1 +
 4 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/tools/widl/header.c b/tools/widl/header.c
index d6b42ef..57109aa 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -204,6 +204,7 @@ void write_type(FILE *h, type_t *t, cons
   int c;
 
   if (n) fprintf(h, "%s", n);
+  else if (t->safearray) fprintf(h, "SAFEARRAY *");
   else {
     if (t->is_const) fprintf(h, "const ");
     if (t->type) {
diff --git a/tools/widl/parser.l b/tools/widl/parser.l
index cefdca9..4fedd34 100644
--- a/tools/widl/parser.l
+++ b/tools/widl/parser.l
@@ -145,6 +145,7 @@ static UUID* parse_uuid(const char*u)
 				yylval.num = strtoul(yytext, NULL, 0);
 				return aNUM;
 			}
+SAFEARRAY{ws}*/\(	return tSAFEARRAY;
 {cident}		return kw_token(yytext);
 \n			line_number++;
 {ws}
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index 7257bd8..1abebd4 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -83,6 +83,7 @@ static ifref_t *make_ifref(type_t *iface
 static var_t *make_var(char *name);
 static func_t *make_func(var_t *def, var_t *args);
 static class_t *make_class(char *name);
+static type_t *make_safearray(void);
 
 static type_t *reg_type(type_t *type, const char *name, int t);
 static type_t *reg_types(type_t *type, var_t *names, int t);
@@ -179,6 +180,7 @@ static type_t std_uhyper = { "MIDL_uhype
 %token tREQUESTEDIT
 %token tRESTRICTED
 %token tRETVAL
+%token tSAFEARRAY
 %token tSHORT
 %token tSIGNED
 %token tSINGLE
@@ -777,6 +779,7 @@ type:	  tVOID					{ $$ = make_tref(NULL,
 	| tSTRUCT aIDENTIFIER			{ $$ = make_tref(NULL, get_type(RPC_FC_STRUCT, $2, tsSTRUCT)); }
 	| uniondef				{ $$ = make_tref(NULL, $1); }
 	| tUNION aIDENTIFIER			{ $$ = make_tref(NULL, find_type2($2, tsUNION)); }
+	| tSAFEARRAY '(' type ')'		{ $$ = make_tref(NULL, make_safearray()); }
 	;
 
 typedef: tTYPEDEF m_attributes type pident_list	{ typeref_t *tref = uniq_tref($3);
@@ -1046,6 +1049,7 @@ static type_t *make_type(unsigned char t
   t->attrs = NULL;
   t->funcs = NULL;
   t->fields = NULL;
+  t->safearray = FALSE;
   t->ignore = parse_only;
   t->is_const = FALSE;
   t->sign = 0;
@@ -1139,6 +1143,13 @@ static class_t *make_class(char *name)
   return c;
 }
 
+static type_t *make_safearray(void)
+{
+  type_t *t = make_type(0, NULL);
+  t->safearray = TRUE;
+  return t;
+}
+
 #define HASHMAX 64
 
 static int hash_ident(const char *name)
diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h
index 508284e..ee73ba6 100644
--- a/tools/widl/widltypes.h
+++ b/tools/widl/widltypes.h
@@ -205,6 +205,7 @@ struct _type_t {
   const attr_t *attrs;
   func_t *funcs;
   var_t *fields;
+  int safearray;
   int ignore, is_const, sign;
   int defined, written, user_types_registered;
   int typelib_idx;



More information about the wine-patches mailing list