diff ast/Exp.d @ 83:9e90694f5da0 new_gen

Parse array indexing, and allow reading from arrays
author Anders Halager <halager@gmail.com>
date Fri, 02 May 2008 19:54:22 +0200
parents 110c7e1c4ca2
children 9375bd975730
line wrap: on
line diff
--- a/ast/Exp.d	Fri May 02 19:51:58 2008 +0200
+++ b/ast/Exp.d	Fri May 02 19:54:22 2008 +0200
@@ -18,7 +18,7 @@
     Deref,
     IntegerLit,
     MemberReference,
-    ArrayReference,
+    Index,
     Identifier,
     ArrayIdentifier,
     PointerIdentifier,
@@ -306,26 +306,31 @@
     private DType myType;
 }
 
-class ArrayReference : Exp
+class IndexExp : Exp
 {
-    this(Exp target, IntegerLit pos)
+    this(Exp target, Exp index)
     {
-        super(ExpType.ArrayReference);
+        super(ExpType.Index);
         this.target = target;
-        this.pos = pos;
+        this.index = index;
     }
 
-    override DType type() { return target.type(); }
+    override DType type()
+    {
+        assert(target.type().isArray(), "Can only index arrays");
+        DArray array = target.type().asArray();
+        return array.arrayOf;
+    }
 
     Exp simplify()
     {
         target = target.simplify;
-        pos.simplify;
+        index = index.simplify;
         return this;
     }
 
     Exp target;
-    IntegerLit pos;
+    Exp index;
 }
 
 class CastExp : Exp
@@ -364,7 +369,7 @@
 
     override DType type()
     {
-        return pointerOf.type.getPointerTo;
+        return pointerOf.type.getPointerTo();
     }
 
     Identifier pointerOf;