Commit Graph

2438 Commits

Author SHA1 Message Date
Chris Lattner
b23f4eb4f8 switch from SmallMap to SmallDenseMap.
Swift SVN r2189
2012-06-17 21:22:13 +00:00
Eli Friedman
9d21e367eb Switch strings over to new constructor syntax. Fix a few constructor bugs I found along the way.
Swift SVN r2166
2012-06-07 20:26:16 +00:00
Eli Friedman
64d67103fa One more small fix for constructor name lookup. Make the auto-generated element-wise constructor use the name "constructor".
Swift SVN r2165
2012-06-07 19:50:18 +00:00
Eli Friedman
7965dff03d A few more misc fixes for constructors. Add a testcase.
Swift SVN r2164
2012-06-07 19:36:07 +00:00
John McCall
30f5e36dbc Semantic analysis and AST support for postfix operators.
Also prevent us from including unary operators in the
lookup results for operators written binary-style and
vice-versa.

Swift SVN r2162
2012-06-07 01:00:08 +00:00
Eli Friedman
75907029f1 Add parsing and semantic analysis for a basic ConstructorDecl. Still missing: no IRGen, and semantic analysis to actually call them.
Swift SVN r2159
2012-06-05 23:51:19 +00:00
Eli Friedman
ecc56538b3 Add a basic TypeLoc; start threading it through the parser.
Doug, please double-check that this is going in the right direction...



Swift SVN r2146
2012-06-05 00:11:59 +00:00
Eli Friedman
27f8a5ab62 Teach the parser's handling of scopes to handle local types correctly.
Swift SVN r2138
2012-06-04 19:14:58 +00:00
Doug Gregor
552e5a16dc Introduce the Enumerable protocol, and make each type with a
getElements() method conform to Enumerable specifically.


Swift SVN r2136
2012-06-04 17:33:36 +00:00
Doug Gregor
4ed242a318 Synchronize protocol grammar in parser with the protocol grammar in LangRef.
Swift SVN r2135
2012-06-04 16:48:27 +00:00
Doug Gregor
9abd2340bc Allow an 'inheritance' clause on typealiases, specifying what
protocols the underlying type of the type alias shall conform to. This
isn't super-motivating by itself (one could extend the underying type
instead), but serves as documentation, makes typealiases provide the
same syntax as other nominal types in this regard, and will also be
used to specify requirements on associated types.


Swift SVN r2133
2012-06-04 16:15:47 +00:00
Eli Friedman
ae86d64644 Rename Decl::getLocStart() to Decl::getStartLoc(). Add Decl::getLoc(), which is essentially the location which should be used for diagnostics.
Swift SVN r2105
2012-05-31 23:56:30 +00:00
Eli Friedman
ba4a76038b Make oneofs never implicitly generate an ExtensionDecl. This matters for local oneofs.
Swift SVN r2098
2012-05-31 21:20:56 +00:00
Chris Lattner
53b09c613a Switch type alias to use = for assignment instead of :, which indicates conformance.
This resolves rdar://11547856



Swift SVN r2064
2012-05-30 00:32:23 +00:00
Eli Friedman
85ed3e1868 Only allow extensions and protocols at module scope.
Swift SVN r2062
2012-05-30 00:19:35 +00:00
Eli Friedman
e63a471347 Fix value name-binding so it correctly performs member lookup for expressions which aren't inside a member function.
Swift SVN r2004
2012-05-25 23:42:40 +00:00
Doug Gregor
9096497f0f Rename "dependent type" to "unresolved type" universally. We've been
using the term "unresolved" in expressions for a while, and it fits
for types better than "dependent type."

The term "dependent type" will likely come back at some point to mean
"involves an archetype".



Swift SVN r1962
2012-05-23 19:03:14 +00:00
Doug Gregor
74436a3120 Introduce the implicit 'This' type into protocols, which refers to the
type T that conforms to the given protocol. 'This' is modeled simply
as an associated type.



Swift SVN r1953
2012-05-23 14:45:55 +00:00
Doug Gregor
d37602629e Implement parsing, AST, and conformance checking for associated types
in protocols, e.g.,

  protocol Range {
    typealias Element
    func getAndAdvance() -> Element
  }



Swift SVN r1941
2012-05-22 21:45:58 +00:00
Doug Gregor
a9906ad38f Introduce support for implicit user-defined conversions.
A user-defined conversion function is an instance method that accepts
an empty tuple and returns a value of the type we're converting to,
has the [conversion] attribute, and is named __conversion. The last of
these restrictions is a temporary hack to work around our inability to
perform a lookup across all extensions for "every function with the
conversion attribute", and shouldn't last too long.

As in C++, we only get one user-defined conversion function. Unlike in
C++, a constructor is not (and cannot) be a conversion function.

Introduce NSString <-> String conversion functions, but leave the
runtime implementations as stubs for Dave to fill in.



Swift SVN r1921
2012-05-21 23:36:16 +00:00
Eli Friedman
bb0a98d487 Finish off varargs.
Swift SVN r1892
2012-05-18 00:04:07 +00:00
Doug Gregor
003ee33c52 It is considered poor form to store stack-allocated memory in the AST.
Swift SVN r1885
2012-05-17 15:42:33 +00:00
Doug Gregor
245d2a46f2 Parse an 'inheritance' clause on extensions, oneofs, structs, and
classes, with the same syntax as we have on protocols. This
inheritance specifies explicit conformance to a protocol.

Later, we can allow a class definition to have a single class type
within this list, when we introduce class inheritance.



Swift SVN r1862
2012-05-15 23:39:19 +00:00
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