[cfe-dev] override support for Objective-C

Stuart Carnie stuart.carnie at gmail.com
Mon Nov 29 18:55:56 PST 2010


Not at all, I am only looking to add compile-time verification of the
developer's intent that they wish to override a particular method.

In the example below, the fictitious developer has derived from
UIViewController<UITableViewDataSource>, and intended to override /
implement the numberOfSectionsInTableView method from the
UITableViewDataSource protocol.  The subtle issue is they have misspelled
the method as numberOfSectionsInTable*v*iew, however as the method is marked
@optional, the compiler issues no warning.  By adding support for
"override", we would force the compiler to walk the inheritance and protocol
hierarchy and issue a warning if the method marked as override was not
found.  It is not changing the behavior of Obj-C or the runtime in anyway.

Cheers,

Stu

*Stuart Carnie, CTO*
*manomio <http://manomio.com/> | in retro we trust!*


On Mon, Nov 29, 2010 at 6:13 PM, Chris Lattner <clattner at apple.com> wrote:

>
> On Nov 29, 2010, at 4:09 PM, Stuart Carnie wrote:
>
> Hi all,
>
> I would like to have a go at hacking a little on Clang when a get a bit of
> spare time, and have found that adding support for override would be useful
> little exercise.  I've seen another post referring to Clang's support for
> __attribute__((override)), and seems like I could use this as a starting
> point.
>
> Big Nerd Ranch <http://weblog.bignerdranch.com/?p=171> would like to see
> an @override keyword, as follows:
>
> @override
> - (NSInteger)numberOfSectionsInTableview:(UITableView *)tv
> { ... }
>
>
> Hi Stuart,
>
> Is your  goal here to allow overloading of ObjC methods?  If so, the
> parsing isn't the hard part, you'd need to mangle selectors somehow, and
> enhance the runtime to support this.  This isn't something we want in ObjC,
> because want to keep it simple.
>
> -Chris
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101129/92b3f2b0/attachment.html>


More information about the cfe-dev mailing list