From f8c00ecff941f5f86b4d54dd73cac3680684a11e Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 16 Jun 2019 08:25:23 +1000 Subject: [PATCH] parsergen: allow $<1 to be used for structs as well as pointer. 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 --- csrc/indent_test.mdc | 6 +++--- csrc/parsergen.mdc | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/csrc/indent_test.mdc b/csrc/indent_test.mdc index 55a0fe6..540ecd2 100644 --- a/csrc/indent_test.mdc +++ b/csrc/indent_test.mdc @@ -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; diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index 6d29131..d30275e 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -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); } -- 2.43.0