Commit Graph

246 Commits

Author SHA1 Message Date
Joe Groff
a5ca6ccd61 Restructure KeyPathExpr to allow more kinds of components.
Expand the representation in anticipation of more kinds of components. NFC intended yet.
2017-04-04 11:31:15 -07:00
Joe Groff
eb5d006e40 Rename ObjCKeyPathExpr -> KeyPathExpr.
We can use the same general shape of expression for native key paths.
2017-04-04 11:31:15 -07: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
634837f722 [gardening] Write "anonymous namespace" instead of "namespace" 2017-03-17 08:08:17 +01:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
practicalswift
8923a0b32e [gardening] Remove unused variable TokEnd 2017-03-07 16:19:12 +01:00
Hugh Bellamy
33f5f89912 Update unreachable control path annotations 2017-03-03 20:21:49 +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
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
b99df061f6 Update lib/Syntax/Status.md for function declarations
NFC.
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
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
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
practicalswift
57fa66e9fe [gardening] Fix inconsistent headers 2017-02-28 17:15:39 +01: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
ff75fa7749 [Syntax] Roughly categorize unimpemented productions in Status.md 2017-02-27 13:57:33 -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
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
19ed1dd62a [Syntax] Remove some more trivial/intermediate productions from Status.md
NFC.
2017-02-22 18:45:29 -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
52096534a6 [Syntax] Fix a few typos and language in Readme.md 2017-02-22 18:45:29 -08:00
Hugh Bellamy
32260e6475 Merge pull request #7588 from hughbe/swiftSyntax-win32
Port swiftSyntax to Windows
2017-02-22 10:26:24 +07:00
practicalswift
312a7fe526 [gardening] Use #if 0 ... #endif instead of /* ... */ to comment out code 2017-02-21 14:20:34 +01:00
David Farler
bd6959b274 [Syntax] Fix unconscionable typography 2017-02-20 17:56:26 -08:00
David Farler
2578ae3be1 [Syntax] Add example object diagram for a return statement
Add a little visualization for a code snippet showing the main
players in the Syntax tree, showing where the strong references
flow.

NFC - documentation only.
2017-02-20 17:53:31 -08:00
Hugh Bellamy
b564a917be Port swiftSyntax to Windows 2017-02-21 08:24:56 +07: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
71346dc5c1 [Syntax] Add round-trip syntax test driver and stdlib roundtrip test 2017-02-17 12:57:04 -08:00
David Farler
9627c5eafd [Syntax] Add Status.md document
This will show what is currently implemented, covered by tests,
and relevant Swift bugs / radars.
2017-02-17 12:57:04 -08:00
David Farler
a6df054ae0 [Syntax] Add README.md for lib/Syntax 2017-02-17 12:57:04 -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
practicalswift
6fa577dfbd [gardening] Fix recently introduced typos. Fix inconsistent headers. 2016-11-17 13:09:02 +01: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