Commit Graph

804 Commits

Author SHA1 Message Date
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
Chris Lattner
65aa09d464 implement support for let declarations.
Swift SVN r11195
2013-12-12 18:33:42 +00:00
Chris Lattner
03518d240f revert r11192, I accidentally included too much in the patch.
Swift SVN r11193
2013-12-12 18:24:33 +00:00
Chris Lattner
778225eb96 Implement let declarations.
Swift SVN r11192
2013-12-12 18:22:46 +00:00
Chris Lattner
b1a2059604 Implement the ability to create a Pattern as a set of 'let' decls instead of
var decls.  I was originally intending to use this for argument lists, but I
don't think that's a great direction to go anymore.

In any case, it seems uncontroversial to enforce immutability on foreach
enumation patterns, so I did that (see testcase)



Swift SVN r11124
2013-12-11 07:28:13 +00:00
John McCall
a5febc6b48 Track discriminators for closure expressions.
Swift SVN r10905
2013-12-06 02:23:57 +00:00
Dave Abrahams
4c0e6eec4a [stdlib] Rename Enumerable => Sequence
Swift SVN r10857
2013-12-05 13:18:41 +00:00
Manman Ren
05899b7a8d SILParser: parse sil_global and sil_global_addr.
rdar://15493552


Swift SVN r10823
2013-12-05 00:46:40 +00:00
Doug Gregor
002038ad8e Allow a comma-separated list of init expressions in C-style for loops.
Swift SVN r10748
2013-12-03 15:14:54 +00:00
Argyrios Kyrtzidis
3a1d504cff [Parser] Fix crash-on-invalid, with top-level statements and -parse-as-library.
Part of rdar://15484631

Swift SVN r10558
2013-11-19 17:55:04 +00:00
Dmitri Hrybenko
81dc5deee8 Change 'def' keyword back to 'func'
Swift SVN r10522
2013-11-17 07:45:28 +00:00
Doug Gregor
3700c7bf13 Allow comma-separated expressions in the increment portion of a C-style for loop.
Fixes <rdar://problem/15267269>.


Swift SVN r10399
2013-11-13 00:54:02 +00:00
Joe Groff
4f2adbe7ed AST: Include 'static' bit in VarDecls.
And track the 'static' SourceLoc in the PatternBindingDecl. This lets isInstanceMember return the right thing for static vars.

Swift SVN r10369
2013-11-12 06:16:48 +00:00
Joe Groff
8b11158753 Parser: Allow static vars in DisallowStoredVar contexts.
The contexts for which we set the DisallowStoredVar bit, currently enums and extensions, can both (theoretically) support static variables, so change PD_DisallowStoredVar to PD_DisallowStoredInstanceVar, and allow static vars to be declared in these contexts.

Swift SVN r10350
2013-11-12 00:13:21 +00:00
Dmitri Hrybenko
d19d82e876 Parser: fix a crash on extra closing brace in parse-as-library mode
rdar://15359129


Swift SVN r10071
2013-11-09 02:44:56 +00:00
Dmitri Hrybenko
d6012459c3 Eliminate IsTopLevel parameter from Parser::parseBraceItems() -- its value can
be computed from other parameter.


Swift SVN r10069
2013-11-09 02:06:39 +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
Dmitri Hrybenko
91ce21666d Change 'func' keyword to 'def'
I tried hard find all references to 'func' in documentation, comments and
diagnostics, but I am sure that I missed a few.  If you find something, please
let me know.

rdar://15346654


Swift SVN r9886
2013-11-02 01:00:42 +00:00
Dmitri Hrybenko
238d898a0d Code completion for enums: model completion in switch case as a separate kind
of completion.  This approach (rather than SourceLoc tricks) better reflects
the intent and allows us to fix the rest of testcases.


Swift SVN r9557
2013-10-21 20:58:23 +00:00
Dmitri Hrybenko
de6a0a0f8c Code completion: complete references to enum elements in switch statements when
we have enough type context to find the correct enum


Swift SVN r9439
2013-10-17 02:09:49 +00:00
Dmitri Hrybenko
278cbad8a4 Code completion: don't produce any results in enum case. Only integer literals
are allowed in that context.


Swift SVN r9383
2013-10-15 22:45:54 +00:00