Lines Matching +full:dc +full:- +full:valid

1 //===--- SemaModule.cpp - Semantic Analysis for Modules -------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 // Objective-C modules syntax, and Clang header modules).
12 //===----------------------------------------------------------------------===//
26 SourceLocation ImportLoc, DeclContext *DC, in checkModuleImportContext() argument
30 if (auto *LSD = dyn_cast<LinkageSpecDecl>(DC)) { in checkModuleImportContext()
31 switch (LSD->getLanguage()) { in checkModuleImportContext()
34 ExternCLoc = LSD->getBeginLoc(); in checkModuleImportContext()
39 DC = LSD->getParent(); in checkModuleImportContext()
42 while (isa<LinkageSpecDecl>(DC) || isa<ExportDecl>(DC)) in checkModuleImportContext()
43 DC = DC->getParent(); in checkModuleImportContext()
45 if (!isa<TranslationUnitDecl>(DC)) { in checkModuleImportContext()
49 << M->getFullModuleName() << DC; in checkModuleImportContext()
50 S.Diag(cast<Decl>(DC)->getBeginLoc(), in checkModuleImportContext()
52 << DC; in checkModuleImportContext()
53 } else if (!M->IsExternC && ExternCLoc.isValid()) { in checkModuleImportContext()
55 << M->getFullModuleName(); in checkModuleImportContext()
72 Name += Piece.first->getName(); in stringFromPath()
88 if (!Imported->isNamedModule()) in isImportingModuleUnitFromSameModule()
93 if (Imported->isModulePartition()) in isImportingModuleUnitFromSameModule()
110 if (!CurrentModule->isModulePartitionImplementation()) in isImportingModuleUnitFromSameModule()
124 /// Additionally, when a module-import-declaration in a module unit of some
126 /// translation units imported by non-exported module-import-declarations in
134 assert(Imported->isNamedModule() && in makeTransitiveImportsVisible()
156 for (Module *TransImported : Importing->Imports) in makeTransitiveImportsVisible()
171 // A global-module-fragment specifies the contents of the global module in ActOnGlobalModuleFragmentDecl()
177 TU->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ReachableWhenImported); in ActOnGlobalModuleFragmentDecl()
178 TU->setLocalOwningModule(GlobalModule); in ActOnGlobalModuleFragmentDecl()
186 "Header units are only valid for C++20 modules"); in HandleStartOfHeaderUnit()
193 SourceMgr.getFileEntryRefForID(SourceMgr.getMainFileID())->getName(); in HandleStartOfHeaderUnit()
198 // When the input is pre-processed source, we need a file ref to the original in HandleStartOfHeaderUnit()
202 // after creating the pre-processed output) fall back to obtaining the file in HandleStartOfHeaderUnit()
219 TU->setModuleOwnershipKind(Decl::ModuleOwnershipKind::Visible); in HandleStartOfHeaderUnit()
220 TU->setLocalOwningModule(Mod); in HandleStartOfHeaderUnit()
229 Valid = -1, in DiagReservedModuleName() enumerator
232 } Reason = Valid; in DiagReservedModuleName()
234 if (II->isStr("module") || II->isStr("import")) in DiagReservedModuleName()
236 else if (II->isReserved(S.getLangOpts()) != in DiagReservedModuleName()
244 Reason = Valid; in DiagReservedModuleName()
247 case Valid: in DiagReservedModuleName()
284 // A (non-partition) module implementation unit requires that we are not in ActOnModuleDecl()
319 // Only one module-declaration is permitted per source file. in ActOnModuleDecl()
328 SeenGMF == (bool)this->TheGlobalModuleFragment) && in ActOnModuleDecl()
331 // In C++20, the module-declaration must be the first declaration if there in ActOnModuleDecl()
346 // appear as identifiers in a module-name or module-partition. All in ActOnModuleDecl()
347 // module-names either beginning with an identifier consisting of std in ActOnModuleDecl()
350 // module-declaration; no diagnostic is required. in ActOnModuleDecl()
352 // Test the first part of the path to see if it's std[0-9]+ but allow the in ActOnModuleDecl()
354 StringRef FirstComponentName = Path[0].first->getName(); in ActOnModuleDecl()
399 if (M->DefinitionLoc.isValid()) in ActOnModuleDecl()
400 Diag(M->DefinitionLoc, diag::note_prev_module_definition); in ActOnModuleDecl()
401 else if (OptionalFileEntryRef FE = M->getASTFile()) in ActOnModuleDecl()
402 Diag(M->DefinitionLoc, diag::note_prev_module_definition_from_ast_file) in ActOnModuleDecl()
403 << FE->getName(); in ActOnModuleDecl()
411 Mod->Kind = Module::ModulePartitionInterface; in ActOnModuleDecl()
417 // C++20 A module-declaration that contains neither an export- in ActOnModuleDecl()
418 // keyword nor a module-partition implicitly imports the primary in ActOnModuleDecl()
419 // module interface unit of the module as if by a module-import- in ActOnModuleDecl()
447 Mod->Kind = Module::ModulePartitionImplementation; in ActOnModuleDecl()
451 if (!this->TheGlobalModuleFragment) { in ActOnModuleDecl()
468 // Otherwise, those declarations are module-private unless explicitly in ActOnModuleDecl()
471 TU->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ReachableWhenImported); in ActOnModuleDecl()
472 TU->setLocalOwningModule(Mod); in ActOnModuleDecl()
481 Listener->EnteringModulePurview(); in ActOnModuleDecl()
495 CurContext->addDecl(Import); in ActOnModuleDecl()
500 Mod->Imports.insert(Interface); // As if we imported it. in ActOnModuleDecl()
515 // A private-module-fragment shall appear only in a primary module in ActOnPrivateModuleFragmentDecl()
518 : ModuleScopes.back().Module->Kind) { in ActOnPrivateModuleFragmentDecl()
567 TU->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate); in ActOnPrivateModuleFragmentDecl()
568 TU->setLocalOwningModule(PrivateModuleFragment); in ActOnPrivateModuleFragmentDecl()
579 "partition seen in non-C++20 code?"); in ActOnModuleImport()
592 ModuleName = NamedMod->getPrimaryModuleInterfaceName().str(); in ActOnModuleImport()
603 // Diagnose self-import before attempting a load. in ActOnModuleImport()
606 // shall not contain a module-import-declaration nominating M. in ActOnModuleImport()
611 getCurrentModule()->Name == ModuleName) { in ActOnModuleImport()
622 if (!Mod->isInterfaceOrPartition() && !ModuleName.empty() && in ActOnModuleImport()
632 /// Determine whether \p D is lexically within an export-declaration.
634 for (auto *DC = D->getLexicalDeclContext(); DC; DC = DC->getLexicalParent()) in getEnclosingExportDecl() local
635 if (auto *ED = dyn_cast<ExportDecl>(DC)) in getEnclosingExportDecl()
644 if (Mod->isHeaderUnit()) in ActOnModuleImport()
647 if (Mod->isNamedModule()) in ActOnModuleImport()
656 // of the same top-level module. Until we do, make it an error rather than in ActOnModuleImport()
659 if (Mod->isForBuilding(getLangOpts())) { in ActOnModuleImport()
663 << Mod->getFullModuleName() << getLangOpts().CurrentModule; in ActOnModuleImport()
670 // FIXME: Pass in and use the location of the header-name token in this in ActOnModuleImport()
672 for (Module *ModCheck = Mod; ModCheck; ModCheck = ModCheck->Parent) in ActOnModuleImport()
674 } else if (getLangOpts().CPlusPlusModules && !Mod->Parent) { in ActOnModuleImport()
684 ModCheck = ModCheck->Parent; in ActOnModuleImport()
692 CurContext->addDecl(Import); in ActOnModuleImport()
701 Mod->Kind == Module::ModuleKind::ModulePartitionImplementation) { in ActOnModuleImport()
705 // Re-export the module if the imported module is exported. in ActOnModuleImport()
706 // Note that we don't need to add re-exported module to Imports field in ActOnModuleImport()
709 getCurrentModule()->Exports.emplace_back(Mod, false); in ActOnModuleImport()
711 getCurrentModule()->Imports.insert(Mod); in ActOnModuleImport()
714 // An export-declaration shall inhabit a namespace scope and appear in the in ActOnModuleImport()
746 TU->addDecl(ImportD); in BuildModuleInclude()
775 for (auto *DC = CurContext; DC; DC = DC->getLexicalParent()) { in ActOnAnnotModuleBegin() local
776 cast<Decl>(DC)->setModuleOwnershipKind( in ActOnAnnotModuleBegin()
780 cast<Decl>(DC)->setLocalOwningModule(Mod); in ActOnAnnotModuleBegin()
816 for (auto *DC = CurContext; DC; DC = DC->getLexicalParent()) { in ActOnAnnotModuleEnd() local
817 cast<Decl>(DC)->setLocalOwningModule(getCurrentModule()); in ActOnAnnotModuleEnd()
819 cast<Decl>(DC)->setModuleOwnershipKind( in ActOnAnnotModuleEnd()
836 TU->addDecl(ImportD); in createImplicitModuleImportForErrorRecovery()
848 // Set this temporarily so we know the export-declaration was braced. in ActOnStartExportDecl()
849 D->setRBraceLoc(LBraceLoc); in ActOnStartExportDecl()
851 CurContext->addDecl(D); in ActOnStartExportDecl()
855 // An export-declaration shall appear only [...] in the purview of a module in ActOnStartExportDecl()
856 // interface unit. An export-declaration shall not appear directly or in ActOnStartExportDecl()
857 // indirectly within [...] a private-module-fragment. in ActOnStartExportDecl()
861 D->setInvalidDecl(); in ActOnStartExportDecl()
868 D->setInvalidDecl(); in ActOnStartExportDecl()
870 } else if (ModuleScopes.back().Module->Kind == in ActOnStartExportDecl()
874 D->setInvalidDecl(); in ActOnStartExportDecl()
879 for (const DeclContext *DC = CurContext; DC; DC = DC->getLexicalParent()) { in ActOnStartExportDecl() local
880 if (const auto *ND = dyn_cast<NamespaceDecl>(DC)) { in ActOnStartExportDecl()
881 // An export-declaration shall not appear directly or indirectly within in ActOnStartExportDecl()
883 if (ND->isAnonymousNamespace()) { in ActOnStartExportDecl()
885 Diag(ND->getLocation(), diag::note_anonymous_namespace); in ActOnStartExportDecl()
886 // Don't diagnose internal-linkage declarations in this region. in ActOnStartExportDecl()
887 D->setInvalidDecl(); in ActOnStartExportDecl()
891 // A declaration is exported if it is [...] a namespace-definition in ActOnStartExportDecl()
901 // [...] its declaration or declaration-seq shall not contain an in ActOnStartExportDecl()
902 // export-declaration. in ActOnStartExportDecl()
905 if (ED->hasBraces()) in ActOnStartExportDecl()
906 Diag(ED->getLocation(), diag::note_export); in ActOnStartExportDecl()
907 D->setInvalidDecl(); in ActOnStartExportDecl()
912 D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::VisibleWhenImported); in ActOnStartExportDecl()
919 /// Check that it's valid to export all the declarations in \p DC.
920 static bool checkExportedDeclContext(Sema &S, DeclContext *DC, in checkExportedDeclContext() argument
923 for (auto *D : DC->decls()) in checkExportedDeclContext()
928 /// Check that it's valid to export \p D.
931 // HLSL: export declaration is valid only on functions in checkExportedDecl()
933 // Export-within-export was already diagnosed in ActOnStartExportDecl in checkExportedDecl()
935 S.Diag(D->getBeginLoc(), diag::err_hlsl_export_not_on_function); in checkExportedDecl()
936 D->setInvalidDecl(); in checkExportedDecl()
947 HasName = (bool)ND->getDeclName(); in checkExportedDecl()
948 if (HasName && ND->getFormalLinkage() == Linkage::Internal) { in checkExportedDecl()
949 S.Diag(ND->getLocation(), diag::err_export_internal) << ND; in checkExportedDecl()
957 // all entities to which all of the using-declarators ultimately refer in checkExportedDecl()
960 NamedDecl *Target = USD->getUnderlyingDecl(); in checkExportedDecl()
961 Linkage Lk = Target->getFormalLinkage(); in checkExportedDecl()
963 S.Diag(USD->getLocation(), diag::err_export_using_internal) in checkExportedDecl()
965 S.Diag(Target->getLocation(), diag::note_using_decl_target); in checkExportedDecl()
972 // Recurse into namespace-scope DeclContexts. (Only namespace-scope in checkExportedDecl()
974 if (auto *DC = dyn_cast<DeclContext>(D)) { in checkExportedDecl() local
979 if (!ND->getDeclName()) { in checkExportedDecl()
980 S.Diag(ND->getLocation(), diag::err_export_anon_ns_internal); in checkExportedDecl()
984 } else if (!DC->decls().empty() && in checkExportedDecl()
985 DC->getRedeclContext()->isFileContext()) { in checkExportedDecl()
986 return checkExportedDeclContext(S, DC, BlockStart); in checkExportedDecl()
996 ED->setRBraceLoc(RBraceLoc); in ActOnFinishExportDecl()
1000 if (!D->isInvalidDecl()) { in ActOnFinishExportDecl()
1002 ED->hasBraces() ? ED->getBeginLoc() : SourceLocation(); in ActOnFinishExportDecl()
1003 for (auto *Child : ED->decls()) { in ActOnFinishExportDecl()
1013 if (FD->isInlineSpecified() && !FD->isDefined()) in ActOnFinishExportDecl()
1020 for (auto *Exported : ED->decls()) in ActOnFinishExportDecl()
1021 Exported->markUsed(getASTContext()); in ActOnFinishExportDecl()
1047 getCurrentModule()->isExplicitGlobalModule() && in PopGlobalModuleFragment()
1070 getCurrentModule()->isImplicitGlobalModule() && in PopImplicitGlobalModuleFragment()
1081 switch (getCurrentModule()->Kind) { in isCurrentModulePurview()