Commit Graph

1224 Commits

Author SHA1 Message Date
Xi Ge
2a39598b4f libSyntax: specialize try expression.
Optional try, forced try and regular try expressions are handled in
this syntax node.
2017-12-12 16:17:48 -08:00
Rintaro Ishizaki
724052d266 [Parse] Rename Lexer::State to LexerState 2017-12-09 13:58:50 +09:00
Rintaro Ishizaki
8bbe4d20ef [libSyntax] Support TypeExpr (#13317)
Just for `Any` for now.
2017-12-07 11:40:05 -08:00
Xi Ge
5ace363dbc libSyntax: specialize As expression and Is expression. (#13179)
This patch also handles variants like "as!" and "as?".
2017-11-30 15:05:22 -08:00
Rintaro Ishizaki
e7cfae0ba9 [libSyntax] Support parsing type-identifier 2017-11-29 09:57:59 +09:00
Rintaro Ishizaki
d1b0d137da [Parse] Set appropriate token kind when consumeStartingCharacterOfCurrentToken() 2017-11-29 09:37:22 +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
Xi Ge
036321546b libSyntax: Support tuple expression.
Tuple expression essentially has the same underlying structure as
function call arguments in libSyntax. However, we separate them as
different libSyntax kinds for better usability.

Different from AST, libSyntax currently allows single-child,
label-free tuple expressions (represented as ParenExpr in AST). This is
subject to change if we need to adopt the same differentiation in
libSyntax in the future.
2017-11-27 16:40:30 -08:00
Xi Ge
588ac6b3e8 libSyntax: add several elementary nodes. (#13085)
They are SequenceExpr, AssignmentExpr, and BinaryOperatorExpr.
2017-11-27 13:15:39 -08:00
Rintaro Ishizaki
d6d26e57be [Syntax] add SyntaxParsingContext::createNodePartially() 2017-11-18 15:35:46 +09:00
Rintaro Ishizaki
0a401b381c [Syntax] Rewrite SyntaxParsingContext
Read RawSyntaxToken along with Parser::consumeToken()

* Single Lexer pass
* Backtracking support
* Split token support
2017-11-18 15:35:46 +09:00
Xi Ge
a4a01f9121 libSyntax: parse ternary expression.
Along with starting to support ternary expressions, this commit also
slightly changes SyntaxParsingContext APIs as follows:

1. Previously, makeNode() only supports node creation by using the nodes
from the underlying syntax token array; this commit allows it to use the nodes from
the pending syntax list as well.

2. This commit strictly limits that the pending syntax list should never
contain token syntax node.

3. The node kind test shouldn't include unknown kinds. They are noisy.
2017-11-14 23:29:23 -08:00
Xi Ge
3d5eb6e062 libSyntax: parse boolean literal expression. (#12908) 2017-11-13 21:03:42 -08:00
Xi Ge
ea76f585b9 libSyntax: parse DiscardAssignmentExpr and NilLiteralExpr. (#12872) 2017-11-11 11:24:34 -08:00
Xi Ge
a71a03986e libSyntax: Start parsing simple identifier expression. (#12862) 2017-11-10 15:26:37 -08:00
Xi Ge
f69bc0eb14 libSyntax: various non-functional enhancements. NFC (#12842)
Avoid heap-allocated memory for syntax parsing context.
Add more assertions to ensure syntax nodes are created only at the top of context stack.
Allow syntax parsing context to delay the specifying of context kind and target syntax kind.
2017-11-09 15:59:25 -08:00
Xi Ge
0d9745f6eb libSyntax: teach parser to parse dictionary and array literals. (#12821)
This commit also adds ArrayExpr and DictionaryExpr to the libSyntax nodes
family. Also, it refactors the original parser code for these two
expressions to better fit to the design of SyntaxParsingContext.

This commit has also fixed two crashers.
2017-11-09 09:00:43 -08:00
Xi Ge
0390d452a6 libSyntax: parse function argument syntax node. (#12803)
This commit teaches parser to parse two libSyntax nodes: FunctionCallArgument and
FunctionCallArgumentList. Along with the change, some libSyntax parsing infrastructure changes
as well: (1) parser doesn't directly insert token into the buffer for libSyntax node creation;
instead, when creating a simple libSyntax node like integer literal expression, parser should indicate the location of the last token in the node; (2) implicit libSyntax nodes like empty
statement list must contain a source location indicating where the implicit nodes should appear
(immediately before the token at the given location).
2017-11-07 15:59:00 -08:00
Xi Ge
b246cf4f48 libSyntax: parse float literal syntax node. 2017-11-03 22:17:06 -07:00
Xi Ge
75db3c1db8 Re-apply libSyntax patches after fixing ASAN issue (#12730)
* Re-apply "libSyntax: Ensure round-trip printing when we build syntax tree from parser incrementally. (#12709)"

* Re-apply "libSyntax: Root parsing context should hold a reference to the current token in the parser, NFC."

* Re-apply "libSyntax: avoid copying token text when lexing token syntax nodes, NFC. (#12723)"

* Actually fix the container-overflow issue.
2017-11-03 13:25:33 -07:00
Xi Ge
4d1249aa82 Revert "libSyntax: Ensure round-trip printing when we build syntax tree from parser incrementally. (#12709)"
This reverts commit 0d98c4c5df.
2017-11-02 14:44:26 -07:00
Xi Ge
cabb6dd063 Revert "libSyntax: Root parsing context should hold a reference to the current token in the parser, NFC."
This reverts commit 19caca7890.
2017-11-02 14:44:10 -07:00
Xi Ge
19caca7890 libSyntax: Root parsing context should hold a reference to the current token in the parser, NFC.
Since all parsing contexts need a reference to the current token of the
parser, we should pass the token reference to the root context. Therefore, the derived
sub-contexts can just copy it while being spawned.
2017-11-02 12:31:45 -07:00
Xi Ge
0d98c4c5df libSyntax: Ensure round-trip printing when we build syntax tree from parser incrementally. (#12709) 2017-11-01 20:29:30 -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
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
Ben Langmuir
48d191f600 [code-completion] Fix for-loop sequences containing collection syntax
This fixes various issues with getting no code-completion in top-level
code containing array/dictionary sugar, such as:
```
for x in [<HERE>] {}
for x in [1: 2, <HERE>] {}
```

And also removes the index variable from completions inside the sequence
(it was coming through as a local variable with <<error type>>).

rdar://problem/33884082
2017-08-17 14:57:57 -07:00
Slava Pestov
f93447e904 Parse: Fix capture list parsing with 'self'
We accepted the following capture lists:

- [x]
- [weak x]
- [weak self]

But not [self]. I think this is an oversight.
2017-07-29 19:18:01 -07:00
Slava Pestov
36d43846ea Parse: Relax a recently-added assertion
We parse default argument expressions before building a
FuncDecl, so we might see GenericTypeParamDecls that have
not yet been re-parented to the FuncDecl's context.

Fixes <https://bugs.swift.org/browse/SR-5559>,
<rdar://problem/33539464>.
2017-07-28 21:35:47 -07:00
Slava Pestov
737174fe9f AST: Add a DeclContext field to ComponentIdentTypeRepr
Plumb this through and set it appropriately, but don't use it
for anything yet.
2017-07-18 22:10:33 -07:00
Robert Widmann
4da853e7cb Rename Specifier::None to Specifier::Owned 2017-07-05 14:02:26 -07:00
Robert Widmann
ac5594dabe Use a meaningful representation of parameter specifiers
In anticipation of future attributes, and perhaps the ability to
declare lvalues with specifiers other than 'let' and 'var', expand
the "isLet" bit into a more general "specifier" field.
2017-06-29 16:03:49 -07:00
Harlan
e89e7f58b2 [Parse] [Syntax] Simplify TupleTypeRepr parsing and add attributes for Syntax (#8298)
* Simplify TupleTypeRepr parsing

This patch introduces a TupleTypeReprElement struct that holds the
locations for all relevant bits of tuple elements. It removes the
NameLoc and UnderscoreLoc arrays from TupleTypeReprElement in favor of
holding each of these on TupleTypeReprElement. These extra bits of info
are required for full-fidelity representation in the Syntax library.

* Remove TupleTypeReprBitfields and move EllipsisLoc out of TrailingObjects

* Update users of TupleTypeRepr

* Don't resize the elts if we're going to push_back

* getType -> getElementType

* Move ellipsis back into TrailingObjects.

* Move NumElements into TupleTypeReprBitfields
2017-06-27 10:54:47 -07:00
Robert Widmann
465492853f Remove recursive stream allocations 2017-06-12 10:12:05 -07:00
Adrian-Constantin Popescu
e13d20d30c Fixed failing test/Constraints/tuple_arguments.swift - returning temporary memory on stack. 2017-06-12 10:08:14 -07:00
Jordan Rose
c0ccdb1626 Change getBaseName to return DeclBaseName instead of Identifier (#9968)
This changes `getBaseName()` on `DeclName` to return a `DeclBaseName`
instead of an `Identifier`. All places that will continue to be
expecting an `Identifier` are changed to call `getBaseIdentifier` which
will later assert that the `DeclName` is actually backed by an
identifier and not a special name.

For transitional purposes, a conversion operator from `DeclBaseName` to
`Identifier` has been added that will be removed again once migration
to DeclBaseName has been completed in other parts of the compiler.

Unify approach to printing declaration names

Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:55:03 -07:00
Slava Pestov
1b254a9843 Sema: Kill off old modeling of generic arguments 2017-05-24 20:39:10 -07:00
Slava Pestov
7ec163a83a Parse: Simplify parsing of generic types
Now that preCheckExpression() can handle more cases, we can
eliminate a special case where sometimes we would make
DeclRefExprs instead of TypeExprs for references to generic
types.
2017-05-23 02:10:03 -07:00
Joe Groff
faa6bc72f0 Sema: Reject unimplemented key path components during resolveKeyPathExpr.
This is a bit more robust and user-friendly than hoping more brittle recovery in SILGen or IRGen for unsupported components kicks in. rdar://problem/32200714
2017-05-15 16:10:59 -07:00
Xi Ge
e997128129 [CodeCompletion] Provide basic code completion support for Swift KeyPath. rdar://31768743 (#9467) 2017-05-10 21:48:50 -07:00
practicalswift
49ed8579c4 [gardening] Use American English. 2017-05-09 20:44:30 +02:00
Pavel Yaskevich
ddaccf88bb [QoI] Properly diagnose closure parameter distructuring after SE-0110
Swift 3 supported limited argument destructuring when it comes to
declaring (trailing) closures. Such behavior has been changed by
SE-0110. This patch aims to provide better error message as well
as fix-it (if structure of the expected and actual arguments matches)
to make the migration easier and disambiguate some of the common
mistakes.

Resolves: SR-4738, SR-4745, rdar://problem/31892961.
2017-05-08 23:04:37 -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
Huon Wilson
bb5d42d56d [Parser] Extract postfix expression suffix parsing. NFC. 2017-05-01 05:31:22 -07:00
Joe Groff
cdb54ccadf Put keypaths behind a flag. 2017-04-19 20:39:11 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Graydon Hoare
4d9ea18e59 Add mode to Parser::parseUnqualifiedDeclName for 0-arg compound names. 2017-04-18 11:12:54 -07:00
Graydon Hoare
e191b92966 Add mode to Parser::parseUnqualifiedDeclName to handle operator BaseNames. 2017-04-18 11:12:54 -07:00