Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jim Blandy <jimb@redhat.com>
To: Neil Booth <neil@daikokuya.demon.co.uk>
Cc: gdb-patches@sources.redhat.com
Subject: Re: RFC: preprocessor macro support (should actually work now)
Date: Fri, 29 Mar 2002 13:17:00 -0000	[thread overview]
Message-ID: <npadsrnkea.fsf@zwingli.cygnus.com> (raw)
In-Reply-To: <20020329100102.GA1261@daikokuya.demon.co.uk>


Neil Booth <neil@daikokuya.demon.co.uk> writes:
> I've done a bit more research into examples of when token marking is
> needed when expanding macros.  There are a few in the CPP testsuite;
> here is one (I got this by disabling the feature in CPP and seeing
> what broke):
> 
> #define M(x) 2 + M(x)
> #define N(a) M(a)
> N (N (9))
> 
> The correct expansion is
> 
> 2 + M(2 + M(9))
> 
> I expect your code (though I've not tested it!) will get:
> 
> 2 + M(2 + 2 + M(9))

Yes indeedy:

    (gdb) show macro M
    Defined at /rigel/jimb/gdb/macros/play/macros4.c:4
      included at /rigel/jimb/gdb/macros/play/macros4.c:0
    #define M(x) 2 + M(x)
    (gdb) show macro N
    Defined at /rigel/jimb/gdb/macros/play/macros4.c:5
      included at /rigel/jimb/gdb/macros/play/macros4.c:0
    #define N(a) M(a)
    (gdb) macro expand N (N (9))
    expands to: 2 + M(2 + 2 + M(9))
    (gdb) 

(That `included at macros4.c:0' stuff is a GCC bug I think Daniel B's
working on.)

For spectators: libcpp represents the stream of source code it's
expanding as an array of token structures, not a simple array of
characters.  When it sees some macro named X expand to a sequence that
includes the identifier token X, it sets a flag on that token
indicating that it should never be expanded as a macro invocation.  As
the example shows, this flag may need to remain set long after the
original invocation of the macro named X has been processed.  I don't
see any easy way to get this effect with a string-based expander, like
the one in my patch.

I didn't really understand all the logistics that got brought up
regarding moving libcpp into its own directory in the repository, to
make it easier to share with gdb.  But the sooner that happens, the
sooner we can replace my macro expander with one that works better.


  reply	other threads:[~2002-03-29 21:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-27 23:05 Jim Blandy
2002-03-28  0:55 ` Eli Zaretskii
2002-03-29  2:01 ` Neil Booth
2002-03-29 13:17   ` Jim Blandy [this message]
2002-03-29 13:27     ` Neil Booth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=npadsrnkea.fsf@zwingli.cygnus.com \
    --to=jimb@redhat.com \
    --cc=gdb-patches@sources.redhat.com \
    --cc=neil@daikokuya.demon.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox