Eli Friedman
a5a39860cd
Basic parsing plus a bit more of the AST for ClassDecls.
...
Swift SVN r1860
2012-05-15 22:07:31 +00:00
Eli Friedman
6f045aad2f
Throw the switch to use "var" syntax to declare members of structs. This also means we no longer build an implicit extension for every struct decl. Everything seems to be working, but please yell if this breaks anything.
...
Swift SVN r1851
2012-05-15 03:27:13 +00:00
Doug Gregor
bf03c9af28
Remove byref(implicit). Instead, introduce [assignment], which only
...
applies to operators whose first parameter is [byref]. Assignments
must return Void, and have their first arguments implicitly treated as
an lvalue.
As part of this, add the various C compound operators (+=, -=, *=, /=,
&=, |=, and ^=) to the standard library.
Swift SVN r1846
2012-05-15 00:55:32 +00:00
Doug Gregor
515bcb44e9
Allow subscript declarations in protocols, which require a suitable
...
subscripting operator. Such protocols are fairly useful without
associated types, however.
Swift SVN r1831
2012-05-14 15:56:58 +00:00
Eli Friedman
d98c55f665
Followup to r1819: there was an issue with that commit I hadn't spotted before related to mismatched types. This commit solves it for FuncDecls, but not SubscriptDecls (see the FIXME).
...
Swift SVN r1822
2012-05-12 02:52:14 +00:00
Eli Friedman
01a18f6c7a
Use VarDecls to represent struct members, and MemberRefExprs to represent member access in structs. Eliminate the horrible hack which was LookThroughOneOfExpr.
...
Swift SVN r1808
2012-05-11 03:08:15 +00:00
Doug Gregor
70bfc235b8
Implement protocol inheritance, e.g.,
...
protocol Document { var title : String }
protocol Versioning { func bumpVersion() }
protocol VersionedDocument : Document, Versioning { }
This commit covers the basic functionality of protocol inheritance, including:
- Parsing & AST representation
- Conforming to a protocol also requires conforming to its inherited
protocols
- Member lookup into a protocol also looks into its inherited
protocols (results are aggregated; there is no name hiding)
- Teach ErasureExpr to maintain lvalueness, so we don't end up
performing a silly load/erase/materialize dance when accessing
members from an inherited protocol.
Swift SVN r1804
2012-05-11 00:00:50 +00:00
Doug Gregor
169dd225bf
Switch Parser::parseProtocolBody() over to use parseDecl(), with a
...
giant list of "you can't do that" restrictions. Update grammar
accordingly, killing off decl-var-simple.
Swift SVN r1781
2012-05-09 00:35:53 +00:00
Eli Friedman
77fa49ec2b
Introduce StructDecl and StructType; use them for structs instead of OneOfDecl/OneOfType. To keep this patch small, I'm leaving in LookThroughOneOf etc. for the moment, but that's next on the agenda.
...
Swift SVN r1780
2012-05-09 00:27:44 +00:00
Doug Gregor
a581941440
Tighten up protocol parsing a bit.
...
Swift SVN r1779
2012-05-08 23:49:20 +00:00
Doug Gregor
5f2344afe0
Introduce ProtocolDecl, which describes (*gasp*) a protocol. Move the
...
guts of ProtocolType over to ProtocolDecl.
Swift SVN r1778
2012-05-08 23:28:55 +00:00
Eli Friedman
4ca443d0f5
Add OneOfDecl; use it as a DeclContext for OneOfElementDecls instead of OneOfType, and get rid of the implicit TypeAliasDecl. Add TypeDecl as a base class for OneOfDecl and TypeAliasDecl (and StructDecl, once we have it). Adjust a whole bunch of stuff to this new scheme.
...
Swift SVN r1774
2012-05-08 21:09:42 +00:00
Eli Friedman
a143422c98
Teach name binding to look into default values for tuple types.
...
Swift SVN r1747
2012-05-04 23:09:55 +00:00
Eli Friedman
fd62cbac65
Refactor extension parsing so it's centralized, and so we parse the body of the extension in the correct DeclContext.
...
Swift SVN r1745
2012-05-04 20:59:50 +00:00
Chris Lattner
7d3c8fb905
Change Parser.L to be a pointer instead of a reference, no functionality change.
...
Swift SVN r1740
2012-05-04 06:12:41 +00:00
Chris Lattner
2f44c0038c
Initial stab at implementing string literal interpolation for simple expressions,
...
e.g. "foo is \(i+j)". This implements rdar://11223686
Doug implemented all the hard parts of this. I ripped out support for nested string
literals (i.e. string literals within an interpolated string), which simplified the
approach and defined away some problems with his patch in progress. I plan a few refinements
on top of this basic patch.
Swift SVN r1738
2012-05-04 05:53:50 +00:00
Chris Lattner
774a557e5c
Merge NamedDecl into ValueDecl, rdar://11379147.
...
Swift SVN r1737
2012-05-04 04:50:53 +00:00
Eli Friedman
ff2bef9d62
Extend variable declaration grammar to allow "var a, b : Int, c, d : Double". <rdar://problem/11349535>.
...
I've tried to be pretty strict about exactly which cases we accept here, to avoid any confusing cases.
Swift SVN r1721
2012-05-03 00:49:16 +00:00
Chris Lattner
54c7c6ea74
Add some helper functions to help treat "spaced" lparen and lsquares uniformly.
...
Swift SVN r1708
2012-05-02 00:30:45 +00:00
Eli Friedman
3c8802edbf
Add syntax for declaring multiple unrelated variables on a single line ("var x = 10, y = 20.0"), like we claimed to support during the demo.
...
Swift SVN r1677
2012-04-27 22:40:48 +00:00
Eli Friedman
0241d0ec20
Implement IRGen for local function decls. Known limitations at the moment: currying is unimplemented, and capturing the decl is unimplemented.
...
Swift SVN r1647
2012-04-26 01:16:38 +00:00
Eli Friedman
81776635c5
Add an asmname attribute which overrides the default mangling for a swift function. This is a complete hack, and we intend to remove it (along with function declarations which don't include a definition) once we can properly import C modules. <rdar://problem/11306201>.
...
Swift SVN r1617
2012-04-25 01:53:38 +00:00
Doug Gregor
f997a781bf
Parsing and basic AST representation for 'foreach' statement.
...
Swift SVN r1594
2012-04-24 18:12:44 +00:00
Eli Friedman
be602fcd05
Get rid of the implicit BraceStmt for the TranslationUnit; instead, have the TranslationUnit directly store a list of decls.
...
Swift SVN r1521
2012-04-20 00:17:13 +00:00
Doug Gregor
cd43490fb3
Implement semantic analysis for subscript expressions, using overload
...
resolution to pick the best subscript getter/setter pair. Does not yet
allow type coercion to influence overload resolution.
Swift SVN r1515
2012-04-19 23:01:04 +00:00
Eli Friedman
d5e7784010
Get rid of isModuleScope bit, since we don't like scattering bits across the AST; as a replacement, introduce TopLevelCodeDecl, which provides a DeclContext for all expressions and statements at the top level. <rdar://problem/11259941>.
...
Swift SVN r1503
2012-04-19 21:22:12 +00:00
Doug Gregor
8ff3075ce4
Teach getter/setter functions about their corresponding subscript
...
declaration, so they can mangle themselves appropriately.
Swift SVN r1499
2012-04-19 20:56:22 +00:00
Doug Gregor
846aa7e162
Diagnose attempts to declare subscript operations outside of a type context.
...
Swift SVN r1497
2012-04-19 20:41:42 +00:00
Doug Gregor
06881faea2
Introduce an AST node for subscript declarations, and verify that the bodies of the getter and setter are being type-checked.
...
Swift SVN r1496
2012-04-19 20:29:48 +00:00
Chris Lattner
35d7fc5d1d
fix a crash I'm seeing on test/subscripting.swift: it looks like something isn't
...
pushing a decl onto Entries, which is reasonable in an error condition. Handle
this correctly.
Swift SVN r1480
2012-04-19 00:41:01 +00:00
Doug Gregor
9ba80f7716
Properly pass the arguments specified for subscripting access down to
...
the functions that we generate for the getter/setter, so that the
index parameters are in scope.
Swift SVN r1479
2012-04-18 23:38:10 +00:00
Eli Friedman
dd17ba6324
A few minor bugfixes for REPL.
...
Swift SVN r1477
2012-04-18 21:49:27 +00:00
Doug Gregor
6897b6ab44
Add support for parsing a subscripting declaration, e.g.,
...
subscript (i : Int) -> Double {
get { /* get ith element of something */ }
set { /* set ith element of something to value*/ }
}
Swift SVN r1476
2012-04-18 21:43:54 +00:00
Doug Gregor
c99e526ae8
Refactor var-get-set grammar to a more general get-set grammar, to
...
prepare for re-use in subscripting. No functionality change (yet).
Swift SVN r1475
2012-04-18 20:54:58 +00:00
John McCall
e6d56fd718
Require an unspaced [ to start a subscript or array-type suffix.
...
Per discussion, this should probably be "no newline since the last
token", but that decision should be made simultaneously for ( and [.
Swift SVN r1461
2012-04-18 08:08:58 +00:00
Eli Friedman
37de44a35d
Implement changes to parsing/sema/etc so that we can implement a REPL and the main module parses the same way as a REPL.
...
Next step: implement an actual REPL.
Swift SVN r1441
2012-04-16 23:52:01 +00:00
Doug Gregor
4fc32fd9b4
For a function that is either a getter or setter for a variable,
...
provide a mapping back to that variable. Teach the mangler to provide
a special mangling for such functions (__getVarName,
__setVarName). The mangling will undoubtedly change later, but the
point is that it will need to match the functions generated for
a resilient variable.
Swift SVN r1432
2012-04-14 00:11:04 +00:00
Doug Gregor
0fdb4d00fc
When we parse a 'var' declaration, we add all of the VarDecls and the
...
PatternBindingDecl to the DeclContext. Do the same for the get/set
functions for a property, so we don't need to perform 'deep' setting
of the DeclContext. This is simpler, although it makes pretty-printing
the AST a bit more difficult.
Swift SVN r1428
2012-04-13 22:22:17 +00:00
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