]> ocean-lang.org Git - ocean/commitdiff
oceani - discard anon_typelist
authorNeilBrown <neil@brown.name>
Sat, 9 Oct 2021 21:14:04 +0000 (08:14 +1100)
committerNeilBrown <neil@brown.name>
Sat, 9 Oct 2021 21:14:04 +0000 (08:14 +1100)
Don't keep anon types on a separate list, use the same list but given
them an empty name.

This allows us to use add_type() for adding all types.

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

index c6163a679c2ff92c8afbf6b969e0c56854829d3d..bc8880e72ccaf11343c1782ff6d7670db537f114 100644 (file)
@@ -1485,10 +1485,6 @@ different phases of parse, analyse, print, interpret.
 
 Thus far we have arrays and structs.
 
-Some complex types need do not exist in a name table, so they are kept
-on a linked list in the context (`anon_typelist`).  This allows them to
-be freed when parsing is complete.
-
 #### Arrays
 
 Arrays can be declared by giving a size and a type, as `[size]type' so
@@ -1584,14 +1580,14 @@ make a copy of an array with controllable recursive depth.
 
 ###### type grammar
 
-       | [ NUMBER ] Type ${
-               $0 = calloc(1, sizeof(struct type));
-               *($0) = array_prototype;
-               $0->array.member = $<4;
-               $0->array.vsize = NULL;
-               {
+       | [ NUMBER ] Type ${ {
                char tail[3];
                mpq_t num;
+               struct text noname = { "", 0 };
+
+               $0 = add_type(c, noname, &array_prototype);
+               $0->array.member = $<4;
+               $0->array.vsize = NULL;
                if (number_parse(num, tail, $2.txt) == 0)
                        tok_err(c, "error: unrecognised number", &$2);
                else if (tail[0])
@@ -1606,41 +1602,23 @@ make a copy of an array with controllable recursive depth.
                                        &$2);
                        mpq_clear(num);
                }
-               $0->next = c->anon_typelist;
-               c->anon_typelist = $0;
-               }
-       }$
+       } }$
 
        | [ IDENTIFIER ] Type ${ {
                struct variable *v = var_ref(c, $2.txt);
+               struct text noname = { "", 0 };
 
                if (!v)
                        tok_err(c, "error: name undeclared", &$2);
                else if (!v->constant)
                        tok_err(c, "error: array size must be a constant", &$2);
 
-               $0 = calloc(1, sizeof(struct type));
-               *($0) = array_prototype;
+               $0 = add_type(c, noname, &array_prototype);
                $0->array.member = $<4;
                $0->array.size = 0;
                $0->array.vsize = v;
-               $0->next = c->anon_typelist;
-               c->anon_typelist = $0;
        } }$
 
-###### parse context
-
-       struct type *anon_typelist;
-
-###### free context types
-
-       while (context.anon_typelist) {
-               struct type *t = context.anon_typelist;
-
-               context.anon_typelist = t->next;
-               free(t);
-       }
-
 ###### Binode types
        Index,