C mapping of enums...



Hi all,
	ORBit doesn't generate the correct code for enums.

	I know it wasn't an oversight because of the comment in
orbit-idl-c-headers.c - but a spec is a spec, and there doesn't
seem to be a valid reason for not going by the spec ?

	Below is a patch to fix it (also applies cleanly to ORBit2)

Cheers,
Mark

diff -ur ORBit-0.5.3.old/src/orbit-idl-compiler/backends/c/orbit-idl-c-headers.c ORBit-0.5.3/src/orbit-idl-compiler/backends/c/orbit-idl-c-headers.c
--- ORBit-0.5.3.old/src/orbit-idl-compiler/backends/c/orbit-idl-c-headers.c     Tue Feb  6 20:43:10 2001
+++ ORBit-0.5.3/src/orbit-idl-compiler/backends/c/orbit-idl-c-headers.c Tue Feb  6 20:42:00 2001
@@ -165,30 +165,22 @@
 {
   IDL_tree curitem;
   char *id, *enumid;
-
-  /* CORBA spec says to do
-          typedef unsigned int enum_name;
-     and then #defines for each enumerator.
-     This works just as well and seems cleaner.
-  */
+  guint32 val;

   enumid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_ENUM(tree).ident), "_", 0);
   fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", enumid, enumid);
-  fprintf(ci->fh, "typedef enum {\n");
+  fprintf(ci->fh, "typedef CORBA_unsigned_long %s;\n", enumid);

-  for(curitem = IDL_TYPE_ENUM(tree).enumerator_list;
+  for(curitem = IDL_TYPE_ENUM(tree).enumerator_list, val=0;
       curitem;
-      curitem = IDL_LIST(curitem).next) {
+      curitem = IDL_LIST(curitem).next, val++) {
     id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_LIST(curitem).data), "_", 0);

-    fprintf(ci->fh, "  %s%s\n",
-           id,
-           IDL_LIST(curitem).next?",":"");
+    fprintf(ci->fh, "#define %s %d\n",
+            id, val );

     g_free(id);
   }
-
-  fprintf(ci->fh, "} %s;\n", enumid);

   ch_type_alloc_and_tc(tree, ci, FALSE);






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]