# HG changeset patch # User Anders Halager # Date 1208962884 -7200 # Node ID 90fb4fdfefdde38bf1d98b61cc88512886b05393 # Parent 9bc660cbdbecb4a9c304bb182a76655b6b8ac64a While is back diff -r 9bc660cbdbec -r 90fb4fdfefdd ast/Stmt.d --- a/ast/Stmt.d Wed Apr 23 16:43:42 2008 +0200 +++ b/ast/Stmt.d Wed Apr 23 17:01:24 2008 +0200 @@ -92,15 +92,15 @@ class WhileStmt : Stmt { - this(Exp cond, Stmt[] stmts) + this(Exp cond, Stmt stmts) { super(StmtType.While); this.cond = cond; - this.stmts = stmts; + this.whileBody = stmts; } Exp cond; - Stmt[] stmts; + Stmt whileBody; } class SwitchStmt : Stmt diff -r 9bc660cbdbec -r 90fb4fdfefdd gen/LLVMGen.d --- a/gen/LLVMGen.d Wed Apr 23 16:43:42 2008 +0200 +++ b/gen/LLVMGen.d Wed Apr 23 17:01:24 2008 +0200 @@ -382,8 +382,7 @@ b.buildCondBr(cond, bodyBB, doneBB); b.positionAtEnd(bodyBB); - foreach (s; wStmt.stmts) - genStmt(s); + genStmt(wStmt.whileBody); if (b.getInsertBlock().terminated() is false) b.buildBr(condBB); diff -r 9bc660cbdbec -r 90fb4fdfefdd parser/Action.d --- a/parser/Action.d Wed Apr 23 16:43:42 2008 +0200 +++ b/parser/Action.d Wed Apr 23 17:01:24 2008 +0200 @@ -138,6 +138,13 @@ return null; } + /** + */ + StmtT actOnWhileStmt(ref Token whileTok, ExprT cond, StmtT whileBody) + { + return null; + } + StmtT actOnStartOfSwitchStmt() { return null; @@ -258,6 +265,13 @@ return new IfStmt(c, t, e); } + override StmtT actOnWhileStmt(ref Token tok, ExprT cond, StmtT whileBody) + { + Exp c = cast(Exp)cond; + Stmt b = cast(Stmt)whileBody; + return new WhileStmt(c, b); + } + // -- Expressions -- override ExprT actOnNumericConstant(Token c) { diff -r 9bc660cbdbec -r 90fb4fdfefdd parser/Parser.d --- a/parser/Parser.d Wed Apr 23 16:43:42 2008 +0200 +++ b/parser/Parser.d Wed Apr 23 17:01:24 2008 +0200 @@ -82,7 +82,9 @@ { case Tok.Return: Token ret = lexer.next; - Exp exp = parseExpression(); + Exp exp; + if (lexer.peek.type != Tok.Seperator) + exp = parseExpression(); require(Tok.Seperator); return action.actOnReturnStmt(ret, exp); @@ -114,7 +116,10 @@ return action.actOnIfStmt(_if, cond, thenB, _else, elseB); case Tok.While: - return null; + Token _while = lexer.next; + Exp cond = parseExpression(); + Stmt bodyStmt = parseSingleOrCompoundStatement(); + return action.actOnWhileStmt(_while, cond, bodyStmt); case Tok.Identifier: return null; diff -r 9bc660cbdbec -r 90fb4fdfefdd sema/Visitor.d --- a/sema/Visitor.d Wed Apr 23 16:43:42 2008 +0200 +++ b/sema/Visitor.d Wed Apr 23 17:01:24 2008 +0200 @@ -170,8 +170,7 @@ StmtT visitWhileStmt(WhileStmt s) { visitExp(s.cond); - foreach (stmt; s.stmts) - visitStmt(stmt); + visitStmt(s.whileBody); static if (is(StmtT == void)) return; else