#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{
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] != ';';
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);
while ( (gras_ddt_parse_tok_num = 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);
keyval = (char*)strdup(gras_ddt_parse_text);
while ( (gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY );
- if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RP)
- PARSE_ERROR1("Unparsable annotation: Expected parenthesis, got '%s'",gras_ddt_parse_text);
-
/* Done with parsing the annotation. Now deal with it by replacing previously pushed type with the right one */
DEBUG2("Anotation: %s=%s",keyname,keyval);
if (!strcmp(keyval,"1")) {
change_to_ref(identifiers);
free(keyval);
- continue;
} else {
char *p;
int fixed = 1;
change_to_fixed_array(identifiers,atoi(keyval));
change_to_ref(identifiers);
free(keyval);
- continue;
} else {
change_to_ref_pop_array(identifiers);
xbt_dynar_push(fields_to_push,&keyval);
- continue;
}
}
- THROW_IMPOSSIBLE;
-
} else {
PARSE_ERROR1("Unknown annotation type: '%s'",keyname);
}
+
+ /* Get all the multipliers */
+ while (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_STAR) {
+
+ gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump();
+
+ 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);
+
+ keyval = xbt_malloc(strlen(gras_ddt_parse_text)+2);
+ sprintf(keyval,"*%s",gras_ddt_parse_text);
+
+ /* ask caller to push field as a multiplier */
+ xbt_dynar_push(fields_to_push,&keyval);
+
+ /* skip blanks after this block*/
+ while ( (gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump())
+ == GRAS_DDT_PARSE_TOKEN_EMPTY );
+ }
+
+ if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RP)
+ PARSE_ERROR1("Unparsable annotation: Expected parenthesis, got '%s'",
+ gras_ddt_parse_text);
+
continue;
/* End of annotation handling */
/* Make sure that all fields declaring a size push it into the cbps */
xbt_dynar_foreach(fields_to_push,i, name) {
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);
+ if (name[0] == '*') {
+ VERB2("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",
+ name, (void*)struct_type);
+ gras_datadesc_cb_field_push(struct_type, name);
+ }
free(name);
}
xbt_dynar_reset(fields_to_push);
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);
+}