[ELF] Change most llvm::Optional to std::optional
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
This commit is contained in:
@@ -330,7 +330,7 @@ void ScriptParser::addFile(StringRef s) {
|
||||
ctx.driver.addFile(s, /*withLOption=*/false);
|
||||
} else {
|
||||
// Finally, search in the list of library paths.
|
||||
if (Optional<std::string> path = findFromSearchPaths(s))
|
||||
if (std::optional<std::string> path = findFromSearchPaths(s))
|
||||
ctx.driver.addFile(saver().save(*path), /*withLOption=*/true);
|
||||
else
|
||||
setError("unable to find " + s);
|
||||
@@ -379,8 +379,8 @@ void ScriptParser::readInclude() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Optional<std::string> path = searchScript(tok)) {
|
||||
if (Optional<MemoryBufferRef> mb = readFile(*path))
|
||||
if (std::optional<std::string> path = searchScript(tok)) {
|
||||
if (std::optional<MemoryBufferRef> mb = readFile(*path))
|
||||
tokenize(*mb);
|
||||
return;
|
||||
}
|
||||
@@ -1221,33 +1221,33 @@ Expr ScriptParser::readConstant() {
|
||||
// Parses Tok as an integer. It recognizes hexadecimal (prefixed with
|
||||
// "0x" or suffixed with "H") and decimal numbers. Decimal numbers may
|
||||
// have "K" (Ki) or "M" (Mi) suffixes.
|
||||
static Optional<uint64_t> parseInt(StringRef tok) {
|
||||
static std::optional<uint64_t> parseInt(StringRef tok) {
|
||||
// Hexadecimal
|
||||
uint64_t val;
|
||||
if (tok.startswith_insensitive("0x")) {
|
||||
if (!to_integer(tok.substr(2), val, 16))
|
||||
return None;
|
||||
return std::nullopt;
|
||||
return val;
|
||||
}
|
||||
if (tok.endswith_insensitive("H")) {
|
||||
if (!to_integer(tok.drop_back(), val, 16))
|
||||
return None;
|
||||
return std::nullopt;
|
||||
return val;
|
||||
}
|
||||
|
||||
// Decimal
|
||||
if (tok.endswith_insensitive("K")) {
|
||||
if (!to_integer(tok.drop_back(), val, 10))
|
||||
return None;
|
||||
return std::nullopt;
|
||||
return val * 1024;
|
||||
}
|
||||
if (tok.endswith_insensitive("M")) {
|
||||
if (!to_integer(tok.drop_back(), val, 10))
|
||||
return None;
|
||||
return std::nullopt;
|
||||
return val * 1024 * 1024;
|
||||
}
|
||||
if (!to_integer(tok, val, 10))
|
||||
return None;
|
||||
return std::nullopt;
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -1269,11 +1269,11 @@ ByteCommand *ScriptParser::readByteCommand(StringRef tok) {
|
||||
return make<ByteCommand>(e, size, commandString);
|
||||
}
|
||||
|
||||
static llvm::Optional<uint64_t> parseFlag(StringRef tok) {
|
||||
if (llvm::Optional<uint64_t> asInt = parseInt(tok))
|
||||
static std::optional<uint64_t> parseFlag(StringRef tok) {
|
||||
if (std::optional<uint64_t> asInt = parseInt(tok))
|
||||
return asInt;
|
||||
#define CASE_ENT(enum) #enum, ELF::enum
|
||||
return StringSwitch<llvm::Optional<uint64_t>>(tok)
|
||||
return StringSwitch<std::optional<uint64_t>>(tok)
|
||||
.Case(CASE_ENT(SHF_WRITE))
|
||||
.Case(CASE_ENT(SHF_ALLOC))
|
||||
.Case(CASE_ENT(SHF_EXECINSTR))
|
||||
@@ -1308,7 +1308,7 @@ std::pair<uint64_t, uint64_t> ScriptParser::readInputSectionFlags() {
|
||||
while (!errorCount()) {
|
||||
StringRef tok = unquote(next());
|
||||
bool without = tok.consume_front("!");
|
||||
if (llvm::Optional<uint64_t> flag = parseFlag(tok)) {
|
||||
if (std::optional<uint64_t> flag = parseFlag(tok)) {
|
||||
if (without)
|
||||
withoutFlags |= *flag;
|
||||
else
|
||||
@@ -1521,7 +1521,7 @@ Expr ScriptParser::readPrimary() {
|
||||
return [=] { return script->getSymbolValue(tok, location); };
|
||||
|
||||
// Tok is a literal number.
|
||||
if (Optional<uint64_t> val = parseInt(tok))
|
||||
if (std::optional<uint64_t> val = parseInt(tok))
|
||||
return [=] { return *val; };
|
||||
|
||||
// Tok is a symbol name.
|
||||
@@ -1560,7 +1560,7 @@ SmallVector<StringRef, 0> ScriptParser::readOutputSectionPhdrs() {
|
||||
// name of a program header type or a constant (e.g. "0x3").
|
||||
unsigned ScriptParser::readPhdrType() {
|
||||
StringRef tok = next();
|
||||
if (Optional<uint64_t> val = parseInt(tok))
|
||||
if (std::optional<uint64_t> val = parseInt(tok))
|
||||
return *val;
|
||||
|
||||
unsigned ret = StringSwitch<unsigned>(tok)
|
||||
|
||||
Reference in New Issue
Block a user