Commit Graph

127 Commits

Author SHA1 Message Date
Doug Gregor
bbd5dfcfdf Allow variables with a getter or setter to be declared in a
struct/oneof/class extension, making them instance methods. Normal
variables are still not allowed in these contexts, however.

The fact that we set DeclContexts late causes some consternation here,
because it's not clear just how far we need to recurse in
DeclContext. I've done enough to make properties work, but I'm still
rather uneasy about the current state of affairs.


Swift SVN r1423
2012-04-13 21:45:27 +00:00
Doug Gregor
511195b1be Traverse the getter/setter of a VarDecl, so that we get type checking
for these functions. And now that it's actually type-checked, build
the getter's AST properly.


Swift SVN r1416
2012-04-13 18:16:15 +00:00
Eli Friedman
9bf8dcf0f1 Delete some dead code.
Swift SVN r1412
2012-04-13 01:05:12 +00:00
Doug Gregor
7823cd48eb Wire properties into the AST for VarDecl, and add dumping support. No
tests until we start type-checking something.


Swift SVN r1410
2012-04-13 00:27:22 +00:00
Doug Gregor
6ce55acfc4 Parse getters and setters for variables.
Swift SVN r1408
2012-04-12 23:59:53 +00:00
Chris Lattner
dcc3ab2f21 Fix rdar://11087238, a crash on structs inside funcs. This adds
a source location to the implicit ExtensionDecl (fixing the crash)
and also allows extensions that aren't at the top level.  Eventually
we'll want to constrain where extensions can exist (for example,
global types should require extensions to be at global scope?) but
we don't need to do that now.


Swift SVN r1398
2012-04-12 20:22:58 +00:00
Eli Friedman
361481835c Introduce a notion of module scope declarations; use it where appropriate instead of checking for a local declcontext.
Swift SVN r1380
2012-04-11 02:52:40 +00:00
Eli Friedman
065a74d237 Make sure we always explicitly set the DeclContext for a VarDecl built from a pattern.
Swift SVN r1379
2012-04-11 02:24:36 +00:00
Chris Lattner
fbfb76a515 rename 'plus' methods to 'static' methods, resolving:
<rdar://problem/10718220> Need a better name than 'plus' for "static" functions



Swift SVN r1340
2012-04-06 17:50:43 +00:00
Eli Friedman
6d168636b1 Fix comments to reflect LangRef.
Swift SVN r1327
2012-04-05 02:22:35 +00:00
Eli Friedman
f477cf588e Introduce the notion of the "main" module, i.e. the module which defines main(). Disallow top-level statements in modules other than the main module. Fix IRGen to generate a main() function in the main module, and implement top-level statements. Get rid of the main() mangling hack. Part of <rdar://problem/11185451>.
I haven't really carefully considered whether existing type-checking etc. is correct for the main module (I think the name-binding rules need to be a bit different?), but it seems to work well enough for the obvious cases.

This is enough to get the one-liner "println(10)" to print "10" in "swift -i" mode, although the path to swift.swift still needs to be explicitly provided with -I.



Swift SVN r1325
2012-04-05 00:35:28 +00:00
Eli Friedman
70770465e4 Get rid of ParseResult. <rdar://problem/11018362>.
Swift SVN r1321
2012-04-04 20:21:35 +00:00
Eli Friedman
94244131f7 Remove ElementRefDecl and DeclVarName. Add the replacement, PatternBindingDecl. Use proper pattern parsing for variable declarations. Uniformly use PatternBindingDecl for variable initialization. Adapt type-checking and IRGen for this new style of variable declaration. <rdar://problem/11124980>.
Swift SVN r1312
2012-04-02 23:49:28 +00:00
Doug Gregor
f370accf59 Introduce the notion of structured dependent types, such as a tuple
type with one or more elements of dependent type. Previously, an
expression such as (x, 5) would have the (unstructured) dependent
type, limiting our ability to type-check the subexpression 'x'
early. Now, if 'x' has type 'int' (for example), this expression will
now have the type (int, <<unstructured dependent type>>).

Extend coercion of a tuple to tuple type to handle coercion to
(structured) dependent tuple types, coercing element-by-element. This
code is very lightly tested and may still need to be restructured.




Swift SVN r1294
2012-03-29 16:26:04 +00:00
Doug Gregor
4cc616f2be Rename the DependentType class to UnstructuredDependentType, because
this type is only going to cover dependent types for which there is
absolutely no structure. Still no functionality change.


Swift SVN r1292
2012-03-29 14:14:48 +00:00
John McCall
2fd608ae4d Add basic parsing and type-system support for the byref(heap)
qualifier, making sure that variables end up so-qualified by
default.  Add a RequalifyExpr to capture the act of adding
qualifiers (to form a supertype) to an l-value.

Swift SVN r1236
2012-03-19 06:55:23 +00:00
Chris Lattner
1884e4943f refactor some code out of Sema into AST.
Swift SVN r1225
2012-03-17 23:07:00 +00:00
Chris Lattner
4c5f406928 don't crash when printing a decl that doesn't have its type set yet.
Swift SVN r1206
2012-03-11 23:55:47 +00:00
Chris Lattner
01b184acab parse the auto_closure attribute.
Swift SVN r1186
2012-03-11 12:44:19 +00:00
John McCall
b8b1694564 Complain about file names that aren't valid identifiers.
When we divide the world into scripts and modules, this
won't matter for the former.  Recognize <stdin> as a
special case;  it should instead just always be a script.
Fixes rdar://problem/10986311.

Swift SVN r1181
2012-03-11 09:15:17 +00:00
Chris Lattner
4f8040845e improve a comment.
Swift SVN r1180
2012-03-11 04:56:59 +00:00
Chris Lattner
9e873372d9 move attributes out to their own .def file, to match expr's and stmt's.
Part of rdar://10719165 - Clean up attributes code


Swift SVN r1179
2012-03-11 01:39:11 +00:00
Eli Friedman
ddffb633eb Fix build errors with clang-421.
Swift SVN r1167
2012-03-05 19:31:12 +00:00
Chris Lattner
58b4a5d7cc have the parser produce ErrorStmt nodes to handle semantic errors...
except that it never produces semantic errors.  How about that.


Swift SVN r1143
2012-03-01 22:54:41 +00:00
Chris Lattner
1076367d73 implement rdar://10962528 - split up the int/fp literal lexing and grammar.
This cleans up handling of int/fp literals by splitting them appart at the
lexer level.


Swift SVN r1137
2012-03-01 19:06:55 +00:00
Chris Lattner
17ea0a6670 finish my pass over LangRef, updating it and changing it and the parser to keep the grammars in sync.
Swift SVN r1132
2012-03-01 16:55:09 +00:00
Chris Lattner
ee89183c13 attribute-list is nullable, so it doesn't need to be optional, this matches lang-ref.
Swift SVN r1129
2012-02-26 19:01:15 +00:00
Chris Lattner
ee0f2bb436 var names cannot be operators. We already diagnosed this at sema time, but
it's better to catch it earlier to make the grammar more clear.


Swift SVN r1128
2012-02-26 18:55:03 +00:00
Chris Lattner
cd29a77770 introduce a new parseIdentifier method that *just* parses identifiers,
but not operators.  Audit calls to make sure that we use the right one
in the right places.  This allows us to reject structs named * for example.


Swift SVN r1127
2012-02-26 18:20:58 +00:00
Chris Lattner
dd0c5aff52 Rename parseIdentifier to parseAnyIdentifier to match langref and
make it clear to it also allows operators.


Swift SVN r1126
2012-02-26 18:16:30 +00:00
John McCall
00b97b38af Grab-bag of materialization-related changes:
- introduce the concept of qualifiers on l-value types
  - teach overload resolution and coercion how to drop explicitness
  - require explicitness on normal [byref] arguments
  - make 'this' [byref(implicit)]
  - special-case '&' as a unary operator in the parser to make it
    produce an expression which type-checks as turning implicit l-values
    into explicit ones.

Obvious missing pieces:
  - updating LangRef
  - we should really complain about ever trying to rvalue-convert an
    explicit l-value
  - maybe qualification should play a part in overload resolution
  - we should diagnose attempts to declare unary '&' operators
  - there's a test case in expressions.swift which suggests my logic is
    slightly off

But I am out of time, and these will have to wait.

Swift SVN r1119
2012-02-22 06:43:33 +00:00
John McCall
2b65cf22d1 Make 'this' implicitly [byref] when the container type does
not have reference semantics.  Deciding whether the container
type has reference semantics requires us to perform
some amount of limited name-binding and type-checking first,
which introduces a few complexities.

Also, fix a bug in uncurried call emission.

Methods work now.



Swift SVN r1112
2012-02-11 07:37:57 +00:00
John McCall
7b29a420f6 Design and implement the [byref] attribute, checking that
it doesn't appear in places it shouldn't.  The only limits on
this checking right now is the inadequacy of location information
for types, which is something we ought to fix.

Fix type-checking of byref applications.  Fix IR generation
of byref variables.  Whole lotta fixin' goin' on.

But hey, byref calls work.



Swift SVN r1111
2012-02-10 09:42:50 +00:00
John McCall
ce7780af04 I don't think we're really getting anything out of ArgDecl
at the moment.  We can put it back if I'm wrong.



Swift SVN r1100
2012-01-26 02:08:52 +00:00
John McCall
16f8b2e656 Revise the language design for function argument clause syntax.
A function argument clause is now one or more patterns (which
must be parenthesized and explicitly type all positions) not
separated by arrows;  the first arrow then separates off the
return type.

Revisions to language reference forthcoming.



Swift SVN r1099
2012-01-26 01:25:26 +00:00
Chris Lattner
599e4b2528 switch to using the new llvm::MutableArrayRef class, this requires llvm r148463
Swift SVN r1088
2012-01-19 06:39:07 +00:00
Chris Lattner
594c117658 remove a dead diagnostic, simplify the top-level translation unit parsing gunk
Swift SVN r1086
2012-01-19 00:39:33 +00:00
Chris Lattner
1c7d9f79ba simplify value-specifier code to eliminate the 'expr single' previous special case.
Since we reworked how expression binding works, this complexity isn't needed anymore.


Swift SVN r1083
2012-01-18 23:56:19 +00:00
John McCall
ea5e37e276 Getterize uses of TupleTypeElt. I'm trying to figure out how
parameter attributes should work here.



Swift SVN r1066
2012-01-18 04:05:25 +00:00
Chris Lattner
1c42e8f6a6 rename DottedNameType to IdentifierType. It captures loc information for random uses of type names, among other things.
Swift SVN r1064
2012-01-18 01:52:28 +00:00
Chris Lattner
ac190abfef completely eliminate the type symbol table. "boom".
Swift SVN r1058
2012-01-17 07:43:32 +00:00
Chris Lattner
2f7cd03c6b switch type lookup to use value lookup for everything. Dead code ahoy.
Swift SVN r1057
2012-01-17 07:36:16 +00:00
Chris Lattner
9a3d4dbdd6 inject explicit type aliases into the value symbol table.
Swift SVN r1056
2012-01-17 07:20:02 +00:00
Chris Lattner
c8ca11a199 Drop in the new DottedNameType and wire it up in name binding.
This is horribly hack and slash (but enough to pass all tests) for a few reasons:
- I've #if 0'd out the tendrils of the old code 
- This handles *just* what was handled before instead of being more general
- We don't have an llvm::MutableArrayRef type, so there is some really gross
  const_cast'ing and other struggles to deal with its absence.



Swift SVN r1050
2012-01-17 06:32:00 +00:00
Chris Lattner
f5799a5b0b don't inject the struct constructor into the containing translation unit, because this will affect name lookup done by the name binder, causing an ambiguity error.
Swift SVN r1027
2012-01-12 21:51:51 +00:00
Chris Lattner
eb165f03ab ok, take a big jump and inject the metatype for a oneof into its
scope... instead of injecting the constructor function for a struct.  Everything 
still seems to work!

This will allow us to greatly simplify name lookup, etc but this isn't done yet.


Swift SVN r1018
2012-01-12 08:03:40 +00:00
Chris Lattner
89587ef545 add a comment.
Swift SVN r998
2012-01-06 22:21:18 +00:00
Chris Lattner
b737b112e7 modernize ProtocolType a bit to follow the form of OneOfType
Swift SVN r991
2012-01-05 21:51:48 +00:00
Chris Lattner
17b11e9bbd implement parsing, AST, and LangRef support for 'plus' methods. Dot syntax will need some work though to actually use them.
Swift SVN r949
2011-12-21 23:21:58 +00:00
Chris Lattner
cc0529ba34 remove support for "func foo::bar() {}". "Just use extensions".
Swift SVN r947
2011-12-21 22:45:37 +00:00