diff ast/Exp.d @ 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 2be29b296081
children a14ac9e5c858
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;
     }