Mercurial > projects > dang
diff parser/Action.d @ 45:9bc660cbdbec new_gen
If statements are back
Also fixed a bug in the codegen preventing return in the else branch, now
it is optional.
Also found an issue with the way we are generating our llvm from ifs - it
doesn't mean anything but the code looks ugly.
if (cond_1)
if (cond_2)
statement;
return 0;
Becomes:
br cond_1, then, merge
then:
br cond_2 then2, merge2
merge:
ret 0
then2:
statements
merge2:
br merge
This is because we use appendBasicBlock on the function
author | Anders Halager <halager@gmail.com> |
---|---|
date | Wed, 23 Apr 2008 16:43:42 +0200 |
parents | 495188f9078e |
children | 90fb4fdfefdd |
line wrap: on
line diff
--- a/parser/Action.d Wed Apr 23 00:57:45 2008 +0200 +++ b/parser/Action.d Wed Apr 23 16:43:42 2008 +0200 @@ -130,6 +130,14 @@ return null; } + /** + */ + StmtT actOnIfStmt(ref Token ifTok, ExprT cond, StmtT thenBody, + ref Token elseTok, StmtT elseBody) + { + return null; + } + StmtT actOnStartOfSwitchStmt() { return null; @@ -200,6 +208,7 @@ */ class AstAction : Action { + // -- Declarations -- override DeclT actOnDeclarator(ref Id type, ref Id id, ExprT init) { Exp exp = cast(Exp)init; @@ -224,11 +233,11 @@ return fd; } + // -- Statements -- override StmtT actOnCompoundStmt(ref Token l, ref Token r, StmtT[] stmts) { StmtT[] array = stmts.dup; Stmt[] statements = cast(Stmt[])array; - Stdout(statements).newline; return new CompoundStatement(cast(Stmt[])array); } @@ -240,6 +249,16 @@ return res; } + override StmtT actOnIfStmt(ref Token ifTok, ExprT cond, StmtT thenBody, + ref Token elseTok, StmtT elseBody) + { + Exp c = cast(Exp)cond; + Stmt t = cast(Stmt)thenBody; + Stmt e = cast(Stmt)elseBody; + return new IfStmt(c, t, e); + } + + // -- Expressions -- override ExprT actOnNumericConstant(Token c) { return new IntegerLit(c);