From patchwork Wed Sep 29 23:17:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 66103 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id AB1BEB70A3 for ; Thu, 30 Sep 2010 09:18:02 +1000 (EST) Received: (qmail 8316 invoked by alias); 29 Sep 2010 23:18:00 -0000 Received: (qmail 8303 invoked by uid 22791); 29 Sep 2010 23:17:58 -0000 X-SWARE-Spam-Status: No, hits=0.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_PSBL, TW_BJ, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 29 Sep 2010 23:17:52 +0000 Received: from eggs.gnu.org ([140.186.70.92]:42688) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1P15uH-0003Wo-RB for gcc-patches@gnu.org; Wed, 29 Sep 2010 19:17:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1P15uF-0000hE-QL for gcc-patches@gnu.org; Wed, 29 Sep 2010 19:17:49 -0400 Received: from smtp121.iad.emailsrvr.com ([207.97.245.121]:36671) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1P15uF-0000h9-L6 for gcc-patches@gnu.org; Wed, 29 Sep 2010 19:17:47 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp42.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 2B7561483DD for ; Wed, 29 Sep 2010 19:17:47 -0400 (EDT) Received: from dynamic8.wm-web.iad.mlsrvr.com (dynamic8.wm-web.iad1a.rsapps.net [192.168.2.149]) by smtp42.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 1152A1483CA for ; Wed, 29 Sep 2010 19:17:47 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic8.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 0253F305006C for ; Wed, 29 Sep 2010 19:17:47 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Thu, 30 Sep 2010 01:17:47 +0200 (CEST) Date: Thu, 30 Sep 2010 01:17:47 +0200 (CEST) Subject: ObjC - standardize parsing of @class etc From: "Nicola Pero" To: gcc-patches@gnu.org MIME-Version: 1.0 X-Type: plain Message-ID: <1285802267.006520968@192.168.2.227> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This small patch standardizes how tokens such as @class are parsed by the Objective-C and Objective-C++ frontends. With this patch they are always reported as CPP_AT_NAME / RID_AT_CLASS, which is consistent with how @synchronized & similar are reported (CPP_AT_NAME / RID_AT_SYNCHRONIZED) and prevents any confusions with C++ keywords (reported as RID_CLASS etc). It also makes c_lex_one_token() in C and C++ much more similar - which may allow someone to merge them at some point if so wished. I also tidied up comments around etc. No regressions - OK to apply ? Thanks Index: gcc/c-family/ChangeLog =================================================================== --- gcc/c-family/ChangeLog (revision 164736) +++ gcc/c-family/ChangeLog (working copy) @@ -1,5 +1,10 @@ 2010-09-29 Nicola Pero + * c-lex.c (c_lex_with_flags): Updated comments for CPP_AT_NAME + Objective-C/Objective-C++ keywords. + +2010-09-29 Nicola Pero + Merge from 'apple/trunk' branch on FSF servers. 2005-10-04 Fariborz Jahanian Index: gcc/c-family/c-lex.c =================================================================== --- gcc/c-family/c-lex.c (revision 164736) +++ gcc/c-family/c-lex.c (working copy) @@ -370,6 +370,12 @@ c_lex_with_flags (tree *value, location_t *loc, un || OBJC_IS_CXX_KEYWORD (C_RID_CODE (*value))) { type = CPP_AT_NAME; + /* Note the complication: if we found an OBJC_CXX + keyword, for example, 'class', we will be + returning a token of type CPP_AT_NAME and rid + code RID_CLASS (not RID_AT_CLASS). The language + parser needs to convert that to RID_AT_CLASS. + */ break; } /* FALLTHROUGH */ Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 164736) +++ gcc/ChangeLog (working copy) @@ -1,5 +1,20 @@ 2010-09-29 Nicola Pero + * c-parser.c (c_lex_one_token): When finding a CPP_AT_NAME + Objective-C token, map RID_CLASS to RID_AT_CLASS and similar. + (c_parser_external_declaration): Use RID_AT_CLASS + instead of RID_CLASS. + (c_parser_objc_class_declaration): Same change. + (c_parser_objc_try_catch_statement): Use RID_AT_TRY instead of + RID_TRY and RID_AT_CATCH instead of RID_CATCH. + (c_parser_objc_class_instance_variables): Use RID_AT_PRIVATE + instead of RID_PRIVATE, RID_AT_PROTECTED instead of RID_PROTECTED + and RID_AT_PUBLIC instead of RID_PUBLIC. + (c_parser_statement_after_labels): Use RID_AT_TRY instead of + RID_TRY and RID_AT_CATCH instead of RID_CATCH. + +2010-09-29 Nicola Pero + Merge from 'apple/trunk' branch on FSF servers. * c-parser.c: Applied change originally in c-parse.in. Index: gcc/cp/ChangeLog =================================================================== --- gcc/cp/ChangeLog (revision 164736) +++ gcc/cp/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2010-09-29 Nicola Pero + + * parser.c (cp_lexer_get_preprocessor_token): Tidied up comments + and indentation when finding an Objective-C++ CPP_AT_NAME token. + 2010-09-29 Richard Guenther * cp-tree.h (CP_DECL_CONTEXT): Check DECL_FILE_SCOPE_P. Index: gcc/cp/parser.c =================================================================== --- gcc/cp/parser.c (revision 164736) +++ gcc/cp/parser.c (working copy) @@ -565,21 +565,28 @@ cp_lexer_get_preprocessor_token (cp_lexer *lexer, token->keyword = RID_MAX; } } - /* Handle Objective-C++ keywords. */ else if (token->type == CPP_AT_NAME) { + /* This only happens in Objective-C++; it must be a keyword. */ token->type = CPP_KEYWORD; switch (C_RID_CODE (token->u.value)) { - /* Map 'class' to '@class', 'private' to '@private', etc. */ - case RID_CLASS: token->keyword = RID_AT_CLASS; break; - case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break; + /* Replace 'class' with '@class', 'private' with '@private', + etc. This prevents confusion with the C++ keyword + 'class', and makes the tokens consistent with other + Objective-C 'AT' keywords. For example '@class' is + reported as RID_AT_CLASS which is consistent with + '@synchronized', which is reported as + RID_AT_SYNCHRONIZED. + */ + case RID_CLASS: token->keyword = RID_AT_CLASS; break; + case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break; case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break; - case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break; - case RID_THROW: token->keyword = RID_AT_THROW; break; - case RID_TRY: token->keyword = RID_AT_TRY; break; - case RID_CATCH: token->keyword = RID_AT_CATCH; break; - default: token->keyword = C_RID_CODE (token->u.value); + case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break; + case RID_THROW: token->keyword = RID_AT_THROW; break; + case RID_TRY: token->keyword = RID_AT_TRY; break; + case RID_CATCH: token->keyword = RID_AT_CATCH; break; + default: token->keyword = C_RID_CODE (token->u.value); } } else if (token->type == CPP_PRAGMA) Index: gcc/c-parser.c =================================================================== --- gcc/c-parser.c (revision 164736) +++ gcc/c-parser.c (working copy) @@ -310,7 +310,25 @@ c_lex_one_token (c_parser *parser, c_token *token) case CPP_AT_NAME: /* This only happens in Objective-C; it must be a keyword. */ token->type = CPP_KEYWORD; - token->keyword = C_RID_CODE (token->value); + switch (C_RID_CODE (token->value)) + { + /* Replace 'class' with '@class', 'private' with '@private', + etc. This prevents confusion with the C++ keyword + 'class', and makes the tokens consistent with other + Objective-C 'AT' keywords. For example '@class' is + reported as RID_AT_CLASS which is consistent with + '@synchronized', which is reported as + RID_AT_SYNCHRONIZED. + */ + case RID_CLASS: token->keyword = RID_AT_CLASS; break; + case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break; + case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break; + case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break; + case RID_THROW: token->keyword = RID_AT_THROW; break; + case RID_TRY: token->keyword = RID_AT_TRY; break; + case RID_CATCH: token->keyword = RID_AT_CATCH; break; + default: token->keyword = C_RID_CODE (token->value); + } break; case CPP_COLON: case CPP_COMMA: @@ -1106,7 +1124,7 @@ c_parser_external_declaration (c_parser *parser) gcc_assert (c_dialect_objc ()); c_parser_objc_class_definition (parser, NULL_TREE); break; - case RID_CLASS: + case RID_AT_CLASS: gcc_assert (c_dialect_objc ()); c_parser_objc_class_declaration (parser); break; @@ -4081,7 +4099,7 @@ c_parser_statement_after_labels (c_parser *parser) case RID_ASM: stmt = c_parser_asm_statement (parser); break; - case RID_THROW: + case RID_AT_THROW: gcc_assert (c_dialect_objc ()); c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_SEMICOLON)) @@ -4097,7 +4115,7 @@ c_parser_statement_after_labels (c_parser *parser) goto expect_semicolon; } break; - case RID_TRY: + case RID_AT_TRY: gcc_assert (c_dialect_objc ()); c_parser_objc_try_catch_statement (parser); break; @@ -6483,19 +6501,19 @@ c_parser_objc_class_instance_variables (c_parser * break; } /* Parse any objc-visibility-spec. */ - if (c_parser_next_token_is_keyword (parser, RID_PRIVATE)) + if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE)) { c_parser_consume_token (parser); objc_set_visibility (2); continue; } - else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED)) + else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED)) { c_parser_consume_token (parser); objc_set_visibility (0); continue; } - else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC)) + else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC)) { c_parser_consume_token (parser); objc_set_visibility (1); @@ -6530,7 +6548,7 @@ static void c_parser_objc_class_declaration (c_parser *parser) { tree list = NULL_TREE; - gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS)); + gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS)); c_parser_consume_token (parser); /* Any identifiers, including those declared as type names, are OK here. */ @@ -7052,12 +7070,12 @@ c_parser_objc_try_catch_statement (c_parser *parse { location_t loc; tree stmt; - gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY)); + gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY)); c_parser_consume_token (parser); loc = c_parser_peek_token (parser)->location; stmt = c_parser_compound_statement (parser); objc_begin_try_stmt (loc, stmt); - while (c_parser_next_token_is_keyword (parser, RID_CATCH)) + while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH)) { struct c_parm *parm; c_parser_consume_token (parser);