Commit Graph

12 Commits

Author SHA1 Message Date
Alex Hoppen
56bf9a3469 [SwiftSyntax] Refactor AbsolutePosition
AbsolutePosition being a mutable reference type easily leads to bugs
where an AbsolutePosition is modified. Making it immutable eliminates
this issue. Furthermore, the introduction of SourceLength should allow
easier manipulation of AbsolutePositions on the client side.

We still cannot make AbsolutePosition a value type since it is used
inside AtomicCache, but the immutability gives the same safety.
2018-08-01 11:55:35 -07:00
Xi Ge
cbf840fad4 SwiftSyntax: Allow absolute position access for dangling nodes.
Since absolute position is defined by accumulating proceeding nodes,
we should allow its access for nodes without SourceFileSyntax as root.
2018-05-03 12:13:36 -07:00
Harlan Haskins
572a144d2d Rename byteOffset to utf8Offset and remove utf16 2018-04-24 16:14:37 -04:00
Harlan Haskins
5d7549c1e0 Monomorphize AbsolutePosition.copy() 2018-04-24 14:11:02 -04:00
Harlan Haskins
76d8331a99 Un-rename property 2018-04-24 11:50:31 -04:00
Harlan Haskins
6bc087374c Clarify comment 2018-04-24 11:49:24 -04:00
Harlan Haskins
6189e6f1e9 Simplify AbsolutePosition offset calculation and support columns 2018-04-24 11:42:24 -04:00
Xi Ge
20bc656261 SwiftSyntax: make absolute position calculation independent of specific encoding. NFC (#15352) 2018-03-19 16:33:05 -07:00
Xi Ge
4c1be6aabd SwiftSyntax: avoid creating c-string when accumulating text. NFC 2018-03-15 18:16:22 -07:00
Xi Ge
ee36dbeda3 [WIP] SwiftSyntax: Implement APIs for Syntax nodes to calculate absolute positions. (#15097)
Syntax nodes are designed as reusable blocks to construct Swift source
code. For this reason, we don't track absolute position in each node;
instead, the absolute position should be calculated on the fly when
needed. We recently found absolute positions are useful to bridge with
sourcekitd, which typically speaks in the language of line, column and
offset. Therefore, this patch tries to add a computed
property on SyntaxNode to get its absolute position.

To compute the absolute position of a SyntaxNode from scratch requires tree traversal.
However, getting the absolute position from these added APIs doesn't necessarily
mean we'll traverse since SyntaxData will actively cache the computed position.
Also, since we recursively compute the absolute position, all the position caches
for a SyntaxNode's previous siblings and ancestors will be populated as well during
the calculation of this SyntaxNode.
2018-03-12 15:42:46 -07:00
Rintaro Ishizaki
fced748790 [Syntax] Represent missing optioanl nodes as nullptr (#14300)
Allocating RawSyntax/SyntaxData for missing optional node is a waste of
resource.
2018-01-31 19:24:00 +09:00
Harlan
ade67ca899 [Syntax] Swift libSyntax API (#11320)
* Create Swift libSyntax API

This patch is an initial implementation of the Swift libSyntax API. It
aims to provide all features of the C++ API but exposed to Swift.

It currently resides in SwiftExperimental and will likely exist in a
molten state for a while.

* Only build SwiftSyntax on macOS
2017-08-14 16:47:48 -07:00