]> ocean-lang.org Git - ocean/blobdiff - csrc/oceani.mdc
oceani: add type entry for new structs early.
[ocean] / csrc / oceani.mdc
index c80c99262004c6b39f82ca924e7e513fb3fddfaf..e032a7d5a268e76c5f6e459e666859640fbcab22 100644 (file)
@@ -2917,24 +2917,31 @@ function will be needed.
        }
 
 ###### top level grammar
-       DeclareStruct -> struct IDENTIFIER FieldBlock Newlines ${ {
-               struct type *t;
-               t = find_type(c, $ID.txt);
-               if (!t)
-                       t = add_type(c, $ID.txt, &structure_prototype);
-               else if (t->size >= 0) {
+       $*type
+       StructName -> IDENTIFIER ${ {
+               struct type *t = find_type(c, $ID.txt);
+
+               if (t && t->size >= 0) {
                        tok_err(c, "error: type already declared", &$ID);
                        tok_err(c, "info: this is location of declartion", &t->first_use);
-                       /* Create a new one - duplicate */
-                       t = add_type(c, $ID.txt, &structure_prototype);
-               } else {
-                       struct type tmp = *t;
-                       *t = structure_prototype;
-                       t->name = tmp.name;
-                       t->next = tmp.next;
+                       t = NULL;
                }
-               t->structure.field_list = $<FB;
+               if (!t)
+                       t = add_type(c, $ID.txt, NULL);
                t->first_use = $ID;
+               $0 = t;
+       } }$
+       $void
+       DeclareStruct -> struct StructName FieldBlock Newlines ${ {
+               struct type *t = $<SN;
+               struct type tmp = *t;
+
+               *t = structure_prototype;
+               t->name = tmp.name;
+               t->next = tmp.next;
+               t->first_use = tmp.first_use;
+
+               t->structure.field_list = $<FB;
        } }$
 
        $*fieldlist
@@ -3166,8 +3173,8 @@ anything in the heap or on the stack.  A reference can be assigned
        | @ IDENTIFIER ${ {
                struct type *t = find_type(c, $ID.txt);
                if (!t) {
-                       t = add_type(c, $ID.txt, NULL);
-                       t->first_use = $ID;
+                       t = add_type(c, $ID.txt, NULL); // UNTESTED
+                       t->first_use = $ID;     // UNTESTED
                }
                $0 = find_anon_type(c, &reference_prototype, "@%.*s",
                                    $ID.txt.len, $ID.txt.txt);
@@ -4801,11 +4808,7 @@ be declared at any time.
                        return Tnone;
 
                if (t) {
-                       if (propagate_types(b->right, c, perr_local, t, 0) != t &&
-                           *perr_local & Efail)
-                               if (b->left->type == Xvar)
-                                       type_err(c, "info: variable '%v' was set as %1 here.",
-                                                cast(var, b->left)->var->where_set, t, rules, NULL);
+                       propagate_types(b->right, c, perr_local, t, 0);
                } else {
                        t = propagate_types(b->right, c, perr_local, NULL, 0);
                        if (t)
@@ -4826,6 +4829,9 @@ be declared at any time.
                }
                if (t && t->dup == NULL && !(*perr_local & Emaycopy))
                        type_err(c, "error: cannot assign value of type %1", b, t, 0, NULL);
+               if (b->left->type == Xvar && (*perr_local & Efail))
+                       type_err(c, "info: variable '%v' was set as %1 here.",
+                                cast(var, b->left)->var->where_set, t, rules, NULL);
                return Tnone;
 
                break;