Commit Graph

723 Commits

Author SHA1 Message Date
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
Chris Lattner
c9ee19e269 Implement parser, sema, doc, and name lookup support for refined import declarations. You can still only do top level references, but that's because we don't have namespaces or anything else interesting yet.
This allows "import swift.int" for example. 

Swift SVN r329
2011-03-23 05:18:29 +00:00
Chris Lattner
a1cf13d201 Switch ActOnTupleType to take an ArrayRef, simplifying it.
Swift SVN r311
2011-03-22 04:54:13 +00:00
Chris Lattner
1fda8dd71d Fix a scoping problem with my recent "make oneof constructors have the right typealias name" patch.
Swift SVN r305
2011-03-21 22:56:00 +00:00
Chris Lattner
0d9da2b967 Improve diagnostics for oneof decls by making the constructors for the elements use the named type for the oneof decl instead of the underlying (unnamed) oneof type.
Swift SVN r302
2011-03-21 21:55:46 +00:00
Chris Lattner
c9eb885752 Introduce top-level expressions and simplify TranslationUnitDecl (and various things that hack on it) by making it hold a single BraceExpr instead of a list of exprs and decls.
Swift SVN r293
2011-03-20 06:59:37 +00:00
Chris Lattner
6807ad7fb1 Move some type validity checking to SemaDecl::handleEndOfTranslationUnit, out of NameBinding.
Swift SVN r287
2011-03-19 06:41:26 +00:00
Chris Lattner
d23c2f26f3 Document and implement lexer and parser support for trivial import decls. No Sema/AST support yet.
Swift SVN r285
2011-03-18 22:52:48 +00:00
Chris Lattner
6ab4eec127 Two changes that got mixed up:
#1: Change type conversion errors to print the types involved, making the diagnostic better.  We still don't have ranges, but it is progress.

#2: Reimplement support for anonymous closure arguments (e.g. func($0+$1)) where func takes a closure, step #1.
 - This removes AnonDecl, replacing it with AnonClosureArgExpr.  $0 and friends have to be expressions since they don't get a type and don't get resolved until TypeChecking.
 - For now we just replace the existing broken support, a future step is to implement type checking support for them.


Swift SVN r278
2011-03-17 06:09:19 +00:00
Chris Lattner
ca1b16b9df Cleanup SemaExpr::ActOnDotIdentifier.
Swift SVN r275
2011-03-17 04:31:55 +00:00
Chris Lattner
d6d92deeb7 Wire DiagnoseUnresolvedType back up and clean up handling of vardecls. This now causes us to explode on tuples with default values so temporarily remove the tests. This also causes us to reject more anondecl tests since those aren't (re)implemented yet.
Swift SVN r267
2011-03-14 22:16:50 +00:00
Chris Lattner
c5506dc66e Capture the structure of a declared VarName in the ast as DeclVarName.
Swift SVN r266
2011-03-14 21:54:21 +00:00