[cfe-commits] r114347 - in /cfe/trunk: test/Index/index-templates.cpp tools/libclang/CIndexUSRs.cpp
Douglas Gregor
dgregor at apple.com
Mon Sep 20 13:37:39 PDT 2010
Author: dgregor
Date: Mon Sep 20 15:37:39 2010
New Revision: 114347
URL: http://llvm.org/viewvc/llvm-project?rev=114347&view=rev
Log:
Introduce a simple, substitution-based compression scheme for USRs, so
that redundant types don't result in super-long USRs. Fixes
<rdar://problem/8447875>.
Modified:
cfe/trunk/test/Index/index-templates.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=114347&r1=114346&r2=114347&view=diff
==============================================================================
--- cfe/trunk/test/Index/index-templates.cpp (original)
+++ cfe/trunk/test/Index/index-templates.cpp Mon Sep 20 15:37:39 2010
@@ -72,7 +72,7 @@
swap<T>(x, x);
}
-template<typename T, U>
+template<typename T, typename U>
struct Pair {
T first;
U second;
@@ -85,6 +85,16 @@
Pair<T, U> p = { t, second_type(u) };
}
+template<typename T>
+struct compare { };
+
+template<typename Key, typename Value,
+ typename Comparison = compare<Pair<Key, Value> >,
+ typename Allocator = allocator<Pair<Key, Value> > >
+struct map;
+
+void f(map<Z4, Pair<int, Z4> >);
+
// 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]
@@ -154,32 +164,33 @@
// CHECK-LOAD: index-templates.cpp:71:6: OverloadedDeclRef=f[63:7, 64:9]
// CHECK-LOAD: index-templates.cpp:72:3: OverloadedDeclRef=swap[58:27, 59:39]
// CHECK-LOAD: index-templates.cpp:82:6: FunctionTemplate=init_list:82:6 (Definition)
-// CHECK-LOAD: index-templates.cpp:85:14: VarDecl=p:85:14 (Definition) Extent=[85:14 - 85:39]
+// CHECK-LOAD: index-templates.cpp:85:14: VarDecl=p:85:14 (Definition)
// CHECK-LOAD: index-templates.cpp:85:20: DeclRefExpr=t:82:18 Extent=[85:20 - 85:21]
// CHECK-LOAD: index-templates.cpp:85:23: TypeRef=second_type:83:13 Extent=[85:23 - 85:34]
// CHECK-LOAD: index-templates.cpp:85:35: DeclRefExpr=u:82:23 Extent=[85:35 - 85:36]
// 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]
+// CHECK-USRS: index-templates.cpp c:@FT@>3#T#Nt0.0#t>2#T#Nt1.0f#>t0.22S0_# Extent=[3:1 - 4:22]
// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 79 Extent=[3:19 - 3:20]
// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 82 Extent=[3:22 - 3:29]
// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 91 Extent=[3:31 - 3:67]
-// 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:index-templates.cpp at 136@FT@>3#T#Nt0.0#t>2#T#Nt1.0f#>t0.22S0_#@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 - 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 280@CP>1#T at vector>#*t0.0#>@CT>1#T at allocator1S0_ 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:@C at vector>#$@S at Z1#$@C at allocator>#S0_ 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]
+// CHECK-USRS: index-templates.cpp c:@C at vector>#$@S at Z2#$@C at allocator>#S0_ Extent=[22:1 - 25:2]
+// CHECK-USRS: index-templates.cpp c:@C at vector>#$@S at Z2#$@C at allocator>#S0_ at F@clear# Extent=[24:8 - 24:15]
// CHECK-USRS: index-templates.cpp c:@ST>2#T#T at Y Extent=[27:1 - 31:2]
// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 452 Extent=[27:19 - 27:20]
// CHECK-USRS: index-templates.cpp c:index-templates.cpp at 464 Extent=[27:31 - 27:32]
// CHECK-USRS-NOT: type
// CHECK-USRS: index-templates.cpp c:@S at Z3 Extent=[33:1 - 33:14]
+// CHECK-USES: index-templates.cpp c:@F at f#$@S at map>#$@S at Z4#$@S at Pair>#I#S1_#$@S at compare>#$@S at Pair>#S1_#S2_#$@C at allocator>#S4_#
Modified: cfe/trunk/tools/libclang/CIndexUSRs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexUSRs.cpp?rev=114347&r1=114346&r2=114347&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexUSRs.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexUSRs.cpp Mon Sep 20 15:37:39 2010
@@ -34,6 +34,9 @@
bool IgnoreResults;
ASTUnit *AU;
bool generatedLoc;
+
+ llvm::DenseMap<const Type *, unsigned> TypeSubstitutions;
+
public:
USRGenerator(const CXCursor *C = 0)
: Out(Buf),
@@ -510,32 +513,6 @@
// Mangle in ObjC GC qualifiers?
- if (const PointerType *PT = T->getAs<PointerType>()) {
- Out << '*';
- T = PT->getPointeeType();
- continue;
- }
- if (const ReferenceType *RT = T->getAs<ReferenceType>()) {
- Out << '&';
- T = RT->getPointeeType();
- continue;
- }
- if (const FunctionProtoType *FT = T->getAs<FunctionProtoType>()) {
- Out << 'F';
- VisitType(FT->getResultType());
- for (FunctionProtoType::arg_type_iterator
- I = FT->arg_type_begin(), E = FT->arg_type_end(); I!=E; ++I) {
- VisitType(*I);
- }
- if (FT->isVariadic())
- Out << '.';
- return;
- }
- if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) {
- Out << 'B';
- T = BT->getPointeeType();
- continue;
- }
if (const BuiltinType *BT = T->getAs<BuiltinType>()) {
unsigned char c = '\0';
switch (BT->getKind()) {
@@ -598,6 +575,46 @@
Out << c;
return;
}
+
+ // If we have already seen this (non-built-in) type, use a substitution
+ // encoding.
+ llvm::DenseMap<const Type *, unsigned>::iterator Substitution
+ = TypeSubstitutions.find(T.getTypePtr());
+ if (Substitution != TypeSubstitutions.end()) {
+ Out << 'S' << Substitution->second << '_';
+ return;
+ } else {
+ // Record this as a substitution.
+ unsigned Number = TypeSubstitutions.size();
+ TypeSubstitutions[T.getTypePtr()] = Number;
+ }
+
+ if (const PointerType *PT = T->getAs<PointerType>()) {
+ Out << '*';
+ T = PT->getPointeeType();
+ continue;
+ }
+ if (const ReferenceType *RT = T->getAs<ReferenceType>()) {
+ Out << '&';
+ T = RT->getPointeeType();
+ continue;
+ }
+ if (const FunctionProtoType *FT = T->getAs<FunctionProtoType>()) {
+ Out << 'F';
+ VisitType(FT->getResultType());
+ for (FunctionProtoType::arg_type_iterator
+ I = FT->arg_type_begin(), E = FT->arg_type_end(); I!=E; ++I) {
+ VisitType(*I);
+ }
+ if (FT->isVariadic())
+ Out << '.';
+ return;
+ }
+ if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) {
+ Out << 'B';
+ T = BT->getPointeeType();
+ continue;
+ }
if (const ComplexType *CT = T->getAs<ComplexType>()) {
Out << '<';
T = CT->getElementType();
More information about the cfe-commits
mailing list