Commit Graph

2357 Commits

Author SHA1 Message Date
Joe Groff
4c333d8071 AST: Accessors of static properties must be static functions.
Build the getter and setter of a static property as static func decls, and add a verifier check that the static-ness of a var and its accessors match up.

Swift SVN r10395
2013-11-13 00:28:52 +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
Joe Groff
ea698da596 Parser: Admit 'static' properties in nongeneric struct or enum decls.
These properties are truly static and can be implemented just as global variables, and this is all we need in the short term to give a good interface to NS_OPTIONS-like Cocoa enumerations.

Swift SVN r10349
2013-11-11 23:57:27 +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
Doug Gregor
e5ca2c90d0 Parse @optional attribute on protocol members.
Swift SVN r9959
2013-11-05 15:58:19 +00:00
Chris Lattner
68af974227 Remove 'axle' related code and build machinery. It turns out that we
will not be pursuing this project in the immediate future.



Swift SVN r9901
2013-11-03 16:04:27 +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
Jordan Rose
766f41f266 Put top-level decls in the SourceFile DeclContext, rather than in the TU.
Swift SVN r9647
2013-10-24 18:59:24 +00:00
Mark Lacey
eaa7018ed0 Fixup attribute syntax in LangRef.html.
There are still some [infix_left=] in the text. Based on
r4627 it looks like these can just be deleted, but I haven't
done so at this time.

Swift SVN r9616
2013-10-23 08:12:21 +00:00
Dmitri Hrybenko
e2b0f08f57 Parser: allow an optional trailing comma in array and dictionary literals
rdar://14874038


Swift SVN r9567
2013-10-21 23:13:22 +00:00
Dmitri Hrybenko
2b7c36c1a8 Parser recovery: skip multiple right braces at top level, both at the beginning
and at the end of the file

rdar://15267668


Swift SVN r9544
2013-10-21 17:55:31 +00:00
Joe Groff
5721bdda01 Don't pretend we can parse enum case refined types.
There's no way we'll be able to fully implement GADTs anytime soon.

Swift SVN r9477
2013-10-18 01:34:25 +00:00
Dmitri Hrybenko
2415cd9028 Code completion: rename a variable for consistency with AST node name
Swift SVN r9425
2013-10-16 22:28:26 +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
Dmitri Hrybenko
46a4bc1402 Code completion: preserve the AST for the parsed top-level code. This enables
us to find iteration variables while doing code completion in nested top-level
code.

Fixes part of rdar://15199468


Swift SVN r9343
2013-10-15 01:24:16 +00:00
Manman Ren
d503c65036 SILParser: parse sil_vtable
rdar://15165644


Swift SVN r9342
2013-10-15 00:52:40 +00:00
Chris Lattner
b8baf03495 rename parseAttribute* to parseDeclAttribute*, since they
are for decl attributes.


Swift SVN r9288
2013-10-13 16:53:44 +00:00
Chris Lattner
24ff772bad switch get/set specifiers to the new attribute syntax, and completely remove
the old syntax, woo.


Swift SVN r9287
2013-10-13 16:50:03 +00:00
Chris Lattner
b3fe5a30f2 stop parsing old attribute syntax on functions.
Swift SVN r9284
2013-10-13 15:18:12 +00:00
Chris Lattner
61c50396df rip out parser support for the old attribute syntax from a bunch of decl kinds.
notably, var and func are left to go (as are get/set)


Swift SVN r9278
2013-10-13 06:10:28 +00:00
Chris Lattner
a476f65471 Abolish the old attribute syntax for type attributes (and SIL type attrs)
- Change type attribute printing logic (in astprinter and the demangler) 
  to print in the new syntax
- Change the swift parser to only accept type attributes in the new syntax.
- Update canParseTypeTupleBody to lookahead over new-syntax type attributes.
- Update the testsuite to use the new syntax.



Swift SVN r9273
2013-10-13 05:39:46 +00:00
Chris Lattner
80aee75507 The weak/unowned attributes are overloaded to mean two things:
1) on decls, they say the decl is weak/unowned.
2) in sil mode, on types, they indicate that the type has weak/unowned storage.

Since these are different things, split the SIL type attributes out to new 
attributes (sil_weak/sil_unowned) to crystalize the relationship.


Swift SVN r9270
2013-10-13 04:38:11 +00:00
Chris Lattner
e341dd94e9 inout, localstorage and silself are type attributes, not decl attributes.
Swift SVN r9269
2013-10-13 04:14:03 +00:00
Chris Lattner
b75e7c135b cc, auto_closure, thin, and objc_block attributes are only valid on types, make them
specific to types.  While we're at it, improve the diagnostic for when a decl-specific
attribute is applied to a type, or a type-specific attribute is applied to a decl.


Swift SVN r9268
2013-10-13 04:05:45 +00:00
Chris Lattner
6e006bbfea remove the (unused now) AttrListKind enum which previously distinguished
between decl and type attributes.  Now that these are going down different
paths, it isn't needed.


Swift SVN r9267
2013-10-13 03:33:22 +00:00
Chris Lattner
0dd0602b97 introduce a new (thinner) TypeAttributes class, which *just* holds
type attributes.  Use this when parsing type-annotations, and when
building TypeReprs.



Swift SVN r9266
2013-10-13 03:31:09 +00:00
Chris Lattner
09705dc7cd 1) Redesign DeclAttributes to be based around an array indexed by attribute, instead
of having a ton of ad-hoc bools in it.  This allows us to consolidate a ton of 
   boilerplate, eliminating 250 lines of code:

 17 files changed, 435 insertions(+), 662 deletions(-)

2) This eliminates the special case for weak and unowned attributes, which previously
   didn't show up in Attr.def.

3) While we're at it, keep track of proper source locations for each attribute, and
   use these to emit diagnostics pointing at the attribute in question instead of at
   a funcdecl or the @ sign.

4) Fix axle attributes, which had vertex and fragment swapped.



Swift SVN r9263
2013-10-13 01:25:50 +00:00
Chris Lattner
a718c8f57a start improving the attribute implementation: start with passing down
a "kind" for the attribute, to indicate whether the caller is looking for
a type, decl, or sil attribute.  This is currently unused.


Swift SVN r9261
2013-10-12 22:13:51 +00:00
Chris Lattner
9f439292b6 Implement support for type-attributes on the result of a function type or decl.
Also, improve error recovery for new-syntax attributes.

This means that we now compile the testcase into:

t.swift:3:16: error: unknown attribute 'xyz'
var x : () -> @xyz Int
               ^
t.swift:6:16: error: unknown attribute 'xyz'
func foo() -> @xyz Int {
               ^

instead of:

t.swift:4:15: error: expected type for function result
func foo() -> @xyz Int {
              ^
t.swift:4:14: error: consecutive statements on a line must be separated by ';'
func foo() -> @xyz Int {
             ^
             ;
t.swift:4:16: error: unknown attribute 'xyz'
func foo() -> @xyz Int {
               ^
t.swift:7:1: error: expected declaration

^

this is part of rdar://15183765


Swift SVN r9260
2013-10-12 21:27:16 +00:00
Doug Gregor
e0f3477483 Diagnose attempts to declare a postfix '!' operator.
Swift SVN r9184
2013-10-11 00:08:34 +00:00
Jordan Rose
0d2ccf7cb3 Adopt SourceFile in name-binding.
Swift SVN r9105
2013-10-09 22:44:32 +00:00
Doug Gregor
fba128e191 Axle: Implement Vec<T, N> syntactic sugar for the VecTxN structs.
Implements the first part of <rdar://problem/15100137>.


Swift SVN r9092
2013-10-09 21:12:19 +00:00
Jordan Rose
266c445b3c Push ASTStage down into SourceFile.
This was only meaningful for TranslationUnit anyway, and it may help
avoid repeating work in the future.

Swift SVN r9079
2013-10-09 18:38:28 +00:00
Jordan Rose
f5de2e43d7 Push SourceFile into Parser and REPL somewhat.
Swift SVN r9073
2013-10-09 18:38:17 +00:00
Jordan Rose
597640a5d2 Introduce "SourceFile" within a TranslationUnit.
Right now this is just an extra layer of indirection for the decls,
operators, and imports in a TU, but it's the first step towards compiling
multiple source files at once without pretending they're all in a single
file. This is important for the "implicit visibility" feature, where
declarations from other source files in the same module are accessible
from the file currently being compiled.

Swift SVN r9072
2013-10-09 18:38:15 +00:00
Doug Gregor
a012f60633 Make protocol methods generic over <Self>.
Pull the implicit 'Self' associated type out of the protocol and into
an implicitly-declared generic parameter list for the protocol. This
makes all of the methods of a protocol polymorphic, e.g., given

  protocol P {
    typealias Assoc
    func getAssoc() -> Assoc
  }

the type of P.getAssoc is:

  <Self : P> (self : @inout P) -> () -> Self.Assoc

This directly expresses the notion that protocol methods are
polymorphic, even though 'Self' is always implicitly bound. It can be
used to simplify IRgen and some parts of the type checker, as well as
laying more of the groundwork for default definitions within
protocols as well as sundry other improvements to the generics
system.

There are a number of moving parts that needed to be updated in tandem
for this. In no particular order:
  - Protocols always get an implicit generic parameter list, with a
  single generic parameter 'Self' that conforms to the protocol itself.
  - The 'Self' archetype type now knows which protocol it is
  associated with (since we can no longer point it at the Self
  associated type declaration).
  - Protocol methods now get interface types (i.e., canonicalizable
  dependent function types).
  - The "all archetypes" list for a polymorphic function type does not
  include the Self archetype nor its nested types, because they are
  handled implicitly. This avoids the need to rework IRGen's handling
  of archetypes for now.
  - When (de-)serializing a XREF for a function type that has an
  interface type, use the canonicalized interface type, which can be
  meaningfully compared during deserialization (unlike the
  PolymorphicFunctionType we'd otherwise be dealing with).
  - Added a SIL-specific type attribute @sil_self, which extracts the
  'Self' archetype of a protocol, because we can no longer refer to
  the associated type "P.Self". 




Swift SVN r9066
2013-10-09 17:27:58 +00:00
Dmitri Hrybenko
bfbe25fae0 Fix comment: 'constructor' is no longer a keyword
Swift SVN r9043
2013-10-09 00:51:30 +00:00
Jordan Rose
5cca9603e8 Remove DeclContext from IdentTypeRepr.
Unfortunately I can't figure out a way to do the suggested refactoring of
packing the identifier into the PointerUnion as well, since some clients
ask for the identifier back even after name-binding has occurred.

Swift SVN r9009
2013-10-08 00:24:11 +00:00
Dmitri Hrybenko
9ca8498bc5 Code completion: type check all decl contexts of the completion point, not just the nearest one
Fixes some of the crashes with nested nominal type decls.


Swift SVN r9008
2013-10-08 00:15:46 +00:00
Chris Lattner
f990775e3c enhance the parser to parse the new attribute syntax on all decls. Switch a few
testcases to use it.


Swift SVN r8910
2013-10-04 05:03:52 +00:00
Chris Lattner
394ca8f944 implement basic support for parsing the new form of attribute, though this
is only used by the sil parser.  The old form is still parsed.


Swift SVN r8906
2013-10-04 04:02:09 +00:00
Dmitri Hrybenko
04a8cdef03 Completely remove the 'constructor' keyword
Swift SVN r8882
2013-10-03 18:12:15 +00:00
Argyrios Kyrtzidis
f0773bcba1 Rename '__subscript' -> 'subscript'.
Since 'subscript' is a keyword, it cannot conflict with a function name.

Swift SVN r8787
2013-09-30 19:17:29 +00:00
Argyrios Kyrtzidis
151f76e02c [Parser] Add the getter/setter of a subscript decl in source order.
Swift SVN r8781
2013-09-30 17:59:03 +00:00
Argyrios Kyrtzidis
8b76b30931 [AST] Add 'Implicit' boolean parameter in Pattern::clone(), which if true propagates 'implicitness' in the cloned pattern and its subpatterns.
Use it for the patterns of getter/setter of a subscript decl.

Swift SVN r8780
2013-09-30 17:59:01 +00:00
Joe Groff
df5f1f51dd Parse attribute list after enum 'case' keyword.
For consistency with our other decl types. There aren't any case-specific attributes yet, but if/when we add them, this is where they'll go.

Swift SVN r8779
2013-09-30 17:13:34 +00:00
Argyrios Kyrtzidis
c00fce9ad6 [Parser] Add the getter/setter of a computed variable in source order and after the pattern binding decl.
Swift SVN r8766
2013-09-29 00:12:26 +00:00