Commit Graph

563 Commits

Author SHA1 Message Date
Rintaro Ishizaki
4a247efc0a [Parse] Parse label in tuple type as tok::identifier
Made an utility method 'consumeArgumentLabel', and use it for:
* Labels in tuple type
* Labels in tuple expression
* Argument and parameter names in parameter clause
2018-05-22 13:46:42 +09:00
Rintaro Ishizaki
e60d75e873 [Parse] Remove unused diagnostics. 2018-04-13 11:58:33 +09:00
Rintaro Ishizaki
203496f048 [Parse] Hoist diagnostics for named 'subscript'/'init'
Mainly for code readability.
2018-04-13 11:58:33 +09:00
Robert Widmann
03580d2fe5 Add a parameter list to EnumElementDecl
This models, but does not plumb through, default arguments.
2018-03-28 00:05:56 -04:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
Rintaro Ishizaki
2134f9f768 [Parse] Move SyntaxParsingContext to Parse (#14360)
This is only for the Parser.
Also, this resolves layering violation where libAST and libSyntax
depends on each other.
2018-02-03 10:43:52 +09:00
Rintaro Ishizaki
d01f5d1da3 [Syntax] Parse "statement condition" nodes 2017-12-23 12:20:34 +09:00
Rintaro Ishizaki
93a74fea44 [Syntax] Parse "is type pattern" syntax node 2017-12-20 19:59:22 +09:00
Rintaro Ishizaki
89d9993f59 [Syntax] Parse matching pattern syntax node
Added support for ExprPattern and UnresolvedPatternExpr.
2017-12-20 19:47:32 +09:00
Rintaro Ishizaki
bc768b6e0e [Syntax] Parse "value binding pattern" nodes 2017-12-20 18:22:08 +09:00
Rintaro Ishizaki
c379f5c232 [Syntax] Parse wildcard pattern node 2017-12-20 17:33:30 +09:00
Rintaro Ishizaki
a1340fd9a2 [Syntax] Parse tuple pattern node 2017-12-20 17:32:30 +09: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
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
7901583833 libSyntax: create parameter list for function signatures without parameters.
If we don't create the empty parameter list, a 0-parameter function declaration
will not be well-formed.
2017-12-08 15:59:59 -08:00
Xi Ge
ec5232a359 libSyntax: support function signature. 2017-12-07 14:38:44 -08:00
Xi Ge
1b24d23c1e libSyntax: support function parameter nodes. (#13324) 2017-12-07 14:09:17 -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
Slava Pestov
93c80da77c Parse: __shared and __owned should be contextual keywords
This was a source compatibility regression, someone actually had
an identifier named __shared.
2017-10-24 20:45:50 -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
Robert Widmann
b77f2c147c Parse Shared
Add parser support for __shared and __owned as type attributes.  Also, extend parser diagnostics and tests to account for the new type attributes.
2017-07-23 21:47:25 -07:00
Huon Wilson
74ea3c12d4 [Parse] Upgrade unlabeled_parameter_following_variadic_parameter to Swift 4 error.
Part of rdar://problem/28961650 .
2017-07-12 13:17:40 -07:00
Robert Widmann
82b13d11ac Merge pull request #10784 from CodaFi/my-sweet-noescape
[SR-5296] @autoclosure and @noescape are not decl attributes
2017-07-06 00:01:21 -07:00
Robert Widmann
ab580a3a0a Remove @autoclosure and @noescape as decl attributes
Using these in declaration position has been deprecated and
removed in Swift 3.  These attributes were not being parsed and
contained deadweight diagnostics that should have been moved
when these attributes became type attributes.
2017-07-05 21:27:04 -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
Robert Widmann
43f29399f3 Remove an old diagnostic for 'var' in param position
Using the attribute in this position is a relic from the Swift 2
days, and fixing it required letting invalid code fall through to
Sema instead of being diagnosed in Parse proper.  Treat 'var'
in this position like 'let' by simply offering to remove it
instead of extracting it into a separate variable.
2017-06-29 13:35:59 -07: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
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
Rintaro Ishizaki
49d134f1a9 [Parse] Stop lying about QuestionLoc of implicit OptionalTypeRepr (#7384)
In conditional statement let/var patterns.
Set invalid location instead.
2017-02-11 13:39:51 +09:00
Slava Pestov
d880053dd5 Merge pull request #7050 from rintaro/parse-diag-consecutiveids
[Parse] Improve diagnostics for consecutive identifiers
2017-01-31 21:19:19 -08:00
Doug Gregor
400684e20a Merge pull request #6823 from matthewcarroll/SR-2475-Warn-when-an-unlabeled-parameter-follows-a-variadic-parameter
[QoI] SR-2475: Warn when an unlabeled parameter follows a variadic parameter
2017-01-30 10:15:05 -08:00
Slava Pestov
d3966d2567 Parse: Fix recursive diagnostic corner-case with invalid UTF8 in source file 2017-01-28 18:35:25 -08:00
Rintaro Ishizaki
9b4f549943 [Parse] Improve diagnostics for consecutive identifiers 2017-01-26 15:37:19 +09:00
Jordan Rose
dec7f9fe7e Merge pull request #6863 from matthewcarroll/SR-3600-Better-recovery-for-naming-an-initializer-deinitializer-or-subscript
[DiagnosticsQoI] SR-3600: Better recovery for trying to name an initializer, deinitializer, or subscript
2017-01-23 16:30:50 -08:00
Matthew Carroll
f8f147ecf9 [DiagnosticsQoI] SR-3600: Better recovery for trying to name an initializer, deinitializer, or subscript
- Restrict this diagnostic to identifiers that are followed by a left paren.
2017-01-21 11:32:09 -05:00
Matthew Carroll
7882ddcf40 [DiagnosticsQoI] SR-3600: Better recovery for trying to name an initializer, deinitializer, or subscript
Add a diagnostic to remove the name of an initializer, deinitializer, or subscript. The identifier token is consumed and skipped to prevent the parser from emitting additional error messages.

Add tests to verify that the name is removed from initializers, deinitializers, and subscripts declared with a name.
2017-01-17 17:21:56 -05:00
Rintaro Ishizaki
c92dbe5319 [Parse] Remove declaration list specific logic from parseList() 2017-01-17 17:19:36 +09:00
Matthew Carroll
33083f0351 [QoI] SR-2475: Warn when an unlabeled parameter follows a variadic parameter
Add a diagnostic that warns when an unlabeled parameter follows a variadic parameter.
https://bugs.swift.org/browse/SR-2475
2017-01-15 16:34:29 -05:00
Slava Pestov
5eb16e6b34 Include-what-you-use: Initializer.h should not be pulled in from AST.h 2017-01-09 16:46:31 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Robert Widmann
96f2a04f55 Merge pull request #6490 from modocache/ast
[SR-2757][Sema] Mark VarDecl in capture lists
2017-01-05 21:36:16 -07:00
Robert Widmann
e36b52c25d Resolve some compiler crashers
Crashers fixed are minor logic errors:

Patterns: Crash occurred when requesting the range of a created
Pattern.  Validity of the range should be checked before returning it
to keep the entire range valid or invalid but never both.

ParseExpr/ParsePattern: The same fixes as the ones provided in #6319

CSDiag: The generic visitor needn’t look through TypeVarTypes either.
2017-01-03 18:53:06 -07:00
Brian Gesiak
4108e1d9af [Sema] Mark VarDecl in capture lists
Fixes SR-2757.

Variables in capture lists are treated as 'let' constants, which can
result in misleading, incorrect diagnostics. Mark them as such in order
to produce better diagnostics, by adding an extra parameter to the
VarDecl initializer.

Alternatively, these variables could be marked as implicit, but that
results in other diagnostic problems: capture list variables that are
never used produce warnings, but these warnings aren't normally emitted for
implicit variables. Other assertions in the compiler also misfire when
these variables are treated as implicit.

Another alternative would be to walk up the AST and determine whether
the `VarDecl`, but there doesn't appear to be a way to do so.
2017-01-01 12:41:06 -05:00
Robert Widmann
443bc682f6 Actually improve recovery when parsing bogus expressions
The crashes fixed appeared at first to be related to IfConfigStmt
parsing, but are in reality symptoms of being too lax in what we accept
when parsing of sub-expressions fail.

Optional type annotation parsing used to propagate failures before it
was patched to ‘recover’ with an AnyPattern.  Instead, we’ll just hit
the error path for parsing in the main expressions because what is here
now isn’t a reasonable thing to return.

#selector parsing assumed that the current token it was at after
consuming up to a right-brace wasn’t bogus.  Instead, if we’ve got
here, we may as well just return a loc we know is valid: PreviousLoc.
2016-12-15 19:08:26 -05:00
Hugh Bellamy
732e3c5fdc Fix warnings building swift/Parse on Windows using MSVC 2016-12-07 22:20:49 +00:00
Rintaro Ishizaki
9eee4adc91 [Parse] Parameter list parsing cleanup
* Removed `parseConstructorArguments()`, unified with
  `parseSingleParameterClause()`.
* Use `parseSingleParameterClause()` from `parseFunctionSignature()`, so
  that we can share the recovery code.
* Removed `isFirstParameterClause` parameter from `mapParsedParameters`,
  because it's predictable from `paramContext`.
2016-12-07 23:20:30 +09:00
Argyrios Kyrtzidis
fc678740db [code-completion] Avoid a tentantive parse when in code-completion mode and make sure CodeCompletionExpr has a token range.
The tentantive parse is used for diagnostic purposes but can cause code-completion to delay the same decl twice.
The range of CodeCompletionExpr was previously character range which invalidated invariants of the AST.

Fixes:
	validation-test/IDE/crashers_fixed/084-swift-parser-consumedecl.swift
	validation-test/IDE/crashers_fixed/104-swift-gettypeofcompletioncontextexpr.swift
2016-12-05 17:09:49 -08:00
Rintaro Ishizaki
97b89adab3 [Parse] Remove redundant 'inout' parsing from parseParameterClause 2016-11-29 23:30:59 +09:00