mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 05:40:09 +00:00
[clang] NFCI: Use FileEntryRef
in 'clang-tools-extra'
This commit is contained in:
parent
b19fe81eb5
commit
797cad9d32
@ -40,9 +40,8 @@ typedef std::vector<std::string> TUReplacementFiles;
|
||||
typedef std::vector<clang::tooling::TranslationUnitDiagnostics> TUDiagnostics;
|
||||
|
||||
/// Map mapping file name to a set of AtomicChange targeting that file.
|
||||
typedef llvm::DenseMap<const clang::FileEntry *,
|
||||
std::vector<tooling::AtomicChange>>
|
||||
FileToChangesMap;
|
||||
using FileToChangesMap =
|
||||
llvm::DenseMap<clang::FileEntryRef, std::vector<tooling::AtomicChange>>;
|
||||
|
||||
/// Recursively descends through a directory structure rooted at \p
|
||||
/// Directory and attempts to deserialize *.yaml files as
|
||||
|
@ -138,11 +138,11 @@ std::error_code collectReplacementsFromDirectory(
|
||||
///
|
||||
/// \returns A map mapping FileEntry to a set of Replacement targeting that
|
||||
/// file.
|
||||
static llvm::DenseMap<const FileEntry *, std::vector<tooling::Replacement>>
|
||||
static llvm::DenseMap<FileEntryRef, std::vector<tooling::Replacement>>
|
||||
groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
|
||||
const clang::SourceManager &SM) {
|
||||
llvm::StringSet<> Warned;
|
||||
llvm::DenseMap<const FileEntry *, std::vector<tooling::Replacement>>
|
||||
llvm::DenseMap<FileEntryRef, std::vector<tooling::Replacement>>
|
||||
GroupedReplacements;
|
||||
|
||||
// Deduplicate identical replacements in diagnostics unless they are from the
|
||||
@ -165,7 +165,7 @@ groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
|
||||
else
|
||||
SM.getFileManager().makeAbsolutePath(Path);
|
||||
|
||||
if (auto Entry = SM.getFileManager().getFile(Path)) {
|
||||
if (auto Entry = SM.getFileManager().getOptionalFileRef(Path)) {
|
||||
if (SourceTU) {
|
||||
auto &Replaces = DiagReplacements[*Entry];
|
||||
auto It = Replaces.find(R);
|
||||
@ -212,10 +212,10 @@ bool mergeAndDeduplicate(const TUReplacements &TUs, const TUDiagnostics &TUDs,
|
||||
// To report conflicting replacements on corresponding file, all replacements
|
||||
// are stored into 1 big AtomicChange.
|
||||
for (const auto &FileAndReplacements : GroupedReplacements) {
|
||||
const FileEntry *Entry = FileAndReplacements.first;
|
||||
FileEntryRef Entry = FileAndReplacements.first;
|
||||
const SourceLocation BeginLoc =
|
||||
SM.getLocForStartOfFile(SM.getOrCreateFileID(Entry, SrcMgr::C_User));
|
||||
tooling::AtomicChange FileChange(Entry->getName(), Entry->getName());
|
||||
tooling::AtomicChange FileChange(Entry.getName(), Entry.getName());
|
||||
for (const auto &R : FileAndReplacements.second) {
|
||||
llvm::Error Err =
|
||||
FileChange.replace(SM, BeginLoc.getLocWithOffset(R.getOffset()),
|
||||
|
@ -146,8 +146,8 @@ int main(int argc, char **argv) {
|
||||
: tooling::ApplyChangesSpec::kNone;
|
||||
|
||||
for (const auto &FileChange : Changes) {
|
||||
const FileEntry *Entry = FileChange.first;
|
||||
StringRef FileName = Entry->getName();
|
||||
FileEntryRef Entry = FileChange.first;
|
||||
StringRef FileName = Entry.getName();
|
||||
llvm::Expected<std::string> NewFileData =
|
||||
applyChanges(FileName, FileChange.second, Spec, Diagnostics);
|
||||
if (!NewFileData) {
|
||||
|
@ -62,8 +62,8 @@ void FindAllMacros::Ifndef(SourceLocation Loc, const Token &MacroNameTok,
|
||||
}
|
||||
|
||||
void FindAllMacros::EndOfMainFile() {
|
||||
Reporter->reportSymbols(SM->getFileEntryForID(SM->getMainFileID())->getName(),
|
||||
FileSymbols);
|
||||
Reporter->reportSymbols(
|
||||
SM->getFileEntryRefForID(SM->getMainFileID())->getName(), FileSymbols);
|
||||
FileSymbols.clear();
|
||||
}
|
||||
|
||||
|
@ -254,7 +254,7 @@ void FindAllSymbols::run(const MatchFinder::MatchResult &Result) {
|
||||
const SourceManager *SM = Result.SourceManager;
|
||||
if (auto Symbol = CreateSymbolInfo(ND, *SM, Collector)) {
|
||||
Filename =
|
||||
std::string(SM->getFileEntryForID(SM->getMainFileID())->getName());
|
||||
std::string(SM->getFileEntryRefForID(SM->getMainFileID())->getName());
|
||||
FileSymbols[*Symbol] += Signals;
|
||||
}
|
||||
}
|
||||
|
@ -115,8 +115,8 @@ AST_POLYMORPHIC_MATCHER_P(isExpansionInFile,
|
||||
auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getBeginLoc());
|
||||
if (ExpansionLoc.isInvalid())
|
||||
return false;
|
||||
auto *FileEntry =
|
||||
SourceManager.getFileEntryForID(SourceManager.getFileID(ExpansionLoc));
|
||||
auto FileEntry =
|
||||
SourceManager.getFileEntryRefForID(SourceManager.getFileID(ExpansionLoc));
|
||||
if (!FileEntry)
|
||||
return false;
|
||||
return MakeAbsolutePath(SourceManager, FileEntry->getName()) ==
|
||||
@ -135,7 +135,7 @@ public:
|
||||
StringRef /*RelativePath*/,
|
||||
const Module * /*Imported*/,
|
||||
SrcMgr::CharacteristicKind /*FileType*/) override {
|
||||
if (const auto *FileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc)))
|
||||
if (auto FileEntry = SM.getFileEntryRefForID(SM.getFileID(HashLoc)))
|
||||
MoveTool->addIncludes(FileName, IsAngled, SearchPath,
|
||||
FileEntry->getName(), FilenameRange, SM);
|
||||
}
|
||||
@ -341,7 +341,7 @@ bool isInHeaderFile(const Decl *D, llvm::StringRef OriginalRunningDirectory,
|
||||
if (ExpansionLoc.isInvalid())
|
||||
return false;
|
||||
|
||||
if (const auto *FE = SM.getFileEntryForID(SM.getFileID(ExpansionLoc))) {
|
||||
if (auto FE = SM.getFileEntryRefForID(SM.getFileID(ExpansionLoc))) {
|
||||
return MakeAbsolutePath(SM, FE->getName()) ==
|
||||
MakeAbsolutePath(OriginalRunningDirectory, OldHeader);
|
||||
}
|
||||
|
@ -552,7 +552,7 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
|
||||
// location needed depends on the check (in particular, where this check wants
|
||||
// to apply fixes).
|
||||
FileID FID = Sources.getDecomposedExpansionLoc(Location).first;
|
||||
const FileEntry *File = Sources.getFileEntryForID(FID);
|
||||
OptionalFileEntryRef File = Sources.getFileEntryRefForID(FID);
|
||||
|
||||
// -DMACRO definitions on the command line have locations in a virtual buffer
|
||||
// that doesn't have a FileEntry. Don't skip these as well.
|
||||
|
@ -34,8 +34,8 @@ AST_POLYMORPHIC_MATCHER(
|
||||
SourceLocation Loc = SourceManager.getSpellingLoc(Node.getBeginLoc());
|
||||
if (Loc.isInvalid())
|
||||
return false;
|
||||
const FileEntry *FileEntry =
|
||||
SourceManager.getFileEntryForID(SourceManager.getFileID(Loc));
|
||||
OptionalFileEntryRef FileEntry =
|
||||
SourceManager.getFileEntryRefForID(SourceManager.getFileID(Loc));
|
||||
if (!FileEntry)
|
||||
return false;
|
||||
// Determine whether filepath contains "absl/[absl-library]" substring, where
|
||||
|
@ -76,7 +76,7 @@ bool KernelNameRestrictionPPCallbacks::fileNameIsRestricted(
|
||||
void KernelNameRestrictionPPCallbacks::EndOfMainFile() {
|
||||
|
||||
// Check main file for restricted names.
|
||||
const FileEntry *Entry = SM.getFileEntryForID(SM.getMainFileID());
|
||||
OptionalFileEntryRef Entry = SM.getFileEntryRefForID(SM.getMainFileID());
|
||||
StringRef FileName = llvm::sys::path::filename(Entry->getName());
|
||||
if (fileNameIsRestricted(FileName))
|
||||
Check.diag(SM.getLocForStartOfFile(SM.getMainFileID()),
|
||||
|
@ -84,7 +84,7 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
return;
|
||||
// We don't emit warnings on unused-using-decls from headers, so bail out if
|
||||
// the main file is a header.
|
||||
if (const auto *MainFile = Result.SourceManager->getFileEntryForID(
|
||||
if (auto MainFile = Result.SourceManager->getFileEntryRefForID(
|
||||
Result.SourceManager->getMainFileID());
|
||||
utils::isFileExtension(MainFile->getName(), HeaderFileExtensions))
|
||||
return;
|
||||
|
@ -35,9 +35,10 @@ public:
|
||||
// guards.
|
||||
SourceManager &SM = PP->getSourceManager();
|
||||
if (Reason == EnterFile && FileType == SrcMgr::C_User) {
|
||||
if (const FileEntry *FE = SM.getFileEntryForID(SM.getFileID(Loc))) {
|
||||
if (OptionalFileEntryRef FE =
|
||||
SM.getFileEntryRefForID(SM.getFileID(Loc))) {
|
||||
std::string FileName = cleanPath(FE->getName());
|
||||
Files[FileName] = FE;
|
||||
Files[FileName] = *FE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,8 +78,8 @@ public:
|
||||
if (!MI->isUsedForHeaderGuard())
|
||||
continue;
|
||||
|
||||
const FileEntry *FE =
|
||||
SM.getFileEntryForID(SM.getFileID(MI->getDefinitionLoc()));
|
||||
OptionalFileEntryRef FE =
|
||||
SM.getFileEntryRefForID(SM.getFileID(MI->getDefinitionLoc()));
|
||||
std::string FileName = cleanPath(FE->getName());
|
||||
Files.erase(FileName);
|
||||
|
||||
|
@ -380,7 +380,7 @@ getModularizeArgumentsAdjuster(DependencyMap &Dependencies) {
|
||||
// want to design to be applicable to a wider range of tools, and stick it
|
||||
// somewhere into Tooling/ in mainline
|
||||
struct Location {
|
||||
const FileEntry *File;
|
||||
OptionalFileEntryRef File;
|
||||
unsigned Line, Column;
|
||||
|
||||
Location() : File(), Line(), Column() {}
|
||||
@ -391,7 +391,7 @@ struct Location {
|
||||
return;
|
||||
|
||||
std::pair<FileID, unsigned> Decomposed = SM.getDecomposedLoc(Loc);
|
||||
File = SM.getFileEntryForID(Decomposed.first);
|
||||
File = SM.getFileEntryRefForID(Decomposed.first);
|
||||
if (!File)
|
||||
return;
|
||||
|
||||
@ -483,12 +483,12 @@ typedef std::vector<HeaderEntry> HeaderContents;
|
||||
|
||||
class EntityMap : public std::map<std::string, SmallVector<Entry, 2>> {
|
||||
public:
|
||||
DenseMap<const FileEntry *, HeaderContents> HeaderContentMismatches;
|
||||
DenseMap<FileEntryRef, HeaderContents> HeaderContentMismatches;
|
||||
|
||||
void add(const std::string &Name, enum Entry::EntryKind Kind, Location Loc) {
|
||||
// Record this entity in its header.
|
||||
HeaderEntry HE = { Name, Loc };
|
||||
CurHeaderContents[Loc.File].push_back(HE);
|
||||
CurHeaderContents[*Loc.File].push_back(HE);
|
||||
|
||||
// Check whether we've seen this entry before.
|
||||
SmallVector<Entry, 2> &Entries = (*this)[Name];
|
||||
@ -503,16 +503,13 @@ public:
|
||||
}
|
||||
|
||||
void mergeCurHeaderContents() {
|
||||
for (DenseMap<const FileEntry *, HeaderContents>::iterator
|
||||
H = CurHeaderContents.begin(),
|
||||
HEnd = CurHeaderContents.end();
|
||||
for (auto H = CurHeaderContents.begin(), HEnd = CurHeaderContents.end();
|
||||
H != HEnd; ++H) {
|
||||
// Sort contents.
|
||||
llvm::sort(H->second);
|
||||
|
||||
// Check whether we've seen this header before.
|
||||
DenseMap<const FileEntry *, HeaderContents>::iterator KnownH =
|
||||
AllHeaderContents.find(H->first);
|
||||
auto KnownH = AllHeaderContents.find(H->first);
|
||||
if (KnownH == AllHeaderContents.end()) {
|
||||
// We haven't seen this header before; record its contents.
|
||||
AllHeaderContents.insert(*H);
|
||||
@ -534,8 +531,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
DenseMap<const FileEntry *, HeaderContents> CurHeaderContents;
|
||||
DenseMap<const FileEntry *, HeaderContents> AllHeaderContents;
|
||||
DenseMap<FileEntryRef, HeaderContents> CurHeaderContents;
|
||||
DenseMap<FileEntryRef, HeaderContents> AllHeaderContents;
|
||||
};
|
||||
|
||||
class CollectEntitiesVisitor
|
||||
@ -961,9 +958,8 @@ int main(int Argc, const char **Argv) {
|
||||
// they are included.
|
||||
// FIXME: Could we provide information about which preprocessor conditionals
|
||||
// are involved?
|
||||
for (DenseMap<const FileEntry *, HeaderContents>::iterator
|
||||
H = Entities.HeaderContentMismatches.begin(),
|
||||
HEnd = Entities.HeaderContentMismatches.end();
|
||||
for (auto H = Entities.HeaderContentMismatches.begin(),
|
||||
HEnd = Entities.HeaderContentMismatches.end();
|
||||
H != HEnd; ++H) {
|
||||
if (H->second.empty()) {
|
||||
errs() << "internal error: phantom header content mismatch\n";
|
||||
@ -971,8 +967,8 @@ int main(int Argc, const char **Argv) {
|
||||
}
|
||||
|
||||
HadErrors = 1;
|
||||
ModUtil->addUniqueProblemFile(std::string(H->first->getName()));
|
||||
errs() << "error: header '" << H->first->getName()
|
||||
ModUtil->addUniqueProblemFile(std::string(H->first.getName()));
|
||||
errs() << "error: header '" << H->first.getName()
|
||||
<< "' has different contents depending on how it was included.\n";
|
||||
for (unsigned I = 0, N = H->second.size(); I != N; ++I) {
|
||||
errs() << "note: '" << H->second[I].Name << "' in "
|
||||
|
@ -1292,8 +1292,8 @@ void PreprocessorCallbacks::FileChanged(
|
||||
PPTracker.handleHeaderEntry(PP, getSourceLocationFile(PP, Loc));
|
||||
break;
|
||||
case ExitFile: {
|
||||
const clang::FileEntry *F =
|
||||
PP.getSourceManager().getFileEntryForID(PrevFID);
|
||||
clang::OptionalFileEntryRef F =
|
||||
PP.getSourceManager().getFileEntryRefForID(PrevFID);
|
||||
if (F)
|
||||
PPTracker.handleHeaderExit(F->getName());
|
||||
} break;
|
||||
|
@ -476,7 +476,8 @@ void PPCallbacksTracker::appendArgument(const char *Name, FileID Value) {
|
||||
appendArgument(Name, "(invalid)");
|
||||
return;
|
||||
}
|
||||
const FileEntry *FileEntry = PP.getSourceManager().getFileEntryForID(Value);
|
||||
OptionalFileEntryRef FileEntry =
|
||||
PP.getSourceManager().getFileEntryRefForID(Value);
|
||||
if (!FileEntry) {
|
||||
appendArgument(Name, "(getFileEntryForID failed)");
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user