aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/include/clang/Basic/DirectoryEntry.h
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/include/clang/Basic/DirectoryEntry.h')
-rw-r--r--contrib/llvm-project/clang/include/clang/Basic/DirectoryEntry.h137
1 files changed, 44 insertions, 93 deletions
diff --git a/contrib/llvm-project/clang/include/clang/Basic/DirectoryEntry.h b/contrib/llvm-project/clang/include/clang/Basic/DirectoryEntry.h
index edb8031a20b8..906c2e9af23b 100644
--- a/contrib/llvm-project/clang/include/clang/Basic/DirectoryEntry.h
+++ b/contrib/llvm-project/clang/include/clang/Basic/DirectoryEntry.h
@@ -14,13 +14,18 @@
#ifndef LLVM_CLANG_BASIC_DIRECTORYENTRY_H
#define LLVM_CLANG_BASIC_DIRECTORYENTRY_H
+#include "clang/Basic/CustomizableOptional.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ErrorOr.h"
+#include <optional>
+#include <utility>
+
namespace clang {
namespace FileMgr {
@@ -31,12 +36,17 @@ template <class RefTy> class MapEntryOptionalStorage;
/// Cached information about one directory (either on disk or in
/// the virtual file system).
class DirectoryEntry {
+ DirectoryEntry() = default;
+ DirectoryEntry(const DirectoryEntry &) = delete;
+ DirectoryEntry &operator=(const DirectoryEntry &) = delete;
friend class FileManager;
+ friend class FileEntryTestHelper;
// FIXME: We should not be storing a directory entry name here.
StringRef Name; // Name of the directory.
public:
+ LLVM_DEPRECATED("Use DirectoryEntryRef::getName() instead.", "")
StringRef getName() const { return Name; }
};
@@ -62,7 +72,7 @@ public:
bool isSameRef(DirectoryEntryRef RHS) const { return ME == RHS.ME; }
DirectoryEntryRef() = delete;
- DirectoryEntryRef(const MapEntry &ME) : ME(&ME) {}
+ explicit DirectoryEntryRef(const MapEntry &ME) : ME(&ME) {}
/// Allow DirectoryEntryRef to degrade into 'const DirectoryEntry*' to
/// facilitate incremental adoption.
@@ -108,6 +118,8 @@ private:
const MapEntry *ME;
};
+using OptionalDirectoryEntryRef = CustomizableOptional<DirectoryEntryRef>;
+
namespace FileMgr {
/// Customized storage for refs derived from map entires in FileManager, using
@@ -120,27 +132,25 @@ public:
MapEntryOptionalStorage() : MaybeRef(optional_none_tag()) {}
template <class... ArgTypes>
- explicit MapEntryOptionalStorage(llvm::in_place_t, ArgTypes &&...Args)
+ explicit MapEntryOptionalStorage(std::in_place_t, ArgTypes &&...Args)
: MaybeRef(std::forward<ArgTypes>(Args)...) {}
void reset() { MaybeRef = optional_none_tag(); }
- bool hasValue() const { return MaybeRef.hasOptionalValue(); }
+ bool has_value() const { return MaybeRef.hasOptionalValue(); }
- RefTy &getValue() LLVM_LVALUE_FUNCTION {
- assert(hasValue());
+ RefTy &value() & {
+ assert(has_value());
return MaybeRef;
}
- RefTy const &getValue() const LLVM_LVALUE_FUNCTION {
- assert(hasValue());
+ RefTy const &value() const & {
+ assert(has_value());
return MaybeRef;
}
-#if LLVM_HAS_RVALUE_REFERENCE_THIS
- RefTy &&getValue() && {
- assert(hasValue());
+ RefTy &&value() && {
+ assert(has_value());
return std::move(MaybeRef);
}
-#endif
template <class... Args> void emplace(Args &&...args) {
MaybeRef = RefTy(std::forward<Args>(args)...);
@@ -153,9 +163,7 @@ public:
};
} // end namespace FileMgr
-} // end namespace clang
-namespace llvm {
namespace optional_detail {
/// Customize OptionalStorage<DirectoryEntryRef> to use DirectoryEntryRef and
@@ -170,8 +178,8 @@ public:
OptionalStorage() = default;
template <class... ArgTypes>
- explicit OptionalStorage(in_place_t, ArgTypes &&...Args)
- : StorageImpl(in_place_t{}, std::forward<ArgTypes>(Args)...) {}
+ explicit OptionalStorage(std::in_place_t, ArgTypes &&...Args)
+ : StorageImpl(std::in_place_t{}, std::forward<ArgTypes>(Args)...) {}
OptionalStorage &operator=(clang::DirectoryEntryRef Ref) {
StorageImpl::operator=(Ref);
@@ -179,15 +187,30 @@ public:
}
};
-static_assert(sizeof(Optional<clang::DirectoryEntryRef>) ==
- sizeof(clang::DirectoryEntryRef),
- "Optional<DirectoryEntryRef> must avoid size overhead");
+static_assert(sizeof(OptionalDirectoryEntryRef) == sizeof(DirectoryEntryRef),
+ "OptionalDirectoryEntryRef must avoid size overhead");
-static_assert(
- std::is_trivially_copyable<Optional<clang::DirectoryEntryRef>>::value,
- "Optional<DirectoryEntryRef> should be trivially copyable");
+static_assert(std::is_trivially_copyable<OptionalDirectoryEntryRef>::value,
+ "OptionalDirectoryEntryRef should be trivially copyable");
} // end namespace optional_detail
+} // namespace clang
+
+namespace llvm {
+
+template <> struct PointerLikeTypeTraits<clang::DirectoryEntryRef> {
+ static inline void *getAsVoidPointer(clang::DirectoryEntryRef Dir) {
+ return const_cast<clang::DirectoryEntryRef::MapEntry *>(&Dir.getMapEntry());
+ }
+
+ static inline clang::DirectoryEntryRef getFromVoidPointer(void *Ptr) {
+ return clang::DirectoryEntryRef(
+ *reinterpret_cast<const clang::DirectoryEntryRef::MapEntry *>(Ptr));
+ }
+
+ static constexpr int NumLowBitsAvailable = PointerLikeTypeTraits<
+ const clang::DirectoryEntryRef::MapEntry *>::NumLowBitsAvailable;
+};
/// Specialisation of DenseMapInfo for DirectoryEntryRef.
template <> struct DenseMapInfo<clang::DirectoryEntryRef> {
@@ -222,76 +245,4 @@ template <> struct DenseMapInfo<clang::DirectoryEntryRef> {
} // end namespace llvm
-namespace clang {
-
-/// Wrapper around Optional<DirectoryEntryRef> that degrades to 'const
-/// DirectoryEntry*', facilitating incremental patches to propagate
-/// DirectoryEntryRef.
-///
-/// This class can be used as return value or field where it's convenient for
-/// an Optional<DirectoryEntryRef> to degrade to a 'const DirectoryEntry*'. The
-/// purpose is to avoid code churn due to dances like the following:
-/// \code
-/// // Old code.
-/// lvalue = rvalue;
-///
-/// // Temporary code from an incremental patch.
-/// Optional<DirectoryEntryRef> MaybeF = rvalue;
-/// lvalue = MaybeF ? &MaybeF.getDirectoryEntry() : nullptr;
-///
-/// // Final code.
-/// lvalue = rvalue;
-/// \endcode
-///
-/// FIXME: Once DirectoryEntryRef is "everywhere" and DirectoryEntry::LastRef
-/// and DirectoryEntry::getName have been deleted, delete this class and
-/// replace instances with Optional<DirectoryEntryRef>.
-class OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr
- : public Optional<DirectoryEntryRef> {
-public:
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr() = default;
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &&) = default;
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(
- const OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &) = default;
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
- operator=(OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &&) = default;
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
- operator=(const OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &) = default;
-
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(llvm::NoneType) {}
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(DirectoryEntryRef Ref)
- : Optional<DirectoryEntryRef>(Ref) {}
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(Optional<DirectoryEntryRef> MaybeRef)
- : Optional<DirectoryEntryRef>(MaybeRef) {}
-
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &operator=(llvm::NoneType) {
- Optional<DirectoryEntryRef>::operator=(None);
- return *this;
- }
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &operator=(DirectoryEntryRef Ref) {
- Optional<DirectoryEntryRef>::operator=(Ref);
- return *this;
- }
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
- operator=(Optional<DirectoryEntryRef> MaybeRef) {
- Optional<DirectoryEntryRef>::operator=(MaybeRef);
- return *this;
- }
-
- /// Degrade to 'const DirectoryEntry *' to allow DirectoryEntry::LastRef and
- /// DirectoryEntry::getName have been deleted, delete this class and replace
- /// instances with Optional<DirectoryEntryRef>
- operator const DirectoryEntry *() const {
- return hasValue() ? &getValue().getDirEntry() : nullptr;
- }
-};
-
-static_assert(std::is_trivially_copyable<
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr>::value,
- "OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr should be "
- "trivially copyable");
-
-} // end namespace clang
-
#endif // LLVM_CLANG_BASIC_DIRECTORYENTRY_H