fix sparse enums
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Mon, 2 Apr 2007 20:24:17 +0000 (20:24 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Mon, 2 Apr 2007 20:24:17 +0000 (20:24 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@2463 04897980-b3bd-0310-b5e0-8ef037075253

ltt/branches/poly/ltt/facility.c
ltt/branches/poly/ltt/ltt-private.h
ltt/branches/poly/ltt/type.c

index e6573c9dd616f03518b4791f66c0fecc5a4d2a43..380689b4628e773ea4195c8d2fe122e811702cb8 100644 (file)
@@ -395,10 +395,14 @@ void construct_fields(LttFacility *fac,
       {
         guint i;
         type->enum_map = g_hash_table_new(g_direct_hash, g_direct_equal);
+       type->lowest_value = G_MAXINT32;
+       type->highest_value = G_MININT32;
         for(i=0; i<td->labels.position; i++) {
           GQuark value = g_quark_from_string((char*)td->labels.array[i]);
           gint key = *(int*)td->labels_values.array[i];
           g_hash_table_insert(type->enum_map, (gpointer)key, (gpointer)value);
+         type->highest_value = max(key, type->highest_value);
+         type->lowest_value = min(key, type->lowest_value);
         }
       }
       g_assert(type->size != 0);
index a4801c1ca18d61dc090e2357da9af8d071ba8612..c4684bc6526edf9d3c6c355c25bcc161aaa6253a 100644 (file)
@@ -251,6 +251,8 @@ struct _LttType{
   guint size;
   LttTypeEnum type_class;          //which type
   GHashTable *enum_map;                 //maps enum labels to numbers.
+  gint32 highest_value;                        //For enum
+  gint32 lowest_value;                 //For enum
   GArray *fields;     // Array of LttFields, for array, sequence, union, struct.
   GData *fields_by_name;
   guint network;  // Is the type in network byte order ?
index 1d1481de453653599d2c4fde6fd59f2af66545f3..d396d21a0775b61a3612fad174f0ea85b2397ac7 100644 (file)
@@ -251,7 +251,8 @@ unsigned ltt_type_element_number(LttType *t)
   unsigned ret = 0;
 
   if(likely(t->type_class == LTT_ENUM))
-    ret = g_hash_table_size(t->enum_map);
+    // Permits non full enums ret = g_hash_table_size(t->enum_map);
+    ret = (unsigned)(t->highest_value - t->lowest_value);
 
   return ret;
 }
This page took 0.026794 seconds and 4 git commands to generate.