Commit Graph

199 Commits

Author SHA1 Message Date
Harlan Haskins
a273ca405d [Syntax] Don't serialize text for simple tokens
The text for tok::kw_struct, and similar, are always known.
Save space by not serializing them.
2017-06-20 15:43:34 -07:00
Harlan Haskins
841df8d8b5 Correct comment 2017-06-15 16:11:13 -07:00
Harlan Haskins
d0d4967f3f Fix unfinished comment 2017-06-15 16:10:03 -07:00
Harlan Haskins
bc6e56c17c Add simple diff test for serialized syntax 2017-06-15 16:08:11 -07:00
Harlan Haskins
a3aeb4b151 Add serialization code for RawSyntax
This patch will allow for serialization of RawSyntax trees to JSON,
which allows external tools to get access to a RawSyntax tree.

This also adds a hook into swift-syntax-test to generate JSON for a
given Swift source file, which will be used in tests in subsequent
commits.
2017-06-15 15:49:56 -07:00
Robert Widmann
3e2bbfe904 [Gardening] Cleanup TokenKinds.def (#10034)
* [Parse] Refactored internal structure of Tokens.def and documented usage.

Added a level of structure to the macro definitions to allow Swift
keywords to be cleanly accessed separately from SIL and Swift keywords
together. Documented structure and usage.

* [Parse] Made use of new guarantees and abstractions in Tokens.def

Used guarantees about undefining macros after import and new
SWIFT_KEYWORD abstraction to simplify usage of the Token.def
imports.

* Gardening
2017-06-01 15:08:48 -07:00
Huon Wilson
07c5ab8fb2 Implement \ syntax for Swift key paths.
This introduces a few unfortunate things because the syntax is awkward.
In particular, the period and following token in \.[a], \.? and \.! are
token sequences that don't appear anywhere else in Swift, and so need
special handling. This is somewhat compounded by \foo.bar.baz possibly
being \(foo).bar.baz or \(foo.bar).baz (parens around the type), and,
furthermore, needing to distinguish \Foo?.bar from \Foo.?bar.

rdar://problem/31724243
2017-05-01 16:06:15 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
practicalswift
7eb7d5b109 [gardening] Fix 100 typos. 2017-04-18 17:01:42 +02:00
David Farler
303a3e5824 Start the Migrator library
The Swift 4 Migrator is invoked through either the driver and frontend
with the -update-code flag.

The basic pipeline in the frontend is:

- Perform some list of syntactic fixes (there are currently none).
- Perform N rounds of sema fix-its on the primary input file, currently
  set to 7 based on prior migrator seasons.  Right now, this is just set
  to take any fix-it suggested by the compiler.
- Emit a replacement map file, a JSON file describing replacements to a
  file that Xcode knows how to understand.

Currently, the Migrator maintains a history of migration states along
the way for debugging purposes.

- Add -emit-remap frontend option
  This will indicate the EmitRemap frontend action.
- Don't fork to a separte swift-update binary.
  This is going to be a mode of the compiler, invoked by the same flags.
- Add -disable-migrator-fixits option
  Useful for debugging, this skips the phase in the Migrator that
  automatically applies fix-its suggested by the compiler.
- Add -emit-migrated-file-path option
  This is used for testing/debugging scenarios. This takes the final
  migration state's output text and writes it to the file specified
  by this option.
- Add -dump-migration-states-dir

  This dumps all of the migration states encountered during a migration
  run for a file to the given directory. For example, the compiler
  fix-it migration pass dumps the input file, the output file, and the
  remap file between the two.

  State output has the following naming convention:
  ${Index}-${MigrationPassName}-${What}.${extension}, such as:
  1-FixitMigrationState-Input.swift

rdar://problem/30926261
2017-04-17 16:25:02 -07:00
Joe Groff
e3046d6f75 Parsing for native keypaths.
Use `#keyPath2` as a stand-in for the final syntax.
2017-04-04 11:31:15 -07:00
practicalswift
00ba5dc248 [gardening] Fix typos 2017-04-02 16:23:45 +02:00
Harlan
d90032cc45 [Syntax] Make FunctionTypeSyntax use a FunctionParameterList (#8270)
* Made FunctionType use a FunctionParameterList instead of TupleTypeElementList

* Added round-trip test

* Removed unused test variables
2017-03-23 09:57:11 -04:00
Harlan
631c7d8064 [Syntax] Refactor Tuple Type Syntax (#8254)
* Refactor Tuple Type Syntax

This patch:

- Refactors TypeArgumentListSyntax and
  TypeArgumentListSyntaxData to use the SyntaxCollection and
  SyntaxCollectionData APIs.
- Refactors TupleTypeElementSyntax to own its trailing comma, and
  updates the tests accordingly.
- Provides an infrastructure for promoting types to use
  the SyntaxCollection APIs

* Addressed comments.

* Renamed makeBlankTypeArgumentList()

* Update makeTupleType

* Changed makeTupleType to take an element list.

* Updated comment.

* Improved API for creating TupleTypeElementListSyntax'es

* Added round-trip test

* Removed last TypeArgumentList holdovers.

* Fixed round-trip test invocation
2017-03-22 08:02:29 -04:00
Harlan Haskins
c2aeb55119 Add tests for IntegerLiteralExprSyntax.
This also fixes a typo in makePrefixOperator and implements
IntegerLiteralExprSyntax::withSign.
2017-03-21 09:24:42 -07:00
practicalswift
0cf00ac487 [gardening] Add missing headers. 2017-03-07 16:44:53 +01:00
practicalswift
dd588b4273 [gardening] Remove likely word processor artefacts 2017-03-07 16:44:52 +01:00
Ben Langmuir
3020d339d6 Fix SyntaxCollection operator[] in no-asserts build
This operator[] relies on having the cache contain the right number of
elements, and each element be initialized to nullptr, which was only
happening if NDEBUG was not defined.

rdar://problem/30832595
2017-03-03 11:00:01 -08: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
ceb3babbc6 [Syntax] Short diversion converting StmtListSyntax to a SyntaxCollection 2017-03-02 17:02:50 -08:00
David Farler
f900fbdcea Implement function-declaration in lib/Syntax
https://bugs.swift.org/browse/SR-4043
2017-03-02 17:02:50 -08:00
David Farler
18ee4e19a1 Implement declaration-modifier(s) in lib/Syntax
- declaration-modifier
  - DeclModifierSyntax
- declaration-modifiers
  - DeclModifierListSyntax

https://bugs.swift.org/browse/SR-4146
2017-03-02 17:02:50 -08:00
David Farler
288da665e3 Implement function-signature in lib/Syntax
Part of:
https://bugs.swift.org/browse/SR-4043
2017-03-02 17:02:50 -08:00
David Farler
e70a65882f [Syntax] function-parameter-list is now a SyntaxCollection
Removes some code duplication.
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
7ce3b81001 Add generic Syntax collection for unbounded list of nodes
Just a little reusable collection type for things like argument lists,
statement lists, etc.
2017-03-02 17:02:50 -08:00
David Farler
cac51bd69b Implement function-parameter-list and friends in lib/Syntax
Implements the following grammar productions:

- function-parameter-list
- function-parameter

This is mostly reusable for other flavors of function declarations,
such as initializers and whatnot, but those will have separate
top-level syntax nodes.

https://bugs.swift.org/browse/SR-4067
2017-03-02 17:02:50 -08:00
practicalswift
8507c93809 [gardening] Add C++ language marker to .h file 2017-03-02 16:19:56 +01: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
6a51c49752 Merge pull request #7790 from bitjammer/sr-4044-function-call-expr-syntax
[Syntax] Implement stuff for function call expressions
2017-02-27 20:19:45 -08:00
David Farler
c8bb2b8c32 [Syntax] Implement function-call-expression in lib/Syntax
Also includes for its substructure:
- function-call-argument
- function-call-argument-list
- symbolic-reference-expression (for the call target)

https://bugs.swift.org/browse/SR-4044
2017-02-27 13:57:27 -08:00
practicalswift
98d2254073 [gardening] Fix a-vs-an typos 2017-02-24 09:38:00 +01:00
practicalswift
246cfa6c16 [gardening] Use consistent headers 2017-02-24 09:37:37 +01:00
practicalswift
d352652a72 Merge pull request #7727 from practicalswift/typos-20170223
[gardening] Fix typos
2017-02-24 09:15:12 +01:00
practicalswift
33a5601ad1 [gardening] Fix typos 2017-02-23 22:46:40 +01:00
David Farler
733988cdfe [Syntax] Add Trivia C++ unit tests
https://bugs.swift.org/browse/SR-4053
2017-02-23 13:46:08 -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
practicalswift
6d09574ffb [gardening] Fix likely word processing artefacts. 2017-02-21 14:20:34 +01:00
practicalswift
e44af328fb [gardening] Fix incorrect Swift URLs. 2017-02-21 14:20:34 +01:00
David Farler
1801c1ade1 [Syntax] Implement continue-statement in lib/Syntax
https://bugs.swift.org/browse/SR-3991
2017-02-17 22:57:52 -08:00
David Farler
e6ef58af43 [Syntax] Implement break-statement in lib/Syntax
https://bugs.swift.org/browse/SR-3990
2017-02-17 20:15:11 -08:00
David Farler
0d8a82d1ca [Syntax] Implement fallthrough-statement
https://bugs.swift.org/browse/SR-3989
2017-02-17 19:00:31 -08:00
David Farler
2d4cb088f4 [Syntax] Remove dummy indent implementation
This isn't a robust implementation and is breaking the build. I'll
put it back once indentation is better specified.
2017-02-17 15:55:00 -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
44f15558d6 Revert "Refactor: Rename Parser::consumeToken, consumeLoc. Add consumeToken API."
This reverts commit 39bfc123a3.
2016-11-18 13:23:31 -08:00
practicalswift
6fa577dfbd [gardening] Fix recently introduced typos. Fix inconsistent headers. 2016-11-17 13:09:02 +01:00
David Farler
39bfc123a3 Refactor: Rename Parser::consumeToken, consumeLoc. Add consumeToken API.
These APIs return SourceLocs, and eventually the Parser should consume
tokens, which now include source trivia such as whitespace and comments,
and package them into a purely syntactic tree.  Just a tiny step. NFC.
2016-11-15 16:11:57 -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