[cfe-commits] r112720 - in /cfe/trunk: test/Index/index-templates.cpp tools/libclang/CIndex.cpp tools/libclang/CIndexUSRs.cpp
Douglas Gregor
dgregor at apple.com
Wed Sep 1 10:32:37 PDT 2010
Author: dgregor
Date: Wed Sep 1 12:32:36 2010
New Revision: 112720
URL: http://llvm.org/viewvc/llvm-project?rev=112720&view=rev
Log:
Improve libclang indexing support for class template specializations
in a few related ways:
- Don't recurse into instantiations of templates.
- Recurse into explicit specializations.
- Visit the template arguments of an explicit specialization or
explicit instantiation.
- Include template specialization arguments in the USRs for class
template specializations.
Modified:
cfe/trunk/test/Index/index-templates.cpp
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CIndexUSRs.cpp
Modified: cfe/trunk/test/Index/index-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-templates.cpp?rev=112720&r1=112719&r2=112720&view=diff
==============================================================================
--- cfe/trunk/test/Index/index-templates.cpp (original)
+++ cfe/trunk/test/Index/index-templates.cpp Wed Sep 1 12:32:36 2010
@@ -7,11 +7,23 @@
template<typename T, typename Alloc = allocator<T> >
class vector {
+ void clear();
};
template<typename T>
class vector<T*> { };
+struct Z1 { };
+
+template class vector<Z1>;
+
+struct Z2 { };
+
+template<>
+class vector<Z2> {
+ void clear();
+};
+
// RUN: c-index-test -test-load-source all %s | FileCheck -check-prefix=CHECK-LOAD %s
// CHECK-LOAD: index-templates.cpp:4:6: FunctionTemplate=f:4:6 Extent=[3:1 - 4:22]
// CHECK-LOAD: index-templates.cpp:3:19: TemplateTypeParameter=T:3:19 (Definition) Extent=[3:19 - 3:20]
@@ -24,12 +36,20 @@
// CHECK-LOAD: index-templates.cpp:4:13: DeclRefExpr=Value:3:24 Extent=[4:13 - 4:18]
// CHECK-LOAD: index-templates.cpp:6:28: ClassTemplate=allocator:6:28 Extent=[6:1 - 6:37]
// CHECK-LOAD: index-templates.cpp:6:19: TemplateTypeParameter=T:6:19 (Definition) Extent=[6:19 - 6:20]
-// CHECK-LOAD: index-templates.cpp:9:7: ClassTemplate=vector:9:7 (Definition) Extent=[8:1 - 10:2]
+// CHECK-LOAD: index-templates.cpp:9:7: ClassTemplate=vector:9:7 (Definition) Extent=[8:1 - 11:2]
// CHECK-LOAD: index-templates.cpp:8:19: TemplateTypeParameter=T:8:19 (Definition) Extent=[8:19 - 8:20]
// CHECK-LOAD: index-templates.cpp:8:31: TemplateTypeParameter=Alloc:8:31 (Definition) Extent=[8:31 - 8:36]
-// CHECK-LOAD: index-templates.cpp:13:7: ClassTemplatePartialSpecialization=vector:13:7 (Definition) Extent=[12:1 - 13:21]
-// CHECK-LOAD: index-templates.cpp:12:19: TemplateTypeParameter=T:12:19 (Definition) Extent=[12:19 - 12:20]
-// FIXME: Need the template type parameter here
+// CHECK-LOAD: index-templates.cpp:10:8: CXXMethod=clear:10:8 Extent=[10:8 - 10:15]
+// CHECK-LOAD: index-templates.cpp:14:7: ClassTemplatePartialSpecialization=vector:14:7 (Definition) Extent=[13:1 - 14:21]
+// CHECK-LOAD: index-templates.cpp:13:19: TemplateTypeParameter=T:13:19 (Definition) Extent=[13:19 - 13:20]
+// CHECK-LOAD: index-templates.cpp:16:8: StructDecl=Z1:16:8 (Definition) Extent=[16:1 - 16:14]
+// CHECK-LOAD: index-templates.cpp:18:16: ClassDecl=vector:18:16 (Definition) Extent=[18:1 - 18:22]
+// CHECK-LOAD: index-templates.cpp:18:23: TypeRef=struct Z1:16:8 Extent=[18:23 - 18:25]
+// CHECK-LOAD-NOT: CXXMethod=clear
+// CHECK-LOAD: index-templates.cpp:20:8: StructDecl=Z2:20:8 (Definition) Extent=[20:1 - 20:14]
+// CHECK-LOAD: index-templates.cpp:23:7: ClassDecl=vector:23:7 (Definition) Extent=[22:1 - 25:2]
+// CHECK-LOAD: index-templates.cpp:23:14: TypeRef=struct Z2:20:8 Extent=[23:14 - 23:16]
+// CHECK-LOAD: index-templates.cpp:24:8: CXXMethod=clear:24:8 Extent=[24:8 - 24:15]
// RUN: c-index-test -test-load-source-usrs all %s | FileCheck -check-prefix=CHECK-USRS %s
// CHECK-USRS: index-templates.cpp c:@FT@>3#T#Nt0.0#t>2#T#Nt1.0f#>t0.22t0.0# Extent=[3:1 - 4:22]
@@ -39,6 +59,14 @@
// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 136@FT@>3#T#Nt0.0#t>2#T#Nt1.0f#>t0.22t0.0#@x Extent=[4:8 - 4:21]
// CHECK-USRS: index-templates.cpp c:@CT>1#T at allocator Extent=[6:1 - 6:37]
// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 171 Extent=[6:19 - 6:20]
-// CHECK-USRS: index-templates.cpp c:@CT>2#T#T at vector Extent=[8:1 - 10:2]
-// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 264@CP>1#T at vector Extent=[12:1 - 13:21]
-// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 282 Extent=[12:19 - 12:20]
+// CHECK-USRS: index-templates.cpp c:@CT>2#T#T at vector Extent=[8:1 - 11:2]
+// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 210 Extent=[8:19 - 8:20]
+// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 222 Extent=[8:31 - 8:36]
+// CHECK-USRS: index-templates.cpp c:@CT>2#T#T at vector@F at clear# Extent=[10:8 - 10:15]
+// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 280@CP>1#T at vector>#*t0.0#>@CT>1#T at allocator1*t0.0 Extent=[13:1 - 14:21]
+// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 298 Extent=[13:19 - 13:20]
+// CHECK-USRS: index-templates.cpp c:@S at Z1 Extent=[16:1 - 16:14]
+// CHECK-USRS: index-templates.cpp c:@C at vector>#$@S at Z1#$@C at allocator>#$@S at Z1 Extent=[18:1 - 18:22]
+// CHECK-USRS: index-templates.cpp c:@S at Z2 Extent=[20:1 - 20:14]
+// CHECK-USRS: index-templates.cpp c:@C at vector>#$@S at Z2#$@C at allocator>#$@S at Z2 Extent=[22:1 - 25:2]
+// CHECK-USRS: index-templates.cpp c:@C at vector>#$@S at Z2#$@C at allocator>#$@S at Z2@F at clear# Extent=[24:8 - 24:15]
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=112720&r1=112719&r2=112720&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Sep 1 12:32:36 2010
@@ -290,6 +290,7 @@
bool VisitTranslationUnitDecl(TranslationUnitDecl *D);
bool VisitTypedefDecl(TypedefDecl *D);
bool VisitTagDecl(TagDecl *D);
+ bool VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D);
bool VisitClassTemplatePartialSpecializationDecl(
ClassTemplatePartialSpecializationDecl *D);
bool VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
@@ -605,6 +606,41 @@
return VisitDeclContext(D);
}
+bool CursorVisitor::VisitClassTemplateSpecializationDecl(
+ ClassTemplateSpecializationDecl *D) {
+ bool ShouldVisitBody = false;
+ switch (D->getSpecializationKind()) {
+ case TSK_Undeclared:
+ case TSK_ImplicitInstantiation:
+ // Nothing to visit
+ return false;
+
+ case TSK_ExplicitInstantiationDeclaration:
+ case TSK_ExplicitInstantiationDefinition:
+ break;
+
+ case TSK_ExplicitSpecialization:
+ ShouldVisitBody = true;
+ break;
+ }
+
+ // Visit the template arguments used in the specialization.
+ if (TypeSourceInfo *SpecType = D->getTypeAsWritten()) {
+ TypeLoc TL = SpecType->getTypeLoc();
+ if (TemplateSpecializationTypeLoc *TSTLoc
+ = dyn_cast<TemplateSpecializationTypeLoc>(&TL)) {
+ for (unsigned I = 0, N = TSTLoc->getNumArgs(); I != N; ++I)
+ if (VisitTemplateArgumentLoc(TSTLoc->getArgLoc(I)))
+ return true;
+ }
+ }
+
+ if (ShouldVisitBody && VisitCXXRecordDecl(D))
+ return true;
+
+ return false;
+}
+
bool CursorVisitor::VisitClassTemplatePartialSpecializationDecl(
ClassTemplatePartialSpecializationDecl *D) {
// FIXME: Visit the "outer" template parameter lists on the TagDecl
Modified: cfe/trunk/tools/libclang/CIndexUSRs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexUSRs.cpp?rev=112720&r1=112719&r2=112720&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexUSRs.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexUSRs.cpp Wed Sep 1 12:32:36 2010
@@ -422,6 +422,17 @@
else
Buf[off] = 'a';
}
+
+ // For a class template specialization, mangle the template arguments.
+ if (ClassTemplateSpecializationDecl *Spec
+ = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
+ const TemplateArgumentList &Args = Spec->getTemplateInstantiationArgs();
+ Out << '>';
+ for (unsigned I = 0, N = Args.size(); I != N; ++I) {
+ Out << '#';
+ VisitTemplateArgument(Args.get(I));
+ }
+ }
}
void USRGenerator::VisitTypedefDecl(TypedefDecl *D) {
More information about the cfe-commits
mailing list