preproc: add %[i]deftok support

pptok: add %deftok and %ideftok preprocessor directives
This commit is contained in:
Keith Kanios 2009-07-14 01:04:12 -05:00
parent 340ee009d6
commit b83fd0b947
2 changed files with 49 additions and 0 deletions

@ -51,6 +51,7 @@
%clear
%define
%defstr
%deftok
%depend
%elif*
%else
@ -65,6 +66,7 @@
%iassign
%idefine
%idefstr
%ideftok
%if*
%imacro
%include

@ -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:
{