From 46a88c12210a5677435efa706e424a4e37ab4646 Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Sat, 30 Oct 2010 11:22:46 +0000 Subject: In gcc/: 2010-10-30 Nicola Pero In gcc/: 2010-10-30 Nicola Pero Implemented Objective-C 2.0 @property, @synthesize and @dynamic. * c-parser.c (c_parser_objc_at_property_declaration): Removed parsing of RID_COPIES and RID_IVAR. Updated call to objc_add_property_declaration. * c-typecheck.c (build_component_ref): Call objc_maybe_build_component_ref instead of objc_build_setter_call. Use objc_is_property_ref to improve Objective-C checks. (cp_build_modify_expr): Call objc_maybe_build_modify_expr instead of objc_build_getter_call. In gcc/c-family/: 2010-10-30 Nicola Pero Implemented Objective-C 2.0 @property, @synthesize and @dynamic. * c-common.h (enum rid): Removed RID_COPIES and RID_IVAR. (objc_add_property_declaration): Removed arguments for copies and ivar. (objc_build_getter_call): Renamed to objc_maybe_build_component_ref. (objc_build_setter_call): Renamed to objc_maybe_build_modify_expr. (objc_is_property_ref): New. * c-common.c (c_common_reswords): Removed copies and ivar. * stub-objc.c (objc_add_property_declaration): Removed arguments for copies and ivar. (objc_build_getter_call): Renamed to objc_maybe_build_component_ref. (objc_build_setter_call): Renamed to objc_maybe_build_modify_expr. (objc_is_property_ref): New. In gcc/cp/: 2010-10-30 Nicola Pero Implemented Objective-C 2.0 @property, @synthesize and @dynamic. * parser.c (cp_parser_objc_at_property_declaration): Removed parsing of RID_COPIES and RID_IVAR. Updated call to objc_add_property_declaration. * typecheck.c (finish_class_member_access_expr): Call objc_maybe_build_component_ref instead of objc_build_setter_call. (cp_build_modify_expr): Call objc_maybe_build_modify_expr instead of objc_build_getter_call. In gcc/objc/: 2010-10-30 Nicola Pero Implemented Objective-C 2.0 @property, @synthesize and @dynamic. * objc-tree.def (PROPERTY_REF): New. * objc-act.h: Added comments for all the PROPERTY_ macros. (PROPERTY_NAME): Use DECL_NAME. (PROPERTY_COPIES): Removed. (PROPERTY_READONLY): Use DECL_LANG_FLAG_0 for it. (PROPERTY_NONATOMIC): New. (objc_property_assign_semantics): Make it a typedef. (PROPERTY_ASSIGN_SEMANTICS): New. (PROPERTY_DYNAMIC): New. (PROPERTY_REF_OBJECT): New. (PROPERTY_REF_PROPERTY_DECL): New. * objc-act.c (CALL_EXPR_OBJC_PROPERTY_GETTER): Removed. (in_objc_property_setter_name_context): Removed. (objc_add_property_declaration): Removed copies and ivar arguments and code supporting them. Fixed recovering when readonly and setter attributes are specified. Removed support for @property in @implementation context. Updated error message. Double-check that a property does not have a DECL_INITIAL. Validate the property assign semantics and emit appropriate errors and warnings. Check for duplicate property declarations. Set DECL_SOURCE_LOCATION, TREE_DEPRECATED, PROPERTY_NONATOMIC, PROPERTY_ASSIGN_SEMANTICS and PROPERTY_DYNAMIC of the new PROPERTY_DECL. Do not set PROPERTY_COPIES. Set PROPERTY_IVAR_NAME to NULL_TREE. (objc_build_getter_call): Renamed to objc_maybe_build_component_ref. If the property is not found in the interface, search in the protocol list. Do not generate the getter call; instead, build and return a PROPERTY_REF. (objc_is_property_ref): New. (objc_setter_func_call): Removed. (get_selector_from_reference): Removed. (is_property): Removed. (objc_build_setter_call): Renamed to objc_maybe_build_modify_expr. Updated to work on a PROPERTY_REF and use the PROPERTY_DECL from the PROPERTY_REF. Generate an error if the property is read-only. (build_property_reference): Removed. (objc_finish_message_expr): Removed check to produce "readonly property can not be set" error when in_objc_property_setter_name_context. We now generate the error earlier, in objc_maybe_build_modify_expr, which will only generate the setter call if the property is readwrite. (check_methods): Recognize dynamic properties. (check_methods_accessible): Same change. (objc_build_property_ivar_name): Removed. (objc_build_property_setter_name): Dropped bool argument. Always add the ':' at the end. (objc_gen_one_property_datum): Removed. (objc_process_getter_setter): Removed. (objc_synthesize_getter): Mark 'klass' argument as unused. Use PROPERTY_GETTER_NAME instead of PROPERTY_NAME. Set the DECL_SOURCE_LOCATION of the new method to be the same as the one for the @synthesize. Always use PROPERTY_IVAR_NAME as it is instead of trying to guess what it should be. Removed use of CLASS_IVARS. Use the location of @synthesize for c_finish_return and c_end_compound_statement. (objc_synthesize_setter): Mark 'klass' argument as unused. Use PROPERTY_SETTER_NAME instead of trying to guess what it should be. Set the DECL_SOURCE_LOCATION of the new method to be the same as the one for the @synthesize. Always use PROPERTY_IVAR_NAME as it is instead of trying to guess what it should be. Removed use of CLASS_IVARS. Use the location of @synthesize for c_finish_return and c_end_compound_statement. Emit an error and keep going, instead of aborting, if the setter prototype does not have the expected argument. (objc_add_synthesize_declaration_for_property): New. (objc_add_synthesize_declaration): Removed ATTRIBUTE_UNUSED from all arguments. Improved error message. Filled in the rest of the function, which used to be a placeholder, with an actual implementation. (objc_add_dynamic_declaration_for_property): New. (objc_add_dynamic_declaration): Removed ATTRIBUTE_UNUSED from all arguments. Improved error message. Filled in the rest of the function, which used to be a placeholder, with an actual implementation. (objc_gen_property_data): Rewritten. (finish_class): Added explicit switch cases for CLASS_INTERFACE_TYPE, CATEGORY_INTERFACE_TYPE and PROTOCOL_INTERFACE_TYPE. Added a default switch case which is gcc_unreachable. Rewritten the processing of properties, in particular to not synthesize prototypes for getters and setters if they already exist and to install the getter and setter names into PROPERTY_GETTER_NAME and PROPERTY_SETTER_NAME. Do not generate warnings about setter, getter and ivar property attributes. (objc_lookup_ivar): Removed support for properties. (objc_gimplify_property_ref): New. (objc_gimplify_expr): Use a switch. In case of a PROPERTY_REF, call objc_gimplify_property_ref. In gcc/testsuite/: 2010-10-30 Nicola Pero Implemented Objective-C 2.0 @property, @synthesize and @dynamic. * objc.dg/property/property-neg-1.m: Updated for changes in the syntax of @property and the implementation of @synthesize/@dynamic. * objc.dg/property/property-neg-2.m: Same change. * objc.dg/property/property-neg-3.m: Same change. * objc.dg/property/property-neg-4.m: Same change. * objc.dg/property/property-neg-5.m: Same change. * objc.dg/property/property-neg-7.m: Same change. * objc.dg/property/property-1.m: Same change. * objc.dg/property/synthesize-1.m: Same change. * objc.dg/property/at-property-2.m: Same change. * objc.dg/property/at-property-4.m: Same change. * objc.dg/property/fsf-property-method-acces.m: Updated for changes in the syntax of @property and the implementation of @synthesize/@dynamic. Use the same code for GNU and NeXT runtime. * objc.dg/property/fsf-property-basic.m: Same change. * objc.dg/property/fsf-property-named-ivar.m: Same change. * objc.dg/property/at-property-5.m: New. * objc.dg/property/at-property-6.m: New. * objc.dg/property/at-property-7.m: New. * objc.dg/property/at-property-8.m: New. * objc.dg/property/at-property-9.m: New. * objc.dg/property/at-property-10.m: New. * objc.dg/property/at-property-11.m: New. * objc.dg/property/synthesize-2.m: New. * objc.dg/property/dynamic-2.m: New. * obj-c++.dg/property/property-neg-1.mm: Updated for changes in the syntax of @property and the implementation of @synthesize/@dynamic. * obj-c++.dg/property/property-neg-2.mm: Same change. * obj-c++.dg/property/property-neg-3.mm: Same change. * obj-c++.dg/property/property-neg-4.mm: Same change. * obj-c++.dg/property/property-neg-5.mm: Same change. * obj-c++.dg/property/property-neg-7.mm: Same change. * obj-c++.dg/property/property-1.mm: Same change. * obj-c++.dg/property/synthesize-1.mm: Same change. * obj-c++.dg/property/at-property-2.mm: Same change. * obj-c++.dg/property/at-property-4.mm: Same change. * obj-c++.dg/property/fsf-property-method-acces.mm: Updated for changes in the syntax of @property and the implementation of @synthesize/@dynamic. Use the same code for GNU and NeXT runtime. * obj-c++.dg/property/fsf-property-basic.mm: Same change. * obj-c++.dg/property/fsf-property-named-ivar.mm: Same change. * obj-c++.dg/property/at-property-5.mm: New. * obj-c++.dg/property/at-property-6.mm: New. * obj-c++.dg/property/at-property-7.mm: New. * obj-c++.dg/property/at-property-8.mm: New. * obj-c++.dg/property/at-property-9.mm: New. * obj-c++.dg/property/at-property-10.mm: New. * obj-c++.dg/property/at-property-11.mm: New. * obj-c++.dg/property/synthesize-2.mm: New. * obj-c++.dg/property/dynamic-2.mm: New. From-SVN: r166087 --- gcc/objc/objc-act.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 6 deletions(-) (limited to 'gcc/objc/objc-act.h') diff --git a/gcc/objc/objc-act.h b/gcc/objc/objc-act.h index 2456c10..95e9070 100644 --- a/gcc/objc/objc-act.h +++ b/gcc/objc/objc-act.h @@ -54,18 +54,64 @@ tree objc_eh_personality (void); #define METHOD_TYPE_ATTRIBUTES(DECL) ((DECL)->decl_common.abstract_origin) #define METHOD_PROPERTY_CONTEXT(DECL) ((DECL)->decl_common.size_unit) -#define PROPERTY_NAME(DECL) ((DECL)->decl_minimal.name) + +/* PROPERTY_DECL. A PROPERTY_DECL repesents a @property declaration + (when attached to the list of properties of an interface) or a + @synthesize or @dynamic declaration (when attached to the list of + properties of an implementation). */ + +/* TREE_TYPE is the type (int, float, etc) of the property. */ + +/* PROPERTY_NAME is the name of the property. */ +#define PROPERTY_NAME(DECL) DECL_NAME(DECL) + +/* PROPERTY_GETTER_NAME is the identifier of the getter method. */ #define PROPERTY_GETTER_NAME(DECL) ((DECL)->decl_non_common.arguments) + +/* PROPERTY_SETTER_NAME is the identifier of the setter method. */ #define PROPERTY_SETTER_NAME(DECL) ((DECL)->decl_non_common.result) -#define PROPERTY_IVAR_NAME(DECL) ((DECL)->decl_common.initial) -#define PROPERTY_READONLY(DECL) ((DECL)->decl_minimal.context) -#define PROPERTY_COPIES(DECL) ((DECL)->decl_common.size_unit) -enum objc_property_assign_semantics { +/* PROPERTY_READONLY can be 0 or 1. */ +#define PROPERTY_READONLY(DECL) DECL_LANG_FLAG_0 (DECL) + +/* PROPERTY_NONATOMIC can be 0 or 1. */ +#define PROPERTY_NONATOMIC(DECL) DECL_LANG_FLAG_1 (DECL) + +typedef enum objc_property_assign_semantics { OBJC_PROPERTY_ASSIGN = 1, OBJC_PROPERTY_RETAIN = 2, OBJC_PROPERTY_COPY = 3 -}; +} objc_property_assign_semantics; + +/* PROPERTY_ASSIGN_SEMANTICS can be OBJC_PROPERTY_ASSIGN, + OBJC_PROPERTY_RETAIN or OBJC_PROPERTY_COPY. We need an integer to + store it, so we hijack the alignment, that properties don't + have. */ +#define PROPERTY_ASSIGN_SEMANTICS(DECL) ((DECL)->decl_common.align) + +/* PROPERTY_IVAR_NAME is the identifier of the instance variable. + This is set only if the PROPERTY_DECL represents a @synthesize; + otherwise, it is set to TREE_NULL. */ +#define PROPERTY_IVAR_NAME(DECL) ((DECL)->decl_common.initial) + +/* PROPERTY_DYNAMIC can be 0 or 1. This is 1 if the PROPERTY_DECL + represents a @dynamic (or if it is a @property for which a @dynamic + declaration has been parsed); otherwise, it is set to 0. */ +#define PROPERTY_DYNAMIC(DECL) DECL_LANG_FLAG_2 (DECL) + + +/* PROPERTY_REF. A PROPERTY_REF represents an 'object.property' + expression. */ + +/* PROPERTY_REF_OBJECT is the object whose property we are + accessing. */ +#define PROPERTY_REF_OBJECT(NODE) TREE_OPERAND (PROPERTY_REF_CHECK (NODE), 0) + +/* PROPERTY_REF_PROPERTY_DECL is the PROPERTY_DECL for the property + used in the expression. From it, you can get the property type, + and the getter/setter names. */ +#define PROPERTY_REF_PROPERTY_DECL(NODE) TREE_OPERAND (PROPERTY_REF_CHECK (NODE), 1) + /* CLASS_INTERFACE_TYPE, CLASS_IMPLEMENTATION_TYPE, CATEGORY_INTERFACE_TYPE, CATEGORY_IMPLEMENTATION_TYPE, -- cgit v1.1