Author: martin
Date: 2005-04-15 10:13:45 -0400 (Fri, 15 Apr 2005)
New Revision: 43042

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/class.cs
   trunk/mcs/gmcs/cs-parser.jay
   trunk/mcs/gmcs/decl.cs
   trunk/mcs/gmcs/generic.cs
   trunk/mcs/gmcs/tree.cs
Log:
**** Merged r41590 from MCS ****


Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2005-04-15 12:36:05 UTC (rev 43041)
+++ trunk/mcs/gmcs/ChangeLog    2005-04-15 14:13:45 UTC (rev 43042)
@@ -1,3 +1,62 @@
+2005-04-15  Martin Baulig  <[EMAIL PROTECTED]>
+
+       Merged r41590 from MCS and make it work in the generics land.
+
+       * generic.cs (TypeParameter.UpdateConstraints): Removed the
+       `check' argument.
+
+       * class.cs (PartialContainer.UpdateConstraints): Removed.
+       (PartialContainer.CheckConstraints): Removed.
+       (PartialContainer.SetParameterInfo): Store the constraints here.
+       (PartialContainer.DefineTypeParameters): New public method;
+       resolve the type parameter's constraints here.  Note that the
+       PartialContainer doesn't have an EmitContext anymore, so we must
+       do this in the ClassPart.
+
+2005-03-09  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       Clean up a few partial-class semantics.  
+       Fixes test-357.cs and cs1618-2.cs.
+       * cs-parser.jay (struct_declaration): Use 'current_class' as
+       parent of newly-created struct.  Remove call to Register ().
+       Use 'pop_current_class' to complete handing the current struct.
+       (interface_declaration): Likewise.
+       (class_declaration): Likewise.
+       (enum_declaration): Use 'current_class' as parent of newly created
+       enum.
+       (delegate_declaration): Likewise.
+       (pop_current_class): New function.  This is used to handle closing
+       up the 'current_class' and 'current_container', and pointing them
+       to the enclosing class/container.
+       (CSharpParser): Initialize 'current_class' too.
+       * decl.cs (MemberCore): Add check for invariant: a partial
+       container is not a parsed entity, and thus does not enclose any
+       parsed members.
+       (DeclSpace.TypeResolveEmitContext): Expose 'type_resolve_ec'.
+       (DeclSpace.BaseTypeExpr): Use it.
+       (DeclSpace.LookupType): Add check for invariant.
+       * class.cs (TypeContainer): Add check for invariant: a nested
+       class should have the same NamespaceEntry as its enclosing class.
+       (TypeContainer.EmitFieldInitializers): Make virtual.
+       (TypeContainer.DefineDefaultConstructor): Adhere to invariant in
+       MemberCore.
+       (TypeContainer.Register): Remove.
+       (TypeContainer.DefineType): Set the 'ec' of a PartialContainer to
+       null.  Use TypeResolveEmitContext for resolving base types and
+       interfaces.  Move initialization of Parts.TypeBuilder here from
+       ...
+       (TypeContainer.DefineNestedTypes): ... here.
+       (PartialContainer): Take a Namespace not a NamespaceEntry.
+       (PartialContainer.Create): Don't use Register.  Call the
+       appropriate Add... function directly.
+       (ClassPart): Take both the PartialContainer and the enclosing
+       class as constructor arguments.
+       (ClassPart.EmitFieldInitializers): Override.
+       (ClassPart.PartFindNestedTypes): Remove.
+       (FieldBase.GetInitializerExpression): Resolve the initializer
+       expression in the emit context of the enclosing class.
+       * tree.cs (RootTypes): Remove Register ().
+       
 2005-03-08  Marek Safar  <[EMAIL PROTECTED]>
 
        * cs-parser.jay: Removed CS0134.

Modified: trunk/mcs/gmcs/class.cs
===================================================================
--- trunk/mcs/gmcs/class.cs     2005-04-15 12:36:05 UTC (rev 43041)
+++ trunk/mcs/gmcs/class.cs     2005-04-15 14:13:45 UTC (rev 43042)
@@ -462,6 +462,9 @@
                                      Attributes attrs, Kind kind, Location l)
                        : base (ns, parent, name, attrs, l)
                {
+                       if (parent != null && parent != RootContext.Tree.Types 
&& parent.NamespaceEntry != ns)
+                               throw new InternalErrorException ("A nested 
type should be in the same NamespaceEntry as its enclosing class");
+
                        this.Kind = kind;
 
                        types = new ArrayList ();
@@ -834,7 +837,7 @@
                //
                // Emits the instance field initializers
                //
-               public bool EmitFieldInitializers (EmitContext ec)
+               public virtual bool EmitFieldInitializers (EmitContext ec)
                {
                        ArrayList fields;
                        Expression instance_expr;
@@ -897,7 +900,12 @@
                        else if ((ModFlags & Modifiers.ABSTRACT) != 0)
                                mods = Modifiers.PROTECTED;
 
-                       c = new Constructor (this, Basename, mods, 
Parameters.EmptyReadOnlyParameters,
+                       TypeContainer constructor_parent = this;
+                       if (Parts != null)
+                               constructor_parent = (TypeContainer) Parts [0];
+
+                       c = new Constructor (constructor_parent, Basename, mods,
+                                            Parameters.EmptyReadOnlyParameters,
                                             new ConstructorBaseInitializer (
                                                     null, 
Parameters.EmptyReadOnlyParameters,
                                                     Location),
@@ -915,8 +923,6 @@
                /// </remarks>
                public PendingImplementation Pending;
 
-               public abstract void Register ();
-
                public abstract PendingImplementation GetPendingImplementations 
();
 
                TypeExpr[] GetPartialBases (out TypeExpr base_class, out bool 
error)
@@ -1199,8 +1205,6 @@
                        if (TypeBuilder != null)
                                return TypeBuilder;
 
-                       ec = new EmitContext (this, Mono.CSharp.Location.Null, 
null, null, ModFlags);
-
                        TypeAttributes type_attributes = TypeAttr;
 
                        try {
@@ -1237,6 +1241,19 @@
 
                        TypeManager.AddUserType (Name, TypeBuilder, this);
 
+                       if (Parts != null) {
+                               ec = null;
+                               foreach (ClassPart part in Parts) {
+                                       part.TypeBuilder = TypeBuilder;
+                                       part.ptype = ptype;
+                                       part.ec = new EmitContext (part, 
Mono.CSharp.Location.Null, null, null, ModFlags);
+                                       part.ec.ContainerType = TypeBuilder;
+                               }
+                       } else {
+                               ec = new EmitContext (this, 
Mono.CSharp.Location.Null, null, null, ModFlags);
+                               ec.ContainerType = TypeBuilder;
+                       }
+
                        Expression current_type = null;
 
                        if (IsGeneric) {
@@ -1251,31 +1268,40 @@
                                for (int i = offset; i < gen_params.Length; i++)
                                        CurrentTypeParameters [i - 
offset].Define (gen_params [i]);
 
-                               foreach (TypeParameter type_param in 
CurrentTypeParameters) {
-                                       if (!type_param.Resolve (this)) {
-                                               error = true;
-                                               return null;
+                               if (Parts != null) {
+                                       foreach (ClassPart part in Parts) {
+                                               if (!part.DefineTypeParameters 
()) {
+                                                       error = true;
+                                                       return null;
+                                               }
                                        }
-                               }
+                               } else {
+                                       foreach (TypeParameter type_param in 
CurrentTypeParameters) {
+                                               if (!type_param.Resolve (this)) 
{
+                                                       error = true;
+                                                       return null;
+                                               }
+                                       }
 
-                               for (int i = offset; i < gen_params.Length; i++)
-                                       CurrentTypeParameters [i - 
offset].DefineConstraints ();
+                                       for (int i = offset; i < 
gen_params.Length; i++)
+                                               CurrentTypeParameters [i - 
offset].DefineConstraints ();
 
-                               current_type = new SimpleName (Name, 
TypeParameters, Location);
-
-                               foreach (TypeParameter type_param in 
TypeParameters) {
-                                       if (!type_param.DefineType (ec)) {
-                                               error = true;
-                                               return null;
+                                       foreach (TypeParameter type_param in 
TypeParameters) {
+                                               if (!type_param.DefineType 
(ec)) {
+                                                       error = true;
+                                                       return null;
+                                               }
                                        }
-                               }
 
-                               if (!CheckConstraints (ec)) {
-                                       error = true;
-                                       return null;
+                                       current_type = new SimpleName (Name, 
TypeParameters, Location);
                                }
                        }
 
+                       if (!CheckConstraints (ec)) {
+                               error = true;
+                               return null;
+                       }
+
                        if ((Kind == Kind.Struct) && TypeManager.value_type == 
null)
                                throw new Exception ();
 
@@ -1303,8 +1329,10 @@
                        }
 
                        if (base_type != null) {
-                               base_type = base_type.ResolveAsTypeTerminal 
(ec);
-                               if (base_type == null) {
+                               // FIXME: I think this should be ...ResolveType 
(Parent.EmitContext).
+                               //        However, if Parent == 
RootContext.Tree.Types, its NamespaceEntry will be null.
+                               ptype = base_type.ResolveType 
(TypeResolveEmitContext);
+                               if (ptype == null) {
                                        error = true;
                                        return null;
                                }
@@ -1336,7 +1364,8 @@
                        if (iface_exprs != null) {
                                // FIXME: I think this should be 
...ExpandInterfaces (Parent.EmitContext, ...).
                                //        However, if Parent == 
RootContext.Tree.Types, its NamespaceEntry will be null.
-                               ifaces = TypeManager.ExpandInterfaces (ec, 
iface_exprs);
+                               TypeResolveEmitContext.ContainerType = 
TypeBuilder;
+                               ifaces = TypeManager.ExpandInterfaces 
(TypeResolveEmitContext, iface_exprs);
                                if (ifaces == null) {
                                        error = true;
                                        return null;
@@ -1371,11 +1400,6 @@
                                CurrentType = current_type.Type;
                        }
 
-                       //
-                       // Finish the setup for the EmitContext
-                       //
-                       ec.ContainerType = TypeBuilder;
-
                        if (!(this is Iterator))
                                RootContext.RegisterOrder (this); 
 
@@ -1418,14 +1442,6 @@
                                                return false;
                        }
 
-                       if (Parts != null) {
-                               foreach (ClassPart part in Parts) {
-                                       part.TypeBuilder = TypeBuilder;
-                                       part.base_type = base_type;
-                                       part.ec = new EmitContext (part, 
Mono.CSharp.Location.Null, null, null, ModFlags);
-                               }
-                       }
-
                        return true;
                }
 
@@ -1723,14 +1739,6 @@
                                }
                        }
 
-                       if (Parts != null) {
-                               foreach (ClassPart cp in Parts) {
-                                       Type t = cp.PartFindNestedType (name);
-                                       if (t != null)
-                                               return t;
-                               }
-                       }
-
                        return null;
                }
 
@@ -2657,10 +2665,19 @@
                                return pc;
                        }
 
-                       pc = new PartialContainer (ns, parent, member_name, 
mod_flags, kind, loc);
+                       if (parent is ClassPart)
+                               parent = ((ClassPart) parent).PartialContainer;
+
+                       pc = new PartialContainer (ns.NS, parent, member_name, 
mod_flags, kind, loc);
                        RootContext.Tree.RecordDecl (full_name, pc);
-                       parent.AddType (pc);
-                       pc.Register ();
+
+                       if (kind == Kind.Interface)
+                               parent.AddInterface (pc);
+                       else if (kind == Kind.Class || kind == Kind.Struct)
+                               parent.AddClassOrStruct (pc);
+                       else
+                               throw new InvalidOperationException ();
+
                        // This is needed to define our type parameters; we 
define the constraints later.
                        pc.SetParameterInfo (null);
                        return pc;
@@ -2674,19 +2691,19 @@
                        if (pc == null) {
                                // An error occured; create a dummy container, 
but don't
                                // register it.
-                               pc = new PartialContainer (ns, parent, name, 
mod, kind, loc);
+                               pc = new PartialContainer (ns.NS, parent, name, 
mod, kind, loc);
                        }
 
-                       ClassPart part = new ClassPart (ns, pc, mod, attrs, 
kind, loc);
+                       ClassPart part = new ClassPart (ns, pc, parent, mod, 
attrs, kind, loc);
                        pc.AddPart (part);
                        return part;
                }
 
-               protected PartialContainer (NamespaceEntry ns, TypeContainer 
parent,
+               protected PartialContainer (Namespace ns, TypeContainer parent,
                                            MemberName name, int mod, Kind 
kind, Location l)
-                       : base (ns, parent, name, null, kind, l)
+                       : base (null, parent, name, null, kind, l)
                {
-                       this.Namespace = ns.NS;
+                       this.Namespace = ns;
 
                        switch (kind) {
                        case Kind.Class:
@@ -2718,101 +2735,11 @@
                        this.OriginalModFlags = mod;
                }
 
-               public override void Register ()
-               {
-                       if (Kind == Kind.Interface)
-                               Parent.AddInterface (this);
-                       else if (Kind == Kind.Class || Kind == Kind.Struct)
-                               Parent.AddClassOrStruct (this);
-                       else
-                               throw new InvalidOperationException ();
-               }
-
                public override PendingImplementation GetPendingImplementations 
()
                {
                        return PendingImplementation.GetPendingImplementations 
(this);
                }
 
-               ArrayList constraints_lists;
-
-               public void UpdateConstraints (ArrayList constraints_list)
-               {
-                       //
-                       // This is called for each ClassPart in a partial 
generic type declaration.
-                       //
-                       // If no constraints were specified for the part, just 
return.
-                       // Otherwise, if we're called with constraints for the 
first time, they become
-                       // the type's constraint.  If we're called with 
constraints again, we just
-                       // store them somewhere so we can later check whether 
there are no conflicts.
-                       //
-                       if (constraints_list == null)
-                               return;
-
-                       if (constraints_lists != null) {
-                               constraints_lists.Add (constraints_list);
-                               return;
-                       }
-
-                       DoUpdateConstraints (null, constraints_list, false);
-
-                       constraints_lists = new ArrayList ();
-               }
-
-               protected bool DoUpdateConstraints (EmitContext ec, ArrayList 
constraints_list, bool check)
-               {
-                       for (int i = 0; i < TypeParameters.Length; i++) {
-                               string name = TypeParameters [i].Name;
-
-                               Constraints constraints = null;
-                               if (constraints_list != null) {
-                                       foreach (Constraints constraint in 
constraints_list) {
-                                               if (constraint.TypeParameter == 
name) {
-                                                       constraints = 
constraint;
-                                                       break;
-                                               }
-                                       }
-                               }
-
-                               if (!TypeParameters [i].UpdateConstraints (ec, 
constraints, check)) {
-                                       Report.Error (265, Location, "Partial 
declarations of `{0}' have " +
-                                                     "inconsistent constraints 
for type parameter `{1}'.",
-                                                     MemberName.GetTypeName 
(), name);
-                                       return false;
-                               }
-                       }
-
-                       return true;
-               }
-
-               protected override bool CheckConstraints (EmitContext ec)
-               {
-                       if (constraints_lists == null)
-                               return true;
-
-                       //
-                       // If constraints were specified in more than one part 
of a
-                       // partial generic type definition, they must be 
identical.
-                       //
-                       // Note that we must resolve them and then compute the 
fully
-                       // resolved types since different parts may have 
different
-                       // `using' aliases.  See gen-129.cs for an example.
-
-                       foreach (ArrayList constraints_list in 
constraints_lists) {
-                               if (!DoUpdateConstraints (ec, constraints_list, 
true))
-                                       return false;
-                       }
-
-                       return true;
-               }
-
-               public ClassPart AddPart (NamespaceEntry ns, int mod, 
Attributes attrs,
-                                         Location l)
-               {
-                       ClassPart part = new ClassPart (ns, this, mod, attrs, 
Kind, l);
-                       AddPart (part);
-                       return part;
-               }
-
                public override TypeAttributes TypeAttr {
                        get {
                                return base.TypeAttr | DefaultTypeAttributes;
@@ -2824,25 +2751,25 @@
                public readonly PartialContainer PartialContainer;
                public readonly bool IsPartial;
 
-               public ClassPart (NamespaceEntry ns, PartialContainer parent,
+               Constraints[] constraints;
+
+               public ClassPart (NamespaceEntry ns, PartialContainer pc, 
TypeContainer parent,
                                  int mod, Attributes attrs, Kind kind, 
Location l)
-                       : base (ns, parent.Parent, parent.MemberName, attrs, 
kind, l)
+                       : base (ns, parent, pc.MemberName, attrs, kind, l)
                {
-                       this.PartialContainer = parent;
+                       this.PartialContainer = pc;
                        this.IsPartial = true;
 
                        int accmods;
-                       if (parent.Parent == null)
+                       if (parent == null || parent == RootContext.Tree.Types)
                                accmods = Modifiers.INTERNAL;
                        else
                                accmods = Modifiers.PRIVATE;
 
-                       this.ModFlags = Modifiers.Check (
-                               parent.AllowedModifiers, mod, accmods, l);
-               }
+                       this.ModFlags = Modifiers.Check (pc.AllowedModifiers, 
mod, accmods, l);
 
-               public override void Register ()
-               {
+                       if (pc.IsGeneric)
+                               constraints = new Constraints 
[pc.CountCurrentTypeParameters];
                }
 
                public override PendingImplementation GetPendingImplementations 
()
@@ -2859,19 +2786,63 @@
 
                public override void SetParameterInfo (ArrayList 
constraints_list)
                {
-                       PartialContainer.UpdateConstraints (constraints_list);
+                       if (constraints_list == null)
+                               return;
+
+                       TypeParameter[] current_params = 
PartialContainer.CurrentTypeParameters;
+                       for (int i = 0; i < constraints.Length; i++) {
+                               foreach (Constraints constraint in 
constraints_list) {
+                                       if (constraint.TypeParameter == 
current_params [i].Name) {
+                                               constraints [i] = constraint;
+                                               break;
+                                       }
+                               }
+                       }
                }
 
-               public override Type FindNestedType (string name)
+               public bool DefineTypeParameters ()
                {
-                       return PartialContainer.FindNestedType (name);
+                       TypeParameter[] current_params = 
PartialContainer.CurrentTypeParameters;
+
+                       for (int i = 0; i < current_params.Length; i++) {
+                               Constraints new_constraints = constraints [i];
+                               if (new_constraints == null)
+                                       continue;
+
+                               if (!current_params [i].UpdateConstraints (ec, 
new_constraints)) {
+                                       Report.Error (265, Location, "Partial 
declarations of `{0}' have " +
+                                                     "inconsistent constraints 
for type parameter `{1}'.",
+                                                     MemberName.GetTypeName 
(), current_params [i].Name);
+                                       return false;
+                               }
+                       }
+
+                       for (int i = 0; i < current_params.Length; i++) {
+                               if (!current_params [i].Resolve (this))
+                                       return false;
+                       }
+
+                       for (int i = 0; i < current_params.Length; i++)
+                               current_params [i].DefineConstraints ();
+
+                       foreach (TypeParameter type_param in 
PartialContainer.TypeParameters) {
+                               if (!type_param.DefineType (ec))
+                                       return false;
+                       }
+
+                       return true;
                }
 
-               public Type PartFindNestedType (string name)
+               public override bool EmitFieldInitializers (EmitContext ec)
                {
-                       return base.FindNestedType (name);
+                       return PartialContainer.EmitFieldInitializers (ec);
                }
 
+               public override Type FindNestedType (string name)
+               {
+                       return PartialContainer.FindNestedType (name);
+               }
+
                public override MemberCache BaseCache {
                        get {
                                return PartialContainer.BaseCache;
@@ -2940,11 +2911,6 @@
                                }
                        }
                }
-
-               public override void Register ()
-               {
-                       Parent.AddClassOrStruct (this);
-               }
        }
 
        /// <summary>
@@ -3177,11 +3143,6 @@
                        this.ModFlags = Modifiers.Check (AllowedModifiers, mod, 
accmods, l);
                }
 
-               public override void Register ()
-               {
-                       Parent.AddInterface (this);
-               }
-
                public override PendingImplementation GetPendingImplementations 
()
                {
                        return null;
@@ -4731,7 +4692,7 @@
                                }
                        }
                        if (Initializer != null) {
-                               if (GetObsoleteAttribute (Parent) == null && 
Parent.GetObsoleteAttribute (Parent.Parent) == null)
+                               if (GetObsoleteAttribute (Parent) == null && 
Parent.GetObsoleteAttribute (Parent) == null)
                                        Initializer.CheckObsoleteAttribute 
(Parent, Location);
                                else
                                        ec.TestObsoleteMethodUsage = false;
@@ -5649,10 +5610,15 @@
                        else
                                e = new ArrayCreation (Type, "", 
(ArrayList)init, Location);
 
-                       ec.IsFieldInitializer = true;
-                       e = e.DoResolve (ec);
-                       ec.IsFieldInitializer = false;
+                       EmitContext parent_ec = Parent.EmitContext;
 
+                       bool old_is_static = parent_ec.IsStatic;
+                       parent_ec.IsStatic = ec.IsStatic;
+                       parent_ec.IsFieldInitializer = true;
+                       e = e.DoResolve (parent_ec);
+                       parent_ec.IsFieldInitializer = false;
+                       parent_ec.IsStatic = old_is_static;
+
                        init_expr = e;
                        init_expr_initialized = true;
 

Modified: trunk/mcs/gmcs/cs-parser.jay
===================================================================
--- trunk/mcs/gmcs/cs-parser.jay        2005-04-15 12:36:05 UTC (rev 43041)
+++ trunk/mcs/gmcs/cs-parser.jay        2005-04-15 14:13:45 UTC (rev 43042)
@@ -777,16 +777,17 @@
 
                if (partial) {
                        ClassPart part = PartialContainer.CreatePart (
-                               current_namespace, current_container, name, 
(int) $2,
+                               current_namespace, current_class, name, (int) 
$2,
                                (Attributes) $1, Kind.Struct, lexer.Location);
 
                        current_container = part.PartialContainer;
                        current_class = part;
                } else {
                        current_class = new Struct (
-                               current_namespace, current_container, name, 
(int) $2,
+                               current_namespace, current_class, name, (int) 
$2,
                                (Attributes) $1, lexer.Location);
 
+                       current_container.AddClassOrStruct (current_class);
                        current_container = current_class;
                        RootContext.Tree.RecordDecl (name.GetName (true), 
current_class);
                }
@@ -805,8 +806,6 @@
 
                if (RootContext.Documentation != null)
                        current_class.DocComment = Lexer.consume_doc_comment ();
-
-               current_class.Register ();
          }
          struct_body
          {
@@ -815,10 +814,7 @@
          }
          opt_semicolon
          {
-               $$ = current_class;
-
-               current_container = current_container.Parent;
-               current_class = current_container;
+               $$ = pop_current_class ();
          }
        | opt_attributes opt_modifiers opt_partial STRUCT error {
                CheckIdentifierToken (yyToken);
@@ -1481,16 +1477,17 @@
 
                if (partial) {
                        ClassPart part = PartialContainer.CreatePart (
-                               current_namespace, current_container, name, 
(int) $2,
+                               current_namespace, current_class, name, (int) 
$2,
                                (Attributes) $1, Kind.Interface, 
lexer.Location);
 
                        current_container = part.PartialContainer;
                        current_class = part;
                } else {
                        current_class = new Interface (
-                               current_namespace, current_container, name, 
(int) $2,
+                               current_namespace, current_class, name, (int) 
$2,
                                (Attributes) $1, lexer.Location);
 
+                       current_container.AddInterface (current_class);
                        current_container = current_class;
                        RootContext.Tree.RecordDecl (name.GetName (true), 
current_class);
                }
@@ -1511,8 +1508,6 @@
                        current_class.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
-
-               current_class.Register ();
          }
          interface_body
          { 
@@ -1521,10 +1516,7 @@
          }
          opt_semicolon 
          {
-               $$ = current_class;
-
-               current_container = current_container.Parent;
-               current_class = current_container;
+               $$ = pop_current_class ();
          }
        | opt_attributes opt_modifiers opt_partial INTERFACE error {
                CheckIdentifierToken (yyToken);
@@ -2413,7 +2405,7 @@
                Location enum_location = lexer.Location;
 
                MemberName full_name = MakeName (new MemberName ((string) $4));
-               Enum e = new Enum (current_namespace, current_container, 
(Expression) $5, (int) $2,
+               Enum e = new Enum (current_namespace, current_class, 
(Expression) $5, (int) $2,
                                   full_name, (Attributes) $1, enum_location);
                
                if (RootContext.Documentation != null)
@@ -2518,7 +2510,7 @@
          {
                Location l = lexer.Location;
                MemberName name = MakeName ((MemberName) $5);
-               Delegate del = new Delegate (current_namespace, 
current_container, (Expression) $4,
+               Delegate del = new Delegate (current_namespace, current_class, 
(Expression) $4,
                                             (int) $2, name, (Parameters) $7, 
(Attributes) $1, l);
 
                if (RootContext.Documentation != null) {
@@ -3670,7 +3662,7 @@
 
                if (partial) {
                        ClassPart part = PartialContainer.CreatePart (
-                               current_namespace, current_container, name, 
mod_flags,
+                               current_namespace, current_class, name, 
mod_flags,
                                (Attributes) $1, Kind.Class, lexer.Location);
 
                        current_container = part.PartialContainer;
@@ -3678,14 +3670,15 @@
                } else {
                        if ((mod_flags & Modifiers.STATIC) != 0) {
                                current_class = new StaticClass (
-                                       current_namespace, current_container, 
name,
+                                       current_namespace, current_class, name,
                                        mod_flags, (Attributes) $1, 
lexer.Location);
                        } else {
                                current_class = new Class (
-                                       current_namespace, current_container, 
name,
+                                       current_namespace, current_class, name,
                                        mod_flags, (Attributes) $1, 
lexer.Location);
                        }
 
+                       current_container.AddClassOrStruct (current_class);
                        current_container = current_class;
                        RootContext.Tree.RecordDecl (name.GetName (true), 
current_class);
                }
@@ -3712,8 +3705,6 @@
                        current_class.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
-
-               current_class.Register ();
          }
          class_body
          {
@@ -3722,10 +3713,7 @@
          }
          opt_semicolon 
          {
-               $$ = current_class;
-
-               current_container = current_container.Parent;
-               current_class = current_container;
+               $$ = pop_current_class ();
          }
        ;       
 
@@ -4945,6 +4933,23 @@
        }
 }
 
+TypeContainer pop_current_class ()
+{
+       TypeContainer retval = current_class;
+
+       current_class = current_class.Parent;
+       current_container = current_container.Parent;
+       
+       if (current_class != current_container) {
+               if (!(current_class is ClassPart) ||
+                   ((ClassPart) current_class).PartialContainer != 
current_container)
+                       throw new InternalErrorException ();
+       } else if (current_container is ClassPart)
+               current_container = ((ClassPart) 
current_class).PartialContainer;
+
+       return retval;
+}
+
 // <summary>
 //   Given the @class_name name, it creates a fully qualified name
 //   based on the containing declaration space
@@ -5141,6 +5146,8 @@
        this.name = file.Name;
        this.file = file;
        current_container = RootContext.Tree.Types;
+       // TODO: Make RootContext.Tree.Types a PartialContainer.
+       current_class = current_container;
        current_container.NamespaceEntry = current_namespace;
        oob_stack = new Stack ();
        switch_stack = new Stack ();

Modified: trunk/mcs/gmcs/decl.cs
===================================================================
--- trunk/mcs/gmcs/decl.cs      2005-04-15 12:36:05 UTC (rev 43041)
+++ trunk/mcs/gmcs/decl.cs      2005-04-15 14:13:45 UTC (rev 43042)
@@ -259,6 +259,9 @@
                                   Location loc)
                        : base (attrs)
                {
+                       if (parent is PartialContainer && !(this is 
PartialContainer))
+                               throw new InternalErrorException ("A 
PartialContainer cannot be the direct parent of a member");
+
                        Parent = parent;
                        MemberName = name;
                        Location = loc;
@@ -534,6 +537,7 @@
 
                readonly bool is_generic;
                readonly int count_type_params;
+               readonly int count_current_type_params;
 
                // The emit context for toplevel objects.
                protected EmitContext ec;
@@ -568,7 +572,7 @@
                        defined_names = new Hashtable ();
                        if (name.TypeArguments != null) {
                                is_generic = true;
-                               count_type_params = name.TypeArguments.Count;
+                               count_type_params = count_current_type_params = 
name.TypeArguments.Count;
                        }
                        if (parent != null)
                                count_type_params += parent.count_type_params;
@@ -712,6 +716,21 @@
                }
 
                EmitContext type_resolve_ec;
+               protected EmitContext TypeResolveEmitContext {
+                       get {
+                               if (type_resolve_ec == null) {
+                                       // FIXME: I think this should really be 
one of:
+                                       //
+                                       // a. type_resolve_ec = 
Parent.EmitContext;
+                                       // b. type_resolve_ec = new EmitContext 
(Parent, Parent, loc, null, null, ModFlags, false);
+                                       //
+                                       // However, if Parent == 
RootContext.Tree.Types, its NamespaceEntry will be null.
+                                       //
+                                       type_resolve_ec = new EmitContext 
(Parent, this, Location.Null, null, null, ModFlags, false);
+                               }
+                               return type_resolve_ec;
+                       }
+               }
 
                // <summary>
                //    Resolves the expression `e' for a type, and will 
recursively define
@@ -719,23 +738,14 @@
                // </summary>
                public TypeExpr ResolveBaseTypeExpr (Expression e, bool silent, 
Location loc)
                {
-                       if (type_resolve_ec == null) {
-                               // FIXME: I think this should really be one of:
-                               //
-                               // a. type_resolve_ec = Parent.EmitContext;
-                               // b. type_resolve_ec = new EmitContext 
(Parent, Parent, loc, null, null, ModFlags, false);
-                               //
-                               // However, if Parent == 
RootContext.Tree.Types, its NamespaceEntry will be null.
-                               //
-                               type_resolve_ec = new EmitContext (Parent, 
this, loc, null, null, ModFlags, false);
-                       }
-                       type_resolve_ec.loc = loc;
+                       TypeResolveEmitContext.loc = loc;
+                       TypeResolveEmitContext.ContainerType = TypeBuilder;
                        if (this is GenericMethod)
-                               type_resolve_ec.ContainerType = 
Parent.TypeBuilder;
+                               TypeResolveEmitContext.ContainerType = 
Parent.TypeBuilder;
                        else
-                               type_resolve_ec.ContainerType = TypeBuilder;
+                               TypeResolveEmitContext.ContainerType = 
TypeBuilder;
 
-                       return e.ResolveAsTypeTerminal (type_resolve_ec);
+                       return e.ResolveAsTypeTerminal (TypeResolveEmitContext);
                }
                
                public bool CheckAccessLevel (Type check_type) 
@@ -959,6 +969,9 @@
                //
                public FullNamedExpression LookupType (string name, Location 
loc, bool ignore_cs0104)
                {
+                       if (this is PartialContainer)
+                               throw new InternalErrorException ("Should not 
get here");
+
                        FullNamedExpression e;
 
                        if (Cache.Contains (name)) {
@@ -1209,6 +1222,12 @@
                        }
                }
 
+               public int CountCurrentTypeParameters {
+                       get {
+                               return count_current_type_params;
+                       }
+               }
+
                public TypeParameterExpr LookupGeneric (string name, Location 
loc)
                {
                        if (!IsGeneric)

Modified: trunk/mcs/gmcs/generic.cs
===================================================================
--- trunk/mcs/gmcs/generic.cs   2005-04-15 12:36:05 UTC (rev 43041)
+++ trunk/mcs/gmcs/generic.cs   2005-04-15 14:13:45 UTC (rev 43042)
@@ -655,7 +655,7 @@
                        return true;
                }
 
-               public bool UpdateConstraints (EmitContext ec, Constraints 
new_constraints, bool check)
+               public bool UpdateConstraints (EmitContext ec, Constraints 
new_constraints)
                {
                        //
                        // We're used in partial generic type definitions.
@@ -664,20 +664,14 @@
                        // Otherwise we're called after the type parameters 
have already been defined
                        // and check whether the constraints are the same in 
all parts.
                        //
-                       if (!check) {
-                               if (type != null)
-                                       throw new InvalidOperationException ();
-                               constraints = new_constraints;
-                               return true;
-                       }
-
                        if (type == null)
                                throw new InvalidOperationException ();
 
-                       if (constraints == null)
-                               return new_constraints == null;
-                       else if (new_constraints == null)
-                               return false;
+                       if (constraints == null) {
+                               new_constraints = constraints;
+                               return true;
+                       } else if (new_constraints == null)
+                               return true;
 
                        if (!new_constraints.Resolve (ec))
                                return false;

Modified: trunk/mcs/gmcs/tree.cs
===================================================================
--- trunk/mcs/gmcs/tree.cs      2005-04-15 12:36:05 UTC (rev 43041)
+++ trunk/mcs/gmcs/tree.cs      2005-04-15 14:13:45 UTC (rev 43042)
@@ -116,11 +116,6 @@
                        ec = new EmitContext (null, this, Location.Null, null, 
null, 0, false);
                }
 
-               public override void Register ()
-               {
-                       throw new InvalidOperationException ();
-                       }
-
                public override PendingImplementation GetPendingImplementations 
()
                {
                        throw new InvalidOperationException ();

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to