Commit Graph

2727 Commits

Author SHA1 Message Date
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
Eli Friedman
7cf73fb29b Comment tweaks.
Swift SVN r1787
2012-05-09 19:30:05 +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
Eli Friedman
77fa49ec2b Introduce StructDecl and StructType; use them for structs instead of OneOfDecl/OneOfType. To keep this patch small, I'm leaving in LookThroughOneOf etc. for the moment, but that's next on the agenda.
Swift SVN r1780
2012-05-09 00:27:44 +00:00
Doug Gregor
5f2344afe0 Introduce ProtocolDecl, which describes (*gasp*) a protocol. Move the
guts of ProtocolType over to ProtocolDecl.


Swift SVN r1778
2012-05-08 23:28:55 +00:00
Eli Friedman
4ca443d0f5 Add OneOfDecl; use it as a DeclContext for OneOfElementDecls instead of OneOfType, and get rid of the implicit TypeAliasDecl. Add TypeDecl as a base class for OneOfDecl and TypeAliasDecl (and StructDecl, once we have it). Adjust a whole bunch of stuff to this new scheme.
Swift SVN r1774
2012-05-08 21:09:42 +00:00
Eli Friedman
fd62cbac65 Refactor extension parsing so it's centralized, and so we parse the body of the extension in the correct DeclContext.
Swift SVN r1745
2012-05-04 20:59:50 +00:00
Chris Lattner
774a557e5c Merge NamedDecl into ValueDecl, rdar://11379147.
Swift SVN r1737
2012-05-04 04:50:53 +00:00
Eli Friedman
ff2bef9d62 Extend variable declaration grammar to allow "var a, b : Int, c, d : Double". <rdar://problem/11349535>.
I've tried to be pretty strict about exactly which cases we accept here, to avoid any confusing cases.



Swift SVN r1721
2012-05-03 00:49:16 +00:00
Eli Friedman
596f494f51 Add missing getLocStart() implementation for TopLevelCodeDecl.
Swift SVN r1520
2012-04-20 00:13:11 +00:00
Doug Gregor
cd43490fb3 Implement semantic analysis for subscript expressions, using overload
resolution to pick the best subscript getter/setter pair. Does not yet
allow type coercion to influence overload resolution.



Swift SVN r1515
2012-04-19 23:01:04 +00:00
Eli Friedman
6a088458e8 Add a big doxygen comment for TopLevelCodeDecl.
Swift SVN r1511
2012-04-19 22:07:34 +00:00
Eli Friedman
d5e7784010 Get rid of isModuleScope bit, since we don't like scattering bits across the AST; as a replacement, introduce TopLevelCodeDecl, which provides a DeclContext for all expressions and statements at the top level. <rdar://problem/11259941>.
Swift SVN r1503
2012-04-19 21:22:12 +00:00
Doug Gregor
8ff3075ce4 Teach getter/setter functions about their corresponding subscript
declaration, so they can mangle themselves appropriately.


Swift SVN r1499
2012-04-19 20:56:22 +00:00
Doug Gregor
846aa7e162 Diagnose attempts to declare subscript operations outside of a type context.
Swift SVN r1497
2012-04-19 20:41:42 +00:00
Doug Gregor
06881faea2 Introduce an AST node for subscript declarations, and verify that the bodies of the getter and setter are being type-checked.
Swift SVN r1496
2012-04-19 20:29:48 +00:00
Eli Friedman
37de44a35d Implement changes to parsing/sema/etc so that we can implement a REPL and the main module parses the same way as a REPL.
Next step: implement an actual REPL.



Swift SVN r1441
2012-04-16 23:52:01 +00:00
Doug Gregor
83c1611852 VarDecls, even property VarDecls, are always lvalues. Make it so.
Swift SVN r1438
2012-04-16 23:18:48 +00:00
Doug Gregor
970d3d2564 A property is only an lvalue when there is a setter.
Swift SVN r1437
2012-04-16 17:57:00 +00:00
Doug Gregor
4fc32fd9b4 For a function that is either a getter or setter for a variable,
provide a mapping back to that variable. Teach the mangler to provide
a special mangling for such functions (__getVarName,
__setVarName). The mangling will undoubtedly change later, but the
point is that it will need to match the functions generated for
a resilient variable.


Swift SVN r1432
2012-04-14 00:11:04 +00:00
Doug Gregor
0fdb4d00fc When we parse a 'var' declaration, we add all of the VarDecls and the
PatternBindingDecl to the DeclContext. Do the same for the get/set
functions for a property, so we don't need to perform 'deep' setting
of the DeclContext. This is simpler, although it makes pretty-printing
the AST a bit more difficult.



Swift SVN r1428
2012-04-13 22:22:17 +00:00
Doug Gregor
bbd5dfcfdf Allow variables with a getter or setter to be declared in a
struct/oneof/class extension, making them instance methods. Normal
variables are still not allowed in these contexts, however.

The fact that we set DeclContexts late causes some consternation here,
because it's not clear just how far we need to recurse in
DeclContext. I've done enough to make properties work, but I'm still
rather uneasy about the current state of affairs.


Swift SVN r1423
2012-04-13 21:45:27 +00:00
Doug Gregor
7823cd48eb Wire properties into the AST for VarDecl, and add dumping support. No
tests until we start type-checking something.


Swift SVN r1410
2012-04-13 00:27:22 +00:00
Eli Friedman
361481835c Introduce a notion of module scope declarations; use it where appropriate instead of checking for a local declcontext.
Swift SVN r1380
2012-04-11 02:52:40 +00:00
Doug Gregor
a3c34c5dbd Introduce an AST node (OverloadedMemberRefExpr) that represents dot
syntax when name lookup finds multiple candidates. Overload resolution
is then used to select the best candidate and map the overloaded
member reference expression down to DotSyntaxCallExpr or
DotSyntaxBaseIgnoredExpr, as appropriate.

This implements part of <rdar://problem/11071641>, so that simple
overload resolution works, but there is still a bit of cleanup to do.



Swift SVN r1366
2012-04-10 22:52:41 +00:00
Chris Lattner
fbfb76a515 rename 'plus' methods to 'static' methods, resolving:
<rdar://problem/10718220> Need a better name than 'plus' for "static" functions



Swift SVN r1340
2012-04-06 17:50:43 +00:00
Eli Friedman
94244131f7 Remove ElementRefDecl and DeclVarName. Add the replacement, PatternBindingDecl. Use proper pattern parsing for variable declarations. Uniformly use PatternBindingDecl for variable initialization. Adapt type-checking and IRGen for this new style of variable declaration. <rdar://problem/11124980>.
Swift SVN r1312
2012-04-02 23:49:28 +00:00
Doug Gregor
f370accf59 Introduce the notion of structured dependent types, such as a tuple
type with one or more elements of dependent type. Previously, an
expression such as (x, 5) would have the (unstructured) dependent
type, limiting our ability to type-check the subexpression 'x'
early. Now, if 'x' has type 'int' (for example), this expression will
now have the type (int, <<unstructured dependent type>>).

Extend coercion of a tuple to tuple type to handle coercion to
(structured) dependent tuple types, coercing element-by-element. This
code is very lightly tested and may still need to be restructured.




Swift SVN r1294
2012-03-29 16:26:04 +00:00
Doug Gregor
4cc616f2be Rename the DependentType class to UnstructuredDependentType, because
this type is only going to cover dependent types for which there is
absolutely no structure. Still no functionality change.


Swift SVN r1292
2012-03-29 14:14:48 +00:00
Eli Friedman
29f3fca950 First iteration of CaptureAnalysis.
Swift SVN r1284
2012-03-29 00:24:03 +00:00
Doug Gregor
5fffa75e7b Remove empty throw specifications from all of the overloaded new operators; reduces code size by 8k
Swift SVN r1282
2012-03-28 22:00:02 +00:00
John McCall
1a4b945a14 Flag in a ValueDecl whether it's ever been used as an
l-value or a heap l-value, except to immediate convert
it to an r-value or a non-heap l-value.

Swift SVN r1237
2012-03-19 08:28:42 +00:00
Chris Lattner
6185ab6d50 move getImplicitThisDecl to FuncDecl where the other 'this' handling stuff goes.
Swift SVN r1233
2012-03-19 05:43:20 +00:00
Chris Lattner
1884e4943f refactor some code out of Sema into AST.
Swift SVN r1225
2012-03-17 23:07:00 +00:00
Chris Lattner
17ea0a6670 finish my pass over LangRef, updating it and changing it and the parser to keep the grammars in sync.
Swift SVN r1132
2012-03-01 16:55:09 +00:00
Chris Lattner
01a53ac0d5 improve comment.
Swift SVN r1113
2012-02-13 22:27:52 +00:00
John McCall
d0f4d86f3e Use LValueType everywhere instead of the l-value value kind.
Kill off TypeJudgement.  Various fixes and improvements.



Swift SVN r1107
2012-02-06 22:47:08 +00:00
John McCall
ce7780af04 I don't think we're really getting anything out of ArgDecl
at the moment.  We can put it back if I'm wrong.



Swift SVN r1100
2012-01-26 02:08:52 +00:00
Chris Lattner
7c36780e35 sink the 'Init' field from ValueDecl down to VarDecl (as Init) and FuncDecl (as Body),
liberating the other ValueDecl's from its baggage.


Swift SVN r1079
2012-01-18 07:34:54 +00:00
Chris Lattner
7d0f7d53f9 improve type safety and specificity a bit, the body of a function is always a FuncExpr.
Swift SVN r1069
2012-01-18 06:56:53 +00:00
Chris Lattner
cb80e127a6 improve redefinition diagnostics since all type aliases are definitions, not declarations.
Swift SVN r1067
2012-01-18 06:52:15 +00:00
Doug Gregor
ae11ec70f0 Fix CMake build and sync up exception specifications
Swift SVN r1007
2012-01-12 01:08:40 +00:00
Chris Lattner
37cb633b12 Change TypeAliasDecl to be a ValueDecl, whose type is MetaTypeType.
Swift SVN r1004
2012-01-11 07:13:32 +00:00
Chris Lattner
e22a30a130 revert r995: "introduce MetaTypeDecl (though nothing creates it yet)".
After some pondering on this, I can just use DeclRefExpr(TypeAliasDecl) to
represent a named metatype, there is not need to have yet-another decl.  I'm
glad about this, because it didn't seem right.



Swift SVN r999
2012-01-11 05:42:22 +00:00
Chris Lattner
f204abf010 introduce MetaTypeDecl (though nothing creates it yet)
Swift SVN r997
2012-01-06 20:50:56 +00:00
Chris Lattner
8ce4737534 implement "a.b" AST and type checker support. Semantics are that 'a' is evaluated and discard. 'b' is evaluated and returned.
Swift SVN r950
2011-12-21 23:49:30 +00:00
Chris Lattner
17b11e9bbd implement parsing, AST, and LangRef support for 'plus' methods. Dot syntax will need some work though to actually use them.
Swift SVN r949
2011-12-21 23:21:58 +00:00
John McCall
f4ce88878a Remove the reference accessor to ValueDecl::Init.
Swift SVN r945
2011-12-21 03:06:27 +00:00
John McCall
8a8f297bde Basic resilience query.
Swift SVN r937
2011-12-15 00:45:31 +00:00
John McCall
a1f7eefba3 Extract out decl attributes into a separately-allocated structure.
Swift SVN r920
2011-12-10 00:39:10 +00:00