Diagnostic clean ups

Neil Booth neil@daikokuya.demon.co.uk
Sun Jun 9 12:22:00 GMT 2002


Gabriel Dos Reis wrote:-

> My mental model is that a declaration has a location, and that we
> don't deal with a location as an entity in itself but it happens as a
> piece of information about a declaration which we usually dealt with.
> Thus if we have a declaration, we have its location -- and that
> corresponds to almost all uses of locations --; but I don't see any
> need to consider a location by itself.
> 
> What part of cpplib paraticularities am I missing?

Nothing, just that not everything is a declaration, right?  Syntax
errors can occur in the middle of an expression, for example.

> Thanks for the explanation.  My concern is: Why isn't it sufficient to
> have a one-way link from a CPP_TOKEN to a location, i.e. in which
> circumstances is it necessary to have a link back to a CPP_TOKEN from
> a location?

A cpp_token contains the location of the original token in the source
file (possibly in a #define if it comes from a macro invocation).

If M is a macro, then

M M

returns the same tokens twice.  Each token has as its location the
position in the "#define M" line.  If all you have is a token, you
can't be sure to point to the right invocation, but you will point
to the right token in the definition.

If cpplib passes the tokens in an array (of either tokens or pointers
to them), then the position in that array is enough to have all
this information.

Neil.



More information about the Gcc-patches mailing list