Mercurial > projects > dang
diff ast/Exp.d @ 68:381975d76baf new_gen
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Thu, 01 May 2008 19:25:49 +0200 |
parents | 3fdf20b08a81 |
children | 628cb46ab13b |
line wrap: on
line diff
--- a/ast/Exp.d Tue Apr 29 20:15:22 2008 +0200 +++ b/ast/Exp.d Thu May 01 19:25:49 2008 +0200 @@ -21,6 +21,7 @@ Identifier, AssignExp, CallExp, + CastExp, } class Exp @@ -144,6 +145,8 @@ Mul, Div, Mod, } + char[][] getOp = ["=","==","!=","<","<=",">",">=","+","-","*","/","%"]; + this(Operator op, Exp left, Exp right) { super(ExpType.Binary); @@ -157,6 +160,17 @@ if (myType) return myType; + if (op == Operator.Eq || + op == Operator.Ne || + op == Operator.Lt || + op == Operator.Le || + op == Operator.Gt || + op == Operator.Ge) + { + myType = DType.Bool; + return myType; + } + DType l = left.type; DType r = right.type; if (l is r) @@ -167,6 +181,7 @@ myType = l; else return null; + return myType; } char[] resultType() @@ -225,6 +240,8 @@ override DType type() { return DType.Int; } + + Token token; char[] name; } @@ -254,6 +271,8 @@ myType = t; // no error reporting here else assert(0, "Referencing non-existant member"); + + return myType; } Identifier child; @@ -283,6 +302,31 @@ IntegerLit pos; } +class CastExp : Exp +{ + this(Identifier castType, Exp exp) + { + super(ExpType.CastExp); + this.castType = castType; + this.exp = exp; + } + + override DType type() + { + return env.findType(this.castType); + } + + Exp simplify() + { + castType.simplify; + exp.simplify; + return this; + } + + Identifier castType; + Exp exp; +} + class Identifier : Exp { this(Token t)