mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-12 03:10:03 +00:00
[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
This commit is contained in:
parent
8d83867dc9
commit
1ce8e3543b
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user