Mercurial > projects > dang
changeset 149:393a1f47a6d2
For loops in AST and sema. Should have correct scope and such now.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Mon, 21 Jul 2008 21:00:20 +0200 |
parents | 6ec686d9c87d |
children | ee202c72cd30 |
files | ast/Stmt.d parser/Action.d sema/AstAction.d sema/ScopeBuilder.d sema/Visitor.d tests/parser/for_1.d |
diffstat | 6 files changed, 57 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ast/Stmt.d Mon Jul 21 20:28:11 2008 +0200 +++ b/ast/Stmt.d Mon Jul 21 21:00:20 2008 +0200 @@ -19,6 +19,7 @@ Return, If, While, + For, Switch, } @@ -167,6 +168,27 @@ Stmt whileBody; } +class ForStmt : Stmt +{ + this(Stmt init, Exp cond, Exp incre, Stmt stmts) + { + super(StmtType.For); + this.init = init; + this.cond = cond; + this.incre = incre; + this.forBody = stmts; + } + + override void simplify() + { + cond = cond.simplify(); + forBody.simplify(); + } + + Exp cond, incre; + Stmt init, forBody; +} + class SwitchStmt : Stmt { this(Exp target)
--- a/parser/Action.d Mon Jul 21 20:28:11 2008 +0200 +++ b/parser/Action.d Mon Jul 21 21:00:20 2008 +0200 @@ -288,7 +288,7 @@ /** */ - StmtT actOnForStmt(ref Token forTok, StmtT init, ExprT cond, ExprT incre, StmtT whileBody) + StmtT actOnForStmt(ref Token forTok, StmtT init, ExprT cond, ExprT incre, StmtT forBody) { return null; }
--- a/sema/AstAction.d Mon Jul 21 20:28:11 2008 +0200 +++ b/sema/AstAction.d Mon Jul 21 21:00:20 2008 +0200 @@ -196,6 +196,15 @@ return new WhileStmt(c, b); } + StmtT actOnForStmt(ref Token tok, StmtT init, ExprT cond, ExprT incre, StmtT forBody) + { + Stmt i = cast(Stmt)init; + Exp c = cast(Exp)cond; + Exp inc = cast(Exp)incre; + Stmt b = cast(Stmt)forBody; + return new ForStmt(i, c, inc, b); + } + StmtT actOnDeclStmt(DeclT decl) { Decl d = cast(Decl)decl;
--- a/sema/ScopeBuilder.d Mon Jul 21 20:28:11 2008 +0200 +++ b/sema/ScopeBuilder.d Mon Jul 21 21:00:20 2008 +0200 @@ -418,6 +418,14 @@ pop(sc); } + override void visitForStmt(ForStmt s) + { + s.env = current(); + auto sc = push(); + super.visitForStmt(s); + pop(sc); + } + override void visitCompoundStmt(CompoundStatement s) { s.env = current();
--- a/sema/Visitor.d Mon Jul 21 20:28:11 2008 +0200 +++ b/sema/Visitor.d Mon Jul 21 21:00:20 2008 +0200 @@ -70,6 +70,8 @@ return visitIfStmt(cast(IfStmt)stmt); case StmtType.While: return visitWhileStmt(cast(WhileStmt)stmt); + case StmtType.For: + return visitForStmt(cast(ForStmt)stmt); case StmtType.Switch: return visitSwitchStmt(cast(SwitchStmt)stmt); default: @@ -256,6 +258,18 @@ else return StmtT.init; } + + StmtT visitForStmt(ForStmt s) + { + visitStmt(s.init); + visitExp(s.cond); + visitExp(s.incre); + visitStmt(s.forBody); + static if (is(StmtT == void)) + return; + else + return StmtT.init; + } StmtT visitSwitchStmt(SwitchStmt s) {