From: NeilBrown Date: Sat, 20 Nov 2021 00:50:55 +0000 (+1100) Subject: oceani: record if a variable declaration was given an explicit type X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=0897423423ea2704abdfd35dc58065d12d9f7386 oceani: record if a variable declaration was given an explicit type The type may be determined at the same place as the declaration, yet still not be explicit. To ensure correct output when printing code, record what was found. Signed-off-by: NeilBrown --- diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index e3c8291..a421167 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -2771,6 +2771,10 @@ because it really is the same variable no matter where it appears. When a variable is used, we need to remember to follow the `->merged` link to find the primary instance. +When a variable is declared, it may or may not be given an explicit +type. We need to record which so that we can report the parsed code +correctly. + ###### exec type Xvar, @@ -2780,6 +2784,9 @@ link to find the primary instance. struct variable *var; }; +###### variable fields + int explicit_type; + ###### Grammar $TERM : :: @@ -2824,6 +2831,7 @@ link to find the primary instance. v->where_decl = $0; v->where_set = $0; v->type = $explicit_type = 1; } else { v = var_ref(c, $1.txt); $0->var = v; @@ -2842,6 +2850,7 @@ link to find the primary instance. v->where_set = $0; v->type = $constant = 1; + v->explicit_type = 1; } else { v = var_ref(c, $1.txt); $0->var = v; @@ -4031,13 +4040,13 @@ it is declared, and error will be raised as the name is created as print_exec(b->left, indent, bracket); if (cast(var, b->left)->var->constant) { printf("::"); - if (v->where_decl == v->where_set) { + if (v->explicit_type) { type_print(v->type, stdout); printf(" "); } } else { printf(":"); - if (v->where_decl == v->where_set) { + if (v->explicit_type) { type_print(v->type, stdout); printf(" "); }