summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-02-16 17:01:40 -0800
committerH. Peter Anvin <hpa@zytor.com>2008-02-16 17:01:40 -0800
commit134b94665d0eebfaa8c6c46058eb76188d42582e (patch)
tree82444f5f344685badc9341a73edffdf59c0479fb
parent3f3bd41de017db8e7449f5b1345cd80ab77d2571 (diff)
downloadnasm-2.02rc2.tar.gz
Add %ifempty and variantsnasm-2.02rc2
-rw-r--r--CHANGES1
-rw-r--r--doc/nasmdoc.src9
-rw-r--r--pptok.dat3
-rw-r--r--preproc.c11
-rw-r--r--test/iftoken.asm315
-rwxr-xr-xtest/iftoken.pl40
6 files changed, 308 insertions, 71 deletions
diff --git a/CHANGES b/CHANGES
index 313efa74..2ae2b855 100644
--- a/CHANGES
+++ b/CHANGES
@@ -14,6 +14,7 @@
* New compile date and time standard macros.
* %ifnum now returns true for negative numbers.
* New %iftoken test for a single token.
+* New %ifempty test for empty expansion.
* Add support for the XSAVE instruction group.
* Makefile for Netware/gcc.
* Fix issue with some warnings getting emitted way too many times.
diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src
index ebb0f159..0751655c 100644
--- a/doc/nasmdoc.src
+++ b/doc/nasmdoc.src
@@ -2736,6 +2736,15 @@ not (\c{-} being an operator.)
The usual \i\c{%eliftoken}, \i\c\{%ifntoken}, and \i\c{%elifntoken}
variants are also provided.
+\S{ifempty} \i\c{%ifempty}: Test For Empty Expansion
+
+The conditional assembly construct \c{%ifempty} assembles the
+subsequent code if and only if the expanded parameters do not contain
+any tokens at all, whitespace excepted.
+
+The usual \i\c{%elifempty}, \i\c\{%ifnempty}, and \i\c{%elifnempty}
+variants are also provided.
+
\S{pperror} \i\c{%error}: Reporting \i{User-Defined Errors}
The preprocessor directive \c{%error} will cause NASM to report an
diff --git a/pptok.dat b/pptok.dat
index f9bfb43c..3836fd6c 100644
--- a/pptok.dat
+++ b/pptok.dat
@@ -5,13 +5,14 @@
*
*ctx
*def
+*empty
*id
*idn
*idni
*macro
*num
-*token
*str
+*token
%arg
%assign
%clear
diff --git a/preproc.c b/preproc.c
index b8b6ff2f..3a12fc84 100644
--- a/preproc.c
+++ b/preproc.c
@@ -1584,8 +1584,7 @@ static bool if_condition(Token * tline, enum preproc_token ct)
goto iftype;
iftype:
- tline = expand_smacro(tline);
- t = tline;
+ t = tline = expand_smacro(tline);
while (tok_type_(t, TOK_WHITESPACE) ||
(needtype == TOK_NUMBER &&
@@ -1611,6 +1610,14 @@ static bool if_condition(Token * tline, enum preproc_token ct)
}
break;
+ case PPC_IFEMPTY:
+ t = tline = expand_smacro(tline);
+ while (tok_type_(t, TOK_WHITESPACE))
+ t = t->next;
+
+ j = !t; /* Should be empty */
+ break;
+
case PPC_IF:
t = tline = expand_smacro(tline);
tptr = &t;
diff --git a/test/iftoken.asm b/test/iftoken.asm
index c53c74c5..7bf000c2 100644
--- a/test/iftoken.asm
+++ b/test/iftoken.asm
@@ -1,108 +1,315 @@
- db 'N "1": '
+%define ZMACRO
+%define NMACRO 1
+%define TMACRO 1 2
+ db 'N "":'
+%iftoken
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'C "":'
+%iftoken ; With a comment!
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty ; With a comment!
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'N "ZMACRO":'
+%iftoken ZMACRO
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty ZMACRO
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'C "ZMACRO":'
+%iftoken ZMACRO ; With a comment!
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty ZMACRO ; With a comment!
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'N "NMACRO":'
+%iftoken NMACRO
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty NMACRO
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'C "NMACRO":'
+%iftoken NMACRO ; With a comment!
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty NMACRO ; With a comment!
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'N "TMACRO":'
+%iftoken TMACRO
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty TMACRO
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'C "TMACRO":'
+%iftoken TMACRO ; With a comment!
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty TMACRO ; With a comment!
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'N "1":'
%iftoken 1
- db 'Yes', 10
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty 1
+ db ' empty'
%else
- db 'No', 10
+ db ' nempty'
%endif
- db 'C "1": '
+ db 10
+ db 'C "1":'
%iftoken 1 ; With a comment!
- db 'Yes', 10
+ db ' token'
%else
- db 'No', 10
+ db ' ntoken'
%endif
- db 'N "+1": '
+%ifempty 1 ; With a comment!
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'N "+1":'
%iftoken +1
- db 'Yes', 10
+ db ' token'
%else
- db 'No', 10
+ db ' ntoken'
%endif
- db 'C "+1": '
+%ifempty +1
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'C "+1":'
%iftoken +1 ; With a comment!
- db 'Yes', 10
+ db ' token'
%else
- db 'No', 10
+ db ' ntoken'
%endif
- db 'N "1 2": '
+%ifempty +1 ; With a comment!
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'N "1 2":'
%iftoken 1 2
- db 'Yes', 10
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty 1 2
+ db ' empty'
%else
- db 'No', 10
+ db ' nempty'
%endif
- db 'C "1 2": '
+ db 10
+ db 'C "1 2":'
%iftoken 1 2 ; With a comment!
- db 'Yes', 10
+ db ' token'
%else
- db 'No', 10
+ db ' ntoken'
%endif
- db 'N "1,2": '
+%ifempty 1 2 ; With a comment!
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'N "1,2":'
%iftoken 1,2
- db 'Yes', 10
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty 1,2
+ db ' empty'
%else
- db 'No', 10
+ db ' nempty'
%endif
- db 'C "1,2": '
+ db 10
+ db 'C "1,2":'
%iftoken 1,2 ; With a comment!
- db 'Yes', 10
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty 1,2 ; With a comment!
+ db ' empty'
%else
- db 'No', 10
+ db ' nempty'
%endif
- db 'N "foo": '
+ db 10
+ db 'N "foo":'
%iftoken foo
- db 'Yes', 10
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty foo
+ db ' empty'
%else
- db 'No', 10
+ db ' nempty'
%endif
- db 'C "foo": '
+ db 10
+ db 'C "foo":'
%iftoken foo ; With a comment!
- db 'Yes', 10
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty foo ; With a comment!
+ db ' empty'
%else
- db 'No', 10
+ db ' nempty'
%endif
- db 'N "foo bar": '
+ db 10
+ db 'N "foo bar":'
%iftoken foo bar
- db 'Yes', 10
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty foo bar
+ db ' empty'
%else
- db 'No', 10
+ db ' nempty'
%endif
- db 'C "foo bar": '
+ db 10
+ db 'C "foo bar":'
%iftoken foo bar ; With a comment!
- db 'Yes', 10
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty foo bar ; With a comment!
+ db ' empty'
%else
- db 'No', 10
+ db ' nempty'
%endif
- db 'N "%": '
+ db 10
+ db 'N "%":'
%iftoken %
- db 'Yes', 10
+ db ' token'
%else
- db 'No', 10
+ db ' ntoken'
%endif
- db 'C "%": '
+%ifempty %
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'C "%":'
%iftoken % ; With a comment!
- db 'Yes', 10
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty % ; With a comment!
+ db ' empty'
%else
- db 'No', 10
+ db ' nempty'
%endif
- db 'N "+foo": '
+ db 10
+ db 'N "+foo":'
%iftoken +foo
- db 'Yes', 10
+ db ' token'
%else
- db 'No', 10
+ db ' ntoken'
%endif
- db 'C "+foo": '
+%ifempty +foo
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'C "+foo":'
%iftoken +foo ; With a comment!
- db 'Yes', 10
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty +foo ; With a comment!
+ db ' empty'
%else
- db 'No', 10
+ db ' nempty'
%endif
- db 'N "<<": '
+ db 10
+ db 'N "<<":'
%iftoken <<
- db 'Yes', 10
+ db ' token'
%else
- db 'No', 10
+ db ' ntoken'
%endif
- db 'C "<<": '
+%ifempty <<
+ db ' empty'
+%else
+ db ' nempty'
+%endif
+ db 10
+ db 'C "<<":'
%iftoken << ; With a comment!
- db 'Yes', 10
+ db ' token'
+%else
+ db ' ntoken'
+%endif
+%ifempty << ; With a comment!
+ db ' empty'
%else
- db 'No', 10
+ db ' nempty'
%endif
+ db 10
diff --git a/test/iftoken.pl b/test/iftoken.pl
index bbbb5bcd..498b0527 100755
--- a/test/iftoken.pl
+++ b/test/iftoken.pl
@@ -1,19 +1,31 @@
#!/usr/bin/perl
-@list = ('1', '+1', '1 2', '1,2', 'foo', 'foo bar', '%', '+foo', '<<');
+@list = ('', 'ZMACRO', 'NMACRO', 'TMACRO', '1', '+1', '1 2', '1,2',
+ 'foo', 'foo bar', '%', '+foo', '<<');
+@tests = ('token', 'empty');
-foreach $t (@list) {
- print "\tdb 'N \"$t\": '\n";
- print "%iftoken $t\n";
- print "\tdb 'Yes', 10\n";
- print "%else\n";
- print "\tdb 'No', 10\n";
- print "%endif\n";
+print "%define ZMACRO\n";
+print "%define NMACRO 1\n";
+print "%define TMACRO 1 2\n";
- print "\tdb 'C \"$t\": '\n";
- print "%iftoken $t ; With a comment!\n";
- print "\tdb 'Yes', 10\n";
- print "%else\n";
- print "\tdb 'No', 10\n";
- print "%endif\n";
+foreach $x (@list) {
+ print "\tdb 'N \"$x\":'\n";
+ foreach $t (@tests) {
+ print "%if$t $x\n";
+ print "\tdb ' $t'\n";
+ print "%else\n";
+ print "\tdb ' n$t'\n";
+ print "%endif\n";
+ }
+ print "\tdb 10\n";
+
+ print "\tdb 'C \"$x\":'\n";
+ foreach $t (@tests) {
+ print "%if$t $x ; With a comment!\n";
+ print "\tdb ' $t'\n";
+ print "%else\n";
+ print "\tdb ' n$t'\n";
+ print "%endif\n";
+ }
+ print "\tdb 10\n";
}