diff --git a/src/runtime/c/pgf/data.c b/src/runtime/c/pgf/data.c index b91a8f43a..4a7741f90 100644 --- a/src/runtime/c/pgf/data.c +++ b/src/runtime/c/pgf/data.c @@ -100,7 +100,7 @@ GU_DEFINE_TYPE( GU_MEMBER(PgfCncCat, cid, PgfCId), GU_MEMBER_P(PgfCncCat, cats, PgfCCatIds), GU_MEMBER(PgfCncCat, n_lins, size_t), - GU_MEMBER_P(PgfCncCat, labels, GuStringL)); + GU_FLEX_MEMBER(PgfCncCat, labels, GuString)); // GU_DEFINE_TYPE(PgfSequence, GuList, gu_ptr_type(PgfSymbol)); // GU_DEFINE_TYPE(PgfSequence, GuList, gu_type(PgfSymbol)); diff --git a/src/runtime/c/pgf/data.h b/src/runtime/c/pgf/data.h index 0afa24dd1..ea466b0c3 100644 --- a/src/runtime/c/pgf/data.h +++ b/src/runtime/c/pgf/data.h @@ -143,9 +143,9 @@ struct PgfCat { struct PgfCncCat { PgfCId cid; PgfCCatIds* cats; + size_t n_lins; - - GuStringL* labels; + GuString labels[]; /**< Labels for tuples. All nested tuples, records and tables * in the GF linearization types are flattened into a single * tuple in the corresponding PGF concrete category. This diff --git a/src/runtime/c/pgf/printer.c b/src/runtime/c/pgf/printer.c index 52135912b..3d13147b6 100644 --- a/src/runtime/c/pgf/printer.c +++ b/src/runtime/c/pgf/printer.c @@ -290,8 +290,7 @@ pgf_print_cnccat(GuMapItor* fn, const void* key, void* value, gu_puts("\n ", wtr, err); } - GuString lbl = gu_list_index(cnccat->labels, i); - gu_string_write(lbl, wtr, err); + gu_string_write(cnccat->labels[i], wtr, err); } gu_puts("]\n", wtr, err); } diff --git a/src/runtime/c/pgf/reader.c b/src/runtime/c/pgf/reader.c index b4aadb5b8..400ffee9a 100644 --- a/src/runtime/c/pgf/reader.c +++ b/src/runtime/c/pgf/reader.c @@ -695,42 +695,6 @@ pgf_read_new_PgfConcr(GuType* type, PgfReader* rdr, GuPool* pool, return concr; } -static bool -pgf_ccat_n_lins(PgfCCat* cat, int* n_lins) { - if (gu_seq_is_null(cat->prods)) { - return true; - } - size_t n_prods = gu_seq_length(cat->prods); - for (size_t j = 0; j < n_prods; j++) { - PgfProduction prod = - gu_seq_get(cat->prods, PgfProduction, j); - GuVariantInfo i = gu_variant_open(prod); - switch (i.tag) { - case PGF_PRODUCTION_APPLY: { - PgfProductionApply* papp = i.data; - if (*n_lins == -1) { - *n_lins = (int) papp->fun->n_lins; - } else if (*n_lins != (int) papp->fun->n_lins) { - // Inconsistent n_lins for different productions! - return false; - } - break; - } - case PGF_PRODUCTION_COERCE: { - PgfProductionCoerce* pcoerce = i.data; - bool succ = pgf_ccat_n_lins(pcoerce->coerce, n_lins); - if (!succ) { - return false; - } - break; - } - default: - gu_impossible(); - } - } - return true; -} - static void* pgf_read_new_PgfCncCat(GuType* type, PgfReader* rdr, GuPool* pool, size_t* size_out) @@ -738,13 +702,18 @@ pgf_read_new_PgfCncCat(GuType* type, PgfReader* rdr, GuPool* pool, PgfCId cid = *(PgfCId*) rdr->curr_key; gu_enter("-> cid"); (void) (type && size_out); - PgfCncCat* cnccat = gu_new(PgfCncCat, pool); - cnccat->cid = cid; + int first = pgf_read_int(rdr); int last = pgf_read_int(rdr); + int n_lins = pgf_read_len(rdr); + + PgfCncCat* cnccat = + gu_malloc(pool, sizeof(PgfCncCat)+n_lins*sizeof(GuString)); + cnccat->cid = cid; + int len = last + 1 - first; - PgfCCatIds* cats = gu_new_list(PgfCCatIds, pool, len); - int n_lins = -1; + cnccat->cats = gu_new_list(PgfCCatIds, pool, len); + for (int i = 0; i < len; i++) { int fid = first + i; PgfCCat* ccat = gu_map_get(rdr->curr_ccats, &fid, PgfCCat*); @@ -757,24 +726,19 @@ pgf_read_new_PgfCncCat(GuType* type, PgfReader* rdr, GuPool* pool, gu_map_put(rdr->curr_ccats, &fid, PgfCCat*, ccat); } - gu_list_index(cats, i) = ccat; + gu_list_index(cnccat->cats, i) = ccat; ccat->cnccat = cnccat; - if (!pgf_ccat_n_lins(ccat, &n_lins)) { - gu_raise(rdr->err, PgfReadExn); - goto fail; - } gu_debug("range[%d] = %d", i, ccat ? ccat->fid : -1); } - cnccat->n_lins = n_lins == -1 ? 0 : (size_t) n_lins; - cnccat->cats = cats; - cnccat->labels = pgf_read_new(rdr, gu_type(GuStringL), - pool, NULL); + + cnccat->n_lins = n_lins; + for (size_t i = 0; i < cnccat->n_lins; i++) { + pgf_read_to(rdr, gu_type(GuString), &cnccat->labels[i]); + } + gu_exit("<-"); return cnccat; -fail: - gu_exit("<- fail"); - return NULL; } #define PGF_READ_TO_FN(k_, fn_) \