Skip to content

Cherry-pick some post-4.2 changes into swift-4.2-branch #6

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
merged 25 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d259fcc
Simplify AbsolutePosition offset calculation and support columns
Apr 10, 2018
5018466
Clarify comment
Apr 24, 2018
8044478
Un-rename property
Apr 24, 2018
b664867
Monomorphize AbsolutePosition.copy()
Apr 24, 2018
23502d3
Rename byteOffset to utf8Offset and remove utf16
Apr 24, 2018
b970c42
Re-add AbsolutePosition.swift
Apr 24, 2018
cc54246
Actually add offsets in add(columns:) and add(lines:size:)
Apr 24, 2018
60e37d0
Add accessors for source locations and test diagnostic emission (#16141)
harlanhaskins Apr 26, 2018
3dc6e42
Manually cherry-pick tests from apple/swift:
allevato Aug 31, 2018
a2ed7fb
Add descriptions for SwiftSyntax errors (#16339)
harlanhaskins May 3, 2018
54ea839
SwiftSyntax: Allow absolute position access for dangling nodes.
nkcsgexi May 3, 2018
08fb8a0
Add incremental syntax tree deserialization to SwiftSyntax
ahoppen May 24, 2018
7deb6b4
Make RawSyntax a struct
ahoppen May 24, 2018
f104c5f
Add type annotations to speed up compile time
ahoppen Jun 26, 2018
156cc9f
Don't throw just because compilation fails
ahoppen Jul 26, 2018
9bf9210
Record the nodes that have been reused during an incremental transfer
ahoppen May 30, 2018
6294ff3
Refactor AbsolutePosition
ahoppen Jun 28, 2018
84c6d0d
Make AbsolutePosition a value type
ahoppen Aug 14, 2018
b7deaa6
Remove validate methods
ahoppen Aug 23, 2018
9cef71e
Make SourceLength a struct
ahoppen Aug 29, 2018
2703c00
Make RawSyntaxData a direct enum
ahoppen Aug 29, 2018
f511ccc
Don't set the process terminationHandler in SwiftcInvocation
ahoppen Aug 29, 2018
e58d288
Update tests after cherrypicks.
allevato Sep 7, 2018
5d9650b
Allow *ListSyntax nodes to be visited.
allevato Sep 7, 2018
bd3484b
Apply review fixes
allevato Sep 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename byteOffset to utf8Offset and remove utf16
  • Loading branch information
Harlan Haskins authored and allevato committed Aug 31, 2018
commit 23502d3adecc2ef6392310569f06608b78b08691
2 changes: 1 addition & 1 deletion Sources/SwiftSyntax/Diagnostic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public struct SourceLocation: Codable {

public init(file: String, position: AbsolutePosition) {
self.init(line: position.line, column: position.column,
offset: position.byteOffset, file: file)
offset: position.utf8Offset, file: file)
}

public init(line: Int, column: Int, offset: Int, file: String) {
Expand Down
62 changes: 1 addition & 61 deletions Sources/SwiftSyntax/SyntaxData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ final class SyntaxData: Equatable {
}

var byteSize: Int {
return getNextSiblingPos().byteOffset - self.position.byteOffset
return getNextSiblingPos().utf8Offset - self.position.utf8Offset
}

/// Creates a SyntaxData with the provided raw syntax, pointing to the
Expand Down Expand Up @@ -258,63 +258,3 @@ final class SyntaxData: Equatable {
return lhs === rhs
}
}

/// An absolute position in a source file as text - the absolute byteOffset from
/// the start, line, and column.
public final class AbsolutePosition {
public fileprivate(set) var byteOffset: Int
public fileprivate(set) var line: Int
public fileprivate(set) var column: Int
public let encoding: Encoding

public enum Encoding {
case utf8
case utf16
}

public init(line: Int = 1, column: Int = 1, byteOffset: Int = 0,
encoding: Encoding = .utf8) {
self.line = line
self.column = column
self.byteOffset = byteOffset
self.encoding = encoding
}

internal func add(columns: Int) {
self.column += columns
}

internal func add(lines: Int, size: Int) {
self.line += lines * size
self.column = 1
}

/// 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.
switch encoding {
case .utf8:
byteOffset += String(char).utf8.count
case .utf16:
// FIXME: Is this correct?
byteOffset += String(char).utf16.count * 2
}
}
}

internal func copy() -> AbsolutePosition {
return AbsolutePosition(line: line, column: column,
byteOffset: byteOffset)
}
}
4 changes: 2 additions & 2 deletions Sources/SwiftSyntax/Trivia.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ extension Trivia: Collection {
for piece in pieces {
piece.accumulateAbsolutePosition(pos)
}
return pos.byteOffset
return pos.utf8Offset
}
}

Expand Down Expand Up @@ -214,6 +214,6 @@ extension TriviaPiece {
pos.add(text: text)
% end
% end
}
}
}
}