Commit Graph

784 Commits

Author SHA1 Message Date
Chris Lattner
d500e40dc7 Fix <rdar://problem/16843747> Disallow a single semicolon to be used as the only statement within a switch case
go back to disallowing ; in switch statements, people should use break
for empty statements.  It is much more explicit and obvious what you mean.




Swift SVN r17662
2014-05-08 01:08:51 +00:00
Chris Lattner
c24991cff6 Fix <rdar://problem/16798323> Following a 'break' statment by another statement on a new line result in an error/fit-it
Introduce a small amount of whitespace sensitivity into break/continue parsing
so that we don't consider an identifier on the next line to be a label.



Swift SVN r17439
2014-05-05 14:53:57 +00:00
Chris Lattner
92af326a15 generalize consumeIdentifier to work with self and Self. Use it in a few
more places to simplify code.  NFC.


Swift SVN r17438
2014-05-05 14:48:56 +00:00
Argyrios Kyrtzidis
2442d063ef [IDE] Fix syntax annotation crash with #if blocks that are missing an #endif.
rdar://16785562

Swift SVN r17231
2014-05-02 06:12:05 +00:00
Doug Gregor
9cfb1b5ca4 Keep track of the locations of the element names in a TupleExpr.
As part of this, use tail allocation to reduce the memory footprint of
TupleExprs. Use factory methods to make it easier to construct.

I'll be using this information in a follow-on patch. SourceKit
probably wants it as well.


Swift SVN r17129
2014-05-01 00:16:36 +00:00
Chris Lattner
11a79fafb6 tighten up some logic, principly by using dyn_cast instead of dyn_cast_or_null,
NFC.


Swift SVN r16954
2014-04-27 23:42:16 +00:00
Chris Lattner
c2bdc22925 Implement <rdar://problem/16380439> Add support for "#if false" and "#if true"
This implements true and false as magic constants in build configurations.
I considered adding 0 and 1 as magic integers, but true/false fit better with 
our boolean centric model.


Swift SVN r16915
2014-04-27 05:08:27 +00:00
Chris Lattner
0c390777ba Implement <rdar://problem/16204675> Need #elseif
This restructures IfConfigDecl/Stmt to be a list of clauses controlled
by a condition.  This makes it straight-forward to drop in #elseif support.

While I'm in here, this patch moves checking for extraneous stuff at the
end of the #if line from the lexer to the parser.  This means that you can
now put a comment on the same line as a #if/#else/#elseif/#endif.



Swift SVN r16912
2014-04-27 04:51:36 +00:00
Chris Lattner
0a5b27baf4 Implement labeled break/continue support, implementing rdar://11562938.
Right now you can 'break' out of a labeled switch statement, but unlabeled 
break retains its previous semantics of breaking out of the nearest loop.


Swift SVN r16616
2014-04-21 14:38:16 +00:00
Chris Lattner
0e7489c9d5 implement AST support for labels on loops & switch statements. This also
improves location information to track the label location in the AST.  We
don't currently track the location of the colon, but that would be trivial
to drop in if it is interesting.


Swift SVN r16608
2014-04-21 04:56:55 +00:00
Chris Lattner
8a6a9101e2 parser support for labels on loops and switch statements. No AST representation
yet.


Swift SVN r16603
2014-04-21 04:31:15 +00:00
Chris Lattner
b204be71cd simplify Parser::isStartOfStmt: just use the current token instead of having
all of the clients pass in the current token.  NFC.


Swift SVN r16601
2014-04-21 04:01:03 +00:00
Dmitri Hrybenko
f90e0c153b Make 'override' a keyword
rdar://16462192

Swift SVN r16115
2014-04-09 14:19:50 +00:00
Dmitri Hrybenko
a8f85d72bc Allow semicolon can be used as a single no-op statement in otherwise empty cases in
switch statements.

rdar://16381532


Swift SVN r16112
2014-04-09 10:40:48 +00:00
Joe Pamer
7b771affd9 Add limited build configuration support for testing against compiler submit versions. (rdar://problem/16337966)
This is meant to be utilized for a narrow set of scenarios specific to dogfooding our pre-1.0 compiler, so please do not take any dependencies on this.  In fact, I'll be removing this in the next milestone.  (See rdar://problem/16380797.)

Also included - improve error recovery when parsing broken build configuration clauses.

Swift SVN r15694
2014-03-31 20:34:02 +00:00
Joe Pamer
a54848d470 Fix regression when parsing #if clauses without a configuration expression. (rdar://problem/16376781)
Swift SVN r15539
2014-03-27 00:08:50 +00:00
Argyrios Kyrtzidis
f1d14c0911 [Basic/LangOptions] Remove std::unordered_map/unordered_set from LangOptions and use SmallVector instead.
The config options are so few that a map is not worth it currently.

Swift SVN r15476
2014-03-26 00:26:17 +00:00
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
3064e04d47 [Parser] Add the IfConfigDecl/IfConfigStmt ahead of its active members, so we can see it before them, in source order.
Swift SVN r15443
2014-03-25 03:55:28 +00:00
Argyrios Kyrtzidis
8f810a3887 [AST] Add EndLoc to the IfConfigStmt.
Swift SVN r15441
2014-03-25 03:55:26 +00:00
Chris Lattner
1f275532a6 now that nothing uses the PatternBindingDecl::HasStorage bit, there is no
reason to compute it, store it, serialize it, etc.  Remove the associated
logic.



Swift SVN r15302
2014-03-20 22:49:43 +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
Dmitri Hrybenko
c5f0a44c60 Parser: don't use EOF as source location for an error expr, AST verifier
rightfully complains about improper source range nesting

<rdar://problem/16276969> Crash in swift::ide::isSourceInputComplete()


Swift SVN r15115
2014-03-16 21:49:47 +00:00
Joe Pamer
3a0363b405 When parsing build configuration blocks, pass the actual BraceItemListKind through, rather than signify whether something is "top level" or not. This allows proper codegen for overloaded operators at the module top-level.
Swift SVN r14611
2014-03-03 21:48:36 +00:00
Joe Pamer
535cb4667c Minor code cleanup for the build configuration implementation.
Swift SVN r14475
2014-02-27 21:19:03 +00:00
Dmitri Hrybenko
56395e1849 Fix a type checker crash on:
func braceStmt3() {
  {
    undefinedIdentifier {}
  }
}

caused by the parser trying to be helpful and unwrapping the closure's
BraceStmt.  Unfortunately, DeclContexts inside the BraceStmt are wrong with
this recovery approach.

Unfortunately, this causes us to produce some extra error messages that the
original recovery strategy tried to avoid.

One thing we could do alternatively without making QoI worse is trying to save
the parser position and trying to reparse with correct assumptions, but that
could slow down the parser, so I did not implement this.


Swift SVN r14456
2014-02-27 10:25:38 +00:00
Chris Lattner
c16db63ae7 switch "val" to "let" in in the ASTPrinter, unbreaking tests.
Produce a warning + fixit for uses of 'val'.


Swift SVN r14435
2014-02-27 00:32:17 +00:00
Chris Lattner
1344319677 Rename the internal compiler lexicon from val -> let.
Swift SVN r14408
2014-02-26 21:21:18 +00:00
Joe Pamer
a0c57f496d Improve error recover for parsing build configuration blocks. Specifically, improve diagnostics for when users try to use #if/#else/#endif blocks in ways that would break brace statement or member list parsing. (Like if they were trying to emulate the C preprocessor.)
Swift SVN r14369
2014-02-26 02:06:29 +00:00
Joe Pamer
cc91b28076 If a target configuration invocation is followed by an indented identifier on a new line, the target invocation expression may be parsed as having a trailing closure. Add a new StructureMarkerKind so we can prevent this from happening.
Swift SVN r14368
2014-02-26 02:06:29 +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
Dmitri Hrybenko
3da05e347d Change property accessor syntax to include braces
See release notes update for details.

rdar://15966905


Swift SVN r14271
2014-02-22 21:00:56 +00:00
Chris Lattner
28903887e7 Rename the internal compiler lexicon from let -> val.
Swift SVN r13992
2014-02-17 16:48:21 +00:00
Dmitri Hrybenko
571c9b3c5e Split 'type' keyword into 'static' and 'class'
rdar://15911697


Swift SVN r13908
2014-02-14 14:50:32 +00:00
Doug Gregor
45ca5fe987 Use whitespace indentation to detect selector-style call continuations.
Implement several rules that determine when an identifier on a new
line is a continuation of a selector-style call on a previous line:

  - In certain contexts, such as parentheses or square brackets, it's
    always a continuation because one does not split statements in
    those contexts;

  - Otherwise, compare the leading whitespace on the line containing
    the nearest enclosing statement or declaration to the leading
    whitespace for the line containing the identifier.

The leading whitespace for a line is currently defined as all space
and tab characters from the start of the line up to the first
non-space, non-tab character. Leading whitespace is compared via a
string comparison, which eliminates any dependency on the width of a
tab. One can run into a few amusing cases where adjacent lines that
look indented (under some specific tab width) aren't actually indented
according to this rule because there are different mixes of tabs and
spaces in the two lines. See the bottom of call-suffix-indent.swift
for an example.

I had to adjust two test cases that had lines with slightly different
indentation. The diagnostics here are awful; I've made no attempt at
improving them.



Swift SVN r13843
2014-02-12 22:50:50 +00:00
Doug Gregor
e8b29aea02 Allow a closure after the first selector piece.
This allows code such as 

  obj.closure { return 0 } onError { println("error") }

to parse appropriately. The only other functionality change here is
that we no longer allow the use of a trailing closure within the
condition of a C-style for loop, because it did awful things to
recovery. I doubt we'll miss it.



Swift SVN r13823
2014-02-12 07:06:32 +00:00
Chris Lattner
6072e1d40d parse the 'val' keyword. For now it is a synonym for let. I will rip
'let' out (and continue migrating terminology in the compiler) as an
ongoing project.


Swift SVN r13821
2014-02-12 06:29:15 +00:00
Chris Lattner
201e1d9bf9 refactor parseExpr a bit: rename parseExpr to parseExprImpl and change
clients to either go through the new parseExpr (which is never "basic")
or the existing parseExprBasic entrypoint if they don't want trailing
closures.


Swift SVN r13724
2014-02-09 22:36:06 +00:00
Chris Lattner
a3972d96e0 rename AddVarsToScope to CollectVarsAndAddToScope and move it
down next to case statement parsing logic since it is specific to
it.  It looks like we can't fully eliminate this right now, because
patterns in case statements are parsed generally as expr patterns
and sema'd into something more useful later, too late for setting
variables in scopes.  The parsing logic could be improved here, but
I'm not going to work on this. 

As a driveby, improve error recovery when type checking of case
statement patterns fails by marking the decls inside of them as
invalid.


Swift SVN r13712
2014-02-09 19:29:19 +00:00
Chris Lattner
554f5e8ec0 Now that "addFunctionParametersToScope" just adds the variables
from the pattern to the scope (it doesn't do other argument
specific stuff like mucking with decl contexts) rename it to
addPatternVariablesToScope, and use it in two more places
in the parser.


Swift SVN r13710
2014-02-09 18:31:58 +00:00
Chris Lattner
70d547c1da remove a bunch of code that is manually monkeying around with DeclContexts,
now that they are implicitly updated.  This exposes two things:
1) we're unncessarily serializing selfdecls in ctors and dtors.
2) The index pattern of a SubscriptDecl has no sensible DeclContext that 
   owns variables in it.

I'll deal with the first tomorrow, I'm not sure what to do with
the second one.


Swift SVN r13703
2014-02-09 07:36:18 +00:00
Chris Lattner
ce9d97c2b9 similar to the previous patch, have all NominalTypeDecls auto-reparent
all of their generic parameters.  This simplifies logic creating them,
allowing us to eliminate all setDeclContext() calls from the parser.

While we're at it, change Parser::addVarsToScope to be a static 
function in ParseStmt.cpp and dramatically cut it down since none of
its remaining clients are using most of its capabilities.  It needs
to be simplified even further.


Swift SVN r13702
2014-02-09 07:20:03 +00:00
Chris Lattner
43a18e1675 Switch vardecls off of Parser::addVarsToScope, onto a simple
for loop that walks the pattern variables and sets them up.
Move addVarsToScope to ParseStmt.cpp which is what is left
using it.

Add a new "addAccessorsInOrder" helper to add the get/set
accessors to the Decls tree in the right order.



Swift SVN r13697
2014-02-09 06:21:56 +00:00
Chris Lattner
4b142e82d0 move Parser::isStartOfDecl into ParseDecl.cpp (where it makes more sense)
allowing us to turn two Parser methods into static functions.  NFC.


Swift SVN r13473
2014-02-05 04:43:33 +00:00
Argyrios Kyrtzidis
e38950ca4f [Parser] Fix verifier crash with incomplete switch case statement.
Swift SVN r13437
2014-02-04 18:19:31 +00:00
Joe Groff
a91ee5e1a0 Make sure 'switch' source ranges encapsulate their 'case's, even when incomplete.
Fixes <rdar://problem/15971438>.

Swift SVN r13395
2014-02-03 23:50:17 +00:00
Argyrios Kyrtzidis
0e12f527b3 [Parser] Fix verifier crash with case statements in incomplete source.
Swift SVN r13315
2014-02-02 03:14:35 +00:00
Argyrios Kyrtzidis
fa240a959b [Parser] Fix verifier crash when a switch statement has unmatched brace.
Swift SVN r13314
2014-02-02 03:14:34 +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