summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization/ASTReader.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-08-18 04:12:04 +0000
committerDouglas Gregor <dgregor@apple.com>2011-08-18 04:12:04 +0000
commitdf0c151ba67535d21fdf12e4a0d249b88d506ea1 (patch)
tree370e48071a32020e12439e44f645c1a8243e9535 /clang/lib/Serialization/ASTReader.cpp
parent81ded935f8a9741b4778970f189f7840b68fd82d (diff)
downloadbcm5719-llvm-df0c151ba67535d21fdf12e4a0d249b88d506ea1.tar.gz
bcm5719-llvm-df0c151ba67535d21fdf12e4a0d249b88d506ea1.zip
Keep track of which modules have been loaded directly (e.g., via
-import-module) vs. loaded because some other module depends on them. As part of doing this, pass down the module that caused a module to be loaded directly, rather than assuming that we're loading a chain. Finally, write out all of the directly-loaded modules when serializing an AST file (using the new IMPORTS record), so that an AST file can depend on more than one other AST file, all of which will be loaded when that AST file is loaded. This allows us to form and load a tree of modules, but we can't yet load a DAG of modules. llvm-svn: 137923
Diffstat (limited to 'clang/lib/Serialization/ASTReader.cpp')
-rw-r--r--clang/lib/Serialization/ASTReader.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 1d7ea1346fc..d81e9d8a36a 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2045,7 +2045,7 @@ ASTReader::ReadASTBlock(Module &F) {
Idx += Length;
// Load the AST file.
- switch(ReadASTCore(ImportedFile, ImportedKind)) {
+ switch(ReadASTCore(ImportedFile, ImportedKind, &F)) {
case Failure: return Failure;
// If we have to ignore the dependency, we'll have to ignore this too.
case IgnorePCH: return IgnorePCH;
@@ -2724,7 +2724,7 @@ ASTReader::ASTReadResult ASTReader::validateFileEntries() {
ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName,
ModuleKind Type) {
- switch(ReadASTCore(FileName, Type)) {
+ switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) {
case Failure: return Failure;
case IgnorePCH: return IgnorePCH;
case Success: break;
@@ -2829,8 +2829,9 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName,
}
ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName,
- ModuleKind Type) {
- Module &F = ModuleMgr.addModule(FileName, Type);
+ ModuleKind Type,
+ Module *ImportedBy) {
+ Module &F = ModuleMgr.addModule(FileName, Type, ImportedBy);
if (FileName != "-") {
CurrentDir = llvm::sys::path::parent_path(FileName);
@@ -5610,7 +5611,8 @@ ASTReader::~ASTReader() {
}
Module::Module(ModuleKind Kind)
- : Kind(Kind), SizeInBits(0), LocalNumSLocEntries(0), SLocEntryBaseID(0),
+ : Kind(Kind), DirectlyImported(false), SizeInBits(0),
+ LocalNumSLocEntries(0), SLocEntryBaseID(0),
SLocEntryBaseOffset(0), SLocEntryOffsets(0),
SLocFileOffsets(0), LocalNumIdentifiers(0),
IdentifierOffsets(0), BaseIdentifierID(0), IdentifierTableData(0),
@@ -5708,19 +5710,21 @@ llvm::MemoryBuffer *ModuleManager::lookupBuffer(StringRef Name) {
}
/// \brief Creates a new module and adds it to the list of known modules
-Module &ModuleManager::addModule(StringRef FileName, ModuleKind Type) {
- Module *Prev = !size() ? 0 : &getLastModule();
+Module &ModuleManager::addModule(StringRef FileName, ModuleKind Type,
+ Module *ImportedBy) {
Module *Current = new Module(Type);
-
Current->FileName = FileName.str();
-
Chain.push_back(Current);
+
const FileEntry *Entry = FileMgr.getFile(FileName);
+ // FIXME: Check whether we already loaded this module, before
Modules[Entry] = Current;
- if (Prev) {
- Current->ImportedBy.insert(Prev);
- Prev->Imports.insert(Current);
+ if (ImportedBy) {
+ Current->ImportedBy.insert(ImportedBy);
+ ImportedBy->Imports.insert(Current);
+ } else {
+ Current->DirectlyImported = true;
}
return *Current;
OpenPOWER on IntegriCloud