Commit Graph

531 Commits

Author SHA1 Message Date
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
Chris Lattner
f9a83fdc33 Implement the first half of <rdar://problem/15922884> support non-member didset/willset properties
Observing properties now work fine as globals.  Local variables still need some work though.



Swift SVN r13736
2014-02-10 05:43:04 +00:00
Chris Lattner
b9f667b3b2 Implement <rdar://problem/15920332> didSet/willSet variables need to allow initializers
With enough of the world's complexity pushed around, this is now straight-forward,
but we still need to use full parser lookahead to handle some more complex cases.



Swift SVN r13727
2014-02-09 23:15:43 +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
554f5e8ec0 Now that "addFunctionParametersToScope" just adds the variables
from the pattern to the scope (it doesn't do other argument
specific stuff like mucking with decl contexts) rename it to
addPatternVariablesToScope, and use it in two more places
in the parser.


Swift SVN r13710
2014-02-09 18:31:58 +00:00
Chris Lattner
40316dc769 Change FuncDecl/CtorDecl/DTorDecl/ClosureExpr constructors to
automatically reparent VarDecls in their arg/body patterns and
GenericParameters to themselves.  These all have to be created
before the actual context decl is created and then reparented,
so we might as well have the reparenting be done by the decl
itself.  This lets us take out some setDeclContext reparenting
loops from around the parser.  

I'm sure that there are a lot more places they can be removed
from as well.

NFC.


Swift SVN r13701
2014-02-09 07:02:33 +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
Chris Lattner
63dc900f91 Pattern processing cleanups, NFC:
Introduce a new Pattern::forEachVariable that takes a lambda and iterates
over all the variables encompassed by the pattern (the ones found by
collectVariables) and runs the lambda on it.

Use this to implement collectVariables, so we only have one copy of the code.

Convert several places to use this, removing a bunch of duplicated code for
walking the pattern structure and extracting decls.

Convert a few uses of collectVariables to forEachVariable, leading to more
clear code without a temporary smallvector.

Remove simplifyPatternTypes in CSApply.cpp, which is dead.



Swift SVN r13545
2014-02-06 01:52:35 +00:00
Argyrios Kyrtzidis
8758451a43 [Parser/IDE] Introduce ide::isSourceInputComplete() which returns true if the input source is fully formed,
or false if, for example, a closing brace is missing.

This is useful for the REPL.
rdar://15948039

Swift SVN r13313
2014-02-02 03:14:33 +00:00
Joe Pamer
deca1533cd Improve parsing and error recovery for malformed size expressions in array type specifications
Swift SVN r13262
2014-02-01 01:11:07 +00:00
Doug Gregor
88355dd322 Base the implicit 'self' parameter type on DynamicSelf when appropriate.
To get here, make the implicit 'self' parameter a bit more like a
parsed parameter, by giving it a trivial TypeRepr so that pattern
validation will validate the type. This latter piece is important for
DynamicSelf, because we need the interface type of the function to
refer to the implicit generic parameter while the actual type refers
to the archetype.



Swift SVN r12757
2014-01-22 18:36:38 +00:00
Jordan Rose
11008f0ed1 Split diagnostics out into separate files.
Thanks to the way we've set up our diagnostics engine, there's not actually
a reason for /everything/ to get rebuilt when /one/ diagnostic changes.
I've split them up into five categories for now: Parse, Sema, SIL, IRGen,
and Frontend, plus a set of "Common" diagnostics that are used in multiple
areas of the compiler. We can massage this later.

No functionality change, but should speed up compile times!

Swift SVN r12438
2014-01-17 00:15:12 +00:00
Doug Gregor
d6d9bc8290 Some constructor -> initializer renaming
Swift SVN r12042
2014-01-08 04:47:13 +00:00
Doug Gregor
5f1e886907 Wrap delegating initialization ('self.init' calls) in RebindSelfInConstructorExpr.
As with chaining initialization ('super.init' calls), wrapping the
delegating initialization in RebindSelfInConstructorExpr ensures that
'self' gets overwritten by the result of delegation.

Note that I'd much prefer that RebindSelfInConstructorExpr be
introduced by the type checker (not the parser). That cleanup will
follow.



Swift SVN r11932
2014-01-06 18:25:29 +00:00
Doug Gregor
fc00bf6076 Parsing and semantic analysis for delegating initializers.
Swift SVN r11921
2014-01-06 16:33:08 +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
d3c91387e9 Substantially simplify the API to LValueType now that nonsettable is gone.
Swift SVN r11703
2013-12-28 22:48:44 +00:00
Chris Lattner
fc5606ff19 Now that enough bugs are fixed :), mark more things as immutable values:
- foreach enumerators
- closure arguments with explicit patterns
- 'value' in a setter
- subscript arguments



Swift SVN r11681
2013-12-27 23:30:52 +00:00
Chris Lattner
5a053ac85a - fix the ASTDumper to propertly dump closure_expr's.
- mark closure arguments (both explicit and $0's) as immutable
- Adjust the stdlib (one place) and some tests to cope with this.
- Remove some special case logic in sema for lvalue qualifying
  anonymous closure exprs, which is now the wrong thing to do.




Swift SVN r11674
2013-12-27 21:01:00 +00:00
Jordan Rose
308c6139f9 Change ASTContext::allocate(unsigned) to return a MutableArrayRef.
...rather than a raw pointer that points to a buffer with space for N
elements. Just because we *can* get N from context doesn't mean it's
convenient/safe.

No functionality change.

Swift SVN r11488
2013-12-19 23:25:04 +00:00
John McCall
7173cec9db Thread contextual information about parsing the top-level
through various bits and use that to globally discriminate.

Swift SVN r11379
2013-12-17 04:31:40 +00:00
Chris Lattner
71af72a0ca Change a few more kinds of arguments to be 'var' arguments instead of 'let'
arguments.  Until we have @inout methods on structs, we can't mark anything
that can be address-exposed.  This temporarily regresses a few testcases,
but they will come back later.



Swift SVN r11359
2013-12-16 20:33:23 +00:00
Chris Lattner
fbe1d09e77 stop marking "$0" arguments in closures, and generator variables in foreach
loops as 'let', silgen isn't ready for it yet.

Change silgen's handling of let variables to stop using emitLoweredCopyValue,
which is busted for aggregates that contain both trivial and nontrivial types
(15669586).


Swift SVN r11352
2013-12-16 19:38:49 +00:00
Doug Gregor
6faf833365 Finish comment
Swift SVN r11259
2013-12-13 18:40:13 +00:00
Doug Gregor
e0fa463249 Diagnose attempts to allocate multidimensional arrays with specified inner lengths.
In other words, allow "new Int[5][]" but not "new Int[5][5]". Semantic
analysis accepted these, but SILGen would crash. 


Swift SVN r11258
2013-12-13 17:57:46 +00:00
John McCall
30e388fbf2 Extract the actual context info out of the ParseFunctionBody RAII object.
Swift SVN r11205
2013-12-12 19:46:25 +00:00
Chris Lattner
1a3ff1e9b2 implement 'let' pattern bindings.
Swift SVN r11199
2013-12-12 19:16:06 +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
6d4cd89e4e mark closure arguments, subscript arguments and destructor arguments (??)
as immutable.


Swift SVN r11147
2013-12-11 22:36:11 +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
John McCall
a5febc6b48 Track discriminators for closure expressions.
Swift SVN r10905
2013-12-06 02:23:57 +00:00
Dmitri Hrybenko
67f3115e8f Customize diagnostic for using anonymous closure arguments in a closure with explicit arguments
We used to produce:
(swift) { () in $0 }
<REPL Input>:1:9: error: anonymous closure argument not contained in a closure

rdar://15003789


Swift SVN r10751
2013-12-03 18:35:12 +00:00
Dave Zarzycki
005e9a8978 Fix memory corruption with trailing closures
Swift SVN r10704
2013-12-01 06:21:16 +00:00
Doug Gregor
19759529db Allow delayed identifier expressions (.foo) with static variables and methods.
This allows expressions such as ".foo" and ".foo(1)" to refer to
static variables and static methods, respectively, as well as enum
cases. 

To get here, rework the parsing of delayed identifier expressions a
bit, so that the argument itself is part of the delayed argument
expression rather than a separate call expression. This simplifies
both the handling of patterns of this form and the type checker, which
can now user simpler constraints.

If we really want to support (.foo)(1), we can make that work, but it
seems unnecessary and perhaps confusing.


Swift SVN r10626
2013-11-21 06:24:06 +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
d6012459c3 Eliminate IsTopLevel parameter from Parser::parseBraceItems() -- its value can
be computed from other parameter.


Swift SVN r10069
2013-11-09 02:06:39 +00:00
Anna Zaks
54524e622a Replace ExprStmtOrDecl with ASTNode and make it a struct.
Previously, the Parser and BranchStmt typedef-ed ExprStmtOrDecl as a pointer union. Using typedef made the objects compatible, but did not allow us to extend the type with helper methods, such as getSourceRange(), which is something you can get on all of the AST objects. This patch introduces ASTNode that subclasses from PointerUnion and is used by both parser and BranchStmt.

Swift SVN r9971
2013-11-05 21:46:59 +00:00
Chris Lattner
68af974227 Remove 'axle' related code and build machinery. It turns out that we
will not be pursuing this project in the immediate future.



Swift SVN r9901
2013-11-03 16:04:27 +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
Dmitri Hrybenko
238d898a0d Code completion for enums: model completion in switch case as a separate kind
of completion.  This approach (rather than SourceLoc tricks) better reflects
the intent and allows us to fix the rest of testcases.


Swift SVN r9557
2013-10-21 20:58:23 +00:00
Dmitri Hrybenko
63c264446d Code completion for enums: complete "switch e { case .#^A^#"
Swift SVN r9551
2013-10-21 18:53:31 +00:00
Dmitri Hrybenko
da3e2c39fd Portability: isdigit() returns int, which is not required to be strictly 0 or 1
Swift SVN r9541
2013-10-21 15:54:27 +00:00
Dmitri Hrybenko
011284e9c9 Make minus sign part of IntegerLiteralExpr and make integers literals 136-bits
wide

Currently integer literals are 64-bit.  In order to allow checking for overflow
while converting an integer literal to swift.UInt/Int* types we need at least
65 bits.  But floating point numbers (Float32, Float64, Float80) are
BuiltinIntegerLiteralConvertible.  In order to allow spelling large floating
point constants, we allow 136-bit literals.

Rationale: 128 bits are enough to represent the absolute value of min/max IEEE
Binary32, and we need 1 bit to represent the sign.  136 is 129 rounded to the
next 8 bits.

The plan is to have builtins that do the overflow check and convert 136-bit
numbers to the required width.  We need these builtins for both integers and
floating point numbers to ensure that 136-bit numbers are folded into sane
constants in SIL and don’t escape to LLVM IR.


Swift SVN r9253
2013-10-12 04:52:11 +00:00