changeset 139:a22e3663de89

Fixed up our simplify functions Removed some unused stuff and changed all function calls to have () attached. We should only omit parens when calling something that is supposed to be a property - not a function like simplify
author Anders Halager <halager@gmail.com>
date Fri, 18 Jul 2008 13:32:34 +0200
parents b61de188cd0d
children 85d609399fdf
files ast/Exp.d ast/Stmt.d
diffstat 2 files changed, 51 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- a/ast/Exp.d	Fri Jul 18 13:17:02 2008 +0200
+++ b/ast/Exp.d	Fri Jul 18 13:32:34 2008 +0200
@@ -104,6 +104,14 @@
         return f.returnType;
     }
 
+    override CallExp simplify()
+    {
+        foreach (ref arg; args)
+            arg = arg.simplify();
+        exp = exp.simplify();
+        return this;
+    }
+
     Exp exp;
     Exp[] args;
     bool sret = false;
@@ -115,51 +123,6 @@
             res = res + args[$ - 1].sourceRange;
         return res;
     }
-
-    Exp simplify()
-    {
-        /*
-        if(auto t = type.asStruct)
-        {
-            DFunction func_t = cast(DFunction)exp.type();
-            assert(func_t !is null, "Calling on something that isn't a function");
-            if (cast(DStruct)func_t.returnType is null)
-                return this;
-
-            auto call = cast(Identifier)exp;
-            FuncDecl f = env.parentFunction;
-            auto i = new Identifier("temp.var");
-            i.env = f.env;
-            f.env.add(i);
-            f.env.find(i).setType(t);
-            auto ty = new Identifier(t.name);
-            auto var = new VarDecl(ty, i, null);
-            Exp[] args; 
-            args ~= i;
-            args ~= this.args;
-            auto callExp = new CallExp(exp, args);
-            callExp.env = f.env;
-            var.env = f.env;
-            auto stmtVar = new DeclStmt(var);
-            auto stmtCall = new ExpStmt(callExp);
-            Stmt[] stmts;
-            foreach( index, s ; f.statements)
-            {
-                if(stmtIndex == index)
-                {
-                    stmts ~= stmtVar;
-                    stmts ~= stmtCall;
-                }
-                stmts ~= s;
-            }
-            f.statements = stmts;
-            callExp.sret = true;
-
-            return i;
-        }
-        */
-        return this;
-    }
 }
 
 class AssignExp : BinaryExp
@@ -171,10 +134,10 @@
         this.exp = exp;
     }
 
-    Exp simplify()
+    override AssignExp simplify()
     {
-        identifier = identifier.simplify;
-        exp = exp.simplify;
+        identifier = identifier.simplify();
+        exp = exp.simplify();
 
         return this;
     }
@@ -275,10 +238,10 @@
         return null;
     }
 
-    Exp simplify()
+    override BinaryExp simplify()
     {
-        left = left.simplify;
-        right = right.simplify;
+        left = left.simplify();
+        right = right.simplify();
         return this;
     }
 
@@ -295,9 +258,9 @@
         this.exp = exp;
     }
 
-    Exp simplify()
+    override NegateExp simplify()
     {
-        exp = exp.simplify;
+        exp = exp.simplify();
         return this;
     }
 
@@ -319,9 +282,9 @@
         this.exp = exp;
     }
 
-    Exp simplify()
+    override DerefExp simplify()
     {
-        exp = exp.simplify;
+        exp = exp.simplify();
         return this;
     }
 
@@ -352,7 +315,7 @@
         return name;
     }
 
-    Exp simplify()
+    override IntegerLit simplify()
     {
         return this;
     }
@@ -412,9 +375,9 @@
         return null;
     }
 
-    Exp simplify()
+    override MemberReference simplify()
     {
-        target = target.simplify;
+        target = target.simplify();
         return this;
     }
 
@@ -471,10 +434,10 @@
         return target.sourceRange + SourceRange(right_bracket);
     }
 
-    Exp simplify()
+    override IndexExp simplify()
     {
-        target = target.simplify;
-        index = index.simplify;
+        target = target.simplify();
+        index = index.simplify();
         return this;
     }
 
@@ -497,10 +460,10 @@
         return env.findType(this.castType);
     }
 
-    Exp simplify()
+    override CastExp simplify()
     {
-        castType.simplify;
-        exp.simplify;
+        castType = castType.simplify();
+        exp = exp.simplify();
         return this;
     }
 
@@ -656,7 +619,7 @@
         return 0;
     }
 
-    Exp simplify()
+    override Identifier simplify()
     {
         return this;
     }
--- a/ast/Stmt.d	Fri Jul 18 13:17:02 2008 +0200
+++ b/ast/Stmt.d	Fri Jul 18 13:32:34 2008 +0200
@@ -46,10 +46,10 @@
         this.statements = stmts;
     }
 
-    void simplify()
+    override void simplify()
     {
-        foreach ( stmt ; statements )
-            stmt.simplify;
+        foreach (stmt; statements )
+            stmt.simplify();
     }
 
     Stmt[] statements;
@@ -62,12 +62,13 @@
         super(StmtType.Return);
     }
 
-    void simplify()
+    // Needed?
+    override void simplify()
     {
         FuncDecl f = env.parentFunction;
-        if(exp)
-           exp.simplify;
-        if(f !is null && f.sret)
+        if (exp)
+           exp = exp.simplify();
+        if (f !is null && f.sret)
         {
             auto i = new Identifier("ret.val");
             i.env = f.env;
@@ -85,7 +86,6 @@
                 stmts ~= stmt;
             }
             f.statements = stmts;
-            
             exp = null;
         }
     }
@@ -101,9 +101,9 @@
         this.decl = decl;
     }
 
-    void simplify()
+    override void simplify()
     {
-        decl.simplify;
+        decl.simplify();
     }
 
     public Decl decl;
@@ -117,9 +117,9 @@
         this.exp = exp;
     }
 
-    void simplify()
+    override void simplify()
     {
-        exp = exp.simplify;
+        exp = exp.simplify();
     }
 
     public Exp exp;
@@ -135,12 +135,12 @@
         this.else_body = el;
     }
 
-    void simplify()
+    override void simplify()
     {
-        cond.simplify;
-        then_body.simplify;
+        cond = cond.simplify();
+        then_body.simplify();
         if (else_body)
-            else_body.simplify;
+            else_body.simplify();
     }
 
     Exp cond;
@@ -157,10 +157,10 @@
         this.whileBody = stmts;
     }
 
-    void simplify()
+    override void simplify()
     {
-        cond.simplify;
-        whileBody.simplify;
+        cond = cond.simplify();
+        whileBody.simplify();
     }
 
     Exp cond;
@@ -225,14 +225,14 @@
             cases[$ - 1].followedByDefault = true;
     }
 
-    void simplify()
+    override void simplify()
     {
-        cond.simplify;
+        cond = cond.simplify();
         foreach ( stmt ; defaultBlock )
-            stmt.simplify;
+            stmt.simplify();
         foreach ( c ; cases )
             foreach ( stmt ; c.stmts )
-                stmt.simplify;
+                stmt.simplify();
     }
 
     Exp cond;