Skip to content

Commit 6a153f7

Browse files
committed
improve location tracking of SuppressedEntry
1 parent de1260e commit 6a153f7

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

include/swift/AST/Decl.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,10 +1466,17 @@ struct InheritedEntry : public TypeLoc {
14661466

14671467
/// An entry in the "suppressed conformance" list of a type.
14681468
struct SuppressedEntry : public TypeLoc {
1469-
SourceLoc WithoutLoc; // location of the "without" operator on this type.
1469+
SourceRange WithoutRange; // location of the "without" operator on this type.
14701470

1471-
SuppressedEntry(const TypeLoc &typeLoc, SourceLoc withoutLoc)
1472-
: TypeLoc(typeLoc), WithoutLoc(withoutLoc) {}
1471+
SuppressedEntry(const TypeLoc &typeLoc, SourceRange withoutRange)
1472+
: TypeLoc(typeLoc), WithoutRange(withoutRange) {}
1473+
1474+
SourceLoc getLoc() const;
1475+
SourceRange getSourceRange() const;
1476+
1477+
SourceRange getWithoutRange() const { return WithoutRange; }
1478+
1479+
bool hasLocation() const { return (bool)getLoc(); }
14731480
};
14741481

14751482
/// ExtensionDecl - This represents a type extension containing methods

lib/AST/Decl.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,19 @@ InheritedEntry::InheritedEntry(const TypeLoc &typeLoc)
14821482
isUnchecked = typeRepr->findUncheckedAttrLoc().isValid();
14831483
}
14841484

1485+
SourceLoc SuppressedEntry::getLoc() const {
1486+
return WithoutRange.Start;
1487+
}
1488+
1489+
SourceRange SuppressedEntry::getSourceRange() const {
1490+
auto range = TypeLoc::getSourceRange();
1491+
if (!range)
1492+
return WithoutRange;
1493+
1494+
range.widen(WithoutRange);
1495+
return range;
1496+
}
1497+
14851498
ExtensionDecl::ExtensionDecl(SourceLoc extensionLoc,
14861499
TypeRepr *extendedType,
14871500
ArrayRef<InheritedEntry> inherited,

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5735,14 +5735,14 @@ ParserStatus Parser::parseInheritance(
57355735
}
57365736

57375737
// parse the "without" operator
5738-
SourceLoc withoutLoc;
5738+
SourceRange withoutLoc;
57395739
if (Tok.isTilde()) {
57405740
auto loc = consumeToken();
57415741

57425742
if (!options.contains(PI_AllowSuppression))
57435743
diagnose(loc, diag::suppress_illegal_here);
57445744
else
5745-
withoutLoc = loc;
5745+
withoutLoc = SourceRange(loc, loc);
57465746
}
57475747

57485748
auto ParsedTypeResult = parseType();

0 commit comments

Comments
 (0)