Commit Graph

2357 Commits

Author SHA1 Message Date
Matthew Carroll
7882ddcf40 [DiagnosticsQoI] SR-3600: Better recovery for trying to name an initializer, deinitializer, or subscript
Add a diagnostic to remove the name of an initializer, deinitializer, or subscript. The identifier token is consumed and skipped to prevent the parser from emitting additional error messages.

Add tests to verify that the name is removed from initializers, deinitializers, and subscripts declared with a name.
2017-01-17 17:21:56 -05:00
Rintaro Ishizaki
055ee48908 [Parse] Split Decl list parsing from parseList()
Parsing declaration list (e.g. member list of nominal decl) is very
different from comma separated list, because it's elements are separated with
new-line or semi-colon. There's no good reason to consolidate them.

Also, declaration list in 'extension' or inside of decl '#if' didn't
emit diagnostics for consecutive declarations on a line.

    class C {
    #if true
      var value: Int = 42 func foo() {}
    #endif
    }
    extension C {
      func bar() {} subscript(i: Int) -> Int {
        return 24
      }
    }

This change consolidates declaration list parsing for
members of nominal decls, extensions, and inside of '#if'.

In addition, removed unnecessary property 'TrailingSemiLoc' from decl.
2017-01-17 17:19:36 +09:00
Michael Gottesman
d944930591 Remove the deallocating convention.
This is dead code and can be re-added if it is needed. Right now though there
really isnt a ValueOwnershipKind that corresponds to deallocating and I do not
want to add a new ValueOwnershipKind for dead code.
2017-01-10 17:32:17 -08:00
Slava Pestov
5eb16e6b34 Include-what-you-use: Initializer.h should not be pulled in from AST.h 2017-01-09 16:46:31 -08:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
Robert Widmann
d2570cb964 Restore local type declarations list 2017-01-06 16:16:39 -07:00
Robert Widmann
0febbf0b72 Effectively revert #5778
This reverts the contents of #5778 and replaces it with a far simpler
implementation of condition resolution along with canImport.  When
combined with the optimizations in #6279 we get the best of both worlds
with a performance win and a simpler implementation.
2017-01-06 16:16:39 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Slava Pestov
e6ada30291 Parse: Fix crash when alignment is too large 2017-01-03 23:40:44 -08:00
Slava Pestov
32ebe2db5a Parse: Don't crash if property with no declared type has addressors 2017-01-03 23:40:44 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Slava Pestov
2c6b9f71b6 AST: Change TypeAliasDecls to store an interface type as their underlying type
- TypeAliasDecl::getAliasType() is gone. Now, getDeclaredInterfaceType()
  always returns the NameAliasType.

- NameAliasTypes now always desugar to the underlying type as an
  interface type.

- The NameAliasType of a generic type alias no longer desugars to an
  UnboundGenericType; call TypeAliasDecl::getUnboundGenericType() if you
  want that.

- The "lazy mapTypeOutOfContext()" hack for deserialized TypeAliasDecls
  is gone.

- The process of constructing a synthesized TypeAliasDecl is much simpler
  now; instead of calling computeType(), setInterfaceType() and then
  setting the recursive properties in the right order, just call
  setUnderlyingType(), passing it either an interface type or a
  contextual type.

  In particular, many places weren't setting the recursive properties,
  such as the ClangImporter and deserialization. This meant that queries
  such as hasArchetype() or hasTypeParameter() would return incorrect
  results on NameAliasTypes, which caused various subtle problems.

- Finally, add some more tests for generic typealiases, most of which
  fail because they're still pretty broken.
2016-12-15 22:46:15 -08:00
Robert Widmann
cededef0d6 Add condition resolution as a new phrase post-parse
An unfortunately necessary thing to delay defrosting function bodies as
long as we can.
2016-12-14 15:39:19 -05:00
Robert Widmann
72beb9d80d Extract common code into StmtTransformer 2016-12-14 14:59:47 -05:00
Robert Widmann
a060eb5aca [SE-0075] Transfer the power of config resolution to Namebinding
This completely removes Parse’s ability to make any judgement calls
about compilation conditions, instead the parser-relevant parts of
‘evaluateConditionalCompilationExpr’ have been moved into
‘classifyConditionalCompilationExpr’ where they exist to make sure only
decls that we want to parse actually parse later.

The condition-evaluation parts have been moved into NameBinding in the
form of a Walker that evaluates and collapses IfConfigs.  This walker
is meant as an homage to PlaygroundLogger.  It should probably be
factored out into a common walker at some point in the future.
2016-12-14 14:59:47 -05:00
Robin Kunde
ab415e6b3e [Parse] Improve parser diagnostics for keyword-as-identifer errors (#6045)
Instead of the simple "expected identifier in declaration", the error will now read "keyword '%' cannot be used as an identifier here", and will be accompanied by a note suggesting escaping the keyword with backticks, as well as a fixit.

https://bugs.swift.org/browse/SR-3167
2016-12-13 16:12:53 -08:00
Doug Gregor
110bb14652 Merge pull request #6125 from rintaro/parse-decl-initparam
[Parse] Cleanup parameter list parsing
2016-12-07 10:26:44 -08:00
Doug Gregor
f2423b9bbd [Parser] Treat inheritance clauses as a separate scope.
This prevents us from looking in the enclosing scope to resolve names.
2016-12-07 08:10:11 -08:00
Rintaro Ishizaki
9eee4adc91 [Parse] Parameter list parsing cleanup
* Removed `parseConstructorArguments()`, unified with
  `parseSingleParameterClause()`.
* Use `parseSingleParameterClause()` from `parseFunctionSignature()`, so
  that we can share the recovery code.
* Removed `isFirstParameterClause` parameter from `mapParsedParameters`,
  because it's predictable from `paramContext`.
2016-12-07 23:20:30 +09:00
Michael Gottesman
59c6a64f5a [gardening] 0 => nullptr. Fixed with clang-tidy. 2016-12-06 23:14:13 -08:00
Xi Ge
54e8527d5c [code-completion] Ensure consumeDecl() does not alter the state of parser. (#6110)
This also fixes IDE/crashers/029-swift-decl-walk.swift.
2016-12-06 16:01:29 -08:00
Doug Gregor
8a1977dc63 [Sema] Move the computaton of the context type of 'self' later.
We cannot properly determine the context type of any parameter
(including 'self') until after we have determined the generic
environment for the enclosing function.
2016-12-05 22:42:03 -08:00
Argyrios Kyrtzidis
f548c2ba52 [code-completion] Fix assertion hit when completing after incomplete property.
Make sure to call getPtrOrNull() instead of get() directly.
2016-12-05 12:48:48 -08:00
Slava Pestov
8bdbe774e0 AST: Don't call hasType()/getType()/setType() on SubscriptDecls 2016-12-01 13:00:17 -08:00
Rintaro Ishizaki
670d9a166b [Parse] Parse 'inout' along with type attributes. 2016-11-29 20:56:16 +09:00
Slava Pestov
0f7a455d7d AST: Don't call setType() on AbstractFunctionDecls and EnumElementDecls 2016-11-29 03:05:33 -07:00
Slava Pestov
6cbb494ad2 AST: Give all ValueDecls an interface type
Previously, getInterfaceType() would return getType() if no
interface type was set. Instead, always set an interface type
explicitly.

Eventually we want to remove getType() altogether, and this
brings us one step closer to this goal.

Note that ParamDecls are excempt from this treatment, because
they don't have a proper interface type yet. Cleaning this up
requires more effort.
2016-11-29 03:05:25 -07:00
Rintaro Ishizaki
9b243526b8 [AST] Hold element name information in TupleTypeRepr
For now, only 'TupleTypeRepr::isParentType()' is using this informations.
Next commit will eliminate NamedTypeRepr.
2016-11-26 14:15:29 +09:00
practicalswift
2fe4254cb7 Merge pull request #5878 from practicalswift/https-swift-org
[gardening] Use the correct base URL (https://swift.org) in references to the Swift website
2016-11-22 09:17:57 +01:00
practicalswift
ae3c9de4e0 [gardening] Fix typos. 2016-11-20 19:30:10 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
David Farler
f450f0ccdf Revert "Preserve whitespace and comments during lexing as Trivia"
This reverts commit d6e2b58382.
2016-11-18 13:23:31 -08:00
David Farler
44f15558d6 Revert "Refactor: Rename Parser::consumeToken, consumeLoc. Add consumeToken API."
This reverts commit 39bfc123a3.
2016-11-18 13:23:31 -08:00
swift-ci
81f9fa2741 Merge pull request #5789 from rintaro/parse-isstartofdecl-skipattrs 2016-11-17 17:56:00 -08:00
Rintaro Ishizaki
89d7969bb4 [Parse] Skip attributes in isStartOfDecl().
Previously, '@' token was unconditionally considered as isStartOfDecl()

Since canParseTypeTupleBody() fails at isStartOfDecl(),
generics arguments containing attributes, e.g.
Array<(@convention(block) () -> Int) -> Void>
failed to be parsed.
2016-11-16 18:08:47 +09:00
David Farler
39bfc123a3 Refactor: Rename Parser::consumeToken, consumeLoc. Add consumeToken API.
These APIs return SourceLocs, and eventually the Parser should consume
tokens, which now include source trivia such as whitespace and comments,
and package them into a purely syntactic tree.  Just a tiny step. NFC.
2016-11-15 16:11:57 -08:00
David Farler
d6e2b58382 Preserve whitespace and comments during lexing as Trivia
Store leading a trailing "trivia" around a token, such as whitespace,
comments, doc comments, and escaping backticks. These are syntactically
important for preserving formatting when printing ASTs but don't
semantically affect the program.

Tokens take all trailing trivia up to, but not including, the next
newline. This is important to maintain checks that statements without
semicolon separators start on a new line, among other things.

Trivia are now data attached to the ends of tokens, not tokens
themselves.

Create a new Syntax sublibrary for upcoming immutable, persistent,
thread-safe ASTs, which will contain only the syntactic information
about source structure, as well as for generating new source code, and
structural editing. Proactively move swift::Token into there.

Since this patch is getting a bit large, a token fuzzer which checks
for round-trip equivlence with the workflow:

fuzzer => token stream => file1
  => Lexer => token stream => file 2 => diff(file1, file2)

Will arrive in a subsequent commit.

This patch does not change the grammar.
2016-11-15 16:11:57 -08:00
Robert Widmann
6212f0dfec Merge pull request #5759 from CodaFi/end-of-guile
[Parse] Check for the presence of EOF before charging ahead with a brace skip
2016-11-13 13:46:17 -05:00
Robert Widmann
75d28e12a7 Precedence group declarations are only valid at file scope. 2016-11-13 13:01:58 -05:00
Robert Widmann
bb434eba20 Check for the presence of eof before charging ahead with a brace skip 2016-11-13 12:09:26 -05:00
Slava Pestov
9e3d67ea27 Parser: Stylistic cleanup; enums are not called 'unions' anymore 2016-11-03 22:20:29 -07:00
swift-ci
ffe22f6713 Merge pull request #5104 from rintaro/static-toplevel 2016-10-24 00:17:31 -07:00
Rintaro Ishizaki
2c539c71f0 [Parse] Emit specialized diagnostics if seeing non-IdentTypeRepr in inheritance clause
Current Swift grammer accept only IdentTypeRepr (and protocol
composition in generics) in inheritance clause.
2016-10-19 02:22:23 +09:00
Rintaro Ishizaki
17ebbae628 [Parse] Reorder precedence of '&' operator in type parsing
Now 'P1 & P2.Type' is parsed as (composition P1, (metatype P2))
instead of (metatype (composition P1, P2)).

For now, parsing inheritance clause accepts any TypeRepr, that is not allowed
in current Swift grammer. Diagnostic logic will be added in later commits.

Also, in Swift3, (composition P1, (metatype P2)) should be fixed to
(metatype (composition P1, P2)) for source compatibility.
2016-10-19 02:22:23 +09:00
Rintaro Ishizaki
2fb48c6594 [AST] Rename ProtocolCompositionTypeRepr to CompositionTypeRepr
And make it be able to composite any TypeReprs.

Although Swift doesn't support composition of arbitrary types, AST
should be able to hold any TypeReprs, to represent syntax as accurate as
possible.
2016-10-19 02:22:23 +09:00
gregomni
dc239af995 The existing limitation that postfix operators can't begin with '?' or '!'
wasn't being detected while parsing operator decls, and so declarations of
invalid operators would be accepted without error and then later couldn't
be used.

Now errors correctly and new tests added.
2016-10-13 20:40:10 -07:00
Graydon Hoare
77cad91716 Parse and print @available(swift N) / @available(swift, ...) 2016-10-12 11:20:43 -07:00
Graydon Hoare
66f2027f62 s/Version/PlatformVersion/ to availability specs, add LanguageVersion. 2016-10-12 11:20:42 -07:00
Graydon Hoare
42c1a6ce42 Rename UnconditionalAvailabilityKind and UnavailableInCurrentSwift.
UnconditionalAvailabilityKind => PlatformAgnosticAvailabilityKind
    ::UnavailableInCurrentSwift =>   ::SwiftVersionSpecific

Plus a couple related method renamings. Prep work for SR-2709.
2016-10-12 11:20:41 -07:00
Xi Ge
e5d77911a2 [SourceKit] Indent property getters disregarding of empty bodies. rdar://28049927 (#5246)
[SourceKit] Indentation: when the indented line starts with open brace and the
line before starts with a leading declaration keywords, we never add
indentation level on the brace. rdar://28049927
2016-10-11 19:23:29 -07:00