From 025b04b80f75fd004da2b5e884b35233ede2f6f5 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 20 Nov 2021 11:37:52 +1100 Subject: [PATCH] parsergen: avoid creating extra line in code blocks. When performing coverage analysis, it is important that the line numbers seen in the .c file are fairly accurate. Currently we a lines to the end of a code block, and they appear to have line numbers that correspond to whatever appears after the code block. This is confusing. So put all that extra code on the last line (matching the }$). Also switch back to "gen_reduce" immediately after the code block. Signed-off-by: NeilBrown --- csrc/oceani-tests.mdc | 2 +- csrc/oceani.mdc | 12 ++++++------ csrc/parsergen.mdc | 7 ++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index 7a40817..1d7282d 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -97,7 +97,7 @@ arguments separated from the name by commas. For each test, there is a section ## valgrind test code @[ -n "$$SKIP_COVERAGE_CHECK" ] || awk '/NOTEST/ { next } /^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \ END {printf "coverage: %6.2f%%\n", ran * 100 / (ran + skip); \ - if (ran < (ran + skip) *0.968) exit(1) }' \ + if (ran < (ran + skip) *0.973) exit(1) }' \ coverage/oceani.mdc.gcov coverage_oceani: oceani.c diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index c2a19ce..f41e8fd 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -2346,7 +2346,7 @@ function will be needed. | ERROR ${ tok_err(c, "Syntax error in struct field", &$1); }$ Field -> IDENTIFIER : Type = Expression ${ { - int ok; // UNTESTED + int ok; $0 = calloc(1, sizeof(struct fieldlist)); $0->f.name = $1.txt; @@ -2375,9 +2375,9 @@ function will be needed. static void structure_print_type(struct type *t, FILE *f); ###### value functions - static void structure_print_type(struct type *t, FILE *f) // UNTESTED - { // UNTESTED - int i; // UNTESTED + static void structure_print_type(struct type *t, FILE *f) + { + int i; fprintf(f, "struct %.*s\n", t->name.len, t->name.txt); @@ -2398,8 +2398,8 @@ function will be needed. } ###### print type decls - { // UNTESTED - struct type *t; // UNTESTED + { + struct type *t; int target = -1; while (target != 0) { diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index e6dcccb..02abed3 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -2284,17 +2284,17 @@ transformed, and will cause an error when the code is compiled. } c -= 1; } - fputs("\n", f); for (i = 0; i < p->body_size; i++) { if (p->body[i]->struct_name.txt && used[i]) { // assume this has been copied out if (p->body[i]->isref) - fprintf(f, "\t\t*(void**)body[%d] = NULL;\n", i); + fprintf(f, "\t\t*(void**)body[%d] = NULL;", 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); + fprintf(f, "\t\tmemset(body[%d], 0, sizeof(struct %.*s));", i, p->body[i]->struct_name.len, p->body[i]->struct_name.txt); } } + fputs("\n", f); free(used); } @@ -2320,6 +2320,7 @@ transformed, and will cause an error when the code is compiled. if (p->code.txt) { fprintf(f, "#line %d \"%s\"\n", p->code_line, file); gen_code(p, f, g); + fprintf(f, "#line 7 \"gen_reduce\"\n"); } if (p->head->struct_name.txt) -- 2.43.0