Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Sanitize the log channels naming scheme in GRAS too
[simgrid.git] / src / gras / DataDesc / ddt_parse.c
index 341767e..df88228 100644 (file)
@@ -15,7 +15,7 @@
 #include "gras/DataDesc/datadesc_private.h"
 #include "gras/DataDesc/ddt_parse.yy.h"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_parse,datadesc,
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_parse,gras_ddt,
   "Parsing C data structures to build GRAS data description");
 
 typedef struct s_type_modifier{
@@ -181,7 +181,7 @@ static void parse_statement(char     *definition,
     THROW0(mismatch_error,0,"End of the englobing structure or union");
   }
   
-  if (XBT_LOG_ISENABLED(ddt_parse,xbt_log_priority_debug)) {
+  if (XBT_LOG_ISENABLED(gras_ddt_parse,xbt_log_priority_debug)) {
     int colon_pos;
     for (colon_pos = gras_ddt_parse_col_pos;
         definition[colon_pos] != ';';
@@ -315,8 +315,16 @@ static void parse_statement(char    *definition,
          char *end;
          long int size=strtol(gras_ddt_parse_text, &end, 10);
 
-         if (end == gras_ddt_parse_text || *end != '\0')
-           PARSE_ERROR1("Unparsable size of array (found '%c', expected number)",*end);
+         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);
+           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);
+           }
+         }
 
          /* replace the previously pushed type to an array of it */
          change_to_fixed_array(identifiers,size);
@@ -645,3 +653,12 @@ gras_datadesc_parse(const char            *name,
   XBT_OUT;
   return res;
 }
+
+xbt_dict_t gras_dd_constants;
+/** \brief Declare a constant to the parsing mecanism. See the "\#define and fixed size array" section */
+void gras_datadesc_set_const(const char*name, int value) {
+  int *stored = xbt_new(int, 1);
+  *stored=value;
+
+  xbt_dict_set(gras_dd_constants,name, stored, free); 
+}