Skip to content

Commit c9cc803

Browse files
committed
[C++20][Modules][2/8] Add enumerations for partition modules and stream them.
This is an initial enabling patch for module partition support. We add enumerations for partition interfaces/implementations. This means that the module kind enumeration now occupies three bits, so the AST streamer is adjusted for this. Adding one bit there seems preferable to trying to overload the meanings of existing kinds (and we will also want to add a C++20 header unit case later). Differential Revision: https://reviews.llvm.org/D114714
1 parent d6a9eec commit c9cc803

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

clang/include/clang/Basic/Module.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,15 @@ class Module {
106106
/// of header files.
107107
ModuleMapModule,
108108

109-
/// This is a C++ Modules TS module interface unit.
109+
/// This is a C++20 module interface unit.
110110
ModuleInterfaceUnit,
111111

112+
/// This is a C++ 20 module partition interface.
113+
ModulePartitionInterface,
114+
115+
/// This is a C++ 20 module partition implementation.
116+
ModulePartitionImplementation,
117+
112118
/// This is a fragment of the global module within some C++ module.
113119
GlobalModuleFragment,
114120

@@ -150,7 +156,9 @@ class Module {
150156

151157
/// Does this Module scope describe part of the purview of a named C++ module?
152158
bool isModulePurview() const {
153-
return Kind == ModuleInterfaceUnit || Kind == PrivateModuleFragment;
159+
return Kind == ModuleInterfaceUnit || Kind == ModulePartitionInterface ||
160+
Kind == ModulePartitionImplementation ||
161+
Kind == PrivateModuleFragment;
154162
}
155163

156164
/// Does this Module scope describe a fragment of the global module within
@@ -506,6 +514,9 @@ class Module {
506514
Parent->SubModules.push_back(this);
507515
}
508516

517+
/// Is this a module partition.
518+
bool isModulePartition() const { return Name.find(':') != std::string::npos; }
519+
509520
/// Retrieve the full name of this module, including the path from
510521
/// its top-level module.
511522
/// \param AllowStringLiterals If \c true, components that might not be

clang/lib/AST/Decl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,8 @@ Module *Decl::getOwningModuleForLinkage(bool IgnoreLinkage) const {
15501550
return nullptr;
15511551

15521552
case Module::ModuleInterfaceUnit:
1553+
case Module::ModulePartitionInterface:
1554+
case Module::ModulePartitionImplementation:
15531555
return M;
15541556

15551557
case Module::GlobalModuleFragment: {

clang/lib/Sema/SemaModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ Sema::ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc,
261261
: ModuleScopes.back().Module->Kind) {
262262
case Module::ModuleMapModule:
263263
case Module::GlobalModuleFragment:
264+
case Module::ModulePartitionImplementation:
265+
case Module::ModulePartitionInterface:
264266
Diag(PrivateLoc, diag::err_private_module_fragment_not_module);
265267
return nullptr;
266268

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2674,7 +2674,7 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
26742674
Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION));
26752675
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID
26762676
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent
2677-
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Kind
2677+
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Kind
26782678
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework
26792679
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit
26802680
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem

0 commit comments

Comments
 (0)