diff options
author | Douglas Gregor <dgregor@apple.com> | 2013-01-21 19:05:22 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2013-01-21 19:05:22 +0000 |
commit | aabd094cf694039fe823987e133af7ac25cb9711 (patch) | |
tree | 3a14e0f3b77c4ba167042bb0395c85ea9521bcb7 /lib/Sema/SemaObjCProperty.cpp | |
parent | eb8fc58241e1781a77c958764e16a4c402e4d707 (diff) |
Eliminate the oddly-named Sema::ComparePropertiesInBaseAndSuper, which
did a redundant traversal of the lexical declarations in the
superclass. Instead, when we declare a new property, look into the
superclass to see whether we're redeclaring the property. Goot for 1%
of -fsyntax-only time on Cocoa.h and a little less than 3% on my
modules test case.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173073 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaObjCProperty.cpp')
-rw-r--r-- | lib/Sema/SemaObjCProperty.cpp | 73 |
1 files changed, 28 insertions, 45 deletions
diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index 82a97f9ee0..98d70a58ab 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -139,34 +139,31 @@ Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, !(Attributes & ObjCDeclSpec::DQ_PR_unsafe_unretained) && !(Attributes & ObjCDeclSpec::DQ_PR_weak))); - // Proceed with constructing the ObjCPropertDecls. + // Proceed with constructing the ObjCPropertyDecls. ObjCContainerDecl *ClassDecl = cast<ObjCContainerDecl>(CurContext); - if (ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) + ObjCPropertyDecl *Res = 0; + if (ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) { if (CDecl->IsClassExtension()) { - Decl *Res = HandlePropertyInClassExtension(S, AtLoc, LParenLoc, + Res = HandlePropertyInClassExtension(S, AtLoc, LParenLoc, FD, GetterSel, SetterSel, isAssign, isReadWrite, Attributes, ODS.getPropertyAttributes(), isOverridingProperty, TSI, MethodImplKind); - if (Res) { - CheckObjCPropertyAttributes(Res, AtLoc, Attributes, false); - if (getLangOpts().ObjCAutoRefCount) - checkARCPropertyDecl(*this, cast<ObjCPropertyDecl>(Res)); - } - ActOnDocumentableDecl(Res); - return Res; + if (!Res) + return 0; } - - ObjCPropertyDecl *Res = CreatePropertyDecl(S, ClassDecl, AtLoc, LParenLoc, FD, - GetterSel, SetterSel, - isAssign, isReadWrite, - Attributes, - ODS.getPropertyAttributes(), - TSI, MethodImplKind); - if (lexicalDC) - Res->setLexicalDeclContext(lexicalDC); + } + + if (!Res) { + Res = CreatePropertyDecl(S, ClassDecl, AtLoc, LParenLoc, FD, + GetterSel, SetterSel, isAssign, isReadWrite, + Attributes, ODS.getPropertyAttributes(), + TSI, MethodImplKind); + if (lexicalDC) + Res->setLexicalDeclContext(lexicalDC); + } // Validate the attributes on the @property. CheckObjCPropertyAttributes(Res, AtLoc, Attributes, @@ -176,6 +173,16 @@ Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, if (getLangOpts().ObjCAutoRefCount) checkARCPropertyDecl(*this, Res); + // Compare this property against the property in our superclass. + if (ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) { + if (ObjCInterfaceDecl *Super = IFace->getSuperClass()) { + DeclContext::lookup_result R = Super->lookup(Res->getDeclName()); + for (unsigned I = 0, N = R.size(); I != N; ++I) + if (ObjCPropertyDecl *SuperProp = dyn_cast<ObjCPropertyDecl>(R[I])) + DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier()); + } + } + ActOnDocumentableDecl(Res); return Res; } @@ -251,7 +258,7 @@ static unsigned getOwnershipRule(unsigned attr) { ObjCPropertyDecl::OBJC_PR_unsafe_unretained); } -Decl * +ObjCPropertyDecl * Sema::HandlePropertyInClassExtension(Scope *S, SourceLocation AtLoc, SourceLocation LParenLoc, @@ -1276,30 +1283,6 @@ bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property, return false; } -/// ComparePropertiesInBaseAndSuper - This routine compares property -/// declarations in base and its super class, if any, and issues -/// diagnostics in a variety of inconsistent situations. -/// -void Sema::ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl) { - ObjCInterfaceDecl *SDecl = IDecl->getSuperClass(); - if (!SDecl) - return; - // FIXME: We should perform this check when the property in the subclass - // is declared. - for (ObjCInterfaceDecl::prop_iterator S = SDecl->prop_begin(), - E = SDecl->prop_end(); S != E; ++S) { - ObjCPropertyDecl *SuperPDecl = *S; - DeclContext::lookup_result Results - = IDecl->lookup(SuperPDecl->getDeclName()); - for (unsigned I = 0, N = Results.size(); I != N; ++I) { - if (ObjCPropertyDecl *PDecl = dyn_cast<ObjCPropertyDecl>(Results[I])) { - DiagnosePropertyMismatch(PDecl, SuperPDecl, - SDecl->getIdentifier()); - } - } - } -} - /// MatchOneProtocolPropertiesInClass - This routine goes thru the list /// of properties declared in a protocol and compares their attribute against /// the same property declared in the class or category. @@ -1340,7 +1323,7 @@ Sema::MatchOneProtocolPropertiesInClass(Decl *CDecl, ObjCProtocolDecl *PDecl) { E = PDecl->prop_end(); P != E; ++P) { ObjCPropertyDecl *ProtoProp = *P; DeclContext::lookup_result R - = IDecl->lookup(ProtoProp->getDeclName()); + = IDecl->lookup(ProtoProp->getDeclName()); for (unsigned I = 0, N = R.size(); I != N; ++I) { if (ObjCPropertyDecl *ClassProp = dyn_cast<ObjCPropertyDecl>(R[I])) { if (ClassProp != ProtoProp) { |