From: Jan Svoboda Date: Fri, 10 Dec 2021 13:16:29 +0000 (+0100) Subject: [clang][deps] NFC: Use clearer wording around entry initialization X-Git-Tag: upstream/15.0.7~22959 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3031fd71b91433f02f6dd8072a7d99ff24e8aad8;p=platform%2Fupstream%2Fllvm.git [clang][deps] NFC: Use clearer wording around entry initialization The code and documentation around `CachedFileSystemEntry` use the following terms: * "invalid stat" for `llvm::ErrorOr` that is *not* an error and contains an unknown status, * "initialized entry" for an entry that contains "invalid stat", * "valid entry" for an entry that contains "invalid stat", synonymous to "initialized" entry. Having an entry be "valid" while it contains an "invalid" status object is counter-intuitive. This patch cleans up the wording by referring to the status as "unknown" and to the entry as either "initialized" or "uninitialized". --- diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h index 25a7d57..4b286df 100644 --- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h +++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h @@ -30,10 +30,10 @@ namespace dependencies { /// - an opened source file with original contents and a stat value. /// - a directory entry with its stat value. /// - an error value to represent a file system error. -/// - a placeholder with an invalid stat indicating a not yet initialized entry. +/// - uninitialized entry with unknown status. class CachedFileSystemEntry { public: - /// Default constructor creates an entry with an invalid stat. + /// Creates an uninitialized entry. CachedFileSystemEntry() : MaybeStat(llvm::vfs::Status()) {} CachedFileSystemEntry(std::error_code Error) : MaybeStat(std::move(Error)) {} @@ -51,8 +51,10 @@ public: /// Create an entry that represents a directory on the filesystem. static CachedFileSystemEntry createDirectoryEntry(llvm::vfs::Status &&Stat); - /// \returns True if the entry is valid. - bool isValid() const { return !MaybeStat || MaybeStat->isStatusKnown(); } + /// \returns True if the entry is initialized. + bool isInitialized() const { + return !MaybeStat || MaybeStat->isStatusKnown(); + } /// \returns True if the current entry points to a directory. bool isDirectory() const { return MaybeStat && MaybeStat->isDirectory(); } @@ -62,19 +64,19 @@ public: if (!MaybeStat) return MaybeStat.getError(); assert(!MaybeStat->isDirectory() && "not a file"); - assert(isValid() && "not initialized"); + assert(isInitialized() && "not initialized"); return Contents->getBuffer(); } /// \returns The error or the status of the entry. llvm::ErrorOr getStatus() const { - assert(isValid() && "not initialized"); + assert(isInitialized() && "not initialized"); return MaybeStat; } /// \returns the name of the file. StringRef getName() const { - assert(isValid() && "not initialized"); + assert(isInitialized() && "not initialized"); return MaybeStat->getName(); } diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp index 367989f..32e8acb 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp @@ -188,7 +188,7 @@ DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry( std::lock_guard LockGuard(SharedCacheEntry.ValueLock); CachedFileSystemEntry &CacheEntry = SharedCacheEntry.Value; - if (!CacheEntry.isValid()) { + if (!CacheEntry.isInitialized()) { auto MaybeStatus = getUnderlyingFS().status(Filename); if (!MaybeStatus && !shouldCacheStatFailures(Filename)) // HACK: We need to always restat non source files if the stat fails.