aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/pre-process.c
AgeCommit message (Collapse)AuthorFilesLines
2017-08-31Sparse preprocessing bug with zero-arg variadic macrosAl Viro1-1/+3
On Thu, Aug 31, 2017 at 09:54:33PM +0100, Al Viro wrote: > What a mess... Note that for non-vararg it *is* the right interpretation > (with #define A(x) [x] we will have A() interpreted as "empty token sequence > as the only argument", not "no arguments given"). For vararg case we > normally do not need to distinguish "not given" and "empty" - the only > thing that cares is exactly the ,## kludge. There with > #define B(x,...) [x,##__VA_ARGS__] > B(1) and B(1,) yield [1] and [1,] resp. And for everything other than > "just ..." we even get it right... > > I see what's going on there; will post a fix in a few. Fix macro argument parsing for (...) case Nasty corner case for the sake of ,##__VA_ARGS__ perversion - for something like #define A(x,...) [x,##__VA_ARGS] we want A(1) to expand to [1] and A(1,) - to [1,]. In other words, "no vararg given" and "vararg empty" are different and need to be distinguished. Unfortunately, in case when there was nothing but vararg we got it wrong - #define A(...) ,##__VA_ARGS ended up with A() interpreted as "one empty argument" (as it would in non-vararg case) rather than "zero arguments". Reported-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Christopher Li <sparse@chrisli.org>
2017-05-19teach sparse how to dump macro definitionsLuc Van Oostenryck1-0/+55
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2015-02-08Teach sparse about the __COUNTER__ predefined macroLuc Van Oostenryck1-0/+4
__COUNTER__ macro is expanded to a sequential number starting from 0. This is sometimes used to declare unique variable names. Implement support for __COUNTER__ in sparse including a set of small test programs for the test suite. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Acked-by: Sam Ravnborg <sam@ravnborg.org> Reviewed-by: Josh Triplett <josh@joshtriplett.org> Tested-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
2015-02-06Make macro expanded string immutableChristopher Li1-5/+17
The string is shared between different macro expand. It is wrong to modify the string in place if the string is used in a macro. Avoid overwriting the string in that case. Reported-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Tested-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
2013-11-29sparse: Relicense under the MIT licenseFranz Schrober1-1/+17
The old code was relicensed by Novafora Corporation, successor in interest to Transmeta Corporation, in 2009. Other authors were also asked about the change of their contributions to the MIT license and all with copyrightable changes agreed to it. Signed-off-by: Franz Schrober <franzschrober@yahoo.de> Acked-by: Adam DiCarlo <adam@bikko.org> Acked-by: Al Viro <viro@ZenIV.linux.org.uk> Acked-by: Alberto Bertogli <albertito@blitiri.com.ar> Acked-by: Alecs King <alecs@perlchina.org> Acked-by: Alexander Shishkin <alexander.shishckin@gmail.com> Acked-by: Alexey Dobriyan <adobriyan@gmail.com> Acked-by: Alexey Zaytsev <alexey.zaytsev@gmail.com> Acked-by: Andries E. Brouwer <Andries.Brouwer@cwi.nl> Acked-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Acked-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Acked-by: Ben Pfaff <blp@nicira.com> Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Acked-by: Bernd Petrovitsch <bernd@petrovitsch.priv.at> Acked-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> Acked-by: Blue Swirl <blauwirbel@gmail.com> Acked-by: Chris Forbes <chrisf@ijw.co.nz> Acked-by: Chris Wedgwood <cw@f00f.org> Acked-by: Christopher Li <sparse@chrisli.org> Acked-by: Damien Lespiau <damien.lespiau@gmail.com> Acked-by: Dan Carpenter <error27@gmail.com> Acked-by: Dan McGee <dan@archlinux.org> Acked-by: Daniel De Graaf <danieldegraaf@gmail.com> Acked-by: Daniel Sheridan <dan.sheridan@postman.org.uk> Acked-by: Dave Jones <davej@redhat.com> Acked-by: David Given <dg@cowlark.com> Acked-by: David Miller <davem@redhat.com> Acked-by: David Mosberger-Tang <dmosberger@gmail.com> Acked-by: David Olien <David.Olien@lsi.com> Acked-by: Diego Elio Pettenò <flameeyes@flameeyes.eu> Acked-by: Emil Medve <Emilian.Medve@Freescale.com> Acked-by: Ethan Jackson <jacksone@nicira.com> Acked-by: Florian Fainelli <f.fainelli@gmail.com> Acked-by: Frank Zago <fzago@systemfabricworks.com> Acked-by: Frederic Crozat <fcrozat@suse.com> Acked-by: Geoff Johnstone <geoff.johnstone@gmail.com> Acked-by: Hannes Eder <hannes@hanneseder.net> Acked-by: Jan Pokorný <pokorny_jan@seznam.cz> Acked-by: Jeff Garzik <jgarzik@redhat.com> Acked-by: Jiri Slaby <jslaby@suse.cz> Acked-by: Joe Perches <joe@perches.com> Acked-by: Joel Soete <rubisher@scarlet.be> Acked-by: Johannes Berg <johannes@sipsolutions.net> Acked-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net> Acked-by: Josh Triplett <josh@kernel.org> Acked-by: Kamil Dudka <kdudka@redhat.com> Acked-by: Kim Phillips <kim.phillips@linaro.org> Acked-by: KOSAKI Motohiro <kosaki.motohiro@gmail.com> Acked-by: Kovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Acked-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Acked-by: Martin Nagy <nagy.martin@gmail.com> Acked-by: Masatake YAMATO <yamato@redhat.com> Acked-by: Mauro Dreissig <mukadr@gmail.com> Acked-by: Michael Büsch <m@bues.ch> Acked-by: Michael Stefaniuc <mstefani@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Mika Kukkonen <mikukkon@iki.fi> Acked-by: Mike Frysinger <vapier@gentoo.org> Acked-by: Mitesh Shah <Mitesh.Shah@synopsys.com> Acked-by: Morten Welinder <mortenw@gnome.org> Acked-by: Namhyung Kim <namhyung@gmail.com> Acked-by: Nicolas Kaiser <nikai@nikai.net> Acked-by: Oleg Nesterov <oleg@redhat.com> Acked-by: Pavel Roskin <proski@gnu.org> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> Acked-by: Peter Jones <pjones@redhat.com> Acked-by: Peter A Jonsson <pj@sics.se> Acked-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de> Acked-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Acked-by: Randy Dunlap <rdunlap@xenotime.net> Acked-by: Reinhard Tartler <siretart@tauware.de> Ached-by: Richard Knutsson <richard.knutsson@gmail.com> Acked-by: Rob Taylor <rob.taylor@codethink.co.uk> Acked-by: Rui Saraiva <rmpsaraiva@gmail.com> Acked-by: Ryan Anderson <ryan@michonline.com> Acked-by: Sam Ravnborg <sam@ravnborg.org> Acked-by: Samuel Bronson <naesten@gmail.com> Acked-by: Santtu Hyrkkö <santtu.hyrkko@gmail.com> Acked-by: Shakthi Kannan <shakthimaan@gmail.com> Acked-by: Stephen Hemminger <shemminger@linux-foundation.org> Acked-by: Thomas Schmid <Thomas.Schmid@br-automation.com> Acked-by: Tilman Sauerbeck <tilman@code-monkey.de> Acked-by: Vegard Nossum <vegardno@ifi.uio.no> Acked-by: Xi Wang <xi.wang@gmail.com> Acked-by: Yura Pakhuchiy <pakhuchiy@gmail.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
2013-04-21Support #pragma onceJosh Triplett1-0/+9
"#pragma once" acts like a multiple-inclusion guard affecting the entire file, without an associated preprocessor symbol. This allows use of sparse on projects that rely on #pragma once without also using an ifndef-based multiple-inclusion guard, such as systemd; without this change, sparse will get into an include loop. Signed-off-by: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Christopher Li <sparse@chrisli.org>
2013-03-06Larger buffer size for token concatenationChristopher Li1-37/+11
Currently there are a few source file in the kernel can't parse property due to over run of the concatenation buffer. They either have a large string concatnation or huge macro expand. The TRACE macro is a common one. Now show_token_sequence and quote_token_sequence is combined into one function with a bigger buffer. It works for most of the kernel source except the config_data.h. The kernel config is about 70K, larger than the string allocator chunk size. It needs some plumbing work in the allocator before we can allow bigger string token. Signed-off-by: Christopher Li <sparse@chrisli.org>
2013-02-25Get rid of gcc warning about enum valuesChristopher Li1-3/+3
Signed-off-by: Christopher Li <sparse@chrisli.org>
2013-02-12L ## 'a' is valid; so's L ## "a"Al Viro1-1/+26
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2013-02-12switch to delayed handling of escape sequencesAl Viro1-5/+33
#define A(x) #x A('\12') should *not* yield "'\\n'"; the problem is that we are doing the conversion too early. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2013-02-12fix handling of -includeAl Viro1-30/+40
-include foo.h will search not only in the current directory... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2013-02-12simplify handling of newline/whitespace flags in expand()Al Viro1-13/+19
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2012-04-13Fix ,##__VA_ARGS__ kludgeAl Viro1-37/+120
a) it actually allows any number of ##<arg>##... in between, as long as all those args are empty. b) it does *not* allow ## after __VA_ARGS__ - if it's there magic disappears Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2011-05-31Remove set but not used variableChristopher Li1-2/+0
The new gcc complain about set but not used variable. This should make the new gcc happy. Signed-off-by: Christopher Li <sparse@chrisli.org>
2011-04-19Teach 'already_tokenized()' to use the stream name hash tableLinus Torvalds1-3/+5
This replaces the "loop over all streams" with a simple hash lookup. It makes the cost of checking for already tokenized streams basically go away (it could be up to 5% of CPU time, almost entirely due to the "strcmp()" of the name). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Christopher Li <sparse@chrisli.org>
2011-01-03use ARRAY_SIZE() when possibleNamhyung Kim1-2/+2
Convert (sizeof arr / sizeof arr[0]) to ARRAY_SIZE(arr). Signed-off-by: Namhyung Kim <namhyung@gmail.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
2010-06-17Parsing wide char stringChristopher Li1-2/+3
A follow up change to parse the wide char string. It currently only parse and store it like normal strings. Need more change to reflect the base type and size etc. Signed-off-by: Christopher Li <sparse@chrisli.org>
2010-04-08Allow parsing L'\0'Christopher Li1-0/+1
It is nasty that L'\0' start from an identifier letter. I try my best not to slow down the hot path. The test is done inside get_one_identifier() after the ident hash is built. It look a little bit out of palace but faster than testing 'L' before hand. Signed-off-by: Christopher Li <sparse@chrisli.org>
2009-07-18warn directive in argument listAl Viro1-2/+26
On Sat, Mar 21, 2009 at 04:40:20AM +0000, Al Viro wrote: > > Well... patch below would give more or less close approximation to the > current set of nasal demons produced by gcc in these situations + error > when that crap happens. > Warning: it might make things slower, and it needs testing. > > --- It needed testing, all right - #elif handling got broken by the initial variant... Hopefully fixed version follows: Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Christopher Li <sparse@chrisli.org>
2008-12-18Rename dirafter to idirafter.Alexey Zaytsev1-2/+2
Dirafter was probably just a mistake. Gcc uses -idirafter. Acked-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Alexey zaytsev <alexey.zaytsev@gmail.com>
2008-12-18Set gcc include path at runtime.Alexey Zaytsev1-20/+76
You can now tell sparse where to look for the compiler headers with -gcc-base-dir <dir>. Otherwise sparse will look for headers used to build it. Also adds $GCC_BASE/include-fixed used by newer gcc versions. Signed-off-by: Alexey zaytsev <alexey.zaytsev@gmail.com>
2007-06-03Fix infinite loop in free_preprocessor_line()Alexey Dobriyan1-2/+2
While running if-2.c from gcc testsuite sparse goes into infinite loop in free_preprocessor_line(). Trimmed down test-case is #if 1 #if (two lines) Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
2007-05-26check for whitespace before object-like macro bodyAl Viro1-5/+10
6.10.3(3) requires a whitespace between object-like macro and its replacement list. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2007-05-20__DATE__ & __TIME expansionDamien Lespiau1-0/+13
Makes __DATE__expand to a character string literal of the form "Mmm dd yyyy" where the names of the months are the same as those generated by the asctime function, and the first character of dd is a space character if the value is less than 10. Makes __TIME__ expand to a a character string literal of the form "hh:mm:ss" as in the time generated by the asctime function. Signed-off-by: Damien Lespiau <damien.lespiau@gmail.com>
2007-03-10Avoid returning an uninitialized pointer from dup_list of an empty listJosh Triplett1-1/+1
Thanks to Florian Krohm of IBM for reporting the problem. Signed-off-by: Josh Triplett <josh@freedesktop.org>
2007-03-09Fix typos in commentsJosh Triplett1-4/+4
Signed-off-by: Josh Triplett <josh@freedesktop.org>
2006-12-05implement #strong_undefOleg Nesterov1-6/+24
Example // pre-buffer #strong_undef CONFIG_SMP // include/linux/autoconf.h #define CONFIG_SMP 1 // silently ignored #ifdef CONFIG_SMP ... // not taken #endif Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
2006-12-05implement #strong_defineOleg Nesterov1-11/+17
Example #strong_define FOO 1 #undef FOO // silently ignored #define FOO 2 // silently ignored This allows (for example) to override CONFIG_XXX values without editing include/linux/autoconf.h I think this is useful. If you think differently, I will appreciate your comments on this patch correctness. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
2006-12-05prepare for #strong_{define,undef}Oleg Nesterov1-7/+8
This patch renames symbol->weak to symbol->attr and adds symbolic names for it's values. I don't like the new name, and will be happy to rename if you suggest me something different. Probably it is also better to move ->attr into the NS_MACRO part of the union and make it integer. No changes in pre-process.o Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
2006-12-05fix 'weak' attribute lossOleg Nesterov1-3/+5
When NS_MACRO symbol is used, sparse clears it's 'weak' flag. This is bad for multifile parsing, and wrong: #weak_define FOO 1 FOO #weak_define FOO 2 // silently ignored After this patch sparse never writes to NS_MACRO symbols from another scope (except ->used_in). Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
2006-12-05fix redefine of #weak_defineOleg Nesterov1-23/+32
This patch fixes 2 bugs in do_handle_define() 1. if (sym->weak) goto replace_it; This is wrong, we should allocate a new symbol if sym->scope != file_scope, example: inc.h: #weak_define FOO default redefine.c: #define FOO redefine FOO default.c: FOO $ ./test-lexing -include inc.h redefine.c default.c redefine Segmentation fault 2. if (token_list_different(...)) { ... } return 1; This is wrong too: #weak_define FOO 1 #define FOO 1 // has no effect #define FOO 2 // redefined without warning Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
2006-12-05kill NS_INVISIBLEMACRO, introduce NS_UNDEFOleg Nesterov1-3/+10
With this patch handle_undef() doesn't corrupt the builtin macros. This (imho) cleanups the code and is used in the next patches. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
2006-12-05use lookup_macro() in handle_undef()Oleg Nesterov1-10/+5
Current code looks strange, I think it used to remove the symbol from ->symbols list some time ago. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
2006-11-28Fix warning on self check.Christopher Li1-12/+16
Sparse complain about the using do while without compound statment in pre-process.c. This trivial patch fixes that. Signed-Off-By: Christopher Li <sparse@chrisli.org>
2006-11-06Typo fixesPavel Roskin1-1/+1
Signed-off-by: Pavel Roskin <proski@gnu.org> Signed-off-by: Josh Triplett <josh@freedesktop.org>
2005-11-27[PATCH] eliminate elif_ignore, fix handling of unterminated #ifAl Viro1-55/+45
No need to bother with stack; we can just keep # tokens from #if... and use _those_ as a stack instead. struct stream gets a pointer to the current #if..., checks for #elif/#else/#endif out of place become simple if (!stream->top_if) and stream->ifndef becomes a pointer to token instead of an integer (pointer to token in that stack instead of nesting depth). We lose elif_ignore[] array, if_nesting and stream->nesting (nothing cares of those anymore) and get sane handling of unterminated #if for free - instead of reporting the location of the last #if on depth 0 (very likely - in another file and having an #endif) we can give location of the #if that really lacks #endif. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-27[PATCH] lookup_macro() should be staticAl Viro1-1/+1
Not used anywhere else. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-27[PATCH] check for !token in handle_preprocessor_line() should be ↵Al Viro1-1/+1
eof_token(token) IOW, handling of #<newline> had been broken since way back... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-27[PATCH] fixed stream->protect handlingAl Viro1-44/+46
New mechanism: we introduce new fields of struct stream - ifndef and dirty. The former is the nesting level of ifndef that currently protects us, or 0 if there's none. The latter is a boolean - "do we ignore new non-empty stuff shows up right now?". There are five states, more or less matching the old ->constant ones: 1) nothing - dirty = 0, ->protect = NULL, ->ifndef = 0. 2) candidate - dirty = 0, ->protect = <ident>, ->ifndef > 0. 3) checking - dirty = 0, ->protect = <ident>, ->ifndef = 0. 4) maybe - dirty = 1, ->protect = <ident>, ->ifndef > 0. 5) not - dirty = 1, ->protect = NULL, ->ifndef = 0. Rules: - any directive except #ifdef, #ifndef, #else, #endif, #<newline> is considered dirty. - any non-directive (#<not a directive name>...) is considered dirty - any tokens in lines that do not begin with # are considered dirty - #if[n]def with syntax errors is considered dirty. - any nesting errors => stream is non-constant. - any dirty material not under ifndef => stream is non-constant. - the outermost ifndef at the first time we run into dirty material will be the candidate for stream protector. - any subsequent dirty material not under ifndef <protector> => stream is non-constant. We start in "nothing". Transitions: - "nothing": dirty material => "not", see ifndef => "candidate" - "candidate": dirty material => "maybe", leave that ifndef => "nothing" - "maybe": dirty material => "maybe", leave that ifndef => "checking" - "checking": dirty material => "not", same ifndef => "maybe - "not": they check in, but they don't check out... Seeing a nesting error (#else/#elif/#endif out of place/order or unclosed #if... in the end) gets us to "not", no matter which state we were in. That's it. Implementation is actually pretty simple and straightforward; it's less scary than the description above. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-27[PATCH] fixed handling of out-of-place #elif/#else/#endifAl Viro1-10/+19
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-27[PATCH] beginning of #include protection rewrite: cleanupAl Viro1-46/+31
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-27[PATCH] fix places that didn't free preprocessor line for no reason.Al Viro1-30/+37
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-27[PATCH] taking free_preprocessor_line() to caller of ->handler()Al Viro1-39/+40
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-27[PATCH] remove bogus double warning on #define/#undef syntaxAl Viro1-2/+2
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-27[PATCH] saner handling of #if[n]def syntax errorsAl Viro1-9/+28
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-27[PATCH] remove true_nesting, turn if_nesting into a variableAl Viro1-13/+4
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-22[PATCH] shut up the bogus warnings about the #if'ed-out sectionAl Viro1-4/+9
Standard requires much more relaxed treatment of the groups that are #if...'ed out. We used to generate bogus warnings there; fixed, testcase added. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-22[PATCH] no need to special-case comma after ##Al Viro1-2/+0
... normal execution will do exactly the same on the next iteration; case is damn rare (it's _not_ the GNU kludge - there we have ,##) and it's not worth an extra check. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-16Re-name "error()" function to "sparse_error()"Linus Torvalds1-29/+29
Mitesh Shah (and others) report that broken libc's will have their own "error()" that the sparse naming clashes with. So use a sed-script to rewrite all the occurrences. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-09-22[PATCH] replaced warnings with errors.Mitesh Shah1-29/+29
This replaceq calls to warning() with error() at places where (I think) the gcc reports an error. Also added a global variable die_if_error which is set if there is one or more errors. If someone wants to stop processing further, can check for the variable. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-09-09Warn about undefined preprocessor symbols at expansion time, not parse timeLinus Torvalds1-3/+1
This means that we can do #if defined(TOKEN) && TOKEN > 1 and we will _not_ warn even with -Wundef, since the "TOKEN > 1" test will never even be expanded if TOKEN isn't defined. Al Viro gets credit for the algorithm changes, I just did the actual coding. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-08-03Don't overwrite built-in macros when redefining them.Linus Torvalds1-5/+19
This means that we may have both an "invisible" macro _and_ a visible one in scope, so we need to be a bit more careful about lookup. We always look up the topmost one (either visible or invisible), and if it's invisible, that means it is undefined (a builtin macro was first re-defined, and then that redefinition was undefined).
2005-08-03Update the calling interface to "sparse()".Linus Torvalds1-1/+1
Start off with sparse_initialize(argc, argv); which will return the number of filenames found. You can then use that, or just check if *argv is NULL in a loop like while (*argv) list = sparse(argv); where you get the declaration list for each file in turn.
2005-08-02Don't free expressions after preprocessingLinus Torvalds1-1/+2
It used to be that we only had pre-processor expressions at that point, but now that we can pre-process multiple files, we end up having expressions of previous files too, and we mustn't free those.. There aren't enough pre-processor expressions around to be worth worrying about the memory usage anyway.
2005-05-19[PATCH] Fix SIGSEGV on unterminated preprocessor conditionalLuc Van Oostenryck1-0/+2
sparse segfaults with the following input: --- #ifdef notdef oops! --- The segfault occurs at pre-processor.c:free_preprocessor_line() because of the extra calls of handle_endif done in do_preproccess() while trying to do error recoverage. Fix it by not trying to free the non-existent token line in the faked endif handling. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@looxix.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-05-19Fix position reporting on unterminated preprocessor conditionalLinus Torvalds1-3/+3
Luc Van Oostenryck points out that we free all the preprocessor tokens after processing these days, so that pointing back to them for position reporting isn't very clever any more. Fix by just saving the position instead of the token instead.
2005-04-07[PATCH] static declearChristopher Li1-2/+1
This patch add static declare to make sparse happy of checking itself.
2005-04-07[PATCH] make include path handling gcc compatibleSam Ravnborg1-41/+151
Search include paths in same order as gcc does. In other words search directories specified with -I before system directories. This fixes a bug reported by a few persons after the kernel switched over to use -isystem to specify where to find compiler specific include files. Sparse now supports the following include path relevant options: -I dir Add dir to list of directories to search for. Search dir before system dirs. Used for both <> and "" includes. -I- Split include path - previous -I dir paths only used for include "". Also disable searching same dir as input file. -isystem dir Add dir first in row of system dirs to search. -dirafter dir Add dir in end of system dirs to search. -nostdinc Discard all defined system dirs The -iwithprefix, -iprefix and -iwithprefixbefore options are not not supported and silently ignored. gcc discourage use of these options.
2005-04-07Add "stream_name()" helper function, and use it.Linus Torvalds1-2/+2
Much prettier than "input_streams[x].name", since most users really don't want to know about the internals of how the preprocessor lays out its stream tracking.
2005-04-07Remove stat-based file identity tests.Linus Torvalds1-0/+19
Replace it with a simple pathname comparison instead. The pathname check is not only portable (no need for any compatibility helper functions), but we can do it much earlier, and thus make the check much cheaper by avoiding three extra system calls when it triggers (open/fstat/close). And the pathname test seems to match all the cases anyway.
2005-04-07Split out the blob allocator from lib.c into allocate.c.Linus Torvalds1-0/+1
It's disgusting how intimate lib.c is with all the types, and this is slowly trying to split things up a bit. Now the intimate part is in allocate.c, but maybe we can get to the point where each allocation user just declares its own allocation strategy, and just uses the generic routines in allocate.c
2005-04-07Add "optimize" flag, and collect the flags into lib.c.Linus Torvalds1-3/+0
Nothing uses it yet, but it's a good way to test bad ideas (call it an "optimization", and run diff on the result with and without).
2005-04-07Update copyright notices a bit.Linus Torvalds1-1/+1
2005-04-07Free more token memory for re-useLinus Torvalds1-0/+2
It now re-uses the '#' token for all preprocessor lines, and the 'define' token itself (even though it obviously can't free the tokens from the definition). This makes the 2004 IOCC entry a non-issue memory-wise. Now I just need to speed up the parser. Sixteen seconds on pre-processing is not acceptable..
2005-04-07Make the pre-processor free the tokens that never make itLinus Torvalds1-15/+26
into the token stream. Most preprocessor lines are unused after handling, with the notable exception of a #define. And regular tokens that get skipped due to being in a region that is inside a false #if case are also obvious fodder for this. This shrinks the memory usage by a factor of five on some particularly nasty code in the 2004 IOCCC.
2005-04-07Honor pre-processor conditionals even when they don't match within a stream.Linus Torvalds1-10/+6
We still warn about them, but we act as if it was ok. The "vik2" IOCCC-2004 entry does some nasty preprocessor stuff on purpose. We parse it all right, but because we refused to honor #if statements that are terminated in another stream, we didn't get the output Daniel Vik intended.
2005-04-07Using a preprocessor symbol makes it non-weak.Linus Torvalds1-3/+11
This causes us to warn if somebody tries to re-define a symbol that has already been used, even if it was originally non-weak. Noted by Morten Welinder
2005-04-07Make #ifdef/#ifndef/defined() all use the same helper function.Linus Torvalds1-14/+11
"token_defined(token)" does it all.
2005-04-07Add "weak" definesLinus Torvalds1-1/+18
They work like weak symbols: they get used if nobody defines anything else for them, and re-defining them doesn't cause a warning.
2005-04-07When re-defining a symbol, let the new definition shine through.Linus Torvalds1-0/+2
Don't just complain. It may be wrogn to redefine, but if people do it, use the most recent one.
2005-04-07[PATCH] #if expression handling cleanupsAlexander Viro1-22/+24
- handling of "unexpanded identifiers should be replaced with 0" is moved to pre-process.c and done on token replacement level - warning about such replacement made conditional - expand() and expand_one_symbol() return int now - it's "is the first token completely expanded now" (simplifies the life in #if handling, etc.) - crud removed from evaluate.c and expand.c
2005-04-07Fix replace_by_integer.welinder@troll.com1-2/+2
2005-04-07[PATCH] trivial ansi-c declearChristopher Li1-1/+1
Caught by checking sparse with itself.
2005-04-07Morten made us almost -Wwrite-strings clean. Go the extra mile.Linus Torvalds1-4/+6
The only remaining place was the magic constant "0" "1" number token generated by "defined(xxx)". And since we never actually modify number tokens (which would have broken that code anyway), let's just make that const'ness explicit.
2005-04-07Janitorial trivialities.welinder@darter.rentec.com1-1/+1
2005-04-07Many files:welinder@darter.rentec.com1-34/+34
warn->warning error->error_die new error lib.h: warn->warning error->error_die new error Add gcc format checking to warning/error/...
2005-04-07Remove "match_string_ident" now that nothing uses it.Linus Torvalds1-10/+0
It may well come back as a debugging and prototyping thing, but I'd rather remove it and have to re-introduce it, than have people use that stupid interface just "because it's there". Sparse is very good at hashing identifiers and making them all unique. So you really should never need to match by string, you can just compare "struct ident" pointers directly. Thanks to Chris for getting rid of the users.
2005-04-07[PATCH] make preprocesser command a symbolChristopher Li1-12/+17
This all started with I want to remove match_string_ident in preprocessor. I decide that I don't want to search a pointer in the list. There is faster way which is register a symbol with a new name space which contain the handler. This changes: 1) changed name of NS_PRECESSOR to NS_MACRO and give it a new meaning for preprocessor command. Now NS_MACRO means a macro name, and the new NS_PREPROCESSOR means a preprocessor command. 2) The ctype and preprocessor can put into one union. They are on different name space so they _should_ never collapse. I did that and made struct symbol 8 bytes smaller. Nothing blew up for me so it must be correct ;) And a question: 3) When to initialize the preprocessor command symbol. Should we make it part of the init_symbol or let the caller(check.c) initialize it? Do we want to remove the preprocessor command afterwords?
2005-04-07symbol.c:welinder@troll.com1-1/+1
Make eval_init_table static. pre-process.c: Fix match_string_ident.
2005-04-07Make sure to handle TOKEN_STREAMEND even inside a false conditional.welinder@troll.com1-11/+15
2005-04-07Make elif_ignore also keep track of whether we have seen #else.welinder@troll.com1-30/+42
Check for unterminated #if on a per-stream basis. Check for #else after #else or #elif. Check for unmatched #else/#elif/#endif on a per-stream basis.
2005-04-07Encountering #warning or #error at the wrong spot means that the filewelinder@troll.com1-0/+4
is not constant. Not that it really matters, but still...
2005-04-07Fix #warning for lines that end up with precisely 1024 characters.welinder@troll.com1-1/+1
2005-04-07Make "next_path" be per-stream for better "include_next".Linus Torvalds1-16/+11
Maybe this makes us gcc-compatible. Maybe it doesn't.
2005-04-07Implement "include_next"Linus Torvalds1-7/+19
It's trivial now with the re-organized include path handling.
2005-04-07Re-organize search path handling.Linus Torvalds1-23/+49
This is a cunning plan to make "include_next" work. This is just the infrastructure. Actual include_next handling in the next patch.
2005-04-07pre-process.c:welinder@troll.com1-24/+53
Fix file-is-const for #define, #undef, C-code inside the #ifndef. Make it easy to debug file-is-const. tokenize.c: Fix check for identical-file. token.h: Introduce symbolic names for the stream->constant states and comment those states.
2005-04-07pre-process.c, lib.c:welinder@troll.com1-1/+1
Never call isdigit/isspace on type char, use unsigned char only.
2005-04-07pre-process.c:welinder@troll.com1-1/+1
Gnome needs lots of -Ipath -- just up the limit a whole lot.
2005-04-07Handle preprocessor "# <nr> <file>" the same as #line <nr> <file>".Linus Torvalds1-2/+9
This is the format gcc will output the line information in, for example. We still don't actually _use_ the information, and perhaps never will, but at least we'll silently ignore it rather than complain.
2005-04-07[PATCH] #lineterra@gnome.org1-0/+9
Stuff from bison contains #line directives. This makes sparse ignore such lines. This helps but doesn't exactly make sparse happy over such .c files. (Ignoring isn't quite right because, arguably, later error messages should refer to the file from which the c code was generated, not from the c code itself.)
2005-04-07Make #include handling do the right thing for absolute paths.Linus Torvalds1-0/+8
We used to try to use the search path for them, which just doesn't work (it happened to work just by mistake in the common case of an empty path base component, but not in general).
2005-04-07Handle tokenized include-filename with angle brackets.Linus Torvalds1-0/+4
2005-04-07[PATCH] lazy-copy macro expansion in pre-processingAlexander Viro1-374/+574
This is almost a total rewrite of the macro expansion. It now does lazy-copy or the arguments, with the realization that if an argument only shows up once in the macro expansion (quite common), we don't need to allocate a new copy of the argument token stream, we can just insert it as-is. I hope it's reasonably clean and readable; review would be obviously welcome.
2005-04-07[PATCH] saner handling of argument listsAlexander Viro1-25/+83
This does two things: a) get C99 varargs to use the same mechanism as gcc ones use - all we need is to internally convert final ... in the list to ident[__VA_ARGS__] and set its ->next to &variable_argument. After that we don't need any special-casing for them. b) take parsing the argument list in a separate function and does it with all sanity checks; normally it ends up with fewer tests than old variant.
2005-04-07[PATCH] sparse cleanups of handle_define()Alexander Viro1-61/+66
On top of previous patch, takes handling of macros body into a separate function and cleans it up. No changes of behaviour (same tests).
2005-04-07[PATCH] more sparse fixes (body parsing, beginning of ## handling)Alexander Viro1-54/+80
> 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.
2005-04-07Shrink "struct token" by moving "noexpand" into the position flags.Linus Torvalds1-4/+4
This makes it take one bit (which we can just steal from the line number), instead of four bytes.
2005-04-07Oops. Al forgot to handle the new TOKEN_UNTAINT in tokenLinus Torvalds1-0/+1
comparison.
2005-04-07[PATCH] Fix preprocessor expansion anti-recursion properlyAlexander Viro1-68/+95
We taint identifiers when we are done with argument expansion; we untaint them when scan gets through the "untaint" token we leave right after the body of macro; we mark tokens noexpand in three situations: 1) when we copy a token marked noexpand; 2) when we get to expanding a token and see that its identifier is currently tainted; 3) when we scan for closing ) and see an identifier token with currently tainted identifier. That makes sure that by the time we get past the expanded body (and untaint the left-hand side of macro), all tokens bearing that identifier will be seen and marked noexpand. There is more elegant variant (it's practically straight from text of standard - set noexpand only in dup_token() and make it if (token_type(token) == TOKEN_IDENT) alloc->noexpand = token->noexpand | token->ident->tainted; which is as close as to transliteration of 6.10.3.4(2) as it gets), but before we can go for it, we need to sort out another problem - order of expansion/copying for arguments. So for now here's an equivalent heavier variant with a wart ((3) above) that works even with current expand_arguments() and when that gets sorted out we'll be able to get anti-recursion logics absolutely straightforward. And yes, it does preprocessor1.c correctly; it even get much subtler preprocessor7.c right.
2005-04-07Ok, this handles all token types in token comparison,Linus Torvalds1-10/+23
so the preprocessor "redefine" check should now be exact. Call me anal.
2005-04-07Be a bit better about comparing token lists.Linus Torvalds1-1/+29
2005-04-07Use the proper wrapper to access token types.Linus Torvalds1-1/+1
That's what everybody else does too.
2005-04-07Fix equality testing for macro re-definition.Linus Torvalds1-13/+13
We just move the arglist re-write up to before the equality test, so that we have rewritten the expansion in both the new and the old version. Otherwise we'd get spurious differences due to the rewriting and thus incorrect warnings.
2005-04-07[PATCH] cleanup of macro arguments handlingAlexander Viro1-7/+19
Trivial observation: we don't have to check every bloody identifier in the body of macro and see if it's a formal argument _every_ _time_ _we_ _do_ _substitution_. New token type: TOKEN_MACRO_ARGUMENT, with token->argnum as its data. Occurs only in bodies of macros with arguments. handle_define() goes through the body, checks which identifier tokens are arguments (using the same arg_number() we used to do on every expansion) and turns those into TOKEN_MACRO_ARGUMENT ones. expand_arguments() simply checks for TOKEN_MACRO_ARGUMENT. expand_one_argument() doesn't need arglist argument anymore - it gets argument number from token->argnum.
2005-04-07Now that we do the proper (simplified) C99 number tokenLinus Torvalds1-7/+1
handling, we can simplify ## too. The previous code was only needed because the tokenizer split things up too much.
2005-04-07Remove TOKEN_FP vs TOKEN_INTEGER distinction, and make numbers beLinus Torvalds1-30/+10
just TOKEN_NUMBER. This matches how tokenization is supposed to be done, and simplifies the code. Expression evaluation changed to cope with the new rules.
2005-04-07This should largely fix token pasting.Linus Torvalds1-49/+70
It's not perfect now either, but it makes a hell of a lot more sense now, and gets all the kernel cases I've tested right. Which is actually saying quite a lot, since the kernel uses things that are arguably not standard (the token fragments it pastes are not valid tokens on their own, and I think that may be borderline in ANSI - who knows). It still doesn't do the _really_ strange cases, ie trying to paste a ## 0.e10 and expecting that to become "a0" "." "e10" is just not going to happen. I think that's undefined behaviour anyway.
2005-04-07The "original definition" part of the redefined warningLinus Torvalds1-1/+1
is an informational part of a previous warning, don't count it as a separate warning.
2005-04-07Oops. Fix the preprocessor handling of "..." arguments.Linus Torvalds1-0/+1
This has been broken since day one, but since most uses were to things that could happily live with just the first argument in the list, we never noticed.
2005-04-07Fix token expansion array overflow.Linus Torvalds1-1/+7
2005-04-07[PATCH] print out the function which causes errorsChristopher Li1-7/+7
This fixes a bug in adding white space in macro expanding, which cause drivers/atm/ambassador.c complain about include file not found and stop the make. The offensive macro is that #define UCODE(x) UCODE2(atmsar11.x) #define UCODE2(x) #x UCODE(start) It will expand to "atmsar11 . start" instead of "atmsar11.start"
2005-04-07[PATCH] support __VA_ARGS__ variable macro argumentsChristopher Li1-7/+22
This adds support support for variable macro arguments: #define msg(fmt, ...) printf(fmt, __VA_ARGS__) #define msg(fmt, arg...) printf(fmt, arg) make ARCH=um will hit that kind of macros.
2005-04-07[PATCH] print out name of function which causes errorsChristopher Li1-1/+2
2005-04-07Update copyright notices to reflect the fact that TransmetaLinus Torvalds1-0/+1
isn't the sole copyright owner these days.
2005-04-07Fix a nonchecked (and much too small) nesting level limit.Linus Torvalds1-2/+4
2005-04-07Add "-v" flag for verbose mode.Linus Torvalds1-0/+1
Warn about internal "not implemented yet" kinds of things only when verbose. These warnings have nothing to do with the sources we're checking, they're only good for pointing out limitations of sparse itself.
2005-04-07Get rid of "#pragma" lines for now, while still keeping aLinus Torvalds1-0/+26
path to eventually start parsing them. Basic approach: we'll replace the pragma line with some kind of internal attribute-looking thing for the front end.
2005-04-07[PATCH] Get gcc internal header files path from gcc itselfRyan Anderson1-2/+2
This update (hopefully) will allow 'check' to find the appropriate, gcc-local include headers (dependent, of course, upon the system it was built on) It's still a hack, but at least it will work in a few more places.
2005-04-07Fix include path ordering - check for local paths when givenLinus Torvalds1-16/+16
a string name, while <xxxx.h> searches only the path.
2005-04-07Gahh... I really need to revisit the expansion recursion avoidance. Linus Torvalds1-2/+4
In the meantime this fixes some of it. The pre-processor is still a horrible mess.
2005-04-07Stupid pre-processor bug #6981: Don't avoid recursivelyLinus Torvalds1-2/+2
expanding the arguments, just the macro body. Otherwise a simple #define A(x) xx(x) A(A(x)) would decide that the "inner" A(x) was a recursive expansion.
2005-04-07Add current directory to search path.Linus Torvalds1-0/+4
2005-04-07Avoid recursive expansion of tokens by keeping track of expansionLinus Torvalds1-29/+38
parenthood. I desperately tried to avoid expanding the size of a token by using other means, but I couldn't fix the problems that led to. The pre-processor is still a pile of crud and gets multi-token pasting quite wrong (and probably other cases too). I should try to find some test-suite, but I'm afraid of what it would find.
2005-04-07Fix (and simplify) handling of "defined()" in the preprocessor.Linus Torvalds1-19/+13
2005-04-07Use the new factored-out include code to do proper include pathLinus Torvalds1-20/+50
handling. This also should get relative includes right.
2005-04-07Factor out the pre-processor include file handling a little bit,Linus Torvalds1-17/+30
preparing for better include-path searching.
2005-04-07Make the pre-processor search both 3.2.1 and 3.2.2 gcc header files.Linus Torvalds1-1/+2
2005-04-07Start updating the copyright license comments to the OSL,Linus Torvalds1-1/+3
preparing for a public release.
2005-04-07This should fix a macro argument expansion problem - we mark theLinus Torvalds1-2/+2
macro expander busy only oevr its own expansion, not the expansion of the arguments. That way the arguments can expand the same token again, without hitting the recursion limiter.
2005-04-07Add a "preprocessing" flag, so that the expression evaluator canLinus Torvalds1-0/+4
take the semantic differences into account (a undefined symbol behaves differently in a C parse tree than in a preprocessor expression)
2005-04-07Add some limited attribute parsing. "packed", "aligned" and "type".Linus Torvalds1-1/+1
The last one gives a "context mask" and "context value" to a symbol, which can be used to verify that the symbol is only used in a certain context.
2005-04-07Change the copyright to Transmeta Corp, that's likely to beLinus Torvalds1-1/+1
the real one when it goes out the door.
2005-04-07Introduce a "struct position", and have the different types referLinus Torvalds1-65/+65
to it, instead of having everybody have pointers to "struct token" only because they wanted to have the position. Fix array addition type degeneration.
2005-04-07Clean up type handling in a big way. Don't leave thoseLinus Torvalds1-1/+1
dangling anonymous "int_type" types with magic modifiers, but turn all types into explicit C types.
2005-04-07Handle __LINE__ and __FILE__ in pre-processor.Linus Torvalds1-0/+24
2005-04-07Make the includepath be an array of "const char *"Linus Torvalds1-2/+2
2005-04-07Add preprocessor directives to manipulate the include path.Linus Torvalds1-0/+51
2005-04-07Split the compile time constant evaluation up intoLinus Torvalds1-91/+1
evaluate.c instead of keeping it in pre-process.c. Add the proper dependencies
2005-04-07Move expression data structures to "expression.h", they gotLinus Torvalds1-0/+1
left behind in "parse.h" when the files were split.
2005-04-07Uhuh. Fix stupid thinko in insertion of macro expansion.Linus Torvalds1-4/+3
Make the stringifier stop at argument separators.
2005-04-07Remove unused variableLinus Torvalds1-1/+0
2005-04-07Don't expand arguments that are preceded by '#' or preceded or followedLinus Torvalds1-3/+6
by '##' (ANSI C - Appending A �12.3)
2005-04-07Fix stringify that got broken by other changesLinus Torvalds1-1/+0
2005-04-07Teach ## expansion about the magic gcc behaviour: x ## arg goesLinus Torvalds1-0/+24
away entirely if 'arg' is empty.
2005-04-07Fix recursive expansion of preprocessor macros. Linus Torvalds1-50/+47
2005-04-07Handle '#' properly (well, _more_ properly) in macro expansion.Linus Torvalds1-9/+28
2005-04-07Fix showing of tokens - whitespace messed up.Linus Torvalds1-2/+4
2005-04-07Remove global argument/arglist pointers, and pass them properly asLinus Torvalds1-11/+24
arguments in the functions involved instead.
2005-04-07Make the naming in expand_arguments() match the othersLinus Torvalds1-2/+2
2005-04-07Move includepath[] array out of pre-processor, since we wantLinus Torvalds1-9/+1
to change it from the callers..
2005-04-07Parse enum declarations, and associate the enum's with theLinus Torvalds1-9/+29
proper values. Make macro re-declaration legal if the new and old values match.
2005-04-07Add copyright statements and file comments. Add a FAQ, README, andLinus Torvalds1-0/+2
placeholder LICENSE file.
2005-04-07Fix constant expression parsing (a constant expression canLinus Torvalds1-2/+2
contain conditionals, but _not_ assignment expressions)
2005-04-07Bind symbols when declared. Bind arguments to functions.Linus Torvalds1-4/+4
Fix up function argument list to use a proper symbol list.
2005-04-07Parse __alignof__ (although right now it ends up parsing as aLinus Torvalds1-3/+0
EXPR_SIZEOF with the token being "alignof"). Remove stale debug printouts.
2005-04-07First cut at retokenization (ie 'a ## b') in macro expansion.Linus Torvalds1-0/+101
2005-04-07Fix up whitespace for token expansion to make printout prettier.Linus Torvalds1-0/+1
2005-04-07Avoid re-tokenizing header files that are protected byLinus Torvalds1-3/+26
#ifndef X ... #endif X if X is already defined. This avoids doing unnecessary work on duplicate includes.
2005-04-07Start tracking whether a stream may be constant or not. Very experimental.Linus Torvalds1-24/+40
2005-04-07Make the tokenizer insert begin/end tokens at stream boundaries,Linus Torvalds1-3/+12
so that the pre-processor might some day track them. For now, make the pre-processor just mask them out of the stream.
2005-04-07Re-name the "action" thing as something saner - it's now a "stream".Linus Torvalds1-3/+13
Our pre-processor token allocator has different initialization needs from the one in tokenize.c - don't try to share them.
2005-04-07Fix fd leak in tokenization.Linus Torvalds1-0/+1
2005-04-07Tokenization drops whitespace, but there is one area where it isLinus Torvalds1-2/+7
meaningful in parsing: at preprocessor macro definition time, where the whitespace between the macro name and the potentially following '(' determines whether the macro takes arguments or not. Make tokenization save off one bit of whitespace (in addition to the one bit of newline that it already saves off).
2005-04-07This gets us up and parsing through a lot of the regular header files:Linus Torvalds1-7/+15
- Notice loudly if one of out list walkers end up looping. - Fix the 'defined(x)' case for preprocessor conditionals. - Add the internal gcc headers to the search path. - Fix '#else' mixup with '#elif'
2005-04-07Do preprocessor macro argument substitution.Linus Torvalds1-1/+72
2005-04-07Make preprocessor expansion a hell of a lot more readable byLinus Torvalds1-25/+35
splitting it up into several smaller functions.
2005-04-07Parse the incoming argument list for macro expansion.Linus Torvalds1-2/+28
2005-04-07Add scaffolding for argument handling of macros. Very preliminary.Linus Torvalds1-9/+28
2005-04-07Make the preprocessor use the C parser, and then evaluate preprocessorLinus Torvalds1-113/+132
expressions by just walking the parse tree. We de-allocate all the C preprocessor expressions at the end, before we actually start doing the real C parsing. There is no history.
2005-04-07Properly expand tokens on #if/#elif/#include preprocessor linesLinus Torvalds1-34/+55
2005-04-07Argh, fix the pre-processor expression parsing warning to warnLinus Torvalds1-3/+3
at the right point.
2005-04-07Make preprocessor errors more readable, to help adding theLinus Torvalds1-1/+1
right expression parsing.
2005-04-07Do proper recursive expansion, with the right avoidance of infiniteLinus Torvalds1-10/+30
self-expansions. In particular #define A a B #define B b C #define C c A A should result in 'a b c A' since 'A' won't be recursively expanded.
2005-04-07Fix stream naming on include - we need to allocate stable storage for itLinus Torvalds1-2/+5
instead of passing around a pointer to a static buffer that will change.
2005-04-07Fix 'elif' semantics: if we've ever seen a previous if that matched,Linus Torvalds1-10/+12
we can't just switch from a false region to a true region. Use a "elif_ignore[]" stack to keep track of our elif nesting behaviour.
2005-04-07Move some common parsing routines to "lib", so thattheLinus Torvalds1-1/+124
preprocessor and the "real" parser can share them. Add some initial preprocessor expression parsing.
2005-04-07Teach the preprocessing pass to handle 'include' and Linus Torvalds1-2/+97
'elif'.
2005-04-07Do much more pre-processing work: support #ifdef/#else/#endifLinus Torvalds1-21/+196
sanely and efficiently, including proper nesting. Add 'undef'/'error'/'warning' support.
2005-04-07Preprocessor symbol handling: handle simple cases of #define andLinus Torvalds1-8/+83
symbol expansion (ie no argument-handling yet). Mark the EOF token as being on a new line, to make preprocessing simpler.
2005-04-07Add initial preprocessor pass (doesn't actually do much)Linus Torvalds1-0/+51
Make tokens know about newlines