GNU GCC

A project update.

Building on my original plan to generally help clean up GNU's GCC code, I set out to write some scripts to help me do that work for them, and to help others do the same in the future.

#if 0

GCC's project page complained that their code was speckled with preprocessor #if 0 statements--often sitting around in the code version after version doing nothing but getting in the way.

The script I wrote (in C) as a helper for this problem is reasonbly simple.  In its original form, it looks something like this...
__________________________________
open a source file (i.e file.c)

while there is a next line of the file,
    look at the next line.  Cut off the inital whitespace characters.
    If the result is #if 0,
        copy the line number and line text to the next line of file.c.if0s, and continue to copy text to file.c.if0s until one has exited the #if0 statement
Repeat
___________________________________

In my code, I used a separate function to remove the initial whitespace characters for clarity and convenience.




While functional, I increased the utility of the script by letting it accept a list of files to go through and act on as above.

Now my structure is something like this....

Main(filename){
    open (filename)
    Read each line, remove the newline character, and build an array of the filenames written in (filename)
    for each file name of index i in the array,
        run doit(filename[i]), where i is a function equivalent to the script described above.
}


Now I can feed my script a list of all the potential problematic gcc source files, and for each one (i.e. file.c) with #if 0 statements, there will be a corresponding file (i.e file.c.if0s) with the instances recorded and indexed by line number.

The next logical step, and one which I should be a hair away from having finished, is to make the script look at two different versions of the GCC source tree, and for each file in the trees, report the #if 0 statments that occur in both version's instance of the file.  Thus, by comparing the latest GCC release with a much older release, one can compile a list of preprocessor if 0 statements which are very unlikely to be of any current relavence.

It should be noted that there is a extra piece of functionality built into the script which I actually don't make use of in the case of #if 0 statements.
I originally wrote the script to work with any specific if statement.  It therefore is already capable of counting its position in the {, } tree of such if statements for deciding when it should be finished.  With #if, #endif statements, this is pretty much unnecessary, but the script is easily adaptable to the purpose of finding any specific if statements (for example those which might involve an obsolete variable).


For input like this,

yada yada
yada yada
#if 0
    yikes;
    if this
        code here;
    more code;
#endif
codecode
lookatmycode
#if 0
    code1
    code2
    code33 1/3
#endif


I get output like this:

line number 3
#if 0
    yikes;
    if this
        code here;
    more code;
#endif

line number 11
#if 0
    code1
    code2
    code33 1/3
#endif

#endif

A more interesting problem is the possibility of writing a script to automaticaly suggest a way of breaking up a source files.  But the plan of action is less clear on this.  I've been thinkin of ways for a script to try to isolate sections of code whose variables are local to that section, and creating separate functions of those sections.  I'm very open to suggestions on ways to implement this kind of thing.  It would be very cool, and even quite useful, I think.
Regarding administrative details, I'm hoping to be worthy of credit by the end of this quarter.  Once I am able to sign my life over to GNU, I can begin with contributing these scripts and changes they suggest (and I agree with).
Later,
Wes