This is the mail archive of the gcc-patches@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]

Re: cpplib: simplify callbacks, reduce exposed interface


>>>>> "Neil" == Neil Booth <neilb@earthling.net> writes:

> There is a chance this patch fixes the problems Jason was seeing with
> compiling preprocessed files

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.

We used to handle this in lang_init, by calling check_newline
immediately; now the preprocessor isn't initialized until later.  The
delay doesn't really matter, though the comments in compile_file
should probably be updated.  It seems to me that the right place for
this now is _cpp_do_file_change, so that the frontend never knows
about this detail, though it would be much simpler to handle it in
cb_change_file.  Thoughts?

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

static A a;
-----------

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 suppose this delayed
notification works in other situations because we always update lineno
in c_lex (and blame it on C++), but in this case we don't hit c_lex
between the directives.  Probably the simplest solution would be to
update lineno from fc->from.lineno before pushing.

Another question:  Why did you leave the pfile argument, when it's
unused in all implementations?

Also, lex_lineno seems useless; why not just update lineno directly?

Jason

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