mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
libSyntax: add getAbsoluteEndPosition() method to syntax nodes.
This implementation uses sibling's absolute start position to help populate caches while getting the end position.
This commit is contained in:
@@ -66,6 +66,18 @@ RC<SyntaxData> SyntaxData::getPreviousNode() const {
|
||||
return hasParent() ? Parent->getPreviousNode() : nullptr;
|
||||
}
|
||||
|
||||
RC<SyntaxData> SyntaxData::getNextNode() const {
|
||||
if (hasParent()) {
|
||||
for (size_t I = getIndexInParent() + 1, N = Parent->getNumChildren();
|
||||
I != N; I++) {
|
||||
if (auto C = getParent()->getChild(I))
|
||||
return C;
|
||||
}
|
||||
return Parent->getNextNode();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AbsolutePosition SyntaxData::getAbsolutePositionWithLeadingTrivia() const {
|
||||
if (PositionCache.hasValue())
|
||||
return *PositionCache;
|
||||
@@ -85,3 +97,13 @@ AbsolutePosition SyntaxData::getAbsolutePosition() const {
|
||||
getRaw()->accumulateLeadingTrivia(Result);
|
||||
return Result;
|
||||
}
|
||||
|
||||
AbsolutePosition SyntaxData::getAbsoluteEndPosition() const {
|
||||
if (auto N = getNextNode()) {
|
||||
return N->getAbsolutePositionWithLeadingTrivia();
|
||||
} else {
|
||||
auto Result = getAbsolutePositionWithLeadingTrivia();
|
||||
getRaw()->accumulateAbsolutePosition(Result);
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user