Commit Graph

198 Commits

Author SHA1 Message Date
Chris Lattner
c863bea58d merge SemaExpr into ParseExpr.cpp
Swift SVN r554
2011-08-13 22:33:33 +00:00
Chris Lattner
047ecf3b27 split expr parsing out to its own file.
Swift SVN r553
2011-08-13 22:17:50 +00:00
Chris Lattner
f6ff397ab7 zap some more S.Context's now that Parser has its own context member.
Swift SVN r551
2011-08-13 22:14:40 +00:00
Chris Lattner
dab303a541 move statement parsing out to its own file.
Swift SVN r550
2011-08-13 22:13:33 +00:00
Chris Lattner
e5c5dab2df give parser its own ASTContext member instead of having to indirect through Sema.
Swift SVN r549
2011-08-13 22:09:49 +00:00
Chris Lattner
c86d4a5853 Split parsing for types out to its own ParseType.cpp file, and
merge SemaType into it.


Swift SVN r547
2011-08-13 22:06:33 +00:00
Chris Lattner
6009504ae6 split ParseResult out to its own file.
Swift SVN r545
2011-08-13 21:35:37 +00:00
Chris Lattner
5d9e2e4a8d now that the Sema code is in the parse library, the Sema headers are all private, make it so.
Swift SVN r544
2011-08-13 21:15:17 +00:00
Chris Lattner
33f774f9b7 Rearrange a bunch of code for better layering: instead of Parser depending on Sema,
just move the Sema code into the Parser library.  There is no way to use one without
the other.  The library formerly known as Sema will get renamed.


Swift SVN r542
2011-08-13 21:06:10 +00:00
Chris Lattner
b40d2ce29e fix naming convention violations.
Swift SVN r536
2011-08-12 22:52:33 +00:00
Chris Lattner
b8fd157450 rip out the dead "isPrecededByIdentifier" logic from the AST and Lexer.
Swift SVN r529
2011-08-12 21:36:25 +00:00
John McCall
ddd134854e Rename ApplyExpr to CallExpr and change the signature of SemaCallExpr.
Swift SVN r523
2011-08-12 17:31:14 +00:00
Chris Lattner
3ce8ca094e don't promote a sema error to a parse error.
Swift SVN r518
2011-08-12 06:13:49 +00:00
Chris Lattner
096c203901 oneof element names can't be operators.
Swift SVN r517
2011-08-12 06:02:06 +00:00
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