sequence length type
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Thu, 10 Nov 2005 14:20:32 +0000 (14:20 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Thu, 10 Nov 2005 14:20:32 +0000 (14:20 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@1317 04897980-b3bd-0310-b5e0-8ef037075253

genevent-new/README
genevent-new/parser.c
genevent-new/parser.h
genevent-new/test.xml

index ad31d648e4d39986cd3d84184b5c765eca7532bc..951f146cc556c6bad382207aaf45b982abb146bf 100644 (file)
@@ -48,7 +48,7 @@ to the slowest.
        a unsigned int len and const unsigned char *name.
 
        you must use a sequence to declare this efficiently :
-       <sequence lengthtype=<uint>/><char></sequence>
+       <sequence><uint><char></sequence>
                
 3 - The C code presents a \0 terminated string.
        
index ce416ed963ac85dcc7b2ccef0a7be86ff1de0a10..17ebef72373e87de845e524021e659a0b8e6a21e 100644 (file)
@@ -174,7 +174,8 @@ char *allocAndCopy(char *str)
  *
  **************************************************************************/
 
-void getTypeAttributes(parse_file_t *in, type_descriptor_t *t)
+void getTypeAttributes(parse_file_t *in, type_descriptor_t *t,
+                          sequence_t * unnamed_types, table_t * named_types) 
 {
   char * token;
 
@@ -198,7 +199,7 @@ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t)
      // if(car == EOF) in->error(in,"name was expected");
      // else if(car == '\"') t->type_name = allocAndCopy(getQuotedString(in));
      // else t->type_name = allocAndCopy(getName(in));
-    } else if(!strcmp("size",token) || !strcmp("lengthsize", token)) {
+    } else if(!strcmp("size",token)) {
       getEqual(in);
       t->size = getSize(in);
     } else if(!strcmp("align",token)) {
@@ -601,7 +602,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
 
   if(strcmp(token,"struct") == 0) {
     t->type = STRUCT;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getRAnglebracket(in); //<struct>
     getLAnglebracket(in); //<field name=..>
     token = getToken(in);
@@ -624,7 +625,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
   }
   else if(strcmp(token,"union") == 0) {
     t->type = UNION;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getRAnglebracket(in); //<union>
 
     getLAnglebracket(in); //<field name=..>
@@ -647,7 +648,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
   }
   else if(strcmp(token,"array") == 0) {
     t->type = ARRAY;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     if(t->size == 0) in->error(in, "Array has empty size");
     getForwardslash(in);
     getRAnglebracket(in); //<array size=n>
@@ -663,14 +664,33 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
   }
   else if(strcmp(token,"sequence") == 0) {
     t->type = SEQUENCE;
-    getTypeAttributes(in, t);
-    if(t->size == 0) in->error(in, "Sequence has empty lengthsize");
-    getForwardslash(in);
-    getRAnglebracket(in); //<sequence lengthsize=isize>
+    //getTypeAttributes(in, t, unnamed_types, named_types);
+    //getForwardslash(in);
+    getRAnglebracket(in); //<sequence>
 
-    getLAnglebracket(in); //<type struct
-    t->nested_type = parseType(in,NULL, unnamed_types, named_types);
+    getLAnglebracket(in); //<type sequence
+    t->length_type = parseType(in, NULL, unnamed_types, named_types);
 
+    getLAnglebracket(in); //<type sequence> 
+
+    t->nested_type = parseType(in, NULL, unnamed_types, named_types);
+
+    if(t->length_type == NULL) in->error(in, "Sequence has no length type");
+               switch(t->length_type->type) {
+                       case UINT_FIXED :
+                       case UCHAR :
+                       case USHORT :
+                       case UINT :
+                       case ULONG :
+                       case SIZE_T :
+                       case OFF_T :
+                               break;
+                       default:
+                               in->error(in, "Wrong length type for sequence");
+               }
+
+               
+    if(t->nested_type == NULL) in->error(in, "Sequence has no nested type");
     getLAnglebracket(in); //</sequence>
     getForwardslash(in);
     token = getName(in);
@@ -683,7 +703,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
     sequence_init(&(t->labels));
     sequence_init(&(t->labels_description));
                t->already_printed = 0;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     //if(t->size == 0) in->error(in, "Sequence has empty size");
                //Mathieu : we fix enum size to 4 bytes. GCC is always like this.
                //fox copy optimisation.
@@ -725,100 +745,100 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType,
   }
   else if(strcmp(token,"int_fixed") == 0) {
     t->type = INT_FIXED;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     if(t->size == 0) in->error(in, "int has empty size");
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"uint_fixed") == 0) {
     t->type = UINT_FIXED;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     if(t->size == 0) in->error(in, "uint has empty size");
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"char") == 0) {
     t->type = CHAR;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"uchar") == 0) {
     t->type = UCHAR;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"short") == 0) {
     t->type = SHORT;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"ushort") == 0) {
     t->type = USHORT;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"int") == 0) {
     t->type = INT;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"uint") == 0) {
     t->type = UINT;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
 
   else if(strcmp(token,"pointer") == 0) {
     t->type = POINTER;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"long") == 0) {
     t->type = LONG;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"ulong") == 0) {
     t->type = ULONG;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"size_t") == 0) {
     t->type = SIZE_T;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"ssize_t") == 0) {
     t->type = SSIZE_T;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"off_t") == 0) {
     t->type = OFF_T;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"float") == 0) {
     t->type = FLOAT;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
   else if(strcmp(token,"string") == 0) {
     t->type = STRING;
-    getTypeAttributes(in, t);
+    getTypeAttributes(in, t, unnamed_types, named_types);
     getForwardslash(in);
     getRAnglebracket(in); 
   }
index e19dc93d528ddbaf267fa5af4974710ee28c8c37..588790989895417e8e483487873a983a24dc4342 100644 (file)
@@ -113,6 +113,7 @@ typedef struct _type_descriptor {
        int     already_printed;
   sequence_t fields; // for structure
   struct _type_descriptor *nested_type; // for array and sequence 
+       struct _type_descriptor *length_type; // for sequence
   int alignment;
 } type_descriptor_t;
 
index 34ca9b097e544e5d763e836194485129ef661587..6a328bdd1057610c94601e2d8b138acb62e2b418 100644 (file)
                        </array>
                        </field>
                        <field name="mysequence">
-                       <sequence lengthsize=1/>
-                       <float size=8/>
+                       <sequence>
+                               <uint>
+                               <float size=8/>
                        </sequence>
                        </field>
                        <field name="myunion">
This page took 0.028177 seconds and 4 git commands to generate.