Commit Graph

1198 Commits

Author SHA1 Message Date
Chris Lattner
a6ccf69bc6 Implement support for overloading in .-style name lookup. This is not super useful yet because we don't have conversion ranking, but it's progress.
Swift SVN r356
2011-04-10 16:48:31 +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
5e2346492e Implement basic "dot syntax" for applying functions to values. size.area now applies size to area when area is defined as a global function.
Swift SVN r341
2011-04-02 23:10:55 +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
ed7b06c6ff Move semantic analysis of scoped identifiers (x::a) to typechecking, allowing forward referencing of types. This introduces a new UnresolvedScopedIdentifierExpr node to represent the unresolved form.
Swift SVN r334
2011-03-26 22:35:05 +00:00
Chris Lattner
aeb7c0895e The isGroupingParen() predicate doesn't make sense since TupleExpr can be used to create tuple expressions out of a scalar when there is a single element involved. In this case, isGroupingParen would return true but the source and dest types would be different.
This didn't manifest as a bug yet, but it doesn't make sense to wait until it does.  This aspect of grouping parens is a syntactic issue, so make the creator of TupleExpr specify whether the expr is a grouping paren or not and persist this.

Swift SVN r312
2011-03-22 05:04:48 +00:00
Chris Lattner
ae2f026d3f Use isGroupingParen() in one more place, add a TupleExpr::getElementName helper method.
Swift SVN r310
2011-03-22 04:49:47 +00:00
Chris Lattner
20772e3b8e Add a TupleExpr::isGroupingParen() method and use it in a few places.
Swift SVN r309
2011-03-22 04:33:46 +00:00
Chris Lattner
ffb93e65b7 Fix a pretty big issue in typechecking. We were processing things like:
func f() {
   var x = 4
   f()
}

as:
   var x = (4 f())
not:
   var x = 4; f()



Swift SVN r295
2011-03-20 07:37:43 +00:00
Chris Lattner
5e44da89af Change how integer literals get types. Instead of having TypeChecker force them to __builtin_int32_ty, have sema give them integer_literal_type, and expect the library to define what that actually is for a given file.
Swift SVN r282
2011-03-18 06:28:38 +00:00
Chris Lattner
3a57e3f661 Reimplement the SemaExpressionTree expression walking logic in terms of Expr->WalkExpr, which already has it. Enhance WalkExpr to allow skipping visitation of subtrees. No functionality change.
Swift SVN r279
2011-03-17 06:39:02 +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
db236941d0 Check in a massive rewrite of how sema works for expressions in an effort to make way for separate parsing, name binding, type checking phases.
Highlights of this include:
1) most of SemaExpr is gone now, when parsing, all expressions are assigned null types.
2) the introduction of a new TypeChecking pass, which assigns types to expressions, and checks their constraints.
3) ElementRefDecl now properly stores an access path for what it is accessing, and ElementRefDecl's get added to the AST.
4) The parser is much much simpler for expressions now, it just collects lists of primary exprs into SequenceExprs unconditionally.
5) This means that formation of binary expressions, function application etc is now done by TypeChecking.  This is actually simpler, though admittedly surprising.
6) This introduces a new -parse-dump mode which just parses but does not perform name binding or type checking.

I've been working on this for a while and it is still quite broken: it still doesn't handle anondecls at all, doesn't perform conversion checking for default tuple elements, has missing pieces of varname name binding etc.  However, there is no reason to not crash land it now, it's not like I'm going to break anyone else.

Swift SVN r262
2011-03-13 21:52:03 +00:00
Chris Lattner
71eb272b4a Build AST nodes for references to unresolved names. These can be resolved after parse time.
Swift SVN r258
2011-03-07 00:12:38 +00:00
Chris Lattner
7bbe52b52a Expand the swift language to allow typealiases, oneof, and struct within a brace expression. This allows us to have shadowing of type names.
Swift SVN r236
2011-02-22 07:41:44 +00:00
Chris Lattner
e488b69182 Implement sema support for TupleExprs with default elements (represented with null), implement support for conversions from scalar to tuples with multiple default elements.
Swift SVN r220
2010-11-25 23:02:23 +00:00
Chris Lattner
6f7564235d Wire up sema support for creating array types.
Swift SVN r207
2010-10-17 13:12:47 +00:00
Chris Lattner
bffee378d2 Generalize the expression walker to allow rewrites to be implemented.
Swift SVN r191
2010-10-10 06:19:16 +00:00
Chris Lattner
a885cd5dc5 Diagnose completely unresolved expressions with an error like this:
data.swift:114:10: error: ambiguous expression could not resolve a concrete type
var xx = :Zero;
         ^

Do this with a very general pre/post-order walking function.

Swift SVN r190
2010-10-10 06:11:47 +00:00
Chris Lattner
272cbcaba3 Implement parser, ast and minimal sema support for :foo expressions, type resolution isn't done yet.
Swift SVN r185
2010-10-10 00:15:46 +00:00
Chris Lattner
57c697172a Split NamedDecl into NamedDecl with a ValueDecl subclass that has the type and value of the decl.
Swift SVN r173
2010-10-09 20:28:11 +00:00
Chris Lattner
025143611f implement support for tuple expressions with names specified for the elements.
Swift SVN r157
2010-08-07 06:51:12 +00:00
Chris Lattner
04f7a08621 add support for tuple field access with ".", e.g.:
var a : (int, var f : int, int);
  var b = a.field0+a.field1+a.f;

This also eliminates TupleConvertExpr.

Swift SVN r137
2010-08-03 06:55:08 +00:00
Chris Lattner
7a5b428772 start reworking tuple compatibility: two different tuples aren't compatible because their canonical type is the same, they are compatible because one can be converted to the other. I'm just going to rip out canonical type support for now.
Swift SVN r133
2010-08-03 04:17:26 +00:00
Chris Lattner
c6499fe1ed Fixme patrol, clean some up.
Swift SVN r131
2010-08-01 07:09:40 +00:00
Chris Lattner
eae524427b start refactoring to allow bottom-up type inference with re-sema. Still much to be done.
Swift SVN r122
2010-07-30 23:03:23 +00:00
Chris Lattner
1a9f102090 switch expression printing over to use a visitor instead of hand rolled dispatch.
Swift SVN r120
2010-07-30 21:08:58 +00:00
Chris Lattner
667078650a Implement support for anonymous closure arguments. For example, we can now compile this:
var func6 : ((int,int) -> int) -> ();  // Takes a function, returns nothing.
func funcdecl5() {
  func6(_0 + _1);         // Closure with two named anonymous arguments
}
into:

  (apply_expr type='()'
    (declref_expr type='(int, int) -> int -> ()' decl=func6)
    (closure_expr type='(int, int) -> int'
     (anondecl '_0' type='int')
     (anondecl '_1' type='int')
     (tuple_expr type='int'
      (binary_expr '+' type='int'
       (declref_expr type='int' decl=_0)
       (declref_expr type='int' decl=_1))))))))

However, there are still some problems with this (and we're definitely not doing type inference yet, all anon args are assumed 'int').

Swift SVN r111
2010-07-28 06:25:16 +00:00
Chris Lattner
9d33ef3616 add infrasturctuer for binding to "named anonymous" arguments.
Swift SVN r108
2010-07-27 21:37:29 +00:00
Chris Lattner
874421d4ce Implement AST and Sema support for auto-closures. We now parse:
var closure1 : () -> int = 4;  // Function producing 4 whenever it is called.
var closure2 : (int,int) -> int = 4; // Has some (dead) arguments.

into:

(vardecl 'closure1' type='() -> int'
 (closure_expr type='() -> int'
  (integer_literal type='int' value=4)))
(vardecl 'closure2' type='(int, int) -> int'
 (closure_expr type='(int, int) -> int'
  (integer_literal type='int' value=4)))


Swift SVN r101
2010-07-27 06:27:02 +00:00
Chris Lattner
da8a6af90a add a new expression to model sequences instead of hacking up braceexpr to do it.
Swift SVN r94
2010-07-25 23:22:29 +00:00
Chris Lattner
7e0123c768 Kill off add/sub/mul/div as special AST nodes. Instead, + is just yet-another identifier token and BinaryExpr is a generalized infix call expression.
Swift SVN r88
2010-07-25 19:16:45 +00:00
Chris Lattner
12fa92e146 Add a new ApplyExpr expression AST node for function application.
Swift SVN r85
2010-07-25 05:37:45 +00:00
Chris Lattner
9b42d1b273 enhance parenexpr to be tupleexpr. The grouping paren case is just a special case of a tuple literal with one child.
Swift SVN r81
2010-07-24 21:24:44 +00:00
Chris Lattner
2bafb0e8fb Introduce new NamedDecl and FuncDecl classes. The difference between the two is syntactic sugar, so most clients want NamedDecl. This doesn't implement FuncDecl yet, which isn't a high prio for me in the short term.
Swift SVN r77
2010-07-24 19:09:09 +00:00
Chris Lattner
64ecbb8a9c Implement AST and trivial Sema support for brace expressions.
Swift SVN r70
2010-07-23 19:39:51 +00:00
Chris Lattner
58185415a1 now that we have name lookup, we can implement references to
other values.  crazzay.


Swift SVN r67
2010-07-23 05:48:20 +00:00
Chris Lattner
34602d5d22 Make Expr::Kind public.
Swift SVN r57
2010-07-22 06:10:31 +00:00
Chris Lattner
c363b58ea1 Introduce TupleType, an AST representation of tuples.
Swift SVN r49
2010-07-22 01:58:01 +00:00
Chris Lattner
f7c8e53359 implement isa/dyncast and dumping support for exprs.
We can now parse and print this:
var x3 = 4+5*4+12/97;

into:
(vardecl 'x3'
 (binary_expr
  (binary_expr
   (integer_literal 4)
   (binary_expr
    (integer_literal 5)
    (integer_literal 4)))
  (binary_expr
   (integer_literal 12)
   (integer_literal 97))))




Swift SVN r46
2010-07-19 06:52:08 +00:00
Chris Lattner
cea9a29739 fix some include guards and an uninitialized member
Swift SVN r43
2010-07-19 06:11:19 +00:00
Chris Lattner
9eb6733531 Exprs have types.
Swift SVN r36
2010-07-19 04:42:58 +00:00
Chris Lattner
f36e4aa921 introduce Type ast node.
Swift SVN r33
2010-07-19 04:33:59 +00:00
Chris Lattner
a63671f116 add binary expression ast node.
Swift SVN r31
2010-07-19 00:57:54 +00:00
Chris Lattner
17aad28720 set up expression kinds, add ParenExpr ast node.
Swift SVN r30
2010-07-19 00:51:28 +00:00
Chris Lattner
66199fa090 implement a new IntegerLiteral ast node, add plumbing for
allocation of exprs from ASTContext.


Swift SVN r28
2010-07-19 00:42:30 +00:00
Chris Lattner
d3756f2627 Sketch out the new AST library, lets start with expressions.
Swift SVN r25
2010-07-19 00:05:11 +00:00