Commit Graph

40 Commits

Author SHA1 Message Date
Alex Hoppen
73cece2803 [libSyntax] Make SyntaxFactory methods instance methods
This saves us from passing in the SyntaxArena every time a new node is
created.
2021-03-03 11:02:55 +01:00
Alex Hoppen
7be84c115c [libSyntax] Adjust SyntaxTests that were potentially creating SyntaxArena reference cycles 2021-03-02 22:42:45 +01:00
Alex Hoppen
9ff88b2839 [libSyntax] Fix SwiftSyntaxTests broken due to change SyntaxFactory API
This fixes the SwiftSyntaxTests that were broken because the
SyntaxFactory API now requires an Arena in which the nodes should be
created.
2021-03-01 09:43:54 +01:00
Alex Hoppen
db3a520bc7 [libSyntax] Adjust tests for raw trivia being stored in RawSyntax 2021-02-05 08:15:54 +01:00
Doug Gregor
3cfe390a51 [Concurrency] Add Syntax support for 'async'.
Add 'async' to the syntax tree for types, function declarations, and
the "arrow" expression.
2020-07-28 16:41:17 -07:00
Rintaro Ishizaki
60341baf62 [SyntaxParse] Refactor generic requirement syntax structure
Re-apply a part of 0569cbfb28 after
reverting ASTGen changes. This is still an improvement.
2019-10-21 15:16:56 -07:00
Rintaro Ishizaki
8768832f24 Revert "Merge pull request #27281 from rintaro/reapply-syntaxparse-genericparam"
This reverts commit 5d3e8d6c83, reversing
changes made to 27e881d97e.
2019-10-14 12:46:31 -07:00
Rintaro Ishizaki
0569cbfb28 Revert "Revert "[SyntaxParse] Parse generic parameter clause and generic where clause""
This reverts commit 1584e87aa7.
2019-09-20 15:26:04 -07:00
Rintaro Ishizaki
1584e87aa7 Revert "[SyntaxParse] Parse generic parameter clause and generic where clause" 2019-09-20 14:02:53 -07:00
Rintaro Ishizaki
f919b2ddd8 [SyntaxParse] Parse generic parameter clause and generic where clause 2019-09-19 23:09:58 -07:00
Argyrios Kyrtzidis
3612cd3d72 [utils/gyb_syntax_support] Add collection_element_name for when specifying a Child
This is useful to provide `add<ELEMENT_NAME>` APIs for SwiftSyntax that are better named
and without having name conflicts.
2019-04-23 18:14:39 -07:00
Xi Ge
ddd643fe89 syntax: perform rename to avoid name collision in syntax builder. NFC 2019-04-20 16:04:41 -07:00
bannzai
f425c39e60 Add FunctionParameterWithEllipsis test case 2019-01-30 02:26:33 +09: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
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
66d400eb1b [Syntax] Parse 'enum' and 'case' declaration (#15704) 2018-04-04 08:38:08 +09: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
Xi Ge
fe1a4ca0d2 libSyntax: create libSyntax node for var decl accessors. 2017-12-18 15:16:14 -08:00
Rintaro Ishizaki
53b2e0fe14 [Syntax] Parse composition type node 2017-12-15 10:52:10 -08:00
Xi Ge
b4b638651d libSyntax: create syntax node for typealias declarations. (#13450) 2017-12-14 17:44:54 -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
1b24d23c1e libSyntax: support function parameter nodes. (#13324) 2017-12-07 14:09:17 -08:00
Xi Ge
fec040d95e libSyntax: support generic parameter clause. (#13286)
This patch also performs minor refactoring to align syntax parsing
context with the right scope. We start to support the generic clauses
because they are necessary pieces to construct struct or
function syntax node.
2017-12-05 19:34:55 -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
Rintaro Ishizaki
e7cfae0ba9 [libSyntax] Support parsing type-identifier 2017-11-29 09:57:59 +09:00
Xi Ge
e560170a60 libSyntax: Parse member access expression. (#13119)
* libSyntax: Parse member access expression.

This patch uses createNodeInPlace from syntax parsing context API to
merge an expression with its suffix to create recursive nodes such as
member access expression.

Meanwhile, this patch breaks down a signed integer or float literal to a
prefix operator expression. This expression consists of two parts: an
operator and the following expression. This makes literals like "+1" or
"-1" no different from other prefix unary expressions such as "!true".
2017-11-28 16:29:50 -08: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
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
c2aeb55119 Add tests for IntegerLiteralExprSyntax.
This also fixes a typo in makePrefixOperator and implements
IntegerLiteralExprSyntax::withSign.
2017-03-21 09:24:42 -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
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
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
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
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