From: Ted Kremenek Date: Tue, 21 Sep 2010 20:52:59 +0000 (+0000) Subject: Correctly register the class extension as the lexical DeclContext for ObjC methods... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a054fb46b1fb596d1719b89d2d9a5be3c32a4b0d;p=clang Correctly register the class extension as the lexical DeclContext for ObjC methods declared with @property in class extensions. This matches the behavior for setters. Also pass the class extension to ProcessPropertyDecl as the lexical DeclContext, even when not redeclaring the @property. This fixes the remaining issues in . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114477 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index a6f251e107..ba71b4ca4d 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -137,9 +137,9 @@ Sema::HandlePropertyInClassExtension(Scope *S, ObjCCategoryDecl *CDecl, // A case of continuation class adding a new property in the class. This // is not what it was meant for. However, gcc supports it and so should we. // Make sure setter/getters are declared here. - ProcessPropertyDecl(PDecl, CCPrimary); + ProcessPropertyDecl(PDecl, CCPrimary, /* redeclaredProperty = */ 0, + /* lexicalDC = */ CDecl); return PDecl; - } // The property 'PIDecl's readonly attribute will be over-ridden @@ -1099,8 +1099,12 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, // No instance method of same name as property getter name was found. // Declare a getter method and add it to the list of methods // for this class. - GetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(), - property->getLocation(), property->getGetterName(), + SourceLocation Loc = redeclaredProperty ? + redeclaredProperty->getLocation() : + property->getLocation(); + + GetterMethod = ObjCMethodDecl::Create(Context, Loc, Loc, + property->getGetterName(), property->getType(), 0, CD, true, false, true, false, (property->getPropertyImplementation() == @@ -1110,9 +1114,8 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, CD->addDecl(GetterMethod); // FIXME: Eventually this shouldn't be needed, as the lexical context // and the real context should be the same. - if (DeclContext *lexicalDC = property->getLexicalDeclContext()) + if (lexicalDC) GetterMethod->setLexicalDeclContext(lexicalDC); - } else // A user declared getter will be synthesize when @synthesize of // the property with the same name is seen in the @implementation diff --git a/test/Index/properties-class-extensions.m b/test/Index/properties-class-extensions.m index c7e53552d0..17b0425866 100644 --- a/test/Index/properties-class-extensions.m +++ b/test/Index/properties-class-extensions.m @@ -21,8 +21,8 @@ // RUN: c-index-test -test-load-source local %s | FileCheck %s // CHECK: properties-class-extensions.m:4:12: ObjCInterfaceDecl=Foo:4:12 Extent=[4:1 - 4:23] -// CHECK: properties-class-extensions.m:9:15: ObjCInstanceMethodDecl=setB::9:15 Extent=[9:15 - 9:16] -// CHECK: properties-class-extensions.m:9:15: ParmDecl=b:9:15 (Definition) Extent=[9:15 - 9:16] +// CHECK-not: properties-class-extensions.m:9:15: ObjCInstanceMethodDecl=setB::9:15 Extent=[9:15 - 9:16] +// CHECK-not: properties-class-extensions.m:9:15: ParmDecl=b:9:15 (Definition) Extent=[9:15 - 9:16] // CHECK: properties-class-extensions.m:5:12: ObjCCategoryDecl=Cat:5:12 Extent=[5:1 - 7:5] // CHECK: properties-class-extensions.m:5:12: ObjCClassRef=Foo:4:12 Extent=[5:12 - 5:15] // CHECK: properties-class-extensions.m:6:15: ObjCPropertyDecl=a:6:15 Extent=[6:15 - 6:16] @@ -44,7 +44,7 @@ // CHECK: properties-class-extensions.m:18:12: ObjCClassRef=Bar:15:12 Extent=[18:12 - 18:15] // CHECK: properties-class-extensions.m:19:26: ObjCPropertyDecl=bar:19:26 Extent=[19:26 - 19:29] // CHECK: properties-class-extensions.m:19:23: TypeRef=id:0:0 Extent=[19:23 - 19:25] -// CHECK: properties-class-extensions.m:16:25: ObjCInstanceMethodDecl=bar:16:25 Extent=[16:25 - 16:28] +// CHECK-not: properties-class-extensions.m:16:25: ObjCInstanceMethodDecl=bar:16:25 Extent=[16:25 - 16:28] // CHECK: properties-class-extensions.m:19:26: ObjCInstanceMethodDecl=setBar::19:26 Extent=[19:26 - 19:29] // CHECK: properties-class-extensions.m:19:26: ParmDecl=bar:19:26 (Definition) Extent=[19:26 - 19:29] diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 19f99ae265..c0cecffd01 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -920,12 +920,12 @@ bool CursorVisitor::VisitObjCPropertyDecl(ObjCPropertyDecl *PD) { // Visit synthesized methods since they will be skipped when visiting // the @interface. if (ObjCMethodDecl *MD = prevDecl->getGetterMethodDecl()) - if (MD->isSynthesized()) + if (MD->isSynthesized() && MD->getLexicalDeclContext() == CDecl) if (Visit(MakeCXCursor(MD, TU))) return true; if (ObjCMethodDecl *MD = prevDecl->getSetterMethodDecl()) - if (MD->isSynthesized()) + if (MD->isSynthesized() && MD->getLexicalDeclContext() == CDecl) if (Visit(MakeCXCursor(MD, TU))) return true;