From: Peter Johnson Date: Sat, 7 Oct 2006 17:27:56 +0000 (-0000) Subject: Fix error/warnings in the NASM preprocessor to reference the correct line X-Git-Tag: v0.6.0~136 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4bf0ef0ab46e046007d384d9a12c38118d6ba48e;p=yasm Fix error/warnings in the NASM preprocessor to reference the correct line number, rather than the last parsed line number. Also improve "cannot reference symbol" error a bit, to include the symbol name. svn path=/trunk/yasm/; revision=1643 --- diff --git a/libyasm/linemgr.c b/libyasm/linemgr.c index 01b10743..fba32738 100644 --- a/libyasm/linemgr.c +++ b/libyasm/linemgr.c @@ -126,6 +126,25 @@ yasm_linemap_set(yasm_linemap *linemap, const char *filename, mapping->line_inc = line_inc; } +unsigned long +yasm_linemap_poke(yasm_linemap *linemap, const char *filename, + unsigned long file_line) +{ + unsigned long line; + line_mapping *mapping = &linemap->map->vector[linemap->map->size-1]; + + linemap->current++; + yasm_linemap_set(linemap, filename, file_line, 0); + + line = linemap->current; + + linemap->current++; + yasm_linemap_set(linemap, mapping->filename, mapping->file_line, + mapping->line_inc); + + return line; +} + yasm_linemap * yasm_linemap_create(void) { diff --git a/libyasm/linemgr.h b/libyasm/linemgr.h index fecf621a..09e9cb3b 100644 --- a/libyasm/linemgr.h +++ b/libyasm/linemgr.h @@ -92,6 +92,18 @@ unsigned long yasm_linemap_goto_next(yasm_linemap *linemap); void yasm_linemap_set(yasm_linemap *linemap, /*@null@*/ const char *filename, unsigned long file_line, unsigned long line_inc); +/** Poke a single file/line association, restoring the original physical + * association starting point. Caution: increments the current virtual line + * twice. + * \param linemap line mapping repository + * \param filename physical file name (if NULL, not changed) + * \param file_line physical line number + * \return The virtual line number of the poked association. + */ +unsigned long yasm_linemap_poke(yasm_linemap *linemap, + /*@null@*/ const char *filename, + unsigned long file_line); + /** Look up the associated physical file and line for a virtual line. * \param linemap line mapping repository * \param line virtual line diff --git a/modules/preprocs/nasm/nasm-eval.c b/modules/preprocs/nasm/nasm-eval.c index b85cfbf5..66c5c6ed 100644 --- a/modules/preprocs/nasm/nasm-eval.c +++ b/modules/preprocs/nasm/nasm-eval.c @@ -382,9 +382,10 @@ static yasm_expr *expr6(void) case TOKEN_ID: case TOKEN_HERE: case TOKEN_BASE: - error(ERR_NONFATAL, "%s not supported", - (i == TOKEN_ID ? "symbol references" : - i == TOKEN_HERE ? "`$'" : "`$$'")); + error(ERR_NONFATAL, + "cannot reference symbol `%s' in preprocessor", + (i == TOKEN_ID ? tokval->t_charptr : + i == TOKEN_HERE ? "$" : "$$")); e = yasm_expr_create_ident(yasm_expr_int(yasm_intnum_create_int(1)), 0); break; diff --git a/modules/preprocs/nasm/nasm-preproc.c b/modules/preprocs/nasm/nasm-preproc.c index b0f8a2eb..681354cc 100644 --- a/modules/preprocs/nasm/nasm-preproc.c +++ b/modules/preprocs/nasm/nasm-preproc.c @@ -123,7 +123,9 @@ nasm_efunc(int severity, const char *fmt, ...) break; } va_end(va); - yasm_errwarn_propagate(cur_errwarns, yasm_linemap_get_current(cur_lm)); + yasm_errwarn_propagate(cur_errwarns, + yasm_linemap_poke(cur_lm, nasm_src_get_fname(), + (unsigned long)nasm_src_get_linnum())); } static yasm_preproc * diff --git a/modules/preprocs/nasm/tests/ifcritical-err.errwarn b/modules/preprocs/nasm/tests/ifcritical-err.errwarn index 7cc27b44..9c617cf7 100644 --- a/modules/preprocs/nasm/tests/ifcritical-err.errwarn +++ b/modules/preprocs/nasm/tests/ifcritical-err.errwarn @@ -1 +1 @@ --:4: symbol references not supported +-:5: cannot reference symbol `teststringlen' in preprocessor diff --git a/modules/preprocs/nasm/tests/nasmpp-nested.errwarn b/modules/preprocs/nasm/tests/nasmpp-nested.errwarn index 101c132e..7a924868 100644 --- a/modules/preprocs/nasm/tests/nasmpp-nested.errwarn +++ b/modules/preprocs/nasm/tests/nasmpp-nested.errwarn @@ -1,3 +1,3 @@ --:26: warning: (WORK_1:4) 0x4 --:26: warning: (WORK_2:4) 0x4 --:26: warning: (DONT_WORK_1:6) 0x4 0x4 +-:27: warning: (WORK_1:4) 0x4 +-:28: warning: (WORK_2:4) 0x4 +-:29: warning: (DONT_WORK_1:6) 0x4 0x4