diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 24 | ||||
-rw-r--r-- | lib/Lex/PPDirectives.cpp | 18 | ||||
-rw-r--r-- | lib/Lex/Preprocessor.cpp | 8 | ||||
-rw-r--r-- | lib/Parse/Parser.cpp | 31 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 7 |
5 files changed, 54 insertions, 34 deletions
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 35f82174b2..a72370312d 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -1068,9 +1068,8 @@ static void compileModule(CompilerInstance &ImportingInstance, llvm::sys::Path(TempModuleMapFileName).eraseFromDisk(); } -ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, - IdentifierInfo &ModuleName, - SourceLocation ModuleNameLoc) { +ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, + ModuleIdPath Path) { // Determine what file we're searching from. SourceManager &SourceMgr = getSourceManager(); SourceLocation ExpandedImportLoc = SourceMgr.getExpansionLoc(ImportLoc); @@ -1079,13 +1078,19 @@ ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, if (!CurFile) CurFile = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()); + StringRef ModuleName = Path[0].first->getName(); + SourceLocation ModuleNameLoc = Path[0].second; + // Search for a module with the given name. ModuleMap::Module *Module = 0; std::string ModuleFileName; const FileEntry *ModuleFile - = PP->getHeaderSearchInfo().lookupModule(ModuleName.getName(), Module, + = PP->getHeaderSearchInfo().lookupModule(ModuleName, Module, &ModuleFileName); + // FIXME: Verify that the rest of the module path actually corresponds to + // a submodule, and pass that information through. + bool BuildingModule = false; if (!ModuleFile && Module) { // The module is not cached, but we have a module map from which we can @@ -1095,23 +1100,22 @@ ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, SmallVectorImpl<std::string> &ModuleBuildPath = getPreprocessorOpts().ModuleBuildPath; SmallVectorImpl<std::string>::iterator Pos - = std::find(ModuleBuildPath.begin(), ModuleBuildPath.end(), - ModuleName.getName()); + = std::find(ModuleBuildPath.begin(), ModuleBuildPath.end(), ModuleName); if (Pos != ModuleBuildPath.end()) { llvm::SmallString<256> CyclePath; for (; Pos != ModuleBuildPath.end(); ++Pos) { CyclePath += *Pos; CyclePath += " -> "; } - CyclePath += ModuleName.getName(); + CyclePath += ModuleName; getDiagnostics().Report(ModuleNameLoc, diag::err_module_cycle) - << ModuleName.getName() << CyclePath; + << ModuleName << CyclePath; return 0; } getDiagnostics().Report(ModuleNameLoc, diag::warn_module_build) - << ModuleName.getName(); + << ModuleName; BuildingModule = true; compileModule(*this, Module, ModuleFileName); ModuleFile = FileMgr->getFile(ModuleFileName); @@ -1121,7 +1125,7 @@ ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, getDiagnostics().Report(ModuleNameLoc, BuildingModule? diag::err_module_not_built : diag::err_module_not_found) - << ModuleName.getName() + << ModuleName << SourceRange(ImportLoc, ModuleNameLoc); return 0; } diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 88d9429f00..140f793234 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -1279,13 +1279,17 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, // If we are supposed to import a module rather than including the header, // do so now. if (SuggestedModule) { - // FIXME: Actually load the submodule that we were given. - while (SuggestedModule->Parent) - SuggestedModule = SuggestedModule->Parent; - - TheModuleLoader.loadModule(IncludeTok.getLocation(), - Identifiers.get(SuggestedModule->Name), - FilenameTok.getLocation()); + // Compute the module access path corresponding to this module. + // FIXME: Should we have a second loadModule() overload to avoid this + // extra lookup step? + llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path; + for (ModuleMap::Module *Mod = SuggestedModule; Mod; Mod = Mod->Parent) + Path.push_back(std::make_pair(getIdentifierInfo(Mod->Name), + FilenameTok.getLocation())); + std::reverse(Path.begin(), Path.end()); + + // Load the module. + TheModuleLoader.loadModule(IncludeTok.getLocation(), Path); return; } diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 798244c3d2..aeba32f96a 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -575,9 +575,11 @@ void Preprocessor::LexAfterModuleImport(Token &Result) { return; // Load the module. - (void)TheModuleLoader.loadModule(ModuleImportLoc, - *Result.getIdentifierInfo(), - Result.getLocation()); + llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path; + Path.push_back(std::make_pair(Result.getIdentifierInfo(), + Result.getLocation())); + + (void)TheModuleLoader.loadModule(ModuleImportLoc, Path); } void Preprocessor::AddCommentHandler(CommentHandler *Handler) { diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 834e741e30..eb6dc443c9 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -1570,16 +1570,29 @@ Parser::DeclGroupPtrTy Parser::ParseModuleImport() { "Improper start to module import"); SourceLocation ImportLoc = ConsumeToken(); - // Parse the module name. - if (!Tok.is(tok::identifier)) { - Diag(Tok, diag::err_module_expected_ident); - SkipUntil(tok::semi); - return DeclGroupPtrTy(); - } + llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path; + + // Parse the module path. + do { + if (!Tok.is(tok::identifier)) { + Diag(Tok, diag::err_module_expected_ident); + SkipUntil(tok::semi); + return DeclGroupPtrTy(); + } + + // Record this part of the module path. + Path.push_back(std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation())); + ConsumeToken(); + + if (Tok.is(tok::period)) { + ConsumeToken(); + continue; + } + + break; + } while (true); - IdentifierInfo &ModuleName = *Tok.getIdentifierInfo(); - SourceLocation ModuleNameLoc = ConsumeToken(); - DeclResult Import = Actions.ActOnModuleImport(ImportLoc, ModuleName, ModuleNameLoc); + DeclResult Import = Actions.ActOnModuleImport(ImportLoc, Path); ExpectAndConsumeSemi(diag::err_module_expected_semi); if (Import.isInvalid()) return DeclGroupPtrTy(); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index eaf778d130..0659a0f6f3 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -9891,11 +9891,8 @@ Decl *Sema::ActOnFileScopeAsmDecl(Expr *expr, return New; } -DeclResult Sema::ActOnModuleImport(SourceLocation ImportLoc, - IdentifierInfo &ModuleName, - SourceLocation ModuleNameLoc) { - ModuleKey Module = PP.getModuleLoader().loadModule(ImportLoc, - ModuleName, ModuleNameLoc); +DeclResult Sema::ActOnModuleImport(SourceLocation ImportLoc, ModuleIdPath Path) { + ModuleKey Module = PP.getModuleLoader().loadModule(ImportLoc, Path); if (!Module) return true; |