This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: cpplib: get -traditional correct outside directives
- To: Zack Weinberg <zack at wolery dot cumb dot org>
- Subject: Re: cpplib: get -traditional correct outside directives
- From: Dave Brolley <brolley at redhat dot com>
- Date: Mon, 15 May 2000 17:03:51 -0400
- CC: Neil Booth <NeilB at earthling dot net>, gcc-patches at gcc dot gnu dot org
- Organization: Cygnus Solutions, a Red Hat Company
- References: <E12rINU-0003G3-00@monkey.rosenet.ne.jp> <20000515112948.D6082@wolery.cumb.org>
Zack Weinberg wrote:
>
> On Mon, May 15, 2000 at 07:45:36PM +0900, Neil Booth wrote:
> > This patch gets -traditional correct outside directives, by continuing
> > to parse identifiers or numbers interrupted by a comment.
> >
> > e.g. 1.2/**/e-4 is tokenized as <1.2e-4>
> > 1.2 /**/e-4 is tokenized as <1.2> < e> <-> <4>
> > foo/**/bar is tokenized as <foobar>
> >
> > and thus if foobar is a macro it will be expanded normally.
In open text foo/**/bar should be seen by the compiler as the
identifier foobar, but foobar should not expand if it's a macro.
If foo/**/bar appears in the replacement of another macro which
is expanded, *then* foobar also get expanded.
To understand the difference, always go back to how the
preprocessor/compiler interacted *textually* in a traditional K&R
compiler:
The preprocessor scanned text looking for macro names to replace
and removing comments. In open text, given foo/**/bar, it sees
the identifier foo, removes the comment and then sees the
identifier bar. There is no rescanning by the preprocessor,
however the outout -- foobar -- is seen as a single identifier by
the compiler.
Given
#define foobar 1
#define ACK foo/**/bar
ACK
The preprocessor scans the #define an sees the identifier foo,
removes the comment and sees the identifier bar. ACK is defined
as the *text* foobar. When ACK is expanded, it is replaced with
foobar which gets rescanned and recognized as a macro which is
then, in turn expanded.
If you think of the traditional preprocessor as removing
comments, replacing macro invocations with *text* that gets
rescanned and outputting *text* which gets rescanned by the
compiler, you will always arrive at the correct behaviour.
Dave