From: Douglas Gregor Date: Thu, 28 Jul 2011 14:41:43 +0000 (+0000) Subject: Move a Module's ReferencedSelectorsData into the ASTReader itself, so X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8451ec7e709baf777bec07dc70653e0c523dd120;p=clang Move a Module's ReferencedSelectorsData into the ASTReader itself, so that it accumulates referenced selectors from each of the modules/PCH files as they are loaded. No actual functionality change, yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136356 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index d39f2c0c20..7de5ec1ffc 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -328,10 +328,6 @@ public: /// instance and factory methods. void *SelectorLookupTable; - /// \brief Method selectors used in a @selector expression. Used for - /// implementation of -Wselector. - SmallVector ReferencedSelectorsData; - // === Declarations === /// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block. It @@ -747,6 +743,10 @@ private: /// \brief A list of all the delegating constructors we've seen, to diagnose /// cycles. SmallVector DelegatingCtorDecls; + + /// \brief Method selectors used in a @selector expression. Used for + /// implementation of -Wselector. + SmallVector ReferencedSelectorsData; /// \brief A snapshot of Sema's weak undeclared identifier tracking, for /// generating warnings. @@ -1420,12 +1420,17 @@ public: Selector DecodeSelector(unsigned Idx); - virtual Selector GetExternalSelector(uint32_t ID); + virtual Selector GetExternalSelector(serialization::SelectorID ID); uint32_t GetNumExternalSelectors(); Selector GetSelector(const RecordData &Record, unsigned &Idx) { return DecodeSelector(Record[Idx++]); } + + /// \brief Retrieve the global selector ID that corresponds to this + /// the local selector ID in a given module. + serialization::SelectorID getGlobalSelectorID(Module &F, + unsigned LocalID) const; /// \brief Read a declaration name. DeclarationName ReadDeclarationName(Module &F, diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 4b4432e46d..0ae1f62aa3 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2196,7 +2196,14 @@ ASTReader::ReadASTBlock(Module &F) { break; case REFERENCED_SELECTOR_POOL: - F.ReferencedSelectorsData.swap(Record); + if (!Record.empty()) { + for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { + ReferencedSelectorsData.push_back(getGlobalSelectorID(F, + Record[Idx++])); + ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). + getRawEncoding()); + } + } break; case PP_COUNTER_VALUE: @@ -4349,12 +4356,6 @@ void ASTReader::InitializeSema(Sema &S) { } PreloadedDecls.clear(); - // FIXME: Do VTable uses and dynamic classes deserialize too much ? - // Can we cut them down before writing them ? - - // If there were any dynamic classes declarations, deserialize them - // and add them to Sema's vector of such declarations. - // Load the offsets of the declarations that Sema references. // They will be lazily deserialized when needed. if (!SemaDeclRefs.empty()) { @@ -4365,19 +4366,16 @@ void ASTReader::InitializeSema(Sema &S) { SemaObj->StdBadAlloc = SemaDeclRefs[1]; } - for (Module *F = &ModuleMgr.getPrimaryModule(); F; F = F->NextInSource) { - - // If there are @selector references added them to its pool. This is for - // implementation of -Wselector. - if (!F->ReferencedSelectorsData.empty()) { - unsigned int DataSize = F->ReferencedSelectorsData.size()-1; - unsigned I = 0; - while (I < DataSize) { - Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); - SourceLocation SelLoc = ReadSourceLocation( - *F, F->ReferencedSelectorsData, I); - SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); - } + // If there are @selector references added them to its pool. This is for + // implementation of -Wselector. + if (!ReferencedSelectorsData.empty()) { + unsigned int DataSize = ReferencedSelectorsData.size()-1; + unsigned I = 0; + while (I < DataSize) { + Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); + SourceLocation SelLoc + = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); + SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); } } @@ -4743,7 +4741,7 @@ Selector ASTReader::DecodeSelector(unsigned ID) { return SelectorsLoaded[ID - 1]; } -Selector ASTReader::GetExternalSelector(uint32_t ID) { +Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { return DecodeSelector(ID); } @@ -4752,6 +4750,12 @@ uint32_t ASTReader::GetNumExternalSelectors() { return getTotalNumSelectors() + 1; } +serialization::SelectorID +ASTReader::getGlobalSelectorID(Module &F, unsigned LocalID) const { + // FIXME: Perform local -> global remapping + return LocalID; +} + DeclarationName ASTReader::ReadDeclarationName(Module &F, const RecordData &Record, unsigned &Idx) {