]> ocean-lang.org Git - ocean/commitdiff
parsergen: allow $<1 to be used for structs as well as pointer.
authorNeilBrown <neil@brown.name>
Sat, 15 Jun 2019 22:25:23 +0000 (08:25 +1000)
committerNeilBrown <neil@brown.name>
Sat, 15 Jun 2019 22:25:23 +0000 (08:25 +1000)
A future patch will want to use this for non-pointers, so make it
work - it is more consistent this way anyway.

Also: update to parsers to use $< where possible.

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

index 55a0fe65a468a9d7217e28fedc51852c36b401b5..540ecd22584868f832ac6b505b48b8088464ed0d 100644 (file)
@@ -154,7 +154,7 @@ $*statement
                | NEWLINE }
        Block -> Open Statementlist Close ${ $0 = $<2; }$
                | Open SimpleStatements } ${ $0 = $<2; }$
-               | : Statementlist ${ $0 = $2; $2 = NULL; }$
+               | : Statementlist ${ $0 = $<2; }$
 
        SimpleStatements -> SimpleStatements ; SimpleStatement ${
                        {
@@ -224,7 +224,7 @@ $*expression
                                $0->left = $<1;
                                $0->right = $<3;
                        }$
-                   | Term ${ $0 = $1; $1 = NULL; }$
+                   | Term ${ $0 = $<1; }$
        Term -> Term * Factor ${
                                $0 = calloc(1, sizeof(struct expression));
                                $0->op = $2.txt;
@@ -237,7 +237,7 @@ $*expression
                                $0->left = $<1;
                                $0->right = $<3;
                        }$
-             | Factor ${ $0 = $1; $1 = NULL; }$
+             | Factor ${ $0 = $<1; }$
        Factor -> IDENTIFIER ${
                                $0 = calloc(1, sizeof(struct expression));
                                $0->op = $1.txt;
index 6d291312547f0aad1ddadc57ee2affeb7e8b3802..d30275e4e4d383a22905acd1e415c72d89fc56de 100644 (file)
@@ -2112,10 +2112,13 @@ automatically freed.  This is equivalent to assigning `NULL` to the pointer.
                fputs("\n", f);
                for (i = 0; i < p->body_size; i++) {
                        if (p->body[i]->struct_name.txt &&
-                           p->body[i]->isref &&
-                           used[i])
+                           used[i]) {
                                // assume this has been copied out
-                               fprintf(f, "\t\t*(void**)body[%d] = NULL;\n", i);
+                               if (p->body[i]->isref)
+                                       fprintf(f, "\t\t*(void**)body[%d] = NULL;\n", i);
+                               else
+                                       fprintf(f, "\t\tmemset(body[%d], 0, sizeof(struct %.*s));\n", i, p->body[i]->struct_name.len, p->body[i]->struct_name.txt);
+                       }
                }
                free(used);
        }