diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Parse/ParseObjc.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Parse/Parser.cpp | 14 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 13 |
3 files changed, 21 insertions, 12 deletions
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index edf1da171b0..fb8624a324b 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -81,8 +81,10 @@ Parser::DeclGroupPtrTy Parser::ParseObjCAtDirectives() { SingleDecl = ParseObjCPropertyDynamic(AtLoc); break; case tok::objc_import: - if (getLangOpts().Modules || getLangOpts().DebuggerSupport) - return ParseModuleImport(AtLoc); + if (getLangOpts().Modules || getLangOpts().DebuggerSupport) { + SingleDecl = ParseModuleImport(AtLoc); + break; + } Diag(AtLoc, diag::err_atimport); SkipUntil(tok::semi); return Actions.ConvertDeclToDeclGroup(nullptr); diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 0b07ba1888b..72d653797c6 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -556,10 +556,6 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result) { HandlePragmaUnused(); return false; - case tok::kw_import: - Result = ParseModuleImport(SourceLocation()); - return false; - case tok::kw_export: if (NextToken().isNot(tok::kw_module)) break; @@ -637,6 +633,9 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result) { /// ';' /// /// [C++0x/GNU] 'extern' 'template' declaration +/// +/// [Modules-TS] module-import-declaration +/// Parser::DeclGroupPtrTy Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, ParsingDeclSpec *DS) { @@ -764,6 +763,9 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, CurParsedObjCImpl ? Sema::PCC_ObjCImplementation : Sema::PCC_Namespace); cutOffParsing(); return nullptr; + case tok::kw_import: + SingleDecl = ParseModuleImport(SourceLocation()); + break; case tok::kw_export: if (getLangOpts().ModulesTS) { SingleDecl = ParseExportDeclaration(); @@ -2092,7 +2094,7 @@ Parser::DeclGroupPtrTy Parser::ParseModuleDecl() { /// '@' 'import' module-name ';' /// [ModTS] module-import-declaration: /// 'import' module-name attribute-specifier-seq[opt] ';' -Parser::DeclGroupPtrTy Parser::ParseModuleImport(SourceLocation AtLoc) { +Decl *Parser::ParseModuleImport(SourceLocation AtLoc) { assert((AtLoc.isInvalid() ? Tok.is(tok::kw_import) : Tok.isObjCAtKeyword(tok::objc_import)) && "Improper start to module import"); @@ -2119,7 +2121,7 @@ Parser::DeclGroupPtrTy Parser::ParseModuleImport(SourceLocation AtLoc) { if (Import.isInvalid()) return nullptr; - return Actions.ConvertDeclToDeclGroup(Import.get()); + return Import.get(); } /// Parse a C++ Modules TS / Objective-C module name (both forms use the same diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 14dcce48d29..41f6f730b2f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -16171,7 +16171,7 @@ static void checkModuleImportContext(Sema &S, Module *M, DC = LSD->getParent(); } - while (isa<LinkageSpecDecl>(DC)) + while (isa<LinkageSpecDecl>(DC) || isa<ExportDecl>(DC)) DC = DC->getParent(); if (!isa<TranslationUnitDecl>(DC)) { @@ -16349,12 +16349,17 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, IdentifierLocs.push_back(Path[I].second); } - TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl(); - ImportDecl *Import = ImportDecl::Create(Context, TU, StartLoc, + ImportDecl *Import = ImportDecl::Create(Context, CurContext, StartLoc, Mod, IdentifierLocs); if (!ModuleScopes.empty()) Context.addModuleInitializer(ModuleScopes.back().Module, Import); - TU->addDecl(Import); + CurContext->addDecl(Import); + + // Re-export the module if needed. + if (Import->isExported() && + !ModuleScopes.empty() && ModuleScopes.back().ModuleInterface) + getCurrentModule()->Exports.emplace_back(Mod, false); + return Import; } |