734 Commits

Author SHA1 Message Date
John McCall
9f2ca5e4cc Remove juxtaposition handling from the type-checker and put it
in the parser.  Implement the grammar which permits this.
Enforce that binary operators have to, well, operators.



Swift SVN r515
2011-08-12 05:49:30 +00:00
Chris Lattner
10f5c2fc66 remove the UnresolvedType, representing it with a null Type() instead. There is no need to
have two different ways to represent the same thing.  This has the pleasant bonus that stuff
crashes when you do things with unresolved types.


Swift SVN r513
2011-08-12 05:19:52 +00:00
John McCall
4eb22011b6 Make the lexer just determine whether an LP is spaced or not; the
parser can consume this as appropriate.  For now it isn't, but that
will change.



Swift SVN r509
2011-08-12 02:12:48 +00:00
Chris Lattner
36f5427de3 Make the lexer disambiguate between a ( that is the start of an expression and a ( that is the start of
a call argument list.


Swift SVN r508
2011-08-12 01:46:39 +00:00
Chris Lattner
abe344bef2 switch statements to use ParseResult, enhance ParseResult to map ParseResult<BraceStmt>
convertible to ParseResult<Stmt>.


Swift SVN r505
2011-08-12 00:16:41 +00:00
Chris Lattner
7a5e383c0b some localized cleanups for diagnostics.
Swift SVN r504
2011-08-11 23:38:30 +00:00
Chris Lattner
0e8a66ec9d Introduce a new ParseResult<T> helper class, which is effectively
oneof { T*, Absent, ParseError, SemaError }.

This replaces the former convention used by the expression parsing
logic that used NullablePtr + bool to indicate all of these states,
in a way that I could never keep straight.

This should lead to better error recovery, but needs to be adopted by
more parts of the parser.  Sema still uses NullablePtr because it
either returns a valid AST node or has a semantic error, there is no
parse error possible in Sema.



Swift SVN r503
2011-08-11 23:35:27 +00:00
Chris Lattner
9e6817b3cd implement lexer, parser, and dox support for while loops, everything is hooked up now.
Swift SVN r502
2011-08-11 20:47:33 +00:00
John McCall
944183d985 Split tok::oper out of tok::identifier. No functionality change.
The consumeToken(Tok.getKind()) is terrible, but will disappear when
most of these cases have operators stripped out.



Swift SVN r500
2011-08-11 06:17:31 +00:00
Chris Lattner
433d6de807 implement AST and parser support for 'return'. We're still not doing a conversion
to a return type yet though.  We happily diagnose thigns like this as an error:

func foo() -> int {
  return 4 5
}



Swift SVN r493
2011-08-03 23:19:24 +00:00
Chris Lattner
46d0862469 expr-brace -> stmt-brace in comments.
Swift SVN r491
2011-08-03 22:32:21 +00:00
Chris Lattner
b7049da44c clean up the grammar by introducing an explicit 'decl' production.
It turns out we already allow nested functions, how about that.



Swift SVN r490
2011-08-03 22:31:01 +00:00
Chris Lattner
c86e786ab5 switch langref to new func syntax, switch implementation to use FuncExpr instead of LambdaExpr.
Swift SVN r487
2011-08-03 00:32:15 +00:00
Chris Lattner
a64c74ec94 Replace lambda keyword with func. One annoying aspect of this that I didn't
think about will occur when/if we want to support attributes on func expression.
That should look like "func [attributes]{ ... }" but now that requires looking
beyond that attributes to know if this is a funcdecl or funcexpr.  Nothing that
more heroic lookahead can't handle.



Swift SVN r486
2011-08-03 00:28:11 +00:00
Chris Lattner
ea9cd782d8 lambda expressions now require a type that start with a tuple, such as (x : int).
John can fix func decls.


Swift SVN r485
2011-08-03 00:18:12 +00:00
Chris Lattner
23759c8624 rename Lex -> lex too.
Swift SVN r484
2011-08-03 00:08:21 +00:00
Chris Lattner
0265e3cbd1 make 'else if' a special case, disallowing things like "else ;".
Swift SVN r482
2011-08-02 21:31:31 +00:00
Chris Lattner
350b89e6e4 Represent assignments as their own AssignStmt, preserving the model we had
before, but removing the hack where we'd represent them as a binary operator
with a null operator function.  We still have no clear semantics for what 
is valid or not.



Swift SVN r478
2011-08-01 17:45:21 +00:00
Chris Lattner
ebc33d306f add AST support for semicolon statements and clean up the parser. While noone cares, it is trivial
to support and good for completeness.


Swift SVN r475
2011-07-31 21:09:23 +00:00
Chris Lattner
93ac2b3cb9 rename FuncExpr to LambdaExpr.
Swift SVN r468
2011-07-31 20:15:56 +00:00
Chris Lattner
c3bbefcbaa add support for lambda expressions (anonymous functions), which are the thing that
func is sugar for.  Unfortunately, we can't use 'func' without introducing ambiguity
since decls and exprs can exist in the same context, I'm not wed to 'lambda' as the
keyword, thoughts welcome.


Swift SVN r467
2011-07-31 20:12:20 +00:00
Chris Lattner
a8e2788184 implement semantic analysis for FuncExpr and have the parser lower func decls
to func exprs.  All the tests pass again.  Now we have a strict equality 
between:

  func foo(a : int) -> int { a+1 }

and 

  var foo = func(a : int) -> int { a+1 }

except we don't support the later syntax yet.  We also really need return, though
we're getting closer to being able to usefully support it.



Swift SVN r466
2011-07-31 19:33:27 +00:00
Chris Lattner
63ce0be641 make the big switch: {} are now statements, not expressions. This removes some
annoying things from the grammar (like expr-non-brace), and makes it so that 
the body/else of an if is just a statement.

This patch has a fairly serious caveat that we just drop function bodies on the
floor now, since we have no "stmtexpr" sort of thing to represent the syntactic
sugar that is func.  We'll fix that soon.


Swift SVN r462
2011-07-31 17:39:13 +00:00
Chris Lattner
382f33ec74 introduce statements, make if (and ;) a statement. This includes a
few horrible hacks, but is the right direction to go.


Swift SVN r457
2011-07-31 06:52:11 +00:00
Chris Lattner
0fc77abf5c Per discussion on swift-dev, unify 'meth' and 'func' syntax into just 'func' syntax
where you can optionally declare a receiver type.  This is cleaner both conceptually
and in implementation, and eliminates drug references. :)


Swift SVN r444
2011-07-24 20:11:35 +00:00
Chris Lattner
6fbe70dd87 convert TokenKind to a scoped enum, eliminating the old c++'98 hackaround to
emulate it.


Swift SVN r442
2011-07-24 19:28:36 +00:00
Chris Lattner
4dc572ddd7 per discussion on swift dev, remove the "=" syntax for defining a body of a function.
Swift SVN r435
2011-07-24 00:29:22 +00:00
Chris Lattner
4f29cc0e8c convert TheUnresolvedType/TheDependentType and the empty tuple type
to be accessors on their respective classes, for consistency.


Swift SVN r429
2011-07-19 06:41:42 +00:00
Chris Lattner
3af81cccbe raw_ostream and NullablePtr. While there are more types that
could be handled in similar ways, this gets the most of them.


Swift SVN r424
2011-07-19 06:09:31 +00:00
Chris Lattner
10017bef15 ArrayRef and SmallVector[Impl]
Swift SVN r423
2011-07-19 06:03:26 +00:00
Chris Lattner
7275ca527a pull in StringRef and Twine.
Swift SVN r422
2011-07-19 06:00:20 +00:00
Chris Lattner
19dbcaa171 pull the casting operators into LLVM.h
Swift SVN r421
2011-07-19 05:57:01 +00:00
Chris Lattner
e647b29339 stop the llvm-namespace-qualification-insanity by caving in and
adding a new swift/AST/LLVM.h file which forward declares and imports
common llvm classes, starting with SMLoc.


Swift SVN r420
2011-07-19 05:49:43 +00:00
Chris Lattner
d6cf48a22d add a "using llvm::SMLoc" to simplify some code,
move "-> ()" inference into Sema.  The boundary
between Parser and Sema* is nebulous at best.


Swift SVN r419
2011-07-19 05:39:06 +00:00
Chris Lattner
9e8c82435a implement AST and sema support for methods. The example method in the
testcase now AST's to:

   (methdecl 'print2' type='(this : rect) -> (os : ostream) -> ()'
      (closure_expr type='(this : rect) -> (os : ostream) -> ()'
        (closure_expr type='(os : ostream) -> ()'
          (brace_expr type='()'
            (apply_expr type='int'
              (declref_expr type='(r : rect) -> int' decl=area)
              (tuple_expr type='(r : rect)'
                (declref_expr type='rect' decl=this)))))))

which seems right.  Some cleanups are pending.



Swift SVN r416
2011-07-19 05:26:51 +00:00
Chris Lattner
ba2793aa6b implement parser support for methods, including dox and
a testcase.  No AST or sema yet.


Swift SVN r415
2011-07-19 04:46:07 +00:00
Chris Lattner
2db54bd1e9 change consumeToken to return the location of the token that it
just consumed, simplifying some common callers.


Swift SVN r396
2011-06-05 02:26:19 +00:00
Chris Lattner
b9e7823656 Implement lexing and parsing support for a proper if expression. There
is no AST building or typechecking support yet.  Document the intended
semantics in LangRef.  This is clearly subject to change, but is a starting
point.


Swift SVN r393
2011-06-05 02:03:48 +00:00
Chris Lattner
de094d7cde Introduce i1/i8/i16/i64 types, and switch int to be 64-bit.
Swift SVN r390
2011-05-31 03:48:36 +00:00
Chris Lattner
79ba41c1fe add a specialization of AllocateCopy to help out argument deduction a bit,
simplifying some code.


Swift SVN r385
2011-04-29 07:18:11 +00:00
Chris Lattner
d3d1278c7e John points out that struct foo { ... } is more consistent with oneof and generally makes more sense than struct foo (...). Switch!
Swift SVN r372
2011-04-22 06:12:21 +00:00
Chris Lattner
91fb8351b7 Implement support for overloaded binary operators.
Swift SVN r366
2011-04-11 05:59:23 +00:00
Chris Lattner
c3c602f9d3 Reimplement processing of dot expressions to have their base resolved as part of Type checking of SequenceExprs. This ensures that we can establish a proper base expression for the value.
Swift SVN r363
2011-04-11 05:20:21 +00:00
Chris Lattner
c45c9295cf Describe expressions.
Swift SVN r359
2011-04-10 23:36:11 +00:00
Chris Lattner
0d54f3e6f6 Major cleanups to decls and types section of langref.html. Expressions needs to be largely rewritten.
Swift SVN r358
2011-04-10 17:43:26 +00:00
Chris Lattner
3b4a8b03d2 1. With overloading in play, SemaDecl should never resolve unqualified lookup that hits at translation unit scope to a DeclRefExpr. Doing so can break overloading.
2. This exposed a bug: when parsing structs, we weren't adding all decls to the translation unit, we were just adding the type alias.
3. This exposed that TypeChecking wasn't handling OneOfElementDecl.
4. Introduce a new NLKind enum in NameLookup instead of passing around a bool.
5. Have unqualified lookup that returns an overload set form a new OverloadSetRefExpr, which has dependent type.
6. Enhance various stuff to handle OverloadSetRefExpr.  It's still not fully handled yet though, so it can't be used for anything useful.
7. Change Expr.cpp to print types with << instead of T->print(OS) which is simpler and correct in the face of null.

Swift SVN r351
2011-04-10 05:57:10 +00:00
Chris Lattner
5e28a6fcdd Finally get around to doing a major type system refactoring, where we introduce Type as a "smart pointer" and rename the existing Type class to TypeBase.
This prevents use of isa/dyn_cast/etc on Type*'s and means we just pass around Type by value instead of having to use Type* everywhere.

Swift SVN r343
2011-04-05 01:06:57 +00:00
Chris Lattner
85579ef131 Inline a bunch of trivial SemaExpr routines into parser. No need for the additional indirection/layering.
Swift SVN r342
2011-04-04 23:41:44 +00:00
Chris Lattner
7530ec988c Add a error to reject foo() when foo is not a function type. Previously we allowed it because these are two valid top-level values, but we now reject them because they are almost certainly a bug. This can be disabled by putting a space between them if this is useful for some reason.
Swift SVN r339
2011-03-27 02:56:47 +00:00
Chris Lattner
e85928e6f5 Split dollar identifier processing out to its own method.
Swift SVN r336
2011-03-26 23:57:43 +00:00