Commit Graph

268 Commits

Author SHA1 Message Date
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
Dmitri Hrybenko
4a3c36f87c Selector-style function parsing: try harder to recover
Fixes two code completion tests.


Swift SVN r7445
2013-08-22 01:08:29 +00:00
Dmitri Hrybenko
ec7b2eb3db Parser: use ParserResult in the interface of parseExpr()
But the implementation of expression parsing still does not propagate the code
completion bits because it uses NullablePtr for results.


Swift SVN r7425
2013-08-21 21:10:09 +00:00
Dmitri Hrybenko
c79bb3204c parsePattern(): try harder to recover. Fixes a code completion test case
Swift SVN r7397
2013-08-21 01:04:11 +00:00
Dmitri Hrybenko
aefbf9db99 Parser: fix diagnostic regression from r7387
Swift SVN r7396
2013-08-21 00:38:11 +00:00
Dmitri Hrybenko
354c5f4a18 Parser: replace diagnose(Tok.getLoc(), ...) -> diagnose(Tok, ...)
We already had the Parser::diagnose(Token, ...) overload, but it was not used
in all these cases.


Swift SVN r7395
2013-08-21 00:26:30 +00:00
Dmitri Hrybenko
dc43b10a40 Fix indentation
Swift SVN r7393
2013-08-21 00:13:17 +00:00
Dmitri Hrybenko
581db767bf Use ParserResult and ParserStatus in tuple and function argument parsing
This finally fixes a few code completion test cases.

This also regresses the error message in one parsing testcase because
previously we would just happily skip those tokens, but now error handling path
is a little bit different and these tokens hit different error handling code.
This can be fixed by parsing a tuple for the selector argument and complaining
if the tuple had more than one element.


Swift SVN r7389
2013-08-20 23:55:00 +00:00
Dmitri Hrybenko
b0dd877454 Use ParserResult in type parsing
Swift SVN r7353
2013-08-20 01:19:31 +00:00
Dmitri Hrybenko
c098cd1476 Parser: convert some pattern parsing functions to ParserResult
Swift SVN r7336
2013-08-19 22:38:34 +00:00
Dmitri Hrybenko
19a90b69f7 Parser: add ParserResult<T> -- a wrapper around the AST node plus extra bits
This allows the parser to recover, create an AST node, return it to the caller
*and* signal the caller that there was an error to trigger recovery in the
caller.  Until now the error was signalled with a nullptr result (any non-null
result was considered a success and no recovery was done in that case).

This also allows us to signal the caller if there was a code completion token
inside the production we tried to parse to trigger delayed parsing in the
caller while doing recovery in the callee.  Until now we could not do recovery
in the callee so that the caller could find the code completion token.

Right now we don't take any advantage of these features.  This commit just
replaces some uses of NullablePtr with ParserResult.


Swift SVN r7332
2013-08-19 22:11:23 +00:00
Dmitri Hrybenko
4ed9594310 Parser / code completion: don't stop on a parse error when parsing function
parameters.  If we see an arrow, try parsing the result type.


Swift SVN r7315
2013-08-17 03:04:23 +00:00
Argyrios Kyrtzidis
015c1a892b Refactor Parser methods to return TypeReprs directly, instead of modifying TypeLocs.
Swift SVN r6328
2013-07-17 14:57:40 +00:00
Doug Gregor
423abc5038 Codify the default argument hack for __FILE__/__LINE__/__COLUMN__.
Teach TuplePatternElt to keep track of the kind of the default
argument: none, normal (provided by calling into the appropriate
callee generator), __FILE__, __LINE__, or __COLUMN__. For the latter
three cases, the type checker forms the appropriate argument as part
of the call. 

The actual default argument expression will only be held in the tuple
pattern element when we've parsed it; it won't be serialized or
deserialized, because only the defining module cares. This is a step
toward eliminate the initialization expression from tuple types.

The extension to TupleShuffleExpr is a hack, which will also be
replicated in ScalarToTupleExpr, until we finally rework the
representation of TupleShuffleExpr (<rdar://problem/12340004>).


Swift SVN r6299
2013-07-16 22:52:38 +00:00