void InclusionDirective(SourceLocation HashLoc, const Token & /*IncludeTok*/,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> /*File*/, StringRef SearchPath,
+ OptionalFileEntryRef /*File*/, StringRef SearchPath,
StringRef /*RelativePath*/,
const Module * /*Imported*/,
SrcMgr::CharacteristicKind /*FileType*/) override {
void ExpandModularHeadersPPCallbacks::InclusionDirective(
SourceLocation DirectiveLoc, const Token &IncludeToken,
StringRef IncludedFilename, bool IsAngled, CharSourceRange FilenameRange,
- Optional<FileEntryRef> IncludedFile, StringRef SearchPath,
+ OptionalFileEntryRef IncludedFile, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
if (Imported) {
parseToLocation(Loc);
}
void ExpandModularHeadersPPCallbacks::HasInclude(SourceLocation Loc, StringRef,
- bool, Optional<FileEntryRef>,
+ bool, OptionalFileEntryRef,
SrcMgr::CharacteristicKind) {
parseToLocation(Loc);
}
void InclusionDirective(SourceLocation DirectiveLoc,
const Token &IncludeToken, StringRef IncludedFilename,
bool IsAngled, CharSourceRange FilenameRange,
- Optional<FileEntryRef> IncludedFile,
+ OptionalFileEntryRef IncludedFile,
StringRef SearchPath, StringRef RelativePath,
const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void PragmaDiagnosticPop(SourceLocation Loc, StringRef) override;
void PragmaDiagnostic(SourceLocation Loc, StringRef, diag::Severity,
StringRef) override;
- void HasInclude(SourceLocation Loc, StringRef, bool, Optional<FileEntryRef> ,
+ void HasInclude(SourceLocation Loc, StringRef, bool, OptionalFileEntryRef,
SrcMgr::CharacteristicKind) override;
void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *,
SourceLocation StateLoc, unsigned) override;
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FileNameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void KernelNameRestrictionPPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &, StringRef FileName, bool,
- CharSourceRange, Optional<FileEntryRef>, StringRef, StringRef,
- const Module *, SrcMgr::CharacteristicKind) {
+ CharSourceRange, OptionalFileEntryRef, StringRef, StringRef, const Module *,
+ SrcMgr::CharacteristicKind) {
IncludeDirective ID = {HashLoc, FileName};
IncludeDirectives.push_back(std::move(ID));
}
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void SuspiciousIncludePPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
if (IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import)
llvm::sys::path::replace_extension(GuessedFileName,
(HFE.size() ? "." : "") + HFE);
- Optional<FileEntryRef> File =
+ OptionalFileEntryRef File =
PP->LookupFile(DiagLoc, GuessedFileName, IsAngled, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
if (File) {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void EndOfMainFile() override;
void IncludeOrderPPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
// We recognize the first include as a special main module header and want
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void RestrictedIncludesPPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
// Compiler provided headers are allowed (e.g stddef.h).
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void IncludeModernizePPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
clearCurrentEnum(HashLoc);
void RestrictedIncludesPPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
if (!Check.contains(FileName) && SrcMgr::isSystem(FileType)) {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void EndOfMainFile() override;
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void DuplicateIncludeCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
if (llvm::is_contained(Files.back(), FileName)) {
void InclusionDirective(SourceLocation HashLocation,
const Token &IncludeToken, StringRef FileNameRef,
bool IsAngled, CharSourceRange FileNameRange,
- Optional<FileEntryRef> /*IncludedFile*/,
+ OptionalFileEntryRef /*IncludedFile*/,
StringRef /*SearchPath*/, StringRef /*RelativePath*/,
const Module * /*ImportedModule*/,
SrcMgr::CharacteristicKind /*FileType*/) override {
diag(Error, "Invalid regex " + Anchored + ": " + RegexError, Text.Range);
return std::nullopt;
}
- return Result;
+ return std::move(Result);
}
std::optional<std::string> makeAbsolute(Located<std::string> Path,
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
CharSourceRange /*FilenameRange*/,
- Optional<FileEntryRef> File,
+ OptionalFileEntryRef File,
llvm::StringRef /*SearchPath*/,
llvm::StringRef /*RelativePath*/,
const clang::Module * /*Imported*/,
void replay() {
for (const auto &Inc : Includes) {
- llvm::Optional<FileEntryRef> File;
+ OptionalFileEntryRef File;
if (Inc.Resolved != "")
File = expectedToOptional(SM.getFileManager().getFileRef(Inc.Resolved));
make_move_iterator(UnusedHeadersDiags.begin()),
make_move_iterator(UnusedHeadersDiags.end()));
}
- return Result;
+ return std::move(Result);
}
ParsedAST::ParsedAST(ParsedAST &&Other) = default;
namespace clangd {
namespace {
-llvm::Optional<std::string> toURI(Optional<FileEntryRef> File) {
+llvm::Optional<std::string> toURI(OptionalFileEntryRef File) {
if (!File)
return std::nullopt;
auto AbsolutePath = File->getFileEntry().tryGetRealPathName();
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File,
- llvm::StringRef SearchPath,
+ OptionalFileEntryRef File, llvm::StringRef SearchPath,
llvm::StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
auto IncludeURI = toURI(File);
HI.CalleeArgInfo.emplace();
HI.CalleeArgInfo->Name = "arg_b";
HI.CalleeArgInfo->Type = "int &";
- HI.CallPassType.emplace();
- HI.CallPassType->PassBy = PassMode::Ref;
- HI.CallPassType->Converted = false;
+ HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false};
}},
{// Extra info for method call.
R"cpp(
HI.CalleeArgInfo->Name = "arg_a";
HI.CalleeArgInfo->Type = "int";
HI.CalleeArgInfo->Default = "3";
- HI.CallPassType.emplace();
- HI.CallPassType->PassBy = PassMode::Value;
- HI.CallPassType->Converted = false;
+ HI.CallPassType = HoverInfo::PassType{PassMode::Value, false};
}},
{// Dont crash on invalid decl
R"cpp(
HI.CalleeArgInfo->Name = "arg_a";
HI.CalleeArgInfo->Type = "int";
HI.CalleeArgInfo->Default = "7";
- HI.CallPassType.emplace();
- HI.CallPassType->PassBy = PassMode::Value;
- HI.CallPassType->Converted = false;
+ HI.CallPassType = HoverInfo::PassType{PassMode::Value, false};
},
R"(variable foo
HI.CalleeArgInfo->Name = "arg_a";
HI.CalleeArgInfo->Type = "int";
HI.CalleeArgInfo->Default = "7";
- HI.CallPassType.emplace();
- HI.CallPassType->PassBy = PassMode::Ref;
- HI.CallPassType->Converted = false;
+ HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false};
},
R"(variable foo
HI.CalleeArgInfo->Name = "arg_a";
HI.CalleeArgInfo->Type = {"alias_int", "int"};
HI.CalleeArgInfo->Default = "7";
- HI.CallPassType.emplace();
- HI.CallPassType->PassBy = PassMode::Value;
- HI.CallPassType->Converted = true;
+ HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
},
R"(variable foo
HI.CalleeArgInfo->Name = "arg_a";
HI.CalleeArgInfo->Type = "int";
HI.CalleeArgInfo->Default = "7";
- HI.CallPassType.emplace();
- HI.CallPassType->PassBy = PassMode::ConstRef;
- HI.CallPassType->Converted = true;
+ HI.CallPassType = HoverInfo::PassType{PassMode::ConstRef, true};
},
R"(variable foo
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
- CharSourceRange FilenameRange,
- Optional<FileEntryRef>, StringRef, StringRef,
- const clang::Module *,
+ CharSourceRange FilenameRange, OptionalFileEntryRef,
+ StringRef, StringRef, const clang::Module *,
SrcMgr::CharacteristicKind) override {
Includes.emplace_back(SM, HashLoc, IncludeTok, FileName, IsAngled,
FilenameRange);
void InclusionDirective(SourceLocation Hash, const Token &IncludeTok,
StringRef SpelledFilename, bool IsAngled,
CharSourceRange FilenameRange,
- llvm::Optional<FileEntryRef> File,
- StringRef SearchPath, StringRef RelativePath,
- const Module *, SrcMgr::CharacteristicKind) override {
+ OptionalFileEntryRef File, StringRef SearchPath,
+ StringRef RelativePath, const Module *,
+ SrcMgr::CharacteristicKind) override {
if (!Active)
return;
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
CharSourceRange /*FilenameRange*/,
- Optional<FileEntryRef> File,
+ OptionalFileEntryRef File,
llvm::StringRef /*SearchPath*/,
llvm::StringRef /*RelativePath*/,
const clang::Module * /*Imported*/,
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
Checker.collectUmbrellaHeaderHeader(File->getName());
const clang::Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
clang::CharSourceRange FilenameRange,
- llvm::Optional<clang::FileEntryRef> File,
+ clang::OptionalFileEntryRef File,
llvm::StringRef SearchPath,
llvm::StringRef RelativePath,
const clang::Module *Imported,
void PreprocessorCallbacks::InclusionDirective(
clang::SourceLocation HashLoc, const clang::Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
- clang::CharSourceRange FilenameRange,
- llvm::Optional<clang::FileEntryRef> File, llvm::StringRef SearchPath,
- llvm::StringRef RelativePath, const clang::Module *Imported,
- clang::SrcMgr::CharacteristicKind FileType) {
+ clang::CharSourceRange FilenameRange, clang::OptionalFileEntryRef File,
+ llvm::StringRef SearchPath, llvm::StringRef RelativePath,
+ const clang::Module *Imported, clang::SrcMgr::CharacteristicKind FileType) {
int DirectiveLine, DirectiveColumn;
std::string HeaderPath = getSourceLocationFile(PP, HashLoc);
getSourceLocationLineAndColumn(PP, HashLoc, DirectiveLine, DirectiveColumn);
// of whether the inclusion will actually result in an inclusion.
void PPCallbacksTracker::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
llvm::StringRef SearchPath, llvm::StringRef RelativePath,
const Module *Imported, SrcMgr::CharacteristicKind FileType) {
beginCallback("InclusionDirective");
// Append a FileEntry argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
- Optional<FileEntryRef> Value) {
+ OptionalFileEntryRef Value) {
if (!Value) {
appendArgument(Name, "(null)");
return;
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File,
- llvm::StringRef SearchPath,
+ OptionalFileEntryRef File, llvm::StringRef SearchPath,
llvm::StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,
void appendArgument(const char *Name, FileID Value);
/// Append a FileEntryRef argument to the top trace item.
- void appendArgument(const char *Name, Optional<FileEntryRef> Value);
+ void appendArgument(const char *Name, OptionalFileEntryRef Value);
void appendArgument(const char *Name, FileEntryRef Value);
/// Append a SourceLocation argument to the top trace item.
--- /dev/null
+//===- CustomizableOptional.h - Optional with custom storage ----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CLANG_BASIC_CUSTOMIZABLEOPTIONAL_H
+#define CLANG_BASIC_CUSTOMIZABLEOPTIONAL_H
+
+#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/Support/type_traits.h"
+#include <cassert>
+#include <new>
+#include <utility>
+
+namespace clang {
+
+namespace optional_detail {
+template <typename> class OptionalStorage;
+} // namespace optional_detail
+
+// Optional type which internal storage can be specialized by providing
+// OptionalStorage. The interface follows std::optional.
+template <typename T> class CustomizableOptional {
+ optional_detail::OptionalStorage<T> Storage;
+
+public:
+ using value_type = T;
+
+ constexpr CustomizableOptional() = default;
+ constexpr CustomizableOptional(std::nullopt_t) {}
+
+ constexpr CustomizableOptional(const T &y) : Storage(std::in_place, y) {}
+ constexpr CustomizableOptional(const CustomizableOptional &O) = default;
+
+ constexpr CustomizableOptional(T &&y)
+ : Storage(std::in_place, std::move(y)) {}
+ constexpr CustomizableOptional(CustomizableOptional &&O) = default;
+
+ template <typename... ArgTypes>
+ constexpr CustomizableOptional(std::in_place_t, ArgTypes &&...Args)
+ : Storage(std::in_place, std::forward<ArgTypes>(Args)...) {}
+
+ // Allow conversion from Optional<T>.
+ constexpr CustomizableOptional(const llvm::Optional<T> &y)
+ : CustomizableOptional(y ? *y : CustomizableOptional()) {}
+ constexpr CustomizableOptional(llvm::Optional<T> &&y)
+ : CustomizableOptional(y ? std::move(*y) : CustomizableOptional()) {}
+
+ CustomizableOptional &operator=(T &&y) {
+ Storage = std::move(y);
+ return *this;
+ }
+ CustomizableOptional &operator=(CustomizableOptional &&O) = default;
+
+ /// Create a new object by constructing it in place with the given arguments.
+ template <typename... ArgTypes> void emplace(ArgTypes &&...Args) {
+ Storage.emplace(std::forward<ArgTypes>(Args)...);
+ }
+
+ CustomizableOptional &operator=(const T &y) {
+ Storage = y;
+ return *this;
+ }
+ CustomizableOptional &operator=(const CustomizableOptional &O) = default;
+
+ void reset() { Storage.reset(); }
+
+ LLVM_DEPRECATED("Use &*X instead.", "&*X")
+ constexpr const T *getPointer() const { return &Storage.value(); }
+ LLVM_DEPRECATED("Use &*X instead.", "&*X")
+ T *getPointer() { return &Storage.value(); }
+ LLVM_DEPRECATED("std::optional::value is throwing. Use *X instead", "*X")
+ constexpr const T &value() const & { return Storage.value(); }
+ LLVM_DEPRECATED("std::optional::value is throwing. Use *X instead", "*X")
+ T &value() & { return Storage.value(); }
+
+ constexpr explicit operator bool() const { return has_value(); }
+ constexpr bool has_value() const { return Storage.has_value(); }
+ constexpr const T *operator->() const { return &Storage.value(); }
+ T *operator->() { return &Storage.value(); }
+ constexpr const T &operator*() const & { return Storage.value(); }
+ T &operator*() & { return Storage.value(); }
+
+ template <typename U> constexpr T value_or(U &&alt) const & {
+ return has_value() ? operator*() : std::forward<U>(alt);
+ }
+
+ LLVM_DEPRECATED("std::optional::value is throwing. Use *X instead", "*X")
+ T &&value() && { return std::move(Storage.value()); }
+ T &&operator*() && { return std::move(Storage.value()); }
+
+ template <typename U> T value_or(U &&alt) && {
+ return has_value() ? std::move(operator*()) : std::forward<U>(alt);
+ }
+
+ // Allow conversion to Optional<T>.
+ explicit operator llvm::Optional<T> &() const & {
+ return *this ? **this : llvm::Optional<T>();
+ }
+ explicit operator llvm::Optional<T> &&() const && {
+ return *this ? std::move(**this) : llvm::Optional<T>();
+ }
+};
+
+template <typename T>
+CustomizableOptional(const T &) -> CustomizableOptional<T>;
+
+template <class T>
+llvm::hash_code hash_value(const CustomizableOptional<T> &O) {
+ return O ? llvm::hash_combine(true, *O) : llvm::hash_value(false);
+}
+
+template <typename T, typename U>
+constexpr bool operator==(const CustomizableOptional<T> &X,
+ const CustomizableOptional<U> &Y) {
+ if (X && Y)
+ return *X == *Y;
+ return X.has_value() == Y.has_value();
+}
+
+template <typename T, typename U>
+constexpr bool operator!=(const CustomizableOptional<T> &X,
+ const CustomizableOptional<U> &Y) {
+ return !(X == Y);
+}
+
+template <typename T, typename U>
+constexpr bool operator<(const CustomizableOptional<T> &X,
+ const CustomizableOptional<U> &Y) {
+ if (X && Y)
+ return *X < *Y;
+ return X.has_value() < Y.has_value();
+}
+
+template <typename T, typename U>
+constexpr bool operator<=(const CustomizableOptional<T> &X,
+ const CustomizableOptional<U> &Y) {
+ return !(Y < X);
+}
+
+template <typename T, typename U>
+constexpr bool operator>(const CustomizableOptional<T> &X,
+ const CustomizableOptional<U> &Y) {
+ return Y < X;
+}
+
+template <typename T, typename U>
+constexpr bool operator>=(const CustomizableOptional<T> &X,
+ const CustomizableOptional<U> &Y) {
+ return !(X < Y);
+}
+
+template <typename T>
+constexpr bool operator==(const CustomizableOptional<T> &X, std::nullopt_t) {
+ return !X;
+}
+
+template <typename T>
+constexpr bool operator==(std::nullopt_t, const CustomizableOptional<T> &X) {
+ return X == std::nullopt;
+}
+
+template <typename T>
+constexpr bool operator!=(const CustomizableOptional<T> &X, std::nullopt_t) {
+ return !(X == std::nullopt);
+}
+
+template <typename T>
+constexpr bool operator!=(std::nullopt_t, const CustomizableOptional<T> &X) {
+ return X != std::nullopt;
+}
+
+template <typename T>
+constexpr bool operator<(const CustomizableOptional<T> &, std::nullopt_t) {
+ return false;
+}
+
+template <typename T>
+constexpr bool operator<(std::nullopt_t, const CustomizableOptional<T> &X) {
+ return X.has_value();
+}
+
+template <typename T>
+constexpr bool operator<=(const CustomizableOptional<T> &X, std::nullopt_t) {
+ return !(std::nullopt < X);
+}
+
+template <typename T>
+constexpr bool operator<=(std::nullopt_t, const CustomizableOptional<T> &X) {
+ return !(X < std::nullopt);
+}
+
+template <typename T>
+constexpr bool operator>(const CustomizableOptional<T> &X, std::nullopt_t) {
+ return std::nullopt < X;
+}
+
+template <typename T>
+constexpr bool operator>(std::nullopt_t, const CustomizableOptional<T> &X) {
+ return X < std::nullopt;
+}
+
+template <typename T>
+constexpr bool operator>=(const CustomizableOptional<T> &X, std::nullopt_t) {
+ return std::nullopt <= X;
+}
+
+template <typename T>
+constexpr bool operator>=(std::nullopt_t, const CustomizableOptional<T> &X) {
+ return X <= std::nullopt;
+}
+
+template <typename T>
+constexpr bool operator==(const CustomizableOptional<T> &X, const T &Y) {
+ return X && *X == Y;
+}
+
+template <typename T>
+constexpr bool operator==(const T &X, const CustomizableOptional<T> &Y) {
+ return Y && X == *Y;
+}
+
+template <typename T>
+constexpr bool operator!=(const CustomizableOptional<T> &X, const T &Y) {
+ return !(X == Y);
+}
+
+template <typename T>
+constexpr bool operator!=(const T &X, const CustomizableOptional<T> &Y) {
+ return !(X == Y);
+}
+
+template <typename T>
+constexpr bool operator<(const CustomizableOptional<T> &X, const T &Y) {
+ return !X || *X < Y;
+}
+
+template <typename T>
+constexpr bool operator<(const T &X, const CustomizableOptional<T> &Y) {
+ return Y && X < *Y;
+}
+
+template <typename T>
+constexpr bool operator<=(const CustomizableOptional<T> &X, const T &Y) {
+ return !(Y < X);
+}
+
+template <typename T>
+constexpr bool operator<=(const T &X, const CustomizableOptional<T> &Y) {
+ return !(Y < X);
+}
+
+template <typename T>
+constexpr bool operator>(const CustomizableOptional<T> &X, const T &Y) {
+ return Y < X;
+}
+
+template <typename T>
+constexpr bool operator>(const T &X, const CustomizableOptional<T> &Y) {
+ return Y < X;
+}
+
+template <typename T>
+constexpr bool operator>=(const CustomizableOptional<T> &X, const T &Y) {
+ return !(X < Y);
+}
+
+template <typename T>
+constexpr bool operator>=(const T &X, const CustomizableOptional<T> &Y) {
+ return !(X < Y);
+}
+
+} // namespace clang
+
+#endif // CLANG_BASIC_CUSTOMIZABLEOPTIONAL_H
}
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
+ SourceLocation L) {
+ DB.AddSourceRange(CharSourceRange::getTokenRange(L));
+ return DB;
+}
+
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
SourceRange R) {
DB.AddSourceRange(CharSourceRange::getTokenRange(R));
return DB;
#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/ADT/STLExtras.h"
#include "llvm/Support/ErrorOr.h"
#include <utility>
const MapEntry *ME;
};
+using OptionalDirectoryEntryRef = CustomizableOptional<DirectoryEntryRef>;
+
namespace FileMgr {
/// Customized storage for refs derived from map entires in FileManager, using
};
} // end namespace FileMgr
-} // end namespace clang
-namespace llvm {
namespace optional_detail {
/// Customize OptionalStorage<DirectoryEntryRef> to use DirectoryEntryRef and
}
};
-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 {
/// Specialisation of DenseMapInfo for DirectoryEntryRef.
template <> struct DenseMapInfo<clang::DirectoryEntryRef> {
static inline clang::DirectoryEntryRef getEmptyKey() {
namespace clang {
-/// Wrapper around Optional<DirectoryEntryRef> that degrades to 'const
+/// Wrapper around OptionalDirectoryEntryRef 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
+/// an OptionalDirectoryEntryRef 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;
+/// OptionalDirectoryEntryRef MaybeF = rvalue;
/// lvalue = MaybeF ? &MaybeF.getDirectoryEntry() : nullptr;
///
/// // Final code.
///
/// FIXME: Once DirectoryEntryRef is "everywhere" and DirectoryEntry::LastRef
/// and DirectoryEntry::getName have been deleted, delete this class and
-/// replace instances with Optional<DirectoryEntryRef>.
+/// replace instances with OptionalDirectoryEntryRef.
class OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr
- : public Optional<DirectoryEntryRef> {
+ : public OptionalDirectoryEntryRef {
public:
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr() = default;
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(std::nullopt_t) {}
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(DirectoryEntryRef Ref)
- : Optional<DirectoryEntryRef>(Ref) {}
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(Optional<DirectoryEntryRef> MaybeRef)
- : Optional<DirectoryEntryRef>(MaybeRef) {}
+ : OptionalDirectoryEntryRef(Ref) {}
+ OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(
+ OptionalDirectoryEntryRef MaybeRef)
+ : OptionalDirectoryEntryRef(MaybeRef) {}
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
operator=(std::nullopt_t) {
- Optional<DirectoryEntryRef>::operator=(std::nullopt);
+ OptionalDirectoryEntryRef::operator=(std::nullopt);
return *this;
}
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &operator=(DirectoryEntryRef Ref) {
- Optional<DirectoryEntryRef>::operator=(Ref);
+ OptionalDirectoryEntryRef::operator=(Ref);
return *this;
}
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
- operator=(Optional<DirectoryEntryRef> MaybeRef) {
- Optional<DirectoryEntryRef>::operator=(MaybeRef);
+ operator=(OptionalDirectoryEntryRef MaybeRef) {
+ OptionalDirectoryEntryRef::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>
+ /// instances with OptionalDirectoryEntryRef
operator const DirectoryEntry *() const {
return has_value() ? &(*this)->getDirEntry() : nullptr;
}
#ifndef LLVM_CLANG_BASIC_FILEENTRY_H
#define LLVM_CLANG_BASIC_FILEENTRY_H
+#include "clang/Basic/CustomizableOptional.h"
#include "clang/Basic/DirectoryEntry.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/DenseMapInfo.h"
class FileEntryRef;
-} // namespace clang
-
-namespace llvm {
namespace optional_detail {
/// Forward declare a template specialization for OptionalStorage.
-template <>
-class OptionalStorage<clang::FileEntryRef, /*is_trivially_copyable*/ true>;
+template <> class OptionalStorage<clang::FileEntryRef>;
} // namespace optional_detail
-} // namespace llvm
-
-namespace clang {
class FileEntry;
llvm::PointerUnion<FileEntry *, const void *> V;
/// Directory the file was found in. Set if and only if V is a FileEntry.
- Optional<DirectoryEntryRef> Dir;
+ OptionalDirectoryEntryRef Dir;
MapValue() = delete;
MapValue(FileEntry &FE, DirectoryEntryRef Dir) : V(&FE), Dir(Dir) {}
static_assert(std::is_trivially_copyable<FileEntryRef>::value,
"FileEntryRef must be trivially copyable");
-} // end namespace clang
+using OptionalFileEntryRef = CustomizableOptional<FileEntryRef>;
-namespace llvm {
namespace optional_detail {
/// Customize OptionalStorage<FileEntryRef> to use FileEntryRef and its
}
};
-static_assert(sizeof(Optional<clang::FileEntryRef>) ==
- sizeof(clang::FileEntryRef),
- "Optional<FileEntryRef> must avoid size overhead");
+static_assert(sizeof(OptionalFileEntryRef) == sizeof(FileEntryRef),
+ "OptionalFileEntryRef must avoid size overhead");
-static_assert(std::is_trivially_copyable<Optional<clang::FileEntryRef>>::value,
- "Optional<FileEntryRef> should be trivially copyable");
+static_assert(std::is_trivially_copyable<OptionalFileEntryRef>::value,
+ "OptionalFileEntryRef should be trivially copyable");
} // end namespace optional_detail
+} // namespace clang
+namespace llvm {
/// Specialisation of DenseMapInfo for FileEntryRef.
template <> struct DenseMapInfo<clang::FileEntryRef> {
static inline clang::FileEntryRef getEmptyKey() {
namespace clang {
-/// Wrapper around Optional<FileEntryRef> that degrades to 'const FileEntry*',
+/// Wrapper around OptionalFileEntryRef that degrades to 'const FileEntry*',
/// facilitating incremental patches to propagate FileEntryRef.
///
/// This class can be used as return value or field where it's convenient for
-/// an Optional<FileEntryRef> to degrade to a 'const FileEntry*'. The purpose
+/// an OptionalFileEntryRef to degrade to a 'const FileEntry*'. 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<FileEntryRef> MaybeF = rvalue;
+/// OptionalFileEntryRef MaybeF = rvalue;
/// lvalue = MaybeF ? &MaybeF.getFileEntry() : nullptr;
///
/// // Final code.
///
/// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and
/// FileEntry::getName have been deleted, delete this class and replace
-/// instances with Optional<FileEntryRef>.
-class OptionalFileEntryRefDegradesToFileEntryPtr
- : public Optional<FileEntryRef> {
+/// instances with OptionalFileEntryRef.
+class OptionalFileEntryRefDegradesToFileEntryPtr : public OptionalFileEntryRef {
public:
OptionalFileEntryRefDegradesToFileEntryPtr() = default;
OptionalFileEntryRefDegradesToFileEntryPtr(
OptionalFileEntryRefDegradesToFileEntryPtr(std::nullopt_t) {}
OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref)
- : Optional<FileEntryRef>(Ref) {}
- OptionalFileEntryRefDegradesToFileEntryPtr(Optional<FileEntryRef> MaybeRef)
- : Optional<FileEntryRef>(MaybeRef) {}
+ : OptionalFileEntryRef(Ref) {}
+ OptionalFileEntryRefDegradesToFileEntryPtr(OptionalFileEntryRef MaybeRef)
+ : OptionalFileEntryRef(MaybeRef) {}
OptionalFileEntryRefDegradesToFileEntryPtr &operator=(std::nullopt_t) {
- Optional<FileEntryRef>::operator=(std::nullopt);
+ OptionalFileEntryRef::operator=(std::nullopt);
return *this;
}
OptionalFileEntryRefDegradesToFileEntryPtr &operator=(FileEntryRef Ref) {
- Optional<FileEntryRef>::operator=(Ref);
+ OptionalFileEntryRef::operator=(Ref);
return *this;
}
OptionalFileEntryRefDegradesToFileEntryPtr &
- operator=(Optional<FileEntryRef> MaybeRef) {
- Optional<FileEntryRef>::operator=(MaybeRef);
+ operator=(OptionalFileEntryRef MaybeRef) {
+ OptionalFileEntryRef::operator=(MaybeRef);
return *this;
}
/// Degrade to 'const FileEntry *' to allow FileEntry::LastRef and
/// FileEntry::getName have been deleted, delete this class and replace
- /// instances with Optional<FileEntryRef>
+ /// instances with OptionalFileEntryRef
operator const FileEntry *() const {
return has_value() ? &(*this)->getFileEntry() : nullptr;
}
OptionalFileEntryRefDegradesToFileEntryPtr>::value,
"OptionalFileEntryRefDegradesToFileEntryPtr should be trivially copyable");
-inline bool operator==(const FileEntry *LHS,
- const Optional<FileEntryRef> &RHS) {
+inline bool operator==(const FileEntry *LHS, const OptionalFileEntryRef &RHS) {
return LHS == (RHS ? &RHS->getFileEntry() : nullptr);
}
-inline bool operator==(const Optional<FileEntryRef> &LHS,
- const FileEntry *RHS) {
+inline bool operator==(const OptionalFileEntryRef &LHS, const FileEntry *RHS) {
return (LHS ? &LHS->getFileEntry() : nullptr) == RHS;
}
-inline bool operator!=(const FileEntry *LHS,
- const Optional<FileEntryRef> &RHS) {
+inline bool operator!=(const FileEntry *LHS, const OptionalFileEntryRef &RHS) {
return !(LHS == RHS);
}
-inline bool operator!=(const Optional<FileEntryRef> &LHS,
- const FileEntry *RHS) {
+inline bool operator!=(const OptionalFileEntryRef &LHS, const FileEntry *RHS) {
return !(LHS == RHS);
}
// default constructor). It should always have a value in practice.
//
// TODO: remove this once everyone that needs a name uses FileEntryRef.
- Optional<FileEntryRef> LastRef;
+ OptionalFileEntryRef LastRef;
public:
~FileEntry();
SeenBypassFileEntries;
/// The file entry for stdin, if it has been accessed through the FileManager.
- Optional<FileEntryRef> STDIN;
+ OptionalFileEntryRef STDIN;
/// The canonical names of files and directories .
llvm::DenseMap<const void *, llvm::StringRef> CanonicalNames;
bool CacheFailure = true);
/// Get a \c DirectoryEntryRef if it exists, without doing anything on error.
- llvm::Optional<DirectoryEntryRef>
- getOptionalDirectoryRef(StringRef DirName, bool CacheFailure = true) {
+ OptionalDirectoryEntryRef getOptionalDirectoryRef(StringRef DirName,
+ bool CacheFailure = true) {
return llvm::expectedToOptional(getDirectoryRef(DirName, CacheFailure));
}
llvm::Expected<FileEntryRef> getSTDIN();
/// Get a FileEntryRef if it exists, without doing anything on error.
- llvm::Optional<FileEntryRef> getOptionalFileRef(StringRef Filename,
- bool OpenFile = false,
- bool CacheFailure = true) {
+ OptionalFileEntryRef getOptionalFileRef(StringRef Filename,
+ bool OpenFile = false,
+ bool CacheFailure = true) {
return llvm::expectedToOptional(
getFileRef(Filename, OpenFile, CacheFailure));
}
/// bypasses all mapping and uniquing, blindly creating a new FileEntry.
/// There is no attempt to deduplicate these; if you bypass the same file
/// twice, you get two new file entries.
- llvm::Optional<FileEntryRef> getBypassFile(FileEntryRef VFE);
+ OptionalFileEntryRef getBypassFile(FileEntryRef VFE);
/// Open the specified file as a MemoryBuffer, returning a new
/// MemoryBuffer if successful, otherwise returning null.
template<unsigned InternalLen> class SmallString;
template<typename T, unsigned N> class SmallVector;
template<typename T> class SmallVectorImpl;
- template<typename T> class Optional;
+ template <typename T> class Optional;
template <class T> class Expected;
template<typename T>
/// The AST file if this is a top-level module which has a
/// corresponding serialized AST file, or null otherwise.
- Optional<FileEntryRef> ASTFile;
+ OptionalFileEntryRef ASTFile;
/// The top-level headers associated with this module.
llvm::SmallSetVector<const FileEntry *, 2> TopHeaders;
}
/// Set the serialized AST file for the top-level module of this module.
- void setASTFile(Optional<FileEntryRef> File) {
+ void setASTFile(OptionalFileEntryRef File) {
assert((!getASTFile() || getASTFile() == File) && "file path changed");
getTopLevelModule()->ASTFile = File;
}
/// is no such file in the filesystem.
///
/// This should be called before parsing has begun.
- Optional<FileEntryRef> bypassFileContentsOverride(FileEntryRef File);
+ OptionalFileEntryRef bypassFileContentsOverride(FileEntryRef File);
/// Specify that a file is transient.
void setFileIsTransient(const FileEntry *SourceFile);
}
/// Returns the FileEntryRef for the provided FileID.
- Optional<FileEntryRef> getFileEntryRefForID(FileID FID) const {
+ OptionalFileEntryRef getFileEntryRefForID(FileID FID) const {
if (auto *Entry = getSLocEntryForFile(FID))
return Entry->getFile().getContentCache().OrigEntry;
return std::nullopt;
return isNormalDir() ? &u.Dir.getDirEntry() : nullptr;
}
- Optional<DirectoryEntryRef> getDirRef() const {
- return isNormalDir() ? Optional<DirectoryEntryRef>(u.Dir) : std::nullopt;
+ OptionalDirectoryEntryRef getDirRef() const {
+ return isNormalDir() ? OptionalDirectoryEntryRef(u.Dir) : std::nullopt;
}
/// getFrameworkDir - Return the directory that this framework refers to.
return isFramework() ? &u.Dir.getDirEntry() : nullptr;
}
- Optional<DirectoryEntryRef> getFrameworkDirRef() const {
- return isFramework() ? Optional<DirectoryEntryRef>(u.Dir) : std::nullopt;
+ OptionalDirectoryEntryRef getFrameworkDirRef() const {
+ return isFramework() ? OptionalDirectoryEntryRef(u.Dir) : std::nullopt;
}
/// getHeaderMap - Return the directory that this entry refers to.
/// \param [out] MappedName if this is a headermap which maps the filename to
/// a framework include ("Foo.h" -> "Foo/Foo.h"), set the new name to this
/// vector and point Filename to it.
- Optional<FileEntryRef>
+ OptionalFileEntryRef
LookupFile(StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc,
SmallVectorImpl<char> *SearchPath,
SmallVectorImpl<char> *RelativePath, Module *RequestingModule,
bool OpenFile = true) const;
private:
- Optional<FileEntryRef> DoFrameworkLookup(
+ OptionalFileEntryRef DoFrameworkLookup(
StringRef Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath,
SmallVectorImpl<char> *RelativePath, Module *RequestingModule,
ModuleMap::KnownHeader *SuggestedModule,
/// This structure is used to record entries in our framework cache.
struct FrameworkCacheEntry {
/// The directory entry which should be used for the cached framework.
- Optional<DirectoryEntryRef> Directory;
+ OptionalDirectoryEntryRef Directory;
/// Whether this framework has been "user-specified" to be treated as if it
/// were a system framework (even if it was found outside a system framework
/// found in any of searched SearchDirs. Will be set to false if a framework
/// is found only through header maps. Doesn't guarantee the requested file is
/// found.
- Optional<FileEntryRef> LookupFile(
+ OptionalFileEntryRef LookupFile(
StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir,
ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
/// within ".../Carbon.framework/Headers/Carbon.h", check to see if
/// HIToolbox is a subframework within Carbon.framework. If so, return
/// the FileEntry for the designated file, otherwise return null.
- Optional<FileEntryRef> LookupSubframeworkHeader(
+ OptionalFileEntryRef LookupSubframeworkHeader(
StringRef Filename, const FileEntry *ContextFileEnt,
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule);
/// Look up the file with the specified name and determine its owning
/// module.
- Optional<FileEntryRef>
+ OptionalFileEntryRef
getFileAndSuggestModule(StringRef FileName, SourceLocation IncludeLoc,
const DirectoryEntry *Dir, bool IsSystemHeaderDir,
Module *RequestingModule,
/// \param NeedsFramework If M is not a framework but a missing header would
/// be found in case M was, set it to true. False otherwise.
/// \return The resolved file, if any.
- Optional<FileEntryRef>
+ OptionalFileEntryRef
findHeader(Module *M, const Module::UnresolvedHeaderDirective &Header,
SmallVectorImpl<char> &RelativePathName, bool &NeedsFramework);
///
/// \returns The file entry for the module map file containing the given
/// module, or nullptr if the module definition was inferred.
- Optional<FileEntryRef> getContainingModuleMapFile(const Module *Module) const;
+ OptionalFileEntryRef getContainingModuleMapFile(const Module *Module) const;
/// Get the module map file that (along with the module name) uniquely
/// identifies this module.
/// of inferred modules, returns the module map that allowed the inference
/// (e.g. contained 'module *'). Otherwise, returns
/// getContainingModuleMapFile().
- Optional<FileEntryRef> getModuleMapFileForUniquing(const Module *M) const;
+ OptionalFileEntryRef getModuleMapFileForUniquing(const Module *M) const;
void setInferredModuleAllowedBy(Module *M, const FileEntry *ModMap);
/// implicitly 'extern "C"' in C++ mode.
///
virtual void InclusionDirective(SourceLocation HashLoc,
- const Token &IncludeTok,
- StringRef FileName,
- bool IsAngled,
- CharSourceRange FilenameRange,
- Optional<FileEntryRef> File,
- StringRef SearchPath,
- StringRef RelativePath,
+ const Token &IncludeTok, StringRef FileName,
+ bool IsAngled, CharSourceRange FilenameRange,
+ OptionalFileEntryRef File,
+ StringRef SearchPath, StringRef RelativePath,
const Module *Imported,
- SrcMgr::CharacteristicKind FileType) {
- }
+ SrcMgr::CharacteristicKind FileType) {}
/// Callback invoked whenever a submodule was entered.
///
/// Hook called when a '__has_include' or '__has_include_next' directive is
/// read.
virtual void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
- Optional<FileEntryRef> File,
+ OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType);
/// Hook called when a source range is skipped.
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
}
void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
- Optional<FileEntryRef> File,
+ OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType) override;
void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name,
unsigned ImportedModule : 1;
/// The file that was included.
- Optional<FileEntryRef> File;
+ OptionalFileEntryRef File;
public:
InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind,
StringRef FileName, bool InQuotes, bool ImportedModule,
- Optional<FileEntryRef> File, SourceRange Range);
+ OptionalFileEntryRef File, SourceRange Range);
/// Determine what kind of inclusion directive this is.
InclusionKind getKind() const { return static_cast<InclusionKind>(Kind); }
/// Retrieve the file entry for the actual file that was included
/// by this directive.
- Optional<FileEntryRef> getFile() const { return File; }
+ OptionalFileEntryRef getFile() const { return File; }
// Implement isa/cast/dyncast/etc.
static bool classof(const PreprocessedEntity *PE) {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
///
/// Returns std::nullopt on failure. \p isAngled indicates whether the file
/// reference is for system \#include's or not (i.e. using <> instead of "").
- Optional<FileEntryRef>
+ OptionalFileEntryRef
LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled,
ConstSearchDirIterator FromDir, const FileEntry *FromFile,
ConstSearchDirIterator *CurDir, SmallVectorImpl<char> *SearchPath,
}
};
- Optional<FileEntryRef> LookupHeaderIncludeOrImport(
+ OptionalFileEntryRef LookupHeaderIncludeOrImport(
ConstSearchDirIterator *CurDir, StringRef &Filename,
SourceLocation FilenameLoc, CharSourceRange FilenameRange,
const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl,
/// modification time criteria, false if the file is either available and
/// suitable, or is missing.
bool lookupModuleFile(StringRef FileName, off_t ExpectedSize,
- time_t ExpectedModTime, Optional<FileEntryRef> &File);
+ time_t ExpectedModTime, OptionalFileEntryRef &File);
/// View the graphviz representation of the module graph.
void viewGraph();
/// Equal-to operator between two Replacements.
bool operator==(const Replacement &LHS, const Replacement &RHS);
+inline bool operator!=(const Replacement &LHS, const Replacement &RHS) {
+ return !(LHS == RHS);
+}
/// Maintains a set of replacements that are conflict-free.
/// Two replacements are considered conflicts if they overlap or have the same
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,
#define LLVM_CLANG_TOOLING_INCLUSIONS_STANDARDLIBRARY_H
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>
return AllowListFilenames.find(llvm::sys::path::filename(Path)) !=
AllowListFilenames.end();
}
- bool canModifyFile(Optional<FileEntryRef> FE) {
+ bool canModifyFile(OptionalFileEntryRef FE) {
if (!FE)
return false;
return canModifyFile(FE->getName());
I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
FileID FID = I->first;
RewriteBuffer &buf = I->second;
- Optional<FileEntryRef> file = Ctx.getSourceManager().getFileEntryRefForID(FID);
+ OptionalFileEntryRef file =
+ Ctx.getSourceManager().getFileEntryRefForID(FID);
assert(file);
SmallString<512> newText;
llvm::raw_svector_ostream vecOS(newText);
namespace {
struct EditEntry {
- Optional<FileEntryRef> File;
+ OptionalFileEntryRef File;
unsigned Offset = 0;
unsigned RemoveLen = 0;
std::string Text;
return FileEntryRef(NamedFileEnt);
}
-llvm::Optional<FileEntryRef> FileManager::getBypassFile(FileEntryRef VF) {
+OptionalFileEntryRef FileManager::getBypassFile(FileEntryRef VF) {
// Stat of the file and return nullptr if it doesn't exist.
llvm::vfs::Status Status;
if (getStatValue(VF.getName(), Status, /*isFile=*/true, /*F=*/nullptr))
Pair.first->second = NewFile;
}
-Optional<FileEntryRef>
+OptionalFileEntryRef
SourceManager::bypassFileContentsOverride(FileEntryRef File) {
assert(isFileOverridden(&File.getFileEntry()));
- llvm::Optional<FileEntryRef> BypassFile = FileMgr.getBypassFile(File);
+ OptionalFileEntryRef BypassFile = FileMgr.getBypassFile(File);
// If the file can't be found in the FS, give up.
if (!BypassFile)
}
if (Opts.MaxBitIntWidth)
- MaxBitIntWidth = Opts.MaxBitIntWidth;
+ MaxBitIntWidth = static_cast<unsigned>(Opts.MaxBitIntWidth);
if (Opts.FakeAddressSpaceMap)
AddrSpaceMap = &FakeAddrSpaceMap;
// a relative path, so we look into the actual file entry for the main
// file to determine the real absolute path for the file.
std::string MainFileDir;
- if (Optional<FileEntryRef> MainFile =
+ if (OptionalFileEntryRef MainFile =
SM.getFileEntryRefForID(SM.getMainFileID())) {
MainFileDir = std::string(MainFile->getDir().getName());
if (!llvm::sys::path::is_absolute(MainFileName)) {
// The path to the source file where this module was declared
SourceManager &SM = CGM.getContext().getSourceManager();
- Optional<FileEntryRef> mainFile =
- SM.getFileEntryRefForID(SM.getMainFileID());
+ OptionalFileEntryRef mainFile = SM.getFileEntryRefForID(SM.getMainFileID());
std::string path =
(mainFile->getDir().getName() + "/" + mainFile->getName()).str();
module.add(MakeConstantString(path, ".objc_source_file_name"));
void MacroPPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
// Remap files in the source manager (with other files).
for (const auto &RF : InitOpts.RemappedFiles) {
// Find the file that we're mapping to.
- Optional<FileEntryRef> ToFile = FileMgr.getOptionalFileRef(RF.second);
+ OptionalFileEntryRef ToFile = FileMgr.getOptionalFileRef(RF.second);
if (!ToFile) {
Diags.Report(diag::err_fe_remap_missing_to_file) << RF.first << RF.second;
continue;
Instance.getFrontendOpts().AllowPCMWithCompilerErrors;
}
-static Optional<FileEntryRef> getPublicModuleMap(FileEntryRef File,
- FileManager &FileMgr) {
+static OptionalFileEntryRef getPublicModuleMap(FileEntryRef File,
+ FileManager &FileMgr) {
StringRef Filename = llvm::sys::path::filename(File.getName());
SmallString<128> PublicFilename(File.getDir().getName());
if (Filename == "module_private.map")
ModuleMap &ModMap
= ImportingInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap();
bool Result;
- if (Optional<FileEntryRef> ModuleMapFile =
+ if (OptionalFileEntryRef ModuleMapFile =
ModMap.getContainingModuleMapFile(Module)) {
// Canonicalize compilation to start with the public module map. This is
// vital for submodules declarations in the private module maps to be
// correctly parsed when depending on a top level module in the public one.
- if (Optional<FileEntryRef> PublicMMFile = getPublicModuleMap(
+ if (OptionalFileEntryRef PublicMMFile = getPublicModuleMap(
*ModuleMapFile, ImportingInstance.getFileManager()))
ModuleMapFile = PublicMMFile;
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
if (!File)
}
void HasInclude(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled,
- Optional<FileEntryRef> File,
+ OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType) override {
if (!File)
return;
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
}
void DependencyGraphCallback::InclusionDirective(
- SourceLocation HashLoc,
- const Token &IncludeTok,
- StringRef FileName,
- bool IsAngled,
- CharSourceRange FilenameRange,
- Optional<FileEntryRef> File,
- StringRef SearchPath,
- StringRef RelativePath,
- const Module *Imported,
+ SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
+ StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
if (!File)
return;
SourceManager &SM = PP->getSourceManager();
- Optional<FileEntryRef> FromFile =
+ OptionalFileEntryRef FromFile =
SM.getFileEntryRefForID(SM.getFileID(SM.getExpansionLoc(HashLoc)));
if (!FromFile)
return;
Dir = *DirOrErr;
SmallVector<std::pair<const FileEntry *, const DirectoryEntry *>, 1> CWD;
CWD.push_back({nullptr, Dir});
- Optional<FileEntryRef> FE =
+ OptionalFileEntryRef FE =
HS.LookupFile(FileName, SourceLocation(),
/*Angled*/ Input.getKind().getHeaderUnitKind() ==
InputKind::HeaderUnit_System,
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
if (!File)
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
// File is None if it wasn't found.
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void Ident(SourceLocation Loc, StringRef str) override;
}
void PrintPPOutputPPCallbacks::InclusionDirective(
- SourceLocation HashLoc,
- const Token &IncludeTok,
- StringRef FileName,
- bool IsAngled,
- CharSourceRange FilenameRange,
- Optional<FileEntryRef> File,
- StringRef SearchPath,
- StringRef RelativePath,
- const Module *Imported,
+ SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
+ StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
// In -dI mode, dump #include directives prior to dumping their content or
// interpretation.
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void If(SourceLocation Loc, SourceRange ConditionRange,
/// FileChanged() or FileSkipped() is called after this (or neither is
/// called if this #include results in an error or does not textually include
/// anything).
-void InclusionRewriter::InclusionDirective(SourceLocation HashLoc,
- const Token &/*IncludeTok*/,
- StringRef /*FileName*/,
- bool /*IsAngled*/,
- CharSourceRange /*FilenameRange*/,
- Optional<FileEntryRef> /*File*/,
- StringRef /*SearchPath*/,
- StringRef /*RelativePath*/,
- const Module *Imported,
- SrcMgr::CharacteristicKind FileType){
+void InclusionRewriter::InclusionDirective(
+ SourceLocation HashLoc, const Token & /*IncludeTok*/,
+ StringRef /*FileName*/, bool /*IsAngled*/,
+ CharSourceRange /*FilenameRange*/, OptionalFileEntryRef /*File*/,
+ StringRef /*SearchPath*/, StringRef /*RelativePath*/,
+ const Module *Imported, SrcMgr::CharacteristicKind FileType) {
if (Imported) {
auto P = ModuleIncludes.insert(std::make_pair(HashLoc, Imported));
(void)P;
ExpectedLoc = SourceLocation();
} else {
// Lookup file via Preprocessor, like a #include.
- Optional<FileEntryRef> File =
+ OptionalFileEntryRef File =
PP->LookupFile(Pos, Filename, false, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr);
if (!File) {
}
std::string HeaderSearch::getCachedModuleFileName(Module *Module) {
- Optional<FileEntryRef> ModuleMap =
+ OptionalFileEntryRef ModuleMap =
getModuleMap().getModuleMapFileForUniquing(Module);
// The ModuleMap maybe a nullptr, when we load a cached C++ module without
// *.modulemap file. In this case, just return an empty string.
}
std::string HeaderSearch::getPrebuiltImplicitModuleFileName(Module *Module) {
- Optional<FileEntryRef> ModuleMap =
+ OptionalFileEntryRef ModuleMap =
getModuleMap().getModuleMapFileForUniquing(Module);
StringRef ModuleName = Module->Name;
StringRef ModuleMapPath = ModuleMap->getName();
return getHeaderMap()->getFileName();
}
-Optional<FileEntryRef> HeaderSearch::getFileAndSuggestModule(
+OptionalFileEntryRef HeaderSearch::getFileAndSuggestModule(
StringRef FileName, SourceLocation IncludeLoc, const DirectoryEntry *Dir,
bool IsSystemHeaderDir, Module *RequestingModule,
ModuleMap::KnownHeader *SuggestedModule, bool OpenFile /*=true*/,
/// LookupFile - Lookup the specified file in this search path, returning it
/// if it exists or returning null if not.
-Optional<FileEntryRef> DirectoryLookup::LookupFile(
+OptionalFileEntryRef DirectoryLookup::LookupFile(
StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc,
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
/// \param DirName The name of the framework directory.
/// \param SubmodulePath Will be populated with the submodule path from the
/// returned top-level module to the originally named framework.
-static Optional<DirectoryEntryRef>
+static OptionalDirectoryEntryRef
getTopFrameworkDir(FileManager &FileMgr, StringRef DirName,
SmallVectorImpl<std::string> &SubmodulePath) {
assert(llvm::sys::path::extension(DirName) == ".framework" &&
/// DoFrameworkLookup - Do a lookup of the specified file in the current
/// DirectoryLookup, which is a framework directory.
-Optional<FileEntryRef> DirectoryLookup::DoFrameworkLookup(
+OptionalFileEntryRef DirectoryLookup::DoFrameworkLookup(
StringRef Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath,
SmallVectorImpl<char> *RelativePath, Module *RequestingModule,
ModuleMap::KnownHeader *SuggestedModule,
/// for system \#include's or not (i.e. using <> instead of ""). Includers, if
/// non-empty, indicates where the \#including file(s) are, in case a relative
/// search is needed. Microsoft mode will pass all \#including files.
-Optional<FileEntryRef> HeaderSearch::LookupFile(
+OptionalFileEntryRef HeaderSearch::LookupFile(
StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDirArg,
ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
// This is the header that MSVC's header search would have found.
ModuleMap::KnownHeader MSSuggestedModule;
- Optional<FileEntryRef> MSFE;
+ OptionalFileEntryRef MSFE;
// Unless disabled, check to see if the file is in the #includer's
// directory. This cannot be based on CurDir, because each includer could be
bool IncluderIsSystemHeader =
Includer ? getFileInfo(Includer).DirInfo != SrcMgr::C_User :
BuildSystemModule;
- if (Optional<FileEntryRef> FE = getFileAndSuggestModule(
+ if (OptionalFileEntryRef FE = getFileAndSuggestModule(
TmpDir, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader,
RequestingModule, SuggestedModule)) {
if (!Includer) {
bool InUserSpecifiedSystemFramework = false;
bool IsInHeaderMap = false;
bool IsFrameworkFoundInDir = false;
- Optional<FileEntryRef> File = It->LookupFile(
+ OptionalFileEntryRef File = It->LookupFile(
Filename, *this, IncludeLoc, SearchPath, RelativePath, RequestingModule,
SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir,
IsInHeaderMap, MappedName, OpenFile);
ScratchFilename += '/';
ScratchFilename += Filename;
- Optional<FileEntryRef> File = LookupFile(
+ OptionalFileEntryRef File = LookupFile(
ScratchFilename, IncludeLoc, /*isAngled=*/true, FromDir, &CurDir,
Includers.front(), SearchPath, RelativePath, RequestingModule,
SuggestedModule, IsMapped, /*IsFrameworkFound=*/nullptr);
/// within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox
/// is a subframework within Carbon.framework. If so, return the FileEntry
/// for the designated file, otherwise return null.
-Optional<FileEntryRef> HeaderSearch::LookupSubframeworkHeader(
+OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader(
StringRef Filename, const FileEntry *ContextFileEnt,
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule) {
if (needModuleLookup(RequestingModule, SuggestedModule)) {
// Find the top-level framework based on this framework.
SmallVector<std::string, 4> SubmodulePath;
- Optional<DirectoryEntryRef> TopFrameworkDir =
+ OptionalDirectoryEntryRef TopFrameworkDir =
::getTopFrameworkDir(FileMgr, FrameworkName, SubmodulePath);
assert(TopFrameworkDir && "Could not find the top-most framework dir");
StringRef OriginalModuleMapFile) {
// Find the directory for the module. For frameworks, that may require going
// up from the 'Modules' directory.
- Optional<DirectoryEntryRef> Dir;
+ OptionalDirectoryEntryRef Dir;
if (getHeaderSearchOpts().ModuleMapFileHomeIsCwd) {
Dir = FileMgr.getOptionalDirectoryRef(".");
} else {
llvm::sys::path::append(Path, "Frameworks", Framework + ".framework");
}
-Optional<FileEntryRef> ModuleMap::findHeader(
+OptionalFileEntryRef ModuleMap::findHeader(
Module *M, const Module::UnresolvedHeaderDirective &Header,
SmallVectorImpl<char> &RelativePathName, bool &NeedsFramework) {
// Search for the header file within the module's home directory.
auto *Directory = M->Directory;
SmallString<128> FullPathName(Directory->getName());
- auto GetFile = [&](StringRef Filename) -> Optional<FileEntryRef> {
+ auto GetFile = [&](StringRef Filename) -> OptionalFileEntryRef {
auto File =
expectedToOptional(SourceMgr.getFileManager().getFileRef(Filename));
if (!File || (Header.Size && File->getSize() != *Header.Size) ||
return *File;
};
- auto GetFrameworkFile = [&]() -> Optional<FileEntryRef> {
+ auto GetFrameworkFile = [&]() -> OptionalFileEntryRef {
unsigned FullPathLength = FullPathName.size();
appendSubframeworkPaths(M, RelativePathName);
unsigned RelativePathLength = RelativePathName.size();
const Module::UnresolvedHeaderDirective &Header,
bool &NeedsFramework) {
SmallString<128> RelativePathName;
- if (Optional<FileEntryRef> File =
+ if (OptionalFileEntryRef File =
findHeader(Mod, Header, RelativePathName, NeedsFramework)) {
if (Header.IsUmbrella) {
const DirectoryEntry *UmbrellaDir = &File->getDir().getDirEntry();
Cb->moduleMapAddHeader(Header.Entry->getName());
}
-Optional<FileEntryRef>
+OptionalFileEntryRef
ModuleMap::getContainingModuleMapFile(const Module *Module) const {
if (Module->DefinitionLoc.isInvalid())
return std::nullopt;
SourceMgr.getFileID(Module->DefinitionLoc));
}
-Optional<FileEntryRef>
+OptionalFileEntryRef
ModuleMap::getModuleMapFileForUniquing(const Module *M) const {
if (M->IsInferred) {
assert(InferredModuleAllowedBy.count(M) && "missing inferred module map");
PPCallbacks::~PPCallbacks() = default;
void PPCallbacks::HasInclude(SourceLocation Loc, StringRef FileName,
- bool IsAngled, Optional<FileEntryRef> File,
+ bool IsAngled, OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType) {}
// Out of line key method.
PPChainedCallbacks::~PPChainedCallbacks() = default;
void PPChainedCallbacks::HasInclude(SourceLocation Loc, StringRef FileName,
- bool IsAngled, Optional<FileEntryRef> File,
+ bool IsAngled, OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType) {
First->HasInclude(Loc, FileName, IsAngled, File, FileType);
Second->HasInclude(Loc, FileName, IsAngled, File, FileType);
}
-
return nullptr;
}
-Optional<FileEntryRef> Preprocessor::LookupFile(
+OptionalFileEntryRef Preprocessor::LookupFile(
SourceLocation FilenameLoc, StringRef Filename, bool isAngled,
ConstSearchDirIterator FromDir, const FileEntry *FromFile,
ConstSearchDirIterator *CurDirArg, SmallVectorImpl<char> *SearchPath,
// the include path until we find that file or run out of files.
ConstSearchDirIterator TmpCurDir = CurDir;
ConstSearchDirIterator TmpFromDir = nullptr;
- while (Optional<FileEntryRef> FE = HeaderInfo.LookupFile(
+ while (OptionalFileEntryRef FE = HeaderInfo.LookupFile(
Filename, FilenameLoc, isAngled, TmpFromDir, &TmpCurDir,
Includers, SearchPath, RelativePath, RequestingModule,
SuggestedModule, /*IsMapped=*/nullptr,
}
// Do a standard file entry lookup.
- Optional<FileEntryRef> FE = HeaderInfo.LookupFile(
+ OptionalFileEntryRef FE = HeaderInfo.LookupFile(
Filename, FilenameLoc, isAngled, FromDir, &CurDir, Includers, SearchPath,
RelativePath, RequestingModule, SuggestedModule, IsMapped,
IsFrameworkFound, SkipCache, BuildSystemModule, OpenFile, CacheFailures);
// headers on the #include stack and pass them to HeaderInfo.
if (IsFileLexer()) {
if ((CurFileEnt = CurPPLexer->getFileEntry())) {
- if (Optional<FileEntryRef> FE = HeaderInfo.LookupSubframeworkHeader(
+ if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader(
Filename, CurFileEnt, SearchPath, RelativePath, RequestingModule,
SuggestedModule)) {
if (SuggestedModule && !LangOpts.AsmPreprocessor)
for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
if (IsFileLexer(ISEntry)) {
if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) {
- if (Optional<FileEntryRef> FE = HeaderInfo.LookupSubframeworkHeader(
+ if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader(
Filename, CurFileEnt, SearchPath, RelativePath,
RequestingModule, SuggestedModule)) {
if (SuggestedModule && !LangOpts.AsmPreprocessor)
}
}
-Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport(
+OptionalFileEntryRef Preprocessor::LookupHeaderIncludeOrImport(
ConstSearchDirIterator *CurDir, StringRef &Filename,
SourceLocation FilenameLoc, CharSourceRange FilenameRange,
const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl,
const FileEntry *LookupFromFile, StringRef &LookupFilename,
SmallVectorImpl<char> &RelativePath, SmallVectorImpl<char> &SearchPath,
ModuleMap::KnownHeader &SuggestedModule, bool isAngled) {
- Optional<FileEntryRef> File = LookupFile(
- FilenameLoc, LookupFilename,
- isAngled, LookupFrom, LookupFromFile, CurDir,
+ OptionalFileEntryRef File = LookupFile(
+ FilenameLoc, LookupFilename, isAngled, LookupFrom, LookupFromFile, CurDir,
Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr,
&SuggestedModule, &IsMapped, &IsFrameworkFound);
if (File)
// brackets, we can attempt a lookup as though it were a quoted path to
// provide the user with a possible fixit.
if (isAngled) {
- Optional<FileEntryRef> File = LookupFile(
- FilenameLoc, LookupFilename,
- false, LookupFrom, LookupFromFile, CurDir,
+ OptionalFileEntryRef File = LookupFile(
+ FilenameLoc, LookupFilename, false, LookupFrom, LookupFromFile, CurDir,
Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr,
&SuggestedModule, &IsMapped,
/*IsFrameworkFound=*/nullptr);
StringRef TypoCorrectionName = CorrectTypoFilename(Filename);
StringRef TypoCorrectionLookupName = CorrectTypoFilename(LookupFilename);
- Optional<FileEntryRef> File = LookupFile(
- FilenameLoc, TypoCorrectionLookupName, isAngled, LookupFrom, LookupFromFile,
- CurDir, Callbacks ? &SearchPath : nullptr,
+ OptionalFileEntryRef File = LookupFile(
+ FilenameLoc, TypoCorrectionLookupName, isAngled, LookupFrom,
+ LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr,
Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped,
/*IsFrameworkFound=*/nullptr);
if (File) {
BackslashStyle = llvm::sys::path::Style::windows;
}
- Optional<FileEntryRef> File = LookupHeaderIncludeOrImport(
+ OptionalFileEntryRef File = LookupHeaderIncludeOrImport(
&CurDir, Filename, FilenameLoc, FilenameRange, FilenameTok,
IsFrameworkFound, IsImportDecl, IsMapped, LookupFrom, LookupFromFile,
LookupFilename, RelativePath, SearchPath, SuggestedModule, isAngled);
Lexer *TheLexer = new Lexer(FID, *InputFile, *this, IsFirstIncludeOfFile);
if (getPreprocessorOpts().DependencyDirectivesForFile &&
FID != PredefinesFileID) {
- if (Optional<FileEntryRef> File = SourceMgr.getFileEntryRefForID(FID)) {
+ if (OptionalFileEntryRef File = SourceMgr.getFileEntryRefForID(FID)) {
if (Optional<ArrayRef<dependency_directives_scan::Directive>>
DepDirectives =
getPreprocessorOpts().DependencyDirectivesForFile(*File)) {
return false;
// Search include directories.
- Optional<FileEntryRef> File =
+ OptionalFileEntryRef File =
PP.LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, LookupFromFile,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
return;
// Search include directories for this file.
- Optional<FileEntryRef> File =
+ OptionalFileEntryRef File =
LookupFile(FilenameTok.getLocation(), Filename, isAngled, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
if (!File) {
InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec,
InclusionKind Kind, StringRef FileName,
bool InQuotes, bool ImportedModule,
- Optional<FileEntryRef> File,
+ OptionalFileEntryRef File,
SourceRange Range)
: PreprocessingDirective(InclusionDirectiveKind, Range), InQuotes(InQuotes),
Kind(Kind), ImportedModule(ImportedModule), File(File) {
}
void PreprocessingRecord::InclusionDirective(
- SourceLocation HashLoc,
- const Token &IncludeTok,
- StringRef FileName,
- bool IsAngled,
- CharSourceRange FilenameRange,
- Optional<FileEntryRef> File,
- StringRef SearchPath,
- StringRef RelativePath,
- const Module *Imported,
+ SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
+ StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
InclusionDirective::InclusionKind Kind = InclusionDirective::Include;
if (!PPOpts->PCHThroughHeader.empty()) {
// Lookup and save the FileID for the through header. If it isn't found
// in the search path, it's a fatal error.
- Optional<FileEntryRef> File = LookupFile(
+ OptionalFileEntryRef File = LookupFile(
SourceLocation(), PPOpts->PCHThroughHeader,
/*isAngled=*/false, /*FromDir=*/nullptr, /*FromFile=*/nullptr,
/*CurDir=*/nullptr, /*SearchPath=*/nullptr, /*RelativePath=*/nullptr,
Diag(Path[0].second, diag::err_module_redefinition) << ModuleName;
if (M->DefinitionLoc.isValid())
Diag(M->DefinitionLoc, diag::note_prev_module_definition);
- else if (Optional<FileEntryRef> FE = M->getASTFile())
+ else if (OptionalFileEntryRef FE = M->getASTFile())
Diag(M->DefinitionLoc, diag::note_prev_module_definition_from_ast_file)
<< FE->getName();
Mod = M;
// we will also try to fail gracefully by setting up the SLocEntry.
unsigned InputID = Record[4];
InputFile IF = getInputFile(*F, InputID);
- Optional<FileEntryRef> File = IF.getFile();
+ OptionalFileEntryRef File = IF.getFile();
bool OverriddenBuffer = IF.isOverridden();
// Note that we only check if a File was returned. If it was out-of-date
StringRef Filename = FI.Filename;
uint64_t StoredContentHash = FI.ContentHash;
- OptionalFileEntryRefDegradesToFileEntryPtr File =
- expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false));
+ OptionalFileEntryRefDegradesToFileEntryPtr File = OptionalFileEntryRef(
+ expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false)));
// For an overridden file, create a virtual file with the stored
// size/timestamp.
Module *M =
PP.getHeaderSearchInfo().lookupModule(F.ModuleName, F.ImportLoc);
auto &Map = PP.getHeaderSearchInfo().getModuleMap();
- Optional<FileEntryRef> ModMap =
+ OptionalFileEntryRef ModMap =
M ? Map.getModuleMapFileForUniquing(M) : std::nullopt;
// Don't emit module relocation error if we have -fno-validate-pch
if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation &
case PPD_INCLUSION_DIRECTIVE: {
const char *FullFileNameStart = Blob.data() + Record[0];
StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]);
- Optional<FileEntryRef> File;
+ OptionalFileEntryRef File;
if (!FullFileName.empty())
File = PP.getFileManager().getOptionalFileRef(FullFileName);
bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize,
time_t ExpectedModTime,
- Optional<FileEntryRef> &File) {
+ OptionalFileEntryRef &File) {
File = std::nullopt;
if (FileName == "-")
return false;
// Open the file immediately to ensure there is no race between stat'ing and
// opening the file.
- Optional<FileEntryRef> FileOrErr =
+ OptionalFileEntryRef FileOrErr =
expectedToOptional(FileMgr.getFileRef(FileName, /*OpenFile=*/true,
/*CacheFailure=*/false));
if (!FileOrErr)
if (llvm::any_of(CI.getFrontendOpts().Inputs, needsModules)) {
Preprocessor &PP = ScanInstance.getPreprocessor();
if (Module *CurrentModule = PP.getCurrentModuleImplementation())
- if (Optional<FileEntryRef> CurrentModuleMap =
+ if (OptionalFileEntryRef CurrentModuleMap =
PP.getHeaderSearchInfo()
.getModuleMap()
.getModuleMapFileForUniquing(CurrentModule))
void ModuleDepCollectorPP::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
if (!File && !Imported) {
ModuleMap &ModMapInfo =
MDC.ScanInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap();
- Optional<FileEntryRef> ModuleMap = ModMapInfo.getModuleMapFileForUniquing(M);
+ OptionalFileEntryRef ModuleMap = ModMapInfo.getModuleMapFileForUniquing(M);
if (ModuleMap) {
SmallString<128> Path = ModuleMap->getNameAsRequested();
return nullptr;
const InclusionDirective *ID = getCursorInclusionDirective(cursor);
- Optional<FileEntryRef> File = ID->getFile();
+ OptionalFileEntryRef File = ID->getFile();
return const_cast<FileEntry *>(File ? &File->getFileEntry() : nullptr);
}
}
void CXIndexDataConsumer::ppIncludedFile(SourceLocation hashLoc,
- StringRef filename,
- Optional<FileEntryRef> File,
- bool isImport, bool isAngled,
- bool isModuleImport) {
+ StringRef filename,
+ OptionalFileEntryRef File,
+ bool isImport, bool isAngled,
+ bool isModuleImport) {
if (!CB.ppIncludedFile)
return;
void enteredMainFile(const FileEntry *File);
void ppIncludedFile(SourceLocation hashLoc, StringRef filename,
- Optional<FileEntryRef> File, bool isImport, bool isAngled,
+ OptionalFileEntryRef File, bool isImport, bool isAngled,
bool isModuleImport);
void importedModule(const ImportDecl *ImportD);
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
bool isImport = (IncludeTok.is(tok::identifier) &&
ASSERT_THAT(Results.keys(), UnorderedElementsAre("p", "q"));
const TestLattice &LP = getLatticeAtAnnotation(Results, "p");
- EXPECT_THAT(LP.Branch, Optional(true));
+ EXPECT_THAT(LP.Branch, std::make_optional(true));
const TestLattice &LQ = getLatticeAtAnnotation(Results, "q");
- EXPECT_THAT(LQ.Branch, Optional(false));
+ EXPECT_THAT(LQ.Branch, std::make_optional(false));
},
LangStandard::lang_cxx17);
}
// Calling a second time should not affect the UID or size.
unsigned VirtualUID = FE.getUID();
- llvm::Optional<FileEntryRef> SearchRef;
+ OptionalFileEntryRef SearchRef;
ASSERT_THAT_ERROR(Manager.getFileRef("/tmp/test").moveInto(SearchRef),
Succeeded());
EXPECT_EQ(&FE, &SearchRef->getFileEntry());
EXPECT_EQ(FE.getSize(), 10);
// Bypass the file.
- llvm::Optional<FileEntryRef> BypassRef =
- Manager.getBypassFile(File->getLastRef());
+ OptionalFileEntryRef BypassRef = Manager.getBypassFile(File->getLastRef());
ASSERT_TRUE(BypassRef);
EXPECT_EQ("/tmp/test", BypassRef->getName());
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
this->HashLoc = HashLoc;
SmallString<16> FileName;
bool IsAngled;
CharSourceRange FilenameRange;
- Optional<FileEntryRef> File;
+ OptionalFileEntryRef File;
SmallString<16> SearchPath;
SmallString<16> RelativePath;
const Module* Imported;
"#include \"head3.h\"\n#include \"head3.h\"\n"));
FileMgr.setVirtualFileSystem(VFS);
- Optional<FileEntryRef> FE;
+ OptionalFileEntryRef FE;
ASSERT_THAT_ERROR(FileMgr.getFileRef("main.c").moveInto(FE),
llvm::Succeeded());
SourceMgr.setMainFileID(