OSDN Git Service

* godump.c (go_output_typedef): Put enum constants in the macro
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 20 May 2011 16:21:48 +0000 (16:21 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 20 May 2011 16:21:48 +0000 (16:21 +0000)
hash table to avoid duplicate Go const definitions.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@173962 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/godump.c

index 7f8c21a..ea38f8e 100644 (file)
@@ -1,3 +1,8 @@
+2011-05-20  Ian Lance Taylor  <iant@google.com>
+
+       * godump.c (go_output_typedef): Put enum constants in the macro
+       hash table to avoid duplicate Go const definitions.
+
 2011-05-20  Joseph Myers  <joseph@codesourcery.com>
 
        * Makefile.in (LIBDEPS): Add libcommon.a.
index 16a4803..4f83777 100644 (file)
@@ -844,9 +844,24 @@ go_output_typedef (struct godump_container *container, tree decl)
       for (element = TYPE_VALUES (TREE_TYPE (decl));
           element != NULL_TREE;
           element = TREE_CHAIN (element))
-       fprintf (go_dump_file, "const _%s = " HOST_WIDE_INT_PRINT_DEC "\n",
-                IDENTIFIER_POINTER (TREE_PURPOSE (element)),
-                tree_low_cst (TREE_VALUE (element), 0));
+       {
+         const char *name;
+         void **slot;
+
+         name = IDENTIFIER_POINTER (TREE_PURPOSE (element));
+
+         /* Sometimes a name will be defined as both an enum constant
+            and a macro.  Avoid duplicate definition errors by
+            treating enum constants as macros.  */
+         slot = htab_find_slot (macro_hash, name, INSERT);
+         if (*slot == NULL)
+           {
+             *slot = CONST_CAST (char *, name);
+             fprintf (go_dump_file,
+                      "const _%s = " HOST_WIDE_INT_PRINT_DEC "\n",
+                      name, tree_low_cst (TREE_VALUE (element), 0));
+           }
+       }
       pointer_set_insert (container->decls_seen, TREE_TYPE (decl));
       if (TYPE_CANONICAL (TREE_TYPE (decl)) != NULL_TREE)
        pointer_set_insert (container->decls_seen,