Commit Graph

589 Commits

Author SHA1 Message Date
Dmitri Hrybenko
09f44aec2b Move ValueDecl::getDefaultArg() -> AbstractFunctionDecl::getDefaultArg()
Swift SVN r8744
2013-09-27 22:27:12 +00:00
Anna Zaks
3e5c1f81d2 Support transparent attributes on struct and enum extensions.
Attribute [transparent] on extensions should apply to all members(functions, properties) of that extension.

Addresses radar://15035271.

Swift SVN r8735
2013-09-27 20:29:31 +00:00
Anna Zaks
f0dda149ab Move attributes from ValueDecl to Decl.
Swift SVN r8734
2013-09-27 20:29:29 +00:00
Dmitri Hrybenko
ba2e4732d0 Remove unused member EnumDecl::isEnum
Swift SVN r8710
2013-09-27 00:22:39 +00:00
Jordan Rose
e05c03d5bc Standardize terminology for "computed", "stored", "variable", and "property".
These are the terms sent out in the proposal last week and described in
StoredAndComputedVariables.rst.

variable
  anything declared with 'var'
member variable
  a variable inside a nominal type (may be an instance variable or not)
property
  another term for "member variable"
computed variable
  a variable with a custom getter or setter
stored variable
  a variable with backing storage; any non-computed variable

These terms pre-exist in SIL and IRGen, so I only attempted to solidify
their definitions. Other than the use of "field" for "tuple element",
none of these should be exposed to users.

field
  a tuple element, or
  the underlying storage for a stored variable in a struct or class
physical
  describes an entity whose value can be accessed directly
logical
  describes an entity whose value must be accessed through some accessor

Swift SVN r8698
2013-09-26 18:50:44 +00:00
Dmitri Hrybenko
5c142346c6 Destructor syntax: require an empty parameter list for destructors
rdar://14968738


Swift SVN r8694
2013-09-26 18:09:12 +00:00
Dmitri Hrybenko
5268940301 AST Printer: simplify the check for DynamicLookup known protocol
Swift SVN r8677
2013-09-25 23:41:33 +00:00
Jordan Rose
c5322d4bf6 Record a back-pointer from a VarDecl to its containing PatternBindingDecl.
This will be used for lazy type-checking of global and member vars.

Swift SVN r8640
2013-09-25 20:08:07 +00:00
Dmitri Hrybenko
5967115a00 Remove Requirement::isImplicit()
Is was implemented in terms checking if there's a valid SourceLoc for the
colon.  This produced wrong results for deserialized modules.


Swift SVN r8620
2013-09-25 01:39:56 +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
Dmitri Hrybenko
10d8fdc64f AST/AbstractFunctionDecl: Remember if a function had a selector-style signature
... and use this information in AST printing


Swift SVN r8583
2013-09-24 00:56:33 +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
Dmitri Hrybenko
1f601d8ebd AST: rename bitfield data structures to have a common naming pattern
Swift SVN r8539
2013-09-21 01:21:02 +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
f9480828e0 Remove EnumCaseDecl backreference from EnumElementDecl.
Swift SVN r8516
2013-09-20 20:50:24 +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
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
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
Dmitri Hrybenko
f1f189f4e0 Rename PipeClosureExpr -> ClosureExpr
Swift SVN r8321
2013-09-17 01:37:36 +00:00
Dmitri Hrybenko
9636b9fffb Migrate the last use of FuncExprLike to AnyFunctionRef
Swift SVN r8309
2013-09-16 23:54:29 +00:00
Dmitri Hrybenko
34a703a173 Move PipeClosureExpr::getResultType to AbstractClosureExpr
Swift SVN r8308
2013-09-16 23:45:45 +00:00
Argyrios Kyrtzidis
09c8bb7740 [AST] NominalTypeDecl is an abstract node, move its constructor to 'protected' access.
Swift SVN r8305
2013-09-16 23:37:22 +00:00
Dmitri Hrybenko
45448d04b2 Clarify comment per review
Swift SVN r8277
2013-09-16 18:04:07 +00:00
Dmitri Hrybenko
bbed45f0f9 Add a comment for AbstractFunctionDecl::getBody()
Swift SVN r8276
2013-09-16 17:54:12 +00:00
Chris Lattner
ee1a9141a3 move the capture list up to AbstractFunctionDecl, and compute it
for all AbstractFunctionDecl's.  Refactor ASTDump of AbstractFunctionDecl's
to all go through the same funnel point and print it in the right place.


Swift SVN r8242
2013-09-14 04:25:43 +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
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
45e654fbaa Make AbstractFunctionDecl a DeclContext
and remove DeclContext base class from FuncDecl, ConstructorDecl and
DestructorDecl

This decreases the number of DeclContexts to 7 and allows us to apply
alignas(8) to DeclContext.


Swift SVN r8186
2013-09-13 03:38:33 +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
c69c79084a Move result typeloc and body result type from FuncExpr to FuncDecl
Swift SVN r8153
2013-09-12 18:40:57 +00:00
Joe Groff
6dbc1a8835 Add manglings for associated types.
This should allow declarations inside protocols to mangle successfully, which is needed by SourceKit to be able to use mangled names as unique decl identifiers. I'm also planning to use mangled protocol decls to name generic curry thunk symbols.

This only introduces a mangling for independent associated types. I think we will eventually want to mangle dependent associated types (such as T.AssocType for an archetype T : SomeProtocol) with a non-indexed mangling too, but this doesn't do that yet.

Swift SVN r8148
2013-09-12 15:29:08 +00:00
Dmitri Hrybenko
49fe003674 Remove two uses of FuncExprLike and simplify the definition of FuncExprLike
Swift SVN r8137
2013-09-12 01:07:49 +00:00
Dmitri Hrybenko
796eac4b3f Make SILLocation::dump() more informative
Swift SVN r8130
2013-09-12 00:25:32 +00:00
Dmitri Hrybenko
abfa512c4f Sink getArgParamPatterns() and getBodyParamPatterns() into AbstractFunctionDecl
Swift SVN r8097
2013-09-11 18:42:28 +00:00
Dmitri Hrybenko
2c8e7e45a5 Sink GenericParamList to AbstractFunctionDecl from derived classes
Swift SVN r8092
2013-09-11 17:27:59 +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
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
Dmitri Hrybenko
1d86968d33 Update subscript operator example in comments
Swift SVN r8044
2013-09-09 18:06:17 +00:00
Dmitri Hrybenko
bb7c94f458 Remove useless classof() overloads
Swift SVN r8023
2013-09-07 01:30:32 +00:00
Doug Gregor
967072f4b3 Allow dynamic lookup to find a generic member.
The new ConcreteDeclRef class provides a possibly-speciaized reference
to a declaration, which allows DynamicMemberRefExpr to refer to both
generic and non-generic members. without having to split the AST node.


Swift SVN r7839
2013-09-03 14:55:31 +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
Doug Gregor
b06e65c3b3 Add the DynamicLookup protocol for lookup across all classes and protocols.
When performing member lookup into an existential that involves the
DynamicLookup protocol, look into all classes and protocols for that
member. References to anything found via this lookup mechanism are
returned as instances of Optional.

This introduces the basic lookup mechanics into the type
checker. There are still numerous issues to work through:
  - Subscripting isn't supported yet
  - There's no SILGen or IRGen support
  - The ASTs probably aren't good enough for the above anyway
  - References to generics will be broken
  - Ambiguity resolution or non-resolution

Thanks to Jordan for the patch wiring up DynamicLookup.


Swift SVN r7689
2013-08-28 21:38:50 +00:00
Dmitri Hrybenko
69cfa73640 More 'this' -> 'self' replacements
Swift SVN r7657
2013-08-28 02:57:21 +00:00