diff options
author | Nicola Pero <nicola.pero@meta-innovation.com> | 2010-11-08 22:04:03 +0000 |
---|---|---|
committer | Nicola Pero <nicola@gcc.gnu.org> | 2010-11-08 22:04:03 +0000 |
commit | 4741888d0321172ac91ee71c6a035d1048b49f39 (patch) | |
tree | e521b56c661feaac63138566fed5a623b044b767 /gcc/objc | |
parent | 4ca5d2a7bdc3cd7182cbf0e1261a6df44d362d87 (diff) | |
download | gcc-4741888d0321172ac91ee71c6a035d1048b49f39.tar.gz |
In gcc/objc/: 2010-11-08 Nicola Pero <nicola.pero@meta-innovation.com>
In gcc/objc/:
2010-11-08 Nicola Pero <nicola.pero@meta-innovation.com>
* objc-act.c (objc_add_synthesize_declaration_for_property):
Iterate over IMPL_PROPERTY_DECL, not CLASS_PROPERTY_DECL, when
checking for an existing @synthesize or @dynamic declaration.
Search for an inherited @property declaration if none is found in
the local interface. If the required instance variable does not
exist, return instead of trying to continue to prevent a compiler
crash later. Check that the instance variable is not already
being used by another @synthesize.
(objc_add_dynamic_declaration_for_property): Iterate over
IMPL_PROPERTY_DECL, not CLASS_PROPERTY_DECL, when checking for an
existing @synthesize or @dynamic declaration.
(objc_synthesize_getter): Search for the getter declaration in
protocols and superclasses as well.
(objc_synthesize_setter): Search for the setter declaration in
protocols and superclasses as well.
In gcc/testsuite/:
2010-11-08 Nicola Pero <nicola.pero@meta-innovation.com>
* objc.dg/property/synthesize-3.m: New.
* objc.dg/property/synthesize-4.m: New.
* objc.dg/property/synthesize-5.m: New.
* objc.dg/property/synthesize-6.m: New.
* obj-c++.dg/property/synthesize-3.mm: New.
* obj-c++.dg/property/synthesize-4.mm: New.
* obj-c++.dg/property/synthesize-5.mm: New.
* obj-c++.dg/property/synthesize-6.mm: New.
From-SVN: r166456
Diffstat (limited to 'gcc/objc')
-rw-r--r-- | gcc/objc/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/objc/objc-act.c | 68 |
2 files changed, 61 insertions, 25 deletions
diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 93c9f3e544a..6ba9514af10 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,5 +1,23 @@ 2010-11-08 Nicola Pero <nicola.pero@meta-innovation.com> + * objc-act.c (objc_add_synthesize_declaration_for_property): + Iterate over IMPL_PROPERTY_DECL, not CLASS_PROPERTY_DECL, when + checking for an existing @synthesize or @dynamic declaration. + Search for an inherited @property declaration if none is found in + the local interface. If the required instance variable does not + exist, return instead of trying to continue to prevent a compiler + crash later. Check that the instance variable is not already + being used by another @synthesize. + (objc_add_dynamic_declaration_for_property): Iterate over + IMPL_PROPERTY_DECL, not CLASS_PROPERTY_DECL, when checking for an + existing @synthesize or @dynamic declaration. + (objc_synthesize_getter): Search for the getter declaration in + protocols and superclasses as well. + (objc_synthesize_setter): Search for the setter declaration in + protocols and superclasses as well. + +2010-11-08 Nicola Pero <nicola.pero@meta-innovation.com> + * objc-act.c (lookup_property): When checking categories, also check the protocols attached to each. (objc_add_property_declaration): Determine the diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index db41dcab0ac..ff694147ce2 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -9363,7 +9363,7 @@ lookup_ivar (tree interface, tree instance_variable_name) /* This routine synthesizes a 'getter' method. This is only called for @synthesize properties. */ static void -objc_synthesize_getter (tree klass, tree class_method, tree property) +objc_synthesize_getter (tree klass, tree class_methods ATTRIBUTE_UNUSED, tree property) { location_t location = DECL_SOURCE_LOCATION (property); tree fn, decl; @@ -9375,9 +9375,9 @@ objc_synthesize_getter (tree klass, tree class_method, tree property) PROPERTY_GETTER_NAME (property))) return; - /* Find declaration of the property getter in the interface. There - must be one. TODO: Search superclasses as well. */ - decl = lookup_method (CLASS_NST_METHODS (class_method), PROPERTY_GETTER_NAME (property)); + /* Find declaration of the property getter in the interface (or + superclass, or protocol). There must be one. */ + decl = lookup_method_static (klass, PROPERTY_GETTER_NAME (property), 0); /* If one not declared in the interface, this condition has already been reported as user error (because property was not declared in @@ -9542,7 +9542,7 @@ objc_synthesize_getter (tree klass, tree class_method, tree property) /* This routine synthesizes a 'setter' method. */ static void -objc_synthesize_setter (tree klass ATTRIBUTE_UNUSED, tree class_method, tree property) +objc_synthesize_setter (tree klass, tree class_methods ATTRIBUTE_UNUSED, tree property) { location_t location = DECL_SOURCE_LOCATION (property); tree fn, decl; @@ -9554,9 +9554,9 @@ objc_synthesize_setter (tree klass ATTRIBUTE_UNUSED, tree class_method, tree pro PROPERTY_SETTER_NAME (property))) return; - /* Find declaration of the property setter in the interface. There - must be one. TODO: Search superclasses as well. */ - decl = lookup_method (CLASS_NST_METHODS (class_method), PROPERTY_SETTER_NAME (property)); + /* Find declaration of the property setter in the interface (or + superclass, or protocol). There must be one. */ + decl = lookup_method_static (klass, PROPERTY_SETTER_NAME (property), 0); /* If one not declared in the interface, this condition has already been reported as user error (because property was not declared in @@ -9736,10 +9736,11 @@ objc_add_synthesize_declaration_for_property (location_t location, tree interfac { /* Find the @property declaration. */ tree property; + tree x; /* Check that synthesize or dynamic has not already been used for the same property. */ - for (property = CLASS_PROPERTY_DECL (objc_implementation_context); property; property = TREE_CHAIN (property)) + for (property = IMPL_PROPERTY_DECL (objc_implementation_context); property; property = TREE_CHAIN (property)) if (PROPERTY_NAME (property) == property_name) { location_t original_location = DECL_SOURCE_LOCATION (property); @@ -9756,12 +9757,9 @@ objc_add_synthesize_declaration_for_property (location_t location, tree interfac return; } - /* Check that the property is declared in the interface. */ - /* TODO: This only check the immediate class; we need to check the - superclass (and categories ?) as well. */ - for (property = CLASS_PROPERTY_DECL (interface); property; property = TREE_CHAIN (property)) - if (PROPERTY_NAME (property) == property_name) - break; + /* Check that the property is declared in the interface. It could + also be declared in a superclass or protocol. */ + property = lookup_property (interface, property_name); if (!property) { @@ -9783,18 +9781,37 @@ objc_add_synthesize_declaration_for_property (location_t location, tree interfac if (ivar_name == NULL_TREE) ivar_name = property_name; - /* Check that the instance variable exists. You can only use an - instance variable from the same class, not one from the - superclass. */ + /* Check that the instance variable exists. You can only use a + non-private instance variable from the same class, not one from + the superclass (this makes sense as it allows us to check that an + instance variable is only used in one synthesized property). */ if (!is_ivar (CLASS_IVARS (interface), ivar_name)) - error_at (location, "ivar %qs used by %<@synthesize%> declaration must be an existing ivar", - IDENTIFIER_POINTER (property_name)); + { + error_at (location, "ivar %qs used by %<@synthesize%> declaration must be an existing ivar", + IDENTIFIER_POINTER (property_name)); + return; + } /* TODO: Check that the types of the instance variable and of the property match. */ - /* TODO: Check that no other property is using the same instance + /* Check that no other property is using the same instance variable. */ + for (x = IMPL_PROPERTY_DECL (objc_implementation_context); x; x = TREE_CHAIN (x)) + if (PROPERTY_IVAR_NAME (x) == ivar_name) + { + location_t original_location = DECL_SOURCE_LOCATION (x); + + error_at (location, "property %qs is using the same instance variable as property %qs", + IDENTIFIER_POINTER (property_name), + IDENTIFIER_POINTER (PROPERTY_NAME (x))); + + if (original_location != UNKNOWN_LOCATION) + inform (original_location, "originally specified here"); + + /* We keep going on. This won't cause the compiler to fail; + the failure would most likely be at runtime. */ + } /* Note that a @synthesize (and only a @synthesize) always sets PROPERTY_IVAR_NAME to a non-NULL_TREE. You can recognize a @@ -9876,7 +9893,7 @@ objc_add_dynamic_declaration_for_property (location_t location, tree interface, /* Check that synthesize or dynamic has not already been used for the same property. */ - for (property = CLASS_PROPERTY_DECL (objc_implementation_context); property; property = TREE_CHAIN (property)) + for (property = IMPL_PROPERTY_DECL (objc_implementation_context); property; property = TREE_CHAIN (property)) if (PROPERTY_NAME (property) == property_name) { location_t original_location = DECL_SOURCE_LOCATION (property); @@ -9912,9 +9929,10 @@ objc_add_dynamic_declaration_for_property (location_t location, tree interface, METHOD_PROPERTY_CONTEXT that points to the original PROPERTY_DECL; when we check that these methods have been implemented, we need to easily find that they are associated - with a dynamic property. TODO: Clean this up; maybe the - @property PROPERTY_DECL should contain a reference to the - @dynamic PROPERTY_DECL ? */ + with a dynamic property. TODO: Remove this hack; it will not + work with properties in a protocol that may be implemented by + different classes and be @dynamic in some, and non-@dynamic + in other ones. */ PROPERTY_DYNAMIC (property) = 1; /* We have to copy the property, because we want to chain it to |