From ba73adafabb1c0af8bec70a1673edc11e6d30a89 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 19 Jan 2011 20:50:07 +0000 Subject: [PATCH] Teach libclang to generate USRs containing parameter packs and pack expansions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123848 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Index/usrs-cxx0x.cpp | 8 ++++++++ tools/libclang/CIndexUSRs.cpp | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 test/Index/usrs-cxx0x.cpp diff --git a/test/Index/usrs-cxx0x.cpp b/test/Index/usrs-cxx0x.cpp new file mode 100644 index 0000000000..a0ea6ba69c --- /dev/null +++ b/test/Index/usrs-cxx0x.cpp @@ -0,0 +1,8 @@ +template +struct tuple { }; + +void f(tuple); + +// RUN: c-index-test -test-load-source-usrs all -std=c++0x %s | FileCheck %s +// CHECK: usrs-cxx0x.cpp c:@ST>1#pT@tuple Extent=[1:1 - 2:17] +// CHECK: usrs-cxx0x.cpp c:@F@f#$@S@tuple>#p3Ifd# Extent=[4:6 - 4:34] diff --git a/tools/libclang/CIndexUSRs.cpp b/tools/libclang/CIndexUSRs.cpp index 8aed372be6..5e632b9e96 100644 --- a/tools/libclang/CIndexUSRs.cpp +++ b/tools/libclang/CIndexUSRs.cpp @@ -523,6 +523,11 @@ void USRGenerator::VisitType(QualType T) { // Mangle in ObjC GC qualifiers? + if (const PackExpansionType *Expansion = T->getAs()) { + Out << 'P'; + T = Expansion->getPattern(); + } + if (const BuiltinType *BT = T->getAs()) { unsigned char c = '\0'; switch (BT->getKind()) { @@ -666,17 +671,23 @@ void USRGenerator::VisitTemplateParameterList( P != PEnd; ++P) { Out << '#'; if (isa(*P)) { + if (cast(*P)->isParameterPack()) + Out<< 'p'; Out << 'T'; continue; } if (NonTypeTemplateParmDecl *NTTP = dyn_cast(*P)) { + if (NTTP->isParameterPack()) + Out << 'p'; Out << 'N'; VisitType(NTTP->getType()); continue; } TemplateTemplateParmDecl *TTP = cast(*P); + if (TTP->isParameterPack()) + Out << 'p'; Out << 't'; VisitTemplateParameterList(TTP->getTemplateParameters()); } @@ -707,9 +718,10 @@ void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) { Visit(D); break; - case TemplateArgument::Template: case TemplateArgument::TemplateExpansion: - // FIXME: variadic templates + Out << 'P'; // pack expansion of... + // Fall through + case TemplateArgument::Template: VisitTemplateName(Arg.getAsTemplateOrTemplatePattern()); break; @@ -718,7 +730,10 @@ void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) { break; case TemplateArgument::Pack: - // FIXME: Variadic templates + Out << 'p' << Arg.pack_size(); + for (TemplateArgument::pack_iterator P = Arg.pack_begin(), PEnd = Arg.pack_end(); + P != PEnd; ++P) + VisitTemplateArgument(*P); break; case TemplateArgument::Type: -- 2.40.0