aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ASTContext.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2008-12-17 21:40:49 +0000
committerFariborz Jahanian <fjahanian@apple.com>2008-12-17 21:40:49 +0000
commita769c004a2874504c17ea8afccbc4ad35fc33c9f (patch)
tree8b99e51cf54df41037797a650475ecd17322fa53 /lib/AST/ASTContext.cpp
parentb60d7999d621fce608e03d39e82c0e7eda750054 (diff)
This patch will build the Records lazily per Steve's comments.
Note that one test duplicate-ivar-check.m will fail because I need to re-implement duplicate ivar checking. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61154 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ASTContext.cpp')
-rw-r--r--lib/AST/ASTContext.cpp40
1 files changed, 40 insertions, 0 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