Commit Graph

2357 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis
415a7036e2 [AST] In IfConfigDecl, keep track of its members per the block they belong to.
Swift SVN r15446
2014-03-25 03:55:31 +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
Ted Kremenek
4712476353 Wire up basic parsing support for @unavailable. WIP.
Swift SVN r15434
2014-03-25 01:14:51 +00:00
Ted Kremenek
3afa48172d Refactor string literal processing from @asmname into helper method.
This seems generally useful for processing other attributes.

Swift SVN r15433
2014-03-25 01:14:49 +00:00
Ted Kremenek
3673fde994 Change attribute 'asmname' syntax from '@asmname="..."' to '@asmname("...")'.
This grammar change is motivated by consistency with richer
attributes we are going to add in the future, @availablity,
and seems a more scalable syntax amendable to parser recovery.
Conceptually, the values of the attribute look like a tuple of
arguments.

Swift SVN r15430
2014-03-25 00:20:13 +00:00
Ted Kremenek
f43842e160 Change processing of @asmname to use a new internal representation.
This representation is inspired by Clang's internal representation.
The current attribute representation, which is basically a union
of "stuff" in DeclAttributes, is not amendable to richer
attributes, such as @availability, that need to be implemented.
In Clang, attributes are modeled with actual objects that
encode both semantic and syntactic information (e.g., source ranges)
that facilitate richer checking, better diagnostics, and better tools.

This change is foundational for implementing @availability, but
also is a better long-term representation.  As a migratory path,
it creates some duplications, with AttrKind and DeclAttrKind, the
two which should eventually become the same thing.

As part of this patch, there is some additional parser recovery
(for the new attribute representation) for duplicate attributes.
The parser now parses the entire duplicate attribute, which could
be quite complex, and then issues a diagnostic that the attribute
is a duplicate (and discarding it).  This delayed diagnostic
also allows us to present ranges for the duplicate attribute, which
provides a better user experience.

Swift SVN r15365
2014-03-22 14:58:30 +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
Doug Gregor
5e8e7279f8 Allow the first name of a selector-style function declaration to be separated.
Parse function declarations with the form

  func murder inRoom(room: Int) weapon(Int) {}

where the function name ("murder") is separated from the parameter
names. This is the same style used in initializers, i.e.,

  init withCString(cstr: CString) encoding(Encoding)



Swift SVN r15140
2014-03-17 16:04:21 +00:00
Joe Pamer
701ff469be Align declarations permissible within protocol bodies with the language reference.
Namely, nested structs, class, enum and other protocol declarations within protocols should raise a parse error, but not crash the type checker.
Also, protocol methods may not have bodies.

The fact that we weren't catching these issues resulted in a number of crasher bugs:
rdar://problem/15811382
rdar://problem/16290458
rdar://problem/16299208
rdar://problem/16316944

Swift SVN r15093
2014-03-14 23:24:12 +00:00
Doug Gregor
8cf018a1d2 Give Pattern::clone() an OptionSet rather than a bool; it's going to get more interesting.
Swift SVN r15061
2014-03-14 18:31:21 +00:00
Joe Groff
0b44a71741 Accept @asmname property accessors without bodies.
I want this so I can move the less magic bits of the Reflection implementation out of C++.

Swift SVN r15013
2014-03-13 23:51:13 +00:00
Chris Lattner
4d28ecd2b5 rename the default argument for "set" and "willSet" to "newValue" instead of
being "oldValue".


Swift SVN r14950
2014-03-12 05:11:14 +00:00
Joe Groff
b8d48dd7bb Change 'x.type' to 'x.dynamicType'.
It's not a common operation, so it doesn't need a terse name that occupies valuable identifier real estate.

Swift SVN r14932
2014-03-11 23:18:33 +00:00
Joe Groff
b08f06f191 Revert "Accept (and prefer) "import type" as a scoped import for any non-protocol type."
This reverts commit r14488, since we're demoting 'type' back to a plain old identifier.

We could consider reallowing 'type' as a contextual keyword here, but from talking to Jordan he was OK with just reverting this functionality.

Swift SVN r14931
2014-03-11 23:18:30 +00:00
John McCall
6471fc90ce Parse type attributes in generic argument lists in expressions.
Swift SVN r14913
2014-03-11 07:59:23 +00:00
John McCall
a9443d72f8 Parse attributes as part of <type> and simplify the grammar.
This means that we accept type attributes in a much broader
range of places where we previously required a <type>.  <type>
was already a production that demanded a grammatically
unconstrained context because of all the possible continuations;
reducing the number of independent productions makes it easier
to choose one and thus not accidentally limit the range of
possible types parsed.

In particular, we want to be able to parse @unchecked T? pretty
much anywhere you can write a type.

Swift SVN r14912
2014-03-11 07:59:22 +00:00
Dmitri Hrybenko
ab9dcd39c4 Source annotation: fix a crash on var decls with propagated types
rdar://16194527


Swift SVN r14868
2014-03-10 15:09:04 +00:00
Chris Lattner
2593a52b99 implement <rdar://problem/16191398> add an 'oldValue' to didSet so you can implement "didChange" properties
This names the implicit argument "oldValue".  Whether we keep implicit arguments or not
is a subject of debate, tracked by rdar://16268361.



Swift SVN r14819
2014-03-08 02:15:01 +00:00
Joe Groff
2448f33ffc Parser: Record the compound name of selector-style func decls.
Collect the identifiers for the selector pieces we parsed and use them to build a compound DeclName for the func decl. Currently this only manifests when __FUNCTION__ is used inside a selector-style function definition, where we now correctly produce the compound 'foo:bar:' name.

Swift SVN r14717
2014-03-06 03:36:49 +00:00
Doug Gregor
571ae697d5 Parsing and AST support for complete object initializers.
Enforce that complete object initializers always be delegating.

Swift SVN r14549
2014-03-01 00:51:18 +00:00
Jordan Rose
1fe8630bcd Accept (and prefer) "import type" as a scoped import for any non-protocol type.
Previously this was spelled "import typealias", and that spelling will
continue to be allowed (since someone may specifically be importing a
typealias and want that to match), but now that 'type' is a keyword,
"import type" is the right way to spell the generic "import any type"
scoped import.

Swift SVN r14488
2014-02-27 23:46:06 +00:00
Dmitri Hrybenko
f8026519f4 Parser: don't set 'Invalid' bit on SubscriptDecls too eagerly.
This makes the typechecker skip the decl completely, and it does not set types
on parameter patterns (not even to ErrorType).  In fact, in the problematic
case the type checker can cope with the decl just fine, so don't set the
Invalid bit.

This fixes a crash in code completion when it encounters such a decl,
rdar://16132349


Swift SVN r14459
2014-02-27 13:57:54 +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
Doug Gregor
1e8f02a45d Start diagnosing "deinit () { }".
Now that we do this, update the standard library, tests, other documents, etc.

Swift SVN r14423
2014-02-26 23:01:25 +00:00
Chris Lattner
97e1cb5ac5 switch diagnostics to refer to 'let'
Swift SVN r14420
2014-02-26 22:44:20 +00:00
Doug Gregor
dd143263eb Accept the "deinit { }" syntax, but don't require it.
Improve the Fix-It for the older "destructor" syntax so that it
replaces "destructor ()" with "deinit".

Swift SVN r14419
2014-02-26 22:42:14 +00:00
Chris Lattner
1344319677 Rename the internal compiler lexicon from val -> let.
Swift SVN r14408
2014-02-26 21:21:18 +00:00
Doug Gregor
981f8f6509 Rename "destructor" -> "deinit" (as a keyword) and -> "deinitializer" (in diagnostics).
Swift SVN r14380
2014-02-26 05:51:45 +00:00
Joe Groff
98d6fecc99 '.metatype' -> '.Type'
Also, reserve 'type' as a keyword for ensuing syntax changes.

Swift SVN r14375
2014-02-26 04:23:21 +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
Dmitri Hrybenko
1b65bbd641 Amend FIXME to have sensible text
Swift SVN r14340
2014-02-25 17:11:24 +00:00
Dmitri Hrybenko
5af5711ab7 Code completion: implement delayed parsing for accessor bodies, allowing code
completion inside computed properties.

Adding tests for willSet/didSet uncovered some crashes while doing code
completion (see FIXMEs), and I will investigate these next.

Partially addresses rdar://15849262


Swift SVN r14338
2014-02-25 16:51:07 +00:00
Doug Gregor
96be672daf Allow initializer requirements on protocols and check conformance to them.
Swift SVN r14320
2014-02-24 23:17:09 +00:00
Doug Gregor
048c67350b Move the diagnostic about a missing initializer body into Sema.
We did this for func declarations a long time ago; do it for
initializers as well.


Swift SVN r14318
2014-02-24 22:22: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
b30beea50b rework some error handling in the parser to make sure to mark invalid getters and
setters as isInvalid().  This fixes:
<rdar://problem/16109996> Assert on incorrect val computed properties in protocols


Swift SVN r14126
2014-02-20 06:19:15 +00:00
Doug Gregor
a1673d7c8f Add an Objective-C metatype representation spelled with @objc_metatype.
This representation is just a placeholder at the moment.


Swift SVN r14076
2014-02-19 07:21:38 +00:00
Chris Lattner
ecbbb4a42c rework our representations of subscripts to not curry the indexes
separately from the get/set value.  There is no exposed way in the
source language to use this, and this causes shorter term annoyance.

I chose to flatten the value and indices so the value comes first.
In principle, this allows us to completely eliminate our ObjC importer
thunks.  I haven't removed them though, because they might be useful
for something else.


Swift SVN r14049
2014-02-18 21:34:33 +00:00
Dmitri Hrybenko
ecd798b9fd Comment parsing: attaching comments to declarations
We can attach comments to declarations.  Right now we only support comments
that precede the declarations (trailing comments will be supported later).

The implementation approach is different from one we have in Clang.  In Swift
the Lexer attaches the comments to the next token, and parser checks if
comments are present on the first token of the declaration.  This is much
cleaner, and faster than Clang's approach (where we perform a binary search on
source locations and do ad-hoc fixups afterwards).

The comment <-> decl correspondence is modeled as "virtual" attributes that can
not be spelled in the source.  These attributes are not serialized at the
moment -- this will be implemented later.


Swift SVN r14031
2014-02-18 09:04:37 +00:00
Chris Lattner
28903887e7 Rename the internal compiler lexicon from let -> val.
Swift SVN r13992
2014-02-17 16:48:21 +00:00
Chris Lattner
602da91d1c switch diagnostics from let -> val.
Swift SVN r13990
2014-02-17 16:22:39 +00:00
Dmitri Hrybenko
016aee8fe8 Update grammar in comments after type -> static/class change
Swift SVN r13983
2014-02-17 12:27:45 +00:00
Doug Gregor
9d41af15b6 Make SIL output for open_existential actually parseable.
Swift SVN r13939
2014-02-15 05:52:19 +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
Chris Lattner
a6640a1b12 Rework has .sil files handle computed vardecls and subscripts.
Previously, we would just parse vars and subscripts with no definitions,
then let getters and setters be referenced arbitrarily later.  This was
problematic for a number of reasons, not least of which, the .sil file
might be invalid.

Instead, change sil to require that a protocol style definition indicate
whether a vardecl/subscript is computed or not, and whether it is both 
get-able and set-able, e.g. like "var x : Int { get }".  Change the 
sil printer to print decls in this form, and change the SILParser to 
make SILDeclRef::Func values instead of ::Getter/Setter values.

One thing that this exposed is that we weren't correctly serializing the
accessor state in modules, so accessors would get detatched from their
AbstractStorageDecls when deserialized (and in fact, their ASD never got
deserialized at all in some cases).  Fix this in the serialization of
the accessors.

NFC, other than the SIL printer and parser.



Swift SVN r13884
2014-02-14 00:57:04 +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