From e75331cc097fd45e6d8408204a0eee8db661754d Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Sat, 9 Nov 2013 12:02:15 +0400 Subject: [PATCH] BR3392270: preproc: Handle all token chains in mmacro params range A typical example is | | %macro m0 0-* | %rep %0 | m0 arg is %1 | %rotate 1 | %endrep | %endmacro | | %macro m1 0-* | m0 %{1:-1} | %endmacro | | m1 a=b, c=d If passed with nasm -E the output must be like m0 arg is a=b m0 arg is c=d http://bugzilla.nasm.us/show_bug.cgi?id=3392270 Signed-off-by: Cyrill Gorcunov --- preproc.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/preproc.c b/preproc.c index b878e4b1..f781f956 100644 --- a/preproc.c +++ b/preproc.c @@ -3799,19 +3799,28 @@ static Token *expand_mmac_params_range(MMacro *mac, Token *tline, Token ***last) fst--, lst--; /* - * it will be at least one token + * It will be at least one token. Note we + * need to scan params until separator, otherwise + * only first token will be passed. */ tm = mac->params[(fst + mac->rotate) % mac->nparam]; - t = new_Token(NULL, tm->type, tm->text, 0); - head = t, tt = &t->next; + head = new_Token(NULL, tm->type, tm->text, 0); + tt = &head->next, tm = tm->next; + while (tok_isnt_(tm, ",")) { + t = new_Token(NULL, tm->type, tm->text, 0); + *tt = t, tt = &t->next, tm = tm->next; + } + if (fst < lst) { for (i = fst + 1; i <= lst; i++) { t = new_Token(NULL, TOK_OTHER, ",", 0); *tt = t, tt = &t->next; j = (i + mac->rotate) % mac->nparam; tm = mac->params[j]; - t = new_Token(NULL, tm->type, tm->text, 0); - *tt = t, tt = &t->next; + while (tok_isnt_(tm, ",")) { + t = new_Token(NULL, tm->type, tm->text, 0); + *tt = t, tt = &t->next, tm = tm->next; + } } } else { for (i = fst - 1; i >= lst; i--) { @@ -3819,8 +3828,10 @@ static Token *expand_mmac_params_range(MMacro *mac, Token *tline, Token ***last) *tt = t, tt = &t->next; j = (i + mac->rotate) % mac->nparam; tm = mac->params[j]; - t = new_Token(NULL, tm->type, tm->text, 0); - *tt = t, tt = &t->next; + while (tok_isnt_(tm, ",")) { + t = new_Token(NULL, tm->type, tm->text, 0); + *tt = t, tt = &t->next, tm = tm->next; + } } }