<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 13 May 2011, at 17:56, Douglas Gregor wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>On May 13, 2011, at 5:13 AM, Erik Verbruggen wrote:<br><br><blockquote type="cite">On 12 May, 2011,at 05:43 PM, Douglas Gregor <<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>> wrote:<br></blockquote><blockquote type="cite"><font class="Apple-style-span" color="#540000"><font class="Apple-style-span" color="#006312"><br></font></font></blockquote><blockquote type="cite"><blockquote type="cite">However, if the name isn't a simple identifier ("x.operator[]"), then you can still get the location of the start of the member name ("operator"), but when you ask for the range, you'll only get the range of that one token.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Back when we designed libclang, Clang didn't even have the information about where the three tokens of "operator[]" were. Now, we actually have this information via DeclarationNameInfo, so it would make sense to add an API for specifically what you want. Here is a general API that (I think!) could fully solve this problem:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">CXSourceRange clang_getCursorReferenceNameRange(CXCursor C, unsigned NameFlags, unsigned PieceIndex);<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">where C is a cursor that references something else (e.g., a member reference, declaration reference, type reference, etc.), and returns the source range covering the reference itself. The two "unsigned" values would be for configurability:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">- NameFlags could be bitset with three independent flags: WantQualifier (to ask it to include the nested-name-specifier, e.g., Foo:: in x.Foo::y, in the range), WantTemplateArgs (to ask it to include the explicit template arguments, e.g., <int> in x.f<int>, in the range), and WantSinglePiece (described below).<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">- WantPiece/PieceIndex is my attempt at handling cases where the name itself isn't contiguous. For example, imagine the expression "a[y]", which ends up referring to an overloaded operator[]. The source range for the full operator name is, effectively, "[y]", since the name has been split into two parts. However, that's not necessarily useful, so WantPiece would indicate that we want a range covering only one piece of the name, where PieceIndex==0 indicates that we want the '[' and PieceIndex==1 indicates that we want the ']'.<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">So for "operator[]" you would 3 pieces? Or just 1?<br></blockquote><br>Probably just one.<br></div></blockquote></div><br><div>After a bit of thought and some explorative programming, I'm not sure if this API would be covering all cases. It would work for C/ObjC, but C++ is (as usual) a bit more tricky, especially with conversion operators. For example:</div><div><br></div><div>struct Something {</div><div>  operator const std::string &();</div><div>};</div><div><br></div><div>void foo() {</div><div>  Something s;</div><div>  s.operator const  std::string &(); // <-- this line</div><div>}</div><div><br></div><div>In the call to the conversion operator, the visitor will only give a MemberRefExpr as node, and no more detail on the right-hand side of the expression. But what is in there, is a TypeRef. Actually, it can by any id-expression, so it might even be something like "some_template<some_type, 1 + 2 + 3>". (And I do not know if c++0x is going to add some more cases...) So I am wondering if this function might be too limited to be really useful, or if it would still make sense for the other cases.</div><div><br></div><div>-- Erik.</div><div><br></div></body></html>