This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ObjC: remove temporary tree list used when calli ng objc_declare_protocols()


This patch cleans up objc_declare_protocols() to avoid having to create
temporary tree chains just to perform the function call (in the same way
as my other patch cleaned up objc_declare_class()).

Ok to commit ?

Thanks

PS: This patch has no measurable effect on compilation speed in my tests
because the GNUstep codebase almost never uses the protocol forward-declaration
syntax "@protocol X;".  Another codebase that use it extensively may see
some tiny benefit.


Index: gcc/c-family/c-objc.h
===================================================================
--- gcc/c-family/c-objc.h       (revision 172399)
+++ gcc/c-family/c-objc.h       (working copy)
@@ -52,7 +52,7 @@ extern int objc_is_public (tree, tree);
 extern tree objc_is_id (tree);
 extern void objc_declare_alias (tree, tree);
 extern void objc_declare_class (tree);
-extern void objc_declare_protocols (tree, tree);
+extern void objc_declare_protocol (tree, tree);
 extern tree objc_build_message_expr (tree, tree);
 extern tree objc_finish_message_expr (tree, tree, tree, tree*);
 extern tree objc_build_selector_expr (location_t, tree);
Index: gcc/c-family/ChangeLog
===================================================================
--- gcc/c-family/ChangeLog      (revision 172399)
+++ gcc/c-family/ChangeLog      (working copy)
@@ -1,3 +1,9 @@
+2011-04-13  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * stub-objc.c (objc_declare_protocols): Renamed to
+       objc_declare_protocol.
+       * c-objc.h: Likewise.
+       
 2011-04-12  Nathan Froyd  <froydnj@codesourcery.com>
 
        * c-common.h (c_common_init_ts): Declare.
Index: gcc/c-family/stub-objc.c
===================================================================
--- gcc/c-family/stub-objc.c    (revision 172399)
+++ gcc/c-family/stub-objc.c    (working copy)
@@ -115,7 +115,7 @@ objc_declare_class (tree ARG_UNUSED (list))
 }
 
 void
-objc_declare_protocols (tree ARG_UNUSED (list), tree ARG_UNUSED (attributes))
+objc_declare_protocol (tree ARG_UNUSED (name), tree ARG_UNUSED (attributes))
 {
 }
 
Index: gcc/objc/ChangeLog
===================================================================
--- gcc/objc/ChangeLog  (revision 172399)
+++ gcc/objc/ChangeLog  (working copy)
@@ -1,5 +1,12 @@
 2011-04-13  Nicola Pero  <nicola.pero@meta-innovation.com>
 
+       * objc-act.c (objc_declare_protocols): Renamed to
+       objc_declare_protocol.  Changed first argument to be an identifier
+       instead of a tree chain of identifiers, so that callers don't have
+       to create a temporary tree chain.
+
+2011-04-13  Nicola Pero  <nicola.pero@meta-innovation.com>
+
        * objc-act.c (build_keyword_selector): Use get_identifier_with_length
        instead of get_identifier.
 
Index: gcc/objc/objc-act.c
===================================================================
--- gcc/objc/objc-act.c (revision 172399)
+++ gcc/objc/objc-act.c (working copy)
@@ -7869,9 +7869,8 @@ lookup_protocol (tree ident, bool warn_if_deprecat
    they are already declared or defined, the function has no effect.  */
 
 void
-objc_declare_protocols (tree names, tree attributes)
+objc_declare_protocol (tree name, tree attributes)
 {
-  tree list;
   bool deprecated = false;
 
 #ifdef OBJCPLUS
@@ -7896,29 +7895,25 @@ void
        }
     }
 
-  for (list = names; list; list = TREE_CHAIN (list))
+  if (lookup_protocol (name, /* warn if deprecated */ false,
+                      /* definition_required */ false) == NULL_TREE)
     {
-      tree name = TREE_VALUE (list);
-
-      if (lookup_protocol (name, /* warn if deprecated */ false,
-                          /* definition_required */ false) == NULL_TREE)
+      tree protocol = make_node (PROTOCOL_INTERFACE_TYPE);
+      
+      TYPE_LANG_SLOT_1 (protocol)
+       = make_tree_vec (PROTOCOL_LANG_SLOT_ELTS);
+      PROTOCOL_NAME (protocol) = name;
+      PROTOCOL_LIST (protocol) = NULL_TREE;
+      add_protocol (protocol);
+      PROTOCOL_DEFINED (protocol) = 0;
+      PROTOCOL_FORWARD_DECL (protocol) = NULL_TREE;
+      
+      if (attributes)
        {
-         tree protocol = make_node (PROTOCOL_INTERFACE_TYPE);
-
-         TYPE_LANG_SLOT_1 (protocol)
-           = make_tree_vec (PROTOCOL_LANG_SLOT_ELTS);
-         PROTOCOL_NAME (protocol) = name;
-         PROTOCOL_LIST (protocol) = NULL_TREE;
-         add_protocol (protocol);
-         PROTOCOL_DEFINED (protocol) = 0;
-         PROTOCOL_FORWARD_DECL (protocol) = NULL_TREE;
-         
-         if (attributes)
-           {
-             TYPE_ATTRIBUTES (protocol) = attributes;
-             if (deprecated)
-               TREE_DEPRECATED (protocol) = 1;
-           }
+         /* TODO: Do we need to store the attributes here ? */
+         TYPE_ATTRIBUTES (protocol) = attributes;
+         if (deprecated)
+           TREE_DEPRECATED (protocol) = 1;
        }
     }
 }
Index: gcc/ChangeLog
===================================================================
--- gcc/ChangeLog       (revision 172399)
+++ gcc/ChangeLog       (working copy)
@@ -1,3 +1,8 @@
+2011-04-13  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * c-parser.c (c_parser_objc_protocol_definition): Updated for
+       change from objc_declare_protocols() to objc_declare_protocol().
+
 2011-04-13  Nathan Froyd  <froydnj@codesourcery.com>
 
        * tree-flow.h (struct gimple_df): Make free_ssanames a VEC.
Index: gcc/cp/ChangeLog
===================================================================
--- gcc/cp/ChangeLog    (revision 172399)
+++ gcc/cp/ChangeLog    (working copy)
@@ -1,3 +1,8 @@
+2011-04-13  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * parser.c (cp_parser_objc_protocol_declaration): Updated for
+       change from objc_declare_protocols() to objc_declare_protocol().
+
 2011-04-13  Jason Merrill  <jason@redhat.com>
 
        PR c++/48594
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c     (revision 172399)
+++ gcc/cp/parser.c     (working copy)
@@ -22304,7 +22304,8 @@ cp_parser_objc_protocol_declaration (cp_parser* pa
     {
       tok = cp_lexer_peek_token (parser->lexer);
       error_at (tok->location, "identifier expected after %<@protocol%>");
-      goto finish;
+      cp_parser_consume_semicolon_at_end_of_statement (parser);
+      return;
     }
 
   /* See if we have a forward declaration or a definition.  */
@@ -22313,9 +22314,21 @@ cp_parser_objc_protocol_declaration (cp_parser* pa
   /* Try a forward declaration first.  */
   if (tok->type == CPP_COMMA || tok->type == CPP_SEMICOLON)
     {
-      objc_declare_protocols (cp_parser_objc_identifier_list (parser), 
-                             attributes);
-     finish:
+      while (true)
+       {
+         tree id;
+         
+         id = cp_parser_identifier (parser);
+         if (id == error_mark_node)
+           break;
+         
+         objc_declare_protocol (id, attributes);
+         
+         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: gcc/c-parser.c
===================================================================
--- gcc/c-parser.c      (revision 172399)
+++ gcc/c-parser.c      (working copy)
@@ -7078,7 +7078,6 @@ c_parser_objc_protocol_definition (c_parser *parse
   if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA
       || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON)
     {
-      tree list = NULL_TREE;
       /* Any identifiers, including those declared as type names, are
         OK here.  */
       while (true)
@@ -7090,7 +7089,7 @@ c_parser_objc_protocol_definition (c_parser *parse
              break;
            }
          id = c_parser_peek_token (parser)->value;
-         list = chainon (list, build_tree_list (NULL_TREE, id));
+         objc_declare_protocol (id, attributes);
          c_parser_consume_token (parser);
          if (c_parser_next_token_is (parser, CPP_COMMA))
            c_parser_consume_token (parser);
@@ -7098,7 +7097,6 @@ c_parser_objc_protocol_definition (c_parser *parse
            break;
        }
       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
-      objc_declare_protocols (list, attributes);
     }
   else
     {



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]