aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/preprocessor9.c
diff options
authorAlexander Viro <viro@parcelfarce.linux.theplanet.co.uk>2004-06-08 08:25:26 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:02:05 -0700
commit2821582af8b456aef8f273f2a6a586ef5cfc3544 (patch)
treed3fd8cb1ec7a88b5be6f01455ef042aa566fdab7 /validation/preprocessor9.c
parent76bcdc63f8e4b7e2c108f9828284a4ee03021770 (diff)
downloadsparse-dev-2821582af8b456aef8f273f2a6a586ef5cfc3544.tar.gz
[PATCH] more sparse fixes (body parsing, beginning of ## handling)
> 1) no ## in the beginning or end of body. [6.10.3.3(1)] > It's a warning, recovery consists in dropping them at #define time. Fixed in the patch I'm testing, and I was wrong about proper recovery - better ignore the entire definition than go on with mangled one. > 2) ## that comes from argument does *not* have a special meaning; > only one from the body does. [6.10.3.3(3)] Fixed. > 3) assuming left-to-right order of evaluation for ## (we are free > to choose any [6.10.3.3(3)] and left-to-right is much easier when we get > to merging tokens), if ## immediately follows another ## it can be treated > as not having a special meaning (it will be merged with whatever precedes > the first one and even if result of merge will be "##", it won't have a > special meaning). IOW, in > a ## b ## ## c ## ## ## d > the 1st, 2nd, 4th and 6th ## will concatenate; 3rd and 5th ones will be > merge arguments and won't merge anything themselves. Fixed. The rest is not - it will be a separate patch. BTW, there's another couple of bugs - see preprocessor9.c and preprocessor10.c for the stuff that triggers them. Parsing of macro bodies should be OK by now; the only missing check is "the only place where __VA_ARGS__ can occur is in the body of macro with argument list ending on ellipsis" and that will be dealt with later. We get three new kinds of tokens - TOKEN_QUOTED_ARGUMENT (unexpanded arguments next to ##), TOKEN_STR_ARGUMENT (#<argument>) and TOKEN_CONCAT (concatenation operator). When we go through the body of macro at #define time, we a) decide which ## will be operators there (see (3) above) and set the type of those to TOKEN_CONCAT; retokenize() is looking for that token_type() now instead of doing match_op(). b) collapse OP[#] IDENT[argument] to a single token - STR_ARGUMENT[argnum]. expand_arguments() looks for that token type instead of messing with match_op() + check that the next one is an argument. c) mark the rest of arguments either as QUOTED_ARGUMENT or MACRO_ARGUMENT, depending on whether they have a concatenation as neighbor or not; expand_arguments() looks for that to decide if expand_one_arg() should do expansion when subsitituting (instead of messing with checking neighbors). All that stuff is done in one pass and comes pretty much for free - see handle_define() for details. And we get a nice payoff at expansion time for that (will get more when we get to collecting the information on arguments uses). preprocessor{8,9,10}.c added; the first one shows the stuff fixed by now; other two are still not handled correctly. I don't see any regression - neither on validation/* stuff nor on full kernel build.
Diffstat (limited to 'validation/preprocessor9.c')
-rw-r--r--validation/preprocessor9.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/validation/preprocessor9.c b/validation/preprocessor9.c
new file mode 100644
index 00000000..76d6e414
--- /dev/null
+++ b/validation/preprocessor9.c
@@ -0,0 +1,10 @@
+/*
+ * Should result in
+ * #define X 1
+ * X
+ * since only # in the input stream marks beginning of preprocessor command
+ * and here we get it from macro expansion.
+ */
+#define A # define X 1
+A
+X