Commit Graph

123 Commits

Author SHA1 Message Date
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
Alex Hoppen
8430eff670 [libSyntax] Add syntax coloring based on the syntax tree 2018-07-13 17:48:47 -07:00
Alex Hoppen
1b3baf908f [incrParse] Add error nodes to the end of a CodeBlockItem
Creating a new CodeBlockItem meant that when doing an edit in the error
nodes, the prefix gets reused and thus the code is parsed as invalid
although it is not.
2018-05-22 09:07:55 -07:00
Alex Hoppen
e1a99efd57 [incrParse] Fix parsing of nodes covering no source text 2018-05-22 08:52:39 -07:00
Alex Hoppen
b904194998 [libSyntax] Add support for parsing #sourceLocation directives 2018-05-22 08:52:31 -07:00
Harlan
a66931e7fb [SwiftSyntax] Allow for visiting SyntaxCollections (#16687)
* Allow for visiting SyntaxCollections

* The 'base type' for a SyntaxCollection is 'Syntax'

* Actually add test file
2018-05-18 10:22:26 -07:00
Alex Hoppen
a5d4a98ca5 [libSyntax] Add parsing capability for the __consuming modifier 2018-05-01 09:57:28 -07:00
Alex Hoppen
4c1b27db83 [libSyntax] Fix parsing of delayed function bodies 2018-04-27 21:05:36 -07:00
Alex Hoppen
7bbb5fa87a [libSyntax] Fix parsing of key paths on specialised generics 2018-04-27 08:10:20 -07:00
Alex Hoppen
3fd922a9d5 [libSyntax] Accept non-standard accessor kinds 2018-04-27 08:10:20 -07:00
Alex Hoppen
94b8a3545b [libSyntax] Fix parsing for KeyPath 2018-04-25 13:30:31 -07:00
Alex Hoppen
28973f23b6 [libSyntax] Fix parsing of member declarations with trailing semicolon 2018-04-24 14:19:24 -07:00
Alex Hoppen
c6a11097e8 [libSyntax] Fix parsing of #if inside type declarations 2018-04-24 14:16:11 -07:00
Alex Hoppen
3e9ae802c2 [libSyntax] Make parsing of attribute arguments more structured
This also fixes several issues where attribute arguments could not be
parsed as a TokenList since some of its arguments already had structure
and were not tokens
2018-04-24 13:18:15 -07:00
Alex Hoppen
c52f4a8131 [libSyntax] Fix parsing of operators passed to higher order functions 2018-04-23 12:23:27 -07:00
Alex Hoppen
75406c895c [libSyntax] Enable parsing of class restrictions for protocols 2018-04-23 12:23:27 -07:00
Rintaro Ishizaki
338cedd6d5 [Syntax] Parse '#selector' expression syntax 2018-04-12 13:56:04 +09:00
Rintaro Ishizaki
eb69497d64 [Syntax] Parse 'operator' declaration syntax 2018-04-12 13:55:55 +09:00
Rintaro Ishizaki
15a04fc45c Merge pull request #15873 from rintaro/syntax-precedencegroup
[Syntax] Parse 'precedencegroup' declaration syntax
2018-04-12 10:15:27 +09:00
Rintaro Ishizaki
67fb26f759 [Syntax] Remove unused 'SwitchUnknownLabel' 2018-04-12 01:27:40 +09:00
Rintaro Ishizaki
dbcba930fc [Syntax] Add syntax definition for 'precedencegroup' declaration 2018-04-11 23:21:00 +09:00
Jordan Rose
701975ad1d Add parsing support for @unknown (SE-0192)
This is our first statement attribute, made more complicated by the
fact that a 'case'/'default' isn't really a normal statement. I've
chosen /not/ to implement a general statement attribute logic like we
have for types and decls at this time, but I did get the compiler
parsing arbitrary attributes before 'case' and 'default'. As a bonus,
we now treat all cases within functions as being switch-like rather
than enum-like, which is better for recovery when not in a switch.
2018-04-05 16:35:14 -07:00
Rintaro Ishizaki
8e2a0f1861 [Syntax] ModifierList is a collection of DeclModifier (#15734) 2018-04-04 19:07:37 +09:00
Rintaro Ishizaki
66d400eb1b [Syntax] Parse 'enum' and 'case' declaration (#15704) 2018-04-04 08:38:08 +09:00
Rintaro Ishizaki
18b28b9184 [Parse] Factor out declaration modifier list parsing (#15702) 2018-04-03 19:58:57 +09:00
Rintaro Ishizaki
fc3cbcda88 [Syntax] Redesign IfConfigDecl syntax 2018-04-03 01:31:33 +09:00
Xi Ge
9deabd3581 Merge pull request #15539 from rintaro/syntax-typo
[Syntax] Fix typo
2018-03-27 13:07:27 -07:00
Rintaro Ishizaki
4488e99a04 [Syntax] Parse 'switch' statement 2018-03-28 00:30:21 +09:00
Rintaro Ishizaki
93cd5bce15 [Syntax] Fix typo 2018-03-27 22:58:21 +09:00
Rintaro Ishizaki
bf805e47ea [Syntax] Fix make_missing_child() in C++ API 2018-03-14 20:42:51 +09:00
Rintaro Ishizaki
ea5f93807f [Syntax] Add 'unknown' token to Token.py 2018-03-14 20:38:48 +09:00
Harlan
a03ed4384e [Syntax] Add node definition for enums and enum cases (#15196) 2018-03-13 13:11:13 -07:00
omochimetaru
420291bbad [Syntax] isComment in trivia 2018-03-12 23:08:37 +09:00
Xi Ge
e61c8958fd SwiftSyntax: simply trivia implementation on the Swift side. 2018-03-07 16:19:09 -08:00
Xi Ge
94c3f55117 libSyntax: extract meta-information of trivia kinds to syntax_gyb_support. NFC
The existing libSyntax infrastructure uses external python
dictionaries to share logic between C++ and Swift implementations.
This patch teaches trivia kinds to adapt to this infrastructure
 as well.
2018-03-06 17:45:43 -08:00
Harlan
2a3d4cb598 Initial infrastructure for documenting SwiftSyntax API (#14701) 2018-02-26 13:43:11 -05:00
Xi Ge
7c905d38af SwiftSyntax: add WithStatementsSyntax trait and make all names consistent. NFC (#14782) 2018-02-22 14:38:29 -08:00
Xi Ge
02661b3740 SwiftSyntax: Add LabeledSyntax trait. NFC
This commit also adds several "WithTrailingComma" I've missed in the
previous commit.
2018-02-20 16:47:04 -08:00
Xi Ge
bdebd8a210 SwiftSyntax: add WithTrailingCommanSyntax trait and fix inconsistent naming. NFC 2018-02-20 12:02:30 -08:00
Xi Ge
f814309f2e SwiftSyntax: Add ParenthesizedSyntax trait and mark various syntax nodes for conformances. NFC 2018-02-19 19:21:59 -08:00
Xi Ge
1b81fcb2b6 SwiftSyntax: Add a trait for those statement nodes with code block as body. (#14726)
This patch also refactors SyntaxNodes code so that protocol conformances
are declared as extensions.
2018-02-19 18:49:07 -08:00
Xi Ge
1b61ff4f3d SwiftSyntax: add a new trait IdentifiedDeclSyntax. NFC (#14691)
IdentifiedDeclSyntax allows clients to access and modify declared names.
All nominal declarations should have this trait.
2018-02-16 18:47:01 -08:00
Xi Ge
2b61d4edbb SwiftSyntax: add a mechanism to define traits of syntax nodes to allow abstract access to popular child kinds. NFC (#14668)
Swift syntax APIs lack an abstract way of accessing children. The client has to
down-cast a syntax node to the leaf type to access any of its children. However,
some children are common among different syntax kinds, e.g.
DeclAttributeSyntax and DeclMembers. We should allow an abstract way to
access and modify them, so that clients can avoid logic duplication.

This patch adds a mechanism to define new traits and specify satisfied
traits in specific syntax nodes. A trait is a set of common children
and implemented in Swift as a protocol for syntax nodes to conform to.
As a proof-of-concept, we added two traits for now including DeclGroupSyntax
and BracedSyntax.

Resolves: SR-6931 and SR-6916
2018-02-15 16:41:20 -08:00
Rintaro Ishizaki
6c0af2a24f [Syntax] Introduce CodeBlockItem (#14458)
CodeBlockItem represents Decl, Stmt or Expr that optionally followed by
semi-colon.
SourceFile syntax holds a list of CodeBlockItem.
2018-02-08 10:31:01 +09:00
Rintaro Ishizaki
1eedcb7682 [Syntax] Parse '->' in sequence expression 2018-02-06 15:06:00 +09:00
Rintaro Ishizaki
5dc6b78457 [Syntax] Parse generic specialize expression 2018-02-06 15:05:59 +09:00
Rintaro Ishizaki
ba58a2994d [Syntax] Parse associatedtype declaration
Also, added generic where clause to typealias declaration.
2018-02-06 09:33:12 +09:00
Rintaro Ishizaki
62eb27110d [Syntax] Parse 'init', 'deinit' and 'subscript' decl syntax 2018-02-05 19:15:46 +09:00
Harlan
5e02d2a877 Implement #warning and #error (#14048)
* Implement #warning and #error

* Fix #warning/#error in switch statements

* Fix AST printing for #warning/#error

* Add to test case

* Add extra handling to ParseDeclPoundDiagnostic

* fix dumping

* Consume the right paren even in the failure case

* Diagnose extra tokens on the same line after a diagnostic directive
2018-02-03 18:07:05 -05:00
Rintaro Ishizaki
f58548ca17 [Syntax] Don't modify token kind of keyword.
Allow invalid 'throw' in FunctionType instead.
2018-02-02 01:01:01 +09:00