Infer the submodule ID for a given declaration based on the location

of that declaration, and encode the submodule ID in each declaration
stored in an AST file.

llvm-svn: 145555
This commit is contained in:
Douglas Gregor 2011-12-01 02:07:58 +00:00
parent 947ccc7396
commit a28bcddef6
4 changed files with 60 additions and 4 deletions

View File

@ -95,6 +95,9 @@ private:
/// \brief The ASTContext we're writing. /// \brief The ASTContext we're writing.
ASTContext *Context; ASTContext *Context;
/// \brief The preprocessor we're writing.
Preprocessor *PP;
/// \brief The reader of existing AST files, if we're chaining. /// \brief The reader of existing AST files, if we're chaining.
ASTReader *Chain; ASTReader *Chain;
@ -385,6 +388,11 @@ private:
void WriteHeaderSearch(const HeaderSearch &HS, StringRef isysroot); void WriteHeaderSearch(const HeaderSearch &HS, StringRef isysroot);
void WritePreprocessorDetail(PreprocessingRecord &PPRec); void WritePreprocessorDetail(PreprocessingRecord &PPRec);
void WriteSubmodules(Module *WritingModule); void WriteSubmodules(Module *WritingModule);
/// \brief Infer the submodule ID that contains an entity at the given
/// source location.
serialization::SubmoduleID inferSubmoduleIDFromLocation(SourceLocation Loc);
void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag); void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag);
void WriteCXXBaseSpecifiersOffsets(); void WriteCXXBaseSpecifiersOffsets();
void WriteType(QualType T); void WriteType(QualType T);

View File

@ -253,6 +253,10 @@ void ASTDeclReader::VisitDecl(Decl *D) {
D->setAccess((AccessSpecifier)Record[Idx++]); D->setAccess((AccessSpecifier)Record[Idx++]);
D->FromASTFile = true; D->FromASTFile = true;
D->ModulePrivate = Record[Idx++]; D->ModulePrivate = Record[Idx++];
unsigned SubmoduleID = Record[Idx++];
// FIXME: Actual use the submodule ID to determine visibility.
(void)SubmoduleID;
} }
void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {

View File

@ -1943,6 +1943,38 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
Stream.ExitBlock(); Stream.ExitBlock();
} }
serialization::SubmoduleID
ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) {
if (Loc.isInvalid() || SubmoduleIDs.empty())
return 0; // No submodule
// Use the expansion location to determine which module we're in.
SourceManager &SrcMgr = PP->getSourceManager();
SourceLocation ExpansionLoc = SrcMgr.getExpansionLoc(Loc);
if (!ExpansionLoc.isFileID())
return 0;
FileID ExpansionFileID = SrcMgr.getFileID(ExpansionLoc);
const FileEntry *ExpansionFile = SrcMgr.getFileEntryForID(ExpansionFileID);
if (!ExpansionFile)
return 0;
// Find the module that owns this header.
ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap();
Module *OwningMod = ModMap.findModuleForHeader(ExpansionFile);
if (!OwningMod)
return 0;
// Check whether we known about this submodule.
llvm::DenseMap<Module *, unsigned>::iterator Known
= SubmoduleIDs.find(OwningMod);
if (Known == SubmoduleIDs.end())
return 0;
return Known->second;
}
void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag) { void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag) {
RecordData Record; RecordData Record;
for (DiagnosticsEngine::DiagStatePointsTy::const_iterator for (DiagnosticsEngine::DiagStatePointsTy::const_iterator
@ -2862,7 +2894,7 @@ void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) {
} }
ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream) ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream)
: Stream(Stream), Context(0), Chain(0), WritingAST(false), : Stream(Stream), Context(0), PP(0), Chain(0), WritingAST(false),
FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID), FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID),
FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID), FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID),
FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID), FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID),
@ -2903,8 +2935,10 @@ void ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls,
WriteBlockInfoBlock(); WriteBlockInfoBlock();
Context = &SemaRef.Context; Context = &SemaRef.Context;
PP = &SemaRef.PP;
WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile, WritingModule); WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile, WritingModule);
Context = 0; Context = 0;
PP = 0;
WritingAST = false; WritingAST = false;
} }
@ -3123,7 +3157,11 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes);
AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes);
AddTypeRef(Context.getucontext_tType(), SpecialTypes); AddTypeRef(Context.getucontext_tType(), SpecialTypes);
// If we're emitting a module, write out the submodule information.
if (WritingModule)
WriteSubmodules(WritingModule);
// Keep writing types and declarations until all types and // Keep writing types and declarations until all types and
// declarations have been written. // declarations have been written.
Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE);
@ -3188,8 +3226,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record,
Buffer.data(), Buffer.size()); Buffer.data(), Buffer.size());
} }
if (WritingModule)
WriteSubmodules(WritingModule);
WritePreprocessor(PP, WritingModule != 0); WritePreprocessor(PP, WritingModule != 0);
WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot);
WriteSelectors(SemaRef); WriteSelectors(SemaRef);

View File

@ -157,6 +157,7 @@ void ASTDeclWriter::VisitDecl(Decl *D) {
Record.push_back(D->TopLevelDeclInObjCContainer); Record.push_back(D->TopLevelDeclInObjCContainer);
Record.push_back(D->getAccess()); Record.push_back(D->getAccess());
Record.push_back(D->ModulePrivate); Record.push_back(D->ModulePrivate);
Record.push_back(Writer.inferSubmoduleIDFromLocation(D->getLocation()));
} }
void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
@ -1287,6 +1288,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
// NamedDecl // NamedDecl
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
@ -1318,6 +1320,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
// NamedDecl // NamedDecl
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
@ -1354,6 +1357,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
// NamedDecl // NamedDecl
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
@ -1400,6 +1404,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
// NamedDecl // NamedDecl
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
@ -1440,6 +1445,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
// NamedDecl // NamedDecl
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
@ -1487,6 +1493,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
// NamedDecl // NamedDecl
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
@ -1514,6 +1521,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
// NamedDecl // NamedDecl
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name