diff sema/Visitor.d @ 36:ce17bea8e9bd new_gen

Switch statements support Can only switch on IntegerLit's but multiple values per case and the default are supported. An error is emitted if a value is used multiple times or if theres is more than one default block
author Anders Halager <halager@gmail.com>
date Sun, 20 Apr 2008 22:39:07 +0200
parents 69464d465284
children 858b9805843d
line wrap: on
line diff
--- a/sema/Visitor.d	Sun Apr 20 21:33:50 2008 +0200
+++ b/sema/Visitor.d	Sun Apr 20 22:39:07 2008 +0200
@@ -51,6 +51,8 @@
                 return visitIfStmt(cast(IfStmt)stmt);
             case StmtType.While:
                 return visitWhileStmt(cast(WhileStmt)stmt);
+            case StmtType.Switch:
+                return visitSwitchStmt(cast(SwitchStmt)stmt);
             default:
                 throw new Exception("Unknown statement type");
         }
@@ -164,6 +166,24 @@
             return StmtT.init;
     }
 
+    StmtT visitSwitchStmt(SwitchStmt s)
+    {
+        visitExp(s.cond);
+        foreach(stmt; s.defaultBlock)
+            visitStmt(stmt);
+        foreach (c; s.cases)
+        {
+            foreach(lit; c.values)
+                visitIntegerLit(lit);
+            foreach(stmt; c.stmts)
+                visitStmt(stmt);
+        }
+        static if (is(StmtT == void))
+            return;
+        else
+            return StmtT.init;
+    }
+
     StmtT visitExpStmt(ExpStmt s)
     {
         visitExp(s.exp);