Commit Graph

168 Commits

Author SHA1 Message Date
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
Xi Ge
34e2aec662 Parser: use parser to generate a refined token stream to help syntax coloring. (#11809)
This patch allows Parser to generate a refined token stream to satisfy tooling's need. For syntax coloring, token stream from lexer is insufficient because (1) we have contextual keywords like get and set; (2) we may allow keywords to be used as argument labels and names; and (3) we need to split tokens like "==<". In this patch, these refinements are directly fulfilled through parsing without additional heuristics. The refined token vector is optionally saved in SourceFile instance.
2017-09-08 10:28:19 -07:00
Robert Widmann
481715a227 Ensure RawSyntax macro parameters are the same with NDEBUG (#11196)
I forgot to reset the macro parameters after converting them to
varargs, which didn't get caught running PR testing.

This patch ensures they're all the same.
2017-07-26 09:59:58 -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
Robert Widmann
b77f2c147c Parse Shared
Add parser support for __shared and __owned as type attributes.  Also, extend parser diagnostics and tests to account for the new type attributes.
2017-07-23 21:47:25 -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
70089a7bcc [Syntax] Represent TokenSyntax as a Syntax node (#10606)
Previously, users of TokenSyntax would always deal with RC<TokenSyntax>
which is a subclass of RawSyntax. Instead, provide TokenSyntax as a
fully-realized Syntax node, that will always exist as a leaf in the
Syntax tree.

This hides the implementation detail of RawSyntax and SyntaxData
completely from clients of libSyntax, and paves the way for future
generation of Syntax nodes.
2017-06-27 11:08:10 -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
a0047777ff Remove friend declarations for removed classes 2017-06-23 13:33:46 -07:00
Harlan Haskins
0e61e50ebb Fix UnknownSyntaxTests. One test still fails. 2017-06-23 11:59:16 -07:00
Harlan Haskins
b9c04ec51a Clean up AtomicCache 2017-06-23 11:37:54 -07:00
Harlan Haskins
b73725ad41 Fix SyntaxCollection template errors 2017-06-23 11:34:58 -07:00
Harlan Haskins
bbae4df4cf Update README to reflect new structure 2017-06-23 11:06:24 -07:00
Harlan Haskins
972502d024 Remove subclasses of SyntaxData and move validation logic into Syntax subclasses. 2017-06-22 21:52:59 -07:00
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