forked from OSchip/llvm-project
Cleanup/Refactoring of ivar collection. No change in functionality.
llvm-svn: 72827
This commit is contained in:
parent
7f5976e11b
commit
7c80959a97
|
@ -539,11 +539,16 @@ public:
|
||||||
|
|
||||||
void CollectObjCIvars(const ObjCInterfaceDecl *OI,
|
void CollectObjCIvars(const ObjCInterfaceDecl *OI,
|
||||||
llvm::SmallVectorImpl<FieldDecl*> &Fields);
|
llvm::SmallVectorImpl<FieldDecl*> &Fields);
|
||||||
|
|
||||||
|
void ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI,
|
||||||
|
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars,
|
||||||
|
bool CollectSynthesized = true);
|
||||||
void CollectSynthesizedIvars(const ObjCInterfaceDecl *OI,
|
void CollectSynthesizedIvars(const ObjCInterfaceDecl *OI,
|
||||||
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
|
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
|
||||||
void CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
|
void CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
|
||||||
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
|
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
|
||||||
|
unsigned CountSynthesizedIvars(const ObjCInterfaceDecl *OI);
|
||||||
|
unsigned CountProtocolSynthesizedIvars(const ObjCProtocolDecl *PD);
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// Type Operators
|
// Type Operators
|
||||||
|
|
|
@ -613,6 +613,20 @@ void ASTContext::CollectObjCIvars(const ObjCInterfaceDecl *OI,
|
||||||
CollectLocalObjCIvars(this, OI, Fields);
|
CollectLocalObjCIvars(this, OI, Fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ShallowCollectObjCIvars -
|
||||||
|
/// Collect all ivars, including those synthesized, in the current class.
|
||||||
|
///
|
||||||
|
void ASTContext::ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI,
|
||||||
|
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars,
|
||||||
|
bool CollectSynthesized) {
|
||||||
|
for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
|
||||||
|
E = OI->ivar_end(); I != E; ++I) {
|
||||||
|
Ivars.push_back(*I);
|
||||||
|
}
|
||||||
|
if (CollectSynthesized)
|
||||||
|
CollectSynthesizedIvars(OI, Ivars);
|
||||||
|
}
|
||||||
|
|
||||||
void ASTContext::CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
|
void ASTContext::CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
|
||||||
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) {
|
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) {
|
||||||
for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(*this),
|
for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(*this),
|
||||||
|
@ -645,6 +659,38 @@ void ASTContext::CollectSynthesizedIvars(const ObjCInterfaceDecl *OI,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned ASTContext::CountProtocolSynthesizedIvars(const ObjCProtocolDecl *PD) {
|
||||||
|
unsigned count = 0;
|
||||||
|
for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(*this),
|
||||||
|
E = PD->prop_end(*this); I != E; ++I)
|
||||||
|
if ((*I)->getPropertyIvarDecl())
|
||||||
|
++count;
|
||||||
|
|
||||||
|
// Also look into nested protocols.
|
||||||
|
for (ObjCProtocolDecl::protocol_iterator P = PD->protocol_begin(),
|
||||||
|
E = PD->protocol_end(); P != E; ++P)
|
||||||
|
count += CountProtocolSynthesizedIvars(*P);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned ASTContext::CountSynthesizedIvars(const ObjCInterfaceDecl *OI)
|
||||||
|
{
|
||||||
|
unsigned count = 0;
|
||||||
|
for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(*this),
|
||||||
|
E = OI->prop_end(*this); I != E; ++I) {
|
||||||
|
if ((*I)->getPropertyIvarDecl())
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
// Also look into interface's protocol list for properties declared
|
||||||
|
// in the protocol and whose ivars are synthesized.
|
||||||
|
for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(),
|
||||||
|
PE = OI->protocol_end(); P != PE; ++P) {
|
||||||
|
ObjCProtocolDecl *PD = (*P);
|
||||||
|
count += CountProtocolSynthesizedIvars(PD);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
/// getInterfaceLayoutImpl - Get or compute information about the
|
/// getInterfaceLayoutImpl - Get or compute information about the
|
||||||
/// layout of the given interface.
|
/// layout of the given interface.
|
||||||
///
|
///
|
||||||
|
@ -664,14 +710,13 @@ ASTContext::getObjCLayout(const ObjCInterfaceDecl *D,
|
||||||
unsigned FieldCount = D->ivar_size();
|
unsigned FieldCount = D->ivar_size();
|
||||||
// Add in synthesized ivar count if laying out an implementation.
|
// Add in synthesized ivar count if laying out an implementation.
|
||||||
if (Impl) {
|
if (Impl) {
|
||||||
llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
|
unsigned SynthCount = CountSynthesizedIvars(D);
|
||||||
CollectSynthesizedIvars(D, Ivars);
|
FieldCount += SynthCount;
|
||||||
FieldCount += Ivars.size();
|
|
||||||
// If there aren't any sythesized ivars then reuse the interface
|
// If there aren't any sythesized ivars then reuse the interface
|
||||||
// entry. Note we can't cache this because we simply free all
|
// entry. Note we can't cache this because we simply free all
|
||||||
// entries later; however we shouldn't look up implementations
|
// entries later; however we shouldn't look up implementations
|
||||||
// frequently.
|
// frequently.
|
||||||
if (FieldCount == D->ivar_size())
|
if (SynthCount == 0)
|
||||||
return getObjCLayout(D, 0);
|
return getObjCLayout(D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,20 +746,11 @@ ASTContext::getObjCLayout(const ObjCInterfaceDecl *D,
|
||||||
|
|
||||||
// Layout each ivar sequentially.
|
// Layout each ivar sequentially.
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
for (ObjCInterfaceDecl::ivar_iterator IVI = D->ivar_begin(),
|
llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
|
||||||
IVE = D->ivar_end(); IVI != IVE; ++IVI) {
|
ShallowCollectObjCIvars(D, Ivars, Impl);
|
||||||
const ObjCIvarDecl* Ivar = (*IVI);
|
for (unsigned k = 0, e = Ivars.size(); k != e; ++k)
|
||||||
NewEntry->LayoutField(Ivar, i++, false, StructPacking, *this);
|
NewEntry->LayoutField(Ivars[k], i++, false, StructPacking, *this);
|
||||||
}
|
|
||||||
// And synthesized ivars, if this is an implementation.
|
|
||||||
if (Impl) {
|
|
||||||
// FIXME. Do we need to colltect twice?
|
|
||||||
llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
|
|
||||||
CollectSynthesizedIvars(D, Ivars);
|
|
||||||
for (unsigned k = 0, e = Ivars.size(); k != e; ++k)
|
|
||||||
NewEntry->LayoutField(Ivars[k], i++, false, StructPacking, *this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, round the size of the total struct up to the alignment of the
|
// Finally, round the size of the total struct up to the alignment of the
|
||||||
// struct itself.
|
// struct itself.
|
||||||
NewEntry->FinalizeLayout();
|
NewEntry->FinalizeLayout();
|
||||||
|
|
|
@ -1544,14 +1544,8 @@ LValue CGObjCGNU::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
|
||||||
static const ObjCInterfaceDecl *FindIvarInterface(ASTContext &Context,
|
static const ObjCInterfaceDecl *FindIvarInterface(ASTContext &Context,
|
||||||
const ObjCInterfaceDecl *OID,
|
const ObjCInterfaceDecl *OID,
|
||||||
const ObjCIvarDecl *OIVD) {
|
const ObjCIvarDecl *OIVD) {
|
||||||
for (ObjCInterfaceDecl::ivar_iterator IVI = OID->ivar_begin(),
|
|
||||||
IVE = OID->ivar_end(); IVI != IVE; ++IVI)
|
|
||||||
if (OIVD == *IVI)
|
|
||||||
return OID;
|
|
||||||
|
|
||||||
// Also look in synthesized ivars.
|
|
||||||
llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
|
llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
|
||||||
Context.CollectSynthesizedIvars(OID, Ivars);
|
Context.ShallowCollectObjCIvars(OID, Ivars);
|
||||||
for (unsigned k = 0, e = Ivars.size(); k != e; ++k) {
|
for (unsigned k = 0, e = Ivars.size(); k != e; ++k) {
|
||||||
if (OIVD == Ivars[k])
|
if (OIVD == Ivars[k])
|
||||||
return OID;
|
return OID;
|
||||||
|
|
|
@ -47,14 +47,8 @@ static const ObjCInterfaceDecl *FindIvarInterface(ASTContext &Context,
|
||||||
// ASTContext::getObjCLayout is implemented. This should be fixed to
|
// ASTContext::getObjCLayout is implemented. This should be fixed to
|
||||||
// get the information from the layout directly.
|
// get the information from the layout directly.
|
||||||
Index = 0;
|
Index = 0;
|
||||||
for (ObjCInterfaceDecl::ivar_iterator IVI = OID->ivar_begin(),
|
|
||||||
IVE = OID->ivar_end(); IVI != IVE; ++IVI, ++Index)
|
|
||||||
if (OIVD == *IVI)
|
|
||||||
return OID;
|
|
||||||
|
|
||||||
// Also look in synthesized ivars.
|
|
||||||
llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
|
llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
|
||||||
Context.CollectSynthesizedIvars(OID, Ivars);
|
Context.ShallowCollectObjCIvars(OID, Ivars);
|
||||||
for (unsigned k = 0, e = Ivars.size(); k != e; ++k) {
|
for (unsigned k = 0, e = Ivars.size(); k != e; ++k) {
|
||||||
if (OIVD == Ivars[k])
|
if (OIVD == Ivars[k])
|
||||||
return OID;
|
return OID;
|
||||||
|
@ -908,15 +902,6 @@ protected:
|
||||||
unsigned Align,
|
unsigned Align,
|
||||||
bool AddToUsed);
|
bool AddToUsed);
|
||||||
|
|
||||||
/// GetNamedIvarList - Return the list of ivars in the interface
|
|
||||||
/// itself (not including super classes and not including unnamed
|
|
||||||
/// bitfields).
|
|
||||||
///
|
|
||||||
/// For the non-fragile ABI, this also includes synthesized property
|
|
||||||
/// ivars.
|
|
||||||
void GetNamedIvarList(const ObjCInterfaceDecl *OID,
|
|
||||||
llvm::SmallVector<ObjCIvarDecl*, 16> &Res) const;
|
|
||||||
|
|
||||||
CodeGen::RValue EmitLegacyMessageSend(CodeGen::CodeGenFunction &CGF,
|
CodeGen::RValue EmitLegacyMessageSend(CodeGen::CodeGenFunction &CGF,
|
||||||
QualType ResultType,
|
QualType ResultType,
|
||||||
llvm::Value *Sel,
|
llvm::Value *Sel,
|
||||||
|
@ -2198,10 +2183,13 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID,
|
||||||
const_cast<ObjCInterfaceDecl*>(ID->getClassInterface());
|
const_cast<ObjCInterfaceDecl*>(ID->getClassInterface());
|
||||||
|
|
||||||
llvm::SmallVector<ObjCIvarDecl*, 16> OIvars;
|
llvm::SmallVector<ObjCIvarDecl*, 16> OIvars;
|
||||||
GetNamedIvarList(OID, OIvars);
|
CGM.getContext().ShallowCollectObjCIvars(OID, OIvars);
|
||||||
|
|
||||||
for (unsigned i = 0, e = OIvars.size(); i != e; ++i) {
|
for (unsigned i = 0, e = OIvars.size(); i != e; ++i) {
|
||||||
ObjCIvarDecl *IVD = OIvars[i];
|
ObjCIvarDecl *IVD = OIvars[i];
|
||||||
|
// Ignore unnamed bit-fields.
|
||||||
|
if (!IVD->getDeclName())
|
||||||
|
continue;
|
||||||
Ivar[0] = GetMethodVarName(IVD->getIdentifier());
|
Ivar[0] = GetMethodVarName(IVD->getIdentifier());
|
||||||
Ivar[1] = GetMethodVarType(IVD);
|
Ivar[1] = GetMethodVarType(IVD);
|
||||||
Ivar[2] = llvm::ConstantInt::get(ObjCTypes.IntTy,
|
Ivar[2] = llvm::ConstantInt::get(ObjCTypes.IntTy,
|
||||||
|
@ -4696,25 +4684,6 @@ llvm::Constant * CGObjCNonFragileABIMac::EmitIvarOffsetVar(
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
|
|
||||||
void CGObjCCommonMac::GetNamedIvarList(const ObjCInterfaceDecl *OID,
|
|
||||||
llvm::SmallVector<ObjCIvarDecl*, 16> &Res) const {
|
|
||||||
for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
|
|
||||||
E = OID->ivar_end(); I != E; ++I) {
|
|
||||||
// Ignore unnamed bit-fields.
|
|
||||||
if (!(*I)->getDeclName())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Res.push_back(*I);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also save synthesize ivars.
|
|
||||||
// FIXME. Why can't we just use passed in Res small vector?
|
|
||||||
llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
|
|
||||||
CGM.getContext().CollectSynthesizedIvars(OID, Ivars);
|
|
||||||
for (unsigned k = 0, e = Ivars.size(); k != e; ++k)
|
|
||||||
Res.push_back(Ivars[k]);
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList(
|
llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList(
|
||||||
const ObjCImplementationDecl *ID) {
|
const ObjCImplementationDecl *ID) {
|
||||||
|
|
||||||
|
@ -4727,10 +4696,13 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList(
|
||||||
|
|
||||||
// Collect declared and synthesized ivars in a small vector.
|
// Collect declared and synthesized ivars in a small vector.
|
||||||
llvm::SmallVector<ObjCIvarDecl*, 16> OIvars;
|
llvm::SmallVector<ObjCIvarDecl*, 16> OIvars;
|
||||||
GetNamedIvarList(OID, OIvars);
|
CGM.getContext().ShallowCollectObjCIvars(OID, OIvars);
|
||||||
|
|
||||||
for (unsigned i = 0, e = OIvars.size(); i != e; ++i) {
|
for (unsigned i = 0, e = OIvars.size(); i != e; ++i) {
|
||||||
ObjCIvarDecl *IVD = OIvars[i];
|
ObjCIvarDecl *IVD = OIvars[i];
|
||||||
|
// Ignore unnamed bit-fields.
|
||||||
|
if (!IVD->getDeclName())
|
||||||
|
continue;
|
||||||
Ivar[0] = EmitIvarOffsetVar(ID->getClassInterface(), IVD,
|
Ivar[0] = EmitIvarOffsetVar(ID->getClassInterface(), IVD,
|
||||||
ComputeIvarBaseOffset(CGM, ID, IVD));
|
ComputeIvarBaseOffset(CGM, ID, IVD));
|
||||||
Ivar[1] = GetMethodVarName(IVD->getIdentifier());
|
Ivar[1] = GetMethodVarName(IVD->getIdentifier());
|
||||||
|
|
Loading…
Reference in New Issue