From f5bb9ae23d68ffb1e1c37b05fc8d943bc6bff12e Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 21 Jul 2011 23:29:11 +0000 Subject: [PATCH] Clean up the rest of the local -> global declaration ID mappings within the ASTReader (I hope). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135720 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Serialization/ASTReader.h | 1 + lib/Serialization/ASTReader.cpp | 18 ++++++------------ lib/Serialization/ASTReaderDecl.cpp | 2 ++ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 60f2129295..9841f878d9 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -514,6 +514,7 @@ private: /// \brief Information about the contents of a DeclContext. struct DeclContextInfo { + PerFileData *F; void *NameLookupTableData; // a ASTDeclContextNameLookupTable. const serialization::KindDeclIDPair *LexicalDecls; unsigned NumLexicalDecls; diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 74fbd6cc5e..52669d75e4 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -719,7 +719,7 @@ public: if (DataLen > 0) { llvm::SmallVector DeclIDs; for (; DataLen > 0; DataLen -= 4) - DeclIDs.push_back(ReadUnalignedLE32(d)); + DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); Reader.SetGloballyVisibleDecls(II, DeclIDs); } @@ -2062,6 +2062,7 @@ ASTReader::ReadASTBlock(PerFileData &F) { case TU_UPDATE_LEXICAL: { DeclContextInfo Info = { + &F, /* No visible information */ 0, reinterpret_cast(BlobStart), BlobLen / sizeof(KindDeclIDPair) @@ -2079,7 +2080,7 @@ ASTReader::ReadASTBlock(PerFileData &F) { ASTDeclContextNameLookupTrait(*this)); if (ID == 1 && Context) { // Is it the TU? DeclContextInfo Info = { - Table, /* No lexical inforamtion */ 0, 0 + &F, Table, /* No lexical inforamtion */ 0, 0 }; DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); } else @@ -4121,9 +4122,7 @@ ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) continue; - // FIXME: Modules need to know whether this is already mapped to a - // global ID or not. - Decl *D = GetDecl(ID->second); + Decl *D = GetLocalDecl(*I->F, ID->second); assert(D && "Null decl in lexical decls"); Decls.push_back(D); } @@ -4158,11 +4157,9 @@ ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, if (Pos == LookupTable->end()) continue; - // FIXME: Modules need to know whether this is already mapped to a - // global ID or not. ASTDeclContextNameLookupTrait::data_type Data = *Pos; for (; Data.first != Data.second; ++Data.first) - Decls.push_back(cast(GetDecl(*Data.first))); + Decls.push_back(GetLocalDeclAs(*I->F, *Data.first)); break; } @@ -4194,10 +4191,8 @@ void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { = *ItemI; ASTDeclContextNameLookupTrait::data_type Data = Val.second; Decls.clear(); - // FIXME: Modules need to know whether this is already mapped to a - // global ID or not. for (; Data.first != Data.second; ++Data.first) - Decls.push_back(cast(GetDecl(*Data.first))); + Decls.push_back(GetLocalDeclAs(*I->F, *Data.first)); MaterializeVisibleDeclsForName(DC, Val.first, Decls); } } @@ -4664,7 +4659,6 @@ ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, } for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { - // FIXME: Are these IDs local or global? It's not clear! NamedDecl *D = cast(GetDecl(DeclIDs[I])); if (SemaObj) { if (SemaObj->TUScope) { diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 8132ed9a5f..3d58f9552b 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1688,6 +1688,7 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) { DC->setHasExternalLexicalStorage(Offsets.first != 0); DC->setHasExternalVisibleStorage(Offsets.second != 0); DeclContextInfo Info; + Info.F = Loc.F; if (ReadDeclContextStorage(DeclsCursor, Offsets, Info)) return 0; DeclContextInfos &Infos = DeclContextOffsets[DC]; @@ -1707,6 +1708,7 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) { DeclContextVisibleUpdates &U = I->second; DeclContextInfos &Infos = DeclContextOffsets[DC]; DeclContextInfo Info; + Info.F = Loc.F; Info.LexicalDecls = 0; Info.NumLexicalDecls = 0; for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();