Commit Graph

624 Commits

Author SHA1 Message Date
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
Chris Lattner
827e168b40 refactor all the get/set parsing logic to merge the cases together into
one function.  Add to it logic to parse didset/willset.

Sema doesn't exist yet, so these aren't too useful yet.


Swift SVN r13019
2014-01-28 00:09:12 +00:00
Manman Ren
729d30fb54 SILParser: first step towards parsing sil_witness_table.
Only one entry kind out of four is supported right now.


Swift SVN r12936
2014-01-24 21:58:45 +00:00
Doug Gregor
11656c9798 Introduce the ParseDeclOptions option set in the Parser. NFC.
Swift SVN r12588
2014-01-20 17:38:12 +00:00
Doug Gregor
9412c07dea Switch 'static' to 'type' in tests.
Switch some diagnostic text from 'static' over to 'type' to make
things easier, and fix up some parsing issues with selector-style
declarations found by doing this. NFC


Swift SVN r12030
2014-01-08 01:37:32 +00:00
Doug Gregor
7cf688123b Allow "type var" and "type func" as synonyms for "static var" and "static func".
Swift SVN r12025
2014-01-08 00:59:22 +00:00
Doug Gregor
8cb2f1e131 Make sure we have a local context when parsing top-level code.
... even if that code is invalid. Eliminates a crash found as part of
<rdar://problem/15059074>.


Swift SVN r11869
2014-01-03 21:55:12 +00:00
Chris Lattner
fc5606ff19 Now that enough bugs are fixed :), mark more things as immutable values:
- foreach enumerators
- closure arguments with explicit patterns
- 'value' in a setter
- subscript arguments



Swift SVN r11681
2013-12-27 23:30:52 +00:00
John McCall
7173cec9db Thread contextual information about parsing the top-level
through various bits and use that to globally discriminate.

Swift SVN r11379
2013-12-17 04:31:40 +00:00
Chris Lattner
71af72a0ca Change a few more kinds of arguments to be 'var' arguments instead of 'let'
arguments.  Until we have @inout methods on structs, we can't mark anything
that can be address-exposed.  This temporarily regresses a few testcases,
but they will come back later.



Swift SVN r11359
2013-12-16 20:33:23 +00:00
John McCall
ab27d863a1 Parse all top-level code in the same local context.
Swift SVN r11207
2013-12-12 19:56:24 +00:00