public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Zack Weinberg <zack@codesourcery.com>
To: "Joseph S. Myers" <jsm@polyomino.org.uk>
Cc: Per Bothner <per@bothner.com>,  gcc@gcc.gnu.org
Subject: Re: #pragma interface/implementation broken if --enable-mapped-location
Date: Fri, 24 Sep 2004 21:47:00 -0000	[thread overview]
Message-ID: <87zn3f2yx3.fsf@codesourcery.com> (raw)
In-Reply-To: <Pine.LNX.4.61.0409240859290.31590@digraph.polyomino.org.uk> (Joseph S. Myers's message of "Fri, 24 Sep 2004 09:17:13 +0000 (UTC)")

"Joseph S. Myers" <jsm@polyomino.org.uk> writes:

> On Thu, 23 Sep 2004, Zack Weinberg wrote:
>
>> Alternatively, I wanted originally to defer pragmas not by
>> encapsulating the un-tokenized line in a string, but by injecting a
>> keyword (__pragma) at the beginning of the line, a semicolon at the
>> end, and tokenizing normally (but with macro expansion disabled).
>> Matt persuaded me that was hard to implement, but maybe it should be
>> revisited.
>
> That would also probably be convenient for OpenMP pragma implementation 
> for C (where the pragmas can contain expressions that need to go through 
> the parser as usual).  But for most target pragmas attempting to hook them 
> in the grammar like that would seem an excess complication; the grammar 
> would effectively just gather up a sequence of arbitrary tokens again to 
> pass to the target pragma handler.  (Bearing in mind the general 
> desirability that target pragmas share a single implementation for C and 
> C++.)

Well, remember that the way target pragma handlers work now is they
get tokens one at a time by calling c_lex.  This was always intended
to be hookable into a recursive descent parser as C++ has.  (I didn't
consider hooking target-specific pragmas into C's Yacc parser ever to
be feasible.)

My medium-term goals for the C++ front end involve bypassing c_lex and
having cpplib write its tokens directly into the big buffer that
cp/parser.c is now maintaining.  For the sake of the #pragma handlers,
it would then provide its own c_lex that is basically an exported
version of cp_lexer_consume_token.

Given all that, I think it makes sense for all pragmas to become
token sequences.  The difference between the OpenMP pragmas and the
others is just that they want to call back to the expression parser,
which is currently feasible for C++ and not for C.

> I wonder if also the check for unrecognized pragmas should be made
> before the pragma becomes any sort of token, on the basis that the C
> and C++ standards explicitly say that unknown pragmas are ignored
> (and so should be permitted anywhere in the source file, not just in
> reasonable places).  That would seem cleaner than documenting that
> all pragmas are recognized in order to give errors if they occur in
> an inconvenient place.

Suppose that cpplib, on encountering a #pragma, parsed the (namespace
and) keyword to decide what it meant.  If the #pragma was unknown, it
would then throw away the entire line.  If it was not unknown, it
would inject a CPP_PRAGMA token at the beginning of the line *in place
of* the token sequence # pragma [namespace] keyword.  The value of
this token would be a function pointer for the appropriate #pragma
handler.  I think that'd achieve both what you want and what I want,
and would also avoid doing the handler lookup twice.

Thoughts?

zw

  reply	other threads:[~2004-09-24 20:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-24  2:08 Per Bothner
2004-09-24  2:22 ` Zack Weinberg
2004-09-24  2:43   ` Per Bothner
2004-09-24  4:58     ` Zack Weinberg
2004-09-24 14:17       ` Joseph S. Myers
2004-09-24 21:47         ` Zack Weinberg [this message]
2004-09-24 22:15           ` Joseph S. Myers
2004-09-24 22:34             ` Zack Weinberg
2004-09-29 19:24           ` Per Bothner
2004-09-29 20:56             ` Zack Weinberg
2004-09-29 21:57               ` Matt Austern
2004-09-29 22:50                 ` Zack Weinberg
2004-09-30  7:57               ` Per Bothner

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=87zn3f2yx3.fsf@codesourcery.com \
    --to=zack@codesourcery.com \
    --cc=gcc@gcc.gnu.org \
    --cc=jsm@polyomino.org.uk \
    --cc=per@bothner.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).