[Nasm-commits] [nasm:defid] preproc: add %[i]defid support

nasm-bot for Keith Kanios keith at kanios.net
Thu Jun 4 19:56:21 PDT 2020


Commit-ID:  e0725dc769b6b375466e5d1245d3fa1be0087c91
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=e0725dc769b6b375466e5d1245d3fa1be0087c91
Author:     Keith Kanios <keith at kanios.net>
AuthorDate: Sun, 12 Jul 2009 23:39:04 -0500
Committer:  Keith Kanios <keith at kanios.net>
CommitDate: Sun, 12 Jul 2009 23:39:04 -0500

preproc: add %[i]defid support



---
 pptok.dat |  2 ++
 preproc.c | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/pptok.dat b/pptok.dat
index 48b55af1..4edde848 100644
--- a/pptok.dat
+++ b/pptok.dat
@@ -50,6 +50,7 @@
 %assign
 %clear
 %define
+%defid
 %defstr
 %depend
 %elif*
@@ -64,6 +65,7 @@
 %fatal
 %iassign
 %idefine
+%idefid
 %idefstr
 %if*
 %imacro
diff --git a/preproc.c b/preproc.c
index e549b795..40464d43 100644
--- a/preproc.c
+++ b/preproc.c
@@ -2959,6 +2959,47 @@ static int do_directive(Token * tline)
 	free_tlist(origline);
         return DIRECTIVE_FOUND;
 
+	case PP_DEFID:
+	case PP_IDEFID:
+		casesense = (i == PP_IDEFID);
+
+		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",
+				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;
+
+		while (tok_type_(tline, TOK_WHITESPACE))
+			tline = delete_Token(tline);
+			
+		p = detoken(tline, false);
+		if (tok_type_(tline, TOK_STRING)) {
+			macro_start = new_Token(NULL, TOK_ID, p+1, strlen(p)-2);
+		} else {
+			macro_start = new_Token(NULL, TOK_ID, p, strlen(p));
+		}
+		nasm_free(p);
+
+		/*
+		 * We now have a macro name, an implicit parameter count of
+		 * zero, and an id token to use as an expansion. Create
+		 * and store an SMacro.
+		 */
+		define_smacro(ctx, mname, casesense, 0, macro_start);
+		free_tlist(origline);
+		return DIRECTIVE_FOUND;
+
     case PP_DEFSTR:
     case PP_IDEFSTR:
 	casesense = (i == PP_DEFSTR);


More information about the Nasm-commits mailing list