use new llvm::Optional API

`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
This commit is contained in:
Erik Eckstein
2022-11-15 15:08:30 +01:00
parent 567b68aa6f
commit ab1b343dad
328 changed files with 1537 additions and 1536 deletions

View File

@@ -156,7 +156,7 @@ void EditorDiagConsumer::handleDiagnostic(SourceManager &SM,
}
}
if (BufferIDOpt.hasValue()) {
if (BufferIDOpt.has_value()) {
unsigned BufferID = *BufferIDOpt;
SKInfo.Offset = SM.getLocOffsetInBuffer(Info.Loc, BufferID);
@@ -1038,11 +1038,11 @@ public:
return;
}
if (!AstUnit->getPrimarySourceFile().getBufferID().hasValue()) {
if (!AstUnit->getPrimarySourceFile().getBufferID().has_value()) {
LOG_WARN_FUNC("Primary SourceFile is expected to have a BufferID");
return;
}
unsigned BufferID = AstUnit->getPrimarySourceFile().getBufferID().getValue();
unsigned BufferID = AstUnit->getPrimarySourceFile().getBufferID().value();
SemanticAnnotator Annotator(CompIns.getSourceMgr(), BufferID);
Annotator.walk(AstUnit->getPrimarySourceFile());
@@ -1179,7 +1179,7 @@ static Optional<AccessLevel> inferAccessSyntactically(const ValueDecl *D) {
D->getKind() == DeclKind::EnumElement) {
if (auto container = dyn_cast<NominalTypeDecl>(D->getDeclContext())) {
if (auto containerAccess = inferAccessSyntactically(container))
return std::max(containerAccess.getValue(), AccessLevel::Internal);
return std::max(containerAccess.value(), AccessLevel::Internal);
return None;
}
return AccessLevel::Private;
@@ -1204,7 +1204,7 @@ static Optional<AccessLevel> inferAccessSyntactically(const ValueDecl *D) {
AccessLevel access = AccessLevel::Internal;
if (isa<ProtocolDecl>(generic)) {
if (auto protoAccess = inferAccessSyntactically(generic))
access = std::max(AccessLevel::FilePrivate, protoAccess.getValue());
access = std::max(AccessLevel::FilePrivate, protoAccess.value());
}
return access;
}
@@ -1297,14 +1297,14 @@ public:
Node.Kind != SyntaxStructureKind::GenericTypeParam) {
if (auto *VD = dyn_cast_or_null<ValueDecl>(Node.Dcl)) {
if (auto Access = inferAccessSyntactically(VD))
AccessLevel = getAccessLevelUID(Access.getValue());
AccessLevel = getAccessLevelUID(Access.value());
} else if (auto *ED = dyn_cast_or_null<ExtensionDecl>(Node.Dcl)) {
if (auto DefaultAccess = inferDefaultAccessSyntactically(ED))
AccessLevel = getAccessLevelUID(DefaultAccess.getValue());
AccessLevel = getAccessLevelUID(DefaultAccess.value());
}
if (auto *ASD = dyn_cast_or_null<AbstractStorageDecl>(Node.Dcl)) {
if (auto SetAccess = inferSetterAccessSyntactically(ASD))
SetterAccessLevel = getAccessLevelUID(SetAccess.getValue());
SetterAccessLevel = getAccessLevelUID(SetAccess.value());
}
}
@@ -1353,7 +1353,7 @@ public:
BufferID);
}
auto AttrTuple = std::make_tuple(AttrUID.getValue(), AttrOffset,
auto AttrTuple = std::make_tuple(AttrUID.value(), AttrOffset,
AttrEnd - AttrOffset);
Attrs.push_back(AttrTuple);
}
@@ -1824,7 +1824,7 @@ public:
}
// If there was no appropriate parent call expression, it's non-trailing.
if (!targetPlaceholderIndex.hasValue()) {
if (!targetPlaceholderIndex.has_value()) {
OneClosureCallback(Args, /*useTrailingClosure=*/false,
/*isWrappedWithBraces=*/false, TargetClosureInfo);
return true;
@@ -1837,7 +1837,7 @@ public:
while (firstTrailingIndex != 0) {
unsigned i = firstTrailingIndex - 1;
if (params[i].isNonPlaceholderClosure ||
!params[i].placeholderClosure.hasValue())
!params[i].placeholderClosure.has_value())
break;
firstTrailingIndex = i;
}
@@ -2079,9 +2079,9 @@ void SwiftEditorDocument::readSemanticInfo(ImmutableTextSnapshotRef Snapshot,
// If there's no value returned for diagnostics it means they are out-of-date
// (based on a different snapshot).
if (SemaDiags.hasValue()) {
if (SemaDiags.has_value()) {
Consumer.setDiagnosticStage(SemaDiagStage);
for (auto &Diag : SemaDiags.getValue())
for (auto &Diag : SemaDiags.value())
Consumer.handleDiagnostic(Diag, SemaDiagStage);
} else {
Consumer.setDiagnosticStage(ParseDiagStage);