From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14662 invoked by alias); 24 Sep 2004 20:29:51 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 14621 invoked from network); 24 Sep 2004 20:29:48 -0000 Received: from unknown (HELO mail.codesourcery.com) (65.74.133.10) by sourceware.org with SMTP; 24 Sep 2004 20:29:48 -0000 Received: (qmail 32398 invoked from network); 24 Sep 2004 20:29:47 -0000 Received: from localhost (HELO taltos.codesourcery.com) (zack@127.0.0.1) by mail.codesourcery.com with SMTP; 24 Sep 2004 20:29:47 -0000 Received: by taltos.codesourcery.com (sSMTP sendmail emulation); Fri, 24 Sep 2004 13:29:44 -0700 To: "Joseph S. Myers" Cc: Per Bothner , gcc@gcc.gnu.org Subject: Re: #pragma interface/implementation broken if --enable-mapped-location References: <41537AFC.4070709@bothner.com> <87isa4ctbq.fsf@codesourcery.com> <415387BE.9070303@bothner.com> <876564cqyo.fsf@codesourcery.com> From: Zack Weinberg Date: Fri, 24 Sep 2004 21:47:00 -0000 In-Reply-To: (Joseph S. Myers's message of "Fri, 24 Sep 2004 09:17:13 +0000 (UTC)") Message-ID: <87zn3f2yx3.fsf@codesourcery.com> User-Agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2004-09/txt/msg01448.txt.bz2 "Joseph S. Myers" 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