]> ocean-lang.org Git - ocean/commitdiff
ocean: propagate_types: only set Efail on local err.
authorNeilBrown <neil@brown.name>
Sat, 4 Dec 2021 22:29:23 +0000 (09:29 +1100)
committerNeilBrown <neil@brown.name>
Sat, 4 Dec 2021 22:29:23 +0000 (09:29 +1100)
propagate_types() currently sets Efail if there has been any parse error
at all.  This is wrong.
Instead, keep a count of errors, and only set Efail if that count has increased.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani.mdc

index d40cf9a42f5335a3f30ebf263fb8c82ab9c37d01..725719e2558a19c5f1c2f5c4456b97c002a20c4f 100644 (file)
@@ -246,7 +246,7 @@ structures can be used.
                prepare_types(&context);
                if (!context.parse_error && !analyse_funcs(&context)) {
                        fprintf(stderr, "oceani: type error in program - not running.\n");
                prepare_types(&context);
                if (!context.parse_error && !analyse_funcs(&context)) {
                        fprintf(stderr, "oceani: type error in program - not running.\n");
-                       context.parse_error = 1;
+                       context.parse_error += 1;
                }
 
                if (doprint) {
                }
 
                if (doprint) {
@@ -395,14 +395,14 @@ context so indicate that parsing failed.
                        }
                }
                fputs("\n", stderr);
                        }
                }
                fputs("\n", stderr);
-               c->parse_error = 1;
+               c->parse_error += 1;
        }
 
        static void tok_err(struct parse_context *c, char *fmt, struct token *t)
        {
                fprintf(stderr, "%s:%d:%d: %s: %.*s\n", c->file_name, t->line, t->col, fmt,
                        t->txt.len, t->txt.txt);
        }
 
        static void tok_err(struct parse_context *c, char *fmt, struct token *t)
        {
                fprintf(stderr, "%s:%d:%d: %s: %.*s\n", c->file_name, t->line, t->col, fmt,
                        t->txt.len, t->txt.txt);
-               c->parse_error = 1;
+               c->parse_error += 1;
        }
 
 ## Entities: declared and predeclared.
        }
 
 ## Entities: declared and predeclared.
@@ -630,9 +630,10 @@ remains unchanged at `0`, then no more propagation is needed.
        static struct type *propagate_types(struct exec *prog, struct parse_context *c, enum prop_err *perr,
                                            struct type *type, int rules)
        {
        static struct type *propagate_types(struct exec *prog, struct parse_context *c, enum prop_err *perr,
                                            struct type *type, int rules)
        {
+               int pre_err = c->parse_error;
                struct type *ret = __propagate_types(prog, c, perr, type, rules);
 
                struct type *ret = __propagate_types(prog, c, perr, type, rules);
 
-               if (c->parse_error)
+               if (c->parse_error > pre_err)
                        *perr |= Efail;
                return ret;
        }
                        *perr |= Efail;
                return ret;
        }
@@ -2619,7 +2620,7 @@ function will be needed.
                                propagate_types(f->init, c, &perr, f->f.type, 0);
                        } while (perr & Eretry);
                        if (perr & Efail)
                                propagate_types(f->init, c, &perr, f->f.type, 0);
                        } while (perr & Eretry);
                        if (perr & Efail)
-                               c->parse_error = 1;     // NOTEST
+                               c->parse_error += 1;    // NOTEST
                }
 
                t->structure.nfields = cnt;
                }
 
                t->structure.nfields = cnt;
@@ -4953,7 +4954,7 @@ constants.
                                                v->var->type, 0);
                        } while (perr & Eretry);
                        if (perr & Efail)
                                                v->var->type, 0);
                        } while (perr & Eretry);
                        if (perr & Efail)
-                               c->parse_error = 1;
+                               c->parse_error += 1;
                        else {
                                struct value res = interp_exec(
                                        c, vb->right, &v->var->type);
                        else {
                                struct value res = interp_exec(
                                        c, vb->right, &v->var->type);
@@ -5190,7 +5191,7 @@ is a bit more interesting at this level.
                                propagate_types(b->left, c, &perr, Tnone, 0);   // NOTEST
                        }
                        if (perr & Efail)
                                propagate_types(b->left, c, &perr, Tnone, 0);   // NOTEST
                        }
                        if (perr & Efail)
-                               c->parse_error = 1;
+                               c->parse_error += 1;
                }
 
                return !c->parse_error;
                }
 
                return !c->parse_error;
@@ -5211,12 +5212,12 @@ is a bit more interesting at this level.
                        progp = var_value(c, mainv);
                if (!progp || !progp->function) {
                        fprintf(stderr, "oceani: no main function found.\n");
                        progp = var_value(c, mainv);
                if (!progp || !progp->function) {
                        fprintf(stderr, "oceani: no main function found.\n");
-                       c->parse_error = 1;
+                       c->parse_error += 1;
                        return;
                }
                if (!analyse_main(mainv->type, c)) {
                        fprintf(stderr, "oceani: main has wrong type.\n");
                        return;
                }
                if (!analyse_main(mainv->type, c)) {
                        fprintf(stderr, "oceani: main has wrong type.\n");
-                       c->parse_error = 1;
+                       c->parse_error += 1;
                        return;
                }
                al = mainv->type->function.params;
                        return;
                }
                al = mainv->type->function.params;