From 3736895c07537856b3ce035258485dd5cfd8af9a Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 9 May 2016 14:10:32 -0700 Subject: [PATCH] Fix and clean up listing of macro expansion Fix the printing of the macro stack: we need to follow the mstk->next_active list, not mstk->next, and we need to reverse the order so that the highest-level inclusion comes first. Since this should be a rare or at least performance-insensitive operation, do it using simple function recursion. Finally, add an ellipsis before the "from macro" message; it greatly enhances readability. Signed-off-by: H. Peter Anvin --- preproc.c | 24 ++++++++++++++++-------- test/macroerr.asm | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/preproc.c b/preproc.c index fa2dcaf3..e33a6d7d 100644 --- a/preproc.c +++ b/preproc.c @@ -5243,9 +5243,23 @@ static void make_tok_num(Token * tok, int64_t val) tok->type = TOK_NUMBER; } +static void pp_list_one_macro(MMacro *m, int severity) +{ + if (!m) + return; + + /* We need to print the next_active list in reverse order */ + pp_list_one_macro(m->next_active, severity); + + if (m->name && !m->nolist) { + src_set_linnum(m->xline + m->lineno); + src_set_fname(m->fname); + nasm_error(severity, "... from macro `%s' defined here", m->name); + } +} + static void pp_error_list_macros(int severity) { - MMacro *m; int32_t saved_line; const char *saved_fname = NULL; @@ -5253,13 +5267,7 @@ static void pp_error_list_macros(int severity) saved_line = src_get_linnum(); saved_fname = src_get_fname(); - list_for_each(m, istk->mstk) { - if (m->name && !m->nolist) { - src_set_linnum(m->xline + m->lineno); - src_set_fname(m->fname); - nasm_error(severity, "from macro `%s' defined here", m->name); - } - } + pp_list_one_macro(istk->mstk, severity); src_set_fname((char *)saved_fname); src_set_linnum(saved_line); diff --git a/test/macroerr.asm b/test/macroerr.asm index 5f1c93e2..d1be751c 100644 --- a/test/macroerr.asm +++ b/test/macroerr.asm @@ -2,6 +2,7 @@ %macro bluttan 1 mov eax,%1 + blej %1 %endmacro bluttan ptr