Commit Graph

21693 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis
ab82766a74 [AST] Walk the inherited TypeReprs of a nominal type declaration with the ASTWalker.
Swift SVN r8556
2013-09-23 15:39:44 +00:00
Argyrios Kyrtzidis
8e1538e110 [AST] Consolidate walking of NominalTypeDecl subclasses to reduce duplication.
Swift SVN r8555
2013-09-23 15:39:42 +00:00
Doug Gregor
385d13d996 Update use of array_pod_sort for LLVM-side change
Swift SVN r8553
2013-09-23 13:08:31 +00:00
Joe Groff
2c04f45912 Have the ASTWalker walk type-checked raw value exprs.
We don't let it see the pre-type-checked LiteralExpr yet because EnumElementDecls need to do its own checking.

Swift SVN r8547
2013-09-21 15:21:16 +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
efd8e75647 Move type printing to ASTPrinter.cpp and use the AttributePrinter class in Decl attribute printing
Swift SVN r8543
2013-09-21 04:09:28 +00:00
Dmitri Hrybenko
738d65f01e Make generic parameter list printing an implementation detail of TypePrinter
Swift SVN r8540
2013-09-21 02:49:10 +00:00
Dmitri Hrybenko
df26716233 Refactor type printing to use TypeVisitor
Swift SVN r8533
2013-09-20 23:32:57 +00:00
Argyrios Kyrtzidis
207dd91c78 [AST] Sort the includes in Mangle.cpp.
Swift SVN r8530
2013-09-20 23:13:27 +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
Argyrios Kyrtzidis
eecb56a9ad Move the Mangler from the SIL library to the AST one.
No other functionality change.

Swift SVN r8527
2013-09-20 23:10:58 +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
Doug Gregor
bc3f655105 s/constructor/init in a few more places.
Swift SVN r8504
2013-09-20 18:37:15 +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
Doug Gregor
40cf8d1bbc Remove ASTMutationListener::addedExternalType(). It's useless now.
Swift SVN r8491
2013-09-20 15:15:19 +00:00
Doug Gregor
6dad378b32 Filter out duplicates for DynamicLookup lookups.
Swift SVN r8490
2013-09-20 14:58:27 +00:00
Doug Gregor
8f3184ea9d Implicitly-defined default constructors for classes.
When a class definition contains no constructors, and all of the
instance variables are either default initializable or have initial
values in the class, and the superclass (if any) has a constructor
callable with the argument (), implicitly define a default
constructor.

Fixes <rdar://problem/14828518>.


Swift SVN r8487
2013-09-20 14:11: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
Dmitri Hrybenko
37b7284e0c Code completion: don't crash when completing in constructors/destructors placed
in contexts where they are not allowed

We used to throw away the ConstrutorDecl/DestructorDecl, but code completion
captured the pointer as a DeclContext for the code completion point.  Then code
completion passed that AST node to type checker, which crashed.  Now we
properly mark the decl as invalid, pass it to the type checker, and have the
type checker set its type to ErrorType.


Swift SVN r8466
2013-09-19 23:01:26 +00:00
John McCall
c915139f77 Convenience accessor for drilling into Optional<T> to T.
Swift SVN r8437
2013-09-19 00:54:52 +00:00
Greg Clayton
53e32527b6 Added a swift::Type::PrintOptions class to allow printing the module when
dumping type names. This allows you to get a fully qualified type name for any
swift::Type or swift::TypeBase, including any contained types like function
parameter types, bound generic types, etc.



Swift SVN r8426
2013-09-18 22:58:15 +00:00
Dmitri Hrybenko
3fbfded756 Code completion / lookup visible decs: find 'self' in constructors and destructors
Swift SVN r8417
2013-09-18 20:48:55 +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
Dmitri Hrybenko
43859ceb56 Code completion / lookup visible names: find body parameters in functions with selector-style signatures
Swift SVN r8380
2013-09-18 01:00:01 +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
Dmitri Hrybenko
7c408791cd Code completion: implement delayed parsing of destructors (and basic code completion)
Swift SVN r8352
2013-09-17 21:08:09 +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
Dmitri Hrybenko
5b1c412e70 Use 'override' when overriding ASTWalker functions
Swift SVN r8345
2013-09-17 19:31:24 +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
John McCall
cb06e316d0 Add CanBoundGenericType::getGenericArgs().
Swift SVN r8329
2013-09-17 07:22:26 +00:00
Dmitri Hrybenko
f1f189f4e0 Rename PipeClosureExpr -> ClosureExpr
Swift SVN r8321
2013-09-17 01:37:36 +00:00
Dmitri Hrybenko
d26cc5bd2e Tighten verifier check and cast in AbstractClosureExpr::getResultType()
Closure can only have a FunctionType (not a PolymorphicFunctionType).


Swift SVN r8311
2013-09-17 00:04:09 +00:00
Dmitri Hrybenko
34a703a173 Move PipeClosureExpr::getResultType to AbstractClosureExpr
Swift SVN r8308
2013-09-16 23:45:45 +00:00
Dmitri Hrybenko
7a3d43a918 Add a verifier check that the type of closure is sane
Swift SVN r8307
2013-09-16 23:40:16 +00:00
Dmitri Hrybenko
b18c38a322 Rename ImplicitClosureExpr -> AutoClosureExpr
Swift SVN r8304
2013-09-16 23:03:50 +00:00
Dmitri Hrybenko
10291e0334 Make AbstractClosureExpr a DeclContext
(remove DeclContext base class from PipeClosureExpr and ImplicitClosureExpr)


Swift SVN r8303
2013-09-16 22:39:12 +00:00
Dmitri Hrybenko
f2cc4cb303 Rename CapturingExpr -> AbstractClosureExpr
Swift SVN r8299
2013-09-16 21:58:44 +00:00
Dmitri Hrybenko
f8bd657b2f ImplicitClosureExpr (AutoClosureExpr in future): store body as BraceStmt
This allows us to add AnyFunctionRef::getBody(), which returns the body
as a BraceStmt for every function-like AST node.


Swift SVN r8293
2013-09-16 20:52:12 +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
e7af4d6c72 Collapse ImplicitClosureExpr into its abstract base class, ClosureExpr
Swift SVN r8280
2013-09-16 18:31:05 +00:00
Chris Lattner
74bf9c98c6 change the CaptureInfo::getLocalCaptures() method to return a SmallVector
by reference, avoiding allocating heap memory.



Swift SVN r8275
2013-09-16 15:25:48 +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
Chris Lattner
0e9b9c5b65 refactor ast dumping a bit to make room for AbstractFunctionDecl. Right now,
just have it print a body.



Swift SVN r8241
2013-09-14 04:17:42 +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
Dmitri Hrybenko
fb227e6da6 Remove CapturingExpr::getParamPatterns()
Swift SVN r8218
2013-09-13 22:19:20 +00:00
Joe Groff
c0317ec696 AST: Add Type::getStructOrBoundGenericStruct helper.
Swift SVN r8204
2013-09-13 17:10:21 +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