19 #include "llvm/ADT/StringExtras.h"
22 using namespace clang;
27 bool FromInclude =
false) {
30 if (
auto *LSD = dyn_cast<LinkageSpecDecl>(DC)) {
31 switch (LSD->getLanguage()) {
34 ExternCLoc = LSD->getBeginLoc();
42 while (isa<LinkageSpecDecl>(DC) || isa<ExportDecl>(DC))
45 if (!isa<TranslationUnitDecl>(DC)) {
47 ? diag::ext_module_import_not_at_top_level_noop
48 : diag::err_module_import_not_at_top_level_fatal)
50 S.
Diag(cast<Decl>(DC)->getBeginLoc(),
51 diag::note_module_import_not_at_top_level)
54 S.
Diag(ImportLoc, diag::ext_module_import_in_extern_c)
56 S.
Diag(ExternCLoc, diag::note_extern_c_begins_here);
69 for (
auto &Piece :
Path) {
72 Name += Piece.first->getName();
87 Module *&FoundPrimaryModuleInterface) {
98 if (FoundPrimaryModuleInterface)
99 return Imported == FoundPrimaryModuleInterface;
114 assert(!FoundPrimaryModuleInterface ||
115 FoundPrimaryModuleInterface == Imported);
116 FoundPrimaryModuleInterface = Imported;
133 bool IsImportingPrimaryModuleInterface =
false) {
135 "'makeTransitiveImportsVisible()' is intended for standard C++ named "
139 Worklist.push_back(Imported);
141 Module *FoundPrimaryModuleInterface =
142 IsImportingPrimaryModuleInterface ? Imported :
nullptr;
144 while (!Worklist.empty()) {
145 Module *Importing = Worklist.pop_back_val();
152 VisibleModules.
setVisible(Importing, ImportLoc);
155 FoundPrimaryModuleInterface))
157 if (!VisibleModules.
isVisible(TransImported))
158 Worklist.push_back(TransImported);
166 PushGlobalModuleFragment(ModuleLoc);
178 TU->setLocalOwningModule(GlobalModule);
184 void Sema::HandleStartOfHeaderUnit() {
185 assert(getLangOpts().CPlusPlusModules &&
186 "Header units are only valid for C++20 modules");
188 SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
190 StringRef HUName = getLangOpts().CurrentModule;
191 if (HUName.empty()) {
193 SourceMgr.getFileEntryRefForID(SourceMgr.getMainFileID())->getName();
194 const_cast<LangOptions &
>(getLangOpts()).CurrentModule = HUName.str();
200 auto F = SourceMgr.getFileManager().getOptionalFileRef(HUName);
205 F = SourceMgr.getFileEntryRefForID(SourceMgr.getMainFileID());
206 assert(F &&
"failed to find the header unit source?");
207 Module::Header H{HUName.str(), HUName.str(), *F};
208 auto &Map = PP.getHeaderSearchInfo().getModuleMap();
209 Module *Mod = Map.createHeaderUnit(StartOfTU, HUName, H);
210 assert(Mod &&
"module creation should not fail");
211 ModuleScopes.push_back({});
212 ModuleScopes.back().BeginLoc = StartOfTU;
213 ModuleScopes.back().Module = Mod;
214 VisibleModules.setVisible(Mod, StartOfTU);
220 TU->setLocalOwningModule(Mod);
234 if (II->
isStr(
"module") || II->
isStr(
"import"))
250 return S.
Diag(
Loc, diag::err_invalid_module_name) << II;
252 S.
Diag(
Loc, diag::warn_reserved_module_name) << II;
255 llvm_unreachable(
"fell off a fully covered switch");
262 assert(getLangOpts().CPlusPlusModules &&
263 "should only have module decl in standard C++ modules");
265 bool IsFirstDecl = ImportState == ModuleImportState::FirstDecl;
266 bool SeenGMF = ImportState == ModuleImportState::GlobalFragment;
269 ImportState = ModuleImportState::NotACXX20Module;
271 bool IsPartition = !Partition.empty();
274 case ModuleDeclKind::Implementation:
275 MDK = ModuleDeclKind::PartitionImplementation;
277 case ModuleDeclKind::Interface:
278 MDK = ModuleDeclKind::PartitionInterface;
281 llvm_unreachable(
"how did we get a partition type set?");
289 switch (getLangOpts().getCompilingModule()) {
295 if (MDK != ModuleDeclKind::Implementation)
300 Diag(ModuleLoc, diag::err_module_interface_implementation_mismatch)
302 MDK = ModuleDeclKind::Interface;
306 Diag(ModuleLoc, diag::err_module_decl_in_module_map_module);
310 Diag(ModuleLoc, diag::err_module_decl_in_header_unit);
314 assert(ModuleScopes.size() <= 1 &&
"expected to be at global module scope");
320 if (isCurrentModulePurview()) {
321 Diag(ModuleLoc, diag::err_module_redeclaration);
322 Diag(VisibleModules.getImportLoc(ModuleScopes.back().Module),
323 diag::note_prev_module_declaration);
327 assert((!getLangOpts().CPlusPlusModules ||
328 SeenGMF == (
bool)this->TheGlobalModuleFragment) &&
329 "mismatched global module state");
333 if (getLangOpts().CPlusPlusModules && !IsFirstDecl && !SeenGMF) {
334 Diag(ModuleLoc, diag::err_module_decl_not_at_start);
337 ? SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID())
338 : ModuleScopes.back().BeginLoc;
340 Diag(BeginLoc, diag::note_global_module_introducer_missing)
354 StringRef FirstComponentName =
Path[0].first->getName();
355 if (!getSourceManager().isInSystemHeader(
Path[0].second) &&
356 (FirstComponentName ==
"std" ||
357 (FirstComponentName.starts_with(
"std") &&
358 llvm::all_of(FirstComponentName.drop_front(3), &
llvm::isDigit))))
359 Diag(
Path[0].second, diag::warn_reserved_module_name) <<
Path[0].first;
363 for (
auto Part :
Path) {
378 if (!getLangOpts().CurrentModule.empty() &&
379 getLangOpts().CurrentModule != ModuleName) {
380 Diag(
Path.front().second, diag::err_current_module_name_mismatch)
382 ? Partition.back().second
383 :
Path.back().second)
384 << getLangOpts().CurrentModule;
387 const_cast<LangOptions&
>(getLangOpts()).CurrentModule = ModuleName;
389 auto &Map = PP.getHeaderSearchInfo().getModuleMap();
393 case ModuleDeclKind::Interface:
394 case ModuleDeclKind::PartitionInterface: {
397 if (
auto *M = Map.findModule(ModuleName)) {
398 Diag(
Path[0].second, diag::err_module_redefinition) << ModuleName;
399 if (M->DefinitionLoc.isValid())
400 Diag(M->DefinitionLoc, diag::note_prev_module_definition);
402 Diag(M->DefinitionLoc, diag::note_prev_module_definition_from_ast_file)
409 Mod = Map.createModuleForInterfaceUnit(ModuleLoc, ModuleName);
410 if (MDK == ModuleDeclKind::PartitionInterface)
412 assert(Mod &&
"module creation should not fail");
416 case ModuleDeclKind::Implementation: {
421 std::pair<IdentifierInfo *, SourceLocation> ModuleNameLoc(
422 PP.getIdentifierInfo(ModuleName),
Path[0].second);
428 const_cast<LangOptions &
>(getLangOpts()).CurrentModule =
"";
429 Interface = getModuleLoader().loadModule(ModuleLoc, {ModuleNameLoc},
432 const_cast<LangOptions&
>(getLangOpts()).CurrentModule = ModuleName;
435 Diag(ModuleLoc, diag::err_module_not_defined) << ModuleName;
437 Mod = Map.createModuleForInterfaceUnit(ModuleLoc, ModuleName);
439 Mod = Map.createModuleForImplementationUnit(ModuleLoc, ModuleName);
443 case ModuleDeclKind::PartitionImplementation:
446 Mod = Map.createModuleForInterfaceUnit(ModuleLoc, ModuleName);
451 if (!this->TheGlobalModuleFragment) {
452 ModuleScopes.push_back({});
453 if (getLangOpts().ModulesLocalVisibility)
454 ModuleScopes.back().OuterVisibleModules = std::move(VisibleModules);
457 ActOnEndOfTranslationUnitFragment(TUFragmentKind::Global);
461 ModuleScopes.back().BeginLoc = StartLoc;
462 ModuleScopes.back().Module = Mod;
463 VisibleModules.setVisible(Mod, ModuleLoc);
472 TU->setLocalOwningModule(Mod);
476 ImportState = ModuleImportState::ImportAllowed;
478 getASTContext().setCurrentNamedModule(Mod);
480 if (
auto *Listener = getASTMutationListener())
481 Listener->EnteringModulePurview();
495 CurContext->addDecl(Import);
505 return ConvertDeclToDeclGroup(Import);
518 : ModuleScopes.back().Module->Kind) {
525 Diag(PrivateLoc, diag::err_private_module_fragment_not_module);
529 Diag(PrivateLoc, diag::err_private_module_fragment_redefined);
530 Diag(ModuleScopes.back().BeginLoc, diag::note_previous_definition);
534 Diag(PrivateLoc, diag::err_private_module_fragment_not_module_interface);
535 Diag(ModuleScopes.back().BeginLoc,
536 diag::note_not_module_interface_add_export)
549 ActOnEndOfTranslationUnitFragment(TUFragmentKind::Normal);
551 auto &Map = PP.getHeaderSearchInfo().getModuleMap();
552 Module *PrivateModuleFragment =
553 Map.createPrivateModuleFragmentForInterfaceUnit(
554 ModuleScopes.back().Module, PrivateLoc);
555 assert(PrivateModuleFragment &&
"module creation should not fail");
558 ModuleScopes.push_back({});
559 ModuleScopes.back().BeginLoc = ModuleLoc;
560 ModuleScopes.back().Module = PrivateModuleFragment;
561 VisibleModules.setVisible(PrivateModuleFragment, ModuleLoc);
568 TU->setLocalOwningModule(PrivateModuleFragment);
578 assert((!IsPartition || getLangOpts().CPlusPlusModules) &&
579 "partition seen in non-C++20 code?");
583 std::pair<IdentifierInfo *, SourceLocation> ModuleNameLoc;
585 std::string ModuleName;
588 assert(!ModuleScopes.empty() &&
"in a module purview, but no module?");
595 ModuleNameLoc = {PP.getIdentifierInfo(ModuleName),
Path[0].second};
597 }
else if (getLangOpts().CPlusPlusModules) {
599 ModuleNameLoc = {PP.getIdentifierInfo(ModuleName),
Path[0].second};
610 if (getLangOpts().CPlusPlusModules && isCurrentModulePurview() &&
611 getCurrentModule()->Name == ModuleName) {
612 Diag(ImportLoc, diag::err_module_self_import_cxx20)
613 << ModuleName << currentModuleIsImplementation();
617 Module *Mod = getModuleLoader().loadModule(
623 !getLangOpts().ObjC) {
624 Diag(ImportLoc, diag::err_module_import_non_interface_nor_parition)
629 return ActOnModuleImport(StartLoc, ExportLoc, ImportLoc, Mod,
Path);
635 if (
auto *ED = dyn_cast<ExportDecl>(DC))
645 Diag(ImportLoc, diag::warn_experimental_header_unit);
649 getCurrentModule(), ImportLoc);
651 VisibleModules.setVisible(Mod, ImportLoc);
660 Diag(ImportLoc, getLangOpts().isCompilingModule()
661 ? diag::err_module_self_import
662 : diag::err_module_import_in_implementation)
672 for (
Module *ModCheck = Mod; ModCheck; ModCheck = ModCheck->
Parent)
674 }
else if (getLangOpts().CPlusPlusModules && !Mod->
Parent) {
676 IdentifierLocs.push_back(
Path[0].second);
679 for (
unsigned I = 0, N =
Path.size(); I != N; ++I) {
684 ModCheck = ModCheck->
Parent;
686 IdentifierLocs.push_back(
Path[I].second);
691 Mod, IdentifierLocs);
692 CurContext->addDecl(Import);
696 if (!ModuleScopes.empty())
700 if (getLangOpts().CPlusPlusModules && ExportLoc.
isValid() &&
701 Mod->
Kind == Module::ModuleKind::ModulePartitionImplementation) {
702 Diag(ExportLoc, diag::err_export_partition_impl)
704 }
else if (!ModuleScopes.empty() && !currentModuleIsImplementation()) {
709 getCurrentModule()->Exports.emplace_back(Mod,
false);
711 getCurrentModule()->Imports.insert(Mod);
712 }
else if (ExportLoc.
isValid()) {
716 Diag(ExportLoc, diag::err_export_not_in_module_interface);
724 BuildModuleInclude(DirectiveLoc, Mod);
733 bool IsInModuleIncludes =
735 getSourceManager().isWrittenInMainFile(DirectiveLoc);
739 if (getLangOpts().Modules && !IsInModuleIncludes) {
744 if (!ModuleScopes.empty())
747 Consumer.HandleImplicitImportDecl(ImportD);
751 VisibleModules.setVisible(Mod, DirectiveLoc);
753 if (getLangOpts().isCompilingModule()) {
754 Module *ThisModule = PP.getHeaderSearchInfo().lookupModule(
755 getLangOpts().CurrentModule, DirectiveLoc,
false,
false);
757 assert(ThisModule &&
"was expecting a module if building one");
764 ModuleScopes.push_back({});
765 ModuleScopes.back().Module = Mod;
766 if (getLangOpts().ModulesLocalVisibility)
767 ModuleScopes.back().OuterVisibleModules = std::move(VisibleModules);
769 VisibleModules.setVisible(Mod, DirectiveLoc);
774 if (getLangOpts().trackLocalOwningModule()) {
775 for (
auto *DC = CurContext; DC; DC = DC->getLexicalParent()) {
776 cast<Decl>(DC)->setModuleOwnershipKind(
777 getLangOpts().ModulesLocalVisibility
780 cast<Decl>(DC)->setLocalOwningModule(Mod);
786 if (getLangOpts().ModulesLocalVisibility) {
787 VisibleModules = std::move(ModuleScopes.back().OuterVisibleModules);
790 VisibleNamespaceCache.clear();
793 assert(!ModuleScopes.empty() && ModuleScopes.back().Module == Mod &&
794 "left the wrong module scope");
795 ModuleScopes.pop_back();
799 FileID File = getSourceManager().getFileID(EomLoc);
801 if (EomLoc == getSourceManager().getLocForEndOfFile(
File)) {
803 assert(
File != getSourceManager().getMainFileID() &&
804 "end of submodule in main source file");
805 DirectiveLoc = getSourceManager().getIncludeLoc(
File);
808 DirectiveLoc = EomLoc;
810 BuildModuleInclude(DirectiveLoc, Mod);
813 if (getLangOpts().trackLocalOwningModule()) {
816 for (
auto *DC = CurContext; DC; DC = DC->getLexicalParent()) {
817 cast<Decl>(DC)->setLocalOwningModule(getCurrentModule());
818 if (!getCurrentModule())
819 cast<Decl>(DC)->setModuleOwnershipKind(
828 if (isSFINAEContext() || !getLangOpts().ModulesErrorRecovery ||
829 VisibleModules.isVisible(Mod))
837 Consumer.HandleImplicitImportDecl(ImportD);
841 VisibleModules.setVisible(Mod,
Loc);
849 D->setRBraceLoc(LBraceLoc);
851 CurContext->addDecl(
D);
852 PushDeclContext(S,
D);
858 if (!getLangOpts().
HLSL) {
859 if (!isCurrentModulePurview()) {
860 Diag(ExportLoc, diag::err_export_not_in_module_interface) << 0;
863 }
else if (currentModuleIsImplementation()) {
864 Diag(ExportLoc, diag::err_export_not_in_module_interface) << 1;
865 Diag(ModuleScopes.back().BeginLoc,
866 diag::note_not_module_interface_add_export)
870 }
else if (ModuleScopes.back().Module->Kind ==
872 Diag(ExportLoc, diag::err_export_in_private_module_fragment);
873 Diag(ModuleScopes.back().BeginLoc, diag::note_private_module_fragment);
880 if (
const auto *ND = dyn_cast<NamespaceDecl>(DC)) {
883 if (ND->isAnonymousNamespace()) {
884 Diag(ExportLoc, diag::err_export_within_anonymous_namespace);
885 Diag(ND->getLocation(), diag::note_anonymous_namespace);
896 if (!getLangOpts().
HLSL && !DeferredExportedNamespaces.insert(ND).second)
904 Diag(ExportLoc, diag::err_export_within_export);
906 Diag(ED->getLocation(), diag::note_export);
911 if (!getLangOpts().
HLSL)
922 bool AllUnnamed =
true;
923 for (
auto *
D : DC->
decls())
934 if (!dyn_cast<FunctionDecl>(
D) && !dyn_cast<ExportDecl>(
D)) {
943 bool HasName =
false;
944 if (
auto *ND = dyn_cast<NamedDecl>(
D)) {
947 HasName = (
bool)ND->getDeclName();
949 S.
Diag(ND->getLocation(), diag::err_export_internal) << ND;
951 S.
Diag(BlockStart, diag::note_export);
959 if (
auto *USD = dyn_cast<UsingShadowDecl>(
D)) {
963 S.
Diag(USD->getLocation(), diag::err_export_using_internal)
965 S.
Diag(
Target->getLocation(), diag::note_using_decl_target);
967 S.
Diag(BlockStart, diag::note_export);
974 if (
auto *DC = dyn_cast<DeclContext>(
D)) {
975 if (!isa<NamespaceDecl>(
D))
978 if (
auto *ND = dyn_cast<NamedDecl>(
D)) {
979 if (!ND->getDeclName()) {
980 S.
Diag(ND->getLocation(), diag::err_export_anon_ns_internal);
982 S.
Diag(BlockStart, diag::note_export);
984 }
else if (!DC->decls().empty() &&
985 DC->getRedeclContext()->isFileContext()) {
994 auto *ED = cast<ExportDecl>(
D);
996 ED->setRBraceLoc(RBraceLoc);
1003 for (
auto *Child : ED->decls()) {
1005 if (
auto *FD = dyn_cast<FunctionDecl>(Child)) {
1013 if (FD->isInlineSpecified() && !FD->isDefined())
1014 PendingInlineFuncDecls.insert(FD);
1020 for (
auto *Exported : ED->decls())
1021 Exported->markUsed(getASTContext());
1029 if (!TheGlobalModuleFragment) {
1030 ModuleMap &Map = PP.getHeaderSearchInfo().getModuleMap();
1032 BeginLoc, getCurrentModule());
1035 assert(TheGlobalModuleFragment &&
"module creation should not fail");
1038 ModuleScopes.push_back({BeginLoc, TheGlobalModuleFragment,
1040 VisibleModules.setVisible(TheGlobalModuleFragment, BeginLoc);
1042 return TheGlobalModuleFragment;
1045 void Sema::PopGlobalModuleFragment() {
1046 assert(!ModuleScopes.empty() &&
1047 getCurrentModule()->isExplicitGlobalModule() &&
1048 "left the wrong module scope, which is not global module fragment");
1049 ModuleScopes.pop_back();
1053 if (!TheImplicitGlobalModuleFragment) {
1054 ModuleMap &Map = PP.getHeaderSearchInfo().getModuleMap();
1055 TheImplicitGlobalModuleFragment =
1057 getCurrentModule());
1059 assert(TheImplicitGlobalModuleFragment &&
"module creation should not fail");
1062 ModuleScopes.push_back({BeginLoc, TheImplicitGlobalModuleFragment,
1064 VisibleModules.setVisible(TheImplicitGlobalModuleFragment, BeginLoc);
1065 return TheImplicitGlobalModuleFragment;
1068 void Sema::PopImplicitGlobalModuleFragment() {
1069 assert(!ModuleScopes.empty() &&
1070 getCurrentModule()->isImplicitGlobalModule() &&
1071 "left the wrong module scope, which is not global module fragment");
1072 ModuleScopes.pop_back();
1075 bool Sema::isCurrentModulePurview()
const {
1076 if (!getCurrentModule())
1081 switch (getCurrentModule()->
Kind) {
enum clang::sema::@1659::IndirectLocalPathEntry::EntryKind Kind
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Target Target
Defines the clang::Preprocessor interface.
static void makeTransitiveImportsVisible(ASTContext &Ctx, VisibleModuleSet &VisibleModules, Module *Imported, Module *CurrentModule, SourceLocation ImportLoc, bool IsImportingPrimaryModuleInterface=false)
[module.import]p7: Additionally, when a module-import-declaration in a module unit of some module M i...
static const ExportDecl * getEnclosingExportDecl(const Decl *D)
Determine whether D is lexically within an export-declaration.
static bool DiagReservedModuleName(Sema &S, const IdentifierInfo *II, SourceLocation Loc)
Tests whether the given identifier is reserved as a module name and diagnoses if it is.
static bool checkExportedDecl(Sema &, Decl *, SourceLocation)
Check that it's valid to export D.
static std::string stringFromPath(ModuleIdPath Path)
static void checkModuleImportContext(Sema &S, Module *M, SourceLocation ImportLoc, DeclContext *DC, bool FromInclude=false)
static bool checkExportedDeclContext(Sema &S, DeclContext *DC, SourceLocation BlockStart)
Check that it's valid to export all the declarations in DC.
static bool isImportingModuleUnitFromSameModule(ASTContext &Ctx, Module *Imported, Module *CurrentModule, Module *&FoundPrimaryModuleInterface)
Helper function for makeTransitiveImportsVisible to decide whether the.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void addModuleInitializer(Module *M, Decl *Init)
Add a declaration to the list of declarations that are initialized for a module.
bool isInSameModule(const Module *M1, const Module *M2)
If the two module M1 and M2 are in the same module.
TranslationUnitDecl * getTranslationUnitDecl() const
The result of parsing/analyzing an expression, statement etc.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
void addDecl(Decl *D)
Add the declaration D into this context.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Decl - This represents one declaration (or definition), e.g.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
bool isInvalidDecl() const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
SourceLocation getBeginLoc() const LLVM_READONLY
TranslationUnitDecl * getTranslationUnitDecl()
@ VisibleWhenImported
This declaration has an owning module, and is visible when that module is imported.
@ Unowned
This declaration is not owned by a module.
@ ReachableWhenImported
This declaration has an owning module, and is visible to lookups that occurs within that module.
@ ModulePrivate
This declaration has an owning module, but is only visible to lookups that occur within that module.
@ Visible
This declaration has an owning module, but is globally visible (typically because its owning module i...
void setModuleOwnershipKind(ModuleOwnershipKind MOK)
Set whether this declaration is hidden from name lookup.
Represents a standard C++ module export declaration.
static ExportDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation ExportLoc)
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
One of these records is kept for each identifier that is lexed.
ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const
Determine whether this is a name reserved for the implementation (C99 7.1.3, C++ [lib....
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
static ImportDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, Module *Imported, ArrayRef< SourceLocation > IdentifierLocs)
Create a new module import declaration.
static ImportDecl * CreateImplicit(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, Module *Imported, SourceLocation EndLoc)
Create a new module import declaration for an implicitly-generated import.
@ CMK_None
Not compiling a module interface at all.
@ CMK_HeaderUnit
Compiling a module header unit.
@ CMK_ModuleMap
Compiling a module from a module map.
@ CMK_ModuleInterface
Compiling a C++ modules interface unit.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Module * createGlobalModuleFragmentForModuleUnit(SourceLocation Loc, Module *Parent=nullptr)
Create a global module fragment for a C++ module unit.
Module * createImplicitGlobalModuleFragmentForModuleUnit(SourceLocation Loc, Module *Parent)
Describes a module or submodule.
bool isForBuilding(const LangOptions &LangOpts) const
Determine whether this module can be built in this compilation.
bool isInterfaceOrPartition() const
bool isModulePartitionImplementation() const
Is this a module partition implementation unit.
@ AllVisible
All of the names in this module are visible.
Module * Parent
The parent of this module.
ModuleKind Kind
The kind of this module.
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "C"...
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
bool isModulePartition() const
Is this a module partition.
bool isHeaderUnit() const
Is this module a header unit.
@ ModuleImplementationUnit
This is a C++20 module implementation unit.
@ ModuleMapModule
This is a module that was defined by a module map and built out of header files.
@ ImplicitGlobalModuleFragment
This is an implicit fragment of the global module which contains only language linkage declarations (...
@ ModulePartitionInterface
This is a C++20 module partition interface.
@ ModuleInterfaceUnit
This is a C++20 module interface unit.
@ ModuleHeaderUnit
This is a C++20 header unit.
@ ModulePartitionImplementation
This is a C++20 module partition implementation.
@ PrivateModuleFragment
This is the private module fragment within some C++ module.
@ ExplicitGlobalModuleFragment
This is the explicit Global Module Fragment of a modular TU.
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, bool IsFramework, bool IsExplicit, unsigned VisibilityID)
Construct a new module or submodule.
This represents a decl that may have a name.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
Wrapper for void* pointer.
Scope - A scope is a transient data structure that is used while parsing the program.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Sema - This implements semantic analysis and AST building for C.
void ActOnAnnotModuleBegin(SourceLocation DirectiveLoc, Module *Mod)
The parsed has entered a submodule.
void ActOnAnnotModuleInclude(SourceLocation DirectiveLoc, Module *Mod)
The parser has processed a module import translated from a #include or similar preprocessing directiv...
DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, ModuleDeclKind MDK, ModuleIdPath Path, ModuleIdPath Partition, ModuleImportState &ImportState)
The parser has processed a module-declaration that begins the definition of a module interface or imp...
void ActOnAnnotModuleEnd(SourceLocation DirectiveLoc, Module *Mod)
The parser has left a submodule.
DeclResult ActOnModuleImport(SourceLocation StartLoc, SourceLocation ExportLoc, SourceLocation ImportLoc, ModuleIdPath Path, bool IsPartition=false)
The parser has processed a module import declaration.
Decl * ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, SourceLocation LBraceLoc)
We have parsed the start of an export declaration, including the '{' (if present).
const LangOptions & getLangOpts() const
DeclGroupPtrTy ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc)
The parser has processed a global-module-fragment declaration that begins the definition of the globa...
DeclGroupPtrTy ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc, SourceLocation PrivateLoc)
The parser has processed a private-module-fragment declaration that begins the definition of the priv...
SourceManager & getSourceManager() const
void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod)
bool isModuleVisible(const Module *M, bool ModulePrivate=false)
ModuleImportState
An enumeration to represent the transition of states in parsing module fragments and imports.
Decl * ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, SourceLocation RBraceLoc)
Complete the definition of an export declaration.
void createImplicitModuleImportForErrorRecovery(SourceLocation Loc, Module *Mod)
Create an implicit import of the given module at the given source location, for error recovery,...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
A trivial tuple used to represent a source range.
The top declaration context.
A set of visible modules.
bool isVisible(const Module *M) const
Determine whether a module is visible.
void setVisible(Module *M, SourceLocation Loc, VisibleCallback Vis=[](Module *) {}, ConflictCallback Cb=[](ArrayRef< Module * >, Module *, StringRef) {})
Make a specific module visible.
The JSON file list parser is used to communicate input to InstallAPI.
ArrayRef< std::pair< IdentifierInfo *, SourceLocation > > ModuleIdPath
A sequence of identifier/location pairs used to describe a particular module or submodule,...
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
@ TU_ClangModule
The translation unit is a clang module.
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.