From patchwork Tue Nov 2 09:42:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 69868 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 6D4871007D4 for ; Tue, 2 Nov 2010 20:42:30 +1100 (EST) Received: (qmail 5510 invoked by alias); 2 Nov 2010 09:42:26 -0000 Received: (qmail 5490 invoked by uid 22791); 2 Nov 2010 09:42:20 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL, BAYES_00, SARE_SUB_ENC_UTF8, TW_BJ, TW_JL, TW_TJ, 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; Tue, 02 Nov 2010 09:42:12 +0000 Received: from eggs.gnu.org ([140.186.70.92]:35404) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PDDNa-0003G7-7B for gcc-patches@gnu.org; Tue, 02 Nov 2010 05:42:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDDNY-0004IA-6Y for gcc-patches@gnu.org; Tue, 02 Nov 2010 05:42:10 -0400 Received: from smtp171.iad.emailsrvr.com ([207.97.245.171]:58142) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PDDNY-0004I5-0f for gcc-patches@gnu.org; Tue, 02 Nov 2010 05:42:08 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp37.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id ED6AB3B05DD for ; Tue, 2 Nov 2010 05:42:06 -0400 (EDT) Received: from dynamic9.wm-web.iad.mlsrvr.com (dynamic9.wm-web.iad1a.rsapps.net [192.168.2.216]) by smtp37.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id D8DF23B026E for ; Tue, 2 Nov 2010 05:42:06 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic9.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id CAC4C320088 for ; Tue, 2 Nov 2010 05:42:06 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Tue, 2 Nov 2010 10:42:06 +0100 (CET) Date: Tue, 2 Nov 2010 10:42:06 +0100 (CET) Subject: =?UTF-8?Q?ObjC/ObjC++:=20updated=20documentation=20on=20supported=20stan?= =?UTF-8?Q?dards, =20and=20added=20-fobjc-std=3Dobjc1?= From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1288690926.829416922@192.168.2.230> 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 patch: * updates the documentation on the version of Objective-C/Objective-C++ supported by the compiler; * adds a new -fobjc-std=objc1 option which causes the compiler to accept only the Objective-C 1.0 syntax (which for clarity of definition I defined as the Objective-C syntax accepted by GCC 4.0); * adds testcases for the new option. The reason that this new option is useful is that some projects have a large Objective-C codebase and require the codebase to compile with different versions of GCC, including old ones. It is handy to be able to have a flag that will prevent people with new compilers from committing code that uses a syntax not supported by old compilers. Of course, the default is to allow all the Objective-C 2.0 extensions. This flag is only for people who have a specific reason to disable the extensions. :-) The option name itself is not set in stone; suggestions I welcome. I like -fobjc-std=xxx (as opposed to, say, -fobjc-language-version=1 / -fobjc-language-version=2) for consistency with -std=xxx and because we don't know how future versions of the language may be named or presented so having a free string there helps to be adaptable (in the same way as it works for -std=xxx in C/C++). About the short string used to mean 'Objective-C 1.0', I chose 'objc1'. An alternative would be choosing 'gcc40', so the option could become -fobjc-std=gcc40. That may be more accurate, but less obvious (or maybe not). I'm happy to take suggestions on that. Else, Ok to commit to trunk ? Thanks In gcc/: 2010-11-02 Nicola Pero Implemented -fobjc-std=objc1 flag. * doc/invoke.texi (Option Summary): Document -fobjc-std=objc1 option. * doc/standards.texi (Standards): Updated the section on Objective-C; mention support for Objective-C 2.0 features and the new -fstd-objc=objc1 flag to disable them. In gcc/c-family/: 2010-11-02 Nicola Pero Implemented -fobjc-std=objc1 flag. * c.opt (fobjc-std=objc1): New option. In gcc/objc/: 2010-11-02 Nicola Pero Implemented -fobjc-std=objc1 flag. * objc-act.c (objc_start_class_interface): If attributes are specified when flag_objc1_only is set, print an error. (objc_start_category_interface): Same change. (objc_start_protocol): Same change. (objc_add_method_declaration): Same change. (objc_start_method_definition): Same change. (objc_build_keyword_decl): Same change. (objc_set_method_opt): If flag_objc1_only is set, print an error. (objc_add_property_declaration): Same change. (objc_add_synthesize_declaration): Same change. (objc_add_dynamic_declaration): Same change. (objc_finish_foreach_loop): Same change. (objc_maybe_build_component_ref): If flag_objc1_only is set, return immediately. In gcc/testsuite/: 2010-11-02 Nicola Pero Implemented -fobjc-std=objc1 flag. * objc.dg/fobjc-std-1.mm: New. * obj-c++.dg/fobjc-std-1.mm: New. \ No newline at end of file Index: gcc/doc/standards.texi =================================================================== --- gcc/doc/standards.texi (revision 166154) +++ gcc/doc/standards.texi (working copy) @@ -209,11 +209,13 @@ no C++ language dialect options are given, is @opt @cindex Objective-C++ GCC supports ``traditional'' Objective-C (also known as ``Objective-C -1.0''), and contains support for the Objective-C exception and -synchronization syntax. At the time of writing, it has no support for -``Objective-C 2.0'' language extensions. GCC supports Objective-C++ -and features available in Objective-C are also available in -Objective-C++@. +1.0'') and contains support for the Objective-C exception and +synchronization syntax. It has also support for a number of +``Objective-C 2.0'' language extensions, including properties, fast +enumeration (only for Objective-C), method attributes and the +@@optional and @@required keywords in protocols. GCC supports +Objective-C++ and features available in Objective-C are also available +in Objective-C++@. GCC by default uses the GNU Objective-C runtime library, which is part of GCC and is not the same as the Apple/NeXT Objective-C runtime @@ -242,12 +244,25 @@ not documentation on the newer ``Objective-C 2.0'' The Objective-C exception and synchronization syntax (that is, the keywords @@try, @@throw, @@catch, @@finally and @@synchronized) is -fully supported by GCC and is enabled with the option +supported by GCC and is enabled with the option @option{-fobjc-exceptions}. The syntax is briefly documented in this manual and in the Objective-C 2.0 manuals from Apple. -At the time of writing, GCC supports no Objective-C 2.0 features. The -authoritative manual on Objective-C 2.0 is available from Apple: +The Objective-C 2.0 language extensions and features are automatically +enabled; they include properties (via the @@property, @@synthesize and +@@dynamic keywords), fast enumeration (not available in +Objective-C++), attributes for methods (such as deprecated, noreturn, +sentinel, format), the unused attribute for method arguments, the +@@package keyword for instance variables and the @@optional and +@@required keywords in protocols. You can disable all these +Objective-C 2.0 language extensions with the option +@option{-fobjc-std=objc1}, which causes the compiler to recognize the +same Objective-C language syntax recognized by GCC 4.0, and to produce +an error if one of the new features is used. + +GCC has currently no support for non-fragile instance variables. + +The authoritative manual on Objective-C 2.0 is available from Apple: @itemize @item @uref{http://developer.apple.com/@/mac/@/library/@/documentation/@/Cocoa/@/Conceptual/@/ObjectiveC/} Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 166154) +++ gcc/doc/invoke.texi (working copy) @@ -212,6 +212,7 @@ Objective-C and Objective-C++ Dialects}. -fobjc-direct-dispatch @gol -fobjc-exceptions @gol -fobjc-gc @gol +-fobjc-std=objc1 @gol -freplace-objc-classes @gol -fzero-link @gol -gen-decls @gol @@ -2591,6 +2592,17 @@ programs. This option is only available with the GNU runtime has a different garbage collection implementation that does not require special compiler flags. +@item -fobjc-std=objc1 +@opindex fobjc-std +Conform to the language syntax of Objective-C 1.0, the language +recognized by GCC 4.0. This only affects the Objective-C additions to +the C/C++ language; it does not affect conformance to C/C++ standards, +which is controlled by the separate C/C++ dialect option flags. When +this option is used with the Objective-C or Objective-C++ compiler, +any Objective-C syntax that is not recognized by GCC 4.0 is rejected. +This is useful if you need to make sure that your Objective-C code can +be compiled with older versions of GCC. + @item -freplace-objc-classes @opindex freplace-objc-classes Emit a special marker instructing @command{ld(1)} not to statically link in Index: gcc/c-family/c.opt =================================================================== --- gcc/c-family/c.opt (revision 166154) +++ gcc/c-family/c.opt (working copy) @@ -870,6 +870,10 @@ fobjc-sjlj-exceptions ObjC ObjC++ Var(flag_objc_sjlj_exceptions) Init(-1) Enable Objective-C setjmp exception handling runtime +fobjc-std=objc1 +ObjC ObjC++ Var(flag_objc1_only) +Conform to the Objective-C 1.0 language as implemented in GCC 4.0 + fopenmp C ObjC C++ ObjC++ Var(flag_openmp) Enable OpenMP (implies -frecursive in Fortran) Index: gcc/c-family/ChangeLog =================================================================== --- gcc/c-family/ChangeLog (revision 166154) +++ gcc/c-family/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2010-11-02 Nicola Pero + + Implemented -fobjc-std=objc1 flag. + * c.opt (fobjc-std=objc1): New option. + 2010-11-01 Nicola Pero Implemented format and noreturn attributes for Objective-C methods. Index: gcc/objc/objc-act.c =================================================================== --- gcc/objc/objc-act.c (revision 166154) +++ gcc/objc/objc-act.c (working copy) @@ -686,9 +686,14 @@ objc_start_class_interface (tree klass, tree super tree protos, tree attributes) { if (attributes) - warning_at (input_location, OPT_Wattributes, - "class attributes are not available in this version" - " of the compiler, (ignored)"); + { + if (flag_objc1_only) + error_at (input_location, "class attributes are not available in Objective-C 1.0"); + else + warning_at (input_location, OPT_Wattributes, + "class attributes are not available in this version" + " of the compiler, (ignored)"); + } objc_interface_context = objc_ivar_context = start_class (CLASS_INTERFACE_TYPE, klass, super_class, protos); @@ -700,9 +705,14 @@ objc_start_category_interface (tree klass, tree ca tree protos, tree attributes) { if (attributes) - warning_at (input_location, OPT_Wattributes, - "category attributes are not available in this version" - " of the compiler, (ignored)"); + { + if (flag_objc1_only) + error_at (input_location, "category attributes are not available in Objective-C 1.0"); + else + warning_at (input_location, OPT_Wattributes, + "category attributes are not available in this version" + " of the compiler, (ignored)"); + } objc_interface_context = start_class (CATEGORY_INTERFACE_TYPE, klass, categ, protos); objc_ivar_chain @@ -713,9 +723,14 @@ void objc_start_protocol (tree name, tree protos, tree attributes) { if (attributes) - warning_at (input_location, OPT_Wattributes, - "protocol attributes are not available in this version" - " of the compiler, (ignored)"); + { + if (flag_objc1_only) + error_at (input_location, "protocol attributes are not available in Objective-C 1.0"); + else + warning_at (input_location, OPT_Wattributes, + "protocol attributes are not available in this version" + " of the compiler, (ignored)"); + } objc_interface_context = start_protocol (PROTOCOL_INTERFACE_TYPE, name, protos); objc_method_optional_flag = false; @@ -783,13 +798,21 @@ void objc_set_visibility (objc_ivar_visibility_kind visibility) { if (visibility == OBJC_IVAR_VIS_PACKAGE) - warning (0, "%<@package%> presently has the same effect as %<@public%>"); + { + if (flag_objc1_only) + error ("%<@package%> is not available in Objective-C 1.0"); + else + warning (0, "%<@package%> presently has the same effect as %<@public%>"); + } objc_ivar_visibility = visibility; } void objc_set_method_opt (bool optional) { + if (flag_objc1_only) + error_at (input_location, "@optional/@required are not available in Objective-C 1.0"); + objc_method_optional_flag = optional; if (!objc_interface_context || TREE_CODE (objc_interface_context) != PROTOCOL_INTERFACE_TYPE) @@ -827,6 +850,9 @@ objc_add_property_declaration (location_t location bool property_readonly = false; objc_property_assign_semantics property_assign_semantics = OBJC_PROPERTY_ASSIGN; + if (flag_objc1_only) + error_at (input_location, "%<@property%> is not available in Objective-C 1.0"); + if (parsed_property_readonly && parsed_property_readwrite) { error_at (location, "% attribute conflicts with % attribute"); @@ -1069,6 +1095,11 @@ objc_maybe_build_component_ref (tree object, tree tree x = NULL_TREE; tree rtype; + /* If we are in Objective-C 1.0 mode, properties are not + available. */ + if (flag_objc1_only) + return NULL_TREE; + /* Try to determine quickly if 'object' is an Objective-C object or not. If not, return. */ if (object == NULL_TREE || object == error_mark_node @@ -1232,6 +1263,9 @@ objc_add_method_declaration (bool is_class_method, fatal_error ("method declaration not in @interface context"); } + if (flag_objc1_only && attributes) + error_at (input_location, "method attributes are not available in Objective-C 1.0"); + objc_decl_method_attributes (&decl, attributes, 0); objc_add_method (objc_interface_context, decl, @@ -6518,6 +6552,9 @@ objc_build_keyword_decl (tree key_name, tree arg_t { tree keyword_decl; + if (flag_objc1_only && attributes) + error_at (input_location, "method argument attributes are not available in Objective-C 1.0"); + /* If no type is specified, default to "id". */ arg_type = adjust_type_for_id_default (arg_type); @@ -9225,6 +9262,9 @@ objc_add_synthesize_declaration (location_t locati { tree interface, chain; + if (flag_objc1_only) + error_at (input_location, "%<@synthesize%> is not available in Objective-C 1.0"); + if (property_and_ivar_list == error_mark_node) return; @@ -9345,6 +9385,9 @@ objc_add_dynamic_declaration (location_t location, { tree interface, chain; + if (flag_objc1_only) + error_at (input_location, "%<@dynamic%> is not available in Objective-C 1.0"); + if (property_list == error_mark_node) return; @@ -12049,6 +12092,9 @@ objc_finish_foreach_loop (location_t location, tre tree t; int i; + if (flag_objc1_only) + error_at (location, "fast enumeration is not available in Objective-C 1.0"); + if (object_expression == error_mark_node) return; Index: gcc/objc/ChangeLog =================================================================== --- gcc/objc/ChangeLog (revision 166154) +++ gcc/objc/ChangeLog (working copy) @@ -1,3 +1,23 @@ +2010-11-02 Nicola Pero + + Implemented -fobjc-std=objc1 flag. + * objc-act.c (objc_start_class_interface): If attributes are + specified when flag_objc1_only is set, print an error. + (objc_start_category_interface): Same change. + (objc_start_protocol): Same change. + (objc_add_method_declaration): Same change. + (objc_start_method_definition): Same change. + (objc_build_keyword_decl): Same change. + (objc_set_visibility): If OBJC_IVAR_VIS_PACKAGE is used when + flag_objc1_set is set, print an error. + (objc_set_method_opt): If flag_objc1_only is set, print an error. + (objc_add_property_declaration): Same change. + (objc_add_synthesize_declaration): Same change. + (objc_add_dynamic_declaration): Same change. + (objc_finish_foreach_loop): Same change. + (objc_maybe_build_component_ref): If flag_objc1_only is set, + return immediately. + 2010-11-01 Nicola Pero Implemented format and noreturn attributes for Objective-C methods. Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 166154) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,12 @@ +2010-11-02 Nicola Pero + + Implemented -fobjc-std=objc1 flag. + * doc/invoke.texi (Option Summary): Document -fobjc-std=objc1 + option. + * doc/standards.texi (Standards): Updated the section on + Objective-C; mention support for Objective-C 2.0 features and the + new -fstd-objc=objc1 flag to disable them. + 2010-11-01 Paul Koning * config/pdp11/pdp11.md: Use iterators. Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 166154) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2010-11-02 Nicola Pero + + Implemented -fobjc-std=objc1 flag. + * objc.dg/fobjc-std-1.mm: New. + * obj-c++.dg/fobjc-std-1.mm: New. + 2010-11-01 Nicola Pero Implemented format and noreturn attributes for Objective-C methods. Index: gcc/testsuite/objc.dg/fobjc-std-1.m =================================================================== --- gcc/testsuite/objc.dg/fobjc-std-1.m (revision 0) +++ gcc/testsuite/objc.dg/fobjc-std-1.m (revision 0) @@ -0,0 +1,54 @@ +/* Test warnings when using -fobjc-std=objc1. */ +/* { dg-do compile } */ +/* { dg-options "-fobjc-std=objc1" } */ + +#include + +__attribute__ ((deprecated)) +@interface MyRootClass +{ /* { dg-error "class attributes are not available in Objective.C 1.0" } */ + Class isa; +@package /* { dg-error "not available in Objective.C 1.0" } */ + int a; + int b; +} ++ (id) alloc __attribute__ ((deprecated)); /* { dg-error "not available in Objective.C 1.0" } */ +- (id) init; +- (id) testMe: (id) __attribute__((unused)) argument; /* { dg-error "not available in Objective.C 1.0" } */ +@property (nonatomic) int a; /* { dg-error "not available in Objective.C 1.0" } */ +@property (nonatomic) int b; /* { dg-error "not available in Objective.C 1.0" } */ +@end + +@implementation MyRootClass ++ (id) alloc { return self; } +- (id) init { return self; } +- (id) testMe: (id) __attribute__((unused)) argument { return self; } /* { dg-error "not available in Objective.C 1.0" } */ +@synthesize a; /* { dg-error "not available in Objective.C 1.0" } */ +@dynamic b; /* { dg-error "not available in Objective.C 1.0" } */ +@end + +__attribute__ ((deprecated)) +@protocol MyProtocol +- (id) test; /* { dg-error "protocol attributes are not available in Objective.C 1.0" } */ +@required /* { dg-error "not available in Objective.C 1.0" } */ +- (id) variable __attribute__ ((deprecated)); /* { dg-error "not available in Objective.C 1.0" } */ +@optional /* { dg-error "not available in Objective.C 1.0" } */ +@end + +@interface MyRootClass (NSFastEnumeration) +- (unsigned long)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state + objects:(id *)stackbuf + count:(unsigned int)len; +@end + +@class NSArray; + +int array_length (NSArray *array) +{ + int i = 0; + + for (id object in array) /* { dg-error "not available in Objective.C 1.0" } */ + i++; + + return i; +} Index: gcc/testsuite/obj-c++.dg/fobjc-std-1.mm =================================================================== --- gcc/testsuite/obj-c++.dg/fobjc-std-1.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/fobjc-std-1.mm (revision 0) @@ -0,0 +1,55 @@ +/* Test warnings when using -fobjc-std=objc1. */ +/* { dg-do compile } */ +/* { dg-options "-fobjc-std=objc1" } */ + +#include + +__attribute__ ((deprecated)) +@interface MyRootClass /* { dg-error "class attributes are not available in Objective.C 1.0" } */ +{ + Class isa; /* { dg-error ".@package. is not available in Objective.C 1.0" } */ +@package + int a; + int b; +} ++ (id) alloc __attribute__ ((deprecated)); /* { dg-error "not available in Objective.C 1.0" } */ +- (id) init; +- (id) testMe: (id) __attribute__((unused)) argument; /* { dg-error "not available in Objective.C 1.0" } */ +@property (nonatomic) int a; /* { dg-error "not available in Objective.C 1.0" } */ +@property (nonatomic) int b; /* { dg-error "not available in Objective.C 1.0" } */ +@end + +@implementation MyRootClass ++ (id) alloc { return self; } +- (id) init { return self; } +- (id) testMe: (id) __attribute__((unused)) argument { return self; } /* { dg-error "not available in Objective.C 1.0" } */ +@synthesize a; /* { dg-error "not available in Objective.C 1.0" } */ +@dynamic b; /* { dg-error "not available in Objective.C 1.0" } */ +@end + +__attribute__ ((deprecated)) +@protocol MyProtocol /* { dg-error "protocol attributes are not available in Objective.C 1.0" } */ + +@required /* { dg-error "not available in Objective.C 1.0" } */ +- (id) variable __attribute__ ((deprecated)); /* { dg-error "not available in Objective.C 1.0" } */ +@optional /* { dg-error "not available in Objective.C 1.0" } */ +@end +#if 0 /* fast enumeration is not implemented even in Objective-C 2.0 */ +@interface MyRootClass (NSFastEnumeration) +- (unsigned long)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state + objects:(id *)stackbuf + count:(unsigned int)len; +@end + +@class NSArray; + +int array_length (NSArray *array) +{ + int i = 0; + + for (id object in array) /* dg-error "not available in Objective.C 1.0" */ + i++; + + return i; +} +#endif