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] |
This patch implements fast enumeration for Objective-C. :-) It is not a merge from the apple branch because there was almost no working code to merge (the parser is different, and the objc-act.c code no longer even compiled). I (obviously) did study that code a lot though. I mentioned C in the Subject: because while I think I have only substantially changed the code for Objective-C, I had to make substantial changes to c_parser_for_statement() and a C FE maintainer should really look at the changes in this case. ;-) The implementation is hard because: * for some reason, Apple used the syntax "for (object in collection)" instead of the more natural "@for (object in collection)". Hence, the only way to implement it is to modify the parsing of 'for' loops in C, and then there is the problem of even knowing whether we are parsing a normal C for loop or an Objective-C foreach (fast enumeration) loop. * a substantial amount of code generation need to be done in objc-act.c. Apple wrote one chunk of code for Objective-C, and then another chunk for Objective-C++. Apple's code was no longer even compiling and I rewrote the Objective-C one entirely from scratch. To help with these issues, I have: * decided that, unlike in the Apple compiler, "for (id object in collection)" is only available when using -std=c99. "for (object in collection)" is always available. This is what I was expecting from the very beginning as a user and was surprised to find that Apple implemented it in a different way (and made "for (id object in collection)" available even when not using -std=c99). I prefer how I did it because it is identical to how the C syntax for 'for' works in C, and it simplifies a lot the Objective-C implementation if at least that works in the same way (otherwise, when we parse "for", we don't know if we need to open a c99 compound statement or not and we can't know until we have parse part of it, but that parsing generates declarations, so it gets ugly and messy! I hope my code is simpler than that.) * tried to write the code generation in a way that should work for both the Objective-C and Objective-C++ frontends. I haven't looked at Objective-C++ yet, so maybe that is just wishful thinking. ;-) The patch includes a number of testcases that I used to test the implementation; these most likely need to be tidied up. Eg, I disabled them for the NeXT runtime just to avoid having to figure out what headers to include. ;-) I added lots of comments, but no documentation. I also feel we could do better type checking. These are easier things to do once the big patch is in, and I'll send follow up patches as needed. On my i686-pc-linux-gnu machine, there are no Objective-C regressions, but the new fast enumeration testcases all pass with this patch. :-) I'll obviously need to run the full C testsuite before committing and make sure there are no regressions. Comments and suggestions very welcome. Ok to apply ? Thanks gcc/ChangeLog: 2010-10-03 Nicola Pero <nicola.pero@meta-innovation.com> Implemented fast enumeration for Objective-C. * c-parser.c (objc_could_be_foreach_context): New. (c_lex_one_token): Recognize RID_IN keyword in a potential Objective-C foreach context. (c_parser_declaration_or_fndef): Added parameter. Accept Objective-C RID_IN keyword as terminating a declaration; in that case, return the declaration in the new parameter. (c_parser_extenral_declaration): Updated calls to c_parser_declaration_or_fndef. (c_parser_declaration_or_fndef): Same change. (c_parser_compound_statement_nostart): Same change. (c_parser_label): Same change. (c_parser_objc_methodprotolist): Same change. (c_parser_omp_for_loop): Same change. (c_parser_for_statement): Detect and parse Objective-C foreach statements. gcc/objc/ChangeLog: 2010-10-03 Nicola Pero <nicola.pero@meta-innovation.com> Merge from 'apple/trunk' branch on FSF servers. 2006-04-12 Fariborz Jahanian <fjahanian@apple.com> Radar 4507230 * objc-act.c (objc_type_valid_for_messaging): New routine to check for valid objc object types. (objc_finish_foreach_loop): Check for invalid objc objects in foreach header. 2010-10-03 Nicola Pero <nicola.pero@meta-innovation.com> Implemented fast enumeration for Objective-C. * objc-act.c (build_fast_enumeration_state_template): New. (TAG_ENUMERATION_MUTATION): New. (TAG_FAST_ENUMERATION_STATE): New. (objc_init): Call build_fast_enumeration_state_template() and set objc_enumeration_mutation_decl, TAG_ENUMERATION_MUTATION and TAG_FAST_ENUMERATION_STATE. (objc_create_temporary_var): Allow providing a name to temporary variables. (objc_build_exc_ptr): Updated calls to objc_create_temporary_var(). (next_sjlj_build_try_catch_finally): Same change. (objc_finish_foreach_loop): New. * objc-act.h: Added OCTI_FAST_ENUM_STATE_TEMP, OCTI_ENUM_MUTATION_DECL, objc_fast_enumeration_state_template, objc_enumeration_mutation_decl. gcc/c-family/ChangeLog: 2010-10-03 Nicola Pero <nicola.pero@meta-innovation.com> Implemented fast enumeration for Objective-C. * c-common.h (objc_finish_foreach_loop): New. * stub-objc.c (objc_finish_foreach_loop): New. gcc/testsuite/ChangeLog: 2010-10-03 Nicola Pero <nicola.pero@meta-innovation.com> Implemented fast enumeration for Objective-C. * objc.dg/foreach-1.m: New. * objc.dg/foreach-2.m: New. * objc.dg/foreach-3.m: New. * objc.dg/foreach-4.m: New. * objc.dg/foreach-5.m: New. * objc.dg/foreach-6.m: New. Merge from 'apple/trunk' branch on FSF servers: 2006-04-13 Fariborz Jahanian <fjahanian@apple.com> Radar 4502236 * objc.dg/objc-foreach-5.m: New. 2006-04-12 Fariborz Jahanian <fjahanian@apple.com> Radar 4507230 * objc.dg/objc-foreach-4.m: New. 2006-03-13 Fariborz Jahanian <fjahanian@apple.com> Radar 4472881 * objc.dg/objc-foreach-3.m: New. 2005-03-07 Fariborz Jahanian <fjahanian@apple.com> Radar 4468498 * objc.dg/objc-foreach-2.m: New. 2006-02-15 Fariborz Jahanian <fjahanian@apple.com> Radar 4294910 * objc.dg/objc-foreach-1.m: New libobjc/ChangeLog: 2010-10-01 Nicola Pero <nicola.pero@meta-innovation.com> Implemented fast enumeration for Objective-C. * Makefile.in (C_SOURCE_FILES): Added objc-foreach.c. (OBJC_H): Added runtime.h * objc-foreach.c: New file. * objc/runtime.h: New file.
Attachment:
patch
Description: Binary data
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |