widl [5/6]: Add an is_ptr function

Dan Hipschman dsh at linux.ucla.edu
Mon Aug 28 20:32:55 CDT 2006


This patch adds a function to determine whether a type is a pointer or not
and uses it in a few places.  It will be used more in my next patch.

ChangeLog:
* Add is_ptr function and use it.
---
 tools/widl/client.c    |    2 +-
 tools/widl/parser.y    |    2 +-
 tools/widl/proxy.c     |   20 +++-----------------
 tools/widl/typelib.c   |   11 +++++++++++
 tools/widl/widltypes.h |    3 ++-
 5 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/tools/widl/client.c b/tools/widl/client.c
index 64cf8c5..a0b0f25 100644
--- a/tools/widl/client.c
+++ b/tools/widl/client.c
@@ -91,7 +91,7 @@ static void check_pointers(const func_t 
     while (NEXT_LINK(var)) var = NEXT_LINK(var);
     while (var)
     {
-        if (is_pointer(var) && cant_be_null(var))
+        if (is_var_ptr(var) && cant_be_null(var))
         {
             print_client("if (!%s)\n", var->name);
             print_client("{\n");
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index 3213577..daa45f7 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -1342,7 +1342,7 @@ static type_t *reg_typedefs(type_t *type
       }
       cur = alias(cur, names->name);
       cur->attrs = attrs;
-      if (cur->ref)
+      if (is_ptr(cur))
         cur->type = get_pointer_type(cur);
       reg_type(cur, cur->name, 0);
     }
diff --git a/tools/widl/proxy.c b/tools/widl/proxy.c
index 2c4fa10..cb2b2a9 100644
--- a/tools/widl/proxy.c
+++ b/tools/widl/proxy.c
@@ -128,23 +128,9 @@ static void clear_output_vars( var_t *ar
   }
 }
 
-int is_pointer(var_t *arg)
+int is_var_ptr(var_t *v)
 {
-  if (arg->ptr_level)
-    return 1;
-
-  switch (ref_type(arg->type))
-  {
-  case RPC_FC_RP:
-  case RPC_FC_C_CSTRING:
-  case RPC_FC_C_WSTRING:
-  case RPC_FC_FP:
-  case RPC_FC_OP:
-  case RPC_FC_UP:
-    return 1;
-  }
-
-  return 0;
+  return v->ptr_level || is_ptr(v->type);
 }
 
 int cant_be_null(var_t *v)
@@ -213,7 +199,7 @@ static void proxy_check_pointers( var_t 
 {
   END_OF_LIST(arg);
   while (arg) {
-    if (is_pointer(arg) && cant_be_null(arg)) {
+    if (is_var_ptr(arg) && cant_be_null(arg)) {
         print_proxy( "if(!%s)\n", arg->name );
         indent++;
         print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
diff --git a/tools/widl/typelib.c b/tools/widl/typelib.c
index b91ca28..adf9870 100644
--- a/tools/widl/typelib.c
+++ b/tools/widl/typelib.c
@@ -73,6 +73,17 @@ type_t *alias(type_t *t, const char *nam
   return a;
 }
 
+int is_ptr(type_t *t)
+{
+  unsigned char c = t->type;
+  return c == RPC_FC_RP
+      || c == RPC_FC_UP
+      || c == RPC_FC_FP
+      || c == RPC_FC_OP
+      || c == RPC_FC_C_CSTRING
+      || c == RPC_FC_C_WSTRING;
+}
+
 /* List of oleauto types that should be recognized by name.
  * (most of) these seem to be intrinsic types in mktyplib. */
 
diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h
index 1c919ce..54c67e2 100644
--- a/tools/widl/widltypes.h
+++ b/tools/widl/widltypes.h
@@ -297,7 +297,8 @@ type_t *alias(type_t *t, const char *nam
 
 /* Get the actual type field for a type (chase down typedef references).  */
 unsigned char ref_type(const type_t *type);
-int is_pointer(var_t *v);
+int is_ptr(type_t *t);
+int is_var_ptr(var_t *v);
 int cant_be_null(var_t *v);
 
 #endif



More information about the wine-patches mailing list