<div dir="ltr">Hi, all.<br><br>I'm trying to index C++ source code into DB using libclang's cursor facility.<br>One of the key things is that I can use USR to get the indexed cursor from DB.<br>But when I tried to index a source file with template class definition with macro, the USR for all template type parameter are the same:<br>
<br>// test_template.cpp<br>#define TEMP_CLASS(name) \<br> template<typename T1, typename T2> \<br> class name { };<br><br>#define TWO_TEMP_CLASS(name) \<br> TEMP_CLASS(name##1) \<br> TEMP_CLASS(name##2)<br>
<br>TWO_TEMP_CLASS(Test)<br><br>void foo() {}<br><br><br>Note that for T1, T2 of class Test1 and Test2, the USR are "test_template.cpp@172". So with this USR, I cannot distinguish between Test1::T1 and Test2::T2. The locations, extents, spelling and USR of Test1::T1 and Test2::T2.<br>
<br>Is this a bug?<br><br>I check the source code of "clang/lib/Index/USRGeneration.cpp", it just use GenLoc function to generate the USR of template type parameter:<br><br>void USRGenerator::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {<br>
GenLoc(D);<br> return;<br>}<br><br>And non type template parameter also have this problem.<br>I've fixed this with a custom patch:<br><br>void USRGenerator::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {<br>
VisitDeclContext(D->getDeclContext());<br> Out << "@";<br> if (!EmitDeclName(D)) {<br> Out << "@";<br> }<br> GenLoc(D);<br> return;<br>}<br><br>With the class USR and the spelling before the GenLoc, the USR is guaranteed to be unique.<br>
Am I missing anything?<br>And the USR generation rule is not so clear to me. Is there any guildline about how to generate it?<br><br>----<br clear="all"><div><div dir="ltr">Best regards,<br>Yaolong Huang(Curtis)<br><br>Briontech China<br>
<br>Blog: <a href="http://airekans.github.com" target="_blank">http://airekans.github.com</a></div></div>
</div>