Skip to content

Commit

Permalink
Support: Convert some Optional to std::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Dec 2, 2022
1 parent 1a949c8 commit 7403458
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static ELFKind getELFKind(MemoryBufferRef mb, StringRef archiveName) {
// the input objects have been compiled.
static void updateARMVFPArgs(const ARMAttributeParser &attributes,
const InputFile *f) {
Optional<unsigned> attr =
std::optional<unsigned> attr =
attributes.getAttributeValue(ARMBuildAttrs::ABI_VFP_args);
if (!attr)
// If an ABI tag isn't present then it is implicitly given the value of 0
Expand Down Expand Up @@ -145,7 +145,7 @@ static void updateARMVFPArgs(const ARMAttributeParser &attributes,
// is compiled with an architecture that supports these features then lld is
// permitted to use them.
static void updateSupportedARMFeatures(const ARMAttributeParser &attributes) {
Optional<unsigned> attr =
std::optional<unsigned> attr =
attributes.getAttributeValue(ARMBuildAttrs::CPU_arch);
if (!attr)
return;
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/Support/ELFAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include <optional>

namespace llvm {

Expand All @@ -27,7 +28,7 @@ enum AttrType : unsigned { File = 1, Section = 2, Symbol = 3 };

StringRef attrTypeAsString(unsigned attr, TagNameMap tagNameMap,
bool hasTagPrefix = true);
Optional<unsigned> attrTypeFromString(StringRef tag, TagNameMap tagNameMap);
std::optional<unsigned> attrTypeFromString(StringRef tag, TagNameMap tagNameMap);

// Magic numbers for ELF attributes.
enum AttrMagic { Format_Version = 0x41 };
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Support/LineIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#ifndef LLVM_SUPPORT_LINEITERATOR_H
#define LLVM_SUPPORT_LINEITERATOR_H

#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/MemoryBufferRef.h"
#include <iterator>
#include <optional>

namespace llvm {

Expand All @@ -31,7 +31,7 @@ class MemoryBuffer;
///
/// Note that this iterator requires the buffer to be nul terminated.
class line_iterator {
Optional<MemoryBufferRef> Buffer;
std::optional<MemoryBufferRef> Buffer;
char CommentMarker = '\0';
bool SkipBlanks = true;

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Support/ELFAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ StringRef ELFAttrs::attrTypeAsString(unsigned attr, TagNameMap tagNameMap,
return hasTagPrefix ? tagName : tagName.drop_front(4);
}

Optional<unsigned> ELFAttrs::attrTypeFromString(StringRef tag,
TagNameMap tagNameMap) {
std::optional<unsigned> ELFAttrs::attrTypeFromString(StringRef tag,
TagNameMap tagNameMap) {
bool hasTagPrefix = tag.startswith("Tag_");
auto tagNameIt =
find_if(tagNameMap, [tag, hasTagPrefix](const TagNameItem item) {
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Support/LineIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ line_iterator::line_iterator(const MemoryBuffer &Buffer, bool SkipBlanks,

line_iterator::line_iterator(const MemoryBufferRef &Buffer, bool SkipBlanks,
char CommentMarker)
: Buffer(Buffer.getBufferSize() ? Optional<MemoryBufferRef>(Buffer) : None),
: Buffer(Buffer.getBufferSize() ? std::optional<MemoryBufferRef>(Buffer)
: std::nullopt),
CommentMarker(CommentMarker), SkipBlanks(SkipBlanks),
CurrentLine(Buffer.getBufferSize() ? Buffer.getBufferStart() : nullptr,
0) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11399,7 +11399,7 @@ bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
TagLoc = Parser.getTok().getLoc();
if (Parser.getTok().is(AsmToken::Identifier)) {
StringRef Name = Parser.getTok().getIdentifier();
Optional<unsigned> Ret = ELFAttrs::attrTypeFromString(
std::optional<unsigned> Ret = ELFAttrs::attrTypeFromString(
Name, ARMBuildAttrs::getARMAttributeTags());
if (!Ret) {
Error(TagLoc, "attribute name not recognised: " + Name);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ bool CSKYAsmParser::parseDirectiveAttribute() {
TagLoc = Parser.getTok().getLoc();
if (Parser.getTok().is(AsmToken::Identifier)) {
StringRef Name = Parser.getTok().getIdentifier();
Optional<unsigned> Ret =
std::optional<unsigned> Ret =
ELFAttrs::attrTypeFromString(Name, CSKYAttrs::getCSKYAttributeTags());
if (!Ret) {
Error(TagLoc, "attribute name not recognised: " + Name);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@ bool RISCVAsmParser::parseDirectiveAttribute() {
TagLoc = Parser.getTok().getLoc();
if (Parser.getTok().is(AsmToken::Identifier)) {
StringRef Name = Parser.getTok().getIdentifier();
Optional<unsigned> Ret =
std::optional<unsigned> Ret =
ELFAttrs::attrTypeFromString(Name, RISCVAttrs::getRISCVAttributeTags());
if (!Ret) {
Error(TagLoc, "attribute name not recognised: " + Name);
Expand Down

0 comments on commit 7403458

Please sign in to comment.