[cfe-commits] r115425 - in /cfe/trunk: test/Index/index-templates.cpp test/Index/print-typekind.c tools/libclang/CXType.cpp

Douglas Gregor dgregor at apple.com
Sat Oct 2 14:57:59 PDT 2010


Author: dgregor
Date: Sat Oct  2 16:57:58 2010
New Revision: 115425

URL: http://llvm.org/viewvc/llvm-project?rev=115425&view=rev
Log:
Teach clang_getCursorType() about base specifiers and other references
to types. 

Also, teach clang_getTypeDeclaration() about template specializations,
injected-class-names, and elaborated types.

Fixes <rdar://problem/8506460>.

Modified:
    cfe/trunk/test/Index/index-templates.cpp
    cfe/trunk/test/Index/print-typekind.c
    cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/test/Index/index-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-templates.cpp?rev=115425&r1=115424&r2=115425&view=diff
==============================================================================
--- cfe/trunk/test/Index/index-templates.cpp (original)
+++ cfe/trunk/test/Index/index-templates.cpp Sat Oct  2 16:57:58 2010
@@ -95,6 +95,11 @@
 
 void f(map<Z4, Pair<int, Z4> >);
 
+template class Pair<int, int>;
+
+template<typename T, typename U>
+struct SuperPair : Pair<int, int>, Pair<T, U> { };
+
 // 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]
@@ -168,6 +173,12 @@
 // 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]
+// CHECK-LOAD: index-templates.cpp:101:8: ClassTemplate=SuperPair:101:8 (Definition) Extent=[100:1 - 101:50]
+// CHECK-LOAD: index-templates.cpp:100:19: TemplateTypeParameter=T:100:19 (Definition) Extent=[100:19 - 100:20]
+// CHECK-LOAD: index-templates.cpp:100:31: TemplateTypeParameter=U:100:31 (Definition) Extent=[100:31 - 100:32]
+// CHECK-LOAD: index-templates.cpp:101:20: C++ base class specifier=Pair<int, int>:98:16 [access=public isVirtual=false] Extent=[101:20 - 101:34]
+// CHECK-LOAD: index-templates.cpp:101:36: C++ base class specifier=Pair<T, U>:76:8 [access=public isVirtual=false] Extent=[101:36 - 101:46]
+
 
 // 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.22S0_# Extent=[3:1 - 4:22]
@@ -193,4 +204,4 @@
 // 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_#
+// CHECK-USRS: 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/test/Index/print-typekind.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-typekind.c?rev=115425&r1=115424&r2=115425&view=diff
==============================================================================
--- cfe/trunk/test/Index/print-typekind.c (original)
+++ cfe/trunk/test/Index/print-typekind.c Sat Oct  2 16:57:58 2010
@@ -12,11 +12,11 @@
 // CHECK: ParmDecl=p:3:13 (Definition) typekind=Pointer [isPOD=1]
 // CHECK: ParmDecl=x:3:22 (Definition) typekind=Pointer [isPOD=1]
 // CHECK: ParmDecl=z:3:33 (Definition) typekind=Typedef [canonical=Int] [isPOD=1]
-// CHECK: TypeRef=FooType:1:13 typekind=Invalid [isPOD=0]
+// CHECK: TypeRef=FooType:1:13 typekind=Typedef [canonical=Int] [isPOD=1]
 // CHECK: UnexposedStmt= typekind=Invalid [isPOD=0]
 // CHECK: UnexposedStmt= typekind=Invalid [isPOD=0]
 // CHECK: VarDecl=w:4:11 (Definition) typekind=Typedef [canonical=Int] [isPOD=1]
-// CHECK: TypeRef=FooType:1:13 typekind=Invalid [isPOD=0]
+// CHECK: TypeRef=FooType:1:13 typekind=Typedef [canonical=Int] [isPOD=1]
 // CHECK: DeclRefExpr=z:3:33 typekind=Typedef [canonical=Int] [isPOD=1]
 // CHECK: UnexposedStmt= typekind=Invalid [isPOD=0]
 // CHECK: UnexposedExpr= typekind=Pointer [isPOD=1]

Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=115425&r1=115424&r2=115425&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXType.cpp (original)
+++ cfe/trunk/tools/libclang/CXType.cpp Sat Oct  2 16:57:58 2010
@@ -18,6 +18,7 @@
 #include "clang/AST/Type.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/Frontend/ASTUnit.h"
 
 using namespace clang;
@@ -106,6 +107,8 @@
 extern "C" {
 
 CXType clang_getCursorType(CXCursor C) {
+  using namespace cxcursor;
+  
   ASTUnit *AU = cxcursor::getCursorASTUnit(C);
 
   if (clang_isExpression(C.kind)) {
@@ -128,6 +131,40 @@
       return MakeCXType(FD->getType(), AU);
     return MakeCXType(QualType(), AU);
   }
+  
+  if (clang_isReference(C.kind)) {
+    switch (C.kind) {
+    case CXCursor_ObjCSuperClassRef:
+      return MakeCXType(
+                QualType(getCursorObjCSuperClassRef(C).first->getTypeForDecl(), 
+                         0), 
+                        AU);
+      
+    case CXCursor_ObjCClassRef:
+      return MakeCXType(
+                      QualType(getCursorObjCClassRef(C).first->getTypeForDecl(), 
+                               0), 
+                        AU);
+      
+    case CXCursor_TypeRef:
+      return MakeCXType(QualType(getCursorTypeRef(C).first->getTypeForDecl(), 
+                                 0), 
+                        AU);
+      
+    case CXCursor_CXXBaseSpecifier:
+      return cxtype::MakeCXType(getCursorCXXBaseSpecifier(C)->getType(), AU);
+      
+    case CXCursor_ObjCProtocolRef:        
+    case CXCursor_TemplateRef:
+    case CXCursor_NamespaceRef:
+    case CXCursor_MemberRef:
+    case CXCursor_OverloadedDeclRef:      
+    default:
+      break;
+    }
+    
+    return MakeCXType(QualType(), AU);
+  }
 
   return MakeCXType(QualType(), AU);
 }
@@ -185,22 +222,41 @@
 
   Decl *D = 0;
 
+try_again:
   switch (TP->getTypeClass()) {
-    case Type::Typedef:
-      D = cast<TypedefType>(TP)->getDecl();
-      break;
-    case Type::ObjCObject:
-      D = cast<ObjCObjectType>(TP)->getInterface();
-      break;
-    case Type::ObjCInterface:
-      D = cast<ObjCInterfaceType>(TP)->getDecl();
-      break;
-    case Type::Record:
-    case Type::Enum:
-      D = cast<TagType>(TP)->getDecl();
-      break;
-    default:
-      break;
+  case Type::Typedef:
+    D = cast<TypedefType>(TP)->getDecl();
+    break;
+  case Type::ObjCObject:
+    D = cast<ObjCObjectType>(TP)->getInterface();
+    break;
+  case Type::ObjCInterface:
+    D = cast<ObjCInterfaceType>(TP)->getDecl();
+    break;
+  case Type::Record:
+  case Type::Enum:
+    D = cast<TagType>(TP)->getDecl();
+    break;
+  case Type::TemplateSpecialization:
+    if (const RecordType *Record = TP->getAs<RecordType>())
+      D = Record->getDecl();
+    else
+      D = cast<TemplateSpecializationType>(TP)->getTemplateName()
+                                                         .getAsTemplateDecl();
+    break;
+      
+  case Type::InjectedClassName:
+    D = cast<InjectedClassNameType>(TP)->getDecl();
+    break;
+
+  // FIXME: Template type parameters!      
+
+  case Type::Elaborated:
+    TP = cast<ElaboratedType>(TP)->getNamedType().getTypePtr();
+    goto try_again;
+    
+  default:
+    break;
   }
 
   if (!D)





More information about the cfe-commits mailing list