aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/ASTContext.cpp40
-rw-r--r--lib/AST/DeclObjC.cpp45
-rw-r--r--lib/CodeGen/CodeGenTypes.cpp8
-rw-r--r--lib/Sema/SemaDecl.cpp3
-rw-r--r--lib/Sema/SemaDeclObjC.cpp1
5 files changed, 46 insertions, 51 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 9f8db595b7..4983d217c3 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -472,6 +472,46 @@ void ASTRecordLayout::LayoutField(const FieldDecl *FD, unsigned FieldNo,
Alignment = std::max(Alignment, FieldAlign);
}
+static void CollectObjCIvars(const ObjCInterfaceDecl *OI,
+ std::vector<FieldDecl*> &Fields) {
+ const ObjCInterfaceDecl *SuperClass = OI->getSuperClass();
+ if (SuperClass)
+ CollectObjCIvars(SuperClass, Fields);
+ for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
+ E = OI->ivar_end(); I != E; ++I) {
+ ObjCIvarDecl *IVDecl = (*I);
+ if (!IVDecl->isInvalidDecl())
+ Fields.push_back(cast<FieldDecl>(IVDecl));
+ }
+}
+
+/// addRecordToClass - produces record info. for the class for its
+/// ivars and all those inherited.
+///
+const RecordDecl *ASTContext::addRecordToClass(const ObjCInterfaceDecl *D)
+{
+ const RecordDecl *&RD = ASTRecordForInterface[D];
+ if (RD)
+ return RD;
+ std::vector<FieldDecl*> RecFields;
+ CollectObjCIvars(D, RecFields);
+ RecordDecl *NewRD = RecordDecl::Create(*this, TagDecl::TK_struct, 0,
+ D->getLocation(),
+ D->getIdentifier());
+ /// FIXME! Can do collection of ivars and adding to the record while
+ /// doing it.
+ for (unsigned int i = 0; i != RecFields.size(); i++) {
+ FieldDecl *Field = FieldDecl::Create(*this, NewRD,
+ RecFields[i]->getLocation(),
+ RecFields[i]->getIdentifier(),
+ RecFields[i]->getType(),
+ RecFields[i]->getBitWidth(), false, 0);
+ NewRD->addDecl(*this, Field);
+ }
+ NewRD->completeDefinition(*this);
+ RD = NewRD;
+ return RD;
+}
/// getASTObjcInterfaceLayout - Get or compute information about the layout of
/// the specified Objective C, which indicates its size and ivar
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index a7e878fc24..ec8a1ff044 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -338,18 +338,6 @@ ObjCIvarDecl *
return 0;
}
-void ObjCInterfaceDecl::CollectObjCIvars(std::vector<FieldDecl*> &Fields) {
- ObjCInterfaceDecl *SuperClass = getSuperClass();
- if (SuperClass)
- SuperClass->CollectObjCIvars(Fields);
- for (ObjCInterfaceDecl::ivar_iterator I = ivar_begin(),
- E = ivar_end(); I != E; ++I) {
- ObjCIvarDecl *IVDecl = (*I);
- if (!IVDecl->isInvalidDecl())
- Fields.push_back(cast<FieldDecl>(IVDecl));
- }
-}
-
/// ObjCAddInstanceVariablesToClass - Inserts instance variables
/// into ObjCInterfaceDecl's fields.
///
@@ -369,44 +357,17 @@ void ObjCInterfaceDecl::addInstanceVariablesToClass(ObjCIvarDecl **ivars,
///
FieldDecl *ObjCInterfaceDecl::lookupFieldDeclForIvar(ASTContext &Context,
const ObjCIvarDecl *ivar) {
- /* When a super class's ivar is referenced in the subclass method with no ivar
- of its own, record for the sub-class is not built yet. Build it lazily
- here. */
- if (!RecordForDecl)
- addRecordToClass(Context);
+ const RecordDecl *RecordForDecl = Context.addRecordToClass(this);
assert(RecordForDecl && "lookupFieldDeclForIvar no storage for class");
DeclarationName Member = ivar->getDeclName();
- DeclContext::lookup_result Lookup = RecordForDecl->lookup(Context, Member);
+ DeclContext::lookup_result Lookup = (const_cast< RecordDecl *>(RecordForDecl))
+ ->lookup(Context, Member);
assert((Lookup.first != Lookup.second) && "field decl not found");
FieldDecl *MemberDecl = dyn_cast<FieldDecl>(*Lookup.first);
assert(MemberDecl && "field decl not found");
return MemberDecl;
}
-/// addRecordToClass - produces record info. for the class for its
-/// ivars and all those inherited.
-///
-void ObjCInterfaceDecl::addRecordToClass(ASTContext &Context)
-{
- std::vector<FieldDecl*> RecFields;
- CollectObjCIvars(RecFields);
- RecordDecl *RD = RecordDecl::Create(Context, TagDecl::TK_struct, 0,
- getLocation(),
- getIdentifier());
- /// FIXME! Can do collection of ivars and adding to the record while
- /// doing it.
- for (unsigned int i = 0; i != RecFields.size(); i++) {
- FieldDecl *Field = FieldDecl::Create(Context, RD,
- RecFields[i]->getLocation(),
- RecFields[i]->getIdentifier(),
- RecFields[i]->getType(),
- RecFields[i]->getBitWidth(), false, 0);
- RD->addDecl(Context, Field);
- }
- RD->completeDefinition(Context);
- RecordForDecl = RD;
-}
-
/// ObjCAddInstanceVariablesToClassImpl - Checks for correctness of Instance
/// Variables (Ivars) relative to what declared in @implementation;s class.
/// Ivars into ObjCImplementationDecl's fields.
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp
index 10b1e15ae3..e8a38a286b 100644
--- a/lib/CodeGen/CodeGenTypes.cpp
+++ b/lib/CodeGen/CodeGenTypes.cpp
@@ -273,13 +273,7 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
// We are issuing warnings elsewhere!
ObjCInterfaceType OIT = cast<ObjCInterfaceType>(Ty);
ObjCInterfaceDecl *ID = OIT.getDecl();
- RecordDecl *RD = ID->getRecordForDecl();
- if(!RD) {
- // Sometimes, class type is being directly generated in code gen for
- // built-in class types.
- ID->addRecordToClass(Context);
- RD = ID->getRecordForDecl();
- }
+ const RecordDecl *RD = Context.addRecordToClass(ID);
return ConvertTagDeclType(cast<TagDecl>(RD));
}
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 6ef9ecd817..5ae266ef00 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3029,7 +3029,7 @@ void Sema::ActOnFields(Scope* S,
ObjCIvarDecl **ClsFields = reinterpret_cast<ObjCIvarDecl**>(&RecFields[0]);
if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(EnclosingDecl)) {
ID->addInstanceVariablesToClass(ClsFields, RecFields.size(), RBrac);
- ID->addRecordToClass(Context);
+#if 0
// Must enforce the rule that ivars in the base classes may not be
// duplicates.
FieldIDs.clear();
@@ -3049,6 +3049,7 @@ void Sema::ActOnFields(Scope* S,
}
}
}
+#endif
}
else if (ObjCImplementationDecl *IMPDecl =
dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 5887f29d4f..d4cef9b0de 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -599,7 +599,6 @@ void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
/// Add implementations's ivar to the synthesize class's ivar list.
if (IDecl->ImplicitInterfaceDecl()) {
IDecl->addInstanceVariablesToClass(ivars, numIvars, RBrace);
- IDecl->addRecordToClass(Context);
return;
}
// If implementation has empty ivar list, just return.