Commit Graph

1224 Commits

Author SHA1 Message Date
Dave Zarzycki
fa0b0467e5 Finish generalizing operators in TupleExprs
Before this change, an operator in a tuple forced the entire tuple to
contain only operators.

Swift SVN r4280
2013-03-04 18:56:07 +00:00
Dave Zarzycki
84e757b391 Allow operators in TupleExprs, not just ParenExprs
Swift SVN r4275
2013-03-04 05:58:34 +00:00
Joe Groff
6588b83a53 Parser: Parse '(<op>)' as a DeclRef of an operator
Enable operator functions to be referred to by name as, e.g., (+), (+=), etc. Unary/binary ambiguities are resolved via type context. Prefix/postfix unary ambiguities aren't resolved. References to assignment operators produce plain [byref] functions.

Swift SVN r4274
2013-03-03 19:31:00 +00:00
Dave Zarzycki
68c6d4c6e3 13324820 Change tuple accessor syntax to 'tuple.0'
Swift SVN r4265
2013-03-02 17:51:03 +00:00
Doug Gregor
315451eb45 Implement parsing, AST, semantic analysis, and IRgen for dictionary literals.
Swift SVN r4193
2013-02-25 07:27:15 +00:00
Doug Gregor
b61ea41e3f Refactor array-literal parsing to make way for dictionary literals.
Swift SVN r4192
2013-02-25 05:58:59 +00:00
Joe Groff
a8b5a2ec26 AST: Add UnresolvedSpecializeExpr.
This node represents a type parameter list application in an unresolved expr context. The type checker will use these to explicitly bind type variables of generic types.

Swift SVN r4046
2013-02-14 19:41:23 +00:00
Joe Groff
dc016b8d7e Parse: Fake parsing type parameters in expressions
When parsing an expression, if we see the production [[identifier '<']], use the following heuristic to choose whether to parse it as a type list or as an operator expression:
- Speculatively parse the subsequent production as a type parameter list.
- If the parse succeeds, examine the token after the closing '>'. If it is one of the following:
  l_paren_following
  l_square_following
  r_paren
  r_square
  l_brace
  r_brace
  comma
  semicolon
  period
then accept the parse as a type list.
- If the parse fails, or if the type list is not followed by one of those tokens, reject the type list and parse as an operator expression.

This only implements the parsing rule. The type parameters are just dropped on the floor--the AST representation and Sema changes are forthcoming. Encouragingly, no test or library code appears to be broken by this rule.

Swift SVN r4044
2013-02-14 00:34:55 +00:00
Dave Zarzycki
177e243ad5 Tokens should not be named after their use
This fixes an old TODO item based on feedback from Chris and John.

Swift SVN r4038
2013-02-13 21:40:43 +00:00
Joe Groff
750374f61a Sema: Typecheck super.method expressions.
Add support to the constraint checker for typechecking UnresolvedSuperMemberRef expressions and constructing SuperMemberRef or SuperCall expressions as appropriate. We’ll also need a GenericSuperMemberRefExpr to refer to properties of generic supertypes, but in the interests of demo expedience I’m leaving that case partially-implemented for now.

Swift SVN r4020
2013-02-12 19:23:34 +00:00
Dave Zarzycki
d2ba334949 Simplify parseMatchingToken()
Swift SVN r3966
2013-02-06 06:19:25 +00:00
Dave Zarzycki
8a56780ab8 Subscription should implicitly tuple the key/index
This now works:

struct no_index {
  subscript () -> Int { return 42 }
  func test() -> Int { return this[] }
}

struct tuple_index {
  subscript (x : Int, y : Int) -> (Int, Int) { return (x, y) }
  func test()  -> (Int, Int) { return this[123, 456] }
  func test2() -> (Int, Int) { return this[y = 123, x = 456] }
}

Swift SVN r3965
2013-02-06 05:47:33 +00:00
Joe Groff
b5bc022686 Incomplete support for array literal expressions.
Analyze an expression of the form [<tuple contents>] into a call to T.convertFromArrayLiteral(<tuple contents>) for some T conforming to an ArrayLiteralConvertible protocol. Because of some limitations in the constraint checker and protocol conformance checkers, it currently does an ad-hoc conformance check using member constraints. It also currently fails to typecheck for generic container types, and does not provide a default fallback to 'T[]' if unable to deduce a better type from context.

Swift SVN r3953
2013-02-05 21:23:42 +00:00
Joe Groff
7c3c5700ec Parse: Update inaccurate comment
Bit of debris from implementing super.constructor. 'expr-super' isn't an expr-unary.

Swift SVN r3896
2013-01-29 22:38:24 +00:00
Dave Zarzycki
b36678214a Rename l_(paren|square)_(call|subscript)
Thanks Chris and John for the feedback.

Swift SVN r3893
2013-01-29 21:13:39 +00:00
Dave Zarzycki
5fe85d7020 Formalize unary prefix '&' to mean "make ref"
This makes reserved operator parsing more robust and easier to understand.

Swift SVN r3884
2013-01-27 21:20:06 +00:00
Dave Zarzycki
93a81f1cd8 Fix unresolved member versus field access ambiguity
'.' is an operator, therefore unary prefix '.' can mean something
different than binary '.' (field access).

Swift SVN r3883
2013-01-27 00:30:40 +00:00
Dave Zarzycki
1dcfff8497 'this' and 'This' are keywords
Swift SVN r3858
2013-01-24 21:54:43 +00:00
Dave Zarzycki
eb5bb20bf9 Remove unnecessary use of isAnyLParen()
Swift SVN r3857
2013-01-24 17:36:36 +00:00
Joe Groff
057f1b6468 Sema: Type check non-overloaded super.constructor.
Implement base class constructor lookup to resolve the function reference for SuperConstructorRefCallExprs.

Swift SVN r3855
2013-01-24 02:29:41 +00:00
Joe Groff
14c68e95d0 Lexer: Special-case 'super' and 'constructor'.
Dave noted that he's trying to scrub the parser codebase of wishy-washy 'isAnyLParen' and 'isAnyLBrace' calls by consistently lexing opening bracket tokens correctly to begin with. Since currently only 'super' and 'constructor' need to be lexed like identifiers for expression syntax (and, in the future, 'this' and 'This' when those become keywords), mark them as a special kind of 'identifier keyword' in Tokens.def and roll back some of the changes I made to make parsing other decls support either token.

Swift SVN r3848
2013-01-23 22:23:37 +00:00
Joe Groff
e6d3c3e00c Parser: Parse 'super' expressions.
Set up AST nodes for 'super.<identifier>', 'super.constructor', and 'super[<expr>]' expressions, and implement parsing for them without any sema or backend support.

Swift SVN r3847
2013-01-23 21:24:28 +00:00
Joe Groff
8af835edcc Lexer: '[' and '(' after a keyword is non-literal.
Opening brackets after a keyword have to lex as l_paren_call or l_square_subscript in order for expressions like 'super.constructor()' or 'super[i]' to parse. While we're here, let's move the keyword and punctuator list to a metaprogrammable Tokens.def header too. Update decl and stmt parsers to use 'isAnyLParen' so that, e.g., 'constructor(' and 'constructor (' both work as before.

Swift SVN r3846
2013-01-23 21:24:26 +00:00
Dave Zarzycki
735294a5c9 Make the lexing of '(', '[', and '.' consistent
The lexer now models tuples, patterns, subscripting, function calls, and
field access robustly. The output tokens are now better named as well:
l_paren and l_paren_call, and l_square and l_square_subscript. It
should be much more clear now which one to use. Also, the use of
l_paren or l_square will not arbitrarily flip flop if the token before
it is a keyword or if the token before it was the trailing ']' of an
attribute list. Similarly, tuples will always cause the lexer to produce
l_paren, regardless if the user typed '((x,y))' or '( (x,y))'.

When we someday add array literals, the right token is now naturally
falling out of the lexer.

Swift SVN r3840
2013-01-23 03:23:17 +00:00
Dave Zarzycki
2d51225e7d Misc cleanup
Swift SVN r3833
2013-01-22 21:08:47 +00:00
Joe Groff
6449655e21 Implement selector-style function definition syntax.
rdar://12315571
Allow a function to be defined with this syntax:

  func doThing(a:Thing) withItem(b:Item) -> Result { ... }

This allows the keyword names in the function type (in this case
`(_:Thing, withItem:Item) -> Result`) to differ from the names bound in the
function body (in this case `(a:Thing, b:Item) -> Result`, which allows
for Cocoa-style `verbingNoun` keyword idioms to be used without requiring
those keywords to also be used as awkward variable names. In addition
to modifying the parser, this patch extends the FuncExpr type by replacing
the former `getParamPatterns` accessor with separate `getArgParamPatterns`
and `getBodyParamPatterns`, which retrieve the argument name patterns and
body parameter binding patterns respectively.



Swift SVN r3098
2012-11-01 21:53:15 +00:00
Eli Friedman
b62d47a2e5 Rewrite the way we build capture list so we don't miss capturing "this". <rdar://problem/12583581>.
Swift SVN r3093
2012-10-30 22:33:18 +00:00
John McCall
2f8f05615e Rename TypeOfExpr / TypeOfInst to MetatypeExpr / MetatypeInst.
Introduce a '.metatype' form in the syntax and do some basic
type-checking that I probably haven't done right.  Change
IR-generation for that and GetMetatypeExpr to use code that
actually honors the dynamic type of an expression.

Swift SVN r3053
2012-10-24 07:54:23 +00:00
Eli Friedman
9e06964c8a Make the TypeLoc constructor which takes just a type private, and expose a
static method to call it, to make it more explicit what is happening.  Avoid
using TypeLoc::withoutLoc for function definitions; instead, just use an empty
TypeLoc.



Swift SVN r2606
2012-08-10 02:09:00 +00:00
Chris Lattner
5184be484f Finish off rdar://12017658 - func() expression should support type inference of argument types.
This implements inference of return types, per the discussion today.



Swift SVN r2572
2012-08-07 05:12:32 +00:00
Chris Lattner
b6f6eec106 implement rdar://11935352 - accepting closures with no body expression (the closure
just returns "()").


Swift SVN r2503
2012-08-02 20:08:51 +00:00
Eli Friedman
e6917fbc51 Add support for "new" with classes with non-default constructors. <rdar://problem/11917082>.
Swift SVN r2384
2012-07-20 21:37:08 +00:00
Eli Friedman
d6a4ba90dd Move TypeLocs to a design where a TypeLoc is a struct containing a type plus
location info for that type.  Propagate TypeLocs a bit more through the AST.



Swift SVN r2383
2012-07-20 21:00:30 +00:00
Eli Friedman
361f931a16 Start propgating TypeLocs from the parser into the AST.
Swift SVN r2372
2012-07-19 02:54:28 +00:00
Eli Friedman
f1f67db652 Big cleanup for how we handle computing types for functions and semantic
analysis for patterns.

Major changes:
1. We no longer try to compute the types of functions in the parser.
2. The type of a function always matches the type of the argument patterns.
3. Every FuncDecl now has a corresponding FuncExpr; that FuncExpr might not
   have a body, though.
4. We now use a new class "ExprHandle" so that both a pattern and a type
   can hold a reference to the same expression.

Hopefully this will be a more reasonable foundation for further changes to
how we compute the types of FuncDecls in generics and for the implementation
of type location information.



Swift SVN r2370
2012-07-19 02:09:04 +00:00
Eli Friedman
2eb6261838 Don't try to capture TypeDecls in local functions.
Swift SVN r2180
2012-06-08 23:51:02 +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
John McCall
8c46c69efa Lexically distinguish prefix, postfix, and binary operators
and use this information as cues in the language.  Right now,
we do not accept things like "-- *i" because the prefix
operator is not correctly right-bound;  instead you have to
write "--(*i)".  I'm okay with that;  I did add a specialized
diagnostic recognizing operator-binary in a place where we're
expecting a potential operator-prefix.

Swift SVN r2161
2012-06-07 01:00:06 +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
Eli Friedman
33f20a14e0 Add NewReferenceExpr, for allocating class objects.
Swift SVN r1867
2012-05-16 01:36:03 +00:00
Chris Lattner
ca3732e2a2 rework the parsing logic for \() in string literals to just parse them as normal paren-exprs (tuples or parens).
Swift SVN r1769
2012-05-08 05:57:55 +00:00
Chris Lattner
0054cd197c refactor string literal parsing out to its own method, since it is non-trivial now.
Swift SVN r1768
2012-05-08 05:34:22 +00:00
Chris Lattner
2a1e15f372 document string literal interpolation in langref.
Swift SVN r1742
2012-05-04 06:33:40 +00:00
Chris Lattner
024e592beb Now that the parser's lexer can be changed, just change it, instead of mutating the lexer,
simplifying things a bit.


Swift SVN r1741
2012-05-04 06:16:29 +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
678843cbc5 improve error recovery when the lexer returns a tok::unknown and we're parsing an expression.
Swift SVN r1739
2012-05-04 06:04: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
54c7c6ea74 Add some helper functions to help treat "spaced" lparen and lsquares uniformly.
Swift SVN r1708
2012-05-02 00:30:45 +00:00
Chris Lattner
48f1556a1a Change swift to special case ++ and -- as unary-only operators. Making them
useful.  This resolves:
 <rdar://problem/11297111> ++ and -- operators are annoyingly confused with binary operators

for now.



Swift SVN r1703
2012-05-01 17:56:22 +00:00