581 Commits

Author SHA1 Message Date
Chris Lattner
2e898da8e7 remove the ban on selectors that have selector chunks with the same name. As
long as the inner argument names are unique, the different chunks can be referred
to in the definition.  There is still some problem with calling these, but that
will be resolved by declaration based invocation rules when they are available.


Swift SVN r13750
2014-02-10 17:09:51 +00:00
Chris Lattner
d6729baba3 refactor some argument parsing logic out to a new parseArgument function,
and generalize it to work with nameless selector chunks.  foo:: is allowed
to ignore the second argument name if it wants to :-)



Swift SVN r13749
2014-02-10 16:43:29 +00:00
Chris Lattner
62244c409f peel the first iteration of the parsing loop, it is special.
Swift SVN r13748
2014-02-10 16:30:21 +00:00
Chris Lattner
fb3ae2aaff rework argument parsing to pull curried argument parsing into the main loop.
Swift SVN r13747
2014-02-10 16:09:51 +00:00
Chris Lattner
201e1d9bf9 refactor parseExpr a bit: rename parseExpr to parseExprImpl and change
clients to either go through the new parseExpr (which is never "basic")
or the existing parseExprBasic entrypoint if they don't want trailing
closures.


Swift SVN r13724
2014-02-09 22:36:06 +00:00
Chris Lattner
55fee7a763 simplify some code by creating a ParenPattern directly instead of using
TuplePattern::createSimple.  Also, mark the namedpattern implicit, since
it is.  Add an example of rdar://15993514 using non-trivial types.

NFC.


Swift SVN r13695
2014-02-09 05:16:52 +00:00
Chris Lattner
3dc956e196 Implement <rdar://problem/15993514> Enhance method declaration syntax to be less redundant
and add it to the release notes.  Now you can elide the name on the second (or later) selector
chunk in a func declaration, and it gets implicitly named the same as the selector chunk.

This requires a speculative parse in the general case, but in the common cases
we don't need that.



Swift SVN r13691
2014-02-09 02:52:55 +00:00
Dave Zarzycki
1e3fd1a5b1 Parser: allow '...' to be an operator for ranges
<rdar://problem/16018151> Allow me to declare an operator spelled "..."

Swift SVN r13670
2014-02-08 02:10:37 +00:00
Chris Lattner
ee0986fa9e introduce a new TypeRepr to represent "inout" in the argument list to a
function.  Parse inout as a contextual keyword there, shoving it into the
TypedPattern (instead of introducing a new kind of Pattern).  This enables
us to parse, sema, and irgen the new '@-less' syntax for inout.


Swift SVN r13559
2014-02-06 04:31:13 +00:00
Dmitri Hrybenko
33bb1fb7e7 Fix code completion for function declaration with 'var' and 'let' parameters
Swift SVN r13433
2014-02-04 16:20:26 +00:00
Dmitri Hrybenko
e4a9ada5ca Unbreak code completion of types in selector-style function declarations
(broken since r12321)


Swift SVN r13432
2014-02-04 14:56:55 +00:00
Chris Lattner
cc31c6edb5 remove the '-enable-let-arguments' staging option.
Swift SVN r12374
2014-01-16 01:29:14 +00:00
Chris Lattner
e15de8ae71 Rework getFirstSelectorPattern to use the new rebuildImplicitPatternAround
function, which is fully general w.r.t. different pattern structures that can
happen in the first argument of a selector-style function.  Notably, this
handles VarPatterns, so we can now use var/let in selector-style functions,
resolving rdar://15814933.


Swift SVN r12322
2014-01-15 07:30:43 +00:00
Chris Lattner
642afebd62 Reimplement selector parsing logic to use parsePatternTuple instead of
substantially reimplementing it.  AFAICT, this was duplicated out because
we need to build two parallel patterns: one for the argument pattern and
one for the body pattern.  Instead of building these in parallel, just parse
the body pattern as normal, then use a simple ASTWalker to rerewrite a clone
of the body pattern for the argument context.

One bad thing about this patch is that it changes code completion within the
type portion of a selector-style argument list.  I don't understand this well
enough to know how to fix it, so I disabled the test for now and will follow
up offline with smart people that know this stuff.

This is required (but not sufficient) to resolve rdar://15814933.


Swift SVN r12321
2014-01-15 07:13:26 +00:00
Chris Lattner
b0b5a8f774 Switch constructor arguments, curried arguments and selector arguments to be
'let' values (so they are immutable and don't get a box, etc).  Add a flag to
the swift compiler that turns the bulk of function arguments into lets, but 
don't set it yet.


Swift SVN r12274
2014-01-14 03:53:11 +00:00
Doug Gregor
9412c07dea Switch 'static' to 'type' in tests.
Switch some diagnostic text from 'static' over to 'type' to make
things easier, and fix up some parsing issues with selector-style
declarations found by doing this. NFC


Swift SVN r12030
2014-01-08 01:37:32 +00:00
Chris Lattner
468ead25a6 allow 'var' and 'let' to appear in patterns (not just matching patterns).
This allows them to appear in argument lists of functions, enabling behavior
like this:

func test_arguments(a : Int, var b : Int, let c : Int) {
  a = 1  // ok (for now).
  b = 2  // ok.
  c = 3  // expected-error {{cannot assign to the result of this expression}}
}



Swift SVN r11746
2013-12-30 21:48:06 +00:00
Chris Lattner
6a8b1a40ef rename Parser::parseMatchingPatternIsa -> parseMatchingPatternIs
and Parser::parseMatchingPatternVar -> parseMatchingPatternVarOrLet

to better reflect what they are.


Swift SVN r11744
2013-12-30 21:17:42 +00:00
Chris Lattner
1a3ff1e9b2 implement 'let' pattern bindings.
Swift SVN r11199
2013-12-12 19:16:06 +00:00
Chris Lattner
65aa09d464 implement support for let declarations.
Swift SVN r11195
2013-12-12 18:33:42 +00:00
Chris Lattner
03518d240f revert r11192, I accidentally included too much in the patch.
Swift SVN r11193
2013-12-12 18:24:33 +00:00
Chris Lattner
778225eb96 Implement let declarations.
Swift SVN r11192
2013-12-12 18:22:46 +00:00
John McCall
342a8b35db Parse default-argument expressions in an initializer context.
Swift SVN r11178
2013-12-12 03:36:27 +00:00
Chris Lattner
b1a2059604 Implement the ability to create a Pattern as a set of 'let' decls instead of
var decls.  I was originally intending to use this for argument lists, but I
don't think that's a great direction to go anymore.

In any case, it seems uncontroversial to enforce immutability on foreach
enumation patterns, so I did that (see testcase)



Swift SVN r11124
2013-12-11 07:28:13 +00:00
Chris Lattner
698380d6d3 Introduce a new bit in VarDecl, "isLet". Teach Sema that 'isLet' properties
are not settable (like get-only ones).  Set the 'isLet' bit in various 
places, but not the particularly interesting or useful places yet.



Swift SVN r11121
2013-12-11 06:45:40 +00:00
Joe Groff
4f2adbe7ed AST: Include 'static' bit in VarDecls.
And track the 'static' SourceLoc in the PatternBindingDecl. This lets isInstanceMember return the right thing for static vars.

Swift SVN r10369
2013-11-12 06:16:48 +00:00
Dmitri Hrybenko
e2b0f08f57 Parser: allow an optional trailing comma in array and dictionary literals
rdar://14874038


Swift SVN r9567
2013-10-21 23:13:22 +00:00
Chris Lattner
9f439292b6 Implement support for type-attributes on the result of a function type or decl.
Also, improve error recovery for new-syntax attributes.

This means that we now compile the testcase into:

t.swift:3:16: error: unknown attribute 'xyz'
var x : () -> @xyz Int
               ^
t.swift:6:16: error: unknown attribute 'xyz'
func foo() -> @xyz Int {
               ^

instead of:

t.swift:4:15: error: expected type for function result
func foo() -> @xyz Int {
              ^
t.swift:4:14: error: consecutive statements on a line must be separated by ';'
func foo() -> @xyz Int {
             ^
             ;
t.swift:4:16: error: unknown attribute 'xyz'
func foo() -> @xyz Int {
               ^
t.swift:7:1: error: expected declaration

^

this is part of rdar://15183765


Swift SVN r9260
2013-10-12 21:27:16 +00:00
Dmitri Hrybenko
3628d6c4d6 Parser: recover when a keyword was used as an identifier in a pattern
Swift SVN r8883
2013-10-03 18:24:58 +00:00
Joe Groff
3b0180b1b0 Allow '_' in assignments again.
Parse '_' as a DiscardAssignmentExpr. Type-check it as an lvalue, and check that it only appears in the LHS of AssignExprs. During matching pattern resolution, convert it into an AnyPattern. In SILGen, when we see '_' in the LHS of an assignment, ignore the corresponding RHS rvalue.

Swift SVN r8848
2013-10-02 18:43:20 +00:00
Argyrios Kyrtzidis
097d9a0d0e When we have selector-style syntax for functions, make the argument patterns implicit.
Argument patterns create pseudo-named patterns, so make them implicit and ignore them when scanning for explicit source information.
Also make sure that the clang importer sets the HasSelectorStyleSignature bit appropriately.

Swift SVN r8803
2013-10-01 15:37:46 +00:00
Argyrios Kyrtzidis
7205b7df0b [Parser] Some refactoring inside parseSelectorArgument(), no functionality change.
Swift SVN r8802
2013-10-01 15:37:44 +00:00
Argyrios Kyrtzidis
bedc40ed82 [Parser] Make sure VarDecls created for UnresolvedPatternExprs have a DeclContext.
Swift SVN r8765
2013-09-29 00:12:24 +00:00
Argyrios Kyrtzidis
b955d8e134 [Parser] Adjust the end source locations in a few places.
Swift SVN r8728
2013-09-27 17:24:33 +00:00
Dmitri Hrybenko
10d8fdc64f AST/AbstractFunctionDecl: Remember if a function had a selector-style signature
... and use this information in AST printing


Swift SVN r8583
2013-09-24 00:56:33 +00:00
Doug Gregor
62e84f59e4 s/constructor/initializer in diagnostics
Swift SVN r8506
2013-09-20 18:59:22 +00:00
Doug Gregor
e52687f6ee Use "initial value" rather than "initializer" in diagnostics.
Swift SVN r8505
2013-09-20 18:45:15 +00:00
Dmitri Hrybenko
0aaceb3878 Parser: improve error recovery in case of a bad function signature with selector-style arguments
We used to skip until the end of the file in two of these cases.
Looks like plain skipUntil() is never the correct tool for recovery.


Swift SVN r8441
2013-09-19 02:24:59 +00:00
Dmitri Hrybenko
667969602b Code completion: implement completion of types in constructor parameter lists
Swift SVN r8439
2013-09-19 00:56:12 +00:00
Dmitri Hrybenko
d3bfad83bd Parser: simplify code
Swift SVN r8384
2013-09-18 02:01:39 +00:00
Doug Gregor
90b8b3e499 Constructor selectors always start with 'init'.
Implement the new rules for mapping between selector names and
constructors. The selector for a given constructor is formed by
looking at the names of the constructor parameters:
  * For the first parameter, prepend "init" to the parameter name and
  uppercase the first letter of the parameter name. Append ':' if
  there are > 1 parameters or the parameter has non-empty-tuple type.
  * For the remaining parameters, the name of each parameter followed
  by ':'.

When a parameter doesn't exist, assume that the parameter name is the
empty string.

And, because I failed to commit it separately, support selector-style
declarations of constructor parameters so that we can actually write
constructors nicely, e.g.:

  // selector is initWithFoo:bar:
  constructor withFoo(foo : Foo) bar(bar : Bar) { ... }



Swift SVN r8361
2013-09-17 22:49:05 +00:00
Dmitri Hrybenko
935d494f90 Mark the diagnostic for missing function return type as PointsToFirstBadToken
and use it in func decl parsing instead of the generic 'expected type'
diagnostic


Swift SVN r7996
2013-09-06 20:33:40 +00:00
Dmitri Hrybenko
bdba280e52 Parser: add a fixit for the case when ':' was used instead of '->' to specify
the function return type

rdar://11266221


Swift SVN r7930
2013-09-05 00:32:44 +00:00
Dmitri Hrybenko
734fe3120d parseDeclFunc(): sink error recovery for bad signature into
parseFunctionSignature() and add more tests


Swift SVN r7922
2013-09-04 23:02:24 +00:00
Dmitri Hrybenko
7ada2781a2 Remove an unused diagnostic and improve diagostic wording
Swift SVN r7870
2013-09-03 22:11:16 +00:00
Dmitri Hrybenko
53652960a6 Make 'self' and 'Self' real keywords.
Also, remove IDENTIFIER_KEYWORD macro because these two were the last
identifier keywords.


Swift SVN r7806
2013-08-30 22:07:47 +00:00
Dmitri Hrybenko
44e8296f7f Make 'weak' and 'unowned' real keywords
Swift SVN r7802
2013-08-30 21:29:50 +00:00
Dmitri Hrybenko
e378af3c37 Make 'metatype' a normal keyword
Swift SVN r7801
2013-08-30 21:22:10 +00:00
Dmitri Hrybenko
1500410290 Make 'super' a normal keyword
Swift SVN r7775
2013-08-30 01:40:18 +00:00
Dmitri Hrybenko
35ceac419d Code completion: ensure we don't try to complete the identifier in pattern-atom
Swift SVN r7555
2013-08-24 03:47:05 +00:00