Skip to content

Commit b0abc9d

Browse files
committed
[clang] NFCI: Use FileEntryRef in ASTReader::GetHeaderFileInfo()
This is the `ASTReader` counterpart to PR llvm#67383.
1 parent c718336 commit b0abc9d

File tree

23 files changed

+91
-96
lines changed

23 files changed

+91
-96
lines changed

clang-tools-extra/clangd/IncludeCleaner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ bool mayConsiderUnused(const Inclusion &Inc, ParsedAST &AST,
102102
// Headers without include guards have side effects and are not
103103
// self-contained, skip them.
104104
if (!AST.getPreprocessor().getHeaderSearchInfo().isFileMultipleIncludeGuarded(
105-
&FE->getFileEntry())) {
105+
*FE)) {
106106
dlog("{0} doesn't have header guard and will not be considered unused",
107107
FE->getName());
108108
return false;

clang-tools-extra/clangd/ParsedAST.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
499499
// (The rest of HeaderFileInfo is not relevant for our purposes).
500500
if (Preamble && Preamble->MainIsIncludeGuarded) {
501501
const SourceManager &SM = Clang->getSourceManager();
502-
const FileEntry *MainFE = SM.getFileEntryForID(SM.getMainFileID());
503-
Clang->getPreprocessor().getHeaderSearchInfo().MarkFileIncludeOnce(MainFE);
502+
OptionalFileEntryRef MainFE = SM.getFileEntryRefForID(SM.getMainFileID());
503+
Clang->getPreprocessor().getHeaderSearchInfo().MarkFileIncludeOnce(*MainFE);
504504
}
505505

506506
// Set up ClangTidy. Must happen after BeginSourceFile() so ASTContext exists.

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ class CppFilePreambleCallbacks : public PreambleCallbacks {
122122
CapturedCtx.emplace(CI);
123123

124124
const SourceManager &SM = CI.getSourceManager();
125-
const FileEntry *MainFE = SM.getFileEntryForID(SM.getMainFileID());
125+
OptionalFileEntryRef MainFE = SM.getFileEntryRefForID(SM.getMainFileID());
126126
IsMainFileIncludeGuarded =
127127
CI.getPreprocessor().getHeaderSearchInfo().isFileMultipleIncludeGuarded(
128-
MainFE);
128+
*MainFE);
129129

130130
if (Stats) {
131131
const ASTContext &AST = CI.getASTContext();

clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,10 @@ std::string once(llvm::StringRef Code) {
465465

466466
bool mainIsGuarded(const ParsedAST &AST) {
467467
const auto &SM = AST.getSourceManager();
468-
const FileEntry *MainFE = SM.getFileEntryForID(SM.getMainFileID());
468+
OptionalFileEntryRef MainFE = SM.getFileEntryRefForID(SM.getMainFileID());
469469
return AST.getPreprocessor()
470470
.getHeaderSearchInfo()
471-
.isFileMultipleIncludeGuarded(MainFE);
471+
.isFileMultipleIncludeGuarded(*MainFE);
472472
}
473473

474474
MATCHER_P(diag, Desc, "") {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, public CommentHandler {
188188
if (Reason == PPCallbacks::ExitFile) {
189189
// At file exit time HeaderSearchInfo is valid and can be used to
190190
// determine whether the file was a self-contained header or not.
191-
if (const FileEntry *FE = SM.getFileEntryForID(PrevFID)) {
192-
if (tooling::isSelfContainedHeader(FE, SM, HeaderInfo))
191+
if (OptionalFileEntryRef FE = SM.getFileEntryRefForID(PrevFID)) {
192+
if (tooling::isSelfContainedHeader(*FE, SM, HeaderInfo))
193193
Out->NonSelfContainedFiles.erase(FE->getUniqueID());
194194
else
195195
Out->NonSelfContainedFiles.insert(FE->getUniqueID());

clang/include/clang/Lex/HeaderSearch.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class ExternalHeaderFileInfoSource {
139139
/// \returns Header file information for the given file entry, with the
140140
/// \c External bit set. If the file entry is not known, return a
141141
/// default-constructed \c HeaderFileInfo.
142-
virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) = 0;
142+
virtual HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE) = 0;
143143
};
144144

145145
/// This structure is used to record entries in our framework cache.
@@ -487,7 +487,7 @@ class HeaderSearch {
487487
OptionalFileEntryRef LookupFile(
488488
StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
489489
ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir,
490-
ArrayRef<std::pair<const FileEntry *, DirectoryEntryRef>> Includers,
490+
ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>> Includers,
491491
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
492492
Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
493493
bool *IsMapped, bool *IsFrameworkFound, bool SkipCache = false,
@@ -522,33 +522,32 @@ class HeaderSearch {
522522

523523
/// Return whether the specified file is a normal header,
524524
/// a system header, or a C++ friendly system header.
525-
SrcMgr::CharacteristicKind getFileDirFlavor(const FileEntry *File) {
525+
SrcMgr::CharacteristicKind getFileDirFlavor(FileEntryRef File) {
526526
return (SrcMgr::CharacteristicKind)getFileInfo(File).DirInfo;
527527
}
528528

529529
/// Mark the specified file as a "once only" file due to
530530
/// \#pragma once.
531-
void MarkFileIncludeOnce(const FileEntry *File) {
531+
void MarkFileIncludeOnce(FileEntryRef File) {
532532
HeaderFileInfo &FI = getFileInfo(File);
533533
FI.isPragmaOnce = true;
534534
}
535535

536536
/// Mark the specified file as a system header, e.g. due to
537537
/// \#pragma GCC system_header.
538-
void MarkFileSystemHeader(const FileEntry *File) {
538+
void MarkFileSystemHeader(FileEntryRef File) {
539539
getFileInfo(File).DirInfo = SrcMgr::C_System;
540540
}
541541

542542
/// Mark the specified file as part of a module.
543-
void MarkFileModuleHeader(const FileEntry *FE,
544-
ModuleMap::ModuleHeaderRole Role,
543+
void MarkFileModuleHeader(FileEntryRef FE, ModuleMap::ModuleHeaderRole Role,
545544
bool isCompilingModuleHeader);
546545

547546
/// Mark the specified file as having a controlling macro.
548547
///
549548
/// This is used by the multiple-include optimization to eliminate
550549
/// no-op \#includes.
551-
void SetFileControllingMacro(const FileEntry *File,
550+
void SetFileControllingMacro(FileEntryRef File,
552551
const IdentifierInfo *ControllingMacro) {
553552
getFileInfo(File).ControllingMacro = ControllingMacro;
554553
}
@@ -558,10 +557,10 @@ class HeaderSearch {
558557
/// macro.
559558
///
560559
/// This routine does not consider the effect of \#import
561-
bool isFileMultipleIncludeGuarded(const FileEntry *File) const;
560+
bool isFileMultipleIncludeGuarded(FileEntryRef File) const;
562561

563562
/// Determine whether the given file is known to have ever been \#imported.
564-
bool hasFileBeenImported(const FileEntry *File) const {
563+
bool hasFileBeenImported(FileEntryRef File) const {
565564
const HeaderFileInfo *FI = getExistingFileInfo(File);
566565
return FI && FI->isImport;
567566
}
@@ -806,13 +805,13 @@ class HeaderSearch {
806805

807806
/// Return the HeaderFileInfo structure for the specified FileEntry,
808807
/// in preparation for updating it in some way.
809-
HeaderFileInfo &getFileInfo(const FileEntry *FE);
808+
HeaderFileInfo &getFileInfo(FileEntryRef FE);
810809

811810
/// Return the HeaderFileInfo structure for the specified FileEntry,
812811
/// if it has ever been filled in.
813812
/// \param WantExternal Whether the caller wants purely-external header file
814813
/// info (where \p External is true).
815-
const HeaderFileInfo *getExistingFileInfo(const FileEntry *FE,
814+
const HeaderFileInfo *getExistingFileInfo(FileEntryRef FE,
816815
bool WantExternal = true) const;
817816

818817
SearchDirIterator search_dir_begin() { return {*this, 0}; }

clang/include/clang/Lex/Preprocessor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,13 +1483,13 @@ class Preprocessor {
14831483

14841484
/// Mark the file as included.
14851485
/// Returns true if this is the first time the file was included.
1486-
bool markIncluded(const FileEntry *File) {
1486+
bool markIncluded(FileEntryRef File) {
14871487
HeaderInfo.getFileInfo(File);
14881488
return IncludedFiles.insert(File).second;
14891489
}
14901490

14911491
/// Return true if this header has already been included.
1492-
bool alreadyIncluded(const FileEntry *File) const {
1492+
bool alreadyIncluded(FileEntryRef File) const {
14931493
HeaderInfo.getFileInfo(File);
14941494
return IncludedFiles.count(File);
14951495
}

clang/include/clang/Serialization/ASTReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ class ASTReader
18211821
SourceRange ReadSkippedRange(unsigned Index) override;
18221822

18231823
/// Read the header file information for the given file entry.
1824-
HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override;
1824+
HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE) override;
18251825

18261826
void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
18271827

clang/include/clang/Tooling/Inclusions/HeaderAnalysis.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#ifndef LLVM_CLANG_TOOLING_INCLUSIONS_HEADER_ANALYSIS_H
1010
#define LLVM_CLANG_TOOLING_INCLUSIONS_HEADER_ANALYSIS_H
1111

12+
#include "clang/Basic/FileEntry.h"
1213
#include "llvm/ADT/StringRef.h"
1314
#include <optional>
1415

1516
namespace clang {
16-
class FileEntry;
1717
class SourceManager;
1818
class HeaderSearch;
1919

@@ -27,7 +27,7 @@ namespace tooling {
2727
///
2828
/// This function can be expensive as it may scan the source code to find out
2929
/// dont-include-me pattern heuristically.
30-
bool isSelfContainedHeader(const FileEntry *FE, const SourceManager &SM,
30+
bool isSelfContainedHeader(FileEntryRef FE, const SourceManager &SM,
3131
const HeaderSearch &HeaderInfo);
3232

3333
/// This scans the given source code to see if it contains #import(s).

clang/lib/Frontend/FrontendAction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
830830
HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo();
831831
// Relative searches begin from CWD.
832832
auto Dir = CI.getFileManager().getOptionalDirectoryRef(".");
833-
SmallVector<std::pair<const FileEntry *, DirectoryEntryRef>, 1> CWD;
834-
CWD.push_back({nullptr, *Dir});
833+
SmallVector<std::pair<OptionalFileEntryRef, DirectoryEntryRef>, 1> CWD;
834+
CWD.push_back({std::nullopt, *Dir});
835835
OptionalFileEntryRef FE =
836836
HS.LookupFile(FileName, SourceLocation(),
837837
/*Angled*/ Input.getKind().getHeaderUnitKind() ==

0 commit comments

Comments
 (0)