[clang] e8541e4 - [NFC] [Modules] Rename modules related things in Preprocessor and AffectingModules
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 27 01:40:53 PDT 2022
Author: Chuanqi Xu
Date: 2022-10-27T16:40:26+08:00
New Revision: e8541e4b42c54e106940b846123508742e026b7d
URL: https://github.com/llvm/llvm-project/commit/e8541e4b42c54e106940b846123508742e026b7d
DIFF: https://github.com/llvm/llvm-project/commit/e8541e4b42c54e106940b846123508742e026b7d.diff
LOG: [NFC] [Modules] Rename modules related things in Preprocessor and AffectingModules
Rename module related things according to the consensus in
https://discourse.llvm.org/t/rfc-unifying-the-terminology-about-modules-in-clang/66054/
to reduce further confusings.
This only renames things I can make sure. It doesn't mean all the names
in Preprocessor are correct now.
Added:
Modified:
clang/include/clang/Basic/Module.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Serialization/ASTWriter.h
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/Preprocessor.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h
index 5f8882e4a00d5..3e9669ced1009 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -349,7 +349,7 @@ class alignas(8) Module {
/// The set of top-level modules that affected the compilation of this module,
/// but were not imported.
- llvm::SmallSetVector<Module *, 2> AffectingModules;
+ llvm::SmallSetVector<Module *, 2> AffectingClangModules;
/// Describes an exported module.
///
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 2c0f8f3a632ff..bf39153e3d3c4 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -315,14 +315,14 @@ class Preprocessor {
/// lexed, if any.
SourceLocation ModuleImportLoc;
- /// The module import path that we're currently processing.
- SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> ModuleImportPath;
+ /// The import path for named module that we're currently processing.
+ SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> NamedModuleImportPath;
/// Whether the last token we lexed was an '@'.
bool LastTokenWasAt = false;
/// A position within a C++20 import-seq.
- class ImportSeq {
+ class StdCXXImportSeq {
public:
enum State : int {
// Positive values represent a number of unclosed brackets.
@@ -332,7 +332,7 @@ class Preprocessor {
AfterImportSeq = -3,
};
- ImportSeq(State S) : S(S) {}
+ StdCXXImportSeq(State S) : S(S) {}
/// Saw any kind of open bracket.
void handleOpenBracket() {
@@ -398,7 +398,7 @@ class Preprocessor {
};
/// Our current position within a C++20 import-seq.
- ImportSeq ImportSeqState = ImportSeq::AfterTopLevelTokenSeq;
+ StdCXXImportSeq StdCXXImportSeqState = StdCXXImportSeq::AfterTopLevelTokenSeq;
/// Track whether we are in a Global Module Fragment
class TrackGMF {
@@ -865,7 +865,7 @@ class Preprocessor {
/// The set of top-level modules that affected preprocessing, but were not
/// imported.
- llvm::SmallSetVector<Module *, 2> AffectingModules;
+ llvm::SmallSetVector<Module *, 2> AffectingClangModules;
/// The set of known macros exported from modules.
llvm::FoldingSet<ModuleMacro> ModuleMacros;
@@ -1329,20 +1329,21 @@ class Preprocessor {
/// \}
- /// Mark the given module as affecting the current module or translation unit.
- void markModuleAsAffecting(Module *M) {
+ /// Mark the given clang module as affecting the current clang module or translation unit.
+ void markClangModuleAsAffecting(Module *M) {
+ assert(M->isModuleMapModule());
if (!BuildingSubmoduleStack.empty()) {
if (M != BuildingSubmoduleStack.back().M)
- BuildingSubmoduleStack.back().M->AffectingModules.insert(M);
+ BuildingSubmoduleStack.back().M->AffectingClangModules.insert(M);
} else {
- AffectingModules.insert(M);
+ AffectingClangModules.insert(M);
}
}
- /// Get the set of top-level modules that affected preprocessing, but were not
+ /// Get the set of top-level clang modules that affected preprocessing, but were not
/// imported.
- const llvm::SmallSetVector<Module *, 2> &getAffectingModules() const {
- return AffectingModules;
+ const llvm::SmallSetVector<Module *, 2> &getAffectingClangModules() const {
+ return AffectingClangModules;
}
/// Mark the file as included.
diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h
index 530c816fc6c3e..81e5fac4a7294 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -466,7 +466,7 @@ class ASTWriter : public ASTDeserializationListener,
createSignature(StringRef AllBytes, StringRef ASTBlockBytes);
void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts,
- std::set<const FileEntry *> &AffectingModuleMaps);
+ std::set<const FileEntry *> &AffectingClangModuleMaps);
void WriteSourceManagerBlock(SourceManager &SourceMgr,
const Preprocessor &PP);
void writeIncludedFiles(raw_ostream &Out, const Preprocessor &PP);
diff --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index e495f33701246..5062c4cc5e265 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -169,9 +169,9 @@ class ModuleDepCollectorPP final : public PPCallbacks {
/// Traverses the affecting modules and updates \c MD with references to the
/// parent \c ModuleDepCollector info.
- void addAllAffectingModules(const Module *M, ModuleDeps &MD,
+ void addAllAffectingClangModules(const Module *M, ModuleDeps &MD,
llvm::DenseSet<const Module *> &AddedModules);
- void addAffectingModule(const Module *M, ModuleDeps &MD,
+ void addAffectingClangModule(const Module *M, ModuleDeps &MD,
llvm::DenseSet<const Module *> &AddedModules);
};
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index c28eaba80fba8..6402f1607485f 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -2031,7 +2031,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
Sub = loadModule(ImportLoc, PrivPath, Visibility, IsInclusionDirective);
if (Sub) {
MapPrivateSubModToTopLevel = true;
- PP->markModuleAsAffecting(Module);
+ PP->markClangModuleAsAffecting(Module);
if (!getDiagnostics().isIgnored(
diag::warn_no_priv_submodule_use_toplevel, ImportLoc)) {
getDiagnostics().Report(Path[I].second,
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 72303452f9334..65316f4e79617 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1594,7 +1594,7 @@ static bool suggestModule(HeaderSearch &HS, const FileEntry *File,
return true;
}
// TODO: Add this module (or just its module map file) into something like
- // `RequestingModule->AffectingModules`.
+ // `RequestingModule->AffectingClangModules`.
return false;
}
}
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 3fc0606d62b9a..20f173a5b8809 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -2241,14 +2241,14 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
}
}
// Maybe a usable clang header module.
- bool UsableHeaderModule =
+ bool UsableClangHeaderModule =
(getLangOpts().CPlusPlusModules || getLangOpts().Modules) && SM &&
!SM->isHeaderUnit();
// Determine whether we should try to import the module for this #include, if
// there is one. Don't do so if precompiled module support is disabled or we
// are processing this module textually (because we're building the module).
- if (MaybeTranslateInclude && (UsableHeaderUnit || UsableHeaderModule)) {
+ if (MaybeTranslateInclude && (UsableHeaderUnit || UsableClangHeaderModule)) {
// If this include corresponds to a module but that module is
// unavailable, diagnose the situation and bail out.
// FIXME: Remove this; loadModule does the same check (but produces
@@ -2287,7 +2287,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
if (Imported) {
Action = Import;
} else if (Imported.isMissingExpected()) {
- markModuleAsAffecting(
+ markClangModuleAsAffecting(
static_cast<Module *>(Imported)->getTopLevelModule());
// We failed to find a submodule that we assumed would exist (because it
// was in the directory of an umbrella header, for instance), but no
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 3b11a7a58b681..281683be8d06a 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -871,7 +871,7 @@ bool Preprocessor::HandleIdentifier(Token &Identifier) {
(getLangOpts().Modules || getLangOpts().DebuggerSupport) &&
CurLexerKind != CLK_CachingLexer) {
ModuleImportLoc = Identifier.getLocation();
- ModuleImportPath.clear();
+ NamedModuleImportPath.clear();
ModuleImportExpectsIdentifier = true;
CurLexerKind = CLK_LexAfterModuleImport;
}
@@ -916,57 +916,57 @@ void Preprocessor::Lex(Token &Result) {
Result.setIdentifierInfo(nullptr);
}
- // Update ImportSeqState to track our position within a C++20 import-seq
+ // Update StdCXXImportSeqState to track our position within a C++20 import-seq
// if this token is being produced as a result of phase 4 of translation.
// Update TrackGMFState to decide if we are currently in a Global Module
- // Fragment. GMF state updates should precede ImportSeq ones, since GMF state
- // depends on the prevailing ImportSeq state in two cases.
+ // Fragment. GMF state updates should precede StdCXXImportSeq ones, since GMF state
+ // depends on the prevailing StdCXXImportSeq state in two cases.
if (getLangOpts().CPlusPlusModules && LexLevel == 1 &&
!Result.getFlag(Token::IsReinjected)) {
switch (Result.getKind()) {
case tok::l_paren: case tok::l_square: case tok::l_brace:
- ImportSeqState.handleOpenBracket();
+ StdCXXImportSeqState.handleOpenBracket();
break;
case tok::r_paren: case tok::r_square:
- ImportSeqState.handleCloseBracket();
+ StdCXXImportSeqState.handleCloseBracket();
break;
case tok::r_brace:
- ImportSeqState.handleCloseBrace();
+ StdCXXImportSeqState.handleCloseBrace();
break;
// This token is injected to represent the translation of '#include "a.h"'
// into "import a.h;". Mimic the notional ';'.
case tok::annot_module_include:
case tok::semi:
TrackGMFState.handleSemi();
- ImportSeqState.handleSemi();
+ StdCXXImportSeqState.handleSemi();
break;
case tok::header_name:
case tok::annot_header_unit:
- ImportSeqState.handleHeaderName();
+ StdCXXImportSeqState.handleHeaderName();
break;
case tok::kw_export:
TrackGMFState.handleExport();
- ImportSeqState.handleExport();
+ StdCXXImportSeqState.handleExport();
break;
case tok::identifier:
if (Result.getIdentifierInfo()->isModulesImport()) {
- TrackGMFState.handleImport(ImportSeqState.afterTopLevelSeq());
- ImportSeqState.handleImport();
- if (ImportSeqState.afterImportSeq()) {
+ TrackGMFState.handleImport(StdCXXImportSeqState.afterTopLevelSeq());
+ StdCXXImportSeqState.handleImport();
+ if (StdCXXImportSeqState.afterImportSeq()) {
ModuleImportLoc = Result.getLocation();
- ModuleImportPath.clear();
+ NamedModuleImportPath.clear();
ModuleImportExpectsIdentifier = true;
CurLexerKind = CLK_LexAfterModuleImport;
}
break;
} else if (Result.getIdentifierInfo() == getIdentifierInfo("module")) {
- TrackGMFState.handleModule(ImportSeqState.afterTopLevelSeq());
+ TrackGMFState.handleModule(StdCXXImportSeqState.afterTopLevelSeq());
break;
}
[[fallthrough]];
default:
TrackGMFState.handleMisc();
- ImportSeqState.handleMisc();
+ StdCXXImportSeqState.handleMisc();
break;
}
}
@@ -1147,7 +1147,7 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) {
// For now, we only support header-name imports in C++20 mode.
// FIXME: Should we allow this in all language modes that support an import
// declaration as an extension?
- if (ModuleImportPath.empty() && getLangOpts().CPlusPlusModules) {
+ if (NamedModuleImportPath.empty() && getLangOpts().CPlusPlusModules) {
if (LexHeaderName(Result))
return true;
} else {
@@ -1243,7 +1243,7 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) {
if (ModuleImportExpectsIdentifier && Result.getKind() == tok::identifier) {
// We expected to see an identifier here, and we did; continue handling
// identifiers.
- ModuleImportPath.push_back(std::make_pair(Result.getIdentifierInfo(),
+ NamedModuleImportPath.push_back(std::make_pair(Result.getIdentifierInfo(),
Result.getLocation()));
ModuleImportExpectsIdentifier = false;
CurLexerKind = CLK_LexAfterModuleImport;
@@ -1260,7 +1260,7 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) {
}
// If we didn't recognize a module name at all, this is not a (valid) import.
- if (ModuleImportPath.empty() || Result.is(tok::eof))
+ if (NamedModuleImportPath.empty() || Result.is(tok::eof))
return true;
// Consume the pp-import-suffix and expand any macros in it now, if we're not
@@ -1283,28 +1283,28 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) {
// FIXME: Is this the right level to be performing this transformation?
std::string FlatModuleName;
if (getLangOpts().ModulesTS || getLangOpts().CPlusPlusModules) {
- for (auto &Piece : ModuleImportPath) {
+ for (auto &Piece : NamedModuleImportPath) {
if (!FlatModuleName.empty())
FlatModuleName += ".";
FlatModuleName += Piece.first->getName();
}
- SourceLocation FirstPathLoc = ModuleImportPath[0].second;
- ModuleImportPath.clear();
- ModuleImportPath.push_back(
+ SourceLocation FirstPathLoc = NamedModuleImportPath[0].second;
+ NamedModuleImportPath.clear();
+ NamedModuleImportPath.push_back(
std::make_pair(getIdentifierInfo(FlatModuleName), FirstPathLoc));
}
Module *Imported = nullptr;
if (getLangOpts().Modules) {
Imported = TheModuleLoader.loadModule(ModuleImportLoc,
- ModuleImportPath,
+ NamedModuleImportPath,
Module::Hidden,
/*IsInclusionDirective=*/false);
if (Imported)
makeModuleVisible(Imported, SemiLoc);
}
if (Callbacks)
- Callbacks->moduleImport(ModuleImportLoc, ModuleImportPath, Imported);
+ Callbacks->moduleImport(ModuleImportLoc, NamedModuleImportPath, Imported);
if (!Suffix.empty()) {
EnterTokens(Suffix);
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index b2ab6b84aebb3..d1132032c71fc 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -4379,7 +4379,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
case UnresolvedModuleRef::Affecting:
if (ResolvedMod)
- Unresolved.Mod->AffectingModules.insert(ResolvedMod);
+ Unresolved.Mod->AffectingClangModules.insert(ResolvedMod);
continue;
case UnresolvedModuleRef::Export:
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index b019b6f48a63a..b70eb9526e19b 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1477,15 +1477,15 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
Record.push_back(SM.getMainFileID().getOpaqueValue());
Stream.EmitRecord(ORIGINAL_FILE_ID, Record);
- std::set<const FileEntry *> AffectingModuleMaps;
+ std::set<const FileEntry *> AffectingClangModuleMaps;
if (WritingModule) {
- AffectingModuleMaps =
+ AffectingClangModuleMaps =
GetAllModuleMaps(PP.getHeaderSearchInfo(), WritingModule);
}
WriteInputFiles(Context.SourceMgr,
PP.getHeaderSearchInfo().getHeaderSearchOpts(),
- AffectingModuleMaps);
+ AffectingClangModuleMaps);
Stream.ExitBlock();
}
@@ -1505,7 +1505,7 @@ struct InputFileEntry {
void ASTWriter::WriteInputFiles(
SourceManager &SourceMgr, HeaderSearchOptions &HSOpts,
- std::set<const FileEntry *> &AffectingModuleMaps) {
+ std::set<const FileEntry *> &AffectingClangModuleMaps) {
using namespace llvm;
Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4);
@@ -1547,9 +1547,9 @@ void ASTWriter::WriteInputFiles(
if (isModuleMap(File.getFileCharacteristic()) &&
!isSystem(File.getFileCharacteristic()) &&
- !AffectingModuleMaps.empty() &&
- AffectingModuleMaps.find(Cache->OrigEntry) ==
- AffectingModuleMaps.end()) {
+ !AffectingClangModuleMaps.empty() &&
+ AffectingClangModuleMaps.find(Cache->OrigEntry) ==
+ AffectingClangModuleMaps.end()) {
SkippedModuleMaps.insert(Cache->OrigEntry);
// Do not emit modulemaps that do not affect current module.
continue;
@@ -2876,9 +2876,9 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
}
// Emit the modules affecting compilation that were not imported.
- if (!Mod->AffectingModules.empty()) {
+ if (!Mod->AffectingClangModules.empty()) {
RecordData Record;
- for (auto *I : Mod->AffectingModules)
+ for (auto *I : Mod->AffectingClangModules)
Record.push_back(getSubmoduleID(I));
Stream.EmitRecord(SUBMODULE_AFFECTING_MODULES, Record);
}
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 2f3444d74b10b..f0fed7d12f3de 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -371,7 +371,7 @@ void ModuleDepCollectorPP::EndOfMainFile() {
MDC.addFileDep(MDC.ScanInstance.getPreprocessorOpts().ImplicitPCHInclude);
for (const Module *M :
- MDC.ScanInstance.getPreprocessor().getAffectingModules())
+ MDC.ScanInstance.getPreprocessor().getAffectingClangModules())
if (!MDC.isPrebuiltModule(M))
DirectModularDeps.insert(M);
@@ -444,7 +444,7 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
llvm::DenseSet<const Module *> SeenDeps;
addAllSubmodulePrebuiltDeps(M, MD, SeenDeps);
addAllSubmoduleDeps(M, MD, SeenDeps);
- addAllAffectingModules(M, MD, SeenDeps);
+ addAllAffectingClangModules(M, MD, SeenDeps);
MDC.ScanInstance.getASTReader()->visitTopLevelModuleMaps(
*MF, [&](const FileEntry *FE) {
@@ -527,19 +527,19 @@ void ModuleDepCollectorPP::addModuleDep(
}
}
-void ModuleDepCollectorPP::addAllAffectingModules(
+void ModuleDepCollectorPP::addAllAffectingClangModules(
const Module *M, ModuleDeps &MD,
llvm::DenseSet<const Module *> &AddedModules) {
- addAffectingModule(M, MD, AddedModules);
+ addAffectingClangModule(M, MD, AddedModules);
for (const Module *SubM : M->submodules())
- addAllAffectingModules(SubM, MD, AddedModules);
+ addAllAffectingClangModules(SubM, MD, AddedModules);
}
-void ModuleDepCollectorPP::addAffectingModule(
+void ModuleDepCollectorPP::addAffectingClangModule(
const Module *M, ModuleDeps &MD,
llvm::DenseSet<const Module *> &AddedModules) {
- for (const Module *Affecting : M->AffectingModules) {
+ for (const Module *Affecting : M->AffectingClangModules) {
assert(Affecting == Affecting->getTopLevelModule() &&
"Not quite import not top-level module");
if (Affecting != M->getTopLevelModule() &&
More information about the cfe-commits
mailing list