From b83fd0b9471057d333e7225e91ee2bba4e9c9e9f Mon Sep 17 00:00:00 2001 From: Keith Kanios Date: Tue, 14 Jul 2009 01:04:12 -0500 Subject: [PATCH] preproc: add %[i]deftok support pptok: add %deftok and %ideftok preprocessor directives --- pptok.dat | 2 ++ preproc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/pptok.dat b/pptok.dat index 48b55af1..c7dd9550 100644 --- a/pptok.dat +++ b/pptok.dat @@ -51,6 +51,7 @@ %clear %define %defstr +%deftok %depend %elif* %else @@ -65,6 +66,7 @@ %iassign %idefine %idefstr +%ideftok %if* %imacro %include diff --git a/preproc.c b/preproc.c index e549b795..15a9524a 100644 --- a/preproc.c +++ b/preproc.c @@ -2999,6 +2999,53 @@ static int do_directive(Token * tline) define_smacro(ctx, mname, casesense, 0, macro_start); free_tlist(origline); return DIRECTIVE_FOUND; + + case PP_DEFTOK: + case PP_IDEFTOK: + casesense = (i == PP_DEFTOK); + + tline = tline->next; + skip_white_(tline); + tline = expand_id(tline); + if (!tline || (tline->type != TOK_ID && + (tline->type != TOK_PREPROC_ID || + tline->text[1] != '$'))) { + error(ERR_NONFATAL, + "`%s' expects a macro identifier as first parameter", + pp_directives[i]); + free_tlist(origline); + return DIRECTIVE_FOUND; + } + ctx = get_ctx(tline->text, &mname, false); + last = tline; + 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 (t->type != TOK_STRING) { + error(ERR_NONFATAL, + "`%s` requires string as second parameter", + pp_directives[i]); + free_tlist(tline); + free_tlist(origline); + return DIRECTIVE_FOUND; + } + + nasm_unquote(t->text, NULL); + macro_start = tokenize(t->text); + + /* + * We now have a macro name, an implicit parameter count of + * zero, and a numeric token to use as an expansion. Create + * and store an SMacro. + */ + define_smacro(ctx, mname, casesense, 0, macro_start); + free_tlist(tline); + free_tlist(origline); + return DIRECTIVE_FOUND; case PP_PATHSEARCH: { -- 2.11.4.GIT