Commit Graph

541 Commits

Author SHA1 Message Date
Chris Lattner
d2a604ab66 Remove trailing closure parsing from 'parseExprCallSuffix'. This is
leftovers from one of the old selector syntaxes.  The general expression
suffix parsing loop handles trailing closures in a superset of the cases
that this code does.  NFC.


Swift SVN r17604
2014-05-07 05:30:00 +00:00
Chris Lattner
fcb3b0e98c Rework capture list parsing and generalize it. Now the preparse is
much fuzzier, and the real parse is stricter.  Also, generalize this
to support the full "unowned name = expr" syntax in the capture list.

There is still a lot missing here.



Swift SVN r17499
2014-05-05 23:53:53 +00:00
Chris Lattner
0bab49db70 use consumeIdentifier a bit more to simplify parser logic, NFC.
Swift SVN r17452
2014-05-05 16:32:14 +00:00
Chris Lattner
d230228cdd store the capture list of a ClosureExpr in the AST and print it out
in the AST dumper.


Swift SVN r17451
2014-05-05 16:25:33 +00:00
Chris Lattner
1262105e61 Start parsing capture lists in closure expressions. Still much work
to go.



Swift SVN r17367
2014-05-04 05:39:22 +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
Ted Kremenek
4e70269c53 More renaming 'unchecked optional' to 'implicitly unwrapped optional'.
Swift SVN r17236
2014-05-02 06:22:01 +00:00
Ted Kremenek
050fd53af7 Rename UncheckedOptional to ImplicitlyUnwrappedOptional.
Swift SVN r17232
2014-05-02 06:13:57 +00:00
Doug Gregor
3d3ff6811a Add a pile of missing #includes exposed by pruning includes in top-of-tree LLVM.
Swift SVN r17157
2014-05-01 14:26:34 +00:00
Doug Gregor
9cfb1b5ca4 Keep track of the locations of the element names in a TupleExpr.
As part of this, use tail allocation to reduce the memory footprint of
TupleExprs. Use factory methods to make it easier to construct.

I'll be using this information in a follow-on patch. SourceKit
probably wants it as well.


Swift SVN r17129
2014-05-01 00:16:36 +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
Chris Lattner
db876399ad create a helper function for creating a TypeExpr from a
specialized declref, factoring some code.  NFC


Swift SVN r17021
2014-04-29 05:33:32 +00:00
Chris Lattner
30915de98f Form TypeExprs for non-specialized unqualified declrefs that refer to types... like "Int".
Building on previous work, this allows us to properly handle things like Int?() and Int[]().

Of course doing this exposed that TypeExpr was not correct in lots of ways, so this also:
 - Revamps TypeExpr processing to carry a decl in the TypeLoc instead of 
   carrying a Type.  This allows us to correctly handle more complex generics case.  
 - Enhances CSGen to properly open generic types so we can infer generic type parameters from
   context.


Swift SVN r17019
2014-04-29 05:25:21 +00:00
Chris Lattner
c45e6b75fd Rip out logic added to me misunderstanding ExistentialMetatypeType,
and teach type checking to resolve TypeExprs that lack TypeReprs.

This gets us debugged enough to start shoving all local type references
down the TypeExpr path, which is significant progress.


Swift SVN r16958
2014-04-28 04:42:44 +00:00
Ted Kremenek
6caf910d32 Implement new syntactic sugar for UncheckedOptional<T>.
This leaves in the existing syntax for @unchecked T?.  That will
be addressed in later patches.

There's still a mysterious case where some of the SIL output
includes UncheckedOptional<T> and some places T!.

Moreover, this doesn't handle SourceKit's behavior for printing
for overrides.  This just handles parsing the 'T!' syntax.

Swift SVN r16945
2014-04-27 21:59:29 +00:00
Dmitri Hrybenko
fe185d78d3 Parser: rework dictionary literal parser not to rely on skipUntil
Swift SVN r16752
2014-04-24 11:14:51 +00:00
Doug Gregor
57b2146c0b Remove the separated call syntax.
We had our transition path, and now it's time to kill it because it's
causing problems <rdar://problem/16672558>.

Amusing note: the SILGen test change is actually an improvement. We
weren't rebinding self when performing initializer delegation with the
separated call syntax.

Swift SVN r16707
2014-04-23 18:20:34 +00:00
Dmitri Hrybenko
98c63bae08 Code completion: propagate code completion bits at top-level better
rdar://16688622


Swift SVN r16697
2014-04-23 10:42:49 +00:00
Chris Lattner
78e8d3f0a9 rename the MetatypeExpr AST node to DynamicTypeExpr now that it is only
used by the "foo.dynamicType" syntax.


Swift SVN r16658
2014-04-22 20:10:11 +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
40b2c9f7a4 Create ParamDecls for function parameters in more places.
Swift SVN r16584
2014-04-20 05:57:34 +00:00
Joe Groff
4904dd1385 Parser: Don't crash when a dictionary literal doesn't parse in its first pair.
Recover by skipping to the closing bracket and returning ErrorExpr instead. Fixes <rdar://problem/16226567>.

Swift SVN r16558
2014-04-19 00:17:08 +00:00
Ted Kremenek
d77515264f Revert "Add sugar syntax for @unchecked T?: T!"
Some discussion points about this patch were raised on swift-dev.
Reverting for now until those are sorted out.

Swift SVN r16497
2014-04-18 05:28:15 +00:00
Ted Kremenek
1a8e1b8a9c Add sugar syntax for @unchecked T?: T!
There is ambiguity in the grammar in the case of 'X as T', where
a '!' following the type 'T' indicates a forced cast.  In this case
we do not parse the '!' as indicating @unchecked optional.

This patch also does not change the pretty-printing of @unchecked T?.
That can come in latter patches as it is clear where the sugared
version should be used.

In the REPL, we see:

(swift) let x : Int! = 42
// x : @unchecked Int?

Part of <rdar://problem/16579799>.

Swift SVN r16493
2014-04-18 04:54:22 +00:00
Dmitri Hrybenko
70ed107d69 Code completion: extend the hack to complete function call patterns after left
paren to work with method calls on AnyObject and curried function calls


Swift SVN r16412
2014-04-16 13:42:55 +00:00
Dmitri Hrybenko
236c581de7 Code completion: complete "?.member" on T?, and ".member" on @unchecked T?
In order for Xcode to use these completions, we complete "?.member" when the
user has typed "anOptional.", but we also say that in order to apply this
result, N bytes to the left of the cursor should be erased first.

rdar://16579657 rdar://15233283


Swift SVN r16409
2014-04-16 10:50:14 +00:00
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
Dmitri Hrybenko
da41b2e766 Code completion: provide results for initializers after the left paren:
class A {
    init(a: Int) {}
  }
  A(#^HERE^#

In its current state, this is a hack that I am not proud of.  There is
potential here to provide such completions for all function calls:

  class A {
    func foo(a: Int) {}
    func foo(a: Double) {}
  }
  A().foo(#^HERE^#

but this requires code completion doing its own name lookup, since the type
checker will give us an error type due to ambiguity of overloaded functions.

Type checker also sometimes gives up in cases like these:

  struct A {
    func foo() {}
  }
  A().foo

which is understandable, since we disallow partial applications of functions on
values, but returning the correct type here is useful for code completion.

rdar://16597372


Swift SVN r16367
2014-04-15 12:05:05 +00:00
Argyrios Kyrtzidis
3de7e8d5af [Parser] Fix crash with invalid code.
rdar://16601779

Swift SVN r16286
2014-04-13 21:09:36 +00:00
Doug Gregor
e418e93511 Start cleaning up method name importing.
Import a selector into a Swift method name, performing splitting at
that point. Use the resulting method name to determine the argument
names of the parameters, rather than trying to chop up the selector
again. There's more refactoring to do here.

This fixes a longstanding bug where the first argument of an
Objective-C method got the internal parameter name when it should
have gotten no name at all.

Swift SVN r15850
2014-04-03 00:34:40 +00:00
Doug Gregor
37a4ce2227 Produce an error with Fix-Its for the "separated" call syntax.
We are removing this syntax. To stage the move, first error with
Fix-Its to rewrite to the keyword-argument syntax. In a week or so,
we'll remove all of the code supporting the "separated" call syntax.

Swift SVN r15833
2014-04-02 21:34:27 +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 Groff
45eadd1d9b Rename AddressOfExpr to InOutExpr.
The "address" is an implementation detail; formally, it turns an lvalue into an inout parameter.

Swift SVN r15458
2014-03-25 16:28:28 +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
Joe Groff
5acb661fee Parse: Allow binary operator chains to extend past 'as' or 'is'.
Continue parsing operators after 'as <type>' or 'is <type>', which allows cast chains like 'x as Derived! as Base' or '1 as UInt8 + x' without parens, finishing <rdar://problem/15640006>.

Swift SVN r15357
2014-03-22 01:09:03 +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
Joe Groff
d75eeb61d5 Parser: Accept 'x as T!' as a synonym for '(x as T)!'.
Look for a postfix '!' after an 'as' production, and if we see it, carry it along in the CheckedCastExpr so we can wrap the cast in a ForceValueExpr once sequence folding resolves the LHS of the cast. Implements part of <rdar://problem/15640006>.

Swift SVN r15307
2014-03-21 00:18:26 +00:00
John McCall
486463a398 Track the depth of a BindOptionalExpr.
Swift SVN r15210
2014-03-18 22:57:34 +00:00
Joe Pamer
7ff7c73775 Add missing null check when parsing subscript expressions.
Swift SVN r15092
2014-03-14 23:24:10 +00:00
Chris Lattner
7adbe981e9 implement <rdar://problem/14524409> Support empty collection literals when context provides type information
These are spelled as [] and [:] for empty array and dictionary, respectively.



Swift SVN r15020
2014-03-14 00:37:45 +00:00
Joe Groff
b8d48dd7bb Change 'x.type' to 'x.dynamicType'.
It's not a common operation, so it doesn't need a terse name that occupies valuable identifier real estate.

Swift SVN r14932
2014-03-11 23:18:33 +00:00
Joe Groff
1585b625f9 Sema: Wire up compound name lookup to UnresolvedSelectorExpr.
Resolve selector references using compound name lookup, pushing DeclNames a bit deeper through the type-checker and diagnostics as necessary.

Swift SVN r14791
2014-03-07 20:52:30 +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
d758e0dfe3 Eliminate more "DynamicLookup" in favor of "AnyObject", this is the
bulk of finishing rdar://13327098.


Swift SVN r14653
2014-03-04 22:15:46 +00:00
Chris Lattner
aef2f62406 inline actOnIdentifierExpr into its (now) only callsite. This is better
(among other reasons) because it isn't an action method, it does parsing.



Swift SVN r14605
2014-03-03 19:10:39 +00:00
Chris Lattner
30863729a0 remove parser support for DynamicSelf. The world should have switched
by now and it is in my way.  The internal compiler nomenclature still 
needs to be updated, Doug can handle that best.


Swift SVN r14604
2014-03-03 19:07:15 +00:00
Joe Groff
363a324984 Parse: Start parsing selector member references.
Parse 'x.y:z:' for at least two selector pieces as an UnresolvedSelectorExpr, and declare it unimplemented in Sema.

Swift SVN r14492
2014-02-28 01:47:32 +00:00
Chris Lattner
1344319677 Rename the internal compiler lexicon from val -> let.
Swift SVN r14408
2014-02-26 21:21:18 +00:00
Joe Groff
c0d8ae7c13 Parse 'x.self' as an identity expression.
Factor an IdentityExpr base class out of ParenExpr, and migrate most of the logic to see through ParenExprs to see through IdentityExprs instead. Add DotSelfExpr as a new subclass of IdentityExpr, produced by parsing 'x.self'.

Swift SVN r14381
2014-02-26 06:23:55 +00:00