Factor CollectClassPropertyImplementations out of Sema into AST

This would make it possible for the analyzer to use the function.

llvm-svn: 166210
This commit is contained in:
Anna Zaks 2012-10-18 19:17:53 +00:00
parent e0586a574e
commit 673d76b0bc
3 changed files with 48 additions and 42 deletions

View File

@ -541,6 +541,12 @@ public:
ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
typedef llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> PropertyMap;
/// This routine collects list of properties to be implemented in the class.
/// This includes, class's and its conforming protocols' properties.
virtual void collectPropertiesToImplement(PropertyMap& PM) const {}
SourceLocation getAtStartLoc() const { return AtStart; }
void setAtStartLoc(SourceLocation Loc) { AtStart = Loc; }
@ -900,6 +906,8 @@ public:
ObjCPropertyDecl
*FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId) const;
virtual void collectPropertiesToImplement(PropertyMap& PM) const;
/// isSuperClassOf - Return true if this class is the specified class or is a
/// super class of the specified interface class.
bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
@ -1294,6 +1302,8 @@ public:
return getFirstDeclaration();
}
virtual void collectPropertiesToImplement(PropertyMap& PM) const;
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == ObjCProtocol; }

View File

@ -190,6 +190,18 @@ ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
return 0;
}
void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap& PM) const {
for (ObjCContainerDecl::prop_iterator P = prop_begin(),
E = prop_end(); P != E; ++P) {
ObjCPropertyDecl *Prop = *P;
PM[Prop->getIdentifier()] = Prop;
}
for (ObjCInterfaceDecl::all_protocol_iterator
PI = all_referenced_protocol_begin(),
E = all_referenced_protocol_end(); PI != E; ++PI)
(*PI)->collectPropertiesToImplement(PM);
}
void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
ASTContext &C)
@ -1313,6 +1325,20 @@ void ObjCProtocolDecl::startDefinition() {
RD->Data = this->Data;
}
void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap& PM) const {
for (ObjCProtocolDecl::prop_iterator P = prop_begin(),
E = prop_end(); P != E; ++P) {
ObjCPropertyDecl *Prop = *P;
// Insert into PM if not there already.
PM.insert(std::make_pair(Prop->getIdentifier(), Prop));
}
// Scan through protocol's protocols.
for (ObjCProtocolDecl::protocol_iterator PI = protocol_begin(),
E = protocol_end(); PI != E; ++PI)
(*PI)->collectPropertiesToImplement(PM);
}
//===----------------------------------------------------------------------===//
// ObjCCategoryDecl
//===----------------------------------------------------------------------===//

View File

@ -1435,8 +1435,8 @@ bool Sema::isPropertyReadonly(ObjCPropertyDecl *PDecl,
/// CollectImmediateProperties - This routine collects all properties in
/// the class and its conforming protocols; but not those it its super class.
void Sema::CollectImmediateProperties(ObjCContainerDecl *CDecl,
llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap,
llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap) {
ObjCContainerDecl::PropertyMap& PropMap,
ObjCContainerDecl::PropertyMap& SuperPropMap) {
if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
for (ObjCContainerDecl::prop_iterator P = IDecl->prop_begin(),
E = IDecl->prop_end(); P != E; ++P) {
@ -1482,44 +1482,14 @@ void Sema::CollectImmediateProperties(ObjCContainerDecl *CDecl,
}
}
/// CollectClassPropertyImplementations - This routine collects list of
/// properties to be implemented in the class. This includes, class's
/// and its conforming protocols' properties.
static void CollectClassPropertyImplementations(ObjCContainerDecl *CDecl,
llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap) {
if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
for (ObjCContainerDecl::prop_iterator P = IDecl->prop_begin(),
E = IDecl->prop_end(); P != E; ++P) {
ObjCPropertyDecl *Prop = *P;
PropMap[Prop->getIdentifier()] = Prop;
}
for (ObjCInterfaceDecl::all_protocol_iterator
PI = IDecl->all_referenced_protocol_begin(),
E = IDecl->all_referenced_protocol_end(); PI != E; ++PI)
CollectClassPropertyImplementations((*PI), PropMap);
}
else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(CDecl)) {
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
E = PDecl->prop_end(); P != E; ++P) {
ObjCPropertyDecl *Prop = *P;
// Insert into PropMap if not there already.
PropMap.insert(std::make_pair(Prop->getIdentifier(), Prop));
}
// scan through protocol's protocols.
for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
E = PDecl->protocol_end(); PI != E; ++PI)
CollectClassPropertyImplementations((*PI), PropMap);
}
}
/// CollectSuperClassPropertyImplementations - This routine collects list of
/// properties to be implemented in super class(s) and also coming from their
/// conforming protocols.
static void CollectSuperClassPropertyImplementations(ObjCInterfaceDecl *CDecl,
llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap) {
ObjCInterfaceDecl::PropertyMap& PropMap) {
if (ObjCInterfaceDecl *SDecl = CDecl->getSuperClass()) {
while (SDecl) {
CollectClassPropertyImplementations(SDecl, PropMap);
SDecl->collectPropertiesToImplement(PropMap);
SDecl = SDecl->getSuperClass();
}
}
@ -1530,20 +1500,20 @@ static void CollectSuperClassPropertyImplementations(ObjCInterfaceDecl *CDecl,
void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl,
ObjCInterfaceDecl *IDecl) {
llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> PropMap;
CollectClassPropertyImplementations(IDecl, PropMap);
ObjCInterfaceDecl::PropertyMap PropMap;
IDecl->collectPropertiesToImplement(PropMap);
if (PropMap.empty())
return;
llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> SuperPropMap;
ObjCInterfaceDecl::PropertyMap SuperPropMap;
CollectSuperClassPropertyImplementations(IDecl, SuperPropMap);
for (llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>::iterator
for (ObjCInterfaceDecl::PropertyMap::iterator
P = PropMap.begin(), E = PropMap.end(); P != E; ++P) {
ObjCPropertyDecl *Prop = P->second;
// If property to be implemented in the super class, ignore.
if (SuperPropMap[Prop->getIdentifier()])
continue;
// Is there a matching propery synthesize/dynamic?
// Is there a matching property synthesize/dynamic?
if (Prop->isInvalidDecl() ||
Prop->getPropertyImplementation() == ObjCPropertyDecl::Optional ||
IMPDecl->FindPropertyImplIvarDecl(Prop->getIdentifier()))
@ -1596,11 +1566,11 @@ void Sema::DefaultSynthesizeProperties(Scope *S, Decl *D) {
void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
ObjCContainerDecl *CDecl,
const SelectorSet &InsMap) {
llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> SuperPropMap;
ObjCContainerDecl::PropertyMap SuperPropMap;
if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl))
CollectSuperClassPropertyImplementations(IDecl, SuperPropMap);
llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> PropMap;
ObjCContainerDecl::PropertyMap PropMap;
CollectImmediateProperties(CDecl, PropMap, SuperPropMap);
if (PropMap.empty())
return;
@ -1611,7 +1581,7 @@ void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
EI = IMPDecl->propimpl_end(); I != EI; ++I)
PropImplMap.insert(I->getPropertyDecl());
for (llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>::iterator
for (ObjCContainerDecl::PropertyMap::iterator
P = PropMap.begin(), E = PropMap.end(); P != E; ++P) {
ObjCPropertyDecl *Prop = P->second;
// Is there a matching propery synthesize/dynamic?