-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SwiftSyntax] Simplify AbsolutePosition offset calculation and support columns #16131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nkcsgexi
merged 7 commits into
swiftlang:master
from
harlanhaskins:absolute-position-positions-absolutely
Apr 24, 2018
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6189e6f
Simplify AbsolutePosition offset calculation and support columns
6bc0873
Clarify comment
76d8331
Un-rename property
5d7549c
Monomorphize AbsolutePosition.copy()
572a144
Rename byteOffset to utf8Offset and remove utf16
6b29e2d
Re-add AbsolutePosition.swift
0f5ac8d
Actually add offsets in add(columns:) and add(lines:size:)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//===--------------- AbsolutePosition.swift - Source Positions ------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// An absolute position in a source file as text - the absolute utf8Offset from | ||
/// the start, line, and column. | ||
public final class AbsolutePosition { | ||
public fileprivate(set) var utf8Offset: Int | ||
public fileprivate(set) var line: Int | ||
public fileprivate(set) var column: Int | ||
|
||
public init(line: Int = 1, column: Int = 1, utf8Offset: Int = 0) { | ||
self.line = line | ||
self.column = column | ||
self.utf8Offset = utf8Offset | ||
} | ||
|
||
internal func add(columns: Int) { | ||
self.column += columns | ||
self.utf8Offset += columns | ||
} | ||
|
||
internal func add(lines: Int, size: Int) { | ||
self.line += lines * size | ||
self.column = 1 | ||
self.utf8Offset += lines * size | ||
} | ||
|
||
/// Use some text as a reference for adding to the absolute position, | ||
/// taking note of newlines, etc. | ||
internal func add(text: String) { | ||
for char in text { | ||
switch char { | ||
case "\n", "\r\n": | ||
line += 1 | ||
column = 1 | ||
default: | ||
column += 1 | ||
} | ||
|
||
// FIXME: This is currently very wasteful, but should be fast once the | ||
// small-string optimization lands. | ||
utf8Offset += String(char).utf8.count | ||
} | ||
} | ||
|
||
internal func copy() -> AbsolutePosition { | ||
return AbsolutePosition(line: line, column: column, | ||
utf8Offset: utf8Offset) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprisingly, this code was never called.