|
10 | 10 | // |
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 |
|
13 | | -/// Represent the user-facing part of SourceLocation that can be calculated |
14 | | -/// on demand. |
15 | | -struct ComputedLocation: Hashable, Codable, CustomDebugStringConvertible { |
16 | | - /// The line in the file where this location resides. 1-based. |
17 | | - let line: Int |
18 | | - |
19 | | - /// The UTF-8 byte offset from the beginning of the line where this location |
20 | | - /// resides. 1-based. |
21 | | - let column: Int |
22 | | - |
23 | | - /// The file in which this location resides. |
24 | | - let file: String |
25 | | - |
26 | | - var debugDescription: String { |
27 | | - // Print file name? |
28 | | - return "\(line):\(column)" |
29 | | - } |
30 | | - |
31 | | - init(line: Int, column: Int, file: String) { |
32 | | - self.line = line |
33 | | - self.column = column |
34 | | - self.file = file |
35 | | - } |
36 | | - init(offset: Int, using converter: SourceLocationConverter) { |
37 | | - let loc = converter.location(for: AbsolutePosition(utf8Offset: offset)) |
38 | | - precondition(loc.offset == offset) |
39 | | - self.line = loc.line! |
40 | | - self.column = loc.column! |
41 | | - self.file = loc.file! |
42 | | - } |
43 | | -} |
44 | | - |
45 | 13 | /// Represents a source location in a Swift file. |
46 | 14 | public struct SourceLocation: Hashable, Codable, CustomDebugStringConvertible { |
47 | 15 |
|
48 | | - /// Line and column that can be computed on demand. |
49 | | - private var compLoc: ComputedLocation? |
50 | | - |
51 | 16 | /// The UTF-8 byte offset into the file where this location resides. |
52 | 17 | public let offset: Int |
53 | 18 |
|
54 | 19 | /// The line in the file where this location resides. 1-based. |
55 | | - public var line: Int? { |
56 | | - return compLoc?.line |
57 | | - } |
| 20 | + public var line: Int |
58 | 21 |
|
59 | 22 | /// The UTF-8 byte offset from the beginning of the line where this location |
60 | 23 | /// resides. 1-based. |
61 | | - public var column: Int? { |
62 | | - return compLoc?.column |
63 | | - } |
| 24 | + public let column: Int |
64 | 25 |
|
65 | 26 | /// The file in which this location resides. |
66 | | - public var file: String? { |
67 | | - return compLoc?.file |
68 | | - } |
| 27 | + public let file: String |
69 | 28 |
|
70 | 29 | public var debugDescription: String { |
71 | | - guard let compLoc = compLoc else { |
72 | | - return "\(offset)" |
73 | | - } |
74 | | - return compLoc.debugDescription |
| 30 | + // Print file name? |
| 31 | + return "\(line):\(column)" |
75 | 32 | } |
76 | 33 |
|
77 | 34 | public init(line: Int, column: Int, offset: Int, file: String) { |
| 35 | + self.line = line |
78 | 36 | self.offset = offset |
79 | | - self.compLoc = ComputedLocation(line: line, column: column, file: file) |
80 | | - } |
81 | | - |
82 | | - /// Initialize SourceLocation with a utf8 offset. |
83 | | - /// If a SourceLocationConverter is given, line, column and file will be populated; |
84 | | - /// otherwise they will be nil. |
85 | | - public init(offset: Int, converter: SourceLocationConverter? = nil) { |
86 | | - self.offset = offset |
87 | | - if let converter = converter { |
88 | | - self.compLoc = ComputedLocation(offset: offset, using: converter) |
89 | | - } |
| 37 | + self.column = column |
| 38 | + self.file = file |
90 | 39 | } |
91 | 40 | } |
92 | 41 |
|
|
0 commit comments