From patchwork Wed Apr 13 20:52:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 91110 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 A492A1007DA for ; Thu, 14 Apr 2011 06:52:16 +1000 (EST) Received: (qmail 14197 invoked by alias); 13 Apr 2011 20:52:14 -0000 Received: (qmail 14188 invoked by uid 22791); 13 Apr 2011 20:52:12 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, SARE_SUB_ENC_UTF8, TW_BJ, 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, 13 Apr 2011 20:52:04 +0000 Received: from eggs.gnu.org ([140.186.70.92]:54930) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1QA72h-0004Pv-JF for gcc-patches@gnu.org; Wed, 13 Apr 2011 16:52:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QA72g-0007ft-5i for gcc-patches@gnu.org; Wed, 13 Apr 2011 16:52:03 -0400 Received: from smtp141.iad.emailsrvr.com ([207.97.245.141]:33246) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QA72f-0007fo-Vk for gcc-patches@gnu.org; Wed, 13 Apr 2011 16:52:02 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp54.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 5E2BE2B0B13 for ; Wed, 13 Apr 2011 16:52:01 -0400 (EDT) Received: from dynamic2.wm-web.iad.mlsrvr.com (dynamic2.wm-web.iad1a.rsapps.net [192.168.2.151]) by smtp54.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 48ABB2B03F7 for ; Wed, 13 Apr 2011 16:52:01 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic2.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 19F5828E8066 for ; Wed, 13 Apr 2011 16:52:01 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Wed, 13 Apr 2011 22:52:01 +0200 (CEST) Date: Wed, 13 Apr 2011 22:52:01 +0200 (CEST) Subject: =?UTF-8?Q?ObjC:=20remove=20temporary=20tree=20list=20used=20when=20calli?= =?UTF-8?Q?ng=20objc=5Fdeclare=5Fclass()?= From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1302727921.10478072@192.168.4.58> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 207.97.245.141 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 patch removes another case of temporary tree chains from the ObjC compiler. When the parser finds a @class NSArray; declaration, it would call objc_declare_class() passing as argument a temporary tree list containing the identifier. This tree list is created, used for the function call, then discarded. Btw, this made some sense when you have a list with multiple identifiers, as in @class NSArray, NSString; as they are all passed in the same linked list. it is still cleaner and more efficient to call objc_declare_class() for each identifier, as opposed to creating a temporary tree list, populating it with the identifiers, then calling objc_declare_class() which then iterates over the temporary tree list to read the identifiers, and then the list gets thrown away. The patch speeds things up but the effect is very small; the GNUstep system headers do contain about 800 @class declarations or so, so the patch typically saves something like 1k allocations or so when compiling a file. That is probably a 0.05% speedup (order of magnitude). But we get rid of a the tree list. :-) The ObjC++ parser needed a bit of changes, but while changing it I also made the ObjC++ parsing code almost identical to the ObjC one, which simplifies maintenance. Ok to commit ? Thanks Index: c-family/ChangeLog =================================================================== --- c-family/ChangeLog (revision 172360) +++ c-family/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2011-04-13 Nicola Pero + + * stub-objc.c (objc_declare_class): Updated argument name. + 2011-04-12 Nathan Froyd * c-common.h (c_common_init_ts): Declare. Index: c-family/stub-objc.c =================================================================== --- c-family/stub-objc.c (revision 172360) +++ c-family/stub-objc.c (working copy) @@ -110,7 +110,7 @@ objc_declare_alias (tree ARG_UNUSED (alias), tree } void -objc_declare_class (tree ARG_UNUSED (list)) +objc_declare_class (tree ARG_UNUSED (identifier)) { } Index: objc/ChangeLog =================================================================== --- objc/ChangeLog (revision 172360) +++ objc/ChangeLog (working copy) @@ -1,5 +1,12 @@ 2011-04-13 Nicola Pero + * objc-act.c (objc_declare_class): Changed to take a single + identifier as argument instead of a tree list. This means callers + don't have to build temporary tree lists to call this function. + (synth_module_prologue): Updated calls to objc_declare_class. + +2011-04-13 Nicola Pero + * objc-act.c (build_keyword_selector): Use get_identifier_with_length instead of get_identifier. Index: objc/objc-act.c =================================================================== --- objc/objc-act.c (revision 172360) +++ objc/objc-act.c (working copy) @@ -2953,7 +2953,7 @@ synth_module_prologue (void) /* Forward-declare '@interface Protocol'. */ type = get_identifier (PROTOCOL_OBJECT_CLASS_NAME); - objc_declare_class (tree_cons (NULL_TREE, type, NULL_TREE)); + objc_declare_class (type); objc_protocol_type = build_pointer_type (xref_tag (RECORD_TYPE, type)); /* Declare receiver type used for dispatching messages to 'super'. */ @@ -2985,7 +2985,7 @@ synth_module_prologue (void) if (!constant_string_class_name) constant_string_class_name = runtime.default_constant_string_class_name; constant_string_id = get_identifier (constant_string_class_name); - objc_declare_class (tree_cons (NULL_TREE, constant_string_id, NULL_TREE)); + objc_declare_class (constant_string_id); /* Pre-build the following entities - for speed/convenience. */ self_id = get_identifier ("self"); @@ -3360,48 +3360,42 @@ objc_declare_alias (tree alias_ident, tree class_i } void -objc_declare_class (tree ident_list) +objc_declare_class (tree identifier) { - tree list; #ifdef OBJCPLUS if (current_namespace != global_namespace) { error ("Objective-C declarations may only appear in global scope"); } #endif /* OBJCPLUS */ - for (list = ident_list; list; list = TREE_CHAIN (list)) + if (! objc_is_class_name (ident)) { - tree ident = TREE_VALUE (list); - - if (! objc_is_class_name (ident)) + tree record = lookup_name (ident), type = record; + + if (record) { - tree record = lookup_name (ident), type = record; - - if (record) + if (TREE_CODE (record) == TYPE_DECL) + type = DECL_ORIGINAL_TYPE (record) + ? DECL_ORIGINAL_TYPE (record) + : TREE_TYPE (record); + + if (!TYPE_HAS_OBJC_INFO (type) + || !TYPE_OBJC_INTERFACE (type)) { - if (TREE_CODE (record) == TYPE_DECL) - type = DECL_ORIGINAL_TYPE (record) - ? DECL_ORIGINAL_TYPE (record) - : TREE_TYPE (record); - - if (!TYPE_HAS_OBJC_INFO (type) - || !TYPE_OBJC_INTERFACE (type)) - { - error ("%qE redeclared as different kind of symbol", - ident); - error ("previous declaration of %q+D", - record); - } + error ("%qE redeclared as different kind of symbol", + ident); + error ("previous declaration of %q+D", + record); } - - record = xref_tag (RECORD_TYPE, ident); - INIT_TYPE_OBJC_INFO (record); - /* In the case of a @class declaration, we store the ident - in the TYPE_OBJC_INTERFACE. If later an @interface is - found, we'll replace the ident with the interface. */ - TYPE_OBJC_INTERFACE (record) = ident; - hash_class_name_enter (cls_name_hash_list, ident, NULL_TREE); } + + record = xref_tag (RECORD_TYPE, ident); + INIT_TYPE_OBJC_INFO (record); + /* In the case of a @class declaration, we store the ident in + the TYPE_OBJC_INTERFACE. If later an @interface is found, + we'll replace the ident with the interface. */ + TYPE_OBJC_INTERFACE (record) = ident; + hash_class_name_enter (cls_name_hash_list, ident, NULL_TREE); } } Index: ChangeLog =================================================================== --- ChangeLog (revision 172360) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-04-13 Nicola Pero + + * c-parser.c (c_parser_objc_class_declaration): Updated call to + objc_declare_class. + 2011-04-12 Nathan Froyd * c-decl.c (union lang_tree_node): Check for TS_COMMON before Index: cp/ChangeLog =================================================================== --- cp/ChangeLog (revision 172360) +++ cp/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-04-13 Nicola Pero + + * parser.c (cp_parser_objc_class_declaration): Updated for change + in objc_declare_class(). + 2011-04-12 Nathan Froyd * cp-lang.c (cp_init_ts): Call cp_common_init_ts. Move Index: cp/parser.c =================================================================== --- cp/parser.c (revision 172360) +++ cp/parser.c (working copy) @@ -21615,7 +21615,21 @@ static void cp_parser_objc_class_declaration (cp_parser* parser) { cp_lexer_consume_token (parser->lexer); /* Eat '@class'. */ - objc_declare_class (cp_parser_objc_identifier_list (parser)); + while (true) + { + tree id; + + id = cp_parser_identifier (parser); + if (id == error_mark_node) + break; + + objc_declare_class (id); + + if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) + cp_lexer_consume_token (parser->lexer); + else + break; + } cp_parser_consume_semicolon_at_end_of_statement (parser); } Index: c-parser.c =================================================================== --- c-parser.c (revision 172360) +++ c-parser.c (working copy) @@ -6994,7 +6994,6 @@ c_parser_objc_class_instance_variables (c_parser * static void c_parser_objc_class_declaration (c_parser *parser) { - tree list = NULL_TREE; 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 @@ -7010,7 +7009,7 @@ c_parser_objc_class_declaration (c_parser *parser) return; } id = c_parser_peek_token (parser)->value; - list = chainon (list, build_tree_list (NULL_TREE, id)); + objc_declare_class (id); c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_COMMA)) c_parser_consume_token (parser); @@ -7018,7 +7017,6 @@ c_parser_objc_class_declaration (c_parser *parser) break; } c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); - objc_declare_class (list); } /* Parse an objc-alias-declaration.