Skip to content

Commit cb92511

Browse files
authored
[clang] NFC: Remove OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr (#74900)
1 parent 0cb0a48 commit cb92511

File tree

7 files changed

+15
-93
lines changed

7 files changed

+15
-93
lines changed

clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
124124
MainFileDecls.push_back(D);
125125
}
126126
llvm::DenseSet<include_cleaner::Symbol> SeenSymbols;
127-
const DirectoryEntry *ResourceDir =
127+
OptionalDirectoryEntryRef ResourceDir =
128128
PP->getHeaderSearchInfo().getModuleMap().getBuiltinDir();
129129
// FIXME: Find a way to have less code duplication between include-cleaner
130130
// analysis implementation and the below code.

clang-tools-extra/clangd/IncludeCleaner.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,10 @@ IncludeCleanerFindings computeIncludeCleanerFindings(ParsedAST &AST) {
397397
std::vector<MissingIncludeDiagInfo> MissingIncludes;
398398
llvm::DenseSet<IncludeStructure::HeaderID> Used;
399399
trace::Span Tracer("include_cleaner::walkUsed");
400-
const DirectoryEntry *ResourceDir = AST.getPreprocessor()
401-
.getHeaderSearchInfo()
402-
.getModuleMap()
403-
.getBuiltinDir();
400+
OptionalDirectoryEntryRef ResourceDir = AST.getPreprocessor()
401+
.getHeaderSearchInfo()
402+
.getModuleMap()
403+
.getBuiltinDir();
404404
include_cleaner::walkUsed(
405405
AST.getLocalTopLevelDecls(), /*MacroRefs=*/Macros,
406406
AST.getPragmaIncludes().get(), AST.getPreprocessor(),

clang-tools-extra/include-cleaner/lib/Analysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ analyze(llvm::ArrayRef<Decl *> ASTRoots,
8787
llvm::StringSet<> Missing;
8888
if (!HeaderFilter)
8989
HeaderFilter = [](llvm::StringRef) { return false; };
90-
const DirectoryEntry *ResourceDir =
90+
OptionalDirectoryEntryRef ResourceDir =
9191
PP.getHeaderSearchInfo().getModuleMap().getBuiltinDir();
9292
walkUsed(ASTRoots, MacroRefs, PI, PP,
9393
[&](const SymbolReference &Ref, llvm::ArrayRef<Header> Providers) {
9494
bool Satisfied = false;
9595
for (const Header &H : Providers) {
9696
if (H.kind() == Header::Physical &&
9797
(H.physical() == MainFile ||
98-
H.physical().getDir() == ResourceDir)) {
98+
(ResourceDir && H.physical().getDir() == *ResourceDir))) {
9999
Satisfied = true;
100100
}
101101
for (const Include *I : Inc.match(H)) {
@@ -114,7 +114,7 @@ analyze(llvm::ArrayRef<Decl *> ASTRoots,
114114
for (const Include &I : Inc.all()) {
115115
if (Used.contains(&I) || !I.Resolved ||
116116
HeaderFilter(I.Resolved->getFileEntry().tryGetRealPathName()) ||
117-
I.Resolved->getFileEntry().getDir() == ResourceDir)
117+
(ResourceDir && I.Resolved->getFileEntry().getDir() == *ResourceDir))
118118
continue;
119119
if (PI) {
120120
if (PI->shouldKeep(*I.Resolved))

clang/include/clang/Basic/DirectoryEntry.h

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -245,78 +245,4 @@ template <> struct DenseMapInfo<clang::DirectoryEntryRef> {
245245

246246
} // end namespace llvm
247247

248-
namespace clang {
249-
250-
/// Wrapper around OptionalDirectoryEntryRef that degrades to 'const
251-
/// DirectoryEntry*', facilitating incremental patches to propagate
252-
/// DirectoryEntryRef.
253-
///
254-
/// This class can be used as return value or field where it's convenient for
255-
/// an OptionalDirectoryEntryRef to degrade to a 'const DirectoryEntry*'. The
256-
/// purpose is to avoid code churn due to dances like the following:
257-
/// \code
258-
/// // Old code.
259-
/// lvalue = rvalue;
260-
///
261-
/// // Temporary code from an incremental patch.
262-
/// OptionalDirectoryEntryRef MaybeF = rvalue;
263-
/// lvalue = MaybeF ? &MaybeF.getDirectoryEntry() : nullptr;
264-
///
265-
/// // Final code.
266-
/// lvalue = rvalue;
267-
/// \endcode
268-
///
269-
/// FIXME: Once DirectoryEntryRef is "everywhere" and DirectoryEntry::LastRef
270-
/// and DirectoryEntry::getName have been deleted, delete this class and
271-
/// replace instances with OptionalDirectoryEntryRef.
272-
class OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr
273-
: public OptionalDirectoryEntryRef {
274-
public:
275-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr() = default;
276-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(
277-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &&) = default;
278-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(
279-
const OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &) = default;
280-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
281-
operator=(OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &&) = default;
282-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
283-
operator=(const OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &) = default;
284-
285-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(std::nullopt_t) {}
286-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(DirectoryEntryRef Ref)
287-
: OptionalDirectoryEntryRef(Ref) {}
288-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(
289-
OptionalDirectoryEntryRef MaybeRef)
290-
: OptionalDirectoryEntryRef(MaybeRef) {}
291-
292-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
293-
operator=(std::nullopt_t) {
294-
OptionalDirectoryEntryRef::operator=(std::nullopt);
295-
return *this;
296-
}
297-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &operator=(DirectoryEntryRef Ref) {
298-
OptionalDirectoryEntryRef::operator=(Ref);
299-
return *this;
300-
}
301-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
302-
operator=(OptionalDirectoryEntryRef MaybeRef) {
303-
OptionalDirectoryEntryRef::operator=(MaybeRef);
304-
return *this;
305-
}
306-
307-
/// Degrade to 'const DirectoryEntry *' to allow DirectoryEntry::LastRef and
308-
/// DirectoryEntry::getName have been deleted, delete this class and replace
309-
/// instances with OptionalDirectoryEntryRef
310-
operator const DirectoryEntry *() const {
311-
return has_value() ? &(*this)->getDirEntry() : nullptr;
312-
}
313-
};
314-
315-
static_assert(std::is_trivially_copyable<
316-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr>::value,
317-
"OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr should be "
318-
"trivially copyable");
319-
320-
} // end namespace clang
321-
322248
#endif // LLVM_CLANG_BASIC_DIRECTORYENTRY_H

clang/include/clang/Basic/Module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class alignas(8) Module {
156156
/// The build directory of this module. This is the directory in
157157
/// which the module is notionally built, and relative to which its headers
158158
/// are found.
159-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr Directory;
159+
OptionalDirectoryEntryRef Directory;
160160

161161
/// The presumed file name for the module map defining this module.
162162
/// Only non-empty when building from preprocessed source.

clang/include/clang/Lex/ModuleMap.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class ModuleMap {
8282

8383
/// The directory used for Clang-supplied, builtin include headers,
8484
/// such as "stdint.h".
85-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr BuiltinIncludeDir;
85+
OptionalDirectoryEntryRef BuiltinIncludeDir;
8686

8787
/// Language options used to parse the module map itself.
8888
///
@@ -408,16 +408,12 @@ class ModuleMap {
408408
/// Set the target information.
409409
void setTarget(const TargetInfo &Target);
410410

411-
/// Set the directory that contains Clang-supplied include
412-
/// files, such as our stdarg.h or tgmath.h.
413-
void setBuiltinIncludeDir(DirectoryEntryRef Dir) {
414-
BuiltinIncludeDir = Dir;
415-
}
411+
/// Set the directory that contains Clang-supplied include files, such as our
412+
/// stdarg.h or tgmath.h.
413+
void setBuiltinIncludeDir(DirectoryEntryRef Dir) { BuiltinIncludeDir = Dir; }
416414

417415
/// Get the directory that contains Clang-supplied include files.
418-
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr getBuiltinDir() const {
419-
return BuiltinIncludeDir;
420-
}
416+
OptionalDirectoryEntryRef getBuiltinDir() const { return BuiltinIncludeDir; }
421417

422418
/// Is this a compiler builtin header?
423419
bool isBuiltinHeader(FileEntryRef File);

clang/lib/Serialization/ASTReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3152,7 +3152,7 @@ ASTReader::ReadControlBlock(ModuleFile &F,
31523152
if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation &
31533153
DisableValidationForModuleKind::Module) &&
31543154
F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) {
3155-
auto BuildDir = PP.getFileManager().getDirectory(Blob);
3155+
auto BuildDir = PP.getFileManager().getOptionalDirectoryRef(Blob);
31563156
if (!BuildDir || *BuildDir != M->Directory) {
31573157
if (!canRecoverFromOutOfDate(F.FileName, ClientLoadCapabilities))
31583158
Diag(diag::err_imported_module_relocated)

0 commit comments

Comments
 (0)