Mercurial > projects > dang
diff ast/Stmt.d @ 56:4ae365eff712 new_gen
Now return types works for structs... Also, simplyfing in AST have been startet - but still messy. This update is a little messy...
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Mon, 28 Apr 2008 21:40:00 +0200 |
parents | 90fb4fdfefdd |
children | 43bb0a36b869 |
line wrap: on
line diff
--- a/ast/Stmt.d Sat Apr 26 23:11:13 2008 +0200 +++ b/ast/Stmt.d Mon Apr 28 21:40:00 2008 +0200 @@ -1,7 +1,8 @@ module ast.Stmt; import Array = tango.core.Array, - Integer = tango.text.convert.Integer; + Integer = tango.text.convert.Integer, + tango.io.Stdout; import ast.Exp, ast.Decl; @@ -28,8 +29,13 @@ this.stmtType = stmtType; } + void simplify() + { + } + StmtType stmtType; Scope env; + int stmtIndex; } class CompoundStatement : Stmt @@ -40,6 +46,12 @@ this.statements = stmts; } + void simplify() + { + foreach ( stmt ; statements ) + stmt.simplify; + } + Stmt[] statements; } @@ -50,6 +62,35 @@ super(StmtType.Return); } + void simplify() + { + FuncDecl f = env.parentFunction; + if(f.sret) + { + auto i = new Identifier("ret.val"); + i.env = f.env; + auto ass = new AssignExp(i, exp); + ass.env = f.env; + auto assStmt = new ExpStmt(ass); + assStmt.env = f.env; + + Stmt[] stmts; + Stdout(stmtIndex).newline; + foreach(index, stmt ; f.statements) + { + if(stmtIndex == index) + stmts ~= assStmt; + + stmts ~= stmt; + } + f.statements = stmts; + + exp = null; + } + if(exp) + exp.simplify; + } + public Exp exp; } @@ -61,6 +102,11 @@ this.decl = decl; } + void simplify() + { + decl.simplify; + } + public Decl decl; } @@ -72,6 +118,11 @@ this.exp = exp; } + void simplify() + { + exp = exp.simplify; + } + public Exp exp; } @@ -85,6 +136,13 @@ this.else_body = el; } + void simplify() + { + cond.simplify; + then_body.simplify; + else_body.simplify; + } + Exp cond; Stmt then_body; Stmt else_body; @@ -99,6 +157,12 @@ this.whileBody = stmts; } + void simplify() + { + cond.simplify; + whileBody.simplify; + } + Exp cond; Stmt whileBody; } @@ -156,6 +220,16 @@ cases[$ - 1].followedByDefault = true; } + void simplify() + { + cond.simplify; + foreach ( stmt ; defaultBlock ) + stmt.simplify; + foreach ( c ; cases ) + foreach ( stmt ; c.stmts ) + stmt.simplify; + } + Exp cond; Case[] cases; Stmt[] defaultBlock;