Commit Graph

21693 Commits

Author SHA1 Message Date
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
Doug Gregor
ec674b3bce Make the implicit 'this' argument [byref] rather than
[byref(implicit)], and rely on type coercion for the implicit object
argument to deal with the implicitness. This is one half of
<rdar://problem/11215969>. 

The other half of <rdar://problem/11215969> requires us to invent some
syntax to allow increment/decrement/assignment to operate on lvalues
without requiring one to write '&'. There are two distinct ideas
gaining traction here:

  - Adding an [assignment] attribute to these operators, which tells
    us both that use of the operators is a statement (not an
    expression) and that the byref argument (either on the left, or
    the only argument).

  - Allowing operators to be written as member functions, so that they
    get the same treatment as "a.b".

The former seems like the better option.



Swift SVN r1819
2012-05-12 00:19:22 +00:00
Doug Gregor
a49d6c88c8 Introduce a conversion-to-supertype expression to capture conversions
from a protocol to a protocol it inherits. This is a far simpler
operation that the general type-erasure expression, so generate this
AST when we can.


Swift SVN r1813
2012-05-11 17:25: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
3e7b52d025 Implement support for coercing a value of a given type T to a protocol
P, so long as T conforms to the protocol P.



Swift SVN r1797
2012-05-10 18:55:30 +00:00
Doug Gregor
88b214d020 Revert r1792; it's missing a file :(
Swift SVN r1795
2012-05-10 17:13:44 +00:00
Doug Gregor
f4f2f9f570 Implement support for coercing a value of a given type T to a protocol
P, so long as T conforms to the protocol P.


Swift SVN r1794
2012-05-10 16:15:34 +00:00
Eli Friedman
bfe3f8446d Fix PrettyStackTraceDecl so it doesn't crash for a NamedDecl without a name.
Swift SVN r1785
2012-05-09 02:09:21 +00:00
Chris Lattner
a5030c00cb minor pedantic tidying up.
Swift SVN r1783
2012-05-09 00:53:46 +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
22ef9b45c7 Avoid using TypeBase* directly in a case where it isn't necessary.
Swift SVN r1775
2012-05-08 21:12:28 +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
Chris Lattner
96f6398f8d rename Diagnostics.cpp -> DiagnosticList.cpp, it keeps confusing me.
Swift SVN r1773
2012-05-08 18:29:02 +00:00
Chris Lattner
d91626180f fix up \n printing in interpolated_string_literal_expr ast dumps
Swift SVN r1771
2012-05-08 17:10:27 +00:00
Chris Lattner
79cf8ed4fb add a fixme explaining what is going on.
Swift SVN r1760
2012-05-05 23:41:55 +00:00
Chris Lattner
d77d0d3fe3 refactor SourceRange printing out of Verifier.cpp into methods on SourceRange and SourceLoc.
Swift SVN r1752
2012-05-05 21:08:44 +00:00
Chris Lattner
1357aea129 remove extra blank line AST-dumping sequence_expr.
Swift SVN r1751
2012-05-05 19:59:22 +00:00
Eli Friedman
f75e305a20 Add ScalarToTupleExpr to represent an implicit conversion from a scalar to a tuple, with or without default arguments. Make Sema and IRGen work with them.
I'm not completely sure this is the representation we want, but it isn't much code to rip out if we decide to represent it some other way.

While I'm in the area, also fix a case where tuple->tuple conversion wasn't working.



Swift SVN r1748
2012-05-05 00:50:06 +00:00
Chris Lattner
2f44c0038c Initial stab at implementing string literal interpolation for simple expressions,
e.g. "foo is \(i+j)".  This implements rdar://11223686

Doug implemented all the hard parts of this.  I ripped out support for nested string
literals (i.e. string literals within an interpolated string), which simplified the
approach and defined away some problems with his patch in progress.  I plan a few refinements
on top of this basic patch.



Swift SVN r1738
2012-05-04 05:53: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
e6177f35a9 Get rid of the outdated notion of type lookup in Module. <rdar://problem/11026489>.
Swift SVN r1734
2012-05-04 00:41:54 +00:00
Eli Friedman
a8128aed25 A couple more minor tweaks to dumping for PatternBindingDecls.
Swift SVN r1719
2012-05-02 20:58:22 +00:00
Eli Friedman
4671ed57a7 Make dumping a PatternBindingDecl also print the pattern. Fix a missing close-paren dumping PatternBindingDecls. Part of <rdar://problem/11361233>.
Swift SVN r1718
2012-05-02 20:54:42 +00:00
Chris Lattner
46c94377f1 Add support for var decls in the initializer of a c-style for loop,
implementing rdar://11360347 / 11349750.  C-style for loops could be
further enhanced by allowing a comma-separated list of statements in
the increment, but this isn't something I plan to do in the short term.


Swift SVN r1713
2012-05-02 05:44:58 +00:00
Eli Friedman
48c1cbbe6b Make the type of VarDecls match the declared type of the variable/parameter/etc. <rdar://problem/11125010>.
Swift SVN r1680
2012-04-28 01:26:19 +00:00
Chris Lattner
615ca4a360 implement the rest of character literal support, and enhance Char to be character literal
compatible.  This wraps up rdar://11305635, though some cleanup of the testsuite can now be done.


Swift SVN r1672
2012-04-27 06:18:30 +00:00
Doug Gregor
86cf79a746 Add a range subscript operation for SliceInt64 that produces a slice, e.g.,
a[5..9]

will return a 4-element slice of the array a. Addresses
<rdar://problem/11329415>.


Swift SVN r1665
2012-04-27 00:07:52 +00:00
Chris Lattner
20663a8aff introduce a new abstract LiteralExpr base class shared among the literals,
simplifying some code that previously enumerated all of them.


Swift SVN r1664
2012-04-26 23:04:24 +00:00
Eli Friedman
e33b1aac24 Don't try to synthesize an expression for a return statement which doesn't have one. <rdar://problem/11315114>.
Swift SVN r1639
2012-04-25 22:58:06 +00:00
Doug Gregor
a04776044e Teach the import mechanism that it's rude to parse the same library
multiple times, as well as teaching the name lookup mechanism that
it's similarly rude to report ambiguous results because it searched
the same import twice. Fixes <rdar://problem/11287213>.

Yes, this is a bit of an ugly hack.


Swift SVN r1610
2012-04-24 22:36:17 +00:00
Doug Gregor
e1b8daa717 Rework 'foreach' AST to reflect how IRgen actually wants it to look,
rather than how I felt like generating it.


Swift SVN r1599
2012-04-24 20:42:17 +00:00
Doug Gregor
f997a781bf Parsing and basic AST representation for 'foreach' statement.
Swift SVN r1594
2012-04-24 18:12:44 +00:00
John McCall
c7b7c085bd Following IR gen's motivated lead, split Builtin.store
into Builtin.assign and Builtin.init operations.

Swift SVN r1593
2012-04-24 09:51:05 +00:00
John McCall
becacee265 MemberRefExpr can only refer to a VarDecl for now.
Swift SVN r1588
2012-04-24 08:16:46 +00:00
Chris Lattner
a1d7ca3a8d Fix a crash on an overly large integer now that they are a warning instead of an error.
Add a testcase for rdar://11297273, which was a bugfix in StringRef (LLVM r155329)


Swift SVN r1555
2012-04-23 00:32:14 +00:00
Doug Gregor
b237823246 Implement load and store builtins, which we use to provide get() and
set() functions for UnsafePointerInt.


Swift SVN r1533
2012-04-20 17:58:23 +00:00
Doug Gregor
95cdc20902 Member expressions (which refer to properties) require their bases to
be lvalues (materializing them if necessary), as we do with subscript
expressions. Introduce a verifier for member expressions to make sure
this property holds.

Note that there is a slight regression in semantic analysis for
assignments to properties, because we no longer detect some cases of
writing into a property that should not be set. The general solution
to the problem is covered by <rdar://problem/11259972>.



Swift SVN r1530
2012-04-20 15:48:39 +00:00
Doug Gregor
59fab3f97c Teach the subscript expression verifier to check the type of the
subscript expression itself.


Swift SVN r1529
2012-04-20 15:35:30 +00:00
Doug Gregor
b0616a72bb Clean up the AST for subscript expressions in a few ways:
- Ensure that the base is always an lvalue, materializing it if necessary
  - Give appropriate lvalue qualifiers to the subscript expression
  - Make sure to write the converted indices back into the AST

Finally, introduce a verifier for subscript expressions.


Swift SVN r1528
2012-04-20 15:33:46 +00:00
Eli Friedman
7610d26be3 A couple minor tweaks to newlines in AST dumping.
Swift SVN r1522
2012-04-20 00:57:40 +00:00
Eli Friedman
be602fcd05 Get rid of the implicit BraceStmt for the TranslationUnit; instead, have the TranslationUnit directly store a list of decls.
Swift SVN r1521
2012-04-20 00:17:13 +00:00
Eli Friedman
596f494f51 Add missing getLocStart() implementation for TopLevelCodeDecl.
Swift SVN r1520
2012-04-20 00:13:11 +00:00
Doug Gregor
6122a9f5e3 Introduce an overloaded subscript expression type, to cope with cases
where overloading based on the indices is insufficient to select an
overload candidate. Implement type coercion for overloaded subscript
expressions, so that the context can help push overload resolution
along.


Swift SVN r1516
2012-04-19 23:43:44 +00:00
Doug Gregor
cd7be4edf1 Add an AST for subscript expressions; no real type checking yet.
Swift SVN r1512
2012-04-19 22:07:42 +00:00
Chris Lattner
cbc1eac438 irgen parser and sema support for for statements.
Swift SVN r1505
2012-04-19 21:43:46 +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
John McCall
4c15635046 Finish type-checking for new[] expressions.
Swift SVN r1502
2012-04-19 21:05:43 +00:00