diff options
| author | Douglas Gregor <dgregor@apple.com> | 2011-01-24 18:44:28 +0000 | 
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2011-01-24 18:44:28 +0000 | 
| commit | 62c31346292888357d82f42bac8e1a0e05c356fb (patch) | |
| tree | e5df21483ca0ef963ee176584ffdb4c93ec7c3be | |
| parent | f277b5d4348402162c0afd064a3bc20ec7c99e3c (diff) | |
| download | bcm5719-llvm-62c31346292888357d82f42bac8e1a0e05c356fb.tar.gz bcm5719-llvm-62c31346292888357d82f42bac8e1a0e05c356fb.zip  | |
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.
llvm-svn: 124133
| -rw-r--r-- | clang/test/Index/print-typekind.c | 2 | ||||
| -rw-r--r-- | clang/tools/libclang/CXType.cpp | 39 | 
2 files changed, 22 insertions, 19 deletions
diff --git a/clang/test/Index/print-typekind.c b/clang/test/Index/print-typekind.c index d521f06ed0a..fad3a2dc252 100644 --- a/clang/test/Index/print-typekind.c +++ b/clang/test/Index/print-typekind.c @@ -4,6 +4,7 @@ int *f(int *p, char *x, FooType z) {    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 @@ int *f(int *p, char *x, FooType z) {  // 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] diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp index 7cb44928048..7b603c0f932 100644 --- a/clang/tools/libclang/CXType.cpp +++ b/clang/tools/libclang/CXType.cpp @@ -113,6 +113,7 @@ CXType clang_getCursorType(CXCursor C) {    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 @@ CXType clang_getCursorType(CXCursor C) {      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 @@ CXType clang_getCursorType(CXCursor C) {    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 @@ CXString clang_getDeclObjCTypeEncoding(CXCursor C) {    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("?");  | 

