cpplib: simplify callbacks, reduce exposed interface

Neil Booth neil@daikokuya.demon.co.uk
Sat Dec 16 16:24:00 GMT 2000


Jason Merrill wrote:-

> Thanks, it mostly does.  However, we still need to reimplement
> the special handling of a #line directive on the first line of the
> file, in which case the given filename overrides the physical
> filename.  Currently the main_input_filename is incorrectly set,
> such that for the following testcase the static constructor function
> will be named after the filename you give it, rather than wa.C.

> -----------
> # 1 "wa.C"
> struct A {
>   A();
> };
> 
> static A a;
> -----------

The patch I've just committed should fix this.

> Playing with cb_change_file, I notice that when we have multiple #line
> directives, as in
> 
> ---
> # 1 "/home/jason/eg/gcc/crtstuff.c"
> # 58 "/home/jason/eg/gcc/crtstuff.c"
> # 1 "auto-host.h" 1
> ---
> 
> we don't call cb_change_file for the second line, so lineno is
> incorrect when we call cb_change_file for the third line, so we store
> the wrong number in the input_file_stack.

I'd be curious to know if you still see this.  cpplib is doing the
right thing, because preprocessing a preprocessed file is now an
identity mapping, including # lines, so it must be doing the correct
callbacks.

If it is still wrong for the front ends, the callback handler in
c-lex.c is not doing the right thang.  I'm not fully clear on exactly
how the front-ends handle their file stack, so that is entirely
possible.

Anyway, we should now be trying to "virtualize" the file-stack in the
front ends (or get rid of it altogether if it is a C-like front-end
only thing) and use cpplib to print the file stack (and keep whatever
if anything currently does the analogous thing for non-C front ends).
There are now various things like _Pragma that cpplib indicates in
diagnostics that front ends cannot possibly know about.  In future, I
might also add an indication of which macro expansion(s) the error
appears in.

Also, we should change the front ends to query cpplib as to whether
we're in a system header file.  Front ends do not see #pragma GCC
system_header, so cannot always get it right.

A couple of new exported interfaces should suffice.

Neil.


More information about the Gcc-patches mailing list