Commit Graph

262 Commits

Author SHA1 Message Date
Doug Gregor
e12afa2e1d Start naming functions more uniformly.
For any function that has a name, ensure that the name is a compound
name with argument names for each of the parameters. 


Swift SVN r16398
2014-04-16 06:05:45 +00:00
Doug Gregor
86ecc725c9 Start building compound names for functions parsed with the new signature style.
Swift SVN r16394
2014-04-16 03:55:05 +00:00
Doug Gregor
18bf604360 Distinguish betweeen simple names ("foo") and zero-argument compound names ("foo()").
This isn't actually used yet, but it's an important distinction.

Swift SVN r16326
2014-04-14 20:05:34 +00:00
Doug Gregor
c1e41584dd Parse the new function syntax for initializers.
Extend parsing of the new function syntax, where both the argument
(API) and parameter (internal) name are specified prior to the colon,
to initializers.


Swift SVN r16311
2014-04-14 14:19:53 +00:00
Dmitri Hrybenko
f90e0c153b Make 'override' a keyword
rdar://16462192

Swift SVN r16115
2014-04-09 14:19:50 +00:00
Dmitri Hrybenko
3d404e3749 Remove dead argument parsing code
Swift SVN r16051
2014-04-08 08:28:37 +00:00
Doug Gregor
6da952e798 Parse the new function syntax.
Parse the new function syntax, which allows both the argument (API)
and parameter (internal) name to be specified prior to the colon
within each parameter. Don't re-use the existing pattern-parsing
logic. Rather, implement a new (far simpler) parser for this purpose,
then map from its simple data structures to ArgParams and BodyParams
as we're used to.

There are a number of caveats here:
  - We no longer have the ability to use patterns for parameters in
  function declarations. The only place this really has an impact is
  that it makes the ~> hack in the standard library even uglier.
  - This exposed some issues with code completion with generic
  parameters that need to be investigated.
  - There's still some work to be done to improve recovery when things
  parse poorly within a parameter list; there are some XFAILs to deal
  with that.

I'll address the last two issues with follow-up commits.

Swift SVN r15967
2014-04-05 00:21:06 +00:00
Doug Gregor
527b147ba7 Revert "Allow the first name of a selector-style function declaration to be separated."
This reverts r15140.

Conflicts:
	include/swift/Serialization/ModuleFormat.h
	lib/Parse/ParsePattern.cpp

Swift SVN r15846
2014-04-02 23:27:52 +00:00
Doug Gregor
9189145cc5 Change DeclName over to basename(arg1:arg2:...argN:).
Swift will use the basename + argument names formulation for
names. Update the DeclName interfaces, printing, and __FUNCTION__ to
use the method syntax.

We'll still need to rework the "x.foo:bar:wibble:" syntax; that will
come (significantly) later.

Swift SVN r15763
2014-04-02 00:00:03 +00:00
Joe Pamer
cbc69bc8ee Restrict use of default arguments on protocol method signatures.
We were never handling this correctly, and default arguments are checked along with the method body.
In some cases where no further validation was necessary (such as when the default argument was a literal value),
the compiler would let this slip through but in others this would cause a crash.  (rdar://problem/16476405)

Swift SVN r15736
2014-04-01 16:53:21 +00:00
Joe Groff
4fdc20f739 Allow '<pattern> as T' checked patterns with subpattern bindings.
Allow a form of 'case is T' that matches the cast result to a subpattern, 'case <pattern> as T'. This exposes an issue in switch destructuring with casting into complex class hierarchies <rdar://problem/16401831> but works for common cases.

Swift SVN r15396
2014-03-24 00:02:44 +00:00
Chris Lattner
6f1bd416eb implement <rdar://problem/16393849> Closures cannot define variable parameters: closure exprs parsing patterns as tuple-types
we were previously lookahead parsing the argument list of a closure 
literal as a tuple-type, when we should be doing so as a tuple-pattern.
This doesn't permit some pattern stuff, such as var/let on arguments.

Implement pattern parsing lookahead and use it.


Swift SVN r15350
2014-03-21 23:26:46 +00:00
Argyrios Kyrtzidis
286927effa [Parser] Fix source range for an incomplete function that has no open paren.
Swift SVN r15182
2014-03-18 05:31:28 +00:00
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