This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Remove duplicate or commented-out #includes
- From: Tom Tromey <tom at tromey dot com>
- To: Gary Benson <gbenson at redhat dot com>
- Cc: Tom Tromey <tom at tromey dot com>, gdb-patches at sourceware dot org
- Date: Mon, 21 Jan 2019 21:07:32 -0700
- Subject: Re: [PATCH] Remove duplicate or commented-out #includes
- References: <20190119213007.23712-1-tom@tromey.com> <20190121172843.GA7007@blade.nx>
>> It would be possible to sort #includes, or maybe run
>> include-what-you-use on gdb, but I haven't tried that. I'd be
>> interested to hear if you think this would be worthwhile, thoug.
Gary> I'd consider it worthwhile. I'd really like sorted #includes.
Gary> Some files have random whitespace in the list too, that maybe
Gary> made sense once.
I wrote a script to sort the includes. The output is rather voluminous,
not totally sure yet how I will submit it.
It doesn't try to do a 100% job. For example, some files in gdb include
other files at random spots -- not all includes are at the top of the
file -- and the script doesn't try to handle this.
It did find 40 .h files that don't have include guards. Maybe I will
try to automatically fix these.
Building revealed a few minor order dependencies in the headers. I'll
submit this as an initial cleanup.
I chose to have the includes ordered this way:
First stanza:
1. defs.h (or server.h or common-defs.h)
2. for a .c file, the corresponding .h if it exists
(two exceptions were needed to this rule)
Second stanza (stanzas separated by a blank line) holds system headers.
Third stanzas holds includes of headers in binutils-gdb but not part of
gdb proper.
Fourth stanza is gdb-specific headers.
It's reasonably easy to change this around though.
It would be possible to modify this same script to try removing includes
from .c files and seeing whether the file still compiles. It would just
take a long time on this machine I have at the moment.
If anyone wants to try it out for themselves, I can send the
instructions.
Tom