From patchwork Sun Jul 10 16:59:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 104064 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 D73D5B6F8D for ; Mon, 11 Jul 2011 02:59:51 +1000 (EST) Received: (qmail 30873 invoked by alias); 10 Jul 2011 16:59:50 -0000 Received: (qmail 30862 invoked by uid 22791); 10 Jul 2011 16:59:48 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, 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; Sun, 10 Jul 2011 16:59:33 +0000 Received: from eggs.gnu.org ([140.186.70.92]:37517) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1QfxLw-0003fV-Ns for gcc-patches@gnu.org; Sun, 10 Jul 2011 12:59:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QfxLu-0006ki-Ka for gcc-patches@gnu.org; Sun, 10 Jul 2011 12:59:32 -0400 Received: from smtp171.iad.emailsrvr.com ([207.97.245.171]:49754) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QfxLu-0006kc-Bo for gcc-patches@gnu.org; Sun, 10 Jul 2011 12:59:30 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp57.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 50DBAF826A for ; Sun, 10 Jul 2011 12:59:29 -0400 (EDT) Received: by smtp57.relay.iad1a.emailsrvr.com (Authenticated sender: nicola.pero-AT-meta-innovation.com) with ESMTPSA id 92F40F826F for ; Sun, 10 Jul 2011 12:59:28 -0400 (EDT) From: Nicola Pero Subject: ObjC: hide encoding obstacks inside objc-encoding.c Date: Sun, 10 Jul 2011 17:59:26 +0100 Message-Id: <8509173B-10D8-4C6C-BD30-A9E2D6660201@meta-innovation.com> To: gcc-patches@gnu.org Mime-Version: 1.0 (Apple Message framework v1084) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 207.97.245.171 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 Objective-C patch does an obvious cleanup of the encoding code internal API, by hiding the obstacks used to create the encoding strings inside objc-encoding.c. This provides a cleaner, simpler API, and improves code modularity. In practice, the patch makes the following changes: * have objc-act.c use the new objc_encoding_init() instead of setting up the obstacks directly; * improve encode_field_decl() to take only the field_decl as argument, and return the encoding string as identifier instead of requiring callers to access and manipulate the obstacks directly. * consequent cleanups, including removing dependency of various files from obstack.h. Ok to commit ? Thanks Index: objc/objc-encoding.c =================================================================== --- objc/objc-encoding.c (revision 176090) +++ objc/objc-encoding.c (working copy) @@ -53,18 +53,24 @@ along with GCC; see the file COPYING3. If not see /* Set up for use of obstacks. */ #include "obstack.h" -/* This obstack is used to accumulate the encoding of a data type. - TODO: Make this static. */ -struct obstack util_obstack; +/* This obstack is used to accumulate the encoding of a data type. */ +static struct obstack util_obstack; /* This points to the beginning of obstack contents, so we can free - the whole contents. TODO: Make this static. */ -char *util_firstobj; + the whole contents. */ +static char *util_firstobj; +void objc_encoding_init (void) +{ + gcc_obstack_init (&util_obstack); + util_firstobj = (char *) obstack_finish (&util_obstack); +} + int generating_instance_variables = 0; static void encode_type_qualifiers (tree); static void encode_type (tree, int, int); +static void encode_field (tree field_decl, int curtype, int format); static tree objc_method_parm_type (tree type) @@ -470,7 +476,7 @@ encode_aggregate_fields (tree type, bool pointed_t obstack_1grow (&util_obstack, '"'); } - encode_field_decl (field, curtype, format); + encode_field (field, curtype, format); } } @@ -802,8 +808,8 @@ encode_gnu_bitfield (int position, tree type, int obstack_grow (&util_obstack, buffer, strlen (buffer)); } -void -encode_field_decl (tree field_decl, int curtype, int format) +static void +encode_field (tree field_decl, int curtype, int format) { #ifdef OBJCPLUS /* C++ static members, and things that are not fields at all, @@ -828,6 +834,25 @@ encode_gnu_bitfield (int position, tree type, int encode_type (TREE_TYPE (field_decl), curtype, format); } +tree +encode_field_decl (tree field_decl) +{ + tree result; + + encode_field (field_decl, + obstack_object_size (&util_obstack), + OBJC_ENCODE_DONT_INLINE_DEFS); + + /* Null terminate string. */ + obstack_1grow (&util_obstack, 0); + + /* Get identifier for the string. */ + result = get_identifier (XOBFINISH (&util_obstack, char *)); + obstack_free (&util_obstack, util_firstobj); + + return result; +} + /* This routine encodes the attribute of the input PROPERTY according to following formula: Index: objc/ChangeLog =================================================================== --- objc/ChangeLog (revision 176090) +++ objc/ChangeLog (working copy) @@ -1,3 +1,30 @@ +2011-07-10 Nicola Pero + + * objc-encoding.h (obstack.h): Do not include. + (util_obstack, util_firstobj): Do not declare. + (encode_field_decl): Updated prototype to return a tree and take a + single tree argument. Updated comments. + * objc-encoding.c (util_obstack, util_firstobj): Made static. + (objc_encoding_init): New. + (encode_field_decl): Existing function renamed to encode_field and + made static. New encode_field_decl wrapper function added. + (encode_aggregate_fields): Update call to encode_field_decl to + call encode_field. + * objc-next-runtime-abi-02.c (obstack.h): Do not include. + (util_obstack, util_firstobj): Do not declare. + (build_v2_ivar_list_initializer): Updated call to + encode_field_decl. + * objc-runtime-shared-support.c (obstack.h): Do not include. + (util_obstack, util_firstobj): Do not declare. + (build_ivar_list_initializer): Updated call to encode_field_decl. + * objc-act.c (objc_init): Use objc_encoding_init. + * Make-lang.in (objc/objc-runtime-shared-support.o): Do not depend + on OBSTACK_H. + (objc/objc-gnu-runtime-abi-01.o): Likewise. + (objc/objc-next-runtime-abi-01.o): Likewise. + (objc/objc-next-runtime-abi-02.o): Likewise. + (objc/objc-act.o): Likewise. + 2011-07-04 Nicola Pero Refactored encoding code into objc-encoding.h and objc-encoding.c. Index: objc/objc-encoding.h =================================================================== --- objc/objc-encoding.h (revision 176090) +++ objc/objc-encoding.h (working copy) @@ -22,26 +22,11 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_OBJC_ENCODING_H #define GCC_OBJC_ENCODING_H -/* TODO: Hide the following obstack code in objc-encoding.c, and have - a objc_encoding_init() that is called by objc_init() to set them - up. */ - -/* Set up for use of obstacks. */ -#include "obstack.h" - -/* This obstack is used to accumulate the encoding of a data type. */ -extern struct obstack util_obstack; - -/* This points to the beginning of obstack contents, so we can free - the whole contents. */ -extern char *util_firstobj; - -/* This will be used to initialize the obstacks used by encoding. It +/* This is used to initialize the obstacks used by encoding. It should be called before any encoding function is used. It is usually done in objc_init(). */ -/* extern void objc_encoding_init (void); */ +extern void objc_encoding_init (void); - /* Encode a method prototype. The format is described in gcc/doc/objc.texi, section 'Method signatures'. */ extern tree encode_method_prototype (tree method_decl); @@ -57,8 +42,10 @@ extern tree objc_build_encode_expr (tree type); /* Encode the attributes of a property. */ extern tree objc_v2_encode_prop_attr (tree property); -/* Encode the type of a field. */ -extern void encode_field_decl (tree field_decl, int curtype, int format); +/* Encode the type of a field. Return an identifier with the type + encoding for the field. The type encoding is a null-terminated + string. */ +extern tree encode_field_decl (tree field_decl); /* Tells "encode_pointer/encode_aggregate" whether we are generating type descriptors for instance variables (as opposed to methods). Index: objc/objc-runtime-shared-support.c =================================================================== --- objc/objc-runtime-shared-support.c (revision 176090) +++ objc/objc-runtime-shared-support.c (working copy) @@ -41,12 +41,6 @@ along with GCC; see the file COPYING3. If not see #include "objcp-decl.h" #endif /* OBJCPLUS */ -#include "obstack.h" - -/* These are only used for encoding ivars. */ -extern struct obstack util_obstack; -extern char *util_firstobj; - /* Hooks for string decls etc. */ #include "objc-runtime-hooks.h" @@ -551,16 +545,9 @@ build_ivar_list_initializer (tree type, tree field CONSTRUCTOR_APPEND_ELT (ivar, NULL_TREE, build_int_cst (NULL_TREE, 0)); /* Set type. */ - encode_field_decl (field_decl, - obstack_object_size (&util_obstack), - OBJC_ENCODE_DONT_INLINE_DEFS); - - /* Null terminate string. */ - obstack_1grow (&util_obstack, 0); - id = add_objc_string (get_identifier (XOBFINISH (&util_obstack, char *)), + id = add_objc_string (encode_field_decl (field_decl), meth_var_types); CONSTRUCTOR_APPEND_ELT (ivar, NULL_TREE, id); - obstack_free (&util_obstack, util_firstobj); /* Set offset. */ CONSTRUCTOR_APPEND_ELT (ivar, NULL_TREE, byte_position (field_decl)); Index: objc/Make-lang.in =================================================================== --- objc/Make-lang.in (revision 176090) +++ objc/Make-lang.in (working copy) @@ -88,7 +88,6 @@ objc/objc-runtime-shared-support.o : objc/objc-run gt-objc-objc-runtime-shared-support.h \ $(START_HDRS) \ $(GGC_H) $(DIAGNOSTIC_CORE_H) $(FLAGS_H) input.h \ - $(OBSTACK_H) \ objc/objc-encoding.h \ objc/objc-next-metadata-tags.h \ objc/objc-runtime-shared-support.h @@ -97,7 +96,6 @@ objc/objc-gnu-runtime-abi-01.o: objc/objc-gnu-runt gt-objc-objc-gnu-runtime-abi-01.h \ $(START_HDRS) \ $(GGC_H) $(DIAGNOSTIC_CORE_H) $(FLAGS_H) input.h \ - $(OBSTACK_H) \ toplev.h \ objc/objc-encoding.h \ objc/objc-runtime-hooks.h \ @@ -107,7 +105,6 @@ objc/objc-next-runtime-abi-01.o: objc/objc-next-ru gt-objc-objc-next-runtime-abi-01.h \ $(START_HDRS) \ $(GGC_H) $(DIAGNOSTIC_CORE_H) $(FLAGS_H) input.h \ - $(OBSTACK_H) \ $(TARGET_H) output.h \ objc/objc-encoding.h \ objc/objc-next-metadata-tags.h \ @@ -118,7 +115,6 @@ objc/objc-next-runtime-abi-02.o: objc/objc-next-ru gt-objc-objc-next-runtime-abi-02.h \ $(START_HDRS) \ $(GGC_H) $(DIAGNOSTIC_CORE_H) $(FLAGS_H) input.h \ - $(OBSTACK_H) \ $(TARGET_H) \ objc/objc-encoding.h \ objc/objc-next-metadata-tags.h \ @@ -129,7 +125,6 @@ objc/objc-act.o : objc/objc-act.c \ gt-objc-objc-act.h \ $(START_HDRS) \ $(GGC_H) $(DIAGNOSTIC_CORE_H) $(FLAGS_H) input.h \ - $(OBSTACK_H) \ toplev.h $(FUNCTION_H) output.h debug.h $(LANGHOOKS_DEF_H) \ $(HASHTAB_H) $(GIMPLE_H) \ $(C_PRAGMA_H) $(C_TARGET_H) \ Index: objc/objc-act.c =================================================================== --- objc/objc-act.c (revision 176090) +++ objc/objc-act.c (working copy) @@ -381,9 +381,7 @@ objc_init (void) /* Set up stuff used by FE parser and all runtimes. */ errbuf = XNEWVEC (char, 1024 * 10); hash_init (); - /* TODO: Use objc_encoding_init(). */ - gcc_obstack_init (&util_obstack); - util_firstobj = (char *) obstack_finish (&util_obstack); + objc_encoding_init (); /* ... and then check flags and set-up for the selected runtime ... */ if (flag_next_runtime && flag_objc_abi >= 2) ok = objc_next_runtime_abi_02_init (&runtime); Index: objc/objc-next-runtime-abi-02.c =================================================================== --- objc/objc-next-runtime-abi-02.c (revision 176090) +++ objc/objc-next-runtime-abi-02.c (working copy) @@ -50,13 +50,8 @@ along with GCC; see the file COPYING3. If not see #include "ggc.h" #include "target.h" -#include "obstack.h" #include "tree-iterator.h" -/* These are only used for encoding ivars. */ -extern struct obstack util_obstack; -extern char *util_firstobj; - #include "objc-runtime-hooks.h" #include "objc-runtime-shared-support.h" #include "objc-encoding.h" @@ -2852,15 +2847,9 @@ build_v2_ivar_list_initializer (tree class_name, t meth_var_names)); /* Set type. */ - encode_field_decl (field_decl, - obstack_object_size (&util_obstack), - OBJC_ENCODE_DONT_INLINE_DEFS); - /* Null terminate string. */ - obstack_1grow (&util_obstack, 0); - id = add_objc_string (get_identifier (XOBFINISH (&util_obstack, char *)), + id = add_objc_string (encode_field_decl (field_decl), meth_var_types); CONSTRUCTOR_APPEND_ELT (ivar, NULL_TREE, id); - obstack_free (&util_obstack, util_firstobj); /* Set alignment. */ val = DECL_ALIGN_UNIT (field_decl); Index: objcp/Make-lang.in =================================================================== --- objcp/Make-lang.in (revision 176090) +++ objcp/Make-lang.in (working copy) @@ -92,7 +92,6 @@ objcp/objc-runtime-shared-support.o : objc/objc-ru gt-objc-objc-runtime-shared-support.h \ $(START_HDRS) \ $(GGC_H) $(DIAGNOSTIC_CORE_H) $(FLAGS_H) input.h \ - $(OBSTACK_H) \ objc/objc-encoding.h \ objc/objc-next-metadata-tags.h \ objc/objc-runtime-shared-support.h \ @@ -104,7 +103,6 @@ objcp/objc-gnu-runtime-abi-01.o: objc/objc-gnu-run gt-objc-objc-gnu-runtime-abi-01.h \ $(START_HDRS) \ $(GGC_H) $(DIAGNOSTIC_CORE_H) $(FLAGS_H) input.h \ - $(OBSTACK_H) \ toplev.h \ objc/objc-encoding.h \ objc/objc-runtime-hooks.h \ @@ -117,7 +115,6 @@ objcp/objc-next-runtime-abi-01.o: objc/objc-next-r gt-objc-objc-next-runtime-abi-01.h \ $(START_HDRS) \ $(GGC_H) $(DIAGNOSTIC_CORE_H) $(FLAGS_H) input.h \ - $(OBSTACK_H) \ $(TARGET_H) output.h \ objc/objc-encoding.h \ objc/objc-next-metadata-tags.h \ @@ -131,7 +128,6 @@ objcp/objc-next-runtime-abi-02.o: objc/objc-next-r gt-objc-objc-next-runtime-abi-02.h \ $(START_HDRS) \ $(GGC_H) $(DIAGNOSTIC_CORE_H) $(FLAGS_H) input.h \ - $(OBSTACK_H) \ $(TARGET_H) \ objc/objc-encoding.h \ objc/objc-next-metadata-tags.h \ @@ -148,7 +144,6 @@ objcp/objcp-act.o : objc/objc-act.c \ gt-objc-objc-act.h \ $(START_HDRS) \ $(GGC_H) $(DIAGNOSTIC_H) $(FLAGS_H) input.h \ - $(OBSTACK_H) \ toplev.h $(FUNCTION_H) output.h debug.h $(LANGHOOKS_DEF_H) \ $(HASHTAB_H) $(GIMPLE_H) \ $(RTL_H) $(EXPR_H) $(TARGET_H) \ Index: objcp/ChangeLog =================================================================== --- objcp/ChangeLog (revision 176090) +++ objcp/ChangeLog (working copy) @@ -1,3 +1,12 @@ +2011-07-10 Nicola Pero + + * Make-lang.in (objcp/objc-runtime-shared-support.o): Do not + depend on OBSTACK_H. + (objcp/objc-gnu-runtime-abi-01.o): Likewise. + (objcp/objc-next-runtime-abi-01.o): Likewise. + (objcp/objc-next-runtime-abi-02.o): Likewise. + (objcp/objcp-act.o): Likewise. + 2011-07-04 Nicola Pero * Make-lang.in (OBJCXX_OBJS): Added objc-encoding.o.