Commit Graph

1147 Commits

Author SHA1 Message Date
Huon Wilson
bb5d42d56d [Parser] Extract postfix expression suffix parsing. NFC. 2017-05-01 05:31:22 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Graydon Hoare
3d5c995615 Parse @_implements(Proto, DeclName) 2017-04-18 11:12:54 -07:00
Graydon Hoare
4d9ea18e59 Add mode to Parser::parseUnqualifiedDeclName for 0-arg compound names. 2017-04-18 11:12:54 -07:00
Graydon Hoare
e191b92966 Add mode to Parser::parseUnqualifiedDeclName to handle operator BaseNames. 2017-04-18 11:12:54 -07:00
Joe Groff
e3046d6f75 Parsing for native keypaths.
Use `#keyPath2` as a stand-in for the final syntax.
2017-04-04 11:31:15 -07:00
Rintaro Ishizaki
b56ab17fa5 [Parse] Separate compilation condition validation and evaluation
Fixes:
https://bugs.swift.org/browse/SR-3455
https://bugs.swift.org/browse/SR-3663
https://bugs.swift.org/browse/SR-4032
https://bugs.swift.org/browse/SR-4031

Now, compilation conditions are validated at first, then evaluated. Also,
in non-Swift3 mode, '&&' now has higher precedence than '||'.
'A || B && C || D' are evaluated as 'A || (B && C) || D'.

Swift3 source breaking changes:

* [SR-3663] This used to be accepted and evaluate to 'true' because of short
  circuit without any validation.

  #if true || true * 12 = try Anything is OK?
  print("foo")
  #endif

  In this change, remaining expressions are properly validated and
  diagnosed if it's invalid.

* [SR-4031] Compound name references are now diagnosed as errors.
  e.g. `#if os(foo:bar:)(macOS)` or `#if FLAG(x:y:)`

Swift3 compatibility:

* [SR-3663] The precedence of '||' and '&&' are still the same and the
  following code evaluates to 'true'.

  #if false || true && false
  print("foo")
  #endif
2017-03-23 01:25:29 +09:00
Huon Wilson
49277e4e05 [Parser] Don't warn about unescaping the _ in foo(_: 3).
foo(_: 3) is equivalent to foo(3), so calling a function that has _ as
an argument label (func foo(`_`: 3)) still requires the _ to be
escaped. Before this patch, the compiler would suggest removing the `s,
even though that changes behaviour.

Fixes rdar://problem/31077797.
2017-03-21 15:28:11 -07:00
Huon Wilson
ca3a398b4a Merge pull request #8021 from huonw/protocol-where-clause
Parse/typecheck/print where clauses on protocols
2017-03-15 11:00:46 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Huon Wilson
54f247693c [AST]/[Parse] parse where clauses on protocol declarations. 2017-03-09 16:08:16 -08:00
swift-ci
af53cb9778 Merge pull request #7733 from rintaro/parse-ifconfig-refactoring 2017-02-28 19:10:59 -08:00
Slava Pestov
928a74c47e Parse: Support for generic subscripts 2017-02-23 21:14:02 -08:00
Rintaro Ishizaki
3a2f8c9a40 [Parse] Promote parseDeclItem() to Parser method 2017-02-24 01:37:48 +09:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Rintaro Ishizaki
ff826e3491 [Parse] Limit max nesting level of StructureMarkerRAII (#7330)
The threshold is 256, for now.
2017-02-09 15:04:09 +09:00
Roman Levenstein
e5d5d7d5fd Some LayoutConstraint improvements.
This biggest change is:
- LayoutConstraintInfo is now a FoldingSetNode, which allows for proper canonicalization of LayoutConstraints. This is important for the correctness of type comparisons if types contain layout constraints.

No functionality changes from the client's point of view.
2017-02-07 17:03:11 -08:00
Rintaro Ishizaki
9b4f549943 [Parse] Improve diagnostics for consecutive identifiers 2017-01-26 15:37:19 +09:00
Slava Pestov
a67f4bdff4 Merge pull request #6948 from matthewcarroll/SR-3599-Better-Recovery-For-Decl-Names
[DiagnosticsQoI] SR-3599: Better recovery for decls with consecutive identifiers
2017-01-23 17:37:07 -08:00
Rintaro Ishizaki
0705506d91 [Parse] Make parseDecl() return ParserResult instead of ParserStatus 2017-01-23 13:18:11 +09:00
Rintaro Ishizaki
2192ca13b5 [Parse] Make parseDeclSubscript return ParserResult for SubscriptDecl 2017-01-23 13:18:11 +09:00
Rintaro Ishizaki
5537727046 [Parse] Make parseDeclEnumCase() return ParserResult for EnumCaseDecl 2017-01-23 13:18:11 +09:00
Rintaro Ishizaki
3705e2e4f2 [Parse] Make parseDeclVar() always return the ParserResult for PatternBindingDecl 2017-01-23 13:18:11 +09:00
practicalswift
9f9fd75a85 [gardening] Fix doxygen comment (///). 2017-01-21 10:32:33 +01:00
Matthew Carroll
93a7a9f80d [DiagnosticsQoI] SR-3599: Better recovery for decls with consecutive identifiers
Add diagnostics to fix decls with consecutive identifiers. This applies to
types, properties, variables, and enum cases. The diagnostic adds a camel-cased option if it is different than the first option.

https://bugs.swift.org/browse/SR-3599
2017-01-19 23:44:33 -05:00
Roman Levenstein
ed6c0aa34b Parsing of @_specialize
The new `@_specialize` attribute has a syntax like this:

```swift
@_specialize(exported: true, kind: full, where K == Int, V == Int)
@_specialize(exported: false, kind: partial, where K: _Trivial64)
func dictFunction<K, V>(dict: Dictionary<K, V>) {
}
```

If `exported` is set, the corresponding specialization would have a public visibility and can be used by clients.
If `exported` is omitted, it's value is assumed to be `false`.

If `kind` is `full` it means a full specialization.
If `kind` is `partial` it means a partial specialization.
If `kind` is omitted, its value is assumed to be `full`.
2017-01-18 16:42:10 -08:00
Rintaro Ishizaki
c92dbe5319 [Parse] Remove declaration list specific logic from parseList() 2017-01-17 17:19:36 +09: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
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
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
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
Joe Groff
277608a69b Print and parse SILBoxTypes with a new syntax.
Use a syntax that declares the layout's generic parameters and fields,
followed by the generic arguments to apply to the layout:

  { var Int, let String } // A concrete box layout with a mutable Int
                          // and immutable String field
  <T, U> { var T, let U } <Int, String> // A generic box layout,
                                        // applied to Int and String
                                        // arguments
2016-12-02 13:44:22 -08:00
Rintaro Ishizaki
670d9a166b [Parse] Parse 'inout' along with type attributes. 2016-11-29 20:56:16 +09:00
swift-ci
1e4bf0f2d3 Merge pull request #5909 from rintaro/parse-reject-throws-identifier 2016-11-23 19:08:03 -08:00
Rintaro Ishizaki
a1760161c5 [Parse] Don't parse 'throws' or 'rethrows' as identifiers
It seems there is no reason to accept them.
Why we want to accept `class C<throws> { ... }`?
2016-11-24 10:55:24 +09:00
Slava Pestov
02ad3cccef Merge pull request #5879 from apple/diag-split-tokens
[Lexer] Don’t suppress diagnostics when splitting a token
2016-11-23 18:25:17 -05:00
Jacob Bandes-Storch
f02e4ac2bf [Lexer] Don’t suppress diagnostics when splitting a token 2016-11-21 22:32:26 -08: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
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
Rintaro Ishizaki
47e07bc611 [Parse] Create DiagnosticTransaction along with BacktrackingScope
This prevents duplicated diagnostics.
2016-10-27 11:58:08 +09:00
Graydon Hoare
1af5c856fa Support #if swift(subminor-version), rdar://problem/28786959 / SR-2908. 2016-10-24 18:12:45 -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
3576b1480e [Parse] Factor-out old protocol<...> parser 2016-10-19 02:22:23 +09:00