diff options
author | Eugene Zelenko <eugene.zelenko@gmail.com> | 2017-12-06 23:18:41 +0000 |
---|---|---|
committer | Eugene Zelenko <eugene.zelenko@gmail.com> | 2017-12-06 23:18:41 +0000 |
commit | 08fe1221761fe36d59a47304d2b5e6ba66c61c87 (patch) | |
tree | 83ecc978c82d82c9ca24eda318d3162a71562e2c /lib/Lex | |
parent | 1dae00ad5ffbc58dc0cf00953ca9c991adfd93fd (diff) |
[Lex] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319986 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex')
-rw-r--r-- | lib/Lex/HeaderSearch.cpp | 66 | ||||
-rw-r--r-- | lib/Lex/ModuleMap.cpp | 83 | ||||
-rw-r--r-- | lib/Lex/PTHLexer.cpp | 89 |
3 files changed, 141 insertions, 97 deletions
diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index b18d27376a..aa2588659d 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -1,4 +1,4 @@ -//===--- HeaderSearch.cpp - Resolve Header File Locations ---===// +//===- HeaderSearch.cpp - Resolve Header File Locations -------------------===// // // The LLVM Compiler Infrastructure // @@ -12,25 +12,38 @@ //===----------------------------------------------------------------------===// #include "clang/Lex/HeaderSearch.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/Module.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Basic/VirtualFileSystem.h" +#include "clang/Lex/DirectoryLookup.h" #include "clang/Lex/ExternalPreprocessorSource.h" #include "clang/Lex/HeaderMap.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/LexDiagnostic.h" -#include "clang/Lex/Lexer.h" +#include "clang/Lex/ModuleMap.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Allocator.h" #include "llvm/Support/Capacity.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#include <algorithm> +#include <cassert> +#include <cstddef> #include <cstdio> +#include <cstring> +#include <string> +#include <system_error> #include <utility> -#if defined(LLVM_ON_UNIX) -#include <limits.h> -#endif + using namespace clang; const IdentifierInfo * @@ -52,7 +65,7 @@ HeaderFileInfo::getControllingMacro(ExternalPreprocessorSource *External) { return ControllingMacro; } -ExternalHeaderFileInfoSource::~ExternalHeaderFileInfoSource() {} +ExternalHeaderFileInfoSource::~ExternalHeaderFileInfoSource() = default; HeaderSearch::HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts, SourceManager &SourceMgr, DiagnosticsEngine &Diags, @@ -60,17 +73,7 @@ HeaderSearch::HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts, const TargetInfo *Target) : HSOpts(std::move(HSOpts)), Diags(Diags), FileMgr(SourceMgr.getFileManager()), FrameworkMap(64), - ModMap(SourceMgr, Diags, LangOpts, Target, *this) { - AngledDirIdx = 0; - SystemDirIdx = 0; - NoCurDirSearch = false; - - ExternalLookup = nullptr; - ExternalSource = nullptr; - NumIncluded = 0; - NumMultiIncludeFileOptzn = 0; - NumFrameworkLookups = NumSubFrameworkLookups = 0; -} + ModMap(SourceMgr, Diags, LangOpts, Target, *this) {} HeaderSearch::~HeaderSearch() { // Delete headermaps. @@ -142,27 +145,26 @@ std::string HeaderSearch::getPrebuiltModuleFileName(StringRef ModuleName, return i->second; if (FileMapOnly || HSOpts->PrebuiltModulePaths.empty()) - return std::string(); + return {}; // Then go through each prebuilt module directory and try to find the pcm // file. - for (const std::string &Dir : HSOpts->PrebuiltModulePaths) { - SmallString<256> Result(Dir); - llvm::sys::fs::make_absolute(Result); - - llvm::sys::path::append(Result, ModuleName + ".pcm"); - if (getFileMgr().getFile(Result.str())) - return Result.str().str(); - } - return std::string(); + for (const std::string &Dir : HSOpts->PrebuiltModulePaths) { + SmallString<256> Result(Dir); + llvm::sys::fs::make_absolute(Result); + llvm::sys::path::append(Result, ModuleName + ".pcm"); + if (getFileMgr().getFile(Result.str())) + return Result.str().str(); } + return {}; +} std::string HeaderSearch::getCachedModuleFileName(StringRef ModuleName, StringRef ModuleMapPath) { // If we don't have a module cache path or aren't supposed to use one, we // can't do anything. if (getModuleCachePath().empty()) - return std::string(); + return {}; SmallString<256> Result(getModuleCachePath()); llvm::sys::fs::make_absolute(Result); @@ -182,7 +184,7 @@ std::string HeaderSearch::getCachedModuleFileName(StringRef ModuleName, Parent = "."; auto *Dir = FileMgr.getDirectory(Parent); if (!Dir) - return std::string(); + return {}; auto DirName = FileMgr.getCanonicalName(Dir); auto FileName = llvm::sys::path::filename(ModuleMapPath); @@ -381,7 +383,6 @@ const FileEntry *DirectoryLookup::LookupFile( Filename = StringRef(MappedName.begin(), MappedName.size()); HasBeenMapped = true; Result = HM->LookupFile(Filename, HS.getFileMgr()); - } else { Result = HS.getFileMgr().getFile(Dest); } @@ -592,7 +593,6 @@ void HeaderSearch::setTarget(const TargetInfo &Target) { ModMap.setTarget(Target); } - //===----------------------------------------------------------------------===// // Header File Location. //===----------------------------------------------------------------------===// @@ -959,7 +959,6 @@ LookupSubframeworkHeader(StringRef Filename, HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end()); if (!(FE = FileMgr.getFile(HeadersFilename, /*openFile=*/true))) { - // Check ".../Frameworks/HIToolbox.framework/PrivateHeaders/HIToolbox.h" HeadersFilename = FrameworkName; HeadersFilename += "PrivateHeaders/"; @@ -1116,7 +1115,7 @@ bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP, // FIXME: this is a workaround for the lack of proper modules-aware support // for #import / #pragma once - auto TryEnterImported = [&](void) -> bool { + auto TryEnterImported = [&]() -> bool { if (!ModulesEnabled) return false; // Ensure FileInfo bits are up to date. @@ -1449,7 +1448,6 @@ Module *HeaderSearch::loadFrameworkModule(StringRef Name, return ModMap.findModule(Name); } - HeaderSearch::LoadModuleMapResult HeaderSearch::loadModuleMapFile(StringRef DirName, bool IsSystem, bool IsFramework) { diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp index fc7fe138c5..fbbae7a095 100644 --- a/lib/Lex/ModuleMap.cpp +++ b/lib/Lex/ModuleMap.cpp @@ -1,4 +1,4 @@ -//===--- ModuleMap.cpp - Describe the layout of modules ---------*- C++ -*-===// +//===- ModuleMap.cpp - Describe the layout of modules ---------------------===// // // The LLVM Compiler Infrastructure // @@ -11,29 +11,47 @@ // of a module as it relates to headers. // //===----------------------------------------------------------------------===// + #include "clang/Lex/ModuleMap.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/Diagnostic.h" -#include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/Module.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" -#include "clang/Basic/TargetOptions.h" +#include "clang/Basic/VirtualFileSystem.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/LiteralSupport.h" +#include "clang/Lex/Token.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Allocator.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/Host.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" -#include <stdlib.h> -#if defined(LLVM_ON_UNIX) -#include <limits.h> -#endif +#include <algorithm> +#include <cassert> +#include <cstdint> +#include <cstring> +#include <string> +#include <system_error> +#include <utility> + using namespace clang; Module::HeaderKind ModuleMap::headerRoleToKind(ModuleHeaderRole Role) { @@ -80,7 +98,7 @@ ModuleMap::resolveExport(Module *Mod, // Resolve the module-id. Module *Context = resolveModuleId(Unresolved.Id, Mod, Complain); if (!Context) - return Module::ExportDecl(); + return {}; return Module::ExportDecl(Context, Unresolved.Wildcard); } @@ -344,7 +362,7 @@ ModuleMap::KnownHeader ModuleMap::findHeaderInUmbrellaDirs(const FileEntry *File, SmallVectorImpl<const DirectoryEntry *> &IntermediateDirs) { if (UmbrellaDirs.empty()) - return KnownHeader(); + return {}; const DirectoryEntry *Dir = File->getDir(); assert(Dir && "file in no directory"); @@ -372,7 +390,7 @@ ModuleMap::findHeaderInUmbrellaDirs(const FileEntry *File, // Resolve the parent path to a directory entry. Dir = SourceMgr.getFileManager().getDirectory(DirName); } while (Dir); - return KnownHeader(); + return {}; } static bool violatesPrivateInclude(Module *RequestingModule, @@ -502,7 +520,7 @@ ModuleMap::KnownHeader ModuleMap::findModuleForHeader(const FileEntry *File, bool AllowTextual) { auto MakeResult = [&](ModuleMap::KnownHeader R) -> ModuleMap::KnownHeader { if (!AllowTextual && R.getRole() & ModuleMap::TextualHeader) - return ModuleMap::KnownHeader(); + return {}; return R; }; @@ -592,7 +610,7 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File) { return Header; } - return KnownHeader(); + return {}; } ArrayRef<ModuleMap::KnownHeader> @@ -1188,6 +1206,7 @@ bool ModuleMap::resolveConflicts(Module *Mod, bool Complain) { //----------------------------------------------------------------------------// namespace clang { + /// \brief A token in a module map file. struct MMToken { enum TokenKind { @@ -1226,6 +1245,7 @@ namespace clang { union { // If Kind != IntegerLiteral. const char *StringData; + // If Kind == IntegerLiteral. uint64_t IntegerValue; }; @@ -1275,7 +1295,7 @@ namespace clang { bool IsSystem; /// \brief Whether an error occurred. - bool HadError; + bool HadError = false; /// \brief Stores string data for the various string literals referenced /// during parsing. @@ -1285,7 +1305,7 @@ namespace clang { MMToken Tok; /// \brief The active module. - Module *ActiveModule; + Module *ActiveModule = nullptr; /// \brief Whether a module uses the 'requires excluded' hack to mark its /// contents as 'textual'. @@ -1304,13 +1324,13 @@ namespace clang { /// (or the end of the file). void skipUntil(MMToken::TokenKind K); - typedef SmallVector<std::pair<std::string, SourceLocation>, 2> ModuleId; + using ModuleId = SmallVector<std::pair<std::string, SourceLocation>, 2>; + bool parseModuleId(ModuleId &Id); void parseModuleDecl(); void parseExternModuleDecl(); void parseRequiresDecl(); - void parseHeaderDecl(clang::MMToken::TokenKind, - SourceLocation LeadingLoc); + void parseHeaderDecl(MMToken::TokenKind, SourceLocation LeadingLoc); void parseUmbrellaDirDecl(SourceLocation UmbrellaLoc); void parseExportDecl(); void parseExportAsDecl(); @@ -1320,7 +1340,8 @@ namespace clang { void parseConflict(); void parseInferredModuleDecl(bool Framework, bool Explicit); - typedef ModuleMap::Attributes Attributes; + using Attributes = ModuleMap::Attributes; + bool parseOptionalAttributes(Attributes &Attrs); public: @@ -1331,10 +1352,9 @@ namespace clang { const FileEntry *ModuleMapFile, const DirectoryEntry *Directory, bool IsSystem) - : L(L), SourceMgr(SourceMgr), Target(Target), Diags(Diags), Map(Map), - ModuleMapFile(ModuleMapFile), Directory(Directory), - IsSystem(IsSystem), HadError(false), ActiveModule(nullptr) - { + : L(L), SourceMgr(SourceMgr), Target(Target), Diags(Diags), Map(Map), + ModuleMapFile(ModuleMapFile), Directory(Directory), + IsSystem(IsSystem) { Tok.clear(); consumeToken(); } @@ -1344,7 +1364,8 @@ namespace clang { bool terminatedByDirective() { return false; } SourceLocation getLocation() { return Tok.getLocation(); } }; -} + +} // namespace clang SourceLocation ModuleMapParser::consumeToken() { SourceLocation Result = Tok.getLocation(); @@ -1566,20 +1587,26 @@ bool ModuleMapParser::parseModuleId(ModuleId &Id) { } namespace { + /// \brief Enumerates the known attributes. enum AttributeKind { /// \brief An unknown attribute. AT_unknown, + /// \brief The 'system' attribute. AT_system, + /// \brief The 'extern_c' attribute. AT_extern_c, + /// \brief The 'exhaustive' attribute. AT_exhaustive, + /// \brief The 'no_undeclared_includes' attribute. AT_no_undeclared_includes }; -} + +} // namespace /// \brief Parse a module declaration. /// @@ -1702,7 +1729,6 @@ void ModuleMapParser::parseModuleDecl() { if (parseOptionalAttributes(Attrs)) return; - // Parse the opening brace. if (!Tok.is(MMToken::LBrace)) { Diags.Report(Tok.getLocation(), diag::err_mmap_expected_lbrace) @@ -2574,7 +2600,7 @@ void ModuleMapParser::parseInferredModuleDecl(bool Framework, bool Explicit) { Done = true; break; - case MMToken::ExcludeKeyword: { + case MMToken::ExcludeKeyword: if (ActiveModule) { Diags.Report(Tok.getLocation(), diag::err_mmap_expected_inferred_member) << (ActiveModule != nullptr); @@ -2593,7 +2619,6 @@ void ModuleMapParser::parseInferredModuleDecl(bool Framework, bool Explicit) { .push_back(Tok.getString()); consumeToken(); break; - } case MMToken::ExportKeyword: if (!ActiveModule) { diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp index ec806e8445..d6c20a13d2 100644 --- a/lib/Lex/PTHLexer.cpp +++ b/lib/Lex/PTHLexer.cpp @@ -1,4 +1,4 @@ -//===--- PTHLexer.cpp - Lex from a token stream ---------------------------===// +//===- PTHLexer.cpp - Lex from a token stream -----------------------------===// // // The LLVM Compiler Infrastructure // @@ -12,19 +12,32 @@ //===----------------------------------------------------------------------===// #include "clang/Lex/PTHLexer.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/FileSystemStatCache.h" #include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/SourceManager.h" #include "clang/Basic/TokenKinds.h" #include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/PTHManager.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/Token.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Support/EndianStream.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/ErrorOr.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/OnDiskHashTable.h" +#include <cassert> +#include <cstdint> +#include <cstdlib> +#include <cstring> +#include <ctime> #include <memory> -#include <system_error> +#include <utility> + using namespace clang; static const unsigned StoredTokenSize = 1 + 1 + 2 + 4 + 4; @@ -35,9 +48,8 @@ static const unsigned StoredTokenSize = 1 + 1 + 2 + 4 + 4; PTHLexer::PTHLexer(Preprocessor &PP, FileID FID, const unsigned char *D, const unsigned char *ppcond, PTHManager &PM) - : PreprocessorLexer(&PP, FID), TokBuf(D), CurPtr(D), LastHashTokPtr(nullptr), - PPCond(ppcond), CurPPCondPtr(ppcond), PTHMgr(PM) { - + : PreprocessorLexer(&PP, FID), TokBuf(D), CurPtr(D), PPCond(ppcond), + CurPPCondPtr(ppcond), PTHMgr(PM) { FileStartLoc = PP.getSourceManager().getLocForStartOfFile(FID); } @@ -167,7 +179,7 @@ void PTHLexer::DiscardToEndOfLine() { // We don't need to actually reconstruct full tokens from the token buffer. // This saves some copies and it also reduces IdentifierInfo* lookup. const unsigned char* p = CurPtr; - while (1) { + while (true) { // Read the token kind. Are we at the end of the file? tok::TokenKind x = (tok::TokenKind) (uint8_t) *p; if (x == tok::eof) break; @@ -186,6 +198,7 @@ void PTHLexer::DiscardToEndOfLine() { /// SkipBlock - Used by Preprocessor to skip the current conditional block. bool PTHLexer::SkipBlock() { using namespace llvm::support; + assert(CurPPCondPtr && "No cached PP conditional information."); assert(LastHashTokPtr && "No known '#' token."); @@ -303,23 +316,24 @@ SourceLocation PTHLexer::getSourceLocation() { /// to map from FileEntry objects managed by FileManager to offsets within /// the PTH file. namespace { + class PTHFileData { const uint32_t TokenOff; const uint32_t PPCondOff; + public: PTHFileData(uint32_t tokenOff, uint32_t ppCondOff) - : TokenOff(tokenOff), PPCondOff(ppCondOff) {} + : TokenOff(tokenOff), PPCondOff(ppCondOff) {} uint32_t getTokenOffset() const { return TokenOff; } uint32_t getPPCondOffset() const { return PPCondOff; } }; - class PTHFileLookupCommonTrait { public: - typedef std::pair<unsigned char, StringRef> internal_key_type; - typedef unsigned hash_value_type; - typedef unsigned offset_type; + using internal_key_type = std::pair<unsigned char, StringRef>; + using hash_value_type = unsigned; + using offset_type = unsigned; static hash_value_type ComputeHash(internal_key_type x) { return llvm::HashString(x.second); @@ -328,6 +342,7 @@ public: static std::pair<unsigned, unsigned> ReadKeyDataLength(const unsigned char*& d) { using namespace llvm::support; + unsigned keyLen = (unsigned)endian::readNext<uint16_t, little, unaligned>(d); unsigned dataLen = (unsigned) *(d++); @@ -340,12 +355,12 @@ public: } }; -} // end anonymous namespace +} // namespace class PTHManager::PTHFileLookupTrait : public PTHFileLookupCommonTrait { public: - typedef const FileEntry* external_key_type; - typedef PTHFileData data_type; + using external_key_type = const FileEntry *; + using data_type = PTHFileData; static internal_key_type GetInternalKey(const FileEntry* FE) { return std::make_pair((unsigned char) 0x1, FE->getName()); @@ -357,8 +372,9 @@ public: static PTHFileData ReadData(const internal_key_type& k, const unsigned char* d, unsigned) { - assert(k.first == 0x1 && "Only file lookups can match!"); using namespace llvm::support; + + assert(k.first == 0x1 && "Only file lookups can match!"); uint32_t x = endian::readNext<uint32_t, little, unaligned>(d); uint32_t y = endian::readNext<uint32_t, little, unaligned>(d); return PTHFileData(x, y); @@ -367,11 +383,11 @@ public: class PTHManager::PTHStringLookupTrait { public: - typedef uint32_t data_type; - typedef const std::pair<const char*, unsigned> external_key_type; - typedef external_key_type internal_key_type; - typedef uint32_t hash_value_type; - typedef unsigned offset_type; + using data_type = uint32_t; + using external_key_type = const std::pair<const char *, unsigned>; + using internal_key_type = external_key_type; + using hash_value_type = uint32_t; + using offset_type = unsigned; static bool EqualKey(const internal_key_type& a, const internal_key_type& b) { @@ -390,6 +406,7 @@ public: static std::pair<unsigned, unsigned> ReadKeyDataLength(const unsigned char*& d) { using namespace llvm::support; + return std::make_pair( (unsigned)endian::readNext<uint16_t, little, unaligned>(d), sizeof(uint32_t)); @@ -404,6 +421,7 @@ public: static uint32_t ReadData(const internal_key_type& k, const unsigned char* d, unsigned) { using namespace llvm::support; + return endian::readNext<uint32_t, little, unaligned>(d); } }; @@ -420,11 +438,10 @@ PTHManager::PTHManager( const unsigned char *spellingBase, const char *originalSourceFile) : Buf(std::move(buf)), PerIDCache(std::move(perIDCache)), FileLookup(std::move(fileLookup)), IdDataTable(idDataTable), - StringIdLookup(std::move(stringIdLookup)), NumIds(numIds), PP(nullptr), + StringIdLookup(std::move(stringIdLookup)), NumIds(numIds), SpellingBase(spellingBase), OriginalSourceFile(originalSourceFile) {} -PTHManager::~PTHManager() { -} +PTHManager::~PTHManager() = default; static void InvalidPTH(DiagnosticsEngine &Diags, const char *Msg) { Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0")) << Msg; @@ -557,6 +574,7 @@ PTHManager *PTHManager::Create(StringRef file, DiagnosticsEngine &Diags) { IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) { using namespace llvm::support; + // Look in the PTH file for the string data for the IdentifierInfo object. const unsigned char* TableEntry = IdDataTable + sizeof(uint32_t)*PersistentID; const unsigned char *IDData = @@ -566,7 +584,7 @@ IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) { // Allocate the object. std::pair<IdentifierInfo,const unsigned char*> *Mem = - Alloc.Allocate<std::pair<IdentifierInfo,const unsigned char*> >(); + Alloc.Allocate<std::pair<IdentifierInfo, const unsigned char *>>(); Mem->second = IDData; assert(IDData[0] != '\0'); @@ -626,26 +644,26 @@ PTHLexer *PTHManager::CreateLexer(FileID FID) { //===----------------------------------------------------------------------===// namespace { + class PTHStatData { public: uint64_t Size; time_t ModTime; llvm::sys::fs::UniqueID UniqueID; - const bool HasData; + const bool HasData = false; bool IsDirectory; + PTHStatData() = default; PTHStatData(uint64_t Size, time_t ModTime, llvm::sys::fs::UniqueID UniqueID, bool IsDirectory) : Size(Size), ModTime(ModTime), UniqueID(UniqueID), HasData(true), IsDirectory(IsDirectory) {} - - PTHStatData() : HasData(false) {} }; class PTHStatLookupTrait : public PTHFileLookupCommonTrait { public: - typedef StringRef external_key_type; // const char* - typedef PTHStatData data_type; + using external_key_type = StringRef; // const char* + using data_type = PTHStatData; static internal_key_type GetInternalKey(StringRef path) { // The key 'kind' doesn't matter here because it is ignored in EqualKey. @@ -660,7 +678,6 @@ public: static data_type ReadData(const internal_key_type& k, const unsigned char* d, unsigned) { - if (k.first /* File or Directory */) { bool IsDirectory = true; if (k.first == 0x1 /* File */) { @@ -682,11 +699,14 @@ public: return data_type(); } }; -} // end anonymous namespace + +} // namespace namespace clang { + class PTHStatCache : public FileSystemStatCache { - typedef llvm::OnDiskChainedHashTable<PTHStatLookupTrait> CacheTy; + using CacheTy = llvm::OnDiskChainedHashTable<PTHStatLookupTrait>; + CacheTy Cache; public: @@ -720,7 +740,8 @@ public: return CacheExists; } }; -} + +} // namespace clang std::unique_ptr<FileSystemStatCache> PTHManager::createStatCache() { return llvm::make_unique<PTHStatCache>(*FileLookup); |