Commit Graph

1224 Commits

Author SHA1 Message Date
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
Joe Groff
5096abcaa6 Expose MetatypeExpr again as 'expr.type'.
And drop the 'typeof' stdlib function.

Swift SVN r14378
2014-02-26 05:10:19 +00:00
Doug Gregor
0bde325327 Collapse 'DynamicSelf' into 'Self'.
Swift SVN r14377
2014-02-26 05:04:05 +00:00
Joe Pamer
f83f94d9d8 Support build and target configurations
These changes add support for build and target configurations in the compiler.
Build and target configurations, combined with the use of #if/#else/#endif allow
for conditional compilation within declaration and statement contexts.

Build configurations can be passed into the compiler via the new '-D' flag, or
set within the LangOptions class. Target configurations are implicit, and
currently only "os" and "arch" are supported.

Swift SVN r14305
2014-02-24 18:16:48 +00:00
Dmitri Hrybenko
3da05e347d Change property accessor syntax to include braces
See release notes update for details.

rdar://15966905


Swift SVN r14271
2014-02-22 21:00:56 +00:00
Argyrios Kyrtzidis
eeb9589d2c [AST] Introduce "hasName()" convenience methods and replace "getName().empty()" callers.
Swift SVN r14206
2014-02-21 15:00:38 +00:00
Chris Lattner
28903887e7 Rename the internal compiler lexicon from let -> val.
Swift SVN r13992
2014-02-17 16:48:21 +00:00
Chris Lattner
366d570ae5 fix lookahead disambiguation for closures vs didSet/willSet blocks to handle
attributes on the didSet/willSet declaration.  This fixes:
<rdar://problem/16076758> Attributes on didSet/willSet + property initializer completely confuse the parser


Swift SVN r13936
2014-02-15 02:04:02 +00:00
John McCall
10ac15ed0d Lex $notAllDigits as an identifier and diagnose it in the lexer
outside of debugger-support mode.  Rip out the existing special-case
code when parsing expr-identifier.

This means that the Lexer needs a LangOptions.  Doug and I
talked about just adding that as a field of SourceMgr, but
decided that it was worth it to preserve the possibility of
parsing different dialects in different source files.

By design, the lexer doesn't tokenize fundamentally differently
in different language modes; it might decide something is invalid,
or it might (eventually) use a different token kind for the
same consumed text, but we don't want it deciding to consume more or
less of the stream per token.

Note that SIL mode does make that kind of difference, and that
arguably means that various APIs for tokenizing need to take a
"is SIL mode" flag, but we're getting away with it because we
just don't really care about fidelity of SIL source files.

rdar://14899000

Swift SVN r13896
2014-02-14 01:54:17 +00:00
John McCall
81df78e2ed In the debugger, permit $x0 where we would parse an expr-identifier.
Not sure this is really testable with the restrictions I've
put on it, but presumably the debugger's own test suite will
quickly grow a number of relevant tests.

rdar://14899000

Swift SVN r13880
2014-02-14 00:09:49 +00:00
Doug Gregor
71f9438dd0 Introduce very basic support for selector-style initializations.
The type checker changes here are a complete hack; I'll be revisiting
this shortly. Addresses the rest of <rdar://problem/16031332>.


Swift SVN r13858
2014-02-13 04:15:55 +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
Doug Gregor
521cafd4f5 Parse expr-call-suffix after self.init and super.init.
This can be used as, for example

  self.init withRed(0.5) green(0.5) blue(0.5) alpha(1.0)

which mimics the declaration. THe same goes for super.

Note that this does not yet support

  NSColor.init withRed(0.5) green(0.5) blue(0.5) alpha(1.0)

due to a limitation in the type checker.


Swift SVN r13825
2014-02-12 07:36:07 +00:00
Doug Gregor
e8b29aea02 Allow a closure after the first selector piece.
This allows code such as 

  obj.closure { return 0 } onError { println("error") }

to parse appropriately. The only other functionality change here is
that we no longer allow the use of a trailing closure within the
condition of a C-style for loop, because it did awful things to
recovery. I doubt we'll miss it.



Swift SVN r13823
2014-02-12 07:06:32 +00:00
Doug Gregor
b2b621a409 Parse the expr-call-suffix after identifier generic-args?, not generally.
We don't want to parse the expr-call-suffix as a general
postfix-expression; rather, we only want it when we're directly naming
a method. This doesn't matter so much in the current model, but it
becomes important when we move over to the newer keyword argument model.


Swift SVN r13819
2014-02-12 06:17:04 +00:00
Doug Gregor
8a99029787 Remove unused isConstructor parameter from Parser::parseExprCallSuffix().
Swift SVN r13809
2014-02-12 04:02:55 +00:00
Doug Gregor
560e7584d3 Allow a closure after each selector piece name.
a.foo(i) bar(d) closure { return "hello" } onError { println("error") }



Swift SVN r13808
2014-02-12 03:57:18 +00:00
Doug Gregor
32ca12e39c Revert r4994 "Remove the least liked of the message-send syntaxes".
In other words, provide basic parsing support for selector arguments
on a single line, i.e.,

  a.foo(1) bar(2.5) wibble("hello")



Swift SVN r13806
2014-02-12 03:35:03 +00:00