Commit Graph

14 Commits

Author SHA1 Message Date
Xi Ge
123ccc7602 SwiftSyntax: add an API to check whether a syntax node has underlying source. (#15389) 2018-03-20 18:16:54 -07:00
Xi Ge
1c9f1c48ed SwiftSyntax: allow any Syntax nodes to access their leading/trailing trivia. (#15278)
Although libSyntax is designed in a way that trivia is attached to
tokens, we shouldn't restrict clients to access trivia only from a token.
An example can be doc-comment, which conceptually attaches to a declaration rather
than the start token of a declaration, like at-attributes.
2018-03-15 15:31:08 -07:00
Xi Ge
af868778b6 SwiftSyntax: add an API to teach Trivia to calculate byte size. (#15251)
This missing piece will allow clients to customize the size of
SyntaxNode better.
2018-03-14 17:14:52 -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
Denis Morozov
6608176e13 Use RawSyntax presence state properties in SwiftSyntax 2018-03-12 15:35:29 -07:00
Denis Morozov
568ae2deda Improve comments in Syntax.swift 2018-03-11 11:46:51 -07:00
Harlan
e41a42b060 [SwiftSyntax] Ensure SyntaxRewriter respects nil children when rewriting (#15052) 2018-03-08 00:37:41 -05:00
Ben Cohen
9ee856f386 [stdlib][WIP] Eliminate (Closed)CountableRange using conditional conformance (#13342)
* Make Range conditionally a Collection

* Convert ClosedRange to conditionally a collection

* De-gyb Range/ClosedRange, refactoring some methods.

* Remove use of Countable{Closed}Range from stdlib

* Remove Countable use from Foundation

* Fix test errors and warnings resulting from Range/CountableRange collapse

* fix prespecialize test for new mangling

* Update CoreAudio use of CountableRange

* Update SwiftSyntax use of CountableRange

* Restore ClosedRange.Index: Hashable conformance

* Move fixed typechecker slowness test for array-of-ranges from slow to fast, yay

* Apply Doug's patch to loosen test to just check for error
2018-02-01 20:59:28 -08: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
95fc7d335e Change vars in SwiftSyntax nodes to lets (#14173) 2018-01-26 15:19:05 -08:00
Harlan
a339c82c1e [SwiftSyntax] Make Syntax nodes structs instead of classes (#14122)
* [Experiment] Make Syntax nodes structs instead of classes

* [Experiment] Add Hashable conformance to concrete types

* Fix pep8 violation

* Remove AnySyntax, explicitly specialize SyntaxCollection nodes

* Refine the comment for SyntaxCollection nodes
2018-01-24 23:17:25 -05:00
Xi Ge
d847bf5ddd SwiftSyntax: make Syntax node Hashable. (#13679)
SwiftSyntax: make Syntax node Hashable.

This gives Syntax node a unique identifier and makes them friendly
to Set and Dictionary.
2018-01-02 14:19:26 -08:00
Tony Allevato
1187890ca4 [SwiftSyntax] Fix SyntaxChildren iteration (#12319)
* [SwiftSyntax] Fix SyntaxChildren iteration

SyntaxChildren.Iterator stops the first time it sees a nil child;
since it traverses all indexes without considering presence, this
causes it to terminate iteration early if there is a missing child
in the list.

* [SwiftSyntax] Add tests for SyntaxChildren
2017-10-15 00:38:35 -04: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