This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

#include names containing `..'


Hi,
Although cccp's behaviour in this regard is not wrong, here's a feature which I
think would be nice.

cccp builds a #include filename by concatenating directory names together. For
instance, `#include "a/b.h"' from inside `ziggy/fink.h' will search for
`ziggy/a/b.h'. If we instead had `#include "../b.h"' cccp'd look for
`ziggy/../b.h'. It would be nice if cccp could notice whether `ziggy/../' was
the same as `'. and DTRT. The situation I'm experiencing is in a directory tree
which looks something like,

top/
 +- debug/
     +- debug.h
 +- hash/
     +- hash.h -- include ../debug/debug.h
 +- print/
     +- print.h -- include ../debug/debug.h, ../hash.hash.h
 *- other/
     +- other.cc -- include ../debug/debug.h, ../hash.hash.h, ../print/print.h

Depending on the exact ordering of the header inclusions, debug.h might be seen
from other/other.cc as any of the following,
  other/../debug/debug.h
  other/../print/../debug/debug.h
  other/../print/../hash/../debug.h

which is mildly confusing.

cccp uses inodes to detect that all three are actually the same file -- so the
idempotency optimization of noticing #ifndef .. #define .. #endif works.

It would not be sufficient to blindly squash out `a/..' sequences, because `a'
might be a symbolic link -- again inode comparison on `' and `a/..' would be
needed. I had a brief look at cccp.c and it seems that this could be placed in
open_include_file. You'd probably want it after looking up in the hash table by
file name, and after determining the file actually exists. Ie, the pseudo code
would be something like,

is name in hash table? -> do it
does file not open? -> fail
new behaviour: canonicalize file name
rehash and insert
...

canonicalizing the name would look for `PREFIX/dir/../' sequences and compare
inodes on `PREFIX' and `PREFIX/dir/..'. Similarly `PREFIX/./' could be compared
to `PREFIX', (would that ever fail?) and `../dir' compared to `.'.

a) how popular would such behaviour be?
b) am I on the right track in how to implement it?

nathan
-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]