Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove old style logging macros.
[simgrid.git] / src / gras / DataDesc / ddt_parse.c
index b136eec..d6d3b3f 100644 (file)
@@ -1,10 +1,7 @@
-/* $Id$ */
-
 /* DataDesc/ddt_parse.c -- automatic parsing of data structures             */
 
-/* Copyright (c) 2003 Arnaud Legrand.                                       */
-/* Copyright (c) 2003, 2004 Martin Quinson.                                 */
-/* All rights reserved.                                                     */
+/* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
+ * 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. */
@@ -49,45 +46,45 @@ static void parse_type_modifier(type_modifier_t type_modifier)
   do {
     if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_STAR) {
       /* This only used when parsing 'short *' since this function returns when int, float, double,... is encountered */
-      DEBUG0("This is a reference");
+      XBT_DEBUG("This is a reference");
       type_modifier->is_ref++;
 
     } else if (!strcmp(gras_ddt_parse_text, "unsigned")) {
-      DEBUG0("This is an unsigned");
+      XBT_DEBUG("This is an unsigned");
       type_modifier->is_unsigned = 1;
 
     } else if (!strcmp(gras_ddt_parse_text, "short")) {
-      DEBUG0("This is short");
+      XBT_DEBUG("This is short");
       type_modifier->is_short = 1;
 
     } else if (!strcmp(gras_ddt_parse_text, "long")) {
-      DEBUG0("This is long");
+      XBT_DEBUG("This is long");
       type_modifier->is_long++; /* handle "long long" */
 
     } else if (!strcmp(gras_ddt_parse_text, "struct")) {
-      DEBUG0("This is a struct");
+      XBT_DEBUG("This is a struct");
       type_modifier->is_struct = 1;
 
     } else if (!strcmp(gras_ddt_parse_text, "union")) {
-      DEBUG0("This is an union");
+      XBT_DEBUG("This is an union");
       type_modifier->is_union = 1;
 
     } else if (!strcmp(gras_ddt_parse_text, "enum")) {
-      DEBUG0("This is an enum");
+      XBT_DEBUG("This is an enum");
       type_modifier->is_enum = 1;
 
     } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_EMPTY) {
-      DEBUG0("Pass space");
+      XBT_DEBUG("Pass space");
 
     } else {
-      DEBUG1("Done with modifiers (got %s)", gras_ddt_parse_text);
+      XBT_DEBUG("Done with modifiers (got %s)", gras_ddt_parse_text);
       break;
     }
 
     gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump();
     if ((gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) &&
         (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_STAR)) {
-      DEBUG2("Done with modifiers (got %s,%d)", gras_ddt_parse_text,
+      XBT_DEBUG("Done with modifiers (got %s,%d)", gras_ddt_parse_text,
              gras_ddt_parse_tok_num);
       break;
     }
@@ -127,7 +124,7 @@ 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) + 48);
-  DEBUG2("Array specification (size=%ld, elm='%s'), change pushed type",
+  XBT_DEBUG("Array specification (size=%ld, elm='%s'), change pushed type",
          size, former.type_name);
   sprintf(array.type_name, "%s%s%s%s[%ld]",
           (former.tm.is_unsigned ? "u " : ""),
@@ -150,7 +147,7 @@ static void change_to_ref(xbt_dynar_t dynar)
   XBT_IN;
   xbt_dynar_pop(dynar, &former);
   ref.type_name = (char *) xbt_malloc(strlen(former.type->name) + 2);
-  DEBUG1("Ref specification (elm='%s'), change pushed type",
+  XBT_DEBUG("Ref specification (elm='%s'), change pushed type",
          former.type_name);
   sprintf(ref.type_name, "%s*", former.type_name);
   free(former.type_name);
@@ -251,7 +248,7 @@ static void parse_statement(char *definition,
     for (colon_pos = gras_ddt_parse_col_pos;
          definition[colon_pos] != ';'; colon_pos++);
     definition[colon_pos] = '\0';
-    DEBUG3("Parse the statement \"%s%s;\" (col_pos=%d)",
+    XBT_DEBUG("Parse the statement \"%s%s;\" (col_pos=%d)",
            gras_ddt_parse_text,
            definition + gras_ddt_parse_col_pos, gras_ddt_parse_col_pos);
     definition[colon_pos] = ';';
@@ -259,8 +256,8 @@ static void parse_statement(char *definition,
 
   if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD)
     PARSE_ERROR1
-      ("Unparsable symbol: found a typeless statement (got '%s' instead)",
-       gras_ddt_parse_text);
+        ("Unparsable symbol: found a typeless statement (got '%s' instead)",
+         gras_ddt_parse_text);
 
         /**** get the type modifier of this statement ****/
   parse_type_modifier(&identifier.tm);
@@ -269,7 +266,7 @@ static void parse_statement(char *definition,
   if (identifier.tm.is_union || identifier.tm.is_enum
       || identifier.tm.is_struct)
     PARSE_ERROR0
-      ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle recursive type definition yet");
+        ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle recursive type definition yet");
 
         /**** get the base type, giving "short a" the needed love ****/
   if (!identifier.tm.is_union &&
@@ -283,21 +280,21 @@ static void parse_statement(char *definition,
 
     /* bastard user, they omited "int" ! */
     identifier.type_name = (char *) strdup("int");
-    DEBUG0("the base type is 'int', which were omited (you vicious user)");
+    XBT_DEBUG("the base type is 'int', which were omited (you vicious user)");
   } else {
     identifier.type_name = (char *) strdup(gras_ddt_parse_text);
-    DEBUG1("the base type is '%s'", identifier.type_name);
+    XBT_DEBUG("the base type is '%s'", identifier.type_name);
     gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump();
   }
 
         /**** build the base type for latter use ****/
   if (identifier.tm.is_union) {
     PARSE_ERROR0
-      ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle union yet (get callback from annotation?)");
+        ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle union yet (get callback from annotation?)");
 
   } else if (identifier.tm.is_enum) {
     PARSE_ERROR0
-      ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle enum yet");
+        ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle enum yet");
 
   } else if (identifier.tm.is_struct) {
     sprintf(buffname, "struct %s", identifier.type_name);
@@ -348,7 +345,7 @@ static void parse_statement(char *definition,
       identifier.type = gras_datadesc_by_name("char");
 
     } else {
-      DEBUG1("Base type is a constructed one (%s)", identifier.type_name);
+      XBT_DEBUG("Base type is a constructed one (%s)", identifier.type_name);
       if (!strcmp(identifier.type_name, "xbt_matrix_t")) {
         identifier.tm.is_matrix = 1;
       } else if (!strcmp(identifier.type_name, "xbt_dynar_t")) {
@@ -383,7 +380,7 @@ static void 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_RB) {
           PARSE_ERROR0
-            ("Unimplemented feature: GRAS_DEFINE_TYPE cannot deal with [] constructs (yet)");
+              ("Unimplemented feature: GRAS_DEFINE_TYPE cannot deal with [] constructs (yet)");
 
         } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) {
           char *end;
@@ -391,14 +388,14 @@ static void parse_statement(char *definition,
 
           if (end == gras_ddt_parse_text || *end != '\0') {
             /* Not a number. Get the constant value, if any */
-            int *storage =
-              xbt_dict_get_or_null(gras_dd_constants, gras_ddt_parse_text);
+            int *storage = xbt_dict_get_or_null(gras_dd_constants,
+                                                gras_ddt_parse_text);
             if (storage) {
               size = *storage;
             } else {
               PARSE_ERROR1
-                ("Unparsable size of array. Found '%s', expected number or known constant. Need to use gras_datadesc_set_const(), huh?",
-                 gras_ddt_parse_text);
+                  ("Unparsable size of array. Found '%s', expected number or known constant. Need to use gras_datadesc_set_const(), huh?",
+                   gras_ddt_parse_text);
             }
           }
 
@@ -409,7 +406,7 @@ static void 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_RB)
             PARSE_ERROR0("Unparsable size of array");
-          DEBUG1("Fixed size array, size=%ld", size);
+          XBT_DEBUG("Fixed size array, size=%ld", size);
           continue;
         } else {
           PARSE_ERROR0("Unparsable size of array");
@@ -423,51 +420,58 @@ static void parse_statement(char *definition,
         char *keyval = NULL;
         memset(&array, 0, sizeof(array));
         if (strcmp(gras_ddt_parse_text, "GRAS_ANNOTE"))
-          PARSE_ERROR1("Unparsable symbol: Expected 'GRAS_ANNOTE', got '%s'",
-                       gras_ddt_parse_text);
+          PARSE_ERROR1
+              ("Unparsable symbol: Expected 'GRAS_ANNOTE', got '%s'",
+               gras_ddt_parse_text);
 
         gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump();
         if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_LP)
           PARSE_ERROR1
-            ("Unparsable annotation: Expected parenthesis, got '%s'",
-             gras_ddt_parse_text);
+              ("Unparsable annotation: Expected parenthesis, got '%s'",
+               gras_ddt_parse_text);
 
         while ((gras_ddt_parse_tok_num =
-                gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY);
+                gras_ddt_parse_lex_n_dump()) ==
+               GRAS_DDT_PARSE_TOKEN_EMPTY);
 
         if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD)
-          PARSE_ERROR1("Unparsable annotation: Expected key name, got '%s'",
-                       gras_ddt_parse_text);
+          PARSE_ERROR1
+              ("Unparsable annotation: Expected key name, got '%s'",
+               gras_ddt_parse_text);
         keyname = (char *) strdup(gras_ddt_parse_text);
 
         while ((gras_ddt_parse_tok_num =
-                gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY);
+                gras_ddt_parse_lex_n_dump()) ==
+               GRAS_DDT_PARSE_TOKEN_EMPTY);
 
         if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_COLON)
           PARSE_ERROR1
-            ("Unparsable annotation: expected ',' after the key name, got '%s'",
-             gras_ddt_parse_text);
+              ("Unparsable annotation: expected ',' after the key name, got '%s'",
+               gras_ddt_parse_text);
 
         while ((gras_ddt_parse_tok_num =
-                gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY);
+                gras_ddt_parse_lex_n_dump()) ==
+               GRAS_DDT_PARSE_TOKEN_EMPTY);
 
         /* get the value */
 
         if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD)
-          PARSE_ERROR1("Unparsable annotation: Expected key value, got '%s'",
-                       gras_ddt_parse_text);
+          PARSE_ERROR1
+              ("Unparsable annotation: Expected key value, got '%s'",
+               gras_ddt_parse_text);
         keyval = (char *) strdup(gras_ddt_parse_text);
 
         while ((gras_ddt_parse_tok_num =
-                gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY);
+                gras_ddt_parse_lex_n_dump()) ==
+               GRAS_DDT_PARSE_TOKEN_EMPTY);
 
         /* Done with parsing the annotation. Now deal with it by replacing previously pushed type with the right one */
 
-        DEBUG2("Anotation: %s=%s", keyname, keyval);
+        XBT_DEBUG("Anotation: %s=%s", keyname, keyval);
         if (!strcmp(keyname, "size")) {
-          free(keyname);
           if (!identifier.tm.is_ref)
-            PARSE_ERROR0("Size annotation for a field not being a reference");
+            PARSE_ERROR0
+                ("Size annotation for a field not being a reference");
           identifier.tm.is_ref--;
 
           if (!strcmp(keyval, "1")) {
@@ -499,16 +503,16 @@ static void parse_statement(char *definition,
             identifier.tm.is_dynar = -1;
           } else {
             PARSE_ERROR1
-              ("subtype annotation only accepted for dynars and matrices, but passed to '%s'",
-               identifier.type_name);
+                ("subtype annotation only accepted for dynars and matrices, but passed to '%s'",
+                 identifier.type_name);
           }
           free(keyval);
         } else if (!strcmp(keyname, "free_f")) {
           int *storage = xbt_dict_get_or_null(gras_dd_constants, keyval);
           if (!storage)
             PARSE_ERROR1
-              ("value for free_f annotation of field %s is not a known constant",
-               identifier.name);
+                ("value for free_f annotation of field %s is not a known constant",
+                 identifier.name);
           if (identifier.tm.is_matrix == -1) {
             add_free_f(identifiers, *(void_f_pvoid_t *) storage);
             identifier.tm.is_matrix = 0;
@@ -517,14 +521,15 @@ static void parse_statement(char *definition,
             identifier.tm.is_dynar = 0;
           } else {
             PARSE_ERROR1
-              ("free_f annotation only accepted for dynars and matrices which subtype is already declared (field %s)",
-               identifier.name);
+                ("free_f annotation only accepted for dynars and matrices which subtype is already declared (field %s)",
+                 identifier.name);
           }
           free(keyval);
         } else {
           free(keyval);
           PARSE_ERROR1("Unknown annotation type: '%s'", keyname);
         }
+        free(keyname);
 
         /* Get all the multipliers */
         while (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_STAR) {
@@ -533,8 +538,8 @@ static void parse_statement(char *definition,
 
           if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD)
             PARSE_ERROR1
-              ("Unparsable annotation: Expected field name after '*', got '%s'",
-               gras_ddt_parse_text);
+                ("Unparsable annotation: Expected field name after '*', got '%s'",
+                 gras_ddt_parse_text);
 
           keyval = xbt_malloc(strlen(gras_ddt_parse_text) + 2);
           sprintf(keyval, "*%s", gras_ddt_parse_text);
@@ -549,16 +554,16 @@ static void parse_statement(char *definition,
 
         if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RP)
           PARSE_ERROR1
-            ("Unparsable annotation: Expected parenthesis, got '%s'",
-             gras_ddt_parse_text);
+              ("Unparsable annotation: Expected parenthesis, got '%s'",
+               gras_ddt_parse_text);
 
         continue;
 
         /* End of annotation handling */
       } else {
         PARSE_ERROR1
-          ("Unparsable symbol: Got '%s' instead of expected comma (',')",
-           gras_ddt_parse_text);
+            ("Unparsable symbol: Got '%s' instead of expected comma (',')",
+             gras_ddt_parse_text);
       }
     } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_COLON) {
       PARSE_ERROR0("Unparsable symbol: Unexpected comma (',')");
@@ -573,16 +578,16 @@ static void parse_statement(char *definition,
     if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) {
 
       identifier.name = (char *) strdup(gras_ddt_parse_text);
-      DEBUG1("Found the identifier \"%s\"", identifier.name);
+      XBT_DEBUG("Found the identifier \"%s\"", identifier.name);
 
       xbt_dynar_push(identifiers, &identifier);
-      DEBUG1("Dynar_len=%lu", xbt_dynar_length(identifiers));
+      XBT_DEBUG("Dynar_len=%lu", xbt_dynar_length(identifiers));
       expect_id_separator = 1;
       continue;
     }
 
     PARSE_ERROR0
-      ("Unparasable symbol (maybe a def struct in a def struct or a parser bug ;)");
+        ("Unparasable symbol (maybe a def struct in a def struct or a parser bug ;)");
   }
 
   if (identifier.tm.is_matrix > 0)
@@ -618,18 +623,18 @@ static gras_datadesc_type_t parse_struct(char *definition)
   /* Create the struct descriptor */
   if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) {
     struct_type = gras_datadesc_struct(gras_ddt_parse_text);
-    VERB1("Parse the struct '%s'", gras_ddt_parse_text);
+    XBT_VERB("Parse the struct '%s'", gras_ddt_parse_text);
     gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump();
   } else {
     sprintf(buffname, "anonymous struct %d", anonymous_struct++);
-    VERB1("Parse the anonymous struct nb %d", anonymous_struct);
+    XBT_VERB("Parse the anonymous struct nb %d", anonymous_struct);
     struct_type = gras_datadesc_struct(buffname);
   }
 
   if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_LA)
     PARSE_ERROR1
-      ("Unparasable symbol: Expecting struct definition, but got %s instead of '{'",
-       gras_ddt_parse_text);
+        ("Unparasable symbol: Expecting struct definition, but got %s instead of '{'",
+         gras_ddt_parse_text);
 
   /* Parse the identifiers */
   done = 0;
@@ -644,33 +649,33 @@ static gras_datadesc_type_t parse_struct(char *definition)
       done = 1;
     }
 
-    DEBUG1("This statement contained %lu identifiers",
+    XBT_DEBUG("This statement contained %lu identifiers",
            xbt_dynar_length(identifiers));
     /* append the identifiers we've found */
     xbt_dynar_foreach(identifiers, iter, field) {
       if (field.tm.is_ref)
         PARSE_ERROR2
-          ("Not enough GRAS_ANNOTATE to deal with all dereferencing levels of %s (%d '*' left)",
-           field.name, field.tm.is_ref);
+            ("Not enough GRAS_ANNOTATE to deal with all dereferencing levels of %s (%d '*' left)",
+             field.name, field.tm.is_ref);
 
-      VERB2("Append field '%s' to %p", field.name, (void *) struct_type);
+      XBT_VERB("Append field '%s' to %p", field.name, (void *) struct_type);
       gras_datadesc_struct_append(struct_type, field.name, field.type);
       free(field.name);
       free(field.type_name);
 
     }
     xbt_dynar_reset(identifiers);
-    DEBUG1("struct_type=%p", (void *) struct_type);
+    XBT_DEBUG("struct_type=%p", (void *) struct_type);
 
     /* Make sure that all fields declaring a size push it into the cbps */
     xbt_dynar_foreach(fields_to_push, iter, name) {
-      DEBUG1("struct_type=%p", (void *) struct_type);
+      XBT_DEBUG("struct_type=%p", (void *) struct_type);
       if (name[0] == '*') {
-        VERB2("Push field '%s' as a multiplier into size stack of %p",
+        XBT_VERB("Push field '%s' as a multiplier into size stack of %p",
               name + 1, (void *) struct_type);
         gras_datadesc_cb_field_push_multiplier(struct_type, name + 1);
       } else {
-        VERB2("Push field '%s' into size stack of %p",
+        XBT_VERB("Push field '%s' into size stack of %p",
               name, (void *) struct_type);
         gras_datadesc_cb_field_push(struct_type, name);
       }
@@ -683,8 +688,8 @@ static gras_datadesc_type_t parse_struct(char *definition)
   /* terminates */
   if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RA)
     PARSE_ERROR1
-      ("Unparasable symbol: Expected '}' at the end of struct definition, got '%s'",
-       gras_ddt_parse_text);
+        ("Unparasable symbol: Expected '}' at the end of struct definition, got '%s'",
+         gras_ddt_parse_text);
 
   gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump();
 
@@ -716,16 +721,17 @@ static gras_datadesc_type_t parse_typedef(char *definition)
 
   if (tm.is_ref)
     PARSE_ERROR0
-      ("GRAS_DEFINE_TYPE cannot handle reference without annotation");
+        ("GRAS_DEFINE_TYPE cannot handle reference without annotation");
 
   /* get the aliasing name */
   if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD)
-    PARSE_ERROR1("Unparsable typedef: Expected the alias name, and got '%s'",
-                 gras_ddt_parse_text);
+    PARSE_ERROR1
+        ("Unparsable typedef: Expected the alias name, and got '%s'",
+         gras_ddt_parse_text);
 
   /* (FIXME: should) build the alias */
   PARSE_ERROR0
-    ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle typedef yet");
+      ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle typedef yet");
 
   XBT_OUT;
   return typedef_desc;
@@ -761,7 +767,7 @@ gras_datadesc_parse(const char *name, const char *C_statement)
   definition[def_count] = '\0';
 
   /* init */
-  VERB2("_gras_ddt_type_parse(%s) -> %d chars", definition, def_count);
+  XBT_VERB("_gras_ddt_type_parse(%s) -> %d chars", definition, def_count);
   gras_ddt_parse_pointer_string_init(definition);
 
   /* Do I have a typedef, or a raw struct ? */
@@ -778,20 +784,20 @@ gras_datadesc_parse(const char *name, const char *C_statement)
     res = parse_typedef(definition);
 
   } else {
-    ERROR1
-      ("Failed to parse the following symbol (not a struct neither a typedef) :\n%s",
-       definition);
+    XBT_ERROR
+        ("Failed to parse the following symbol (not a struct neither a typedef) :\n%s",
+         definition);
     xbt_abort();
   }
 
   gras_ddt_parse_pointer_string_close();
-  VERB0("end of _gras_ddt_type_parse()");
+  XBT_VERB("end of _gras_ddt_type_parse()");
   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_ERROR
+        ("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();