[clang] 6e73cfa - Basic: Change Module::Umbrella to a PointerUnion, NFC
Duncan P. N. Exon Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 4 13:19:54 PST 2020
Author: Duncan P. N. Exon Smith
Date: 2020-11-04T16:19:39-05:00
New Revision: 6e73cfa8363d43689f77b0e4e4c2787ae6ae3fb6
URL: https://github.com/llvm/llvm-project/commit/6e73cfa8363d43689f77b0e4e4c2787ae6ae3fb6
DIFF: https://github.com/llvm/llvm-project/commit/6e73cfa8363d43689f77b0e4e4c2787ae6ae3fb6.diff
LOG: Basic: Change Module::Umbrella to a PointerUnion, NFC
Change `Module::Umbrella` from a `const void *` to a `PointerUnion` of
`FileEntry` and `DirectoryEntry`. We can drop the `HasUmbrellaDir` bit
(since `PointerUnion` includes that).
This change makes it safer to update to `FileEntryRef` and
`DirectoryEntryRef` in a future patch.
Differential Revision: https://reviews.llvm.org/D90481
Added:
Modified:
clang/include/clang/Basic/Module.h
clang/lib/Basic/Module.cpp
clang/lib/Lex/ModuleMap.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h
index 5a4975f25b72..82ea1f462949 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -15,6 +15,7 @@
#ifndef LLVM_CLANG_BASIC_MODULE_H
#define LLVM_CLANG_BASIC_MODULE_H
+#include "clang/Basic/DirectoryEntry.h"
#include "clang/Basic/FileEntry.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/ArrayRef.h"
@@ -44,8 +45,6 @@ class raw_ostream;
namespace clang {
-class DirectoryEntry;
-class FileEntry;
class FileManager;
class LangOptions;
class TargetInfo;
@@ -134,7 +133,7 @@ class Module {
std::string PresumedModuleMapFile;
/// The umbrella header or directory.
- const void *Umbrella = nullptr;
+ llvm::PointerUnion<const FileEntry *, const DirectoryEntry *> Umbrella;
/// The module signature.
ASTFileSignature Signature;
@@ -303,9 +302,6 @@ class Module {
/// to a regular (public) module map.
unsigned ModuleMapIsPrivate : 1;
- /// Whether Umbrella is a directory or header.
- unsigned HasUmbrellaDir : 1;
-
/// Describes the visibility of the various names within a
/// particular module.
enum NameVisibilityKind {
@@ -548,15 +544,16 @@ class Module {
/// Retrieve the header that serves as the umbrella header for this
/// module.
Header getUmbrellaHeader() const {
- if (!HasUmbrellaDir)
- return Header{UmbrellaAsWritten,
- static_cast<const FileEntry *>(Umbrella)};
+ if (auto *FE = Umbrella.dyn_cast<const FileEntry *>())
+ return Header{UmbrellaAsWritten, FE};
return Header{};
}
/// Determine whether this module has an umbrella directory that is
/// not based on an umbrella header.
- bool hasUmbrellaDir() const { return Umbrella && HasUmbrellaDir; }
+ bool hasUmbrellaDir() const {
+ return Umbrella && Umbrella.is<const DirectoryEntry *>();
+ }
/// Add a top-level header associated with this module.
void addTopHeader(const FileEntry *File);
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 68c1d0f77f22..8a8c400c9503 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -44,7 +44,7 @@ Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent,
InferSubmodules(false), InferExplicitSubmodules(false),
InferExportWildcard(false), ConfigMacrosExhaustive(false),
NoUndeclaredIncludes(false), ModuleMapIsPrivate(false),
- HasUmbrellaDir(false), NameVisibility(Hidden) {
+ NameVisibility(Hidden) {
if (Parent) {
IsAvailable = Parent->isAvailable();
IsUnimportable = Parent->isUnimportable();
@@ -247,7 +247,7 @@ Module::DirectoryName Module::getUmbrellaDir() const {
if (Header U = getUmbrellaHeader())
return {"", U.Entry->getDir()};
- return {UmbrellaAsWritten, static_cast<const DirectoryEntry *>(Umbrella)};
+ return {UmbrellaAsWritten, Umbrella.dyn_cast<const DirectoryEntry *>()};
}
void Module::addTopHeader(const FileEntry *File) {
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index c47a3a0f14c4..cb49173757d8 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1125,7 +1125,6 @@ void ModuleMap::setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
Twine NameAsWritten) {
Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader));
Mod->Umbrella = UmbrellaHeader;
- Mod->HasUmbrellaDir = false;
Mod->UmbrellaAsWritten = NameAsWritten.str();
UmbrellaDirs[UmbrellaHeader->getDir()] = Mod;
@@ -1137,7 +1136,6 @@ void ModuleMap::setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
void ModuleMap::setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
Twine NameAsWritten) {
Mod->Umbrella = UmbrellaDir;
- Mod->HasUmbrellaDir = true;
Mod->UmbrellaAsWritten = NameAsWritten.str();
UmbrellaDirs[UmbrellaDir] = Mod;
}
More information about the cfe-commits
mailing list