[cfe-commits] r124133 - in /cfe/trunk: test/Index/print-typekind.c tools/libclang/CXType.cpp
Douglas Gregor
dgregor at apple.com
Mon Jan 24 10:44:28 PST 2011
Author: dgregor
Date: Mon Jan 24 12:44:28 2011
New Revision: 124133
URL: http://llvm.org/viewvc/llvm-project?rev=124133&view=rev
Log:
Eliminate the use of getTypeForDecl from clang_getCursorType() and
clang_getDeclObjCTypeEncoding(); use ASTContext's methods instead,
which will (lazily) create the type as needed. Otherwise, we can end
up with null QualTypes.
Modified:
cfe/trunk/test/Index/print-typekind.c
cfe/trunk/tools/libclang/CXType.cpp
Modified: cfe/trunk/test/Index/print-typekind.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-typekind.c?rev=124133&r1=124132&r2=124133&view=diff
==============================================================================
--- cfe/trunk/test/Index/print-typekind.c (original)
+++ cfe/trunk/test/Index/print-typekind.c Mon Jan 24 12:44:28 2011
@@ -4,6 +4,7 @@
FooType w = z;
return p + z;
}
+typedef double OtherType;
// RUN: c-index-test -test-print-typekind %s | FileCheck %s
// CHECK: TypedefDecl=FooType:1:13 (Definition) typekind=Typedef [canonical=Int] [isPOD=1]
@@ -22,4 +23,5 @@
// CHECK: UnexposedExpr= typekind=Pointer [isPOD=1]
// CHECK: DeclRefExpr=p:3:13 typekind=Pointer [isPOD=1]
// CHECK: DeclRefExpr=z:3:33 typekind=Typedef [canonical=Int] [isPOD=1]
+// CHECK: TypedefDecl=OtherType:7:16 (Definition) typekind=Typedef [canonical=Double] [isPOD=1]
Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=124133&r1=124132&r2=124133&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXType.cpp (original)
+++ cfe/trunk/tools/libclang/CXType.cpp Mon Jan 24 12:44:28 2011
@@ -113,6 +113,7 @@
using namespace cxcursor;
CXTranslationUnit TU = cxcursor::getCursorTU(C);
+ ASTContext &Context = static_cast<ASTUnit *>(TU->TUData)->getASTContext();
if (clang_isExpression(C.kind)) {
QualType T = cxcursor::getCursorExpr(C)->getType();
return MakeCXType(T, TU);
@@ -122,9 +123,9 @@
Decl *D = cxcursor::getCursorDecl(C);
if (TypeDecl *TD = dyn_cast<TypeDecl>(D))
- return MakeCXType(QualType(TD->getTypeForDecl(), 0), TU);
+ return MakeCXType(Context.getTypeDeclType(TD), TU);
if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
- return MakeCXType(QualType(ID->getTypeForDecl(), 0), TU);
+ return MakeCXType(Context.getObjCInterfaceType(ID), TU);
if (ValueDecl *VD = dyn_cast<ValueDecl>(D))
return MakeCXType(VD->getType(), TU);
if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D))
@@ -136,22 +137,22 @@
if (clang_isReference(C.kind)) {
switch (C.kind) {
- case CXCursor_ObjCSuperClassRef:
- return MakeCXType(
- QualType(getCursorObjCSuperClassRef(C).first->getTypeForDecl(),
- 0),
- TU);
-
- case CXCursor_ObjCClassRef:
- return MakeCXType(
- QualType(getCursorObjCClassRef(C).first->getTypeForDecl(),
- 0),
- TU);
-
- case CXCursor_TypeRef:
- return MakeCXType(QualType(getCursorTypeRef(C).first->getTypeForDecl(),
- 0),
- TU);
+ case CXCursor_ObjCSuperClassRef: {
+ QualType T
+ = Context.getObjCInterfaceType(getCursorObjCSuperClassRef(C).first);
+ return MakeCXType(T, TU);
+ }
+
+ case CXCursor_ObjCClassRef: {
+ QualType T = Context.getObjCInterfaceType(getCursorObjCClassRef(C).first);
+ return MakeCXType(T, TU);
+ }
+
+ case CXCursor_TypeRef: {
+ QualType T = Context.getTypeDeclType(getCursorTypeRef(C).first);
+ return MakeCXType(T, TU);
+
+ }
case CXCursor_CXXBaseSpecifier:
return cxtype::MakeCXType(getCursorCXXBaseSpecifier(C)->getType(), TU);
@@ -372,7 +373,7 @@
else {
QualType Ty;
if (TypeDecl *TD = dyn_cast<TypeDecl>(D))
- Ty = QualType(TD->getTypeForDecl(), 0);
+ Ty = Ctx.getTypeDeclType(TD);
if (ValueDecl *VD = dyn_cast<ValueDecl>(D))
Ty = VD->getType();
else return cxstring::createCXString("?");
More information about the cfe-commits
mailing list