diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2008-12-17 21:40:49 +0000 | 
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2008-12-17 21:40:49 +0000 | 
| commit | f327e89dabc34946f0086961b30813d4e25d22a5 (patch) | |
| tree | 496f31158d1abae748194fc51ab809a842342c82 /clang/lib/AST/ASTContext.cpp | |
| parent | 3d1f552643159f6b9514d21e96b6de23bd3bbd70 (diff) | |
| download | bcm5719-llvm-f327e89dabc34946f0086961b30813d4e25d22a5.tar.gz bcm5719-llvm-f327e89dabc34946f0086961b30813d4e25d22a5.zip | |
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.
llvm-svn: 61154
Diffstat (limited to 'clang/lib/AST/ASTContext.cpp')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 40 | 
1 files changed, 40 insertions, 0 deletions
| diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 9f8db595b75..4983d217c3e 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/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 | 

