Commit Graph

2076 Commits

Author SHA1 Message Date
Dmitri Hrybenko
b884b17891 AST Printer: don't print a space before a colon in a tuple label
For example:

  func f(a: Int)

instead of:

  func f(a : Int)


Swift SVN r8795
2013-09-30 22:58:16 +00:00
Joe Groff
92cce69e15 AST: Give NominalTypePattern a better AST-level representation.
Instead of relying on the subpattern being a well-formed TuplePattern, let's track our own subelements so we can associate them to properties and validate them ourselves.

Swift SVN r8771
2013-09-30 01:03:18 +00:00
Dmitri Hrybenko
52555294f9 Type printer: replace a broken variant of GenericParamList printer with a use of AST printer
Swift SVN r8751
2013-09-28 02:45:44 +00:00
Dmitri Hrybenko
38994060d5 AST printing: merge swift::Type::PrintOptions into swift::PrintOptions
There is no reason to have two different options structs.


Swift SVN r8749
2013-09-28 02:19:31 +00:00
Dmitri Hrybenko
b33caadd89 AST printer: print raw type of EnumDecl
Swift SVN r8716
2013-09-27 01:52:07 +00:00
Dmitri Hrybenko
448d7cff8e AST Printer: add tests for printing deserialized modules
...and fix bugs found by this.


Swift SVN r8706
2013-09-26 23:17:32 +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
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Anna Zaks
970bcd3bc6 fixup for r8625
Fix a copy and paste error + a better comment.
Thanks Dmitry.

Swift SVN r8631
2013-09-25 17:56:23 +00:00
Anna Zaks
30039a59f1 Emit Swift declarations when printing SIL.
Only print function member declarations and skip the bodies since the bodies are already represented in SIL and ASTPrinter is not good enough to print arbitrary expressions.

In order to have valid output, make sure that ASTPrinter does not print references to DynamicLookup protocol.

Swift SVN r8627
2013-09-25 17:08:42 +00:00
Dmitri Hrybenko
725b0e01eb AST Printer: fix printing of same type requirement in generic parameter lists
These types are really the same for the type checker, so they are printed in
exactly the same way.  To recover the original spelling, prefer to print
a TypeRepr, if available.


Swift SVN r8603
2013-09-24 21:16:35 +00:00
Dmitri Hrybenko
71dddd1c88 AST Printer: implement requirement printing in a generic parameter list
Swift SVN r8595
2013-09-24 17:55:19 +00:00
Dmitri Hrybenko
a044e2a420 AST Printer: don't print properties twice and don't print top-level variables in braces
Swift SVN r8587
2013-09-24 02:05:02 +00:00
Dmitri Hrybenko
dec19cc7c3 AST printing: function parameter printing: simplify code
Swift SVN r8585
2013-09-24 01:27:13 +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
Dmitri Hrybenko
c9d1aa3f96 AST Printer: fix parameter name printing in setters
Also, add an AST verifier check that the parameter patterns in getters/setters
are sane.


Swift SVN r8574
2013-09-23 22:25:35 +00:00
Dmitri Hrybenko
ec899dee8c AST Printer: don't print a trailing space after "get:", "set:" labels
Swift SVN r8566
2013-09-23 20:12:04 +00:00
Dmitri Hrybenko
af8fa8c8cd Remove a circular dependency AST<->Sema caused by type printing
AST used to depend on Sema in type printing.  Specifically,
TypeVariableType::printImpl() is inside Sema.

This change moves the type variable identifier from
TypeVariableType::Implementation to TypeVariableType. This enables us to print
type variables in AST library.

Because type variable type is a temporary type for use inside type checker
only, I don't expect that we will modify it to be more verbose to enhance
diagnostics.  This is a job for locator printing.


Swift SVN r8559
2013-09-23 17:40:43 +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
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
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
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
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
Jordan Rose
3107bcd8bb AST printer: include inheritance info even if we don't have source info for it
Essentially, fall back to the list of protocols (and possibly the superclass)
if the "inherited types" array is empty.

<rdar://problem/14788337>

Swift SVN r7884
2013-09-04 00:31:32 +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
Chris Lattner
69d0afb658 rename [force_inlining] to [transparent].
Swift SVN r7448
2013-08-22 16:05:41 +00:00
Doug Gregor
1ddb34fb71 Factor generic parameters and associated types into their own decl nodes.
Previously, TypeAliasDecl was used for typealiases, generic
parameters, and assocaited types, which is hideous and the source of
much confusion. Factor the latter two out into their own decl nodes,
with a common abstract base for "type parameters", and push these
nodes throughout the frontend.

No real functionality change, but this is a step toward uniquing
polymorphic types, among other things.


Swift SVN r7345
2013-08-19 23:36:58 +00:00
Jordan Rose
26c1181502 Fix printing for unions, vars, subscripts, and typealiases.
Union cases were still being printed enum-style, and computed vars,
subscripts, and typealiases would print their definitions even when
the corresponding printing option was disabled. All fixed.

Swift SVN r7285
2013-08-16 20:21:55 +00:00
Doug Gregor
ad71b469bc When pretty-printing func declarations, use selector style when needed.
Swift SVN r7284
2013-08-16 18:45:04 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Jordan Rose
093a428ca9 Add parsing support for the [exported] attribute.
As discussed, this is an interim syntax for re-exports:
  import [exported] Foundation
In the long run, we're probably going to use the same syntax as access
control for this, but that hasn't been designed yet.

Swift SVN r7050
2013-08-08 19:09:10 +00:00
Jordan Rose
c92fa28833 Have ImportDecl vend a separate "module path" and "decl path".
This makes it very clean to reason about which part should be used
to find a module to load, and which part should be used to filter
lookup within that module.

This breaks the old "import swift.print" syntax in favor of the new
"import func swift.print", but the new syntax is currently ignored.

Swift SVN r6849
2013-08-02 21:00:22 +00:00
Jordan Rose
757cf9826f Add Parse and AST support for the new import syntax.
Also, update LangRef.

Note that an explicit "import module" has been left out for now, since
it's not strictly necessary and "module" isn't a keyword yet.

Swift SVN r6786
2013-07-31 23:23:26 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Argyrios Kyrtzidis
21785c8a36 Call Type::print(), instead of TypeBase::print(); the former includes the null check.
Swift SVN r6751
2013-07-30 21:25:36 +00:00
Anna Zaks
74bc6f05b2 Add "noreturn" attribute : stage 1
- Add the attribute to AnyFunctionType::ExtInfo.
- Propagate the attributes from DeclAttributes to AnyFunctionType for
  FuncDecls in TypeCheckDecl.cpp.
- Make sure the new attribute is serialized.

The main missing pieces are checking the applicability of the type attributes
on the FuncDecl and teaching typechecker about conversions on types with
noreturn.

Swift SVN r6359
2013-07-18 22:57:22 +00:00
Argyrios Kyrtzidis
5082f375a4 Print a vararg in a pattern as written, without the array slice notation.
rdar://14447454

Swift SVN r6341
2013-07-18 01:12:52 +00:00
Argyrios Kyrtzidis
37dc84e13c Remove VarargBaseType from TuplePatternElt and introduce a bit in TuplePattern to indicate if there is a vararg.
The semantics of varargs (only for the last element) make it more appropriate as a property of the TuplePattern.
Also free the Parser from needing to construct synthetic types (ArraySlice for type of vararg element) to
accommodate the TypeChecker and move the logic to the TypeChecker. This will be more beneficial when the parser stops
creating types in general.

Swift SVN r6271
2013-07-15 20:21:30 +00:00
Joe Groff
3b21e6a201 Add a OneOfElementPattern AST node type.
Add a node for references to oneof cases in patterns. No user-facing functionality change yet.

Swift SVN r6239
2013-07-13 01:21:31 +00:00
Jordan Rose
e3999dde36 [serialization] Handle absent protocol conformances.
These still need to be serialized, because they are one-to-one with the
type's protocol list, but don't actually require any data. Found on
attempting to emit a module for the standard library.

Most of the churn here is moving Interleave.h to a more general STLExtras.h.

Swift SVN r6167
2013-07-11 18:38:50 +00:00
Jordan Rose
b31e79e571 Sink InfixOperatorDecl's InfixData into Decl's bitfields.
InfixData is still useful, since the type-checker uses it to treat other
operator-like constructs (e.g. 'is') the same way.

Swift SVN r6077
2013-07-08 23:40:58 +00:00
Joe Groff
53221db84c AST: Add 'VarPattern' node.
We decided to go with 'var' as a distributive pattern introducer which applies to bare identifiers within the subpattern. For example, 'var (a, b)' and '(var a, var b)' would be equivalent patterns. To model this, give 'var' its own AST node with a subpattern and remove the introducer loc from NamedPattern.

Swift SVN r5824
2013-06-26 23:01:47 +00:00
Joe Groff
e460a01af6 Remove the 'UnresolvedCallPattern' I stubbed out.
I talked to John about parsing patterns today, and because of the magnitude of name-lookup-dependent ambiguities between patterns and expressions, we agreed that at least for a first-pass implementation it makes sense to parse patterns as extensions of the expr grammar and charge name binding with distinguishing patterns from expressions. This gets us out of needing the concept of an "unresolved pattern", at least in the short term.

Swift SVN r5808
2013-06-26 04:23:47 +00:00
Joe Groff
8deec52b17 Rework AST representation of CaseStmts.
A single case block can have one or more 'case ...:' labels. 'case' labels contain patterns instead of exprs. 'default:' is a funny spelling for 'case _:'. Change the CaseStmt representation and rip out all the parsing, type-checking, and SILGen built off the old representation.

Swift SVN r5795
2013-06-25 00:31:42 +00:00