* ArrayLiteral.cs: added internal size field as an ArrayLiteral can have
authorCésar Natarén <cesar@mono-cvs.ximian.com>
Fri, 25 Jun 2004 23:40:48 +0000 (23:40 -0000)
committerCésar Natarén <cesar@mono-cvs.ximian.com>
Fri, 25 Jun 2004 23:40:48 +0000 (23:40 -0000)
        elisions we keep track of the "real" size here. Added constructor. Added initial
        Resolve and Emit code.

svn path=/trunk/mcs/; revision=30431

mcs/class/Microsoft.JScript/Microsoft.JScript/ArrayLiteral.cs

index 2487263b52be54dff9ac4c7306ebc44481f3a112..7bb06f960b6bc89d9ead342ecde2b1458c3d23d1 100644 (file)
 //
 
 using System;
+using System.Collections;
+using System.Reflection.Emit;
 
-namespace Microsoft.JScript.Tmp {
+namespace Microsoft.JScript {
 
        public class ArrayLiteral : AST {
 
-               ASTList elems;
+               internal ASTList elems;
+               internal int size;
 
                public ArrayLiteral (Context context, ASTList elems)
                {
                        throw new NotImplementedException ();
                }
 
+               internal ArrayLiteral (AST parent)
+               {
+                       this.parent = parent;
+                       elems = new ASTList ();
+               }
+
                internal override bool Resolve (IdentificationTable context)
                {
-                       throw new NotImplementedException ();
+                       bool r = true;
+                       foreach (AST ast in elems.elems)
+                               r &= ast.Resolve (context);
+                       return r;
                }
 
                internal override void Emit (EmitContext ec)
                {
-                       throw new NotImplementedException ();
+                       int i = 0;
+                       ILGenerator ig = ec.ig;
+                       ArrayList exps = elems.elems;
+                       ig.Emit (OpCodes.Ldc_I4, size);
+                       ig.Emit (OpCodes.Newarr, typeof (object));
+                       foreach (AST ast in exps) {
+                               ig.Emit (OpCodes.Dup);
+                               ig.Emit (OpCodes.Ldc_I4, i);                            
+                               ast.Emit (ec);
+                               ig.Emit (OpCodes.Stelem_Ref);
+                               i++;
+                       }
+                       ig.Emit (OpCodes.Call, typeof (Globals).GetMethod ("ConstructArrayLiteral"));
                }
        }
 }