Commit Graph

45 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
b904194998 [libSyntax] Add support for parsing #sourceLocation directives 2018-05-22 08:52:31 -07:00
Alex Hoppen
a5d4a98ca5 [libSyntax] Add parsing capability for the __consuming modifier 2018-05-01 09:57:28 -07:00
Alex Hoppen
3fd922a9d5 [libSyntax] Accept non-standard accessor kinds 2018-04-27 08:10:20 -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
Rintaro Ishizaki
eb69497d64 [Syntax] Parse 'operator' declaration syntax 2018-04-12 13:55:55 +09:00
Rintaro Ishizaki
dbcba930fc [Syntax] Add syntax definition for 'precedencegroup' declaration 2018-04-11 23:21:00 +09: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
Rintaro Ishizaki
4488e99a04 [Syntax] Parse 'switch' statement 2018-03-28 00:30:21 +09:00
Harlan
a03ed4384e [Syntax] Add node definition for enums and enum cases (#15196) 2018-03-13 13:11:13 -07: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
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
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
Yurii Samsoniuk
d5771cea6b Added extension specialization to libSyntax 2017-12-29 01:27:26 +09:00
Davide Italiano
72ee07b8d5 [lib/Syntax] Rename an API, accesor->accessor.
The latter is the correct way.
2017-12-28 00:54:45 +09:00
Xi Ge
6c1f682af9 libSyntax: allow children of syntax nodes to have multiple choices. rdar://35879331 (#13562)
Some structures of syntax nodes can have children choices, e.g. a
dictionary expression can either contain a single ':' token or a list of
key-value pairs.

This patch gives the existing code generation infrastructure a way to
specify such node choices. Node choices are specified under a child
declaration with two constraints: a choice cannot be declared as
optional, and a choice cannot have further recursive choices.

Since we don't have too many node structures with choices, part of the
SyntaxFactory code for these nodes is manually typed.

This patch also teaches AccessorBlock to use node choices.
2017-12-20 15:33:57 -08:00
Xi Ge
e0d167f1dd libSyntax: create syntax nodes for variable declarations.
Variable declarations are declarations led by either 'var' or 'let'. It
can contain multiple pattern bindings as children.

For patterns, this patch only creates syntax nodes for simple identifier
patterns, e.g. 'a = 3'. The rest of the pattern kinds are still left
unknown (UnknownPattern).
2017-12-19 12:25:51 -08:00
Xi Ge
fe1a4ca0d2 libSyntax: create libSyntax node for var decl accessors. 2017-12-18 15:16:14 -08:00
Faiçal Tchirou
5e41098851 libSyntax: specialize class declaration syntax node. (#13485) 2017-12-16 11:36:58 -08:00
Xi Ge
df7db884cf libSyntax: create syntax nodes for IfConfigDecl. 2017-12-15 13:36:47 -08:00
Xi Ge
b4b638651d libSyntax: create syntax node for typealias declarations. (#13450) 2017-12-14 17:44:54 -08:00
Xi Ge
a6b3559a8a libSyntax: specialize import declaration. (#13437) 2017-12-14 12:27:52 -08:00
Rintaro Ishizaki
e616b2ad37 [Syntax] Use initializer clause syntax node for function parameter (#13430) 2017-12-14 08:12:10 -08:00
Xi Ge
9ddd60d4ef libSyntax: create syntax nodes for closure signature. (#13415)
This patch also refactors the structure of function signature node so
that closure signature can re-use parts of function signature. For
instance, we group arrow and return type to be "ReturnClause". And we
group parenthesized parameter list to be "ParamClause".

This structure of closure signature also calls for a good way to
represent either-or node in libSyntax APIs, since we've two ways to
specify parameters in closure: one is as regular function parameter and
the other is dot-separated simple names.
2017-12-13 16:48:24 -08:00
Xi Ge
fda8dfcfd3 libSyntax: specialize protocol declaration syntax. 2017-12-11 16:17:13 -08:00
Xi Ge
8256b1f88f libSyntax: function declaration syntax should accept operators as name. 2017-12-08 16:30:45 -08:00
Xi Ge
1b24d23c1e libSyntax: support function parameter nodes. (#13324) 2017-12-07 14:09:17 -08:00
Xi Ge
c4604d700e libSyntax: specialize struct declaration syntax node. (#13307)
To construct struct syntax, this patch first specialized type
inheritance clause. For protocol's class requirement, we currently
treat it as an unknown type.

This patch also teaches SyntaxParsingContext to collect syntax nodes
from back in place. This is useful to squash multiple decl modifiers
for declarations like function. This is not used for struct declaration
because only accessibility modifier is allowed.
2017-12-06 14:12:12 -08:00
Xi Ge
1a7f1911b8 libSyntax: support declaration modifiers, like static, private, etc. (#13221)
Some declaration modifiers may have more details attached, like
"private(set)". This patch represents the detail part "(set)" as a token
list.
2017-12-04 13:03:02 -08:00
Xi Ge
9cd54c45f6 libSyntax: encapsulate members of a struct declaration into MemberDeclBlock. (#13193) 2017-12-01 09:19:13 -08:00
Harlan
ade67ca899 [Syntax] Swift libSyntax API (#11320)
* Create Swift libSyntax API

This patch is an initial implementation of the Swift libSyntax API. It
aims to provide all features of the C++ API but exposed to Swift.

It currently resides in SwiftExperimental and will likely exist in a
molten state for a while.

* Only build SwiftSyntax on macOS
2017-08-14 16:47:48 -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