<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">This falls into the "namespace for selectors" discussion on a previous thread about a month ago.<div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Blaine</div><div><br></div><div><br></div><div><div><div>On Nov 29, 2010, at 4:09 PM, Stuart Carnie wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><font face="tahoma,sans-serif">Hi all,</font><div><font face="tahoma,sans-serif"><br></font></div><div><font face="tahoma,sans-serif">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.</font></div>
<div><font face="tahoma,sans-serif"><br></font></div><div><font face="tahoma,sans-serif"><a href="http://weblog.bignerdranch.com/?p=171">Big Nerd Ranch</a> would like to see an @override keyword, as follows:</font></div><div>
<font face="tahoma,sans-serif"><br></font></div><div><font face="tahoma,sans-serif"><span class="Apple-style-span" style="font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 12px; color: rgb(48, 48, 48); line-height: 19px; "><pre class="code" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; font-family: Courier; font-size: 1.2em; width: 672px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-width: initial; border-color: initial; border-top-width: thin; border-right-width: thin; border-bottom-width: thin; border-left-width: thin; ">@override
- (NSInteger)numberOfSectionsInTableview:(UITableView *)tv
{ ... }</pre></span></font></div><div><font face="tahoma,sans-serif"><br></font></div><div><font face="tahoma,sans-serif">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:</font></div>
<div><font face="tahoma,sans-serif"><br></font></div><div><font class="Apple-style-span" face="tahoma, sans-serif"><span class="Apple-style-span" style="font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 12px; color: rgb(48, 48, 48); line-height: 19px; "><pre class="code" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; font-family: Courier; font-size: 1.2em; width: 672px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-width: initial; border-color: initial; border-top-width: thin; border-right-width: thin; border-bottom-width: thin; border-left-width: thin; ">- (NSInteger)numberOfSectionsInTableview:(UITableView *)tv __attribute__((override))
{ ... }</pre></span></font></div><div><font class="Apple-style-span" face="tahoma, sans-serif"><br></font></div><div><font class="Apple-style-span" face="tahoma, sans-serif">Can I implement this as a Clang plugin or must I modify Clang source?</font></div>
<div><font class="Apple-style-span" face="tahoma, sans-serif"><br></font></div><div><font class="Apple-style-span" face="tahoma, sans-serif">One other question is I couldn't get Clang 2.8 to recognize __has_attribute(override) for a .cpp file:</font></div>
<div><font class="Apple-style-span" face="tahoma, sans-serif"><br></font></div><div><div><font class="Apple-style-span" face="'courier new', monospace">#ifndef __has_attribute         </font></div><div><font class="Apple-style-span" face="'courier new', monospace">  #define __has_attribute(x) 0</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">  #warning no __has_attribute support</font></div><div><font class="Apple-style-span" face="'courier new', monospace">#endif</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">#if __has_attribute(override)</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre">    </span>#define OVERRIDE __attribute__((override))</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">#else</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre">   </span>#warning No override attribute</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">#endif</font></div></div><div><font class="Apple-style-span" face="tahoma, sans-serif"><br></font></div><div><font class="Apple-style-span" face="tahoma, sans-serif">Would always output the two warnings.</font></div>
<div><font class="Apple-style-span" face="tahoma, sans-serif"><br></font></div><div><font class="Apple-style-span" face="tahoma, sans-serif">Cheers,</font></div><div><font class="Apple-style-span" face="tahoma, sans-serif"><br>
Stu</font></div><div><font face="tahoma,sans-serif"><br clear="all"></font><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse;color:rgb(80, 0, 80)"><strong><span style="color:rgb(153, 204, 255)">Stuart Carnie, CTO</span></strong><br>
<span style="color:rgb(255, 102, 0)"><strong><a href="http://manomio.com/" style="color:rgb(255, 102, 0)" target="_blank">manomio</a> | in retro we trust!</strong></span></span><br>
</div>
_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev<br></blockquote></div><br></div></body></html>