[1/2] widl: Fix enum entries output based on previous entry value

Nikolay Sivov nsivov at codeweavers.com
Fri Nov 23 02:33:55 CST 2012


Apparently this is how midl works
-------------- next part --------------
>From 4c706efb2fe75ee1d59f1d5033048019caaaca9c Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov at codeweavers.com>
Date: Fri, 23 Nov 2012 10:20:00 -0500
Subject: [PATCH 1/2] Fix enum entries output based on previous entry value

---
 tools/widl/header.c    |    8 +++++++-
 tools/widl/parser.y    |    2 ++
 tools/widl/widltypes.h |    1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/widl/header.c b/tools/widl/header.c
index 2f275c7..40756ae 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -241,7 +241,13 @@ static void write_enums(FILE *h, var_list_t *enums)
       fprintf(h, "%s", get_name(v));
       if (v->eval) {
         fprintf(h, " = ");
-        write_expr(h, v->eval, 0, 1, NULL, NULL, "");
+        if (v->derived)
+        {
+            var_t *prev = LIST_ENTRY( list_prev( enums, &v->entry ), var_t, entry );
+            fprintf(h, "%s + 1", get_name(prev));
+        }
+        else
+            write_expr(h, v->eval, 0, 1, NULL, NULL, "");
       }
     }
     if (list_next( enums, &v->entry )) fprintf(h, ",\n");
diff --git a/tools/widl/parser.y b/tools/widl/parser.y
index 616a538..c1bfcd2 100644
--- a/tools/widl/parser.y
+++ b/tools/widl/parser.y
@@ -621,6 +621,7 @@ enum_list: enum					{ if (!$1->eval)
                                                   {
                                                     var_t *last = LIST_ENTRY( list_tail($$), var_t, entry );
                                                     $3->eval = make_exprl(EXPR_NUM, last->eval->cval + 1);
+                                                    $3->derived = 1;
                                                   }
                                                   $$ = append_var( $1, $3 );
 						}
@@ -1696,6 +1697,7 @@ var_t *make_var(char *name)
   v->attrs = NULL;
   v->eval = NULL;
   v->stgclass = STG_NONE;
+  v->derived = 0;
   init_loc_info(&v->loc_info);
   return v;
 }
diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h
index 84e4467..f08ff17 100644
--- a/tools/widl/widltypes.h
+++ b/tools/widl/widltypes.h
@@ -435,6 +435,7 @@ struct _var_t {
   attr_list_t *attrs;
   expr_t *eval;
   enum storage_class stgclass;
+  unsigned int derived : 1; /* used for enum entries only, means entry value wasn't explicitely specified */
   unsigned int procstring_offset;
   unsigned int typestring_offset;
 
-- 
1.7.10.4




More information about the wine-patches mailing list