Commit Graph

349 Commits

Author SHA1 Message Date
Doug Gregor
5e8e7279f8 Allow the first name of a selector-style function declaration to be separated.
Parse function declarations with the form

  func murder inRoom(room: Int) weapon(Int) {}

where the function name ("murder") is separated from the parameter
names. This is the same style used in initializers, i.e.,

  init withCString(cstr: CString) encoding(Encoding)



Swift SVN r15140
2014-03-17 16:04:21 +00:00
Doug Gregor
8cabdb817f Fix two crashers involving inheritance of invalid designated initializers.
Swift SVN r15066
2014-03-14 20:26:37 +00:00
Doug Gregor
8cf018a1d2 Give Pattern::clone() an OptionSet rather than a bool; it's going to get more interesting.
Swift SVN r15061
2014-03-14 18:31:21 +00:00
John McCall
a9443d72f8 Parse attributes as part of <type> and simplify the grammar.
This means that we accept type attributes in a much broader
range of places where we previously required a <type>.  <type>
was already a production that demanded a grammatically
unconstrained context because of all the possible continuations;
reducing the number of independent productions makes it easier
to choose one and thus not accidentally limit the range of
possible types parsed.

In particular, we want to be able to parse @unchecked T? pretty
much anywhere you can write a type.

Swift SVN r14912
2014-03-11 07:59:22 +00:00
Joe Groff
96c09d7179 Renovate name lookup to prepare for compound name lookup.
Make the name lookup interfaces all take DeclNames instead of identifiers, and update the lookup caches of the various file units to index their members by both compound name and simple name. Serialized modules are keyed by identifiers, so as a transitional hack, do simple name lookup then filter the results by compound name.

Swift SVN r14768
2014-03-07 03:21:29 +00:00
Joe Groff
2448f33ffc Parser: Record the compound name of selector-style func decls.
Collect the identifiers for the selector pieces we parsed and use them to build a compound DeclName for the func decl. Currently this only manifests when __FUNCTION__ is used inside a selector-style function definition, where we now correctly produce the compound 'foo:bar:' name.

Swift SVN r14717
2014-03-06 03:36:49 +00:00
Joe Groff
9e5bc637ae Add __FUNCTION__ as a magic literal identifier.
Add __FUNCTION__ to the repertoire of magic source-location-identifying tokens. Inside a function, it gives the function name; inside a property accessor, it gives the property name; inside special members like 'init', 'subscript', and 'deinit', it gives the keyword name, and at top level, it gives the module name. As a bit of future-proofing, stringify the full DeclName, even though we only ever give declarations simple names currently.

Swift SVN r14710
2014-03-06 01:06:06 +00:00
Chris Lattner
c16db63ae7 switch "val" to "let" in in the ASTPrinter, unbreaking tests.
Produce a warning + fixit for uses of 'val'.


Swift SVN r14435
2014-02-27 00:32:17 +00:00
Chris Lattner
1344319677 Rename the internal compiler lexicon from val -> let.
Swift SVN r14408
2014-02-26 21:21:18 +00:00
Dmitri Hrybenko
44de02f14b Rename a function not to mention 'let', since it was renamed to 'val'
Swift SVN r14149
2014-02-20 14:12:33 +00:00
Chris Lattner
28903887e7 Rename the internal compiler lexicon from let -> val.
Swift SVN r13992
2014-02-17 16:48:21 +00:00
Doug Gregor
45ca5fe987 Use whitespace indentation to detect selector-style call continuations.
Implement several rules that determine when an identifier on a new
line is a continuation of a selector-style call on a previous line:

  - In certain contexts, such as parentheses or square brackets, it's
    always a continuation because one does not split statements in
    those contexts;

  - Otherwise, compare the leading whitespace on the line containing
    the nearest enclosing statement or declaration to the leading
    whitespace for the line containing the identifier.

The leading whitespace for a line is currently defined as all space
and tab characters from the start of the line up to the first
non-space, non-tab character. Leading whitespace is compared via a
string comparison, which eliminates any dependency on the width of a
tab. One can run into a few amusing cases where adjacent lines that
look indented (under some specific tab width) aren't actually indented
according to this rule because there are different mixes of tabs and
spaces in the two lines. See the bottom of call-suffix-indent.swift
for an example.

I had to adjust two test cases that had lines with slightly different
indentation. The diagnostics here are awful; I've made no attempt at
improving them.



Swift SVN r13843
2014-02-12 22:50:50 +00:00
Chris Lattner
6072e1d40d parse the 'val' keyword. For now it is a synonym for let. I will rip
'let' out (and continue migrating terminology in the compiler) as an
ongoing project.


Swift SVN r13821
2014-02-12 06:29:15 +00:00
Chris Lattner
e1632555a4 add a missing case, that broke the stdlib build.
Swift SVN r13816
2014-02-12 06:06:15 +00:00
Chris Lattner
0695fcea12 improve diagnostic about missing ) in parameter list to use the phrase
"parameter list" instead of "tuple argument".  Fix a potential crash I 
introduced by making an assumption about default initialized implied name
parameters being the only thing in parens.


Swift SVN r13813
2014-02-12 05:46:46 +00:00
Chris Lattner
b2a4952908 Fix <rdar://problem/16034148> swift incorrectly rejects destructuring argument
Swift SVN r13812
2014-02-12 05:22:16 +00:00
Chris Lattner
41bff7d5b5 fix <rdar://problem/16030644> Implicit parameter names in selector-style functions don't support default values
This also fixes 'inout' in implied name arguments as well.


Swift SVN r13811
2014-02-12 05:06:00 +00:00
Chris Lattner
c57b0d25b7 Implement <rdar://problem/16021869> the first portion of a function selector should allow implicit arg names
This allows us to use implicit names in protocols and asm name functions, as well
as for the first chunk of selectors.  This feature is particularly useful for
delegate methods.



Swift SVN r13751
2014-02-10 17:39:57 +00:00
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