<div dir="ltr">Hi Michael,<div><br></div><div>Thanks for the detailed report! I believe you're correct, <span style="font-size:12.800000190734863px">clang_getTypeSpelling should return the fully qualified name for the typedefs since it does so for the other types. </span></div><div><br></div><div><span style="font-size:12.800000190734863px">It looks like you're on the right track with the diff that you've shown. I would encourage you to submit it as a patch (with tests) to cfe-commits, either by using Phabricator (</span><a href="http://llvm.org/docs/Phabricator.html">http://llvm.org/docs/Phabricator.html</a><span style="font-size:12.800000190734863px">) or by emailing the patch directly to the list.</span></div><div><span style="font-size:12.800000190734863px"><br></span></div><div><span style="font-size:12.800000190734863px">Cheers,</span></div><div><span style="font-size:12.800000190734863px">Alex</span></div><div><span style="font-size:12.800000190734863px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 10 February 2017 at 12:39, Michael via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi<br>
<br>
I'm using libclang to parse header files and generate code from them. I found that clang_getTypeSpelling() usually includes the namespace(s) a type was declared in. However with the exception being typedefs (and same for "using A = B"). Not sure if this is a bug or intended behavior, but it seems at least inconsistent. I also couldn't really find a good workaround for this. I'd have to manually figure out all typedefs (not just pure typedefs, they could also be nested template arguments or whatever) and then their originating namespaces. This is a bit cumbersome and not really straight forward. Getting the canonical type is also not really a solution as I would like to keep the typedefs.<br>
<br>
Minimal example:<br>
<br>
namespace foo {<br>
class Bar {<br>
};<br>
typedef Bar BarDef;<br>
}<br>
<br>
clang_getTypeSpelling on "Bar" (kind "Record") gives: "foo::Bar"<br>
clang_getTypeSpelling on "BarDef" (kind "Typedef") gives: "BarDef" (<== missing "foo::")<br>
<br>
<br>
I had a look into the clang sources. It seems this little patch would fix the problem. This was pure guess work, I don't know what deeper consequences this might have.<br>
<br>
Index: lib/AST/TypePrinter.cpp<br>
==============================<wbr>==============================<wbr>=======<br>
--- lib/AST/TypePrinter.cpp     (revision 294732)<br>
+++ lib/AST/TypePrinter.cpp     (working copy)<br>
@@ -96,7 +96,7 @@<br>
<br>
     static bool canPrefixQualifiers(const Type *T, bool &NeedARCStrongQualifier);<br>
     void spaceBeforePlaceHolder(raw_ost<wbr>ream &OS);<br>
-    void printTypeSpec(const NamedDecl *D, raw_ostream &OS);<br>
+    void printTypeSpec(NamedDecl *D, raw_ostream &OS);<br>
<br>
     void printBefore(const Type *ty, Qualifiers qs, raw_ostream &OS);<br>
     void printBefore(QualType T, raw_ostream &OS);<br>
@@ -798,7 +798,14 @@<br>
   printAfter(T->getReturnType()<wbr>, OS);<br>
 }<br>
<br>
-void TypePrinter::printTypeSpec(con<wbr>st NamedDecl *D, raw_ostream &OS) {<br>
+void TypePrinter::printTypeSpec(Nam<wbr>edDecl *D, raw_ostream &OS) {<br>
+<br>
+  // Compute the full nested-name-specifier for this type.<br>
+  // In C, this will always be empty except when the type<br>
+  // being printed is anonymous within other Record.<br>
+  if (!Policy.SuppressScope)<br>
+    AppendScope(D->getDeclContext(<wbr>), OS);<br>
+<br>
   IdentifierInfo *II = D->getIdentifier();<br>
   OS << II->getName();<br>
   spaceBeforePlaceHolder(OS);<br>
<br>
(I would of course also fix the unit tests if needed)<br>
<br>
Please let me know what you think.<br>
<br>
Thanks<br>
<br>
Michael<br>
<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>