Rob Shearman : widl: Add a new function, type_iface_get_inherit.

Alexandre Julliard julliard at winehq.org
Tue Jan 6 08:23:17 CST 2009


Module: wine
Branch: master
Commit: 8fc59d0ead57d32a6e10146464d9fee3688a4663
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=8fc59d0ead57d32a6e10146464d9fee3688a4663

Author: Rob Shearman <robertshearman at gmail.com>
Date:   Mon Jan  5 23:35:06 2009 +0000

widl: Add a new function, type_iface_get_inherit.

Use it for retrieving the parent interface for interfaces.

---

 tools/widl/header.c     |   17 ++++++++++-------
 tools/widl/proxy.c      |   28 +++++++++++++++++++---------
 tools/widl/typetree.c   |    4 ++--
 tools/widl/typetree.h   |    6 ++++++
 tools/widl/write_msft.c |   21 +++++++++++++--------
 5 files changed, 50 insertions(+), 26 deletions(-)

diff --git a/tools/widl/header.c b/tools/widl/header.c
index 7c784fa..0d24a18 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -628,7 +628,8 @@ static void write_method_macro(FILE *header, const type_t *iface, const char *na
   const statement_t *stmt;
   int first_iface = 1;
 
-  if (iface->ref) write_method_macro(header, iface->ref, name);
+  if (type_iface_get_inherit(iface))
+    write_method_macro(header, type_iface_get_inherit(iface), name);
 
   STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts)
   {
@@ -713,7 +714,8 @@ static void do_write_c_method_def(FILE *header, const type_t *iface, const char
   const statement_t *stmt;
   int first_iface = 1;
 
-  if (iface->ref) do_write_c_method_def(header, iface->ref, name);
+  if (type_iface_get_inherit(iface))
+    do_write_c_method_def(header, type_iface_get_inherit(iface), name);
 
   STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts)
   {
@@ -743,7 +745,7 @@ static void write_c_method_def(FILE *header, const type_t *iface)
 
 static void write_c_disp_method_def(FILE *header, const type_t *iface)
 {
-  do_write_c_method_def(header, iface->ref, iface->name);
+  do_write_c_method_def(header, type_iface_get_inherit(iface), iface->name);
 }
 
 static void write_method_proto(FILE *header, const type_t *iface)
@@ -924,9 +926,10 @@ static void write_com_interface_end(FILE *header, type_t *iface)
     write_iface_guid(header, iface);
   /* C++ interface */
   fprintf(header, "#if defined(__cplusplus) && !defined(CINTERFACE)\n");
-  if (iface->ref)
+  if (type_iface_get_inherit(iface))
   {
-    fprintf(header, "interface %s : public %s\n", iface->name, iface->ref->name);
+    fprintf(header, "interface %s : public %s\n", iface->name,
+            type_iface_get_inherit(iface)->name);
     fprintf(header, "{\n");
   }
   else
@@ -944,7 +947,7 @@ static void write_com_interface_end(FILE *header, type_t *iface)
     write_cpp_method_def(header, iface);
     indentation--;
   }
-  if (!iface->ref)
+  if (!type_iface_get_inherit(iface))
     fprintf(header, "    END_INTERFACE\n");
   fprintf(header, "};\n");
   fprintf(header, "#else\n");
@@ -967,7 +970,7 @@ static void write_com_interface_end(FILE *header, type_t *iface)
   fprintf(header, "#ifdef COBJMACROS\n");
   /* dispinterfaces don't have real functions, so don't write macros for them,
    * only for the interface this interface inherits from, i.e. IDispatch */
-  write_method_macro(header, dispinterface ? iface->ref : iface, iface->name);
+  write_method_macro(header, dispinterface ? type_iface_get_inherit(iface) : iface, iface->name);
   fprintf(header, "#endif\n");
   fprintf(header, "\n");
   fprintf(header, "#endif\n");
diff --git a/tools/widl/proxy.c b/tools/widl/proxy.c
index 39f4c2c..0d96ae9 100644
--- a/tools/widl/proxy.c
+++ b/tools/widl/proxy.c
@@ -194,17 +194,19 @@ int cant_be_null(const var_t *v)
 
 static int need_delegation(const type_t *iface)
 {
-    return iface->ref && iface->ref->ref && iface->ref->ignore;
+    return type_iface_get_inherit(iface) &&
+           type_iface_get_inherit(type_iface_get_inherit(iface)) &&
+           type_iface_get_inherit(iface)->ignore;
 }
 
 static int get_delegation_indirect(const type_t *iface, const type_t ** delegate_to)
 {
   const type_t * cur_iface;
-  for (cur_iface = iface; cur_iface != NULL; cur_iface = cur_iface->ref)
+  for (cur_iface = iface; cur_iface != NULL; cur_iface = type_iface_get_inherit(cur_iface))
     if (need_delegation(cur_iface))
     {
       if(delegate_to)
-        *delegate_to = cur_iface->ref;
+        *delegate_to = type_iface_get_inherit(cur_iface);
       return 1;
     }
   return 0;
@@ -530,7 +532,9 @@ static int count_methods(type_t *iface)
     const statement_t *stmt;
     int count = 0;
 
-    if (iface->ref) count = count_methods(iface->ref);
+    if (type_iface_get_inherit(iface))
+        count = count_methods(type_iface_get_inherit(iface));
+
     STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) {
         const var_t *func = stmt->u.var;
         if (!is_callas(func->attrs)) count++;
@@ -543,7 +547,9 @@ static int write_proxy_methods(type_t *iface, int skip)
   const statement_t *stmt;
   int i = 0;
 
-  if (iface->ref) i = write_proxy_methods(iface->ref, need_delegation(iface));
+  if (type_iface_get_inherit(iface))
+    i = write_proxy_methods(type_iface_get_inherit(iface),
+                            need_delegation(iface));
   STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) {
     const var_t *func = stmt->u.var;
     if (!is_callas(func->attrs)) {
@@ -561,8 +567,10 @@ static int write_stub_methods(type_t *iface, int skip)
   const statement_t *stmt;
   int i = 0;
 
-  if (iface->ref) i = write_stub_methods(iface->ref, need_delegation(iface));
-  else return i; /* skip IUnknown */
+  if (type_iface_get_inherit(iface))
+    i = write_stub_methods(type_iface_get_inherit(iface), need_delegation(iface));
+  else
+    return i; /* skip IUnknown */
 
   STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) {
     const var_t *func = stmt->u.var;
@@ -619,7 +627,9 @@ static void write_proxy(type_t *iface, unsigned int *proc_offset)
   /* interface didn't have any methods - search in inherited interfaces */
   if (midx == -1) {
     const type_t *inherit_iface;
-    for (inherit_iface = iface->ref; inherit_iface; inherit_iface = inherit_iface->ref) {
+    for (inherit_iface = type_iface_get_inherit(iface);
+         inherit_iface;
+         inherit_iface = type_iface_get_inherit(inherit_iface)) {
       STATEMENTS_FOR_EACH_FUNC(stmt, inherit_iface->details.iface->stmts) {
         const var_t *func = stmt->u.var;
         int idx = func->type->details.function->idx;
@@ -759,7 +769,7 @@ static void build_iface_list( const statement_list_t *stmts, type_t **ifaces[],
         else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
         {
             type_t *iface = stmt->u.type;
-            if (iface->ref && need_proxy(iface))
+            if (type_iface_get_inherit(iface) && need_proxy(iface))
             {
                 *ifaces = xrealloc( *ifaces, (*count + 1) * sizeof(*ifaces) );
                 (*ifaces)[(*count)++] = iface;
diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c
index 83650ee..75f494a 100644
--- a/tools/widl/typetree.c
+++ b/tools/widl/typetree.c
@@ -86,8 +86,8 @@ static int compute_method_indexes(type_t *iface)
     if (!iface->details.iface)
         return 0;
 
-    if (iface->ref)
-        idx = compute_method_indexes(iface->ref);
+    if (type_iface_get_inherit(iface))
+        idx = compute_method_indexes(type_iface_get_inherit(iface));
     else
         idx = 0;
 
diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h
index 200d17d..de4dc4b 100644
--- a/tools/widl/typetree.h
+++ b/tools/widl/typetree.h
@@ -80,6 +80,12 @@ static inline var_list_t *type_union_get_cases(const type_t *type)
         return type->details.structure->fields;
 }
 
+static inline type_t *type_iface_get_inherit(const type_t *type)
+{
+    assert(type->type == RPC_FC_IP);
+    return type->ref;
+}
+
 static inline var_list_t *type_dispiface_get_props(const type_t *type)
 {
     assert(type->type == RPC_FC_IP);
diff --git a/tools/widl/write_msft.c b/tools/widl/write_msft.c
index 380710a..4e63769 100644
--- a/tools/widl/write_msft.c
+++ b/tools/widl/write_msft.c
@@ -1995,6 +1995,7 @@ static void add_interface_typeinfo(msft_typelib_t *typelib, type_t *interface)
     msft_typeinfo_t *msft_typeinfo;
     importinfo_t *ref_importinfo = NULL;
     int num_parents = 0, num_funcs = 0;
+    type_t *inherit;
     const type_t *derived;
 
     if (-1 < interface->typelib_idx)
@@ -2006,11 +2007,14 @@ static void add_interface_typeinfo(msft_typelib_t *typelib, type_t *interface)
     /* midl adds the parent interface first, unless the parent itself
        has no parent (i.e. it stops before IUnknown). */
 
-    if(interface->ref) {
-        ref_importinfo = find_importinfo(typelib, interface->ref->name);
+    inherit = type_iface_get_inherit(interface);
 
-        if(!ref_importinfo && interface->ref->ref && interface->ref->typelib_idx == -1)
-            add_interface_typeinfo(typelib, interface->ref);
+    if(inherit) {
+        ref_importinfo = find_importinfo(typelib, inherit->name);
+
+        if(!ref_importinfo && type_iface_get_inherit(inherit) &&
+           inherit->typelib_idx == -1)
+            add_interface_typeinfo(typelib, inherit);
     }
 
     interface->typelib_idx = typelib->typelib_header.nrtypeinfos;
@@ -2018,7 +2022,7 @@ static void add_interface_typeinfo(msft_typelib_t *typelib, type_t *interface)
     msft_typeinfo->typeinfo->size = 4;
     msft_typeinfo->typeinfo->typekind |= 0x2200;
 
-    for (derived = interface->ref; derived; derived = derived->ref)
+    for (derived = inherit; derived; derived = type_iface_get_inherit(derived))
         if (derived->name && !strcmp(derived->name, "IDispatch"))
             msft_typeinfo->typeinfo->flags |= 0x1000; /* TYPEFLAG_FDISPATCHABLE */
 
@@ -2026,11 +2030,12 @@ static void add_interface_typeinfo(msft_typelib_t *typelib, type_t *interface)
     if (!(msft_typeinfo->typeinfo->flags & 0x1000)) /* TYPEFLAG_FDISPATCHABLE */
         msft_typeinfo->typeinfo->flags &= ~0x40; /* TYPEFLAG_FDUAL */
 
-    if(interface->ref)
-        add_impl_type(msft_typeinfo, interface->ref, ref_importinfo);
+    if(type_iface_get_inherit(interface))
+        add_impl_type(msft_typeinfo, type_iface_get_inherit(interface),
+                      ref_importinfo);
 
     /* count the number of inherited interfaces and non-local functions */
-    for(ref = interface->ref; ref; ref = ref->ref) {
+    for(ref = inherit; ref; ref = type_iface_get_inherit(ref)) {
         num_parents++;
         STATEMENTS_FOR_EACH_FUNC( stmt_func, ref->details.iface->stmts ) {
             var_t *func = stmt_func->u.var;




More information about the wine-cvs mailing list