Commit Graph

1198 Commits

Author SHA1 Message Date
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
Eli Friedman
6abecd43cb Minor cleanup.
Swift SVN r2003
2012-05-25 22:38:22 +00:00
Eli Friedman
95838dca5d Move the SequenceExpr transformation from the expression pre-check into the main expression type-checking visitor.
Swift SVN r2002
2012-05-25 22:27:50 +00:00
Eli Friedman
2947962120 Fix getLoc() for DotSyntaxCallExpr.
Swift SVN r1999
2012-05-25 21:22:41 +00:00
Doug Gregor
0062c84351 Introduce ExistentialMemberRefExpr for references to the members of
values of existential type, e.g.,

  var x : Printable
  x.print()

Existential member references reify the type of the implicit object
argument (implicitly, because we have no way of expressing this in the
type system), and replace the types of any other archetypes
with existential types that (don't, but will eventually) conform to
the protocols to which the archetypes conform.



Swift SVN r1963
2012-05-23 23:06:34 +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
c68c9da1b6 Introduce ThisApplyExpr, an ApplyExpr meant for the various forms of
application expressions that provide a 'this' parameter to a
method. There will eventually be more than just DotSyntaxCallExpr, to
capture the other syntactic (and implicit) forms.


Swift SVN r1924
2012-05-22 00:25:40 +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
6e69e27975 Kill ScalarToTupleExpr, which is no longer in use.
Swift SVN r1881
2012-05-17 01:50:48 +00:00
Eli Friedman
d4750d9014 Finish off the semantic analysis of vararg tuples.
Swift SVN r1880
2012-05-17 01:44:27 +00:00
Eli Friedman
7614b53e9f Semantic analysis, part 1b.
Swift SVN r1878
2012-05-17 00:58:53 +00:00
Eli Friedman
33f20a14e0 Add NewReferenceExpr, for allocating class objects.
Swift SVN r1867
2012-05-16 01:36:03 +00:00
Doug Gregor
056ba286eb Implement subtyping rules that allow one to convert a function type to
another function type, so long as the source is a subtype of the
target. The subtyping relation is fairly obvious, allowing parameter
renaming, qualification conversions for lvalue types, and
protocol-conformance conversions (at the top level of function
types). It is a strict subset of the allowed type coercions.

The representation of FunctionConversionExpr is temporary. It will
need to account for the capture of the source of the conversion in the
trivial-trivial case.



Swift SVN r1839
2012-05-14 19:10:22 +00:00
Doug Gregor
59db25658a Ban the use of SuperConversionExpr to produce lvalues, since that is,
in general, not sound. For the limited cases where we did use this
expression kind on lvalues (member access or instance method
invocations on a superprotocol), leave the conversion to the client of
their respective AST nodes (MemberRefExpr, DotSyntaxCallExpr). We may
decide to enrich these ASTs in the future with more information about
the conversion path, but it's not clear that it's actually useful
information for, e.g., IRgen.


Swift SVN r1830
2012-05-14 15:38:27 +00:00
Eli Friedman
2a78055566 Second attempt at <rdar://problem/11228914>.
Swift SVN r1820
2012-05-12 00:49:12 +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
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
Chris Lattner
2d99b7cca0 switch LiteralExpr::classof to a range-based check, as suggested by Doug.
Swift SVN r1756
2012-05-05 22:43:21 +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
Eli Friedman
a684be9af7 Per John's comments on r1696, use IGM.getPointerSize(), and add a bit to CapturingExpr for whether the function is captured.
Swift SVN r1700
2012-05-01 02:43:12 +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
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
John McCall
5e31e0df7f When parsing a multi-dimensional array declarator in an expr-new,
update the element type with the computed type.

Swift SVN r1652
2012-04-26 08:07:31 +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
ed4bf70eb7 Fix the source range for DotSyntaxCallExpr when it is modeling an implicit this, repairing an ASTVerifier abort
Swift SVN r1550
2012-04-21 22:24:14 +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
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
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
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
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
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
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
548c2e50c2 Fix the beginning source ranges for dot expressions where the object
argument is the implicit 'this' argument. Add a number of overloading
tests for overloaded member access, which naturally exercises these
source locations.


Swift SVN r1390
2012-04-11 16:17:22 +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
5650d08ddf implement parsing, AST, and sema support for simple strings,
no irgen yet.


Swift SVN r1351
2012-04-10 01:25:51 +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
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
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
bfe7ff2168 Extend the AST walker that performs type coercion to have two modes:
one that performs the coercion on the AST and produces diagnostics for
any problems, and one that simply determines whether the coercion
would succeed. The former already existed (as
TypeChecker::convertToType), while an approximation of the latter was
already implemented as Expr::getRankOfConversionTo(). Unifying these
code paths addresses several issues:

  - Lots of redundancy in the code for computing these two properties,
    which causes bugs. For example, Expr::getRankOfConversionTo()
    wasn't able to handle literals (!).
  - Determining whether a conversion is possible will need the full
    power of the type checker, e.g., to deal with closures in cases
    like:

      func f(g : (int, int) -> int);
      func h() { f({$1 + 0}); }

    Although this is not handled correctly now.

I have opted not to adopt Clang's ImplicitConversionSequence (or
InitializationSequence) design, which computes a record of the steps
needed to perform the conversion/coercion and later applies those
steps, because we don't need that complexity yet. If we start
introducing more implicit conversions into the language, we'll revisit
this decision.



Swift SVN r1308
2012-04-02 21:43:15 +00:00
Doug Gregor
3299d8b176 Eliminate BinaryExpr::getArgTuple(). The argument to a binary
expression will always be a two-element tuple, but it may not always
be a tuple literal. In the near future, it could also be a tuple
shuffle.



Swift SVN r1299
2012-03-30 18:37:02 +00:00
Doug Gregor
c76edd6643 Remove Expr::setDependentType(); it's not really documenting anything,
and with structured dependent types, many more setType() calls
actually would have to be setDependentType() to be documenting.


Swift SVN r1297
2012-03-29 18:57:18 +00:00
Eli Friedman
b65f969193 Replace ":foo" syntax for oneof members with ".foo".
Swift SVN r1288
2012-03-29 01:58:55 +00:00
Doug Gregor
e17398510a Re-pack a few Expr nodes for the inevitable switch to 32-bit source
locations.


Swift SVN r1283
2012-03-28 23:54:38 +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