Commit Graph

28382 Commits

Author SHA1 Message Date
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
a53aa62c82 Fix a minor inconsistency in how ASTs are built for REPL printing.
Swift SVN r1513
2012-04-19 22:09:12 +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
a5e1b4c645 Fix the REPL, which I accidentally broke. Add a test so it doesn't break by accident again.
Swift SVN r1504
2012-04-19 21:30:23 +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
John McCall
66318f5e12 First round of type-checking for new-expressions: form
the appropriate slice type and check the bounds.  The
first bound must be a literal or a type with a
getArrayBoundValue method, which has the same recursive
nature as getLogicValue (i.e. it can return a type that
has a getArrayBoundValue that returns an integral type,
but that's it;  it's capped at one hop).  The rest
of the bounds must be empty (meaning a slice) or
constant under the same conditions as fixed-size
array types.

Swift SVN r1501
2012-04-19 21:05:37 +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
Ted Kremenek
e161141731 Per Doug's feedback, refine diagnostics when we cannot find a unary or
binary operator for a given set of argument types.  When the argument types
are not dependent or error types, include them in a short single error
diagnostic, and not separated in a separate note.

Swift SVN r1488
2012-04-19 04:31:21 +00:00
Eli Friedman
89752e6dd4 REPL printing for structs and tuples.
Swift SVN r1486
2012-04-19 02:21:02 +00:00
Eli Friedman
3672f0db34 Fix tests. Make REPL printing work with lvalues.
Swift SVN r1485
2012-04-19 01:30:25 +00:00
Eli Friedman
acc17d69aa Initial implementation of the "print" part of the REPL.
Swift SVN r1484
2012-04-19 01:13:37 +00:00
Doug Gregor
b7b8f171b3 Treat a function application A(b) as a coercion of the expression 'b'
to the type named by A (when A is in fact a direct reference to a
type). If that coercion would fail, then fall back to invoking a
constructor. Fixes <rdar://problem/11272190>.



Swift SVN r1472
2012-04-18 17:04:34 +00:00
Doug Gregor
0c95e915a2 When calling an object of metatype type, consider as overloading
candidates both the elements of a oneof and any methods with the same
name as the oneof (which is our current hack for a constructor).

Given var x : Int, we can now write Double(x) rather than Double.Double(x).


Swift SVN r1469
2012-04-18 15:26:57 +00:00
Doug Gregor
819d03a4fb When a member name (e.g., Double.Double) matches the name of a oneof
element, add that element as a member lookup result but don't stop
there: also find extension functions with that same name.

Fixes <rdar://problem/11270370>.


Swift SVN r1468
2012-04-18 15:05:30 +00:00
John McCall
71157c65d5 Add parsing support, but no type-checking or IR-generation,
for new expressions.

Swift SVN r1466
2012-04-18 08:09:18 +00:00
John McCall
6133630544 When type-checking a slice type, "desugar" it to a type that is
generic over the type of the base.  By "generic" I mean that it's
looked up by prepending the word "Slice" to the name of the base
type.

Swift SVN r1464
2012-04-18 08:09:10 +00:00
Ted Kremenek
ee0e03adc1 Remove unnecessary cast<>s.
Swift SVN r1451
2012-04-17 23:06:34 +00:00
Ted Kremenek
9cc9c3358f Enhance diagnostic for failed overload resolution with operator calls by
printing the operator, adjusting the diagnostic to point to the operator
and not the second operand, properly highlighting the ranges of the operands,
and printing out the types of the operands when appropriate.

Printing out the types is very useful when trying to understand the mismatch.

Note: I only partially know what I am doing at this stage.  This feels a bit
kludgy, as the "cast<>"s reek of not enough implicit invariants being documented
in the ASTs themselves.

Fixes <rdar://problem/11266762>

Swift SVN r1449
2012-04-17 22:31:09 +00:00
Doug Gregor
3243108518 Introduce an new expression, MemberRefExpr, that refers to a
member of an object. This expression kind is currently used to refer
to properties within an object, but will eventually be extended to
refer to fields as well (once we make StructDecl real).


Swift SVN r1445
2012-04-17 00:35:06 +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
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
511195b1be Traverse the getter/setter of a VarDecl, so that we get type checking
for these functions. And now that it's actually type-checked, build
the getter's AST properly.


Swift SVN r1416
2012-04-13 18:16:15 +00:00
Eli Friedman
9bf8dcf0f1 Delete some dead code.
Swift SVN r1412
2012-04-13 01:05:12 +00:00
Eli Friedman
1569d73cb2 Fix a crash involving extensions.
Swift SVN r1411
2012-04-13 00:48:53 +00:00
Doug Gregor
ba56d2c0b1 Implement support for lookup of members of the current
oneof/struct/protocol within a static method. The lookup is performed
on the metatype (as one would get when using qualified syntax
Type.member). Add tests to verify that this provides proper
overloading behavior.

As a drive-by, actually set the type of the implicit 'this' variable
during name binding for a non-static method.



Swift SVN r1394
2012-04-11 18:22:53 +00:00
Doug Gregor
13aa703185 Explicitly define a move constructor for SemaCoerce::CoerceDiagnostic,
for compilers that don't implement the rules for implicitly defining
one (e.g., Xcode 4.3 Clang).


Swift SVN r1392
2012-04-11 16:58:44 +00:00
Doug Gregor
7e9b7da0ca Remove the general diagnostic-suppression mechanism. Instead,
introduce a simple suppression mechanism into the type-coercion code,
which is the only place we should need it.


Swift SVN r1388
2012-04-11 14:31:40 +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
Ted Kremenek
352453a53b Revert "Fix a bunch of "has virtual functions but non-virtual destructor" warnings"
Swift SVN r1376
2012-04-11 00:02:16 +00:00
Ted Kremenek
8a61ea1fd0 Fix a bunch of "has virtual functions but non-virtual destructor" warnings
Swift SVN r1373
2012-04-10 23:53:46 +00:00
Doug Gregor
ee0a2d2184 Robustify the lookup of members within a metaclass ever so slightly,
by not allowing name lookup to return find struct or tuple members
(which make swift crash).


Swift SVN r1370
2012-04-10 23:34:27 +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
Eli Friedman
6348a5a372 A bit of minor hacking to get print("hello") working.
Swift SVN r1355
2012-04-10 02:06:33 +00:00
Eli Friedman
bb597c7a37 Minor cleanup.
Swift SVN r1354
2012-04-10 01:47:45 +00:00
Chris Lattner
5650d08ddf implement parsing, AST, and sema support for simple strings,
no irgen yet.


Swift SVN r1351
2012-04-10 01:25:51 +00:00
Chris Lattner
65b400e30d introduce a new "Builtin.RawPointer" type, which corresponds to LLVM's "i8*" type,
and is just an unmanaged pointer.  Also, introduce a basic swift.string type.

This is progress towards rdar://10923403 and strings.  Review welcome.



Swift SVN r1349
2012-04-10 00:52:52 +00:00
Doug Gregor
c24d6ec8c4 Factor OverloadSetRefExpr into an abstract base class covering the
notion of a reference to a set of declarations. Introduce one derived
class, OverloadedDeclRefExpr, which covers the only case we currently
handle for overload resolution [*]: a direct (unqualified) reference
to an overloaded set of entities. Future subclasses should handle,
e.g., overloaded member references such as a.b or a.b.c.

[*] Ugly hacks for static methods notwithstanding


Swift SVN r1345
2012-04-09 17:16:11 +00:00
Doug Gregor
6379980cea Pull the lvalue-to-rvalue conversion into the type coercion
logic. This eliminates spurious diagnostics when attempting to coerce
(for overload resolution) between lvalues and rvalues. Also, improve
error recovery and diagnostics when dealing with an incorrect '&' in
the source.


Swift SVN r1344
2012-04-09 15:41:45 +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
John McCall
72c423fee4 Fix a bug where we were failing to mark the variable associated with a heap l-value
as heap, and add a test case to verify that we release the owner of the reference.

Swift SVN r1339
2012-04-06 07:07:34 +00:00
Doug Gregor
2a2059db45 Provide a more specialized diagnostic (+ tests) when coercion fails
to resolve an overloaded reference that is not called.


Swift SVN r1335
2012-04-05 21:15:43 +00:00
Doug Gregor
0f3584acd6 Downgrade integer overflow diagnostic to a warning, and don't let it
have any effect on overload resolution.


Swift SVN r1329
2012-04-05 19:59:14 +00:00
Eli Friedman
f477cf588e Introduce the notion of the "main" module, i.e. the module which defines main(). Disallow top-level statements in modules other than the main module. Fix IRGen to generate a main() function in the main module, and implement top-level statements. Get rid of the main() mangling hack. Part of <rdar://problem/11185451>.
I haven't really carefully considered whether existing type-checking etc. is correct for the main module (I think the name-binding rules need to be a bit different?), but it seems to work well enough for the obvious cases.

This is enough to get the one-liner "println(10)" to print "10" in "swift -i" mode, although the path to swift.swift still needs to be explicitly provided with -I.



Swift SVN r1325
2012-04-05 00:35:28 +00:00
Eli Friedman
22b7cd05f5 Some minor incremental improvements for module import. Allow explicitly importing Builtin, and implicitly import swift for any module which doesn't explicitly import Builtin or swift. Fixes <rdar://problem/11185519>.
Swift SVN r1323
2012-04-04 21:56:40 +00:00
Doug Gregor
5cf0a09e1a Allow type coercion from one function type to another function type,
so long as the input and result types are equivalent modulo renaming
of labels. This conversion is a no-op.


Swift SVN r1318
2012-04-03 17:51:41 +00:00
Doug Gregor
9c4f9b3cd4 Remove some uninteresting FIXMEs in the type-coercion code
Swift SVN r1317
2012-04-03 14:59:19 +00:00