Commit Graph

1710 Commits

Author SHA1 Message Date
Rintaro Ishizaki
f1202c4563 Merge pull request #15891 from rintaro/syntax-operator-selector
[Syntax] Parse 'operator' decl and '#selector' expr syntax.
2018-04-13 15:45:43 +09:00
Rintaro Ishizaki
203496f048 [Parse] Hoist diagnostics for named 'subscript'/'init'
Mainly for code readability.
2018-04-13 11:58:33 +09:00
Rintaro Ishizaki
eb69497d64 [Syntax] Parse 'operator' declaration syntax 2018-04-12 13:55:55 +09:00
Rintaro Ishizaki
b457500389 [Syntax] Parse 'precedencegroup' declaration syntax 2018-04-11 23:21:54 +09:00
Jordan Rose
6d30272bfd Merge pull request #14382 from jrose-apple/unknown-case
Implementation for `@unknown default`
2018-04-10 11:19:53 -07:00
David Zarzycki
7174d14dad [Parsing] NFC: metaprogram contextual decl keywords into Attr.def 2018-04-07 18:00:12 -04:00
Jordan Rose
701975ad1d Add parsing support for @unknown (SE-0192)
This is our first statement attribute, made more complicated by the
fact that a 'case'/'default' isn't really a normal statement. I've
chosen /not/ to implement a general statement attribute logic like we
have for types and decls at this time, but I did get the compiler
parsing arbitrary attributes before 'case' and 'default'. As a bonus,
we now treat all cases within functions as being switch-like rather
than enum-like, which is better for recovery when not in a switch.
2018-04-05 16:35:14 -07:00
Sho Ikeda
63d5d0994a [ParseDecl] Fix typo in comment
dyntamic -> dynamic
2018-04-05 13:32:28 +09:00
Rintaro Ishizaki
6d402888ad [Parse] Don't swallow 'try' at declaration member position (#15733)
Previously, this used to be accepted:
  class Foo {
    try func bar() { }
  }
2018-04-05 07:59:53 +09:00
Rintaro Ishizaki
66d400eb1b [Syntax] Parse 'enum' and 'case' declaration (#15704) 2018-04-04 08:38:08 +09:00
Rintaro Ishizaki
2e14337e4a [Parse] Don't allow attributed #errror/#warning (#15705) 2018-04-04 08:36:18 +09:00
Rintaro Ishizaki
18b28b9184 [Parse] Factor out declaration modifier list parsing (#15702) 2018-04-03 19:58:57 +09:00
Slava Pestov
f7697291df Parse: Backward compatibility for old spellings @_inlineable and @_versioned
Just parse these as @inlinable and @versioned, then emit a warning
(Swift 4.2 and below) or error (Swift 5).
2018-03-30 21:55:31 -07:00
Slava Pestov
d3e32388c5 Parse: Better error recovery from invalid attributes 2018-03-30 21:55:30 -07:00
Robert Widmann
03580d2fe5 Add a parameter list to EnumElementDecl
This models, but does not plumb through, default arguments.
2018-03-28 00:05:56 -04:00
Slava Pestov
34fd4ae512 AST: Use DeclBaseName::Kind::Constructor
Fixes <rdar://problem/35852727>, <https://bugs.swift.org/browse/SR-1660>,
<https://bugs.swift.org/browse/SR-6557>.
2018-03-16 00:25:56 -07:00
Huon Wilson
b1115af1eb Switch a pile of VarDecl::Specifier::Owneds to ::Default.
A lot of these probably should be Owned, but deciding that is work for
another time.
2018-03-08 12:36:37 +11:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
Slava Pestov
6065168928 Parse: Test that we only parse function bodies in primary files
I added this optimization a while ago but didn't add a test for it.
2018-03-06 19:42:43 -08:00
Arnold Schwaighofer
390ba419fc Add an effects(releasenone) function effects attribute
A ``@effects(releasenone)`` function might read/write global state but does not
perform a release.
2018-03-05 07:03:54 -08:00
Huon Wilson
b94c5364f5 [NFC] Rename 'Ownership' to 'ReferenceOwnership'.
There's really two forms of ownership: references and values. Renaming
to make way for better distinguishing of the two.
2018-03-02 11:38:28 -08:00
Joe Groff
d365c153d4 SIL: Introduce sil_property declarations for property descriptors.
This provides SILGen a place to generate the key path component information for an exported property so that it can be linked to from other modules.
2018-02-23 14:57:45 -08:00
Rintaro Ishizaki
6c0af2a24f [Syntax] Introduce CodeBlockItem (#14458)
CodeBlockItem represents Decl, Stmt or Expr that optionally followed by
semi-colon.
SourceFile syntax holds a list of CodeBlockItem.
2018-02-08 10:31:01 +09:00
Rintaro Ishizaki
ba58a2994d [Syntax] Parse associatedtype declaration
Also, added generic where clause to typealias declaration.
2018-02-06 09:33:12 +09:00
Rintaro Ishizaki
62eb27110d [Syntax] Parse 'init', 'deinit' and 'subscript' decl syntax 2018-02-05 19:15:46 +09:00
Harlan
5e02d2a877 Implement #warning and #error (#14048)
* Implement #warning and #error

* Fix #warning/#error in switch statements

* Fix AST printing for #warning/#error

* Add to test case

* Add extra handling to ParseDeclPoundDiagnostic

* fix dumping

* Consume the right paren even in the failure case

* Diagnose extra tokens on the same line after a diagnostic directive
2018-02-03 18:07:05 -05:00
Rintaro Ishizaki
2134f9f768 [Parse] Move SyntaxParsingContext to Parse (#14360)
This is only for the Parser.
Also, this resolves layering violation where libAST and libSyntax
depends on each other.
2018-02-03 10:43:52 +09:00
Mark Lacey
305a7eb87d IUO: Set the IUO attribute on ParamDecls for accessors arguments.
Add tests to show that for setter, getter, willSet, didSet,
and subscript setter we successfully implicitly unwrap this argument.
2018-01-27 17:22:33 -08:00
Jordan Rose
3f4cba25d4 Use a semantic ClangImporterSynthesizedTypeAttr for error structs
...rather than the ad hoc CustomTypeNameManglingAttr I was using
before. As John pointed out, the AST should be semantic wherever
possible.

We may someday want to get out of this being an attribute altogether,
or duplicating information that's available in the original Clang
node, by actually storing a reference to that node somewhere. This is
tricky and mixed up with deciding what hasClangNode() or
getClangDecl() would mean, though, so for now the attribute just
carries the information we need.
2018-01-24 10:57:52 -08:00
Jordan Rose
9c1a22ad0f Mangle synthesized error structs as a variant of the imported enum
When importing a C enum with the ns_error_domain attribute, we
synthesize a struct containing an NSError object to represent errors
in that domain. That synthesized struct should have a mangled name
that ties it to the original C enum, if we want it to be stable, and
now it does.

Before: $SSC7MyErrorV (a normal struct, which is a lie)
After: $SSC11MyErrorCode13ns_error_enumLLV
  kind=Global
    kind=Structure
      kind=Module, text="__C_Synthesized"
      kind=PrivateDeclName
        kind=Identifier, text="ns_error_enum"
        kind=Identifier, text="MyErrorCode"

Using the "private discriminator" feature allows us to pack in extra
information about the declaration without changing the mangling
grammar, and without stepping on anything the importer is using.

More rdar://problem/24688918
2018-01-23 17:05:43 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Yurii Samsoniuk
d5771cea6b Added extension specialization to libSyntax 2017-12-29 01:27:26 +09:00
Rintaro Ishizaki
2171061431 [Syntax] Fix round trip failure for unknown type attribute position
Use BacktrackingScope for backtracking.
2017-12-27 17:28:04 +09:00
Rintaro Ishizaki
063b5e752c [Syntax] Fix round trip failure for attribute at the top of getter 2017-12-27 16:43:10 +09:00
Rintaro Ishizaki
ed91d507d1 [Syntax] Handle EOF token at parseTopLevel()
instead of the destructor of Parser.
Destructor is not for this kind of tearDown work.
2017-12-26 13:35:12 +09:00
Rintaro Ishizaki
1a71241340 [Syntax] Fix typealias decl backtracking
Backtracking without BacktrackingScope used to cause round trip failure.
2017-12-26 12:30:22 +09:00
Rintaro Ishizaki
39746a9e58 [Parse] Inline skipExtraTopLevelRBraces()
Removed from 'parseTopLevel()'. There's no particular reason to diagnose
it in 'parseTopLevel()'.
2017-12-25 23:32:55 +09:00
Xi Ge
6c1f682af9 libSyntax: allow children of syntax nodes to have multiple choices. rdar://35879331 (#13562)
Some structures of syntax nodes can have children choices, e.g. a
dictionary expression can either contain a single ':' token or a list of
key-value pairs.

This patch gives the existing code generation infrastructure a way to
specify such node choices. Node choices are specified under a child
declaration with two constraints: a choice cannot be declared as
optional, and a choice cannot have further recursive choices.

Since we don't have too many node structures with choices, part of the
SyntaxFactory code for these nodes is manually typed.

This patch also teaches AccessorBlock to use node choices.
2017-12-20 15:33:57 -08:00
Xi Ge
e0d167f1dd libSyntax: create syntax nodes for variable declarations.
Variable declarations are declarations led by either 'var' or 'let'. It
can contain multiple pattern bindings as children.

For patterns, this patch only creates syntax nodes for simple identifier
patterns, e.g. 'a = 3'. The rest of the pattern kinds are still left
unknown (UnknownPattern).
2017-12-19 12:25:51 -08:00
Xi Ge
fe1a4ca0d2 libSyntax: create libSyntax node for var decl accessors. 2017-12-18 15:16:14 -08:00
Rintaro Ishizaki
8e967adc0e [Syntax] Parse attributed type node 2017-12-18 08:28:24 -08:00
Faiçal Tchirou
5e41098851 libSyntax: specialize class declaration syntax node. (#13485) 2017-12-16 11:36:58 -08:00
Xi Ge
b4b638651d libSyntax: create syntax node for typealias declarations. (#13450) 2017-12-14 17:44:54 -08:00
Xi Ge
a6b3559a8a libSyntax: specialize import declaration. (#13437) 2017-12-14 12:27:52 -08:00
Ben Langmuir
68a454556f Merge pull request #13348 from benlangmuir/cc-generic-subscript
[parse] Recover better from malformed subscript decls for code-completion
2017-12-13 15:45:03 -08:00
Ben Langmuir
dc5888d887 [parse] Recover better from malformed subscript decls for code-completion
Code-completion of generic types expects to get a DeclContext for the
subscript, so make sure we recover well enough to produce a
SubscriptDecl.

rdar://35619175
2017-12-13 13:37:41 -08:00
Xi Ge
fda8dfcfd3 libSyntax: specialize protocol declaration syntax. 2017-12-11 16:17:13 -08:00
Rintaro Ishizaki
60bfa893b9 [Parse] Make PersistentParserState to hold ParserPosition
instead of PersistentParserState::ParserPos.
2017-12-09 13:58:50 +09:00
Xi Ge
f870087805 libSyntax: specialize function declaration syntax node. 2017-12-07 17:28:19 -08:00
Xi Ge
c4604d700e libSyntax: specialize struct declaration syntax node. (#13307)
To construct struct syntax, this patch first specialized type
inheritance clause. For protocol's class requirement, we currently
treat it as an unknown type.

This patch also teaches SyntaxParsingContext to collect syntax nodes
from back in place. This is useful to squash multiple decl modifiers
for declarations like function. This is not used for struct declaration
because only accessibility modifier is allowed.
2017-12-06 14:12:12 -08:00