diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-12-06 00:12:39 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-12-06 00:12:39 +0000 |
| commit | b9d0193e5906336d555e033c126dcc5f5ae6b0e3 (patch) | |
| tree | d1b27aabd2bae396ed8cc2e51be1248cf836a1ec /clang/lib | |
| parent | 8e27c2b970f065033cc8c9eeecda480049d1edb5 (diff) | |
| download | bcm5719-llvm-b9d0193e5906336d555e033c126dcc5f5ae6b0e3.tar.gz bcm5719-llvm-b9d0193e5906336d555e033c126dcc5f5ae6b0e3.zip | |
[modules] Use the "redundant #include" diagnostic rather than the "module
import can't appear here" diagnostic if an already-visible module is textually
entered (because we have the module map but not the AST file) within a
function/namespace scope.
llvm-svn: 288737
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Parse/Parser.cpp | 27 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 8 |
2 files changed, 22 insertions, 13 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 78eba62695d..e97b5e495a6 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -77,7 +77,6 @@ Parser::Parser(Preprocessor &pp, Sema &actions, bool skipFunctionBodies) Tok.setKind(tok::eof); Actions.CurScope = nullptr; NumCachedScopes = 0; - ParenCount = BracketCount = BraceCount = 0; CurParsedObjCImpl = nullptr; // Add #pragma handlers. These are removed and destroyed in the @@ -2169,19 +2168,35 @@ bool Parser::parseMisplacedModuleImport() { while (true) { switch (Tok.getKind()) { case tok::annot_module_end: + // If we recovered from a misplaced module begin, we expect to hit a + // misplaced module end too. Stay in the current context when this + // happens. + if (MisplacedModuleBeginCount) { + --MisplacedModuleBeginCount; + Actions.ActOnModuleEnd(Tok.getLocation(), + reinterpret_cast<Module *>( + Tok.getAnnotationValue())); + ConsumeToken(); + continue; + } // Inform caller that recovery failed, the error must be handled at upper - // level. + // level. This will generate the desired "missing '}' at end of module" + // diagnostics on the way out. return true; case tok::annot_module_begin: - Actions.diagnoseMisplacedModuleImport(reinterpret_cast<Module *>( - Tok.getAnnotationValue()), Tok.getLocation()); - return true; + // Recover by entering the module (Sema will diagnose). + Actions.ActOnModuleBegin(Tok.getLocation(), + reinterpret_cast<Module *>( + Tok.getAnnotationValue())); + ConsumeToken(); + ++MisplacedModuleBeginCount; + continue; case tok::annot_module_include: // Module import found where it should not be, for instance, inside a // namespace. Recover by importing the module. Actions.ActOnModuleInclude(Tok.getLocation(), reinterpret_cast<Module *>( - Tok.getAnnotationValue())); + Tok.getAnnotationValue())); ConsumeToken(); // If there is another module import, process it. continue; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 8c180790cc9..984a14ad50d 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -15439,10 +15439,6 @@ static void checkModuleImportContext(Sema &S, Module *M, } } -void Sema::diagnoseMisplacedModuleImport(Module *M, SourceLocation ImportLoc) { - return checkModuleImportContext(*this, M, ImportLoc, CurContext); -} - Sema::DeclGroupPtrTy Sema::ActOnModuleDecl(SourceLocation ModuleLoc, ModuleDeclKind MDK, ModuleIdPath Path) { @@ -15610,7 +15606,7 @@ void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod) { } void Sema::ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod) { - checkModuleImportContext(*this, Mod, DirectiveLoc, CurContext); + checkModuleImportContext(*this, Mod, DirectiveLoc, CurContext, true); ModuleScopes.push_back({}); ModuleScopes.back().Module = Mod; @@ -15621,8 +15617,6 @@ void Sema::ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod) { } void Sema::ActOnModuleEnd(SourceLocation EofLoc, Module *Mod) { - checkModuleImportContext(*this, Mod, EofLoc, CurContext); - if (getLangOpts().ModulesLocalVisibility) { VisibleModules = std::move(ModuleScopes.back().OuterVisibleModules); // Leaving a module hides namespace names, so our visible namespace cache |

