Commit Graph

218 Commits

Author SHA1 Message Date
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
Chris Lattner
b23f4eb4f8 switch from SmallMap to SmallDenseMap.
Swift SVN r2189
2012-06-17 21:22:13 +00:00
Eli Friedman
9d21e367eb Switch strings over to new constructor syntax. Fix a few constructor bugs I found along the way.
Swift SVN r2166
2012-06-07 20:26:16 +00:00
Eli Friedman
64d67103fa One more small fix for constructor name lookup. Make the auto-generated element-wise constructor use the name "constructor".
Swift SVN r2165
2012-06-07 19:50:18 +00:00
Eli Friedman
7965dff03d A few more misc fixes for constructors. Add a testcase.
Swift SVN r2164
2012-06-07 19:36:07 +00:00
John McCall
30f5e36dbc Semantic analysis and AST support for postfix operators.
Also prevent us from including unary operators in the
lookup results for operators written binary-style and
vice-versa.

Swift SVN r2162
2012-06-07 01:00:08 +00:00
Eli Friedman
75907029f1 Add parsing and semantic analysis for a basic ConstructorDecl. Still missing: no IRGen, and semantic analysis to actually call them.
Swift SVN r2159
2012-06-05 23:51:19 +00:00
Eli Friedman
ecc56538b3 Add a basic TypeLoc; start threading it through the parser.
Doug, please double-check that this is going in the right direction...



Swift SVN r2146
2012-06-05 00:11:59 +00:00
Eli Friedman
27f8a5ab62 Teach the parser's handling of scopes to handle local types correctly.
Swift SVN r2138
2012-06-04 19:14:58 +00:00
Doug Gregor
552e5a16dc Introduce the Enumerable protocol, and make each type with a
getElements() method conform to Enumerable specifically.


Swift SVN r2136
2012-06-04 17:33:36 +00:00
Doug Gregor
4ed242a318 Synchronize protocol grammar in parser with the protocol grammar in LangRef.
Swift SVN r2135
2012-06-04 16:48:27 +00:00
Doug Gregor
9abd2340bc Allow an 'inheritance' clause on typealiases, specifying what
protocols the underlying type of the type alias shall conform to. This
isn't super-motivating by itself (one could extend the underying type
instead), but serves as documentation, makes typealiases provide the
same syntax as other nominal types in this regard, and will also be
used to specify requirements on associated types.


Swift SVN r2133
2012-06-04 16:15:47 +00:00
Eli Friedman
ae86d64644 Rename Decl::getLocStart() to Decl::getStartLoc(). Add Decl::getLoc(), which is essentially the location which should be used for diagnostics.
Swift SVN r2105
2012-05-31 23:56:30 +00:00
Eli Friedman
ba4a76038b Make oneofs never implicitly generate an ExtensionDecl. This matters for local oneofs.
Swift SVN r2098
2012-05-31 21:20:56 +00:00
Chris Lattner
53b09c613a Switch type alias to use = for assignment instead of :, which indicates conformance.
This resolves rdar://11547856



Swift SVN r2064
2012-05-30 00:32:23 +00:00
Eli Friedman
85ed3e1868 Only allow extensions and protocols at module scope.
Swift SVN r2062
2012-05-30 00:19:35 +00:00
Eli Friedman
e63a471347 Fix value name-binding so it correctly performs member lookup for expressions which aren't inside a member function.
Swift SVN r2004
2012-05-25 23:42:40 +00:00
Doug Gregor
9096497f0f Rename "dependent type" to "unresolved type" universally. We've been
using the term "unresolved" in expressions for a while, and it fits
for types better than "dependent type."

The term "dependent type" will likely come back at some point to mean
"involves an archetype".



Swift SVN r1962
2012-05-23 19:03:14 +00:00
Doug Gregor
74436a3120 Introduce the implicit 'This' type into protocols, which refers to the
type T that conforms to the given protocol. 'This' is modeled simply
as an associated type.



Swift SVN r1953
2012-05-23 14:45:55 +00:00
Doug Gregor
d37602629e Implement parsing, AST, and conformance checking for associated types
in protocols, e.g.,

  protocol Range {
    typealias Element
    func getAndAdvance() -> Element
  }



Swift SVN r1941
2012-05-22 21:45:58 +00:00
Doug Gregor
a9906ad38f Introduce support for implicit user-defined conversions.
A user-defined conversion function is an instance method that accepts
an empty tuple and returns a value of the type we're converting to,
has the [conversion] attribute, and is named __conversion. The last of
these restrictions is a temporary hack to work around our inability to
perform a lookup across all extensions for "every function with the
conversion attribute", and shouldn't last too long.

As in C++, we only get one user-defined conversion function. Unlike in
C++, a constructor is not (and cannot) be a conversion function.

Introduce NSString <-> String conversion functions, but leave the
runtime implementations as stubs for Dave to fill in.



Swift SVN r1921
2012-05-21 23:36:16 +00:00