Commit Graph

2438 Commits

Author SHA1 Message Date
Dave Zarzycki
523c4bc789 Disable operators in nonglobal scopes other than protocols
Operators in non-global scopes other than protocols don't work. Disable
them for now. We can always revisit this later.

This "fixes": 13002566 Operators not found in structs

Swift SVN r3828
2013-01-22 04:45:39 +00:00
Dave Zarzycki
2f31759280 Remove SemiStmt class
We have no intention of ever supporting actual semicolon statements
(separators, statements no), nor do we ever want to because that would
mean the behavior of the program would potentially change if semicolons
were naively removed.

This patch tracks the trailing semicolon now in the decl/expr/stmt,
which will enable someone to write a good "swift indent" tool in the
future.

Swift SVN r3824
2013-01-22 00:25:26 +00:00
Dave Zarzycki
9eb53f37f5 12641063 Fix the double-indent problem with properties
Swift SVN r3822
2013-01-21 22:43:19 +00:00
Dave Zarzycki
c80639270a Function declarations must have bodies
Back when we started the project, we didn't have modules, a standard
library, or even the "asmname" attribute. Not requring function bodies
provided a quick way to prototype the language. We're long past that day
now.

If you still want or need a pure declaration, the [asmname="..."]
attribute still does not require a function body.

This fixes:
13036833 Syntax ambiguity between selector function decl syntax and top-level code

Swift SVN r3821
2013-01-21 22:42:17 +00:00
Dave Zarzycki
572f7686e9 Minor attribute parsing cleanup
Swift SVN r3819
2013-01-21 02:14:23 +00:00
Dave Zarzycki
86fd48456d Clean up var decl parsing
This works now instead of giving a trail of parse errors:
  var x : Int, y : Int { get { return 42 } }

This is now an explicit error rather than a trail of parse errors:
  var x, y : Int { get { return 42 } }

Swift SVN r3811
2013-01-19 19:37:50 +00:00
Dave Zarzycki
cd5eac535a Adopt a consistent comma parsing style
Swift SVN r3810
2013-01-19 19:37:47 +00:00
Dave Zarzycki
b6ba3992fc Mark invalid decls as erroneous and improve error location reporting
This removes a big/gross validation loop at decl parse time that
attempted to catch errors that should have been caught earlier.

Swift SVN r3775
2013-01-16 09:07:39 +00:00
Dave Zarzycki
d0a0d1bce9 Remove fixed FIXME
If I scrolled down more before the last commit, I would have see this.

Swift SVN r3774
2013-01-16 05:36:30 +00:00
Dave Zarzycki
6504d354ae Catch more invalid ctor/dtor/subscript decls during parsing
Found after "subscript(idx : Int) -> Int {}" was accepted at global scope.

Swift SVN r3773
2013-01-16 04:58:52 +00:00
Dave Zarzycki
d22dcc968b Fix copy-and-paste extension parsing error message
Swift SVN r3751
2013-01-11 19:21:00 +00:00
Doug Gregor
2b2b2cfc31 Replace the constructor 'alllocates_this' attribute with an 'allocate-this' expression.
By splitting out the expression used to allocate 'this' (which exists
in the AST but cannot be written in the Swift language proper), we
make it possible to emit non-allocating constructors for imported
Objective-C classes, which are the only classes that have an
allocate-this expression.


Swift SVN r3558
2012-12-20 15:28:37 +00:00
Jordan Rose
5ea8de9094 Match {}, (), and [] during parse recovery (skipUntil*).
<rdar://problem/12456304>

Swift SVN r3517
2012-12-16 22:53:13 +00:00
Jordan Rose
427be94945 Add the [iboutlet] and [ibaction] attributes.
Currently only used for parsing. The immediate intent of these attributes is
to have them behave like [objc] for the purpose of emitting method
implementations; however, they are semantically distinct and should only be
used to expose outlets and actions to Interface Builder.

Swift SVN r3416
2012-12-08 00:16:03 +00:00
Doug Gregor
d3f6890299 Promote the clonePattern() static to Pattern::clone(), since this is common.
Swift SVN r3381
2012-12-06 18:14:53 +00:00
Doug Gregor
a221a6986b Rename the "allocating" attribute to "allocates_this".
Swift SVN r3353
2012-12-04 20:20:58 +00:00
Doug Gregor
08c9b5c7b2 Allocating constructors are expected to allocate and assign 'this' on their own.
This implementation is very lame, because we don't currently have a
way to detect (in Sema or SIL) where 'this' gets uniquely assigned,
and turn that assignment into initialization.

Also, I'm starting to hate the name 'allocating' constructor, because
it's the opposite of the Itanium C++'s notion of the allocating
constructor. Will think up a better name.




Swift SVN r3347
2012-12-04 01:06:30 +00:00
Joe Groff
759f18a329 Consume trailing semicolons at top level.
Instead of writing in an awkward special case for SemiStmt in ParseStmt, apply the existing semicolon-eating syntax in ParseDecl for types to the toplevel. Suggested by Jordan re: r3336.

Swift SVN r3342
2012-12-04 00:21:50 +00:00
Joe Groff
f2437785be Update some bogus-looking comment text in ParseDecl.cpp
Swift SVN r3101
2012-11-02 22:54:39 +00:00
Joe Groff
6449655e21 Implement selector-style function definition syntax.
rdar://12315571
Allow a function to be defined with this syntax:

  func doThing(a:Thing) withItem(b:Item) -> Result { ... }

This allows the keyword names in the function type (in this case
`(_:Thing, withItem:Item) -> Result`) to differ from the names bound in the
function body (in this case `(a:Thing, b:Item) -> Result`, which allows
for Cocoa-style `verbingNoun` keyword idioms to be used without requiring
those keywords to also be used as awkward variable names. In addition
to modifying the parser, this patch extends the FuncExpr type by replacing
the former `getParamPatterns` accessor with separate `getArgParamPatterns`
and `getBodyParamPatterns`, which retrieve the argument name patterns and
body parameter binding patterns respectively.



Swift SVN r3098
2012-11-01 21:53:15 +00:00
Eli Friedman
b62d47a2e5 Rewrite the way we build capture list so we don't miss capturing "this". <rdar://problem/12583581>.
Swift SVN r3093
2012-10-30 22:33:18 +00:00
John McCall
bdf2730f78 Add an 'objc' method, which is currently only allowed on
classes and methods.

Swift SVN r3087
2012-10-30 00:17:50 +00:00
Jordan Rose
cbf72166ba Swallow semicolons after decls when in a container.
Outside of a container, semicolons after decls are just parsed as SemiStmts.
Inside a container, though, we only allow decls...but we should still allow
trailing (delimiting?) semicolons.

If you have multiple semicolons in a row, though, that's probably a typo,
so parseDecl will now also complain (error) if it sees a semicolon where
a decl is expected.

<rdar://problem/12540877>

Swift SVN r3051
2012-10-24 00:54:51 +00:00
John McCall
88e03293cc Change the formal type of subscript declarations to always
pass the index as a separate argument.  This makes it much
easier to work with these things generically.

Swift SVN r2616
2012-08-13 09:02:37 +00:00
Eli Friedman
9e06964c8a Make the TypeLoc constructor which takes just a type private, and expose a
static method to call it, to make it more explicit what is happening.  Avoid
using TypeLoc::withoutLoc for function definitions; instead, just use an empty
TypeLoc.



Swift SVN r2606
2012-08-10 02:09:00 +00:00
Chris Lattner
5184be484f Finish off rdar://12017658 - func() expression should support type inference of argument types.
This implements inference of return types, per the discussion today.



Swift SVN r2572
2012-08-07 05:12:32 +00:00
Doug Gregor
5b03ddf45c Fix diagnostic when we don't encounter a '(' after parsing 'constructor'.
Swift SVN r2566
2012-08-06 16:16:27 +00:00
Eli Friedman
3d0d23b3ce Stop use OneOfElementDecls to represent constructors in structs.
Swift SVN r2518
2012-08-03 00:53:36 +00:00
Ted Kremenek
361870989c Remove 'hasImplicitThis', as it is never read. Not sure if this should actually do something,
so it would be good for someone to look at this.

Swift SVN r2491
2012-07-30 18:30:24 +00:00
Eli Friedman
84e858da4e Fix static member functions so a member of type T has type "metatype<T> -> () -> ()" instead of "() -> ()".
This is much more convenient for IRGen, and gives us a reasonable representation for a static
polymorphic function on a polymorphic type.

I had to hack up irgen::emitArrayInjectionCall a bit to make the rest of this patch work; John, please
revert those bits once emitCallee is fixed.



Swift SVN r2488
2012-07-28 06:47:25 +00:00
Doug Gregor
f66ca78037 Introduce a set of substitutions into GenericMemberRefExpr, so that we
have a record of how the member is being specialized for the given
context. To do this, I also had to patch up the DeclContext for
template parameters.


Swift SVN r2483
2012-07-27 18:49:09 +00:00
Eli Friedman
36b00fb3e3 Fix parsing for requires clauses on generic types. <rdar://problem/11932940>.
Swift SVN r2418
2012-07-23 22:19:41 +00:00
Eli Friedman
c6901f6a6c Initial parsing/AST for generic constructors.
Swift SVN r2387
2012-07-20 23:07:40 +00:00
Eli Friedman
d6a4ba90dd Move TypeLocs to a design where a TypeLoc is a struct containing a type plus
location info for that type.  Propagate TypeLocs a bit more through the AST.



Swift SVN r2383
2012-07-20 21:00:30 +00:00
Eli Friedman
e592e07f2e Compute full SourceRanges for Decls.
Swift SVN r2376
2012-07-19 22:27:13 +00:00
Eli Friedman
361f931a16 Start propgating TypeLocs from the parser into the AST.
Swift SVN r2372
2012-07-19 02:54:28 +00:00
Eli Friedman
f1f67db652 Big cleanup for how we handle computing types for functions and semantic
analysis for patterns.

Major changes:
1. We no longer try to compute the types of functions in the parser.
2. The type of a function always matches the type of the argument patterns.
3. Every FuncDecl now has a corresponding FuncExpr; that FuncExpr might not
   have a body, though.
4. We now use a new class "ExprHandle" so that both a pattern and a type
   can hold a reference to the same expression.

Hopefully this will be a more reasonable foundation for further changes to
how we compute the types of FuncDecls in generics and for the implementation
of type location information.



Swift SVN r2370
2012-07-19 02:09:04 +00:00
Doug Gregor
27e3a03525 Implement parsing, AST, and basic validation of requires clauses
within generic parameter clauses, e.g.,

  func f<T requires T : P1, T : P2>() {}




Swift SVN r2369
2012-07-18 23:36:56 +00:00
Eli Friedman
77751012d2 Switch over constructors so that they return a value instead of being a
method to initialize the members.  This doesn't matter so much
for structs (the generated IR is essentially equivalent except for
small structs), but on classes, we don't want to make "new X" generate
code that knows about metadata/destructors/etc for the class X.

Also, make sure classes always have a constructor.  (We haven't really
discussed the rules for implicitly declared constructors, so for now,
the rule is just "generate an implicit constructor if there is no
explicit constructor".  We'll want to revisit this when we actually
design object construction.)



Swift SVN r2361
2012-07-17 00:32:28 +00:00
Eli Friedman
5ff5b40159 Misc pieces of Sema for destructors.
Swift SVN r2350
2012-07-12 02:23:49 +00:00
Eli Friedman
6b4a248f04 Parsing and AST support for destructors on classes.
Swift SVN r2348
2012-07-12 01:26:02 +00:00
Eli Friedman
bc5bb8e9f9 Fix the computation of the type of the elements of a generic oneof.
Swift SVN r2327
2012-07-10 03:25:08 +00:00
Eli Friedman
a54c5493da Per discussion with Doug, add UnboundGenericType and BoundGenericType to represent generic types.
Swift SVN r2304
2012-07-04 01:17:16 +00:00
Doug Gregor
bac5470881 Collate the OneOfType*/ClassType*/StructType*/ProtocolType* members of
the various NominalDecl subclasses into a single NominalType* member
in NominalDecl. Use it to make TypeDecl::getDeclaredType() more
efficient/simpler, and simplify the ProtocolDecl/ProtocolType
interaction along the way.

No functionality change.


Swift SVN r2298
2012-07-03 21:46:52 +00:00
Eli Friedman
4555345440 Add basic parser/AST support for defining generic types.
Swift SVN r2292
2012-07-03 01:34:58 +00:00
Eli Friedman
a1a182e3d9 Initial implementation of member operators. Known limitations: currently only works for operators on structs/classes, the lookup rules aren't completely settled,
and we don't actually check whether it's reasonable to declare a given operator as a member.



Swift SVN r2277
2012-06-29 00:47:33 +00:00
John McCall
668f674bfa Split off a PolymorphicFunctionType from FunctionType. I am
*positive* that the behavior here is blatantly wrong in a lot
of places, but I'm going to leave it to Doug to clean up after me. :)

Swift SVN r2255
2012-06-27 00:22:15 +00:00
Eli Friedman
d85f426693 Initial implementation of static functions on protocols. <rdar://problem/11448251>.
There are currently two places where you can use a static function defined on a protocol:
on an object with the type of the protocol (discarding the base), and on an archetype in a generic function.  The AST for the protocol object case is probably okay;
the AST for the generic case is almost certainly wrong, but that whole area isn't really stable at the moment anyway.  The proposal in rdar://problem/11448251 will
add a third way: operators on protocols will be found by overload resolution.  (Having static functions on protocols opens up the possibility of metaprotocols,
but I don't think I need to worry about that for the moment.)



Swift SVN r2211
2012-06-20 02:49:54 +00:00
Doug Gregor
bf71eeb26d Include the generic parameter list of a function declaration in the
FuncDecl AST, and use it for local name lookup.


Swift SVN r2198
2012-06-18 23:49:40 +00:00
Doug Gregor
ec31aaf04b Parse a generic parameter list within a function declaration, and
introduce the generic type parameters (which are simply type aliases
for a to-be-determined archetype type) into scope for name
lookup. We can now parse something like

  func f<T, U : Range>(x : T, y : U) { }

but there is no semantic analysis or even basic safety checking (yet).




Swift SVN r2197
2012-06-18 22:49:54 +00:00