Skip to content

Commit a5a3288

Browse files
authored
Merge pull request #61005 from benlangmuir/storage-is-optional
[syntax] Add has_value() and value() to OptionalStorage
2 parents 3299803 + d7489c1 commit a5a3288

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/swift/Syntax/AbsoluteRawSyntax.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,17 +395,30 @@ class OptionalStorage<AbsoluteRawSyntax> {
395395

396396
void reset() { Storage = AbsoluteRawSyntax(nullptr); }
397397

398+
bool has_value() const { return !Storage.isNull(); }
398399
bool hasValue() const { return !Storage.isNull(); }
399400

401+
AbsoluteRawSyntax &value() & {
402+
assert(hasValue());
403+
return Storage;
404+
}
400405
AbsoluteRawSyntax &getValue() & {
401406
assert(hasValue());
402407
return Storage;
403408
}
409+
AbsoluteRawSyntax const &value() const & {
410+
assert(hasValue());
411+
return Storage;
412+
}
404413
AbsoluteRawSyntax const &getValue() const & {
405414
assert(hasValue());
406415
return Storage;
407416
}
408417
#if LLVM_HAS_RVALUE_REFERENCE_THIS
418+
AbsoluteRawSyntax &&value() &&noexcept {
419+
assert(hasValue());
420+
return std::move(Storage);
421+
}
409422
AbsoluteRawSyntax &&getValue() &&noexcept {
410423
assert(hasValue());
411424
return std::move(Storage);

include/swift/Syntax/SyntaxData.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,17 +414,30 @@ class OptionalStorage<SyntaxDataRef> {
414414

415415
void reset() { Storage = SyntaxDataRef(AbsoluteRawSyntax(nullptr), nullptr); }
416416

417+
bool has_value() const { return !Storage.getAbsoluteRaw().isNull(); }
417418
bool hasValue() const { return !Storage.getAbsoluteRaw().isNull(); }
418419

420+
SyntaxDataRef &value() & {
421+
assert(hasValue());
422+
return Storage;
423+
}
419424
SyntaxDataRef &getValue() & {
420425
assert(hasValue());
421426
return Storage;
422427
}
428+
SyntaxDataRef const &value() const & {
429+
assert(hasValue());
430+
return Storage;
431+
}
423432
SyntaxDataRef const &getValue() const & {
424433
assert(hasValue());
425434
return Storage;
426435
}
427436
#if LLVM_HAS_RVALUE_REFERENCE_THIS
437+
SyntaxDataRef &&value() &&noexcept {
438+
assert(hasValue());
439+
return std::move(Storage);
440+
}
428441
SyntaxDataRef &&getValue() &&noexcept {
429442
assert(hasValue());
430443
return std::move(Storage);

0 commit comments

Comments
 (0)