Commit Graph

28404 Commits

Author SHA1 Message Date
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
27483ce4e1 s/empty/isEmpty/g for the foreach loop informal protocol, because
function names should start with verbs.


Swift SVN r1607
2012-04-24 21:50:12 +00:00
Doug Gregor
6d5f67c790 Implement IR generation for the 'foreach' loop and convert our fractal
examples over to using the 'foreach' loop. Addresses
<rdar://problem/11259997>.


Swift SVN r1606
2012-04-24 21:37:55 +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
ac188c7d59 Implement type checking for the foreach loop and extend the AST to
hold all of the various expressions and declarations we'll need to
understand its semantics.


Swift SVN r1596
2012-04-24 20:22:36 +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
96d7931f8d Teach capture analysis to look through MemberRefExprs.
Swift SVN r1591
2012-04-24 09:36:54 +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
Eli Friedman
1780f0f1e8 Minor bulletproofing for Sema code for REPL.
Swift SVN r1581
2012-04-24 02:34:35 +00:00
Eli Friedman
36472404b2 Parse swift.swift upfront in the REPL. This has two benefits: one, we error immediately if swift.swift can't be found, or something is wrong with it. Two, it lets us JIT swift.swift upfront, which makes the REPL prompt feel more responsive. <rdar://problem/11305258>.
Swift SVN r1575
2012-04-24 00:55:19 +00:00
Doug Gregor
9fe42c0055 Merge infix precedence/associativity for binary operators, rather than
forcing one to declare, e.g., [infix_left=NNN] on every
declaration. The precedence/associativity will be merged from any
similarly-named operator in translation unit scope or in an imported
module. Fixes <rdar://problem/11261874> very, very narrowly for the
demo.

This implementation is hacky and slow; we'll replace it later with
<rdar://problem/11304699>.



Swift SVN r1570
2012-04-23 23:40:56 +00:00
Eli Friedman
a4de7ddba2 Try a different variant of expression printing. <rdar://problem/11296811>.
Swift SVN r1569
2012-04-23 23:19:25 +00:00
Eli Friedman
86d6ad7b6f Implement Chris's tweaks for expression printing in the REPL. <rdar://problem/11296811>.
Swift SVN r1567
2012-04-23 22:33:42 +00:00
Eli Friedman
4d42b6652a REPL printing for VarDecls. <rdar://problem/11287158>.
Swift SVN r1539
2012-04-21 01:30:12 +00:00
Eli Friedman
1d58c4739a Fix type-checking to handle some cases with tuples which contain lvalues. <rdar://problem/11287167>.
Swift SVN r1538
2012-04-20 21:38:16 +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
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
Doug Gregor
3d2e00d4e7 Remove stale FIXME
Swift SVN r1527
2012-04-20 14:42:03 +00:00
Doug Gregor
458549e043 If the right-hand side of an assignment is not dependent, but the
left-hand side is dependent, coerce the left-hand side to an lvalue of
the right-hand side's object type. This allows us to assign into
lvalues that may be overloaded on the underlying value type, e.g.,
subscripting values and overloaded variables. Fixes <rdar://problem/11285171>.


Swift SVN r1526
2012-04-20 14:39:37 +00:00
Eli Friedman
a2c6150c13 Error recovery for the REPL. Seems to be working reasonably well. <rdar://problem/11269380>.
Swift SVN r1523
2012-04-20 01:14:39 +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
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
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