diff options
author | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-06-25 22:15:00 -0700 |
---|---|---|
committer | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-06-25 22:15:00 -0700 |
commit | 8884fc60a204b8b6d0322c76f1ca294472a32498 (patch) | |
tree | 7f6cadf79240465ebf23bef89f4457723b45c901 | |
parent | a227b43b8a20f79d322249e29d24fbb4b1dd9904 (diff) | |
download | nasm-8884fc60a204b8b6d0322c76f1ca294472a32498.tar.gz |
preproc: make %(i)deftok a bit more flexible
Make %(i)deftok capable of handling more than one input string, and
allow unquoted strings, a.k.a. bare tokens.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
-rw-r--r-- | asm/preproc.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/asm/preproc.c b/asm/preproc.c index 72d3c447..2244157f 100644 --- a/asm/preproc.c +++ b/asm/preproc.c @@ -504,11 +504,11 @@ static void nasm_unquote_pp(char *qstr, enum preproc_token directive) } /* - * In-place reverse a list of tokens. + * In-place reverse a list of tokens; optionally link the last + * (formerly first) element to a different token. */ -static Token *reverse_tokens(Token *t) +static Token *reverse_tokens(Token *t, Token *prev) { - Token *prev = NULL; Token *next; while (t) { @@ -905,6 +905,9 @@ static Token *tokenize(char *line) Token *list = NULL; Token *t, **tail = &list; + if (!line) + return NULL; + while (*line) { p = line; if (*p == '%') { @@ -1765,7 +1768,7 @@ static bool if_condition(Token * tline, enum preproc_token ct) { enum pp_conditional i = PP_COND(ct); bool j; - Token *t, *tt, **tptr, *origline; + Token *t, *ttwhi, **tptr, *origline; struct tokenval tokval; expr *evalresult; enum pp_token_type needtype; @@ -3292,6 +3295,9 @@ issue_error: case PP_DEFTOK: case PP_IDEFTOK: + { + char *xstr, *ystr; + casesense = (i == PP_DEFTOK); tline = tline->next; @@ -3311,17 +3317,19 @@ issue_error: tline = expand_smacro(tline->next); last->next = NULL; - t = tline; - while (tok_type_(t, TOK_WHITESPACE)) - t = t->next; - /* t should now point to the string */ - if (!tok_type_(t, TOK_STRING)) { - nasm_error(ERR_NONFATAL, - "`%s` requires string as second parameter", - pp_directives[i]); - free_tlist(tline); - free_tlist(origline); - return DIRECTIVE_FOUND; + xstr = NULL; + + for (t = tline; t; t = t->next) { + if (tok_type_(t, TOK_COMMENT)) + break; + + if (!t->text) + continue; + + if (tok_type_(t, TOK_STRING)) + nasm_unquote_pp(t->text, i); + + xstr = nasm_strappend(xstr, t->text); } /* @@ -3329,8 +3337,8 @@ issue_error: * are stored with the token stream reversed, so we have to * reverse the output of tokenize(). */ - nasm_unquote_pp(t->text, i); - macro_start = reverse_tokens(tokenize(t->text)); + macro_start = reverse_tokens(tokenize(xstr)); + nasm_free(xstr); /* * We now have a macro name, an implicit parameter count of @@ -5024,7 +5032,7 @@ pp_reset(const char *file, int apass, StrList **deplist) dephead = deplist; nasm_add_string_to_strlist(dephead, file); - + /* * Define the __PASS__ macro. This is defined here unlike * all the other builtins, because it is special -- it varies between |