[cfe-dev] override support for Objective-C

Blaine Garst blaine at apple.com
Mon Nov 29 18:09:09 PST 2010


This falls into the "namespace for selectors" discussion on a previous thread about a month ago.

One needs either @override(s) and @implements (or just an overrides attribute annotation) to signal that the intention is to redeclare a method that one intends to redefine.

I have a big issue if the runtime can't enforce distinct selectors for the same name when a superclass introduces a method already introduced and used in a subclass.  Clearly this is part of the API contract.  Just adding the annotation would allow the compiler to say, hey, you *thought* you were introducing a new method, but you weren't, and that would be good, but the principle advantage is to give runtime protection for those binaries that get hosed when in fact a superclass does introduce a method already in use in a later rev.

Adding partial support in the compiler and not the runtime would create source compatibility issues if/when the runtime ever did implement this feature, and might in fact indefinitely delay such an implementation.  I think this requires a combined runtime/compiler approach.

Blaine


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 would like to see an @override keyword, as follows:
> 
> @override
> - (NSInteger)numberOfSectionsInTableview:(UITableView *)tv
> { ... }
> 
> This would seem the most natural, but I feel it would involve mucking with the parser, the AST and therefore fairly complicated.  Given Clang already parses __attribute__, I could take the following approach instead:
> 
> - (NSInteger)numberOfSectionsInTableview:(UITableView *)tv __attribute__((override))
> { ... }
> 
> Can I implement this as a Clang plugin or must I modify Clang source?
> 
> One other question is I couldn't get Clang 2.8 to recognize __has_attribute(override) for a .cpp file:
> 
> #ifndef __has_attribute         
>   #define __has_attribute(x) 0
>   #warning no __has_attribute support
> #endif
> 
> #if __has_attribute(override)
> 	#define OVERRIDE __attribute__((override))
> #else
> 	#warning No override attribute
> #endif
> 
> Would always output the two warnings.
> 
> Cheers,
> 
> Stu
> 
> Stuart Carnie, CTO
> manomio | in retro we trust!
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101129/63aa0464/attachment.html>


More information about the cfe-dev mailing list