Commit Graph

2357 Commits

Author SHA1 Message Date
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
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
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
Dave Zarzycki
4a4cbcc9ec Parser: forgive amp_prefix in func decls
<rdar://problem/15465693> "Expected identifier in function declaration" if '&' is not followed by space

Swift SVN r13728
2014-02-09 23:37:31 +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
e38b12501c change Parser::parseDeclVarGetSet to return the bound variable, instead of
returning it by reference.  NFC.


Swift SVN r13726
2014-02-09 22:54:35 +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
a3972d96e0 rename AddVarsToScope to CollectVarsAndAddToScope and move it
down next to case statement parsing logic since it is specific to
it.  It looks like we can't fully eliminate this right now, because
patterns in case statements are parsed generally as expr patterns
and sema'd into something more useful later, too late for setting
variables in scopes.  The parsing logic could be improved here, but
I'm not going to work on this. 

As a driveby, improve error recovery when type checking of case
statement patterns fails by marking the decls inside of them as
invalid.


Swift SVN r13712
2014-02-09 19:29:19 +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
78a6f969a2 rework SubscriptDecls to work the same as VarDecls: first the
SubscriptDecl is created, then the accessors are installed on it.
This allows us to create the subscript decl before the accessors
have been parsed, allowing us to build the subscript even in invalid
cases (better for later error recovery).

More importantly, this allows us to add it to Decls before calling
parseGetSet, so we can now make parseGetSet add accessors to Decls
without breaking source order (something that deeply upsets the IDE
features).

With all this untangled, we can now remove the 'addAccessorsInOrder'
hack where we parsed the accessors and then later tried to figure out
which order they came for the purpose of linking up the AST: accessors
now work just like everything else.



Swift SVN r13708
2014-02-09 18:22:30 +00:00
Chris Lattner
ce9d97c2b9 similar to the previous patch, have all NominalTypeDecls auto-reparent
all of their generic parameters.  This simplifies logic creating them,
allowing us to eliminate all setDeclContext() calls from the parser.

While we're at it, change Parser::addVarsToScope to be a static 
function in ParseStmt.cpp and dramatically cut it down since none of
its remaining clients are using most of its capabilities.  It needs
to be simplified even further.


Swift SVN r13702
2014-02-09 07:20:03 +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
43a18e1675 Switch vardecls off of Parser::addVarsToScope, onto a simple
for loop that walks the pattern variables and sets them up.
Move addVarsToScope to ParseStmt.cpp which is what is left
using it.

Add a new "addAccessorsInOrder" helper to add the get/set
accessors to the Decls tree in the right order.



Swift SVN r13697
2014-02-09 06:21:56 +00:00
Chris Lattner
143d503cf9 Simplify how accessors are added to "Decls" and have their decl context
set by the parser.  Instead of having addVarsToScope grovel through
and find them to do this, just do it directly when parsing the accessors.
Subscripts do this, so vardecls can too.


Swift SVN r13696
2014-02-09 05:52:09 +00:00
Chris Lattner
a2579527e9 rearrange how the get/set decls are synthesized for observing properties. Now the
parser creates the get/set decls, and sema fills them in, instead of having sema 
do all the work.  This makes it easier to update DeclContexts in all cases.


Swift SVN r13597
2014-02-06 21:36:01 +00:00
Chris Lattner
2339567de6 reapply "replace magic numbers with an (already extant) enum.",
now with less typo and no terrible comment with enum name in it.


Swift SVN r13593
2014-02-06 18:47:05 +00:00
Chris Lattner
063fa84ee9 revert r13591, it broke something.
Swift SVN r13592
2014-02-06 18:41:24 +00:00
Chris Lattner
7d48b7a7a6 replace magic numbers with an (already extant) enum.
Swift SVN r13591
2014-02-06 18:21:21 +00:00
Chris Lattner
595817bd89 Rename data structures relating to WillSetDidSet properties to call them "Observing"
properties internally to the compiler.  NFC.


Swift SVN r13587
2014-02-06 17:51:45 +00:00
Chris Lattner
49f7290288 Add specific diagnostics for sil-only attributes.
Treat inout as a SIL-only attribute, but produce a better diagnostic for it
if someone uses it accidentally (which I expect to be common over the next
few weeks).  inout is done.


Swift SVN r13567
2014-02-06 06:52:28 +00:00
Chris Lattner
44b9321c7a Update the last few uses of @inout in the testsuite, and change
the parser to reject @inout in non-SIL modes.


Swift SVN r13566
2014-02-06 06:37:01 +00:00
Chris Lattner
827acad533 Various inout improvements:
- purge @inout from comments in the compiler except for places talking about
   the SIL argument convention.
 - change diagnostics to not refer to @inout
 - Change the astprinter to print InoutType without the @, so it doesn't show
   up in diagnostics or in closure argument types in code completion.
 - Implement type parsing support for the new inout syntax (before we just 
   handled patterns).
 - Switch the last couple of uses in the stdlib (in types) to inout.
 - Various testcase updates (more to come).



Swift SVN r13564
2014-02-06 06:22:27 +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
fa58183545 Teach the parser to accept "mutating func f()" as an alias for
"@mutating func f()".   I'm keeping the @mutating version around
so we can determine what to do with @!mutating.

Also, improve the QoI of mutating related diagnostics.


Swift SVN r13480
2014-02-05 07:09:11 +00:00
Chris Lattner
4b142e82d0 move Parser::isStartOfDecl into ParseDecl.cpp (where it makes more sense)
allowing us to turn two Parser methods into static functions.  NFC.


Swift SVN r13473
2014-02-05 04:43:33 +00:00
Chris Lattner
f2ae570414 reject things like "var x : Int {}" in the parser, instead of parsing it as a stored decl.
Before my changes from a few days ago, we parsed it as having an empty getter (which
was rejected by sil diagnostics), but my restructuring broke that.  Make sure to reject it,
now with a more specific error.


Swift SVN r13403
2014-02-04 01:56:10 +00:00
Chris Lattner
63adafc7c6 Move my parser-time check for variable initializer requirements to Sema.
Swift SVN r13402
2014-02-04 01:43:12 +00:00
Chris Lattner
72073014da fix <rdar://problem/15626843> Stored global and static properties should require an initializer
Swift SVN r13360
2014-02-03 17:30:28 +00:00
Chris Lattner
f508925dda rearrange the vardecl parsing logic so we handle initializer before get/set expressions.
No change to what we accept.


Swift SVN r13355
2014-02-03 16:23:22 +00:00
Chris Lattner
9f32d521a2 now that ctors and dtors have self patterns, we can unify and simplify the
implementation of AbstractFuncDecl::getImplicitSelfDecl() and eliminate
the ImplicitSelfDeclAndIsCached ivar.


Swift SVN r13351
2014-02-03 15:17:21 +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
Chris Lattner
3e08673772 Introduce patterns for self arguments to ctors and dtors, making them uniform
with FuncDecls.  This allows us to eliminate special case code for handling
self in various parts of the compiler.

This also improves loc info (debug info and AST info) because 'self' now
has a location instead of being invalid.

I also took the opportunity to factor a bunch of places creating self decls
to use similar patterns and less copy and paste code.



Swift SVN r13196
2014-01-31 02:17:22 +00:00
Joe Groff
9fe1ab427a Implement 'if let' and 'while let' statements.
Allow IfStmts and WhileStmts to have as their condition either an expression, as usual, or a pattern binding introduced by 'var' or 'let', which will conditionally bind to the value inside an optional. Unlike normal pattern bindings, these bindings require an in-line initializer, which will be required to be Optional type. Parse variable bindings in this position, and type-check them by requiring an Optional on the right-hand side and unwrapping it to form the pattern type. Extend SILGen's lowering of if and while statements to handle conditionally binding variables.

Swift SVN r13146
2014-01-30 10:37:39 +00:00
Chris Lattner
9f437f79b3 we don't support non-member didset/willset properties yet. Produce an error instead
of crashing.


Swift SVN r13057
2014-01-28 06:47:34 +00:00
Chris Lattner
d407bc8fc4 Teach the parser to add the didSet/willSet functions to the enclosing
type, so we emit them.  Add mangler (and demangler) support for these.
Enhance our testcase to check to make sure that stores within these
specifiers are direct, they don't cause recursive infinite loops.

John, I picked w/W for the mangling letters, let me know if this is ok.


Swift SVN r13050
2014-01-28 05:15:56 +00:00
Chris Lattner
827e168b40 refactor all the get/set parsing logic to merge the cases together into
one function.  Add to it logic to parse didset/willset.

Sema doesn't exist yet, so these aren't too useful yet.


Swift SVN r13019
2014-01-28 00:09:12 +00:00
Chris Lattner
929ad99f08 Clean up and generalize the code pertaining to how a FuncDecl accessor
knows about the AbstractStorageDecl it works on.  NFC.



Swift SVN r12994
2014-01-27 17:57:38 +00:00
Chris Lattner
bea19a3605 Push the AST representation of properties in protocols forward,
mostly to get the brokenness inherent in their current representation out
of my way.

The biggest part of this is that properties in protocols are now always
represented as Computed VarDecls.  If you write "var x : Int" in a protocol,
you get an getter FuncDecl.  If you write "var x : Int { get}" you get the same
thing.  If you write "var x : Int { get set }" then you get a getter and setter
prototype associated with the vardecl.

This then readjusts the various hacks that sort of pass through such things
in SILGen and IRGen, so that we have the same level of hacky support for properties
in protocols.

From the functionality perspective, this enables the { get set } syntax described
in rdar://15827219, and means that "var x : Int" is uniformly treated as read-only
(it was treated as mutable in some cases before).  Properties in protocols are
still quite broken though.



Swift SVN r12981
2014-01-27 05:56:57 +00:00
Chris Lattner
64aa85c32a fix an error on invalid case that would cause the parser to spin forever.
Swift SVN r12978
2014-01-26 23:49:15 +00:00
John McCall
fcf1c14924 When deciding whether we can support a type property,
ignore whether it's in an extension vs. the primary declaration,
and permit non-stored properties in any context except a protocol.

Swift SVN r12943
2014-01-24 22:46:22 +00:00
John McCall
f416dd81a8 Track whether a PatternBindingDecl theoretically
declares storage or not.

Swift SVN r12942
2014-01-24 22:46:22 +00:00
Manman Ren
729d30fb54 SILParser: first step towards parsing sil_witness_table.
Only one entry kind out of four is supported right now.


Swift SVN r12936
2014-01-24 21:58:45 +00:00
Doug Gregor
3cd14d6643 Don't permit DynamicSelf outside the body or return type of a method.
Swift SVN r12761
2014-01-22 19:20:30 +00:00
Doug Gregor
d52cec4b20 Eliminate a pile of literal identifiers for self, init, destructor, etc.
... because I can't stomach adding another one of these.


Swift SVN r12687
2014-01-22 01:09:49 +00:00
Chris Lattner
f5b85341a1 Expand out the "isComputed" property in AbstractStorageDecl to be an enum
with two kinds, and some more specific predicates that clients can use.

The notion of 'computed or not' isn't specific enough for how properties
are accessed.  We already have problems with ObjC properties that are 
stored but usually accessed through getters and setters, and a bool here
isn't helping matters.

NFC.



Swift SVN r12593
2014-01-20 18:16:30 +00:00
Doug Gregor
11656c9798 Introduce the ParseDeclOptions option set in the Parser. NFC.
Swift SVN r12588
2014-01-20 17:38:12 +00:00
Chris Lattner
a0f0c28868 Two related but (theoretically at least) seperable changes:
1. Implement parser and sema support for our subscript syntax proposal in
   protocols.  Now you have to use subscript(..) { get } or  {get set} to 
   indicate what you want.  I suspect that the syntax will evolve, but at
   least we can express what we need now.
2. Change the representation of SubscriptDecls in protocols to make 
   (empty) funcdecls for the getter and setter.  This guarantees that 
   every subscript has at least a getter.



Swift SVN r12555
2014-01-19 01:35:13 +00:00
Chris Lattner
99204f9a9b push scopes for getter/setter bodies later. NFC, just unblocking
other refactorings.



Swift SVN r12553
2014-01-18 22:29:08 +00:00
Argyrios Kyrtzidis
84e20a0620 [AST] Break down IdentTypeRepr to different subtypes.
This makes memory allocation for it more efficient and it's more convenient to handle.

Swift SVN r12541
2014-01-18 20:19:09 +00:00
Chris Lattner
7e67fdb30a decls always can get to an ASTContext, remove the unneeded
ASTContext argument from VarDecl::setComputedAccessors.


Swift SVN r12538
2014-01-18 20:04:05 +00:00