aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-23 03:23:08 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-23 03:23:08 +0000
commit8f36aba016c2d236a90f9ecf0a66904209202202 (patch)
tree5bf42b6f3bc3025e22d50be590aeb8f1f4f46c33
parent10b0e1fa3aabd8877dbbc0df1f2414e04afd5fdd (diff)
The ivars in an ObjCImplementationDecl are now stored in the
DeclContext rather than in a separate list. This makes PCH (de-)serialization trivial, so that ivars can be loaded lazily. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69857 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/DeclObjC.h28
-rw-r--r--lib/AST/DeclObjC.cpp6
-rw-r--r--lib/Frontend/PCHReader.cpp5
-rw-r--r--lib/Frontend/PCHWriter.cpp2
-rw-r--r--lib/Sema/SemaDecl.cpp7
-rw-r--r--tools/clang-cc/RewriteObjC.cpp16
6 files changed, 34 insertions, 30 deletions
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h
index 0e1de5e8aa..1672aaa51f 100644
--- a/include/clang/AST/DeclObjC.h
+++ b/include/clang/AST/DeclObjC.h
@@ -946,9 +946,6 @@ class ObjCImplementationDecl : public ObjCImplDecl {
/// Implementation Class's super class.
ObjCInterfaceDecl *SuperClass;
- /// Instance variables declared in the @implementation.
- ObjCList<ObjCIvarDecl> IVars;
-
ObjCImplementationDecl(DeclContext *DC, SourceLocation L,
ObjCInterfaceDecl *classInterface,
ObjCInterfaceDecl *superDecl)
@@ -960,13 +957,6 @@ public:
ObjCInterfaceDecl *classInterface,
ObjCInterfaceDecl *superDecl);
- /// Destroy - Call destructors and release memory.
- virtual void Destroy(ASTContext& C);
-
- void setIVarList(ObjCIvarDecl *const *InArray, unsigned Num, ASTContext &C) {
- IVars.set(InArray, Num, C);
- }
-
/// getIdentifier - Get the identifier that names the class
/// interface associated with this implementation.
IdentifierInfo *getIdentifier() const {
@@ -991,11 +981,19 @@ public:
void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
- typedef ObjCList<ObjCIvarDecl>::iterator ivar_iterator;
- ivar_iterator ivar_begin() const { return IVars.begin(); }
- ivar_iterator ivar_end() const { return IVars.end(); }
- unsigned ivar_size() const { return IVars.size(); }
- bool ivar_empty() const { return IVars.empty(); }
+ typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
+ ivar_iterator ivar_begin(ASTContext &Context) const {
+ return ivar_iterator(decls_begin(Context));
+ }
+ ivar_iterator ivar_end(ASTContext &Context) const {
+ return ivar_iterator(decls_end(Context));
+ }
+ unsigned ivar_size(ASTContext &Context) const {
+ return std::distance(ivar_begin(Context), ivar_end(Context));
+ }
+ bool ivar_empty(ASTContext &Context) const {
+ return ivar_begin(Context) == ivar_end(Context);
+ }
static bool classof(const Decl *D) {
return D->getKind() == ObjCImplementation;
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index 49ff6d53c0..bcd2e08f6d 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -637,12 +637,6 @@ ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl);
}
-/// Destroy - Call destructors and release memory.
-void ObjCImplementationDecl::Destroy(ASTContext &C) {
- IVars.Destroy(C);
- Decl::Destroy(C);
-}
-
//===----------------------------------------------------------------------===//
// ObjCCompatibleAliasDecl
//===----------------------------------------------------------------------===//
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index 0ad93dc65c..481f14855c 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -334,7 +334,8 @@ void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
VisitObjCImplDecl(D);
- // FIXME: Implement.
+ D->setSuperClass(
+ cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
}
@@ -2270,7 +2271,7 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
}
case pch::DECL_OBJC_IMPLEMENTATION: {
- // FIXME: Implement.
+ D = ObjCImplementationDecl::Create(Context, 0, SourceLocation(), 0, 0);
break;
}
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 0a0a38d874..6961eb6a13 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -506,7 +506,7 @@ void PCHDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
void PCHDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
VisitObjCImplDecl(D);
- // FIXME: Implement.
+ Writer.AddDeclRef(D->getSuperClass(), Record);
Code = pch::DECL_OBJC_IMPLEMENTATION;
}
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 040c5467ac..c7a45dc9d7 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3952,7 +3952,12 @@ void Sema::ActOnFields(Scope* S,
} else if (ObjCImplementationDecl *IMPDecl =
dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
assert(IMPDecl && "ActOnFields - missing ObjCImplementationDecl");
- IMPDecl->setIVarList(ClsFields, RecFields.size(), Context);
+ for (unsigned I = 0, N = RecFields.size(); I != N; ++I) {
+ // FIXME: Set the DeclContext correctly when we build the
+ // declarations.
+ ClsFields[I]->setLexicalDeclContext(IMPDecl);
+ IMPDecl->addDecl(Context, ClsFields[I]);
+ }
CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);
}
}
diff --git a/tools/clang-cc/RewriteObjC.cpp b/tools/clang-cc/RewriteObjC.cpp
index f31e5ccf5f..5b8fd5268c 100644
--- a/tools/clang-cc/RewriteObjC.cpp
+++ b/tools/clang-cc/RewriteObjC.cpp
@@ -3185,8 +3185,8 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
}
// Build _objc_ivar_list metadata for classes ivars if needed
- unsigned NumIvars = !IDecl->ivar_empty()
- ? IDecl->ivar_size()
+ unsigned NumIvars = !IDecl->ivar_empty(*Context)
+ ? IDecl->ivar_size(*Context)
: (CDecl ? CDecl->ivar_size() : 0);
if (NumIvars > 0) {
static bool objc_ivar = false;
@@ -3223,9 +3223,15 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
Result += "\n";
ObjCInterfaceDecl::ivar_iterator IVI, IVE;
- if (!IDecl->ivar_empty()) {
- IVI = IDecl->ivar_begin();
- IVE = IDecl->ivar_end();
+ llvm::SmallVector<ObjCIvarDecl *, 8> IVars;
+ if (!IDecl->ivar_empty(*Context)) {
+ for (ObjCImplementationDecl::ivar_iterator
+ IV = IDecl->ivar_begin(*Context),
+ IVEnd = IDecl->ivar_end(*Context);
+ IV != IVEnd; ++IV)
+ IVars.push_back(*IV);
+ IVI = IVars.begin();
+ IVE = IVars.end();
} else {
IVI = CDecl->ivar_begin();
IVE = CDecl->ivar_end();