From 89b05f4755bfc7c6ba81305f4f4cada1141b991e Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 1 Dec 2021 10:09:34 +1100 Subject: [PATCH] oceani: move prepare_type handling to after the parse. This will allow global constants to be used before they are declared. Signed-off-by: NeilBrown --- csrc/oceani.mdc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index a4a9bd7..34c17b2 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -242,6 +242,7 @@ structures can be used. parse_oceani(ss->code, &context.config, dotrace ? stderr : NULL); + prepare_types(&context); if (!context.parse_error && !analyse_funcs(&context)) { fprintf(stderr, "oceani: type error in program - not running.\n"); context.parse_error = 1; @@ -914,6 +915,15 @@ which might be reported in error messages. fprintf(f, "*Unknown*"); // NOTEST } + static void prepare_types(struct parse_context *c) + { + struct type *t; + + for (t = c->typelist; t; t = t->next) + if (t->prepare_type) + t->prepare_type(c, t, 1); + } + ###### forward decls static void free_value(struct type *type, struct value *v); @@ -1858,7 +1868,7 @@ tell if it was set or not later. { if (!v->global) { if (!c->local || !v->type) - return NULL; // NOTEST + return NULL; if (v->frame_pos + v->type->size > c->local_size) { printf("INVALID frame_pos\n"); // NOTEST exit(2); // NOTEST @@ -1884,7 +1894,7 @@ tell if it was set or not later. t->prepare_type(c, t, 1); // NOTEST if (c->global_size & (t->align - 1)) - c->global_size = (c->global_size + t->align) & ~(t->align-1); + c->global_size = (c->global_size + t->align) & ~(t->align-1); // NOTEST if (!v) { v = &scratch; v->type = t; @@ -2236,14 +2246,14 @@ with a const size by whether they are prepared at parse time or not. struct value *vsize; mpz_t q; if (type->array.static_size) - return; // NOTEST + return; if (type->array.unspec && parse_time) - return; // NOTEST + return; if (type->array.vsize) { vsize = var_value(c, type->array.vsize); if (!vsize) - return; // NOTEST + return; mpz_init(q); mpz_tdiv_q(q, mpq_numref(vsize->num), mpq_denref(vsize->num)); type->array.size = mpz_get_si(q); @@ -2735,9 +2745,6 @@ function will be needed. struct type *t = add_type(c, $2.txt, &structure_prototype); t->structure.field_list = $prepare_type) - t->prepare_type(c, t, 1); - } }$ $*fieldlist -- 2.43.0