Commit Graph

1147 Commits

Author SHA1 Message Date
Manman Ren
adb04e5e8c [SILParser] parsing "!" as ImplicitlyUnwrappedOptional.
Swift SVN r21194
2014-08-14 15:06:23 +00:00
Chris Lattner
61715b1da7 Remove some dead code: pattern parsing is now never used for argument lists,
so inout can't appear there and we don't need to propagate an "isArgumentList"
bool down through pattern parsing.  NFC.



Swift SVN r20835
2014-07-31 17:46:08 +00:00
Chris Lattner
a2beb62f85 fix <rdar://problem/16786168> Functions currently permit 'var inout' parameters
fix <rdar://problem/17867059> ` upgrade logic should be removed




Swift SVN r20817
2014-07-31 06:18:42 +00:00
Chris Lattner
fcb6b3df07 Fix <rdar://problem/17391625> Swift Compiler Crashes when Declaring a Variable and didSet in an Extension
This moves a crude parser check for stored properties in enums & extensions into Sema, and changes it
to be correct (rejecting the case that caused the crash in the radar) as well as more descriptive.



Swift SVN r20695
2014-07-29 21:19:56 +00:00
Jordan Rose
29f8c25d63 Move #line state into the Parser and out of the SourceManager.
As part of this change, allow #line directives to extend to the end of the
file, rather than requiring a reset.

Note that #line regions that start or end within function bodies will not
behave correctly when in delayed parsing modes. This was true before and
after this commit. (#line regions contained entirely within a function and
not within any other #line regions should be fine.)

Swift SVN r20571
2014-07-25 23:01:43 +00:00
Manman Ren
b697fe1364 [SILParser] fix parsing issues for stored_with_trivial_accessors.
Before this commit, we were not able to differentiate between stored
property and stored_with_trivial_accessors property. This causes issues
when parsing a SILDeclRef to a trivial getter.

We add @sil_stored for stored properties and we will have 3 cases
A) for stored property: @sil_storage var x : Int
B) for stored_with_trivial_accessors property:
   @sil_storage var x : Int { get set }
C) for computed property: var x : Int { get set }

Fix rdar://17715778 rdar://17381432 rdar://17347296.


Swift SVN r20189
2014-07-18 23:18:14 +00:00
Argyrios Kyrtzidis
8eb7d43d32 [Parser] Introduce a convenience wrapper for Parser functionality.
This is useful when wanting to just do some syntactic parsing for a snippet of code.

Swift SVN r20174
2014-07-18 19:57:32 +00:00
Chris Lattner
195a4b38a3 Reapply r20101: switch 'convenience' from being a specially handles contextual keyword to being a decl modifier just like the rest, this elimiantes a bunch of special case code for handling it.
Swift SVN r20103
2014-07-17 17:27:54 +00:00
Chris Lattner
d2315f2bd8 revert r20101, I built one tree and tested another.
Swift SVN r20102
2014-07-17 17:12:31 +00:00
Chris Lattner
9b0d88e800 switch 'convenience' from being a specially handles contextual keyword
to being a decl modifier just like the rest, this elimiantes a bunch of
special case code for handling it.


Swift SVN r20101
2014-07-17 17:08:32 +00:00
Chris Lattner
f35db30296 simplify the interface to parseNewDeclAttribute, NFC.
Swift SVN r20026
2014-07-16 17:48:29 +00:00
Chris Lattner
f21bcae0bc remove support for attribute inversion (i.e. @!foo). This doesn't work with
decl modifiers and our direction has been established to use "nonfoo" or 
foo(not_for_you) style of attributes.


Swift SVN r20007
2014-07-16 05:40:23 +00:00
Chris Lattner
fe30b66a93 move "override" onto the new fangle decl modifier code, instead of being a virtual
attribute.  As part of this, introduce a new "NotSerialized" flag in Attr.def.
This eliminates a bunch of special case code in the parser and elsewhere for handling
this modifier.



Swift SVN r19997
2014-07-16 01:23:58 +00:00
Chris Lattner
5f55052e89 pull operator decls into the attribute flow: have the parser attach attributes
to operator decls, and validate the attributes in the type checker.  This allows
us to reject invalid operator decls (resolving a fixme) and restores syntax coloring
of 'infix' on an operator (a regression in my last patch).



Swift SVN r19932
2014-07-14 17:03:41 +00:00
Chris Lattner
57cd2506ff Change "operator infix" to "infix operator" for consistency with the rest of the declaration
modifiers and with the func implementations of the operators.  This resolves the rest of:
<rdar://problem/17527000> change operator declarations from "operator prefix" to "prefix operator" & make operator a keyword




Swift SVN r19931
2014-07-14 16:39:10 +00:00
Doug Gregor
a5c079af59 Replace the class_protocol attribute with a "class" requirement.
This only tackles the protocol case (<rdar://problem/17510790>); it
does not yet generalize to an arbitrary "class" requirement on either
existentials or generics.

Swift SVN r19896
2014-07-13 06:57:48 +00:00
Chris Lattner
3a3a5f6610 change 'operator' to be a keyword instead of a contextually sensitive weirdo,
part of rdar://17527000.




Swift SVN r19840
2014-07-11 00:29:50 +00:00
Chris Lattner
02999cac51 Reinstate the @ on the @objc attribute. This is largely a revert of r19555 with a few tweaks.
Swift SVN r19706
2014-07-08 21:50:34 +00:00
Chris Lattner
7a56499d61 Start making @objc not start with an @ sign:
- Change the parser to accept "objc" without an @ sign as a contextual
   keyword, including the dance to handle the general parenthesized case.
 - Update all comments to refer to "objc" instead of "@objc".
 - Update all diagnostics accordingly.
 - Update all tests that fail due to the diagnostics change.
 - Switch the stdlib to use the new syntax.

This does not switch all tests to use the new syntax, nor does it warn about
the old syntax yet.  That will be forthcoming.  Also, this needs a bit of 
refactoring, which will be coming up.



Swift SVN r19555
2014-07-04 05:57:57 +00:00
Adrian Prantl
400f1774e9 Add support for a #line directive.
This patch extends the syntax with a new #line directive that is inspired
by the homonymous CPP directive. It can be specified in all locations a #if
is legal (Stmt, Decl).

Semantics
---------

#line 42 "file.swift"
This makes diagnostics and debug information behave as if the subsequent
lines came from file.swift+42.

#line // without arguments
This switches back to the main source file and the switches back to the
normal line numbering. Any previous #line directives will result in gaps
in the main file.

Rationale
---------

LLDB and the REPL need this for making expressions that are entered into
the expression evaluator or REPL debugable. For more info see
<rdar://problem/17441710> Need #line directive or something similar so we can enhance the debugging of expressions and REPL

Also, I believe the stdlib would benefit from this and it would allow us
to get rid of the line-directive wrapper script.

Swift SVN r19384
2014-06-30 23:50:11 +00:00
Doug Gregor
55ca3b01f3 Parse dictionary type sugar [K : V].
Handle parsing of dictionary type sugar into its own type
representation, including both type and expression contexts.

This is the first part of <rdar://problem/17460972>; we still need a
sugared Type node.


Swift SVN r19239
2014-06-26 16:57:42 +00:00
Doug Gregor
7213cda0f4 Parse [T] as an array type in type contexts.
Swift SVN r19184
2014-06-25 22:04:50 +00:00
Doug Gregor
5783d0b313 Revert r19185: Add T* syntactic sugar type for UnsafePointer<T>.
Swift SVN r18255
2014-05-17 16:43:46 +00:00
Doug Gregor
806daf3a87 Add T* syntactic sugar type for UnsafePointer<T>.
This is the basic plumbing for <rdar://problem/16912508>.


Swift SVN r18195
2014-05-16 15:30:26 +00:00
Ted Kremenek
fe0dbb701d Remove shorthand "x as T!" instead of "(x as T)!"
Implements <rdar://problem/16806243>.

Swift SVN r18156
2014-05-16 01:07:53 +00:00
Jim Ingham
14a6697ba5 Add an attribute marking the "Debugger function" lldb uses for emulating
local contexts.  Get the parser in consultation with the DebuggerClient
to handle moving persistent declarations from the debugger function to the
source file.

<rdar://problem/15302321> [ER] Define Swift classes in expressions


Swift SVN r17948
2014-05-12 19:03:31 +00:00
Doug Gregor
c1daf3fd7f Use perfect forwarding for diagnostic arguments.
While this should be a pointless performance tweak along a path where
we don't care about performance, it actually matters because we
occasionally end up copying SmallStrings or std::strings, then taking
StringRefs to the copies and holding on to them. This was manifesting
as occasional corruption in keyword-argument diagnostics.

Swift SVN r17811
2014-05-09 22:38:01 +00:00
Chris Lattner
40a8fda572 inline hasExprCallSuffix into its two callers now that it is trivial. NFC.
Swift SVN r17605
2014-05-07 05:31:24 +00:00
Chris Lattner
92af326a15 generalize consumeIdentifier to work with self and Self. Use it in a few
more places to simplify code.  NFC.


Swift SVN r17438
2014-05-05 14:48:56 +00:00
Chris Lattner
502e663e23 inline parsePatternIdentifier into its only caller, and simplify the result.
Swift SVN r17407
2014-05-04 23:14:15 +00:00
Doug Gregor
eb7a9144a8 Bring keyword arguments to subscripts.
Subscript declarations were still encoding the names of index
variables in the subscript type, which unintentionally made them
keyword arguments. Bring subscript declarations into the modern day,
using compound names to encode the subscript argument names, which
provides consistency for the keyword-argument world
<rdar://problem/14462349>. Note that arguments in subscripts default
to not being keyword arguments, which seems like the right default.

We now get keyword arguments for subscripts, so one can overload
subscripts on the names of the indices, and distinguish at the call
site. Under -strict-keyword-arguments, we require strictness here as well.

The IRGen/IDE/SILGen test updates are because the mangling of common
subscripts changed from accidentally having keyword arguments to not
having keyword arguments.

Swift SVN r17393
2014-05-04 19:31:09 +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
2427e36ff8 Introduce a new "convenience" context sensitive keyword, which can only be
used on init decls, with the same semantics as "-> Self".  Switch the ast
printer, and fixits to use it.

As driveby's, simplify verification of contextual keywords in declparsing,
and rename parseConstructor/Destructor to parseInit/Deinit.


Swift SVN r17356
2014-05-04 04:02:32 +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
Chris Lattner
029fe4f3af fix <rdar://problem/16792027> compiler infinite loops on a really really mutating function
by restructuring context sensitive keywords a bit.


Swift SVN r17228
2014-05-02 05:43:37 +00:00
Doug Gregor
ca62675c64 Rip out the parsing code for default values in patterns.
This code was already unused.


Swift SVN r17091
2014-04-30 13:59:44 +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
Doug Gregor
2872287dcd Add support for marking function arguments with the back-tick ("`").
Part of <rdar://problem/16742001>. At the moment, this is just a
parsing thing, because argument names are still API by default
anyway.

Swift SVN r16991
2014-04-28 19:35:57 +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
Chris Lattner
0c390777ba Implement <rdar://problem/16204675> Need #elseif
This restructures IfConfigDecl/Stmt to be a list of clauses controlled
by a condition.  This makes it straight-forward to drop in #elseif support.

While I'm in here, this patch moves checking for extraneous stuff at the
end of the #if line from the lexer to the parser.  This means that you can
now put a comment on the same line as a #if/#else/#elseif/#endif.



Swift SVN r16912
2014-04-27 04:51:36 +00:00
Chris Lattner
371a9316f4 - Introduce a new 'nonmutating' context sensitive keyword, and use it instead of @!mutating.
- Change the parser to unconditionally reject @mutating and @!mutating with a fixit and 
  specific diagnostic to rewrite them into the [non]mutating keyword.
- Update tests.

This resolves <rdar://problem/16735619> introduce nonmutating CS keyword and remove the attribute form of mutating all together



Swift SVN r16892
2014-04-26 21:00:06 +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
Chris Lattner
0a5b27baf4 Implement labeled break/continue support, implementing rdar://11562938.
Right now you can 'break' out of a labeled switch statement, but unlabeled 
break retains its previous semantics of breaking out of the nearest loop.


Swift SVN r16616
2014-04-21 14:38:16 +00:00
Chris Lattner
0e7489c9d5 implement AST support for labels on loops & switch statements. This also
improves location information to track the label location in the AST.  We
don't currently track the location of the colon, but that would be trivial
to drop in if it is interesting.


Swift SVN r16608
2014-04-21 04:56:55 +00:00
Chris Lattner
8a6a9101e2 parser support for labels on loops and switch statements. No AST representation
yet.


Swift SVN r16603
2014-04-21 04:31:15 +00:00
Chris Lattner
b204be71cd simplify Parser::isStartOfStmt: just use the current token instead of having
all of the clients pass in the current token.  NFC.


Swift SVN r16601
2014-04-21 04:01:03 +00:00
Doug Gregor
1f4b73b93f Tricky selector-style parameter parsing into creating ParamDecls.
The selector-style parameter parsing code is going away "soon", but we
still need to prop it up a bit longer. Hence, I don't feel too bad
about the Parser-level state I'm using in this hack to make it happen.

With that change, we can now establish two important invariants in the
AST:
  - Only parameters (ParamDecl or GenericTypeParamDecl) can have their
  DeclContexts changed. Everything else comes into being in the
  correct context.
  - All of the parameters in a function/constructor/closure/etc. are
  described by ParamDecls, not just VarDecls.



Swift SVN r16593
2014-04-20 18:25:23 +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