Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ONGOING work on exceptions plus minor cleanups.
[simgrid.git] / src / gras / DataDesc / ddt_parse.c
index e4a8bf9..b2a42e7 100644 (file)
@@ -1,15 +1,17 @@
 /* $Id$ */
 
-/* DataDesc/ddt_parse.c -- automatic parsing of data structures */
+/* DataDesc/ddt_parse.c -- automatic parsing of data structures             */
 
-/* Authors: Arnaud Legrand, Martin Quinson            */
-/* Copyright (C) 2003, 2004 Martin Quinson.                                 */
+/* Copyright (c) 2003 Arnaud Legrand.                                       */
+/* Copyright (c) 2003, 2004 Martin Quinson.                                 */
+/* All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  under the terms of the license (GNU LGPL) which comes with this package. */
* under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <ctype.h> /* isdigit */
 
+#include "xbt/ex.h"
 #include "gras/DataDesc/datadesc_private.h"
 #include "gras/DataDesc/ddt_parse.yy.h"
 
@@ -88,6 +90,7 @@ static void parse_type_modifier(type_modifier_t type_modifier)  {
   XBT_OUT;
 }
 
+static void print_type_modifier(s_type_modifier_t tm) __attribute__((unused));
 static void print_type_modifier(s_type_modifier_t tm) {
   int i;
 
@@ -110,11 +113,16 @@ static void change_to_fixed_array(xbt_dynar_t dynar, long int size) {
 
   XBT_IN;
   xbt_dynar_pop(dynar,&former);
-  array.type_name=(char*)xbt_malloc(strlen(former.type->name)+20);
+  array.type_name=(char*)xbt_malloc(strlen(former.type->name)+48);
   DEBUG2("Array specification (size=%ld, elm='%s'), change pushed type",
         size,former.type_name);
-  sprintf(array.type_name,"%s[%ld]",former.type_name,size);
-  xbt_free(former.type_name);
+  sprintf(array.type_name,"%s%s%s%s[%ld]",
+         (former.tm.is_unsigned?"u ":""),
+         (former.tm.is_short?"s ":""),
+         (former.tm.is_long?"l ":""),
+         former.type_name,
+         size);
+  free(former.type_name);
 
   array.type = gras_datadesc_array_fixed(array.type_name, former.type, size); /* redeclaration are ignored */
   array.name = former.name;
@@ -131,7 +139,7 @@ static void change_to_ref(xbt_dynar_t dynar) {
   ref.type_name=(char*)xbt_malloc(strlen(former.type->name)+2);
   DEBUG1("Ref specification (elm='%s'), change pushed type", former.type_name);
   sprintf(ref.type_name,"%s*",former.type_name);
-  xbt_free(former.type_name);
+  free(former.type_name);
 
   ref.type = gras_datadesc_ref(ref.type_name, former.type); /* redeclaration are ignored */
   ref.name = former.name;
@@ -150,7 +158,7 @@ static void change_to_ref_pop_array(xbt_dynar_t dynar) {
   ref.type_name = (char*)strdup(ref.type->name);
   ref.name = former.name;
 
-  xbt_free(former.type_name);
+  free(former.type_name);
 
   xbt_dynar_push(dynar,&ref);
   XBT_OUT;
@@ -159,7 +167,6 @@ static void change_to_ref_pop_array(xbt_dynar_t dynar) {
 static xbt_error_t parse_statement(char         *definition,
                                    xbt_dynar_t  identifiers,
                                    xbt_dynar_t  fields_to_push) {
-  xbt_error_t errcode;
   char buffname[512];
 
   s_identifier_t identifier;
@@ -172,7 +179,7 @@ static xbt_error_t parse_statement(char      *definition,
   gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump();
   if(gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_RA) {
     XBT_OUT;
-    return mismatch_error; /* end of the englobing structure or union */
+    return old_mismatch_error; /* end of the englobing structure or union */
   }
   
   if (XBT_LOG_ISENABLED(ddt_parse,xbt_log_priority_debug)) {
@@ -247,7 +254,7 @@ static xbt_error_t parse_statement(char      *definition,
       identifier.type = gras_datadesc_by_name("unsigned char");
 
     } else { /* impossible, gcc parses this shit before us */
-      RAISE_IMPOSSIBLE;
+      THROW_IMPOSSIBLE;
     }
     
   } else if (!strcmp(identifier.type_name, "float")) {
@@ -365,14 +372,14 @@ static xbt_error_t parse_statement(char    *definition,
 
        DEBUG2("Anotation: %s=%s",keyname,keyval);
        if (!strcmp(keyname,"size")) {
-         xbt_free(keyname);
+         free(keyname);
          if (!identifier.tm.is_ref)
            PARSE_ERROR0("Size annotation for a field not being a reference");
          identifier.tm.is_ref--;
 
          if (!strcmp(keyval,"1")) {
            change_to_ref(identifiers);
-           xbt_free(keyval);
+           free(keyval);
            continue;
          } else {
            char *p;
@@ -383,7 +390,7 @@ static xbt_error_t parse_statement(char      *definition,
            if (fixed) {
              change_to_fixed_array(identifiers,atoi(keyval));
              change_to_ref(identifiers);
-             xbt_free(keyval);
+             free(keyval);
              continue;
 
            } else {
@@ -392,7 +399,7 @@ static xbt_error_t parse_statement(char      *definition,
              continue;
            }
          }
-         RAISE_IMPOSSIBLE;
+         THROW_IMPOSSIBLE;
 
        } else {
          PARSE_ERROR1("Unknown annotation type: '%s'",keyname);
@@ -479,8 +486,8 @@ static gras_datadesc_type_t parse_struct(char *definition) {
 
       VERB2("Append field '%s' to %p",field.name, (void*)struct_type);      
       gras_datadesc_struct_append(struct_type, field.name, field.type);
-      xbt_free(field.name);
-      xbt_free(field.type_name);
+      free(field.name);
+      free(field.type_name);
 
     }
     xbt_dynar_reset(identifiers);
@@ -491,7 +498,7 @@ static gras_datadesc_type_t parse_struct(char *definition) {
       DEBUG1("struct_type=%p",(void*)struct_type);
       VERB2("Push field '%s' into size stack of %p", name, (void*)struct_type);
       gras_datadesc_cb_field_push(struct_type, name);
-      xbt_free(name);
+      free(name);
     }
     xbt_dynar_reset(fields_to_push);
   }
@@ -599,15 +606,14 @@ gras_datadesc_parse(const char            *name,
 
   gras_ddt_parse_pointer_string_close();
   VERB0("end of _gras_ddt_type_parse()");
-  xbt_free(definition);
+  free(definition);
   /* register it under the name provided as symbol */
   if (strcmp(res->name,name)) {
     ERROR2("In GRAS_DEFINE_TYPE, the provided symbol (here %s) must be the C type name (here %s)",
           name,res->name);
     xbt_abort();
   }    
+  gras_ddt_parse_lex_destroy();
   XBT_OUT;
   return res;
 }
-
-