- /* Handle fixed size arrays */
- gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump();
- if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_RB) {
- ERROR3("Cannot dynamically sized array at %d:%d of %s",
- gras_ddt_parse_line_pos,gras_ddt_parse_char_pos,
- definition);
- gras_abort();
- } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) {
- char *end;
- long int size=strtol(gras_ddt_parse_text, &end, 10);
- identifier_t array;
-
- if (end == gras_ddt_parse_text ||
- *end != '\0') {
- ERROR4("Unparsable size of array at %d:%d of %s. Found '%c', expected '\\0'",
- gras_ddt_parse_line_pos,gras_ddt_parse_char_pos,
- definition,*end);
- gras_abort();
- }
- /* replace the previously pushed type to an array of it */
- gras_dynar_pop(*dynar,&identifier.type);
- array.type_name=malloc(strlen(identifier.type->name)+20);
- DEBUG2("Array specification (size=%ld, elm='%s'), change pushed type",
- size,identifier.type_name);
- sprintf(array.type_name,"%s[%ld]",identifier.type_name,size);
- free(identifier.type_name);
- array.type = gras_datadesc_by_name(array.type_name);
- if (array.type==NULL) {
- TRY(gras_datadesc_declare_array_fixed(array.type_name,
- identifier.type,
- size, &array.type));
- }
- array.name = identifier.name;
- TRY(gras_dynar_push(*dynar,&array));
-
- /* eat the closing bracket */
- gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump();
- if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RB) {
- ERROR3("Unparsable size of array at %d:%d of %s",
- gras_ddt_parse_line_pos,gras_ddt_parse_char_pos,
- definition);
- gras_abort();
- }
- DEBUG1("Fixed size array, size=%ld",size);
- continue;
- } else {
- ERROR3("Unparsable size of array at %d:%d of %s",
- gras_ddt_parse_line_pos,gras_ddt_parse_char_pos,
- definition);
- gras_abort();
- }
+ /* Handle fixed size arrays */
+ 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)");
+
+ } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) {
+ char *end;
+ long int size = strtol(gras_ddt_parse_text, &end, 10);
+
+ 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);
+
+ /* eat the closing bracket */
+ 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);
+ continue;
+ } else {
+ PARSE_ERROR0("Unparsable size of array");
+ }
+ /* End of fixed size arrays handling */
+
+ } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) {
+ /* Handle annotation */
+ s_identifier_t array;
+ char *keyname = NULL;
+ 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);
+
+ 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);
+
+ 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_WORD)
+ 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);
+
+ 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);
+
+ 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);
+
+ /* 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(keyname, "size")) {
+ 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);
+ free(keyval);
+ } else {
+ char *p;
+ int fixed = 1;
+ for (p = keyval; *p != '\0'; p++)
+ if (!isdigit(*p))
+ fixed = 0;
+ if (fixed) {
+ change_to_fixed_array(identifiers, atoi(keyval));
+ change_to_ref(identifiers);
+ free(keyval);
+
+ } else {
+ change_to_ref_pop_array(identifiers);
+ xbt_dynar_push(fields_to_push, &keyval);
+ }
+ }
+ } else if (!strcmp(keyname, "subtype")) {
+ gras_datadesc_type_t subtype = gras_datadesc_by_name(keyval);
+ if (identifier.tm.is_matrix) {
+ change_to_matrix_of(identifiers, subtype);
+ identifier.tm.is_matrix = -1;
+ } else if (identifier.tm.is_dynar) {
+ change_to_dynar_of(identifiers, subtype);
+ identifier.tm.is_dynar = -1;
+ } else {
+ PARSE_ERROR1
+ ("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);
+ if (identifier.tm.is_matrix == -1) {
+ add_free_f(identifiers, *(void_f_pvoid_t *) storage);
+ identifier.tm.is_matrix = 0;
+ } else if (identifier.tm.is_dynar == -1) {
+ add_free_f(identifiers, *(void_f_pvoid_t *) storage);
+ 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(keyval);
+ } else {
+ free(keyval);
+ 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 */