Commit Graph

31 Commits

Author SHA1 Message Date
Alex Hoppen
c8226d1507 [libSyntax] Make a typealias to unsigned to represent SyntaxNodeIds 2018-07-19 13:57:08 -07:00
Alex Hoppen
705f5b79a2 [libSyntax] Rename getAbsolutePosition-related methods for more clarity 2018-07-19 09:15:53 -07:00
Alex Hoppen
9d59cd286b [incrParse] Add a stable id to the syntax nodes
The id is meant to be stable across incremental parses
2018-07-13 16:56:03 -07:00
Alex Hoppen
ec4a527c44 [incrParse] Reparse nodes if the next node's trailing trivia has changed 2018-05-22 08:52:36 -07:00
Alex Hoppen
92f8f34d22 [incrParse] Store reused regions and output them after parsing 2018-05-22 08:52:34 -07:00
Alex Hoppen
de9737c946 [incrParse] Support incremental parsing for edited files 2018-05-22 08:52:33 -07:00
Xi Ge
5a8053e7ef libSyntax: add getAbsoluteEndPosition() method to syntax nodes.
This implementation uses sibling's absolute start position to help
populate caches while getting the end position.
2018-05-01 12:06:41 -07:00
Xi Ge
7b4218c2f7 libSyntax: cache absolute positions on SyntaxData.
Aligning with what we did for SwiftSyntax, this patch uses caches for
absolute position calculation on the C++ side.
2018-04-30 15:09:00 -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
Rintaro Ishizaki
941cfa80bb [Syntax] Don't construct complete Syntax nodes in parsing
Instead, directly use RawSyntax.
2018-01-31 17:13:00 +09:00
Rintaro Ishizaki
98fc073e2e [Syntax] Don't rebuild Syntax with RawSyntax in SyntaxVisitor (#14057)
We don't guarantee RawSyntax nodes as unique object in the tree, while
we do that for SyntaxData. We shouldn't recreate SyntaxData once it was
built.
2018-01-22 14:24:20 -08:00
Xi Ge
031488bada libSyntax: several enhancements on source location bridging. (#13956)
libSyntax nodes don't maintain absolute source location on each
individual node. Instead, the absolute locations are calculated on
demand with a given root by accumulating the length of all the other
nodes before the target node. This bridging is important for issuing
diagnostics from libSyntax entities.

With the observation that our current implementation of the source
location calculation has multiple bugs, this patch re-implemented this
bridging by using the newly-added syntax visitor. Also, we moved the function
from RawSyntax to Syntax for better visibility.

To test this source location calculation, we added a new action in
swift-syntax-test. This action parses a given file as a
SourceFileSyntax, calculates the absolute location of the
EOF token in the SourceFileSyntax, and dump the buffer from the start
of the input file to the absolute location of the EOF. Finally, we compare
the dump with the original input to ensure they are identical.
2018-01-15 16:39:17 -08:00
Xi Ge
b85f6d9c58 libSyntax: add a C++ side read-only syntax visitor to facilitate verification. NFC (#13882) 2018-01-11 16:17:44 -08:00
Harlan Haskins
9732442628 [Syntax] Remove LegacyASTTransformer
As it is no longer ever instantiated, and since Syntax nodes are being
plumbed through the parser, the LegacyASTTransformer no longer needs to
exist.
2017-11-29 17:51:57 -05:00
Xi Ge
e0dfa6119f libSyntax: add a test to ensure the generated syntax kinds from parser are expected. 2017-10-21 14:12:59 -07:00
Xi Ge
844aeae2d5 Re-apply "libSyntax: create a basic infrastructure for generating libSyntax entities by using Parser." (#12538) 2017-10-20 22:58:28 -07:00
Greg Parker
48a6b9d464 Revert "libSyntax: create a basic infrastructure for generating libSyntax entities by using Parser."
This reverts commit ee7a06276d.
It causes build failures like "'swift/Syntax/SyntaxNodes.h' file not found".
2017-10-19 17:11:48 -07:00
Xi Ge
ee7a06276d libSyntax: create a basic infrastructure for generating libSyntax entities by using Parser. 2017-10-18 17:02:00 -07:00
Xi Ge
70dd88446c libSyntax: add a factory method to create meaningful nodes with a generic syntax list. (#12332) 2017-10-09 11:14:35 -07:00
Harlan
a5098e6b69 Generate libSyntax API (#10926)
* Generate libSyntax API

This patch removes the hand-rolled libSyntax API and replaces it with an
API that's entirely automatically generated. This means the API is
guaranteed to be internally stylistically and functionally consistent.
2017-07-25 18:19:58 -07:00
Harlan
b9f468e79a [NFC] Remove Syntax's dependency on Sema (#10984)
* Move LegacyASTTransformer and SyntaxASTMapping to AST

* Fix import in swift-syntax-format

* Update swift-syntax-test
2017-07-18 16:58:18 -07:00
Harlan Haskins
69151171db Clean up removals of friend declarations 2017-06-23 13:36:02 -07:00
Harlan Haskins
a77029a0e4 Remove friend declarations for SyntaxData 2017-06-23 13:34:08 -07:00
Harlan Haskins
972502d024 Remove subclasses of SyntaxData and move validation logic into Syntax subclasses. 2017-06-22 21:52:59 -07:00
David Farler
bb4253e3d3 Convert generic-requirement-list to SyntaxCollection, implement function-declaration
This mostly wraps up the first cut of function-declaration.

https://bugs.swift.org/browse/SR-4043
2017-03-02 17:02:50 -08:00
David Farler
e565392f81 [Syntax] Add convenience iterator for SyntaxCollections 2017-03-02 17:02:50 -08:00
David Farler
c958cd65eb [Syntax] Allow UnknownSyntax to have children
This will make it easier to incrementally implement syntax nodes,
while allowing us to embed nodes that we do know about inside ones
that we don't.

https://bugs.swift.org/browse/SR-4062
2017-02-28 14:30:57 -08:00
David Farler
c343298b8f [Syntax] Implement return-statement and integer-literal-expr
A return statement needs something to return, so implement
integer-literal-expression too. This necessarily also forced
UnknownExprSyntax, UnknownStmtSyntax, and UnknownDeclSyntax,
which are stand-in token buckets for when we don't know
how to transform/migrate an AST.

This commit also contains the core function for caching
SyntaxData children. This is highly tricky code, with some
detailed comments in SyntaxData.{h,cpp}. The gist is that
we have to atomically swap in a SyntaxData pointer into the
child field, so we can maintain pointer identity of SyntaxData
nodes, while still being able to cache them internally.

To prove that this works, there is a multithreaded test that
checks that two threads can ask for a child that hasn't been
cached yet without crashing or violating pointer identity.

https://bugs.swift.org/browse/SR-4010
2017-02-22 18:45:29 -08:00
David Farler
7ee42994c8 Start the Syntax library and optional full token lexing
Add an option to the lexer to go back and get a list of "full"
tokens, which include their leading and trailing trivia, which
we can index into from SourceLocs in the current AST.

This starts the Syntax sublibrary, which will support structured
editing APIs. Some skeleton support and basic implementations are
in place for types and generics in the grammar. Yes, it's slightly
redundant with what we have right now. lib/AST conflates syntax
and semantics in the same place(s); this is a first step in changing
that to separate the two concepts for clarity and also to get closer
to incremental parsing and type-checking. The goal is to eventually
extract all of the syntactic information from lib/AST and change that
to be more of a semantic/symbolic model.

Stub out a Semantics manager. This ought to eventually be used as a hub
for encapsulating lazily computed semantic information for syntax nodes.
For the time being, it can serve as a temporary place for mapping from
Syntax nodes to semantically full lib/AST nodes.

This is still in a molten state - don't get too close, wear appropriate
proximity suits, etc.
2017-02-17 12:57:04 -08:00
David Farler
f450f0ccdf Revert "Preserve whitespace and comments during lexing as Trivia"
This reverts commit d6e2b58382.
2016-11-18 13:23:31 -08:00
David Farler
d6e2b58382 Preserve whitespace and comments during lexing as Trivia
Store leading a trailing "trivia" around a token, such as whitespace,
comments, doc comments, and escaping backticks. These are syntactically
important for preserving formatting when printing ASTs but don't
semantically affect the program.

Tokens take all trailing trivia up to, but not including, the next
newline. This is important to maintain checks that statements without
semicolon separators start on a new line, among other things.

Trivia are now data attached to the ends of tokens, not tokens
themselves.

Create a new Syntax sublibrary for upcoming immutable, persistent,
thread-safe ASTs, which will contain only the syntactic information
about source structure, as well as for generating new source code, and
structural editing. Proactively move swift::Token into there.

Since this patch is getting a bit large, a token fuzzer which checks
for round-trip equivlence with the workflow:

fuzzer => token stream => file1
  => Lexer => token stream => file 2 => diff(file1, file2)

Will arrive in a subsequent commit.

This patch does not change the grammar.
2016-11-15 16:11:57 -08:00