From 3645752a9fc66724d0b6c8cb6a8d494da0d986fe Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 6 Feb 2018 16:42:01 +1100 Subject: [PATCH] parsergen: record line number of reduce fragments. If there is an error in a code fragment used to handle a 'reduce' action, we need the compiler to report the correct line from the grammar file. This information is easily available from the scanner, we just need to pass it along. Signed-off-by: NeilBrown --- csrc/parsergen.mdc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index 7499e07..97bba42 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -452,6 +452,7 @@ Now we have all the bits we need to parse a full production. struct symbol **body; int body_size; struct text code; + int code_line; ###### symbol fields int first_production; @@ -501,6 +502,7 @@ Now we have all the bits we need to parse a full production. tk = token_next(state); } if (tk.num == TK_open) { + p.code_line = tk.line; p.code = collect_code(state, tk); if (p.code.txt == NULL) { err = "code fragment not closed properly"; @@ -2084,8 +2086,10 @@ automatically freed. This is equivalent to assigning `NULL` to the pointer. struct production *p = g->productions[i]; fprintf(f, "\tcase %d:\n", i); - if (p->code.txt) + if (p->code.txt) { + fprintf(f, "#line %d \"%s\"\n", p->code_line, file); gen_code(p, f, g); + } if (p->head->struct_name.txt) fprintf(f, "\t\tret_size = sizeof(struct %.*s%s);\n", -- 2.43.0