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]

ObjC/ObjC++: Objective-C 2.0 class extensions


This patch implements class extensions for Objective-C and Objective-C++.

I know it's phase 3, but it's such a simple change and it's low risk.
I keep hitting testcases in other ObjC compilers that use class extensions and
started to wonder why can't we just implement them and get rid of the problem
(considering how easy it is to implement), so I just did it.  Anyway, I won't
get offended if it's not deemed appropriate for this phase. ;-)

This patch:

 * does the small changes to the parsers to recognize a class extension (a category
with an empty category name);

 * produces an error if a class extension is used with -fobjc-std=objc1;

 * when a class extension is found, simply "reopens" that main @interface and adds any
protocols found in the class extension to it (since we "reopen" that main @interface,
all properties and methods found in the class extension will automatically be added
to the @interface as if they were actually found in the main @interface, which is
what we want);

 * it also sets an objc_in_class_extension flag to 'true' in that case (for a couple
of special differences with the main @interface that I'll detail);

 * when an @interface is closed, if objc_in_class_extension, then it skips creating the instance
variable templates as it's already been done when the original, main @interface was closed;

 * when a readwrite @property is found, if we are in a class extension, then it allows it
to override an existing readonly (but identical) @property already existing in the interface;

 * it includes 12 new testcases.

that's it. :-)

Ok to commit ?

Thanks

In gcc/:
2010-12-10  Nicola Pero  <nicola.pero@meta-innovation.com>

        * c-parser.c (c_parser_objc_class_definition): Recognize
        Objective-C 2.0 class extensions.

In gcc/cp/:
2010-12-10  Nicola Pero  <nicola.pero@meta-innovation.com>

        * parser.c (cp_parser_objc_superclass_or_category): Recognize
        Objective-C 2.0 class extensions.  Added iface_p and
        is_class_extension arguments.
        (cp_parser_objc_class_interface): Updated call to
        cp_parser_objc_superclass_or_category.
        (cp_parser_objc_class_implementation): Same change.

In gcc/objc/:
2010-12-10  Nicola Pero  <nicola.pero@meta-innovation.com>

        * objc-act.c (objc_in_class_extension): New.
        (objc_start_category_interface): If -fobjc-std=objc1
        was specified, produce an error if a class extension is used.
        (objc_finish_interface): Reset objc_in_class_extension to false.
        (objc_add_property_declaration): Allow a class extension to extend
        readonly properties in the main @interface to be readwrite.
        (start_class): Added code to deal with class extensions.  In that
        case, return the existing interface after adding any additional
        protocols to it and setting objc_in_class_extension to true.
        (continue_class): If in a class extension, do not generate the
        instance variable template.

In gcc/testsuite/:
2010-12-10  Nicola Pero  <nicola.pero@meta-innovation.com>

        * objc.dg/class-extension-1.m: New.
        * objc.dg/class-extension-2.m: New.
        * objc.dg/class-extension-3.m: New.
        * objc.dg/property/at-property-26.m: New.
        * objc.dg/property/at-property-27.m: New.
        * objc.dg/property/at-property-28.m: New.
        * obj-c++.dg/class-extension-1.mm: New.
        * obj-c++.dg/class-extension-2.mm: New.
        * obj-c++.dg/class-extension-3.mm: New.
        * obj-c++.dg/property/at-property-26.mm: New.
        * obj-c++.dg/property/at-property-27.mm: New.
        * obj-c++.dg/property/at-property-28.mm: New.

Attachment: patch.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]