2001-10-29 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Mon, 29 Oct 2001 22:15:01 +0000 (22:15 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Mon, 29 Oct 2001 22:15:01 +0000 (22:15 -0000)
* Small changes to prepare for Array initialization.

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

mcs/mcs/ChangeLog
mcs/mcs/cs-parser.jay
mcs/mcs/expression.cs
mcs/mcs/tree.cs

index 008fc47b5f45f54ea8add0b5aede174d8afb0ec1..933b83e63e1e3d6018bd0a6f2f004c845114458f 100755 (executable)
@@ -1,3 +1,7 @@
+2001-10-29  Miguel de Icaza  <miguel@ximian.com>
+
+       * Small changes to prepare for Array initialization.
+
 2001-10-28  Miguel de Icaza  <miguel@ximian.com>
 
        * typemanager.cs (ImplementsInterface): interface might be null;
index 538cfe1acf78755667dbc33ad3e96276110c489a..806fb4c7ee35b0e7603b683cb3750621c762ab6d 100755 (executable)
@@ -294,8 +294,7 @@ using_namespace_directive
 namespace_declaration
        : NAMESPACE qualified_identifier 
          {
-               current_namespace = new Namespace (current_namespace, (string) $2);
-               tree.RecordNamespace ((string) $2, current_namespace);
+               current_namespace = tree.RecordNamespace (current_namespace, (string) $2);
          } 
          namespace_body opt_semicolon
          { 
@@ -1775,7 +1774,8 @@ array_creation_expression
          opt_rank_specifier
          opt_array_initializer
          {
-               $$ = new New ((string) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, lexer.Location);
+               $$ = new ArrayCreation ((string) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, 
+                                       lexer.Location);
          }
        ;
 
index b9ff09a88265ef5e89010b2579f9ce72b874fe84..5aca281857fb3dc4c076f6111c3b091cca717c77 100755 (executable)
@@ -4194,20 +4194,9 @@ namespace CIR {
        }
 
        public class New : ExpressionStatement {
-
-               public enum NType {
-                       Object,
-                       Array
-               };
-
-               public readonly NType     NewType;
                public readonly ArrayList Arguments;
                public readonly string    RequestedType;
 
-               // These are for the case when we have an array
-               public readonly string    Rank;
-               public readonly ArrayList Initializers;
-
                Location Location;
                MethodBase method = null;
 
@@ -4221,25 +4210,9 @@ namespace CIR {
                {
                        RequestedType = requested_type;
                        Arguments = arguments;
-                       NewType = NType.Object;
                        Location = loc;
                }
 
-               public New (string requested_type, ArrayList exprs, string rank, ArrayList initializers, Location loc)
-               {
-                       RequestedType = requested_type;
-                       Rank          = rank;
-                       Initializers  = initializers;
-                       NewType       = NType.Array;
-                       Location      = loc;
-
-                       Arguments = new ArrayList ();
-
-                       foreach (Expression e in exprs)
-                               Arguments.Add (new Argument (e, Argument.AType.Expression));
-                       
-               }
-
                public Expression ValueTypeVariable {
                        get {
                                return value_target;
@@ -4252,76 +4225,57 @@ namespace CIR {
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       if (NewType == NType.Object) {
-
-                               type = ec.TypeContainer.LookupType (RequestedType, false);
-                               
-                               if (type == null)
+                       type = ec.TypeContainer.LookupType (RequestedType, false);
+                       
+                       if (type == null)
+                               return null;
+                       
+                       bool IsDelegate = TypeManager.IsDelegateType (type);
+                       
+                       if (IsDelegate)
+                               return (new NewDelegate (type, Arguments, Location)).Resolve (ec);
+                       
+                       Expression ml;
+                       
+                       ml = MemberLookup (ec, type, ".ctor", false,
+                                          MemberTypes.Constructor, AllBindingsFlags, Location);
+                       
+                       bool is_struct = false;
+                       is_struct = type.IsSubclassOf (TypeManager.value_type);
+                       
+                       if (! (ml is MethodGroupExpr)){
+                               if (!is_struct){
+                                       report118 (Location, ml, "method group");
                                        return null;
-
-                               bool IsDelegate = TypeManager.IsDelegateType (type);
-                               
-                               if (IsDelegate)
-                                       return (new NewDelegate (type, Arguments, Location)).Resolve (ec);
-                               
-                               Expression ml;
-                               
-                               ml = MemberLookup (ec, type, ".ctor", false,
-                                                  MemberTypes.Constructor, AllBindingsFlags, Location);
-                               
-                               bool is_struct = false;
-                               is_struct = type.IsSubclassOf (TypeManager.value_type);
-                               
-                               if (! (ml is MethodGroupExpr)){
-                                       if (!is_struct){
-                                               report118 (Location, ml, "method group");
-                                               return null;
-                                       }
                                }
-                               
-                               if (ml != null) {
-                                       if (Arguments != null){
-                                               for (int i = Arguments.Count; i > 0;){
-                                                       --i;
-                                                       Argument a = (Argument) Arguments [i];
-                                                       
-                                                       if (!a.Resolve (ec))
-                                                               return null;
-                                               }
+                       }
+                       
+                       if (ml != null) {
+                               if (Arguments != null){
+                                       for (int i = Arguments.Count; i > 0;){
+                                               --i;
+                                               Argument a = (Argument) Arguments [i];
+                                               
+                                               if (!a.Resolve (ec))
+                                                       return null;
                                        }
-                                       
-                                       method = Invocation.OverloadResolve (ec, (MethodGroupExpr) ml,
-                                                                            Arguments, Location);
                                }
-
-                               if (method == null && !is_struct) {
-                                       Error (-6, Location,
-                                              "New invocation: Can not find a constructor for " +
-                                              "this argument list");
-                                       return null;
-                               }
-                               
-                               eclass = ExprClass.Value;
-                               return this;
                                
+                               method = Invocation.OverloadResolve (ec, (MethodGroupExpr) ml,
+                                                                    Arguments, Location);
                        }
                        
-                       if (NewType == NType.Array) {
-
-                               type = ec.TypeContainer.LookupType (RequestedType, false);
-
-                               if (TypeManager.IsBuiltinType (type))
-                                       return (new NewBuiltinArray (
-                                                   RequestedType, Rank, Arguments, Initializers, Location)).Resolve (ec);
-                               else
-                                       return (new NewUserdefinedArray (
-                                                   RequestedType, Rank, Arguments, Initializers, Location)).Resolve (ec); 
-
+                       if (method == null && !is_struct) {
+                               Error (-6, Location,
+                                      "New invocation: Can not find a constructor for " +
+                                      "this argument list");
+                               return null;
                        }
                        
-                       return null;
+                       eclass = ExprClass.Value;
+                       return this;
                }
-               
+
                //
                // This DoEmit can be invoked in two contexts:
                //    * As a mechanism that will leave a value on the stack (new object)
@@ -4373,6 +4327,66 @@ namespace CIR {
                }
        }
 
+       // <summary>
+       //   Represents an array creation expression.
+       // </summary>
+       public class ArrayCreation : ExpressionStatement {
+               string RequestedType;
+               string Rank;
+               ArrayList Initializers;
+               Location loc;
+               ArrayList Arguments;
+               Expression Array;
+
+               public ArrayCreation (string requested_type, ArrayList exprs,
+                                     string rank, ArrayList initializers, Location l)
+               {
+                       RequestedType = requested_type;
+                       Rank          = rank;
+                       Initializers  = initializers;
+                       loc           = l;
+
+                       Arguments = new ArrayList ();
+
+                       foreach (Expression e in exprs)
+                               Arguments.Add (new Argument (e, Argument.AType.Expression));
+                       
+               }
+               
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       type = ec.TypeContainer.LookupType (RequestedType, false);
+                       
+                       if (TypeManager.IsBuiltinType (type))
+                               Array = new NewBuiltinArray (
+                                       RequestedType, Rank, Arguments, Initializers, loc)
+                                       .Resolve (ec);
+                       else
+                               Array = new NewUserdefinedArray (
+                                       RequestedType, Rank, Arguments, Initializers, loc)
+                                       .Resolve (ec);
+
+                       if (Array == null)
+                               return null;
+
+                       type = Array.Type;
+                       eclass = ExprClass.Value;
+
+                       return this;
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       Array.Emit (ec);
+               }
+
+               public override void EmitStatement (EmitContext ec)
+               {
+                       Emit (ec);
+                       ec.ig.Emit (OpCodes.Pop);
+               }
+       }
+       
        // 
        // Class to create arrays out of built-in types
        // 
@@ -4387,7 +4401,6 @@ namespace CIR {
 
                MethodBase method = null;
                Type array_element_type;
-
                bool IsOneDimensional = false;
 
                public NewBuiltinArray (string type, string rank, ArrayList args, ArrayList initializers, Location loc)
@@ -4505,7 +4518,6 @@ namespace CIR {
                                ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) method);
                        }
                }
-               
        }
 
        //
index 607f312e90aaeb5bbe96cd8c47f596444d6ef3f1..e053d4181f12e47273e68689f1748d72bd61d4d7 100755 (executable)
@@ -86,19 +86,17 @@ namespace CIR
                        classes.Add (name, c);
                }
 
-               public Namespace AddNamespace(Namespace parent, string name)
+               public Namespace RecordNamespace (Namespace parent, string name)
                {
                        if (namespaces == null)
                                namespaces = new Hashtable ();
 
-                       Namespace ns = new Namespace(parent, name);
-                       if (namespaces.ContainsKey(ns.Name))
-                               return (Namespace)namespaces[ns.Name];
-                       else
-                       {
-                               namespaces.Add (ns.Name, ns);
-                               return ns;
-                       }
+                       if (namespaces.ContainsKey (name))
+                               return (Namespace) namespaces [name];
+                                                                            
+                       Namespace ns = new Namespace (parent, name);
+                       namespaces.Add (ns.Name, ns);
+                       return ns;
                }
                
                public TypeContainer Types {