<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Oct 9, 2011, at 8:35 AM, Erik Verbruggen wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div>On 07 Oct, 2011,at 10:32 PM, Douglas Gregor <<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>> wrote:<br><br></div><div><blockquote type="cite"><div class="msg-quote"><div class="_stretch"><br>
On Oct 6, 2011, at 2:12 AM, Erik Verbruggen wrote:<br>
<br>
> On 30 Sep, 2011,at 07:34 AM, Douglas Gregor <<a href="mailto:dgregor@apple.com" _mce_href="mailto:dgregor@apple.com">dgregor@apple.com</a>> wrote:<br>
> <br>
>> Let's use the existing "annotate" attribute, which is a bit like the "user" attribute mentioned in (2) above, but already implemented in Clang. That way, Qt can have definitions such as:<br>
>> <br>
>> #define Q_OBJECT __attribute__((annotate("qt_object")))<br>
>> <br>
>> Then, you patch need only:<br>
>> <br>
>> (a) add support for parsing attributes on access specifiers, and<br>
>> (b) update libclang to expose the "annotate" attribute <br>
>> <br>
>> That should be sufficient, requires much less effort (and risk) than most of the other solutions, and won't require us to bring anything related to Qt into Clang itself.<br>
> <br>
> Attached is a new patch, which adds parsing of attributes after a C++ access specifier. These attributes get propagated in the same manner as the access specifier.<br>
<br>
I see that this handles, e.g.,<br>
<br>
public slots:<br>
<br>
(with the attribute definition of "slots", of course)<br>
<br>
but it doesn't seem to handle, e.g.,<br>
<br>
signals:<br>
<br>
I assume you want to address that as well?</div></div></blockquote><span> </span></div><div>qobjectdefs.h uses:</div><div><div># define slots</div><div># define signals protected</div></div><div><br></div><div>so with attributes one can use:</div><div><div># define slots __attribute__((annotate("qt_slot")))</div><div># define signals protected __attribute__((annotate("qt_signal")))</div></div></div></blockquote><div><br></div>Ah, okay. Thanks for the clarification.</div><div><br><blockquote type="cite"><div><div><blockquote type="cite"><div class="msg-quote"><div class="_stretch"><br>
> Then in c-index-test I changed the spelling of the annotate attribute to return the quoted string.<br>
<br>
That makes sense, thanks.<br>
<br>
> Question: should I add a check to disallow attributes other than the annotate attribute after an access specifier?<br>
<br>
Yes. I'd like us to enable such attributes on a case-by-case basis, rather than deal with the fallout of them all implicitly propagating.</div></div></blockquote><span> </span></div><div>Ok, added it.</div></div></blockquote><div><br></div><div>I assume that this was meant to catch it:</div><div><br></div><div><div>--- a/lib/Sema/SemaDeclAttr.cpp</div><div>+++ b/lib/Sema/SemaDeclAttr.cpp</div><div>@@ -3482,6 +3482,13 @@ static void ProcessNonInheritableDeclAttr(Sema &S, Scope *scope, Decl *D,</div><div> </div><div> static void ProcessInheritableDeclAttr(Sema &S, Scope *scope, Decl *D,</div><div> const AttributeList &Attr) {</div><div>+ if (isa<AccessSpecDecl>(D) && Attr.getKind() == AttributeList::AT_annotate) {</div><div>+ // Annotation attributes are the only attributes allowed after an access</div><div>+ // specifier.</div><div>+ S.Diag(Attr.getLoc(), diag::err_only_annotate_after_access_spec);</div><div>+ return;</div><div>+ }</div><div>+</div><div> switch (Attr.getKind()) {</div><div> case AttributeList::AT_IBAction: handleIBAction(S, D, Attr); break;</div><div> case AttributeList::AT_IBOutlet: handleIBOutlet(S, D, Attr); break;</div><div><br></div><div>but the condition is wrong (it errors when we have an access declaration with an "annotate" attribute), and it's clearly not working:</div><div><br></div><div><div>struct X {</div><div> public __attribute__((unavailable)):</div><div> void foo();</div><div>};</div><div><br></div><div>void f(X x) {</div><div> x.foo();</div><div>}</div><div><br></div><div>here, there's no diagnostic complaining about the "unavailable" attribute on the access specifier, and the "unavailable" attribute gets propagated down to "foo()". Most likely, you want to pass the access specifier attributes through the call to ActOnAccessSpecifier, here:</div><div><br></div><div><div>@@ -2139,10 +2146,19 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,</div><div> CurAS = AS;</div><div> SourceLocation ASLoc = Tok.getLocation();</div><div> ConsumeToken();</div><div>- if (<a href="http://Tok.is">Tok.is</a>(tok::colon))</div><div>- Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation());</div><div>- else</div><div>+</div><div>+ AccessAttrs.clear();</div><div>+ MaybeParseGNUAttributes(AccessAttrs);</div><div>+</div><div>+ if (<a href="http://Tok.is">Tok.is</a>(tok::colon)) {</div><div>+ Decl *AccessDecl = Actions.ActOnAccessSpecifier(AS, ASLoc,</div><div>+ Tok.getLocation());</div><div>+ if (AttributeList *Attrs = AccessAttrs.getList())</div><div>+ Actions.ProcessDeclAttributeList(Actions.CurScope, AccessDecl,</div><div>+ Attrs, false, true);</div><div>+ } else {</div><div> Diag(Tok, diag::err_expected_colon);</div><div>+ }</div><div> ConsumeToken();</div><div> continue;</div><div> }</div></div><div><br></div><div>so the attributes will get tacked on to the AccessSpecDecl (for good source fidelity) and you'll have a chance to diagnostic non-annotate attributes.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>- Doug</div></div></div></div><br></body></html>