From 10eabf41b2bf7dba40a6c0af428007cea9f15ee1 Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Thu, 28 Jan 2016 23:36:05 +0000 Subject: [PATCH] Class Property: change PropertyMap to include isClassProperty. PropertyMap used to map IdentifierInfo (name of the property) to ObjcPropertyDecl *. Now that a class property can have the same name as an instance property, we change PropertyMap to map a pair to ObjcPropertyDecl *. Also update a few places from iterating over instance_properties to iterating over all properties. rdar://23891898 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259119 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclObjC.h | 4 +- lib/AST/DeclObjC.cpp | 14 +++--- lib/Sema/SemaObjCProperty.cpp | 45 ++++++++++++------- .../Checkers/IvarInvalidationChecker.cpp | 2 + 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index def08daf7f..f89717f698 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -1023,7 +1023,9 @@ public: FindPropertyDeclaration(const IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const; - typedef llvm::DenseMap PropertyMap; + typedef llvm::DenseMap, + ObjCPropertyDecl*> PropertyMap; typedef llvm::DenseMap ProtocolPropertyMap; diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 230c2cfd50..1480a55d56 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -369,14 +369,14 @@ ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap &PM, PropertyDeclOrder &PO) const { - for (auto *Prop : instance_properties()) { - PM[Prop->getIdentifier()] = Prop; + for (auto *Prop : properties()) { + PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop; PO.push_back(Prop); } for (const auto *Ext : known_extensions()) { const ObjCCategoryDecl *ClassExt = Ext; - for (auto *Prop : ClassExt->instance_properties()) { - PM[Prop->getIdentifier()] = Prop; + for (auto *Prop : ClassExt->properties()) { + PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop; PO.push_back(Prop); } } @@ -1848,9 +1848,11 @@ void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM, PropertyDeclOrder &PO) const { if (const ObjCProtocolDecl *PDecl = getDefinition()) { - for (auto *Prop : PDecl->instance_properties()) { + for (auto *Prop : PDecl->properties()) { // Insert into PM if not there already. - PM.insert(std::make_pair(Prop->getIdentifier(), Prop)); + PM.insert(std::make_pair( + std::make_pair(Prop->getIdentifier(), Prop->isClassProperty()), + Prop)); PO.push_back(Prop); } // Scan through protocol's protocols. diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index 35f79b2a3e..ec057c9437 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -1534,8 +1534,9 @@ static void CollectImmediateProperties(ObjCContainerDecl *CDecl, bool IncludeProtocols = true) { if (ObjCInterfaceDecl *IDecl = dyn_cast(CDecl)) { - for (auto *Prop : IDecl->instance_properties()) - PropMap[Prop->getIdentifier()] = Prop; + for (auto *Prop : IDecl->properties()) + PropMap[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = + Prop; // Collect the properties from visible extensions. for (auto *Ext : IDecl->visible_extensions()) @@ -1548,8 +1549,9 @@ static void CollectImmediateProperties(ObjCContainerDecl *CDecl, } } if (ObjCCategoryDecl *CATDecl = dyn_cast(CDecl)) { - for (auto *Prop : CATDecl->instance_properties()) - PropMap[Prop->getIdentifier()] = Prop; + for (auto *Prop : CATDecl->properties()) + PropMap[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = + Prop; if (IncludeProtocols) { // Scan through class's protocols. for (auto *PI : CATDecl->protocols()) @@ -1557,13 +1559,17 @@ static void CollectImmediateProperties(ObjCContainerDecl *CDecl, } } else if (ObjCProtocolDecl *PDecl = dyn_cast(CDecl)) { - for (auto *Prop : PDecl->instance_properties()) { - ObjCPropertyDecl *PropertyFromSuper = SuperPropMap[Prop->getIdentifier()]; + for (auto *Prop : PDecl->properties()) { + ObjCPropertyDecl *PropertyFromSuper = + SuperPropMap[std::make_pair(Prop->getIdentifier(), + Prop->isClassProperty())]; // Exclude property for protocols which conform to class's super-class, // as super-class has to implement the property. if (!PropertyFromSuper || PropertyFromSuper->getIdentifier() != Prop->getIdentifier()) { - ObjCPropertyDecl *&PropEntry = PropMap[Prop->getIdentifier()]; + ObjCPropertyDecl *&PropEntry = + PropMap[std::make_pair(Prop->getIdentifier(), + Prop->isClassProperty())]; if (!PropEntry) PropEntry = Prop; } @@ -1658,6 +1664,7 @@ void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl, ObjCPropertyDecl *Prop = PropertyOrder[i]; // Is there a matching property synthesize/dynamic? if (Prop->isInvalidDecl() || + Prop->isClassProperty() || Prop->getPropertyImplementation() == ObjCPropertyDecl::Optional) continue; // Property may have been synthesized by user. @@ -1678,7 +1685,9 @@ void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl, Diag(PID->getLocation(), diag::note_property_synthesize); continue; } - ObjCPropertyDecl *PropInSuperClass = SuperPropMap[Prop->getIdentifier()]; + ObjCPropertyDecl *PropInSuperClass = + SuperPropMap[std::make_pair(Prop->getIdentifier(), + Prop->isClassProperty())]; if (ObjCProtocolDecl *Proto = dyn_cast(Prop->getDeclContext())) { // We won't auto-synthesize properties declared in protocols. @@ -1821,10 +1830,12 @@ void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, } // Add the properties of 'PDecl' to the list of properties that // need to be implemented. - for (auto *PropDecl : PDecl->instance_properties()) { - if ((*LazyMap)[PropDecl->getIdentifier()]) + for (auto *PropDecl : PDecl->properties()) { + if ((*LazyMap)[std::make_pair(PropDecl->getIdentifier(), + PropDecl->isClassProperty())]) continue; - PropMap[PropDecl->getIdentifier()] = PropDecl; + PropMap[std::make_pair(PropDecl->getIdentifier(), + PropDecl->isClassProperty())] = PropDecl; } } } @@ -1838,7 +1849,7 @@ void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, SelectorSet InsMap; // Collect property accessors implemented in current implementation. - for (const auto *I : IMPDecl->instance_methods()) + for (const auto *I : IMPDecl->methods()) InsMap.insert(I->getSelector()); ObjCCategoryDecl *C = dyn_cast(CDecl); @@ -1850,7 +1861,7 @@ void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, // When reporting on missing setter/getters, do not report when // setter/getter is implemented in category's primary class // implementation. - for (const auto *I : IMP->instance_methods()) + for (const auto *I : IMP->methods()) InsMap.insert(I->getSelector()); } @@ -1908,11 +1919,11 @@ Sema::AtomicPropertySetterGetterRules (ObjCImplDecl* IMPDecl, if (getLangOpts().getGC() != LangOptions::NonGC) return; ObjCContainerDecl::PropertyMap PM; - for (auto *Prop : IDecl->instance_properties()) - PM[Prop->getIdentifier()] = Prop; + for (auto *Prop : IDecl->properties()) + PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop; for (const auto *Ext : IDecl->known_extensions()) - for (auto *Prop : Ext->instance_properties()) - PM[Prop->getIdentifier()] = Prop; + for (auto *Prop : Ext->properties()) + PM[std::make_pair(Prop->getIdentifier(), Prop->isClassProperty())] = Prop; for (ObjCContainerDecl::PropertyMap::iterator I = PM.begin(), E = PM.end(); I != E; ++I) { diff --git a/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp b/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp index dffff38c91..153c05bbef 100644 --- a/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp @@ -390,6 +390,8 @@ visit(const ObjCImplementationDecl *ImplD) const { for (ObjCInterfaceDecl::PropertyMap::iterator I = PropMap.begin(), E = PropMap.end(); I != E; ++I) { const ObjCPropertyDecl *PD = I->second; + if (PD->isClassProperty()) + continue; const ObjCIvarDecl *ID = findPropertyBackingIvar(PD, InterfaceD, Ivars, &FirstIvarDecl); -- 2.50.1