summaryrefslogtreecommitdiff
path: root/preproc.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2002-04-30 20:56:43 +0000
committerH. Peter Anvin <hpa@zytor.com>2002-04-30 20:56:43 +0000
commit4836e3374e813e6719a8da764bcb20701e4931a0 (patch)
treefb6de06a91a7555f0874c093cba31957af38b9e9 /preproc.c
parent4342239f771ad1c832ca936a25d6ad4df827483b (diff)
downloadnasm-4836e3374e813e6719a8da764bcb20701e4931a0.tar.gz
nasm-4836e3374e813e6719a8da764bcb20701e4931a0.tar.bz2
nasm-4836e3374e813e6719a8da764bcb20701e4931a0.zip
NASM 0.98p3.5
Diffstat (limited to 'preproc.c')
-rw-r--r--preproc.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/preproc.c b/preproc.c
index e16432a..4460907 100644
--- a/preproc.c
+++ b/preproc.c
@@ -8,10 +8,30 @@
* initial version 18/iii/97 by Simon Tatham
*/
-#define br0 '{'
-#define br1 "{"
-#define br2 '}'
-#define br3 "}"
+/* Typical flow of text through preproc
+ *
+ * pp_getline gets tokenised lines, either
+ *
+ * from a macro expansion
+ *
+ * or
+ * {
+ * read_line gets raw text from stdmacpos, or predef, or current input file
+ * tokenise converts to tokens
+ * }
+ *
+ * expand_mmac_params is used to expand %1 etc., unless a macro is being
+ * defined or a false conditional is being processed
+ * (%0, %1, %+1, %-1, %%foo
+ *
+ * do_directive checks for directives
+ *
+ * expand_smacro is used to expand single line macros
+ *
+ * expand_mmacro is used to expand multi-line macros
+ *
+ * detoken is used to convert the line back to text
+ */
#include <stdio.h>
#include <stdlib.h>
@@ -323,8 +343,9 @@ int any_extrastdmac;
/*
* Forward declarations.
*/
+static Token *expand_mmac_params (Token *tline);
static Token *expand_smacro (Token *tline);
-static void make_tok_num(Token *tok, long val);
+static void make_tok_num(Token *tok, long val);
/*
* Macros for safe checking of token pointers, avoid *(NULL)
@@ -1413,7 +1434,7 @@ static int do_directive (Token *tline)
if (emitting(istk->conds->state) || istk->conds->state == COND_NEVER)
istk->conds->state = COND_NEVER;
else {
- j = if_condition(tline->next, i);
+ j = if_condition(expand_mmac_params(tline->next), i);
tline->next = NULL; /* it got freed */
free_tlist (origline);
if (j < 0)
@@ -2279,7 +2300,7 @@ static Token *expand_smacro (Token *tline)
white = 0;
continue; /* parameter loop */
}
- if (ch == br0 &&
+ if (ch == '{' &&
(brackets>0 || (brackets==0 &&
!paramsize[nparam])))
{
@@ -2289,7 +2310,7 @@ static Token *expand_smacro (Token *tline)
continue; /* parameter loop */
}
}
- if (ch == br2 && brackets>0)
+ if (ch == '}' && brackets>0)
if (--brackets == 0) {
brackets = -1;
continue; /* parameter loop */
@@ -2966,7 +2987,6 @@ void pp_include_path (char *path)
i = nasm_malloc(sizeof(IncPath));
i->path = nasm_strdup(path);
i->next = ipath;
-
ipath = i;
}