mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[libSyntax] Rename getAbsolutePosition-related methods for more clarity
This commit is contained in:
@@ -200,16 +200,15 @@ public:
|
|||||||
return Data->getAbsolutePosition();
|
return Data->getAbsolutePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the absolute end position (exclusively) of this raw syntax: its offset,
|
/// Get the absolute end position (exclusively) where the trailing trivia of
|
||||||
/// line, and column.
|
/// this node ends.
|
||||||
AbsolutePosition getAbsoluteEndPosition() const {
|
AbsolutePosition getAbsoluteEndPositionAfterTrailingTrivia() const {
|
||||||
return Data->getAbsoluteEndPosition();
|
return Data->getAbsoluteEndPositionAfterTrailingTrivia();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the absolute position without skipping the leading trivia of this
|
/// Get the absolute position at which the leading trivia of this node starts.
|
||||||
/// node.
|
AbsolutePosition getAbsolutePositionBeforeLeadingTrivia() const {
|
||||||
AbsolutePosition getAbsolutePositionWithLeadingTrivia() const {
|
return Data->getAbsolutePositionBeforeLeadingTrivia();
|
||||||
return Data->getAbsolutePositionWithLeadingTrivia();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: hasSameStructureAs ?
|
// TODO: hasSameStructureAs ?
|
||||||
|
|||||||
@@ -255,11 +255,11 @@ public:
|
|||||||
|
|
||||||
/// Calculate the absolute end position of this node, use cache of the immediate
|
/// Calculate the absolute end position of this node, use cache of the immediate
|
||||||
/// next node if populated.
|
/// next node if populated.
|
||||||
AbsolutePosition getAbsoluteEndPosition() const;
|
AbsolutePosition getAbsoluteEndPositionAfterTrailingTrivia() const;
|
||||||
|
|
||||||
/// Get the absolute position without skipping the leading trivia of this
|
/// Get the absolute position without skipping the leading trivia of this
|
||||||
/// node.
|
/// node.
|
||||||
AbsolutePosition getAbsolutePositionWithLeadingTrivia() const;
|
AbsolutePosition getAbsolutePositionBeforeLeadingTrivia() const;
|
||||||
|
|
||||||
/// Returns true if the data node represents type syntax.
|
/// Returns true if the data node represents type syntax.
|
||||||
bool isType() const;
|
bool isType() const;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ using namespace swift::syntax;
|
|||||||
|
|
||||||
bool SyntaxParsingCache::nodeCanBeReused(const Syntax &Node, size_t Position,
|
bool SyntaxParsingCache::nodeCanBeReused(const Syntax &Node, size_t Position,
|
||||||
SyntaxKind Kind) const {
|
SyntaxKind Kind) const {
|
||||||
auto NodeStart = Node.getAbsolutePositionWithLeadingTrivia().getOffset();
|
auto NodeStart = Node.getAbsolutePositionBeforeLeadingTrivia().getOffset();
|
||||||
if (NodeStart != Position)
|
if (NodeStart != Position)
|
||||||
return false;
|
return false;
|
||||||
if (Node.getKind() != Kind)
|
if (Node.getKind() != Kind)
|
||||||
@@ -60,7 +60,8 @@ llvm::Optional<Syntax> SyntaxParsingCache::lookUpFrom(const Syntax &Node,
|
|||||||
if (!Child.hasValue()) {
|
if (!Child.hasValue()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto ChildStart = Child->getAbsolutePositionWithLeadingTrivia().getOffset();
|
auto ChildStart =
|
||||||
|
Child->getAbsolutePositionBeforeLeadingTrivia().getOffset();
|
||||||
auto ChildEnd = ChildStart + Child->getTextLength();
|
auto ChildEnd = ChildStart + Child->getTextLength();
|
||||||
if (ChildStart <= Position && Position < ChildEnd) {
|
if (ChildStart <= Position && Position < ChildEnd) {
|
||||||
return lookUpFrom(Child.getValue(), Position, Kind);
|
return lookUpFrom(Child.getValue(), Position, Kind);
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ bool RawSyntax::accumulateLeadingTrivia(AbsolutePosition &Pos) const {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto &Child: getLayout()) {
|
for (auto &Child: getLayout()) {
|
||||||
if (!Child)
|
if (!Child || Child->isMissing())
|
||||||
continue;
|
continue;
|
||||||
if (Child->accumulateLeadingTrivia(Pos))
|
if (Child->accumulateLeadingTrivia(Pos))
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -96,11 +96,11 @@ RC<SyntaxData> SyntaxData::getFirstToken() const {
|
|||||||
return getParent()->getChild(getIndexInParent());
|
return getParent()->getChild(getIndexInParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
AbsolutePosition SyntaxData::getAbsolutePositionWithLeadingTrivia() const {
|
AbsolutePosition SyntaxData::getAbsolutePositionBeforeLeadingTrivia() const {
|
||||||
if (PositionCache.hasValue())
|
if (PositionCache.hasValue())
|
||||||
return *PositionCache;
|
return *PositionCache;
|
||||||
if (auto P = getPreviousNode()) {
|
if (auto P = getPreviousNode()) {
|
||||||
auto Result = P->getAbsolutePositionWithLeadingTrivia();
|
auto Result = P->getAbsolutePositionBeforeLeadingTrivia();
|
||||||
P->getRaw()->accumulateAbsolutePosition(Result);
|
P->getRaw()->accumulateAbsolutePosition(Result);
|
||||||
// FIXME: avoid using const_cast.
|
// FIXME: avoid using const_cast.
|
||||||
const_cast<SyntaxData*>(this)->PositionCache = Result;
|
const_cast<SyntaxData*>(this)->PositionCache = Result;
|
||||||
@@ -111,16 +111,16 @@ AbsolutePosition SyntaxData::getAbsolutePositionWithLeadingTrivia() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AbsolutePosition SyntaxData::getAbsolutePosition() const {
|
AbsolutePosition SyntaxData::getAbsolutePosition() const {
|
||||||
auto Result = getAbsolutePositionWithLeadingTrivia();
|
auto Result = getAbsolutePositionBeforeLeadingTrivia();
|
||||||
getRaw()->accumulateLeadingTrivia(Result);
|
getRaw()->accumulateLeadingTrivia(Result);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
AbsolutePosition SyntaxData::getAbsoluteEndPosition() const {
|
AbsolutePosition SyntaxData::getAbsoluteEndPositionAfterTrailingTrivia() const {
|
||||||
if (auto N = getNextNode()) {
|
if (auto N = getNextNode()) {
|
||||||
return N->getAbsolutePositionWithLeadingTrivia();
|
return N->getAbsolutePositionBeforeLeadingTrivia();
|
||||||
} else {
|
} else {
|
||||||
auto Result = getAbsolutePositionWithLeadingTrivia();
|
auto Result = getAbsolutePositionBeforeLeadingTrivia();
|
||||||
getRaw()->accumulateAbsolutePosition(Result);
|
getRaw()->accumulateAbsolutePosition(Result);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -655,7 +655,7 @@ private:
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
auto LeadingTriviaOffset =
|
auto LeadingTriviaOffset =
|
||||||
Token.getAbsolutePositionWithLeadingTrivia().getOffset();
|
Token.getAbsolutePositionBeforeLeadingTrivia().getOffset();
|
||||||
visitTrivia(Token.getLeadingTrivia(), LeadingTriviaOffset);
|
visitTrivia(Token.getLeadingTrivia(), LeadingTriviaOffset);
|
||||||
|
|
||||||
SyntaxClassification Classification = TokenClassifications[Token.getId()];
|
SyntaxClassification Classification = TokenClassifications[Token.getId()];
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ bool verifyReusedRegions(ByteBasedSourceRangeSet ExpectedReparseRegions,
|
|||||||
SourceFile *SF) {
|
SourceFile *SF) {
|
||||||
// We always expect the EOF token to be reparsed. Don't complain about it.
|
// We always expect the EOF token to be reparsed. Don't complain about it.
|
||||||
auto Eof = SF->getSyntaxRoot().getChild(SourceFileSyntax::Cursor::EOFToken);
|
auto Eof = SF->getSyntaxRoot().getChild(SourceFileSyntax::Cursor::EOFToken);
|
||||||
auto EofNodeStart = Eof->getAbsolutePositionWithLeadingTrivia().getOffset();
|
auto EofNodeStart = Eof->getAbsolutePositionBeforeLeadingTrivia().getOffset();
|
||||||
if (ExpectedReparseRegions.Ranges.back().End >= EofNodeStart) {
|
if (ExpectedReparseRegions.Ranges.back().End >= EofNodeStart) {
|
||||||
// If the last expected reparse region already covers part of the eof
|
// If the last expected reparse region already covers part of the eof
|
||||||
// leading trivia, extended it
|
// leading trivia, extended it
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ TEST(PositionTests, AbsolutePosition1) {
|
|||||||
ASSERT_EQ(7u, Pos.getLine());
|
ASSERT_EQ(7u, Pos.getLine());
|
||||||
ASSERT_EQ(1u, Pos.getColumn());
|
ASSERT_EQ(1u, Pos.getColumn());
|
||||||
ASSERT_EQ(8u, Pos.getOffset());
|
ASSERT_EQ(8u, Pos.getOffset());
|
||||||
AbsolutePosition EndPos = Token.getAbsoluteEndPosition();
|
AbsolutePosition EndPos = Token.getAbsoluteEndPositionAfterTrailingTrivia();
|
||||||
ASSERT_EQ(7u, EndPos.getLine());
|
ASSERT_EQ(7u, EndPos.getLine());
|
||||||
ASSERT_EQ(4u, EndPos.getColumn());
|
ASSERT_EQ(4u, EndPos.getColumn());
|
||||||
ASSERT_EQ(11u, EndPos.getOffset());
|
ASSERT_EQ(11u, EndPos.getOffset());
|
||||||
@@ -30,7 +30,7 @@ TEST(PositionTests, AbsolutePosition2) {
|
|||||||
ASSERT_EQ(4u, Pos.getLine());
|
ASSERT_EQ(4u, Pos.getLine());
|
||||||
ASSERT_EQ(4u, Pos.getColumn());
|
ASSERT_EQ(4u, Pos.getColumn());
|
||||||
ASSERT_EQ(10u, Pos.getOffset());
|
ASSERT_EQ(10u, Pos.getOffset());
|
||||||
AbsolutePosition EndPos = Token.getAbsoluteEndPosition();
|
AbsolutePosition EndPos = Token.getAbsoluteEndPositionAfterTrailingTrivia();
|
||||||
ASSERT_EQ(4u, EndPos.getLine());
|
ASSERT_EQ(4u, EndPos.getLine());
|
||||||
ASSERT_EQ(7u, EndPos.getColumn());
|
ASSERT_EQ(7u, EndPos.getColumn());
|
||||||
ASSERT_EQ(13u, EndPos.getOffset());
|
ASSERT_EQ(13u, EndPos.getOffset());
|
||||||
|
|||||||
Reference in New Issue
Block a user