[clang] 1ce8e35 - [Frontend] Use std::optional in CompilerInvocation.cpp (NFC)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 9 23:19:28 PST 2022
Author: Kazu Hirata
Date: 2022-12-09T23:19:23-08:00
New Revision: 1ce8e3543bba774e5200c73574420f1afd9d2fcd
URL: https://github.com/llvm/llvm-project/commit/1ce8e3543bba774e5200c73574420f1afd9d2fcd
DIFF: https://github.com/llvm/llvm-project/commit/1ce8e3543bba774e5200c73574420f1afd9d2fcd.diff
LOG: [Frontend] Use std::optional in CompilerInvocation.cpp (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
Added:
Modified:
clang/lib/Frontend/CompilerInvocation.cpp
Removed:
################################################################################
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 06a8815dd959..ef3fc6c2afb7 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -98,6 +98,7 @@
#include <fstream>
#include <limits>
#include <memory>
+#include <optional>
#include <string>
#include <tuple>
#include <type_traits>
@@ -170,18 +171,19 @@ CompilerInvocationRefBase::~CompilerInvocationRefBase() = default;
#include "clang/Driver/Options.inc"
#undef SIMPLE_ENUM_VALUE_TABLE
-static llvm::Optional<bool> normalizeSimpleFlag(OptSpecifier Opt,
- unsigned TableIndex,
- const ArgList &Args,
- DiagnosticsEngine &Diags) {
+static std::optional<bool> normalizeSimpleFlag(OptSpecifier Opt,
+ unsigned TableIndex,
+ const ArgList &Args,
+ DiagnosticsEngine &Diags) {
if (Args.hasArg(Opt))
return true;
return std::nullopt;
}
-static Optional<bool> normalizeSimpleNegativeFlag(OptSpecifier Opt, unsigned,
- const ArgList &Args,
- DiagnosticsEngine &) {
+static std::optional<bool> normalizeSimpleNegativeFlag(OptSpecifier Opt,
+ unsigned,
+ const ArgList &Args,
+ DiagnosticsEngine &) {
if (Args.hasArg(Opt))
return false;
return std::nullopt;
@@ -206,7 +208,7 @@ template <typename T,
std::enable_if_t<!is_uint64_t_convertible<T>(), bool> = false>
static auto makeFlagToValueNormalizer(T Value) {
return [Value](OptSpecifier Opt, unsigned, const ArgList &Args,
- DiagnosticsEngine &) -> Optional<T> {
+ DiagnosticsEngine &) -> std::optional<T> {
if (Args.hasArg(Opt))
return Value;
return std::nullopt;
@@ -221,9 +223,9 @@ static auto makeFlagToValueNormalizer(T Value) {
static auto makeBooleanOptionNormalizer(bool Value, bool OtherValue,
OptSpecifier OtherOpt) {
- return [Value, OtherValue, OtherOpt](OptSpecifier Opt, unsigned,
- const ArgList &Args,
- DiagnosticsEngine &) -> Optional<bool> {
+ return [Value, OtherValue,
+ OtherOpt](OptSpecifier Opt, unsigned, const ArgList &Args,
+ DiagnosticsEngine &) -> std::optional<bool> {
if (const Arg *A = Args.getLastArg(Opt, OtherOpt)) {
return A->getOption().matches(Opt) ? Value : OtherValue;
}
@@ -270,7 +272,7 @@ denormalizeString(SmallVectorImpl<const char *> &Args, const char *Spelling,
denormalizeStringImpl(Args, Spelling, SA, OptClass, TableIndex, Twine(Value));
}
-static Optional<SimpleEnumValue>
+static std::optional<SimpleEnumValue>
findValueTableByName(const SimpleEnumValueTable &Table, StringRef Name) {
for (int I = 0, E = Table.Size; I != E; ++I)
if (Name == Table.Table[I].Name)
@@ -279,7 +281,7 @@ findValueTableByName(const SimpleEnumValueTable &Table, StringRef Name) {
return std::nullopt;
}
-static Optional<SimpleEnumValue>
+static std::optional<SimpleEnumValue>
findValueTableByValue(const SimpleEnumValueTable &Table, unsigned Value) {
for (int I = 0, E = Table.Size; I != E; ++I)
if (Value == Table.Table[I].Value)
@@ -288,10 +290,10 @@ findValueTableByValue(const SimpleEnumValueTable &Table, unsigned Value) {
return std::nullopt;
}
-static llvm::Optional<unsigned> normalizeSimpleEnum(OptSpecifier Opt,
- unsigned TableIndex,
- const ArgList &Args,
- DiagnosticsEngine &Diags) {
+static std::optional<unsigned> normalizeSimpleEnum(OptSpecifier Opt,
+ unsigned TableIndex,
+ const ArgList &Args,
+ DiagnosticsEngine &Diags) {
assert(TableIndex < SimpleEnumValueTablesSize);
const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
@@ -334,9 +336,10 @@ static void denormalizeSimpleEnum(SmallVectorImpl<const char *> &Args,
static_cast<unsigned>(Value));
}
-static Optional<std::string> normalizeString(OptSpecifier Opt, int TableIndex,
- const ArgList &Args,
- DiagnosticsEngine &Diags) {
+static std::optional<std::string> normalizeString(OptSpecifier Opt,
+ int TableIndex,
+ const ArgList &Args,
+ DiagnosticsEngine &Diags) {
auto *Arg = Args.getLastArg(Opt);
if (!Arg)
return std::nullopt;
@@ -344,9 +347,9 @@ static Optional<std::string> normalizeString(OptSpecifier Opt, int TableIndex,
}
template <typename IntTy>
-static Optional<IntTy> normalizeStringIntegral(OptSpecifier Opt, int,
- const ArgList &Args,
- DiagnosticsEngine &Diags) {
+static std::optional<IntTy> normalizeStringIntegral(OptSpecifier Opt, int,
+ const ArgList &Args,
+ DiagnosticsEngine &Diags) {
auto *Arg = Args.getLastArg(Opt);
if (!Arg)
return std::nullopt;
@@ -359,7 +362,7 @@ static Optional<IntTy> normalizeStringIntegral(OptSpecifier Opt, int,
return Res;
}
-static Optional<std::vector<std::string>>
+static std::optional<std::vector<std::string>>
normalizeStringVector(OptSpecifier Opt, int, const ArgList &Args,
DiagnosticsEngine &) {
return Args.getAllArgValues(Opt);
@@ -397,9 +400,10 @@ static void denormalizeStringVector(SmallVectorImpl<const char *> &Args,
}
}
-static Optional<std::string> normalizeTriple(OptSpecifier Opt, int TableIndex,
- const ArgList &Args,
- DiagnosticsEngine &Diags) {
+static std::optional<std::string> normalizeTriple(OptSpecifier Opt,
+ int TableIndex,
+ const ArgList &Args,
+ DiagnosticsEngine &Diags) {
auto *Arg = Args.getLastArg(Opt);
if (!Arg)
return std::nullopt;
@@ -1065,7 +1069,7 @@ static void initOption(AnalyzerOptions::ConfigTable &Config,
DiagnosticsEngine *Diags,
bool &OptionField, StringRef Name, bool DefaultVal) {
auto PossiblyInvalidVal =
- llvm::StringSwitch<Optional<bool>>(
+ llvm::StringSwitch<std::optional<bool>>(
getStringOption(Config, Name, (DefaultVal ? "true" : "false")))
.Case("true", true)
.Case("false", false)
@@ -1362,7 +1366,7 @@ void CompilerInvocation::GenerateCodeGenArgs(
else if (!Opts.DirectAccessExternalData && LangOpts->PICLevel == 0)
GenerateArg(Args, OPT_fno_direct_access_external_data, SA);
- Optional<StringRef> DebugInfoVal;
+ std::optional<StringRef> DebugInfoVal;
switch (Opts.DebugInfo) {
case codegenoptions::DebugLineTablesOnly:
DebugInfoVal = "line-tables-only";
@@ -2368,7 +2372,7 @@ clang::CreateAndPopulateDiagOpts(ArrayRef<const char *> Argv) {
bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
DiagnosticsEngine *Diags,
bool DefaultDiagColor) {
- Optional<DiagnosticsEngine> IgnoringDiags;
+ std::optional<DiagnosticsEngine> IgnoringDiags;
if (!Diags) {
IgnoringDiags.emplace(new DiagnosticIDs(), new DiagnosticOptions(),
new IgnoringDiagConsumer());
@@ -2996,8 +3000,8 @@ static void GenerateHeaderSearchArgs(HeaderSearchOptions &Opts,
auto Matches = [](const HeaderSearchOptions::Entry &Entry,
llvm::ArrayRef<frontend::IncludeDirGroup> Groups,
- llvm::Optional<bool> IsFramework,
- llvm::Optional<bool> IgnoreSysRoot) {
+ std::optional<bool> IsFramework,
+ std::optional<bool> IgnoreSysRoot) {
return llvm::is_contained(Groups, Entry.Group) &&
(!IsFramework || (Entry.IsFramework == *IsFramework)) &&
(!IgnoreSysRoot || (Entry.IgnoreSysRoot == *IgnoreSysRoot));
More information about the cfe-commits
mailing list