]> ocean-lang.org Git - ocean/commitdiff
oceani: record if a variable declaration was given an explicit type
authorNeilBrown <neil@brown.name>
Sat, 20 Nov 2021 00:50:55 +0000 (11:50 +1100)
committerNeilBrown <neil@brown.name>
Sat, 20 Nov 2021 00:50:55 +0000 (11:50 +1100)
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 <neil@brown.name>
csrc/oceani.mdc

index e3c8291572d9d82089c3f74538d2c5406bf86050..a421167632746e9525716f96e3729983ff8022a4 100644 (file)
@@ -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 = $<Type;
+                       v->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 = $<Type;
                        v->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(" ");
                        }