Commit Graph

2357 Commits

Author SHA1 Message Date
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
Eli Friedman
bb0a98d487 Finish off varargs.
Swift SVN r1892
2012-05-18 00:04:07 +00:00
Doug Gregor
003ee33c52 It is considered poor form to store stack-allocated memory in the AST.
Swift SVN r1885
2012-05-17 15:42:33 +00:00
Doug Gregor
245d2a46f2 Parse an 'inheritance' clause on extensions, oneofs, structs, and
classes, with the same syntax as we have on protocols. This
inheritance specifies explicit conformance to a protocol.

Later, we can allow a class definition to have a single class type
within this list, when we introduce class inheritance.



Swift SVN r1862
2012-05-15 23:39:19 +00:00
Eli Friedman
a5a39860cd Basic parsing plus a bit more of the AST for ClassDecls.
Swift SVN r1860
2012-05-15 22:07:31 +00:00
Eli Friedman
6f045aad2f Throw the switch to use "var" syntax to declare members of structs. This also means we no longer build an implicit extension for every struct decl. Everything seems to be working, but please yell if this breaks anything.
Swift SVN r1851
2012-05-15 03:27:13 +00:00
Doug Gregor
bf03c9af28 Remove byref(implicit). Instead, introduce [assignment], which only
applies to operators whose first parameter is [byref]. Assignments
must return Void, and have their first arguments implicitly treated as
an lvalue.

As part of this, add the various C compound operators (+=, -=, *=, /=,
&=, |=, and ^=) to the standard library.



Swift SVN r1846
2012-05-15 00:55:32 +00:00
Doug Gregor
515bcb44e9 Allow subscript declarations in protocols, which require a suitable
subscripting operator. Such protocols are fairly useful without
associated types, however.


Swift SVN r1831
2012-05-14 15:56:58 +00:00
Eli Friedman
d98c55f665 Followup to r1819: there was an issue with that commit I hadn't spotted before related to mismatched types. This commit solves it for FuncDecls, but not SubscriptDecls (see the FIXME).
Swift SVN r1822
2012-05-12 02:52:14 +00:00
Eli Friedman
01a18f6c7a Use VarDecls to represent struct members, and MemberRefExprs to represent member access in structs. Eliminate the horrible hack which was LookThroughOneOfExpr.
Swift SVN r1808
2012-05-11 03:08:15 +00:00
Doug Gregor
70bfc235b8 Implement protocol inheritance, e.g.,
protocol Document { var title : String }
  protocol Versioning { func bumpVersion() }
  protocol VersionedDocument : Document, Versioning { }

This commit covers the basic functionality of protocol inheritance, including:
  - Parsing & AST representation
  - Conforming to a protocol also requires conforming to its inherited
  protocols
  - Member lookup into a protocol also looks into its inherited
  protocols (results are aggregated; there is no name hiding)
  - Teach ErasureExpr to maintain lvalueness, so we don't end up
  performing a silly load/erase/materialize dance when accessing
  members from an inherited protocol.




Swift SVN r1804
2012-05-11 00:00:50 +00:00
Doug Gregor
169dd225bf Switch Parser::parseProtocolBody() over to use parseDecl(), with a
giant list of "you can't do that" restrictions. Update grammar
accordingly, killing off decl-var-simple.



Swift SVN r1781
2012-05-09 00:35:53 +00:00