Unifies the name-lookup mechanisms used in various parts of the AST
and separates lexical name lookup from qualified name lookup. In
particular:
* Make DeclContext the central data structure for storing and
looking up declarations within existing declarations, e.g., members
of structs/unions/classes, enumerators in C++0x enums, members of
C++ namespaces, and (later) members of Objective-C
interfaces/implementations. DeclContext uses a lazily-constructed
data structure optimized for fast lookup (array for small contexts,
hash table for larger contexts).
* Implement C++ qualified name lookup in terms of lookup into
DeclContext.
* Implement C++ unqualified name lookup in terms of
qualified+unqualified name lookup (since unqualified lookup is not
purely lexical in C++!)
* Limit the use of the chains of declarations stored in
IdentifierInfo to those names declared lexically.
* Eliminate CXXFieldDecl, collapsing its behavior into
FieldDecl. (FieldDecl is now a ScopedDecl).
* Make RecordDecl into a DeclContext and eliminates its
Members/NumMembers fields (since one can just iterate through the
DeclContext to get the fields).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60878 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclSerialization.cpp b/lib/AST/DeclSerialization.cpp
index 29714c0..c0ffb0c 100644
--- a/lib/AST/DeclSerialization.cpp
+++ b/lib/AST/DeclSerialization.cpp
@@ -120,11 +120,29 @@
//===----------------------------------------------------------------------===//
void DeclContext::EmitOutRec(Serializer& S) const {
- S.EmitPtr(DeclChain);
+ S.EmitInt(Decls.size());
+ for (decl_iterator D = decls_begin(); D != decls_end(); ++D) {
+ bool Owned = ((*D)->getLexicalDeclContext() == this &&
+ DeclKind != Decl::TranslationUnit &&
+ !isFunctionOrMethod());
+ S.EmitBool(Owned);
+ if (Owned)
+ S.EmitOwnedPtr(*D);
+ else
+ S.EmitPtr(*D);
+ }
}
void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) {
- D.ReadPtr(DeclChain);
+ unsigned NumDecls = D.ReadInt();
+ Decls.resize(NumDecls);
+ for (unsigned Idx = 0; Idx < NumDecls; ++Idx) {
+ bool Owned = D.ReadBool();
+ if (Owned)
+ Decls[Idx] = cast_or_null<ScopedDecl>(D.ReadOwnedPtr<Decl>(C));
+ else
+ D.ReadPtr<ScopedDecl>(Decls[Idx]);
+ }
}
//===----------------------------------------------------------------------===//
@@ -205,14 +223,12 @@
void ScopedDecl::EmitInRec(Serializer& S) const {
NamedDecl::EmitInRec(S);
- S.EmitPtr(getNext()); // From ScopedDecl.
S.EmitPtr(cast_or_null<Decl>(getDeclContext())); // From ScopedDecl.
S.EmitPtr(cast_or_null<Decl>(getLexicalDeclContext())); // From ScopedDecl.
}
void ScopedDecl::ReadInRec(Deserializer& D, ASTContext& C) {
NamedDecl::ReadInRec(D, C);
- D.ReadPtr(Next); // From ScopedDecl.
assert(DeclCtx == 0);
@@ -394,8 +410,8 @@
void EnumDecl::EmitImpl(Serializer& S) const {
ScopedDecl::EmitInRec(S);
S.EmitBool(isDefinition());
- S.Emit(IntegerType);
- S.BatchEmitOwnedPtrs(getEnumConstantList(),getNextDeclarator());
+ S.Emit(IntegerType);
+ S.EmitOwnedPtr(getNextDeclarator());
}
EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) {
@@ -406,12 +422,7 @@
decl->setDefinition(D.ReadBool());
decl->IntegerType = QualType::ReadVal(D);
- Decl* next_declarator;
- Decl* Elist;
-
- D.BatchReadOwnedPtrs(Elist, next_declarator, C);
-
- decl->setDeclChain(cast_or_null<EnumConstantDecl>(Elist));
+ Decl* next_declarator = D.ReadOwnedPtr<Decl>(C);
decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator));
return decl;
@@ -451,14 +462,17 @@
//===----------------------------------------------------------------------===//
void FieldDecl::EmitImpl(Serializer& S) const {
+ S.EmitBool(Mutable);
S.Emit(getType());
- NamedDecl::EmitInRec(S);
+ ScopedDecl::EmitInRec(S);
S.EmitOwnedPtr(BitWidth);
}
FieldDecl* FieldDecl::CreateImpl(Deserializer& D, ASTContext& C) {
void *Mem = C.getAllocator().Allocate<FieldDecl>();
- FieldDecl* decl = new (Mem) FieldDecl(SourceLocation(), NULL, QualType(), 0);
+ FieldDecl* decl = new (Mem) FieldDecl(Field, 0, SourceLocation(), NULL,
+ QualType(), 0, false, 0);
+ decl->Mutable = D.ReadBool();
decl->DeclType.ReadBackpatch(D);
decl->ReadInRec(D, C);
decl->BitWidth = D.ReadOwnedPtr<Expr>(C);
@@ -579,13 +593,7 @@
ScopedDecl::EmitInRec(S);
S.EmitBool(isDefinition());
S.EmitBool(hasFlexibleArrayMember());
- S.EmitSInt(getNumMembers());
- if (getNumMembers() > 0) {
- assert (Members);
- S.BatchEmitOwnedPtrs((unsigned) getNumMembers(), (Decl**) &Members[0]);
- }
- else
- ScopedDecl::EmitOutRec(S);
+ ScopedDecl::EmitOutRec(S);
}
RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) {
@@ -597,17 +605,8 @@
decl->ScopedDecl::ReadInRec(D, C);
decl->setDefinition(D.ReadBool());
decl->setHasFlexibleArrayMember(D.ReadBool());
- decl->NumMembers = D.ReadSInt();
-
- if (decl->getNumMembers() > 0) {
- decl->Members = new FieldDecl*[(unsigned) decl->getNumMembers()];
-
- D.BatchReadOwnedPtrs((unsigned) decl->getNumMembers(),
- (Decl**) &decl->Members[0], C);
- }
- else
- decl->ScopedDecl::ReadOutRec(D, C);
-
+ decl->ScopedDecl::ReadOutRec(D, C);
+
return decl;
}