From: Argyrios Kyrtzidis Date: Mon, 24 Aug 2015 19:50:45 +0000 (+0000) Subject: [libclang] For convenience to clients, make sure that nullability and __kindof annota... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fee3d15fccb6feb49787a7043fc721c6c72903af;p=clang [libclang] For convenience to clients, make sure that nullability and __kindof annotations do not hide the underlying type. rdar://22063577 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245867 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Index/get-cursor.m b/test/Index/get-cursor.m index f659fb1ff6..d321233401 100644 --- a/test/Index/get-cursor.m +++ b/test/Index/get-cursor.m @@ -112,6 +112,23 @@ void foo3(Test3 *test3) { @property (retain) id propProp3; @end +@interface TestNullability +@property (strong, nonnull) id prop1; +@property (strong, nullable) id prop2; +@end + +@implementation TestNullability +- (void)meth { + TestNullability *o; + [o.prop1 meth]; + [o.prop2 meth]; + _Nullable id lo1; + _Nonnull id lo2; + [lo1 meth]; + [lo2 meth]; +} +@end + // RUN: c-index-test -cursor-at=%s:4:28 -cursor-at=%s:5:28 %s | FileCheck -check-prefix=CHECK-PROP %s // CHECK-PROP: ObjCPropertyDecl=foo1:4:26 @@ -170,3 +187,9 @@ void foo3(Test3 *test3) { // CHECK-OBJCOPTIONAL: 108:23 ObjCPropertyDecl=propProp2:108:23 (@optional) [retain,] Extent=[108:1 - 108:32] // CHECK-OBJCOPTIONAL: 111:8 ObjCInstanceMethodDecl=protMeth3:111:8 Extent=[111:1 - 111:18] // CHECK-OBJCOPTIONAL: 112:23 ObjCPropertyDecl=propProp3:112:23 [retain,] Extent=[112:1 - 112:32] + +// RUN: c-index-test -cursor-at=%s:123:12 %s | FileCheck -check-prefix=CHECK-RECEIVER-WITH-NULLABILITY %s +// RUN: c-index-test -cursor-at=%s:124:12 %s | FileCheck -check-prefix=CHECK-RECEIVER-WITH-NULLABILITY %s +// RUN: c-index-test -cursor-at=%s:127:8 %s | FileCheck -check-prefix=CHECK-RECEIVER-WITH-NULLABILITY %s +// RUN: c-index-test -cursor-at=%s:128:8 %s | FileCheck -check-prefix=CHECK-RECEIVER-WITH-NULLABILITY %s +// CHECK-RECEIVER-WITH-NULLABILITY: Receiver-type=ObjCId diff --git a/test/Index/print-type.m b/test/Index/print-type.m index 5a4272b131..777069b3a5 100644 --- a/test/Index/print-type.m +++ b/test/Index/print-type.m @@ -3,6 +3,7 @@ -(int) mymethod; -(const id) mymethod2:(id)x blah:(Class)y boo:(SEL)z; -(bycopy)methodIn:(in int)i andOut:(out short *)j , ...; +-(void)kindof_meth:(__kindof Foo *)p; @end // RUN: c-index-test -test-print-type %s | FileCheck %s @@ -13,3 +14,4 @@ // CHECK: ObjCInstanceMethodDecl=methodIn:andOut::5:10 (variadic) [Bycopy,] [type=] [typekind=Invalid] [resulttype=id] [resulttypekind=ObjCId] [args= [int] [Int] [short *] [Pointer]] [isPOD=0] // CHECK: ParmDecl=i:5:27 (Definition) [In,] [type=int] [typekind=Int] [isPOD=1] // CHECK: ParmDecl=j:5:49 (Definition) [Out,] [type=short *] [typekind=Pointer] [isPOD=1] [pointeetype=short] [pointeekind=Short] +// CHECK: ParmDecl=p:6:36 (Definition) [type=__kindof Foo *] [typekind=ObjCObjectPointer] [canonicaltype=__kindof Foo *] [canonicaltypekind=ObjCObjectPointer] [isPOD=1] [pointeetype=Foo] [pointeekind=ObjCInterface] diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index 1318e86b55..6fd7bc3125 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -101,6 +101,11 @@ CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) { CXTypeKind TK = CXType_Invalid; if (TU && !T.isNull()) { + // Handle attributed types as the original type + if (auto *ATT = T->getAs()) { + return MakeCXType(ATT->getModifiedType(), TU); + } + ASTContext &Ctx = cxtu::getASTUnit(TU)->getASTContext(); if (Ctx.getLangOpts().ObjC1) { QualType UnqualT = T.getUnqualifiedType();