Commit Graph

557 Commits

Author SHA1 Message Date
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
Joe Groff
7ba95cfd26 Add AST nodes for refutable patterns.
Introduce Pattern subclasses for the 'is T', 'T(<pattern>)', and '<expr>' pattern syntaxes we'll be introducing for pattern-matching "switch" statements. Also add an 'UnresolvedCalLPattern' to act as an intermediate for name lookup to resolve to a nominal type, oneof element, or function call expression pattern. Since we'll need to be able to rewrite patterns like we do expressions, add setters to AST nodes that contain references to subpatterns. Implement some basic walking logic in places we search patterns for var decls, but punt on any more complex type-checking or SILGen derived from these nodes until we actually use them.

Swift SVN r5780
2013-06-24 17:17:34 +00:00
Jordan Rose
3b07d4e102 Make Pattern (more) const-correct.
Sub-patterns are now considered part of the enclosing pattern, so if the
parent pattern pointer is const, the child pointer will be too.

I changed the minimal number of files to make this work, but future code
should use "const Pattern *" when intended, and "Pattern *" only if they
intend to modify the pattern.

Swift SVN r5743
2013-06-21 17:51:39 +00:00
Joe Groff
952028c5f2 Parse [class_protocol] attribute on protocols.
Add a [class_protocol] attribute and only allow it on protocol decls. It has no effect yet.

Swift SVN r5551
2013-06-09 03:22:50 +00:00
Joe Groff
cb1f81db84 Make assignment an expression.
Change AssignStmt into AssignExpr; this will make assignment behave more consistently with assignment-like operators, and is a first step toward integrating '=' parsing with SequenceExpr resolution so that '=' can obey precedence rules. This also nicely simplifies the AST representation of c-style ForStmts; the initializer and increment need only be Expr* instead of awkward Expr*/AssignStmt* unions.

This doesn't actually change any user-visible behavior yet; AssignExpr is still only parsed at statement scope, and typeCheckAssignment is still segregrated from the constraint checker at large. (In particular, a PipeClosureExpr containing a single assign expr in its body still doesn't use the assign expr to resolve its own type.) The parsing issue will be addressed by handling '=' during SequenceExpr resolution. typeCheckAssignment can hopefully be reworked to work within the constraint checker too.

Swift SVN r5500
2013-06-06 22:18:54 +00:00
Doug Gregor
87965ac319 When the index types of an Objective-C class's subscript getter and setter mismatch, don't build thunks for either.
Previously, we would build an invalid AST for the getter.


Swift SVN r5434
2013-06-03 18:23:48 +00:00
Joe Groff
e1c838962e Revert "Remove [objc_block] attribute from Swift type system."
Implementing SIL bridging is going to take more IRGen work than I anticipated.

Swift SVN r5113
2013-05-09 16:32:18 +00:00
Joe Groff
38f13e56f5 Remove [objc_block] attribute from Swift type system.
We will handle Swift-function-to-ObjC-block bridging in SILGen as part of general Cocoa-to-Swift type bridging. Temporarily disable building swiftAppKit and tests that exercise block bridging until the new implementation lands.

Swift SVN r5090
2013-05-08 16:52:12 +00:00
Doug Gregor
57002ac3dc Remove byref(heap).
Most of this is mechanical, because we weren't actually relying on
byref(heap) for anything. Simplify capture analysis, now that the only
way a variable can have non-fixed lifetime is if it is actually
captured. Fixes <rdar://problem/11247831>.


Swift SVN r5046
2013-05-06 14:07:54 +00:00
Joe Groff
2eb4ac563a Parse [force_inline] attribute.
Add a force_inline attribute and allow it to be applied for now only to uncurried nongeneric functions. It doesn't do anything yet.

Swift SVN r5036
2013-05-04 00:46:48 +00:00
Joe Groff
6ed98ac0e5 Parse [objc_block] attribute on function types.
So we can use it in tests.

Swift SVN r4722
2013-04-13 17:05:35 +00:00
Chris Lattner
af3b55c1f0 Further reinforce TopLevelCodeDecl as the container for top level code.
This nests top level PatternBindingDecls (in "main modules") under TopLevelCodeDecls,
instead of having them live in a translation unit.  They contain code that is executed,
so they should be in a TLCD.


Swift SVN r4668
2013-04-10 23:13:22 +00:00
Joe Groff
bfd2f85b5c Parse 'fallthrough' statements.
Create a new FallthroughStmt, which transfers control from a 'case' or 'default' block to the next 'case' or 'default' block within a switch. Implement parsing and sema for FallthroughStmt, which syntactically consists of a single 'fallthrough' keyword. Sema verifies that 'fallthrough' actually appears inside a switch statement and that there is a following case or default block to pass control to.

SILGen/IRGen support forthcoming.

Swift SVN r4653
2013-04-10 17:30:42 +00:00
Joe Groff
ac23437886 Replace infix attributes with operator decl lookup
During name binding, associate func decls with operator decls. When parsing SequenceExprs, look up operator decls to determine associativity and precedence of infix operators. Remove the infix_left and infix_left attributes, and make the infix attribute a simple declared attribute [infix] with no precedence.

Operator decls are resolved as follows:

- If an operator is declared in the same module as the use, resolve to the declaration in the current module.
- Otherwise, import operator declarations from all imported modules. If more than one declaration is imported for the operator and they conflict, raise an ambiguity error. If they are equivalent, pick one arbitrarily.

This allows operator declarations within the current module to override imported declarations if desired or to disambiguate conflicting operator declarations.

I've updated the standard library and the tests. stdlib2 and some of the examples still need to be updated.

Swift SVN r4629
2013-04-07 02:43:03 +00:00
Chris Lattner
b4fd6dd04a Change TopLevelCodeDecl to allow it to hold a sequence of different exprs and statements in one unit, wrapping them into a BraceStmt. This makes it more similar to other decls (e.g. funcdecl, ctor decls, etc) and will be useful for future sil work.
Unfortunately, this regresses the repl when expressions like (1,2) are entered. This is because the repl is violating some invariants (forming dags out of ASTs, making ASDAG's which upset the type checker).  I'm going to fix this next, but can't bring myself to do it in the same commit.



Swift SVN r4617
2013-04-05 22:33:14 +00:00
Joe Groff
aeeda4ee12 Parser: Parse operator decls.
At the top level, if 'operator' is followed by 'infix', 'prefix', or 'postfix', consider it a contextual keyword, and parse an operator decl following it that looks like:

  operator {infix|postfix|prefix} <+> {
    attributes…
  }

Prefix and postfix operator decls currently admit no attributes. Infix operators have 'associativity {left|right|none}' and 'precedence <int>' attributes.

This patch implements parsing for operator declarations but does not yet attach the declared attributes to func decls for the operators.

Swift SVN r4596
2013-04-03 23:30:50 +00:00
Joe Groff
062ad267c4 Value-only switch statements.
Implement switch statements with simple value comparison to get the drudge work of parsing and generating switches in place. Cases are checked using a '=~' operator to compare the subject of the switch to the value in the case. Unlike a C switch, cases each have their own scope and don't fall through. 'break' and 'continue' apply to an outer loop rather to the switch itself. Multiple case values can be specified in a comma-separated list, as in 'case 1, 2, 3, 4:'. Currently no effort is made to check for duplicate cases or to rank cases by match strength; cases are just checked in source order, and the first one wins (aside from 'default', which is branched to if all cases fail).

Swift SVN r4359
2013-03-12 04:43:01 +00:00
Doug Gregor
a9a90fd56a Track the Clang macros that were used to generate Swift constants.
Swift SVN r3960
2013-02-06 00:57:03 +00:00
Joe Groff
d73950174d AST: Update printer for new property syntax.
Swift SVN r3942
2013-02-03 19:06:14 +00:00
Joe Groff
8b5c6b10ad ASTPrinter: Print struct fields from Clang imports
The ClangImporter doesn't synthesize PatternBindingDecls around imported struct fields, but the ASTPrinter assumes that a non-property VarDecl will later show up in a PatternBindingDecl. In the ASTPrinter, don't skip VarDecls that originated from Clang.

Swift SVN r3925
2013-02-01 18:18:58 +00:00