Rob Shearman : widl: Add new type_is_alias and type_get_real_type helper functions.

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


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

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

widl: Add new type_is_alias and type_get_real_type helper functions.

Use type_is_alias to replace cumbersome "type->kind == TKIND_ALIAS" expressions.
Use type_get_real_type to simplify some code.

---

 tools/widl/header.c     |   14 +++++++-------
 tools/widl/parser.y     |   32 ++++++++++++--------------------
 tools/widl/typegen.c    |    4 ++--
 tools/widl/typelib.c    |    3 ++-
 tools/widl/typetree.h   |   13 +++++++++++++
 tools/widl/write_msft.c |    2 +-
 6 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/tools/widl/header.c b/tools/widl/header.c
index 6434512..b64f864 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -62,7 +62,7 @@ int is_ptrchain_attr(const var_t *var, enum attr_type t)
         {
             if (is_attr(type->attrs, t))
                 return 1;
-            else if (type->kind == TKIND_ALIAS)
+            else if (type_is_alias(type))
                 type = type->orig;
             else if (is_ptr(type))
                 type = type->ref;
@@ -78,7 +78,7 @@ int is_aliaschain_attr(const type_t *type, enum attr_type attr)
     {
         if (is_attr(t->attrs, attr))
             return 1;
-        else if (t->kind == TKIND_ALIAS)
+        else if (type_is_alias(t))
             t = t->orig;
         else return 0;
     }
@@ -185,8 +185,8 @@ static void write_enums(FILE *h, var_list_t *enums)
 
 int needs_space_after(type_t *t)
 {
-  return (t->kind == TKIND_ALIAS
-          || (!is_ptr(t) && (!is_conformant_array(t) || t->declarray)));
+  return (type_is_alias(t) ||
+          (!is_ptr(t) && (!is_conformant_array(t) || t->declarray)));
 }
 
 void write_type_left(FILE *h, type_t *t, int declonly)
@@ -194,10 +194,10 @@ void write_type_left(FILE *h, type_t *t, int declonly)
   if (!h) return;
 
   if (is_attr(t->attrs, ATTR_CONST) &&
-      (t->kind == TKIND_ALIAS || t->declarray || !is_ptr(t)))
+      (type_is_alias(t) || t->declarray || !is_ptr(t)))
     fprintf(h, "const ");
 
-  if (t->kind == TKIND_ALIAS) fprintf(h, "%s", t->name);
+  if (type_is_alias(t)) fprintf(h, "%s", t->name);
   else if (t->declarray) write_type_left(h, t->ref, declonly);
   else {
     if (t->sign > 0) fprintf(h, "signed ");
@@ -376,7 +376,7 @@ void check_for_additional_prototype_types(const var_list_t *list)
   LIST_FOR_EACH_ENTRY( v, list, const var_t, entry )
   {
     type_t *type;
-    for (type = v->type; type; type = type->kind == TKIND_ALIAS ? type->orig : type->ref) {
+    for (type = v->type; type; type = type_is_alias(type) ? type->orig : type->ref) {
       const char *name = type->name;
       if (type->user_types_registered) continue;
       type->user_types_registered = 1;
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index 5560dff..e88d093 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -1451,7 +1451,7 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl,
     for (ptr = *pt; ptr && !ptr_attr; )
     {
       ptr_attr = get_attrv(ptr->attrs, ATTR_POINTERTYPE);
-      if (!ptr_attr && ptr->kind == TKIND_ALIAS)
+      if (!ptr_attr && type_is_alias(ptr))
         ptr = ptr->orig;
       else
         break;
@@ -1786,7 +1786,7 @@ static void add_incomplete(type_t *t)
 
 static void fix_type(type_t *t)
 {
-  if (t->kind == TKIND_ALIAS && is_incomplete(t)) {
+  if (type_is_alias(t) && is_incomplete(t)) {
     type_t *ot = t->orig;
     fix_type(ot);
     if (is_struct(ot->type) || is_union(ot->type))
@@ -2284,19 +2284,13 @@ static int is_allowed_conf_type(const type_t *type)
 static int is_ptr_guid_type(const type_t *type)
 {
     unsigned int align = 0;
-    for (;;)
-    {
-        if (type->kind == TKIND_ALIAS)
-            type = type->orig;
-        else if (is_ptr(type))
-        {
-            type = type->ref;
-            break;
-        }
-        else
-            return FALSE;
-    }
-    return (type_memsize(type, &align) == 16);
+
+    /* first, make sure it is a pointer to something */
+    if (!is_ptr(type)) return FALSE;
+
+    /* second, make sure it is a pointer to something of size sizeof(GUID),
+     * i.e. 16 bytes */
+    return (type_memsize(type->ref, &align) == 16);
 }
 
 static void check_conformance_expr_list(const char *attr_name, const var_t *arg, const type_t *container_type, expr_list_t *expr_list)
@@ -2394,7 +2388,7 @@ static void check_field_common(const type_t *container_type,
             is_context_handle = 1;
             break;
         }
-        if (type->kind == TKIND_ALIAS)
+        if (type_is_alias(type))
             type = type->orig;
         else if (is_ptr(type) || is_array(type))
             type = type->ref;
@@ -2415,9 +2409,7 @@ static void check_remoting_fields(const var_t *var, type_t *type)
     const var_t *field;
     const var_list_t *fields = NULL;
 
-    /* find the real type */
-    while (type->kind == TKIND_ALIAS)
-        type = type->orig;
+    type = type_get_real_type(type);
 
     if (type->checked)
         return;
@@ -2456,7 +2448,7 @@ static void check_remoting_args(const var_t *func)
                 break;
             if (is_attr(type->attrs, ATTR_CONTEXTHANDLE))
                 break;
-            if (type->kind == TKIND_ALIAS)
+            if (type_is_alias(type))
                 type = type->orig;
             else if (is_ptr(type))
             {
diff --git a/tools/widl/typegen.c b/tools/widl/typegen.c
index 2ad7807..a38efa2 100644
--- a/tools/widl/typegen.c
+++ b/tools/widl/typegen.c
@@ -467,7 +467,7 @@ static type_t *get_user_type(const type_t *t, const char **pname)
             return ut;
         }
 
-        if (t->kind == TKIND_ALIAS)
+        if (type_is_alias(t))
             t = t->orig;
         else
             return 0;
@@ -1005,7 +1005,7 @@ size_t type_memsize(const type_t *t, unsigned int *align)
 {
     size_t size = 0;
 
-    if (t->kind == TKIND_ALIAS)
+    if (type_is_alias(t))
         size = type_memsize(t->orig, align);
     else if (t->declarray && is_conformant_array(t))
     {
diff --git a/tools/widl/typelib.c b/tools/widl/typelib.c
index 446f9a5..17eaaf0 100644
--- a/tools/widl/typelib.c
+++ b/tools/widl/typelib.c
@@ -45,6 +45,7 @@
 #include "typelib.h"
 #include "widltypes.h"
 #include "typelib_struct.h"
+#include "typetree.h"
 
 static typelib_t *typelib;
 
@@ -173,7 +174,7 @@ unsigned short get_type_vt(type_t *t)
     if (vt) return vt;
   }
 
-  if (t->kind == TKIND_ALIAS && is_attr(t->attrs, ATTR_PUBLIC))
+  if (type_is_alias(t) && is_attr(t->attrs, ATTR_PUBLIC))
     return VT_USERDEFINED;
 
   switch (t->type) {
diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h
index 4e887c5..d4fdf19 100644
--- a/tools/widl/typetree.h
+++ b/tools/widl/typetree.h
@@ -135,4 +135,17 @@ static inline expr_t *type_array_get_variance(const type_t *type)
     return type->details.array.length_is;
 }
 
+static inline type_t *type_get_real_type(const type_t *type)
+{
+    if (type->kind == TKIND_ALIAS)
+        return type_get_real_type(type->orig);
+    else
+        return (type_t *)type;
+}
+
+static inline int type_is_alias(const type_t *type)
+{
+    return (type->kind == TKIND_ALIAS);
+}
+
 #endif /* WIDL_TYPE_TREE_H */
diff --git a/tools/widl/write_msft.c b/tools/widl/write_msft.c
index e153604..85dcb0d 100644
--- a/tools/widl/write_msft.c
+++ b/tools/widl/write_msft.c
@@ -979,7 +979,7 @@ static int encode_type(
         int typeinfo_offset;
 
         /* typedef'd types without public attribute aren't included in the typelib */
-        while (type->typelib_idx < 0 && type->kind == TKIND_ALIAS && !is_attr(type->attrs, ATTR_PUBLIC))
+        while (type->typelib_idx < 0 && type_is_alias(type) && !is_attr(type->attrs, ATTR_PUBLIC))
           type = type->orig;
 
         chat("encode_type: VT_USERDEFINED - type %p name = %s type->type %d idx %d\n", type,




More information about the wine-cvs mailing list