Jacek Caban : widl: Use proper macro name for forward declarations of interfaces inside a namespace.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Jul 31 17:25:55 CDT 2015


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Jul 31 13:37:50 2015 +0200

widl: Use proper macro name for forward declarations of interfaces inside a namespace.

---

 tools/widl/header.c    |  4 ++--
 tools/widl/parser.y    |  7 +++++++
 tools/widl/typetree.c  | 31 +++++++++++++++++++++++++++++++
 tools/widl/widltypes.h |  9 +++++++++
 4 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/tools/widl/header.c b/tools/widl/header.c
index bf824d8..a71ad1a 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -1219,8 +1219,8 @@ static void write_function_proto(FILE *header, const type_t *iface, const var_t
 
 static void write_forward(FILE *header, type_t *iface)
 {
-  fprintf(header, "#ifndef __%s_FWD_DEFINED__\n", iface->name);
-  fprintf(header, "#define __%s_FWD_DEFINED__\n", iface->name);
+  fprintf(header, "#ifndef __%s_FWD_DEFINED__\n", iface->c_name);
+  fprintf(header, "#define __%s_FWD_DEFINED__\n", iface->c_name);
   fprintf(header, "typedef interface %s %s;\n", iface->name, iface->name);
   fprintf(header, "#endif\n\n" );
 }
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index f3c250a..b9234a4 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -1971,6 +1971,8 @@ int is_type(const char *name)
 type_t *get_type(enum type_type type, char *name, struct namespace *namespace, int t)
 {
   type_t *tp;
+  if (!namespace)
+    namespace = &global_namespace;
   if (name) {
     tp = find_type(name, namespace, t);
     if (tp) {
@@ -1980,6 +1982,11 @@ type_t *get_type(enum type_type type, char *name, struct namespace *namespace, i
   }
   tp = make_type(type);
   tp->name = name;
+  tp->namespace = namespace;
+  if (is_global_namespace(namespace))
+    tp->c_name = name;
+  else
+    tp->c_name = format_namespace(namespace, "__x_", "_C", name);
   if (!name) return tp;
   return reg_type(tp, name, namespace, t);
 }
diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c
index 6c09806..d27a92a 100644
--- a/tools/widl/typetree.c
+++ b/tools/widl/typetree.c
@@ -45,8 +45,10 @@ type_t *make_type(enum type_type type)
 {
     type_t *t = alloc_type();
     t->name = NULL;
+    t->namespace = NULL;
     t->type_type = type;
     t->attrs = NULL;
+    t->c_name = NULL;
     t->orig = NULL;
     memset(&t->details, 0, sizeof(t->details));
     t->typestring_offset = 0;
@@ -76,6 +78,35 @@ static const var_t *find_arg(const var_list_t *args, const char *name)
     return NULL;
 }
 
+static char *append_namespace(char *ptr, struct namespace *namespace, const char *separator)
+{
+    if(is_global_namespace(namespace))
+        return ptr;
+
+    ptr = append_namespace(ptr, namespace->parent, separator);
+    strcpy(ptr, namespace->name);
+    strcat(ptr, separator);
+    return ptr + strlen(ptr);
+}
+
+char *format_namespace(struct namespace *namespace, const char *prefix, const char *separator, const char *suffix)
+{
+    unsigned len = strlen(prefix) + strlen(suffix);
+    unsigned sep_len = strlen(separator);
+    struct namespace *iter;
+    char *ret, *ptr;
+
+    for(iter = namespace; !is_global_namespace(iter); iter = iter->parent)
+        len += strlen(iter->name) + sep_len;
+
+    ret = xmalloc(len+1);
+    strcpy(ret, prefix);
+    ptr = append_namespace(ret + strlen(ret), namespace, separator);
+    strcpy(ptr, suffix);
+
+    return ret;
+}
+
 type_t *type_new_function(var_list_t *args)
 {
     var_t *arg;
diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h
index 2e89ddb..4d51312 100644
--- a/tools/widl/widltypes.h
+++ b/tools/widl/widltypes.h
@@ -412,6 +412,7 @@ enum type_type
 
 struct _type_t {
   const char *name;
+  struct namespace *namespace;
   enum type_type type_type;
   attr_list_t *attrs;
   union
@@ -427,6 +428,7 @@ struct _type_t {
     struct pointer_details pointer;
     struct bitfield_details bitfield;
   } details;
+  const char *c_name;
   type_t *orig;                   /* dup'd types */
   unsigned int typestring_offset;
   unsigned int ptrdesc;           /* used for complex structs */
@@ -570,6 +572,8 @@ var_list_t *append_var(var_list_t *list, var_t *var);
 
 void init_loc_info(loc_info_t *);
 
+char *format_namespace(struct namespace *namespace, const char *prefix, const char *separator, const char *suffix);
+
 static inline var_list_t *type_get_function_args(const type_t *func_type)
 {
   return func_type->details.function->args;
@@ -599,4 +603,9 @@ static inline int statements_has_func(const statement_list_t *stmts)
   return has_func;
 }
 
+static inline int is_global_namespace(const struct namespace *namespace)
+{
+    return !namespace->name;
+}
+
 #endif




More information about the wine-cvs mailing list