Commit Graph

889 Commits

Author SHA1 Message Date
Doug Gregor
cc4c7d0fd8 [Clang importer] Stop creating property/subscript getter/setter thunks.
Instead of synthesizing Swift code for the property and subscript
getters and setters we import from Objective-C, just create the
declarations and mark them as being Objective-C (foreign) entry
points. This means that we'll use the Objective-C entry points (via
objc_msgSend).


Swift SVN r8692
2013-09-26 15:58:19 +00:00
Anna Zaks
c2adc1e35b Restructure parsing to ensure that bodiless constructors/destructors/subscripts are fully diagnosed.
Previously, we followed an early exit for bodiless constructors/destructors/subscripts.
This prevented some diagnostics and full AST class setup in SIL parsing mode and for bodiless subscripts in general.

Thanks for the suggestion Dmitry!

Swift SVN r8672
2013-09-25 23:28:52 +00:00
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Argyrios Kyrtzidis
e224667315 Refactor Implicit'ness of expressions.
Introduce a bit in Expr to indicate whether the expression is implicit and decouple the implicitness
of an expression from whether it has a source location or not.

This allows implicit expressions to be able to point at the source location where they originated from.
It also allows decoupling the implicitness of a parent from its children, so for example, an implicit CallExpr
can have an explicit parameter value.

Swift SVN r8600
2013-09-24 20:42:29 +00:00
Doug Gregor
6a1db609e0 Allow [objc] subscripts and emit Objective-C thunks for the getters/setters.
Sema and SILGen; IRGen to follow.


Swift SVN r8589
2013-09-24 02:26:23 +00:00
Joe Groff
c4b4db732f Parse and check raw values on enum cases.
Iff an enum declares a raw type, its cases may declare raw values or else have them assigned to them implicitly by autoincrementing from zero, like in C. If the raw type is float-, string-, or char-literal-convertible, there is no autoincrement, and the raw values must all be explicit. The raw type is rejected if any cases have payloads.

We don't yet diagnose duplicate raw values. That'll come next. We also don't yet serialize or deserialize the raw values. We don't strictly need to do this, since the RawRepresentable protocol conformance will be exported from the module as API, but Jordan pointed out that, for fragile raw values, this would be good for documents/jump-to-definition purposes, so we have a plan for only serializing the literals without having to deal with fully general expression serialization.

Swift SVN r8545
2013-09-21 04:31:26 +00:00
Joe Groff
7d35db8a73 Type-check raw type of enum decls.
Allow the inheritance clauses of enums to reference a non-protocol type as their raw type. For now, only diagnose that the raw type occurs first, that there's only one raw type, that there are no circularities in raw types, like we do for class inheritance, and additionally that the raw type is literal convertible, which we'll require for the raw values of the cases.

Swift SVN r8529
2013-09-20 23:13:07 +00:00
Joe Groff
5d8a7ff9e7 Allow multiple comma-separated enum elements in a 'case' decl.
Introduce an EnumCaseDecl for source fidelity to track the 'case' location and ordering of EnumElementDecls. Parse a comma-separated list of EnumElementDecls after a 'case' token.

Swift SVN r8509
2013-09-20 19:51:13 +00:00
Dmitri Hrybenko
429633b18a Let the type checker create implicit DestructorDecls
Improve the type checker to create implicit DestructorDecls, tighten the
assertion in ImplicitReturnLocation::getImplicitReturnLoc(), and add a verifier
check that a class in a type checked AST always has exactly one destructor.

SILGen used to generate a destructor if the class does not have a
DestructorDecl.  SILGen used to put the ClassDecl inside the SILLocation for
the destructor SIL code.  This is not a very clean solution: in this case
ImplicitReturnLocation SILLocations contain ClassDecl, which is surprising.

rdar://14970972 Implicit destructors should have AST nodes


Swift SVN r8498
2013-09-20 17:34:22 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Chris Lattner
401ff53e70 fix bug that clang noticed:
Decl.cpp:997:59: warning: if statement has empty body [-Wempty-body]
      if (!firstPattern->getType()->isEqual(emptyTupleTy));
                                                          ^



Swift SVN r8388
2013-09-18 04:15:34 +00:00
Doug Gregor
90b8b3e499 Constructor selectors always start with 'init'.
Implement the new rules for mapping between selector names and
constructors. The selector for a given constructor is formed by
looking at the names of the constructor parameters:
  * For the first parameter, prepend "init" to the parameter name and
  uppercase the first letter of the parameter name. Append ':' if
  there are > 1 parameters or the parameter has non-empty-tuple type.
  * For the remaining parameters, the name of each parameter followed
  by ':'.

When a parameter doesn't exist, assume that the parameter name is the
empty string.

And, because I failed to commit it separately, support selector-style
declarations of constructor parameters so that we can actually write
constructors nicely, e.g.:

  // selector is initWithFoo:bar:
  constructor withFoo(foo : Foo) bar(bar : Bar) { ... }



Swift SVN r8361
2013-09-17 22:49:05 +00:00
Argyrios Kyrtzidis
f34166c319 [AST] For SubscriptDecl and ConstructorDecl, have the getLoc() point at the 'subscript'/'constructor' respectively, not at their first parameter.
Swift SVN r8346
2013-09-17 19:52:13 +00:00
Argyrios Kyrtzidis
420cab9bc3 [AST] Move the NameLoc source location from ValueDecl's subclasses into ValueDecl itself.
Swift SVN r8332
2013-09-17 15:34:52 +00:00
Doug Gregor
25bec36f9e Allow dynamic lookup through DynamicLookup.metatype.
Given an object of type DynamicLookup.metatype, allow us to find both
static and instance methods. 

Sema only; SILGen and IRGen changes to come.


Swift SVN r8290
2013-09-16 20:26:02 +00:00
Dmitri Hrybenko
536ed954ad Remove FuncExpr. Add CaptureInfo to FuncDecl. Introduce AnyFunctionRef.
AnyFunctionRef is a universal function reference that can wrap all AST nodes
that represent functions and exposes a common interface to them.  Use it in two
places in SIL where CapturingExpr was used previously.

AnyFunctionRef allows further simplifications in other places, but these will
be done separately.


Swift SVN r8239
2013-09-14 02:15:48 +00:00
Dmitri Hrybenko
5ac875e5dc Add CaptureInfo class that manages capture lists
Swift SVN r8234
2013-09-14 00:22:44 +00:00
Doug Gregor
8d3871098f Fix more vector-stream-flushing issues with extracting Objective-C selectors.
Swift SVN r8200
2013-09-13 16:44:52 +00:00
Doug Gregor
dee0a0491e Property return the string for a zero-argument selector.
Swift SVN r8199
2013-09-13 16:44:05 +00:00
Dmitri Hrybenko
ea75b2ac5f Fix implementation of ValueDecl::isDefinition()
No testcase because this is not testable now -- this function is only used in
diagnostics of value redefinitions, which are broken now for redefinitions of
member functions.


Swift SVN r8187
2013-09-13 03:49:07 +00:00
Dmitri Hrybenko
16ce358562 Sink FuncDecl::getExtensionType() to AbstractFunctionDecl
Swift SVN r8184
2013-09-13 02:57:09 +00:00
Dmitri Hrybenko
0d6d9a0ffb Move the DeclContext base class from FuncExpr to FuncDecl
FuncDecl still has a FuncExpr because capture list is stored in FuncExpr
(which is a CapturingExpr).


Swift SVN r8179
2013-09-13 01:40:41 +00:00
Dmitri Hrybenko
8db6568394 Abstract the fact that both FuncExpr and FuncDecl have a type inside semaFuncDecl()
(Recommit a complete refactoring.)


Swift SVN r8161
2013-09-12 21:01:52 +00:00
Dmitri Hrybenko
9e889d1b56 Revert my commit r8157. It is breaking tests in +Asserts.
Swift SVN r8160
2013-09-12 20:53:00 +00:00
Dmitri Hrybenko
f49f9b0774 Abstract the fact that both FuncExpr and FuncDecl have a type inside semaFuncDecl()
Swift SVN r8159
2013-09-12 20:44:28 +00:00
Dmitri Hrybenko
c69c79084a Move result typeloc and body result type from FuncExpr to FuncDecl
Swift SVN r8153
2013-09-12 18:40:57 +00:00
Dmitri Hrybenko
796eac4b3f Make SILLocation::dump() more informative
Swift SVN r8130
2013-09-12 00:25:32 +00:00
Dmitri Hrybenko
3fb2d14a8e Simplify FuncDecl::getExtensionType() implementation
Replace it with a call to DeclContext::getDeclaredTypeInContext().


Swift SVN r8105
2013-09-11 20:52:52 +00:00
Dmitri Hrybenko
7a4ff53826 getSourceRange(): handle delayed constructor and destructor bodies
Right now we don't delay bodies, but we eventually will.


Swift SVN r8100
2013-09-11 19:13:56 +00:00
Dmitri Hrybenko
abfa512c4f Sink getArgParamPatterns() and getBodyParamPatterns() into AbstractFunctionDecl
Swift SVN r8097
2013-09-11 18:42:28 +00:00
Dmitri Hrybenko
3cc01cf7d6 Introduce AbstractFunctionDecl -- a base class for ConstructorDecl,
DestructorDecl, FuncDecl -- and move some of the common concepts and logic
into it

No functionality change.


Swift SVN r8090
2013-09-11 04:04:01 +00:00
Chris Lattner
55200e5274 Now that Module has its own kind field, drop the various module
discriminators from DeclContext.  This is cleaner and should
enable us to drop the alignment of DeclContext (coming next Jordan!)



Swift SVN r8059
2013-09-09 22:43:11 +00:00
Dmitri Hrybenko
1e23c936e0 Rename FuncDecl::getBody() to FuncDecl::getFuncExpr()
ConstructorDecl::getBody() and DestructorDecl::getBody() return 'BraceStmt *'.
After changing the AST representation for functions, FuncDecl::getBody() will
return 'BraceStmt *' and FuncDecl::getFuncExpr() will be gone.


Swift SVN r8050
2013-09-09 19:57:27 +00:00
Chris Lattner
e48b3a4702 Rework how capture lists work in CaptureExpr: now we record
global variables used by functions in the capture list as well.

SILGen and other things that don't care about these (i.e., all 
current current clients) filter the list to get what they want.

This is needed for future definite init improvements, and unblocked
by Doug's patch in r8039 (thanks! :)

No functionality change.



Swift SVN r8045
2013-09-09 18:15:07 +00:00
Chris Lattner
13c33e0cdd split declcontext stuff out to its own file.
Swift SVN r8039
2013-09-09 17:06:45 +00:00
Chris Lattner
77d0fb5ac8 add some support for dumping DeclContexts, which is useful for diagnosing
problems, particularly given LLDB's bug handing our DeclContext class
(filed as rdar://14944683)



Swift SVN r8038
2013-09-09 17:03:57 +00:00
Doug Gregor
5b310906fb Propagate [objc] to properties, methods of [objc] protocols.
Swift SVN r8035
2013-09-09 15:45:05 +00:00
Doug Gregor
1b48b78c07 Dynamic lookup can find members of class extensions.
Swift SVN r8034
2013-09-09 15:13:26 +00:00
Doug Gregor
a22911a0d0 Limit dynamic lookup to [objc] methods/properties/subscripts.
Also turn DynamicLookup into an [objc] protocol.


Swift SVN r7866
2013-09-03 21:29:59 +00:00
Doug Gregor
04d157427d Make sure that the dynamic lookup table has the right set of members.
Clean up the "can be accessed by dynamic lookup" predicate so that it
checks for a generic context. We no longer need to do the checking in
name lookup, since this means that the dynamic lookup table won't have
anything we can't use (thanks Jordan!). Drop the [objc] allowance for
members of a generic context: it still leaves us with a very weird
case of messaging something when we can't even figure out the type
that we think the object has.

Extend the walk searching for members to include inner classes within
structs, so we get all of the members globally.



Swift SVN r7799
2013-08-30 20:43:34 +00:00
Jordan Rose
cc53e1a7e7 Remove Type parameter from ValueDecl constructor.
We only know the type of functions and vars at the time we create them,
and sometimes not even those. Just use setType() in those constructors
and make all other ValueDecls simpler.

Swift SVN r7756
2013-08-29 22:23:07 +00:00
Doug Gregor
9efa20e4eb Improve overload resolution for dynamic lookups.
Unlike normal overload resolution, where we always want the
most-specialized, overriding result, overload resolution for dynamic
lookups favors results in superclasses to those in subclasses, because
we want to put the least requirements on the object
type. Additionally, we don't allow overload resolution to select among
results that come from different classes or protocols.



Swift SVN r7743
2013-08-29 21:07:07 +00:00
Doug Gregor
508e02df19 All classes implicitly conform to the DynamicLookup protocol.
Swift SVN r7700
2013-08-28 22:57:24 +00:00
Dmitri Hrybenko
1593632d7b More 'this' -> 'self' replacements
Swift SVN r7659
2013-08-28 03:08:07 +00:00
Dmitri Hrybenko
69cfa73640 More 'this' -> 'self' replacements
Swift SVN r7657
2013-08-28 02:57:21 +00:00
Ted Kremenek
8f5b8ccb02 Rename "This" to "Self" and "this" to "self".
This was not likely an error-free change.  Where you see problems
please correct them.  This went through a fairly tedious audit
before committing, but comments might have been changed incorrectly,
not changed at all, etc.

Swift SVN r7631
2013-08-27 21:58:27 +00:00
John McCall
ffeea0c229 Move getTypeOfRValue into Sema as well.
Swift SVN r7479
2013-08-22 21:36:39 +00:00
Doug Gregor
7c84fd5926 Start detangling archetypes from the interface of generic functions.
This breaks the type-canonicalization link between a generic parameter
type and the archetype to which it maps. Generic type parameter types
are now separate entities (that can eventually be canonicalized) from
archetypes (rather than just being sugar).

Most of the front end still traffics in archetypes. As a step away
from this, allow us to type-check the generic parameter list's types
prior to wiring the generic type parameter declarations to archetypes,
using the new "dependent" member type to describe assocaited
types. The archetype builder understands dependent member types and
uses them to map down to associated types when building archetypes.

Once we have assigned archetypes, we revert the dependent identifier
types within the generic parameter list to an un-type-checked state
and do the type checking again in the presence of archetypes, so that
nothing beyond the generic-parameter-list checking code has to deal
with dependent types. We'll creep support out to other dependent types
elsewhere over time.



Swift SVN r7462
2013-08-22 18:07:40 +00:00
Doug Gregor
2e91172d4f Don't record the declared type of nominal type decls within the module file.
Instead, compute the type just after we load the nominal type
declaration. This centralizes the type-computation code better as
well.


Swift SVN r7454
2013-08-22 17:33:24 +00:00
Doug Gregor
5034803021 Lazily compute the type of protocol declarations.
Swift SVN r7453
2013-08-22 17:09:16 +00:00