Skip to content

Commit ff8b4c8

Browse files
committed
[clang-tidy][NFC] Minor cleanup in ClangTidyMain.cpp
Extracted some code from a clangTidyMain function into separate functions.
1 parent 71d7e69 commit ff8b4c8

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,31 @@ static bool verifyFileExtensions(
525525
return AnyInvalid;
526526
}
527527

528+
static SmallString<256> makeAbsolute(llvm::StringRef Input) {
529+
if (Input.empty())
530+
return {};
531+
SmallString<256> AbsolutePath(Input);
532+
if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) {
533+
llvm::errs() << "Can't make absolute path from " << Input << ": "
534+
<< EC.message() << "\n";
535+
}
536+
return AbsolutePath;
537+
}
538+
539+
static llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> createBaseFS() {
540+
llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> BaseFS(
541+
new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
542+
543+
if (!VfsOverlay.empty()) {
544+
IntrusiveRefCntPtr<vfs::FileSystem> VfsFromFile =
545+
getVfsFromFile(VfsOverlay, BaseFS);
546+
if (!VfsFromFile)
547+
return nullptr;
548+
BaseFS->pushOverlay(std::move(VfsFromFile));
549+
}
550+
return BaseFS;
551+
}
552+
528553
int clangTidyMain(int argc, const char **argv) {
529554
llvm::InitLLVM X(argc, argv);
530555

@@ -540,44 +565,26 @@ int clangTidyMain(int argc, const char **argv) {
540565
return 1;
541566
}
542567

543-
llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> BaseFS(
544-
new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
545-
546-
if (!VfsOverlay.empty()) {
547-
IntrusiveRefCntPtr<vfs::FileSystem> VfsFromFile =
548-
getVfsFromFile(VfsOverlay, BaseFS);
549-
if (!VfsFromFile)
550-
return 1;
551-
BaseFS->pushOverlay(std::move(VfsFromFile));
552-
}
568+
llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> BaseFS = createBaseFS();
569+
if (!BaseFS)
570+
return 1;
553571

554572
auto OwningOptionsProvider = createOptionsProvider(BaseFS);
555573
auto *OptionsProvider = OwningOptionsProvider.get();
556574
if (!OptionsProvider)
557575
return 1;
558576

559-
auto MakeAbsolute = [](const std::string &Input) -> SmallString<256> {
560-
if (Input.empty())
561-
return {};
562-
SmallString<256> AbsolutePath(Input);
563-
if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) {
564-
llvm::errs() << "Can't make absolute path from " << Input << ": "
565-
<< EC.message() << "\n";
566-
}
567-
return AbsolutePath;
568-
};
569-
570-
SmallString<256> ProfilePrefix = MakeAbsolute(StoreCheckProfile);
577+
SmallString<256> ProfilePrefix = makeAbsolute(StoreCheckProfile);
571578

572579
StringRef FileName("dummy");
573580
auto PathList = OptionsParser->getSourcePathList();
574581
if (!PathList.empty()) {
575582
FileName = PathList.front();
576583
}
577584

578-
SmallString<256> FilePath = MakeAbsolute(std::string(FileName));
579-
585+
SmallString<256> FilePath = makeAbsolute(FileName);
580586
ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
587+
581588
std::vector<std::string> EnabledChecks =
582589
getCheckNames(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers);
583590

0 commit comments

Comments
 (0)