aboutsummaryrefslogtreecommitdiff
path: root/libobjc
diff options
context:
space:
mode:
authorNicola Pero <nicola.pero@meta-innovation.com>2010-10-06 10:10:14 +0000
committerNicola Pero <nicola@gcc.gnu.org>2010-10-06 10:10:14 +0000
commitf05b9d93e96c2a97d80e7fc3b10df7b86c6081b0 (patch)
tree9dd722f6e098569456083c38fb1b313e672cd799 /libobjc
parentb938bc48d844e85327c603e01bb6c303462c2613 (diff)
downloadgcc-f05b9d93e96c2a97d80e7fc3b10df7b86c6081b0.zip
gcc-f05b9d93e96c2a97d80e7fc3b10df7b86c6081b0.tar.gz
gcc-f05b9d93e96c2a97d80e7fc3b10df7b86c6081b0.tar.bz2
In gcc/: 2010-10-06 Nicola Pero <nicola.pero@meta-innovation.com>
In gcc/: 2010-10-06 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. (c_parser_omp_for_loop): Updated call to check_for_loop_decls(). * c-decl.c (check_for_loop_decls): Added parameter to allow ObjC fast enumeration parsing code to turn off the c99 error but still perform checks on the loop declarations. * c-tree.h (check_for_loop_decls): Updated declaration. * doc/objc.texi: Document fast enumeration. In gcc/c-family/: 2010-10-06 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. In gcc/objc/: 2010-10-06 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. (synth_module_prologue): Call build_fast_enumeration_state_template() and set up objc_enumeration_mutation_decl. (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. 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. In gcc/testsuite/: 2010-10-05 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. * objc.dg/foreach-7.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 In libobjc/: 2010-10-06 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. From-SVN: r165019
Diffstat (limited to 'libobjc')
-rw-r--r--libobjc/ChangeLog8
-rw-r--r--libobjc/Makefile.in2
-rw-r--r--libobjc/objc-foreach.c52
-rw-r--r--libobjc/objc/runtime.h88
4 files changed, 150 insertions, 0 deletions
diff --git a/libobjc/ChangeLog b/libobjc/ChangeLog
index b1590c4..ac51fcb 100644
--- a/libobjc/ChangeLog
+++ b/libobjc/ChangeLog
@@ -1,3 +1,11 @@
+2010-10-06 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.
+
2010-09-30 Kai Tietz <kai.tietz@onevision.com>
* objc/deprecated/struct_objc_class.h: Add padding
diff --git a/libobjc/Makefile.in b/libobjc/Makefile.in
index 71a3a2e..d99ab26 100644
--- a/libobjc/Makefile.in
+++ b/libobjc/Makefile.in
@@ -120,6 +120,7 @@ OBJC_H = \
message.h \
objc-api.h \
objc-decls.h \
+ runtime.h \
thr.h \
\
hash.h \
@@ -163,6 +164,7 @@ C_SOURCE_FILES = \
init.c \
memory.c \
nil_method.c \
+ objc-foreach.c \
objc-sync.c \
objects.c \
sarray.c \
diff --git a/libobjc/objc-foreach.c b/libobjc/objc-foreach.c
new file mode 100644
index 0000000..83a9101
--- /dev/null
+++ b/libobjc/objc-foreach.c
@@ -0,0 +1,52 @@
+/* GNU Objective C Runtime 'fast enumeration' implementation
+ Copyright (C) 2010 Free Software Foundation, Inc.
+ Contributed by Nicola Pero <nicola.pero@meta-innovation.com>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under the
+terms of the GNU General Public License as published by the Free Software
+Foundation; either version 3, or (at your option) any later version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+/*
+ This file implements objc_enumeration_mutation() and
+ objc_set_enumeration_mutation_handler(), the two functions required
+ to handle mutations during a fast enumeration.
+*/
+#include "objc/runtime.h" /* For objc_enumerationMutation() and objc_set_enumeration_mutation_handler() */
+#include "objc-private/error.h" /* For _objc_abort() */
+
+/* The enumeration mutation handler currently in use. */
+static void (*__objc_enumeration_mutation_handler)(id) = NULL;
+
+void
+objc_set_enumeration_mutation_handler (void (*handler)(id))
+{
+ __objc_enumeration_mutation_handler = handler;
+}
+
+void
+objc_enumerationMutation (id collection)
+{
+ if (__objc_enumeration_mutation_handler != NULL)
+ (*__objc_enumeration_mutation_handler) (collection);
+
+ /* We always abort if we get here; there is no point in going on as
+ the next iteration in the fast enumeration would probably go
+ deeply wrong. */
+ _objc_abort ("Collection %p mutated during fast enumeration", collection);
+}
diff --git a/libobjc/objc/runtime.h b/libobjc/objc/runtime.h
new file mode 100644
index 0000000..7b16f1b
--- /dev/null
+++ b/libobjc/objc/runtime.h
@@ -0,0 +1,88 @@
+/* GNU Objective-C Runtime API.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+ Contributed by Nicola Pero <nicola.pero@meta-innovation.com>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3, or (at your option) any
+later version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+#ifndef __objc_runtime_INCLUDE_GNU
+#define __objc_runtime_INCLUDE_GNU
+
+#include "objc.h"
+
+/* The following is temporary, until all code from objc-api.h has been
+ moved into this file and objc-api.h will include runtime.h. */
+#include "objc-api.h"
+
+/* 'objc_enumerationMutation()' is called when a collection is
+ mutated while being "fast enumerated". That is a hard error, and
+ objc_enumerationMutation is called to deal with it. 'collection'
+ is the collection object that was mutated during an enumeration.
+
+ objc_enumerationMutation() will invoke the mutation handler if any
+ is set. Then, it will abort the program.
+
+ Compatibility note: the Apple runtime will not abort the program
+ after calling the mutation handler.
+ */
+objc_EXPORT void objc_enumerationMutation (id collection);
+
+/* 'objc_set_enumeration_mutation_handler' can be used to set a
+ function that will be called (instead of aborting) when a fast
+ enumeration is mutated during enumeration. The handler will be
+ called with the 'collection' being mutated as the only argument and
+ it should not return; it should either exit the program, or could
+ throw an exception. The recommended implementation is to throw an
+ exception - the user can then use exception handlers to deal with
+ it.
+
+ This function is not thread safe (other threads may be trying to
+ invoke the enumeration mutation handler while you are changing it!)
+ and should be called during during the program initialization
+ before threads are started. It is mostly reserved for "Foundation"
+ libraries; in the case of GNUstep, GNUstep Base may be using this
+ function to improve the standard enumeration mutation handling.
+ You probably shouldn't use this function unless you are writing
+ your own Foundation library.
+*/
+objc_EXPORT void objc_set_enumeration_mutation_handler (void (*handler)(id));
+
+/* This structure (used during fast enumeration) is automatically
+ defined by the compiler (it is as if this definition was always
+ included in all Objective-C files). Note that it is usually
+ defined again with the name of NSFastEnumeration by "Foundation"
+ libraries such as GNUstep Base. And if NSFastEnumeration is
+ defined, the compiler will use it instead of
+ __objcFastEnumerationState when doing fast enumeration.
+*/
+/*
+struct __objcFastEnumerationState
+{
+ unsigned long state;
+ id *itemsPtr;
+ unsigned long *mutationsPtr;
+ unsigned long extra[5];
+};
+*/
+/* For compatibility with the Apple/NeXT runtime. */
+#define objc_setEnumerationMutationHandler objc_set_enumeration_mutation_handler
+
+#endif