Commit Graph

212 Commits

Author SHA1 Message Date
Chris Lattner
bf73cc23f1 fix <rdar://problem/20167543> "for var x = ..." not parsed as a foreach loop
This was because the ambiguity between c-style and foreach loops wasn't being
properly handled.  Use the canParsePattern() logic to handle this in full 
generality.

Since that logic was unused, dust it off and clean it up a bit.  Similarly,
remove some old vestigates of default argument parsing in tuples and 
old-syntax array handling.



Swift SVN r26164
2015-03-15 21:43:04 +00:00
Chris Lattner
27ef444db5 Remove the "isLet" parameter from the pattern parsing logic. It was (almost)
duplicated by the InVarOrLetPattern state in the Parser object.  Beef 
InVarOrLetPattern up so that we can remove it.

NFC except that we now reject pointless let patterns in foreach loops,
similar to how we reject var patterns inside of let patterns.



Swift SVN r26163
2015-03-15 21:06:37 +00:00
Chris Lattner
20f8f09ea8 Land: <rdar://problem/19382905> improve 'if let' to support refutable patterns and untie it from optionals
This changes 'if let' conditions to take general refutable patterns, instead of
taking a irrefutable pattern and implicitly matching against an optional.

Where before you might have written:
  if let x = foo() {

you now need to write:
  if let x? = foo() {
    
The upshot of this is that you can write anything in an 'if let' that you can
write in a 'case let' in a switch statement, which is pretty general.

To aid with migration, this special cases certain really common patterns like
the above (and any other irrefutable cases, like "if let (a,b) = foo()", and
tells you where to insert the ?.  It also special cases type annotations like
"if let x : AnyObject = " since they are no longer allowed.

For transitional purposes, I have intentionally downgraded the most common
diagnostic into a warning instead of an error.  This means that you'll get:

t.swift:26:10: warning: condition requires a refutable pattern match; did you mean to match an optional?
if let a = f() {
       ^
        ?

I think this is important to stage in, because this is a pretty significant
source breaking change and not everyone internally may want to deal with it
at the same time.  I filed 20166013 to remember to upgrade this to an error.

In addition to being a nice user feature, this is a nice cleanup of the guts
of the compiler, since it eliminates the "isConditional()" bit from
PatternBindingDecl, along with the special case logic in the compiler to handle
it (which variously added and removed Optional around these things).




Swift SVN r26150
2015-03-15 07:06:22 +00:00
Chris Lattner
9ac6c23c1d rename IsaPattern -> IsPattern to follow source syntax, NFC.
Swift SVN r25951
2015-03-10 20:09:02 +00:00
Xi Ge
c0bf1f54ff [CodeCompletion] Further support the context-sensitivity of
auto-completing @attributes. By delaying the handling of code completion token after the entire decl being parsed, we know
what are the targets of the attribute to finishe, thus, only suggesting those applicable attributes.

Swift SVN r25938
2015-03-10 18:40:39 +00:00
Chris Lattner
c049068523 use Tok.isAny a bit more consistently in this file to simplify this code, NFC.
Swift SVN r25932
2015-03-10 17:03:18 +00:00
Chris Lattner
b63567e06e val got renamed to let, update internal function names. NFC.
Swift SVN r25931
2015-03-10 16:58:21 +00:00
Chris Lattner
db187f2183 Enhance VarPattern to capture a bit indicating whether the pattern was a var or let.
Previously we only used this information in the parser, but Sema needs to know as well.

NFC except in -dump-ast.



Swift SVN r25914
2015-03-10 06:07:56 +00:00
Xi Ge
32e9a0aca7 [CodeCompletion] Making the code completion of attributes
context-sensitive. The first step is to recommend parameter-applicable
attributes only when the code completion token is found inside a
param decl.

Swift SVN r25810
2015-03-06 23:20:17 +00:00
Doug Gregor
ac93e35b01 Address Chris's review comments on @autoclosure(escaping).
Swift SVN r25251
2015-02-12 21:20:59 +00:00
Doug Gregor
954b4e4d83 Implement @autoclosure(escaping).
Addresses rdar://problem/19499207.

Swift SVN r25249
2015-02-12 21:09:47 +00:00
Denis Vnukov
0d84be65de Fix for rdar://problem/19605567, Fuzzing Swift: abort() in Verifier::checkSourceRanges(...)
Correct start/end locations of constructor arguments and class body in erroneous scenarios.



Swift SVN r24769
2015-01-28 01:05:36 +00:00
Denis Vnukov
196d500439 Fix for rdar://problem/19563867, Fuzzing Swift: Parser::parseTopLevel() crashes in Verifier::walkToPatternPost(swift::Pattern*):
a vararg subpattern of a TuplePattern should be a TypedPattern

Check for a vararg subpattern to be a typed pattern seemed to be missing in closure arguments parsing.



Swift SVN r24733
2015-01-26 21:11:32 +00:00
Doug Gregor
b642c555be Allow one to change the argument labels of curried function parameters.
Curried function parameters (i.e., those past the first written
parameter list) default to having argument labels (which they always
have), but any attempt to change or remove the argument labels would
fail. Use the fact that we keep both the argument labels and the
parameter names in patterns to generalize our handling of argument
labels to address this problem.

The IDE changes are due to some positive fallout from this change: we
were using the body parameters as labels in code completions for
subscript operations, which was annoying and wrong.

Fixes rdar://problem/17237268.

Swift SVN r24525
2015-01-19 22:15:14 +00:00
Chris Lattner
407bad1445 remove @autoclosure as a type attribute. Recognize it in a parameter
list and produce a nice fixit, so that people using it have an obvious
upgrade path.


Swift SVN r24075
2014-12-22 20:14:56 +00:00
Chris Lattner
86c3c50157 Implement support for parsing declattrs on parameters. The only tricky
case is where there is no argument name, because declattrs and typeattrs
can be juxtaposed.



Swift SVN r24045
2014-12-19 23:42:12 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Doug Gregor
51c1433ddd Add magic "literal" __DSO_HANDLE__ to refer to the DSO handle.
__DSO_HANDLE__ can be used as a callee-side default
argument. Addresses rdar://problem/17878114.


Swift SVN r21440
2014-08-25 16:33:54 +00:00
Chris Lattner
61715b1da7 Remove some dead code: pattern parsing is now never used for argument lists,
so inout can't appear there and we don't need to propagate an "isArgumentList"
bool down through pattern parsing.  NFC.



Swift SVN r20835
2014-07-31 17:46:08 +00:00
Chris Lattner
bc2071a66f make 'inout' be a keyword, to match var and let.
Swift SVN r20829
2014-07-31 16:36:56 +00:00
Chris Lattner
a2beb62f85 fix <rdar://problem/16786168> Functions currently permit 'var inout' parameters
fix <rdar://problem/17867059> ` upgrade logic should be removed




Swift SVN r20817
2014-07-31 06:18:42 +00:00
Doug Gregor
ff92b5f007 Remove -[no]implicit-objc-with.
Toggling this option causes funny things to happen, and there's no
point in keeping it.

Swift SVN r20565
2014-07-25 22:13:46 +00:00
Doug Gregor
795f568898 Start diagnosing the use of '`' rather than '#', with a Fix-It.
<rdar://problem/16891828>.

Swift SVN r17982
2014-05-13 00:03:05 +00:00
Doug Gregor
1efd9fba5b Start accepting '#' in addition to '`' to mark a keyword argument <rdar://problem/16891828>.
Update the standard library, tests, diagnostics, and Fix-Its.

Swift SVN r17981
2014-05-13 00:03:04 +00:00
Argyrios Kyrtzidis
a5eeb9617a [Parser] Create ParamDecls even for unnamed parameters.
This preserves more of source info (e.g. API name location) and simplifies things since
we don't have to construct ParamDecls for the unnamed parameters later on.

Swift SVN r17828
2014-05-10 18:23:47 +00:00
Doug Gregor
ac579592a6 Complain about first keyword arguments in methods/initializers that start with "with".
... with Fix-Its to remove the "with", of course. Only do this under
-implicit-objc-with.

Swift SVN r17755
2014-05-09 01:40:52 +00:00
Argyrios Kyrtzidis
717966f579 [Parser] Emit error + fixit if 'inout' appears after the parameter.
Swift SVN r17518
2014-05-06 01:39:35 +00:00
Argyrios Kyrtzidis
dfa772de8b [AST] Set the source range of ParamDecl as the argument+parameter range and keep track of its parent pattern.
Swift SVN r17441
2014-05-05 15:14:31 +00:00
Chris Lattner
502e663e23 inline parsePatternIdentifier into its only caller, and simplify the result.
Swift SVN r17407
2014-05-04 23:14:15 +00:00
Doug Gregor
eb7a9144a8 Bring keyword arguments to subscripts.
Subscript declarations were still encoding the names of index
variables in the subscript type, which unintentionally made them
keyword arguments. Bring subscript declarations into the modern day,
using compound names to encode the subscript argument names, which
provides consistency for the keyword-argument world
<rdar://problem/14462349>. Note that arguments in subscripts default
to not being keyword arguments, which seems like the right default.

We now get keyword arguments for subscripts, so one can overload
subscripts on the names of the indices, and distinguish at the call
site. Under -strict-keyword-arguments, we require strictness here as well.

The IRGen/IDE/SILGen test updates are because the mangling of common
subscripts changed from accidentally having keyword arguments to not
having keyword arguments.

Swift SVN r17393
2014-05-04 19:31:09 +00:00
Chris Lattner
8f444a4a61 simplify some parsing logic by using Token::isIdentifierOrNone more,
and rearrange some closure parsing logic to tidy it up, NFC.


Swift SVN r17363
2014-05-04 04:42:53 +00:00
Doug Gregor
ca62675c64 Rip out the parsing code for default values in patterns.
This code was already unused.


Swift SVN r17091
2014-04-30 13:59:44 +00:00
Doug Gregor
d003b74c85 An argument with a default value has a keyword argument.
Arguments with default values are one of those places where you
really, really want keyword arguments: make that the default.


Swift SVN r17080
2014-04-30 06:51:43 +00:00
Doug Gregor
0863b2c6ec Operators may never have keyword arguments.
Swift SVN r17071
2014-04-30 04:35:02 +00:00
Doug Gregor
72e32c93af Make argument names default to keyword arguments in the cases where Objective-C has names.
Introduce a model where an argument name is a keyword argument if: 

  - It is an argument to an initializer, or
  - It is an argument to a method after the first argument, or
  - It is preceded by a back-tick (`), or
  - Both a keyword argument name and an internal parameter name are
    specified. 

Provide diagnostics Fix-Its to clean up cases where the user is
probably confused, i.e.,

  - "_ x: Int" -> "x: Int" where "x" would not have been a keyword
  argument anyway
  - "x x: Int" -> "`x: Int"

This covers the compiler side of <rdar://problem/16741975> and
<rdar://problem/16742001>.

Update the AST printer to print in this form, never printing just 
a type for a parameter name because we're also going to adopt
<rdar://problem/16737312> and it was easier to move the tests once
rather than twice.

Standard library and test updates coming separately.




Swift SVN r17056
2014-04-30 00:04:04 +00:00
Doug Gregor
7c8605e6b5 Diagnose use of _ after ` in a parameter declaration; it makes no sense.
Swift SVN r16992
2014-04-28 19:41:02 +00:00
Doug Gregor
2872287dcd Add support for marking function arguments with the back-tick ("`").
Part of <rdar://problem/16742001>. At the moment, this is just a
parsing thing, because argument names are still API by default
anyway.

Swift SVN r16991
2014-04-28 19:35:57 +00:00
Doug Gregor
4e4173f2e6 Remove the "separated" declaration syntax <rdar://problem/16742067>.
Swift SVN r16979
2014-04-28 14:44:53 +00:00
Dmitri Hrybenko
2c88cdfaa3 Fix a crash-on-invalid while parsing a function declaration
rdar://16643959


Swift SVN r16925
2014-04-27 13:57:46 +00:00
Chris Lattner
a9113d7c17 simplify some parsing logic now that function arguments don't have patterns.
Swift SVN r16896
2014-04-26 21:41:58 +00:00
Argyrios Kyrtzidis
6f357713b6 [Parser] Fix assertion hits when trying to print an invalid function.
Swift SVN r16674
2014-04-22 23:21:12 +00:00
Chris Lattner
b204be71cd simplify Parser::isStartOfStmt: just use the current token instead of having
all of the clients pass in the current token.  NFC.


Swift SVN r16601
2014-04-21 04:01:03 +00:00
Doug Gregor
1f4b73b93f Tricky selector-style parameter parsing into creating ParamDecls.
The selector-style parameter parsing code is going away "soon", but we
still need to prop it up a bit longer. Hence, I don't feel too bad
about the Parser-level state I'm using in this hack to make it happen.

With that change, we can now establish two important invariants in the
AST:
  - Only parameters (ParamDecl or GenericTypeParamDecl) can have their
  DeclContexts changed. Everything else comes into being in the
  correct context.
  - All of the parameters in a function/constructor/closure/etc. are
  described by ParamDecls, not just VarDecls.



Swift SVN r16593
2014-04-20 18:25:23 +00:00
Doug Gregor
89ef0af226 Switch subscript index parsing over to a parameter-clause.
Swift SVN r16586
2014-04-20 06:37:47 +00:00
Doug Gregor
997026c6ca Parse closure parameters as a parameter-clause rather than as a pattern.
This means we get ParamDecls rather than VarDecls. Additionally, we
parse both API names and parameter names, although the API names
aren't currently useful. As part of this, loosen up the tentative
parsing that disambiguates between a tuple and a closure
parameter-clause.


Swift SVN r16585
2014-04-20 06:22:12 +00:00
Doug Gregor
09797f7f99 Introduce a new declaration node, ParamDecl, for function parameters.
Use this node to capture the argument name and its source location in
the AST. We're only building these in one place at the moment; the
rest will be updated soon.


Swift SVN r16581
2014-04-20 05:23:35 +00:00
Doug Gregor
f2053e35ee Start rejecting selector-style declarations, with Fix-Its to tuple-style declarations.
Swift SVN r16455
2014-04-17 16:41:48 +00:00
Doug Gregor
ea647624e3 Eliminate the notion of "selector-style" declarations in the AST.
We still parse them, but the distinction is no longer meaningful
beyond the parsing stage.



Swift SVN r16445
2014-04-17 05:42:58 +00:00
Doug Gregor
8e597cc695 Eliminate argument parameter patterns.
Swift SVN r16444
2014-04-17 05:20:14 +00:00
Doug Gregor
2d70fbad63 Give initializers compound names.
Swift SVN r16404
2014-04-16 07:44:31 +00:00