Commit Graph

268 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis
121bf14dd1 [AST] In IfConfigDecl/IfConfigStmt keep track of whether the IfBlock is active or not.
Swift SVN r15444
2014-03-25 03:55:29 +00:00
Argyrios Kyrtzidis
8f810a3887 [AST] Add EndLoc to the IfConfigStmt.
Swift SVN r15441
2014-03-25 03:55:26 +00:00
Argyrios Kyrtzidis
f58b5a5d30 [AST] IfConfigStmt will always be 'explicit', remove the 'implicit' parameter.
Swift SVN r15440
2014-03-25 03:55:25 +00:00
Dmitri Hrybenko
11fea869c1 Change 'switch' not to fall through between empty cases and always require at
least one statement per case

rdar://16301313


Swift SVN r15266
2014-03-20 11:44:59 +00:00
Joe Pamer
535cb4667c Minor code cleanup for the build configuration implementation.
Swift SVN r14475
2014-02-27 21:19:03 +00:00
Joe Pamer
988a5877f2 Some updates:
- Respond to Doug's code review feedback
   - Stop hacking around with scopes and use "emplace" to work around RAII in the inactive config case
   - Limit use of StringRef on the front-end, in favor of std::string
   - Use ArrayRef rather than SmallVector within IfConfigDecl
   - Reorder new property declarations on BraceStmt to prevent unnecessary alignment issues
- Update ParseBraceItems to better capture top-level declarations, rather than using token lookahead

Swift SVN r14306
2014-02-24 18:16:49 +00:00
Joe Pamer
f83f94d9d8 Support build and target configurations
These changes add support for build and target configurations in the compiler.
Build and target configurations, combined with the use of #if/#else/#endif allow
for conditional compilation within declaration and statement contexts.

Build configurations can be passed into the compiler via the new '-D' flag, or
set within the LangOptions class. Target configurations are implicit, and
currently only "os" and "arch" are supported.

Swift SVN r14305
2014-02-24 18:16:48 +00:00
Dave Abrahams
5063c33cbb Rename "Stream" protocol back to "Generator"
The name Stream didn't seem to be working out as intended; we kept
gravitating back to calling it Generator, which is precedented in other
languages.  Also, Stream seems to beg for qualification as Input or
Output.  I think we'd like to reserve Stream for things that are more
bulk-character-API-ish.

Swift SVN r13893
2014-02-14 01:48:52 +00:00
Joe Groff
9fe1ab427a Implement 'if let' and 'while let' statements.
Allow IfStmts and WhileStmts to have as their condition either an expression, as usual, or a pattern binding introduced by 'var' or 'let', which will conditionally bind to the value inside an optional. Unlike normal pattern bindings, these bindings require an in-line initializer, which will be required to be Optional type. Parse variable bindings in this position, and type-check them by requiring an Optional on the right-hand side and unwrapping it to form the pattern type. Extend SILGen's lowering of if and while statements to handle conditionally binding variables.

Swift SVN r13146
2014-01-30 10:37:39 +00:00
Dave Abrahams
0f994b6ba0 Rename "Container" => "Sequence" in core compiler
A few places in the core compiler were referring to instances of the
Sequence protocol as "Containers".  The "Indexable" protocol will soon
be renamed "Container," so eliminate this potential confusion

Swift SVN r11944
2014-01-06 20:07:01 +00:00
Dave Abrahams
ff076dc3f2 [stdlib] "Generator" => "Stream"
This is step 1 of implementing the new Container/Sequence/Stream
protocols.  See test/Prototypes/Container.swift for the complete picture
of where this is headed.

Swift SVN r11924
2014-01-06 16:40:32 +00:00
Anna Zaks
c8ed1954f2 Issue a warning when returned expression is on the next line after the return keyword.
We still want to allow line wrapping, so only issue the warning when the indentation of the expression and the return keyword is the same.

radar://11945406

Swift SVN r9984
2013-11-06 02:00:13 +00:00
Anna Zaks
54524e622a Replace ExprStmtOrDecl with ASTNode and make it a struct.
Previously, the Parser and BranchStmt typedef-ed ExprStmtOrDecl as a pointer union. Using typedef made the objects compatible, but did not allow us to extend the type with helper methods, such as getSourceRange(), which is something you can get on all of the AST objects. This patch introduces ASTNode that subclasses from PointerUnion and is used by both parser and BranchStmt.

Swift SVN r9971
2013-11-05 21:46:59 +00:00
Anna Zaks
16774496fd [SILGen] Emit warnings when SILGen fails to emit unreachable code.
Previously, we just did not emit SIL for unreachable code from these examples.

Swift SVN r9949
2013-11-05 01:17:14 +00:00
Dmitri Hrybenko
acdd5b120a Make type checker debug output redirectable
Introduce a replaceable TypeCheckerDebugConsumer for this.


Swift SVN r9555
2013-10-21 20:26:32 +00:00
Joe Groff
9b6652b3a4 Sema: Set up coerceToType on patterns to rewrite pattern ASTs.
Have coerceToType take its pattern argument by reference so it can replace the node and do things like insert implicit conversions.

Swift SVN r9530
2013-10-20 22:21:59 +00:00
Joe Groff
0bda31c02b Switch over to Generator as the 'for' loop protocol.
Rewrite ForEachStmt SILGen to use the Optional intrinsics with the Generator.next method to iterate through sequences, and kill off the Enumerator path in Sema. Cut over 'EnumeratorType.Element' requirements to instead require 'GeneratorType.Element' in the stdlib.

There are a couple of bugs remaining that need follow-up work. There appears to be a bug in nested enum layout (e.g. T??) that's causing test/Interpreter/enum to break; I'll investigate and fix. There's also a lingering type-checker bug with inferred associated types that causes them to fail requirement checks <rdar://problem/15172101>, which I think Doug needs to look into.

Swift SVN r9017
2013-10-08 01:46:51 +00:00
Joe Groff
08c2cc53b4 Sema: Type-check the Generator protocol in for loops alongside Enumerators.
Set up (currently ignored by SILGen) variable bindings and 'next' method invocations we'll be able to use to cut over to Generator-based iteration.

Swift SVN r9002
2013-10-07 22:28:28 +00:00
Joe Groff
12ffb98156 AST: Give Stmts an independent 'implicit' bit.
Definitions for derived protocol conformances will need to be able to create implicit statements free of the rules formerly hardcoded in Stmt::isImplicit. This also follows Dmitri and Argyrios's "implicit" improvements to the other AST hierarchies.

Swift SVN r8876
2013-10-03 16:53:53 +00:00
Dmitri Hrybenko
796eac4b3f Make SILLocation::dump() more informative
Swift SVN r8130
2013-09-12 00:25:32 +00:00
Dmitri Hrybenko
ce54da3123 Use NullablePtr in ForStmt
ForStmt::Cond is already a NullablePtr<>.  This patch changes
ForStmt::Initializer and ForStmt::Increment to be NullablePtr.  Otherwise it
looks like Cond can be null, while Initializer and Increment can not.


Swift SVN r7265
2013-08-15 17:51:32 +00:00
Argyrios Kyrtzidis
43061a7391 Move NullablePtr from llvm into Swift.
There are no other uses of it outside of swift.

Swift SVN r6113
2013-07-10 15:33:40 +00:00
Joe Groff
f7ad75fc7d AST: Remove unneeded implicit subject var from SwitchStmts.
Our implementation no longer requires an implicit representation of the entire subject value of switches.

Swift SVN r6087
2013-07-09 03:23:49 +00:00
Joe Groff
ce5eb80c33 Parse: Case blocks matching multiple patterns can't bind variables.
Similarly, "fallthrough" cannot transfer control into a case block that binds variables.

Swift SVN r5907
2013-06-30 19:10:11 +00:00
Joe Groff
45a69154bd Parse: Parse switch statements (again).
Reimplement 'switch' parsing for our new AST representation, where cases contain patterns and 'where' guards, case blocks can have multiple cases, and 'default' is constrained to being the lone label of the last block if present. No type-checking or parsing of actual pattern productions yet.

Swift SVN r5834
2013-06-27 05:13:41 +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
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
b9561e00ab Introduce an empty, implicit default constructor into structs.
When the struct definition has no user-defined constructors, and there
is at least one instance variable, add an implicit default
constructor. This default constructor is currently empty; that's to be
fixed next.


Swift SVN r4868
2013-04-24 05:50:06 +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
8caf747853 Put alignas(N) on classes with strict alignment.
We use three tag bits on Expr*, Stmt*, Decl*, TypeBase* and SILTypeInfo*, and four on DeclContext*, so set the alignment of the pointed-to types formally with alignas(N) instead of relying on operator new passing down the right alignment to the allocator. Get rid of the informal T::Alignment members of these classes and pass alignof(T) to their allocators. Fix the 'operator new' of DeclContext subclasses so that we can actually use the four tag bits PointerLikeTypeTraits<DeclContext*> claims are available.

Swift SVN r4587
2013-04-03 17:27:05 +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
Dave Zarzycki
2f31759280 Remove SemiStmt class
We have no intention of ever supporting actual semicolon statements
(separators, statements no), nor do we ever want to because that would
mean the behavior of the program would potentially change if semicolons
were naively removed.

This patch tracks the trailing semicolon now in the decl/expr/stmt,
which will enable someone to write a good "swift indent" tool in the
future.

Swift SVN r3824
2013-01-22 00:25:26 +00:00
Chris Lattner
a052faf351 remove some implementations of classof that are now unneeded with mainline LLVM changes.
Swift SVN r2989
2012-10-12 18:22:16 +00:00
Ted Kremenek
a5ec0af7e8 Rename 'BraceStmt::elements()' to 'getElements()' to match Swift
naming style for accessors.

Swift SVN r2742
2012-08-24 14:17:28 +00:00
Ted Kremenek
69b125d129 Remove dead code.
Swift SVN r2588
2012-08-09 01:08:11 +00:00
Ted Kremenek
479077e354 Remove individual element setters from BraceStmt, and just use MutableArrayRef and ArrayRef to access its elements.
Swift SVN r2586
2012-08-08 05:06:33 +00:00
Ted Kremenek
02c8131049 Add 'elements()' accessor to BraceStmt to provide easy iteration over
a BraceStmt's elements.  The other accessors can probably go away.

Swift SVN r2583
2012-08-07 23:11:47 +00:00
Ted Kremenek
219b7bd430 Move LLVM.h to libBasic.
Swift SVN r2550
2012-08-03 23:54:29 +00:00
Chris Lattner
db0cd646fc lexer/parser/ast/sema support for do/while statements. irgen next.
Swift SVN r2186
2012-06-17 02:29:54 +00:00
Eli Friedman
45f1fa1f6c Fix some comments; remove unused ErrorStmt.
Swift SVN r2169
2012-06-07 22:14:17 +00:00
Eli Friedman
c404598fcb Parsing and semantic analysis for 'break' and 'continue'.
Swift SVN r2087
2012-05-31 00:55:33 +00:00
Doug Gregor
302de6632d Switch the for-each loop informal protocol from getFirst()/dropFirst()
to the more input-iterator-centric getFirstAndAdvance(). Fixes
<rdar://problem/11401273>.


Swift SVN r1766
2012-05-08 00:37:01 +00:00
Chris Lattner
46c94377f1 Add support for var decls in the initializer of a c-style for loop,
implementing rdar://11360347 / 11349750.  C-style for loops could be
further enhanced by allowing a comma-separated list of statements in
the increment, but this isn't something I plan to do in the short term.


Swift SVN r1713
2012-05-02 05:44:58 +00:00
Chris Lattner
8c478d1cb7 remove the foreach keyword, switching foreach loops to use 'for' instead.
This uses one-token lookahead to distinguish between the two forms.


Swift SVN r1710
2012-05-02 01:06:06 +00:00
Chris Lattner
e205e1d2da change the subset of for statements we support: instead of *requiring* parens,
now we *do not allow* them.  This is progress towards unifying for and foreach.


Swift SVN r1709
2012-05-02 00:43:24 +00:00
Eli Friedman
e33b1aac24 Don't try to synthesize an expression for a return statement which doesn't have one. <rdar://problem/11315114>.
Swift SVN r1639
2012-04-25 22:58:06 +00:00
Doug Gregor
e1b8daa717 Rework 'foreach' AST to reflect how IRgen actually wants it to look,
rather than how I felt like generating it.


Swift SVN r1599
2012-04-24 20:42:17 +00:00
Doug Gregor
ac188c7d59 Implement type checking for the foreach loop and extend the AST to
hold all of the various expressions and declarations we'll need to
understand its semantics.


Swift SVN r1596
2012-04-24 20:22:36 +00:00
Doug Gregor
f997a781bf Parsing and basic AST representation for 'foreach' statement.
Swift SVN r1594
2012-04-24 18:12:44 +00:00
Chris Lattner
cbc1eac438 irgen parser and sema support for for statements.
Swift SVN r1505
2012-04-19 21:43:46 +00:00