**** Merged from MCS ****
authorMartin Baulig <martin@novell.com>
Sun, 25 Jul 2004 05:12:59 +0000 (05:12 -0000)
committerMartin Baulig <martin@novell.com>
Sun, 25 Jul 2004 05:12:59 +0000 (05:12 -0000)
svn path=/trunk/mcs/; revision=31451

19 files changed:
mcs/gmcs/ChangeLog
mcs/gmcs/assign.cs
mcs/gmcs/class.cs
mcs/gmcs/codegen.cs
mcs/gmcs/const.cs
mcs/gmcs/cs-parser.jay
mcs/gmcs/cs-tokenizer.cs
mcs/gmcs/decl.cs
mcs/gmcs/delegate.cs
mcs/gmcs/enum.cs
mcs/gmcs/generic.cs
mcs/gmcs/iterators.cs
mcs/gmcs/modifiers.cs
mcs/gmcs/namespace.cs
mcs/gmcs/pending.cs
mcs/gmcs/report.cs
mcs/gmcs/rootcontext.cs
mcs/gmcs/tree.cs
mcs/gmcs/typemanager.cs

index 22395cabc5847f525d3964345c446d36f3cd72a2..ac7632c4399f9cf9b567f911f3f3f1177bb5975d 100755 (executable)
@@ -1,3 +1,140 @@
+2004-07-25  Martin Baulig  <martin@ximian.com>
+
+       * class.cs
+       (TypeContainer.RegisterOrder): Removed, this was unused.
+       (TypeContainer, interface_order): Removed.
+       (TypeContainer.AddClass, AddStruct, AddInterface): Take a
+       TypeContainer as argument since we can also be called with a
+       `PartialContainer' for a partial class/struct/interface.
+       (TypeContainer.IsInterface): Use `Kind == Kind.Interface' instead
+       of checking whether we're an `Interface' - we could be a
+       `PartialContainer'.
+       (PartialContainer.Register): Override; call
+       AddClass()/AddStruct()/AddInterface() on our parent.
+
+       * cs-parser.jay (interface_member_declaration): Add things to the
+       `current_container', not the `current_class'.
+
+       * rootcontext.cs (RegisterOrder): The overloaded version which
+       takes an `Interface' was unused, removed.
+
+       * typemanager.cs (TypeManager.LookupInterface): Return a
+       `TypeContainer', not an `Interface'.
+       (TypeManager.IsInterfaceType): The `builder_to_declspace' may
+       contain a `PartialContainer' for an interface, so check it's
+       `Kind' to figure out what it is.
+
+2004-07-25  Martin Baulig  <martin@ximian.com>
+
+       * class.cs (Class.DefaultTypeAttributes): New public constant.
+       (Struct.DefaultTypeAttributes): Likewise.
+       (Interface.DefaultTypeAttributes): Likewise.
+       (PartialContainer.TypeAttr): Override this and add the
+       DefaultTypeAttributes.
+
+2004-07-25  Martin Baulig  <martin@ximian.com>
+
+       * decl.cs (DeclSpace.Emit): Removed the `TypeContainer' argument,
+       we can just use the `Parent' field instead.
+
+2004-07-25  Martin Baulig  <martin@ximian.com>
+
+       * class.cs (TypeContainer.Emit): Renamed to EmitType().
+
+2004-07-25  Martin Baulig  <martin@ximian.com>
+
+       * class.cs (TypeContainer.DefineMembers): Call DefineMembers() on
+       our parts before defining any methods.
+       (TypeContainer.VerifyImplements): Make this virtual.
+       (ClassPart.VerifyImplements): Override and call VerifyImplements()
+       on our PartialContainer.
+
+2004-07-25  Martin Baulig  <martin@ximian.com>
+
+       * iterators.cs (Iterator.Define): Renamed to DefineIterator().
+
+       * decl.cs (DeclSpace.Define): Removed the `TypeContainer'
+       argument, we can just use the `Parent' field instead.
+
+       * class.cs
+       (MemberBase.CheckBase): Removed the `TypeContainer' argument.   
+       (MemberBase.DoDefine): Likewise.
+
+2004-07-24  Martin Baulig  <martin@ximian.com>
+
+       * decl.cs (MemberCore.Parent): New public field.
+       (DeclSpace.Parent): Moved to MemberCore.
+
+       * class.cs (MethodCore.ds): Removed; use `Parent' instead.
+       (MemberBase.ctor): Added TypeContainer argument, pass it to our
+       parent's .ctor.
+       (FieldBase, Field, Operator): Likewise.
+       (EventProperty.ctor): Take a TypeContainer instead of a DeclSpace.
+       (EventField, Event): Likewise.
+
+2004-07-23  Martin Baulig  <martin@ximian.com>
+
+       * class.cs (PartialContainer): New public class.
+       (ClassPart): New public class.
+       (TypeContainer): Added support for partial classes.
+       (TypeContainer.GetClassBases): Splitted some of the functionality
+       out into GetNormalBases() and GetPartialBases().
+
+       * cs-tokenizer.cs (Token.PARTIAL): New token.
+       (Tokenizer.consume_identifier): Added some hacks to recognize
+       `partial', but only if it's immediately followed by `class',
+       `struct' or `interface'.
+
+       * cs-parser.jay: Added support for partial clases.
+
+2004-07-23  Martin Baulig  <martin@ximian.com>
+
+       * class.cs (MethodCore.ds): Made this a `TypeContainer' instead of
+       a `DeclSpace' and also made it readonly.
+       (MethodCore.ctor): Take a TypeContainer instead of a DeclSpace.
+       (Method.ctor, Constructor.ctor, Destruktor.ctor): Likewise.
+       (PropertyBase.ctor, Property.ctor, Indexer.ctor): Likewise.
+
+       * cs-parser.jay: Pass the `current_class', not the
+       `current_container' (at the moment, this is still the same thing)
+       to a new Method, Property, Event, Indexer or Constructor.
+
+2004-07-23  Martin Baulig  <martin@ximian.com>
+
+       * cs-parser.jay (CSharpParser): Added a new `current_class' field
+       and removed the `current_interface' one.
+       (struct_declaration, class_declaration, interface_declaration):
+       Set `current_class' to the newly created class/struct/interface;
+       set their `Bases' and call Register() before parsing their body.
+
+2004-07-23  Martin Baulig  <martin@ximian.com>
+
+       * class.cs (Kind): New public enum.
+       (TypeContainer): Made this class abstract.
+       (TypeContainer.Kind): New public readonly field.
+       (TypeContainer.CheckDef): New public method; moved here from
+       cs-parser.jay.
+       (TypeContainer.Register): New public abstract method.
+       (TypeContainer.GetPendingImplementations): New public abstract
+       method.
+       (TypeContainer.GetClassBases): Removed the `is_class' and
+       `is_iface' parameters.
+       (TypeContainer.DefineNestedTypes): Formerly known as
+       DoDefineType().
+       (ClassOrStruct): Made this class abstract.
+
+       * tree.cs (RootTypes): New public type. 
+
+2004-07-20  Martin Baulig  <martin@ximian.com>
+
+       * tree.cs (Tree.RecordNamespace): Removed.
+       (Tree.Namespaces): Removed.
+
+       * rootcontext.cs (RootContext.IsNamespace): Removed.
+
+       * cs-parser.jay (namespace_declaration): Just create a new
+       NamespaceEntry here.
+
 2004-07-21  Lluis Sanchez Gual  <lluis@novell.com>
 
        * Makefile: Install gmcs.exe.config file together with gmcs.exe.
index 7655f7fb2ed084f194efdf1a1c94a674699446b5..434ac859a0d4fa93a974b8d72b8e369f27ce244a 100755 (executable)
@@ -44,6 +44,110 @@ namespace Mono.CSharp {
                // for expressions like a [f ()] ++, where you can't call `f ()' twice.
                //
                void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load);
+               
+               /*
+               For simple assignments, this interface is very simple, EmitAssign is called with source
+               as the source expression and leave_copy and prepare_for_load false.
+               
+               For compound assignments it gets complicated.
+               
+               EmitAssign will be called as before, however, prepare_for_load will be
+               true. The @source expression will contain an expression
+               which calls Emit. So, the calls look like:
+               
+               this.EmitAssign (ec, source, false, true) ->
+                       source.Emit (ec); ->
+                               [...] ->
+                                       this.Emit (ec, false); ->
+                                       end this.Emit (ec, false); ->
+                               end [...]
+                       end source.Emit (ec);
+               end this.EmitAssign (ec, source, false, true)
+               
+               
+               When prepare_for_load is true, EmitAssign emits a `token' on the stack that
+               Emit will use for its state.
+               
+               Let's take FieldExpr as an example. assume we are emitting f ().y += 1;
+               
+               Here is the call tree again. This time, each call is annotated with the IL
+               it produces:
+               
+               this.EmitAssign (ec, source, false, true)
+                       call f
+                       dup
+                       
+                       Binary.Emit ()
+                               this.Emit (ec, false);
+                               ldfld y
+                               end this.Emit (ec, false);
+                               
+                               IntConstant.Emit ()
+                               ldc.i4.1
+                               end IntConstant.Emit
+                               
+                               add
+                       end Binary.Emit ()
+                       
+                       stfld
+               end this.EmitAssign (ec, source, false, true)
+               
+               Observe two things:
+                       1) EmitAssign left a token on the stack. It was the result of f ().
+                       2) This token was used by Emit
+               
+               leave_copy (in both EmitAssign and Emit) tells the compiler to leave a copy
+               of the expression at that point in evaluation. This is used for pre/post inc/dec
+               and for a = x += y. Let's do the above example with leave_copy true in EmitAssign
+               
+               this.EmitAssign (ec, source, true, true)
+                       call f
+                       dup
+                       
+                       Binary.Emit ()
+                               this.Emit (ec, false);
+                               ldfld y
+                               end this.Emit (ec, false);
+                               
+                               IntConstant.Emit ()
+                               ldc.i4.1
+                               end IntConstant.Emit
+                               
+                               add
+                       end Binary.Emit ()
+                       
+                       dup
+                       stloc temp
+                       stfld
+                       ldloc temp
+               end this.EmitAssign (ec, source, true, true)
+               
+               And with it true in Emit
+               
+               this.EmitAssign (ec, source, false, true)
+                       call f
+                       dup
+                       
+                       Binary.Emit ()
+                               this.Emit (ec, true);
+                               ldfld y
+                               dup
+                               stloc temp
+                               end this.Emit (ec, true);
+                               
+                               IntConstant.Emit ()
+                               ldc.i4.1
+                               end IntConstant.Emit
+                               
+                               add
+                       end Binary.Emit ()
+                       
+                       stfld
+                       ldloc temp
+               end this.EmitAssign (ec, source, false, true)
+               
+               Note that these two examples are what happens for ++x and x++, respectively.
+               */
        }
 
        /// <summary>
index 4efa9e3376b2640c75762898d8d553e4b366eb21..c0800312624c255a4a3b2ed97472a8957784d2a1 100755 (executable)
@@ -39,10 +39,21 @@ using System.Runtime.InteropServices;
 
 namespace Mono.CSharp {
 
+       public enum Kind {
+               Root,
+               Struct,
+               Class,
+               Interface
+       }
+
        /// <summary>
        ///   This is the base class for structs and classes.  
        /// </summary>
-       public class TypeContainer : DeclSpace, IMemberContainer {
+       public abstract class TypeContainer : DeclSpace, IMemberContainer {
+
+               // Whether this is a struct, class or interface
+               public readonly Kind Kind;
+
                // Holds a list of classes and structures
                ArrayList types;
 
@@ -73,9 +84,6 @@ namespace Mono.CSharp {
                // Holds the list of
                ArrayList interfaces;
 
-               // Holds order in which interfaces must be closed
-               ArrayList interface_order;
-               
                // Holds the methods.
                ArrayList methods;
 
@@ -91,6 +99,9 @@ namespace Mono.CSharp {
                // Holds the iterators
                ArrayList iterators;
 
+               // Holds the parts of a partial class;
+               ArrayList parts;
+
                // The emit context for toplevel objects.
                EmitContext ec;
                
@@ -137,19 +148,60 @@ namespace Mono.CSharp {
 
                Type GenericType;
 
-               public TypeContainer ():
-                       this (null, null, MemberName.Null, null, new Location (-1)) {
-               }
-
                public TypeContainer (NamespaceEntry ns, TypeContainer parent,
-                                     MemberName name, Attributes attrs, Location l)
+                                     MemberName name, Attributes attrs, Kind kind, Location l)
                        : base (ns, parent, name, attrs, l)
                {
+                       this.Kind = kind;
+
                        types = new ArrayList ();
 
                        base_class_name = null;
                }
 
+               // <summary>
+               //   Used to report back to the user the result of a declaration
+               //   in the current declaration space
+               // </summary>
+               public void CheckDef (AdditionResult result, string name, Location loc)
+               {
+                       if (result == AdditionResult.Success)
+                               return;
+
+                       switch (result){
+                       case AdditionResult.NameExists:
+                               Report.Error (102, loc, "The container `{0}' already " +
+                                             "contains a definition for `{1}'",
+                                             Name, name);
+                               break;
+
+                               //
+                               // This is handled only for static Constructors, because
+                               // in reality we handle these by the semantic analysis later
+                               //
+                       case AdditionResult.MethodExists:
+                               Report.Error (111, loc, "Class `{0}' already defines a " +
+                                             "member called '{1}' with the same parameter " +
+                                             "types (more than one default constructor)",
+                                             Name, name);
+                               break;
+
+                       case AdditionResult.EnclosingClash:
+                               Report.Error (542, loc, "Member names cannot be the same " +
+                                             "as their enclosing type");
+                               break;
+               
+                       case AdditionResult.NotAConstructor:
+                               Report.Error (1520, loc, "Class, struct, or interface method " +
+                                             "must have a return type");
+                               break;
+
+                       case AdditionResult.Error:
+                               // Error has already been reported.
+                               break;
+                       }
+               }
+
                public AdditionResult AddConstant (Const constant)
                {
                        AdditionResult res;
@@ -184,7 +236,7 @@ namespace Mono.CSharp {
                        return AdditionResult.Success;
                }
                
-               public AdditionResult AddClass (Class c)
+               public AdditionResult AddClass (TypeContainer c)
                {
                        AdditionResult res;
                        string name = c.Basename;
@@ -198,7 +250,7 @@ namespace Mono.CSharp {
                        return AdditionResult.Success;
                }
 
-               public AdditionResult AddStruct (Struct s)
+               public AdditionResult AddStruct (TypeContainer s)
                {
                        AdditionResult res;
                        string name = s.Basename;
@@ -285,7 +337,7 @@ namespace Mono.CSharp {
                        return AdditionResult.Success;
                }
                
-               public AdditionResult AddInterface (Interface iface)
+               public AdditionResult AddInterface (TypeContainer iface)
                {
                        AdditionResult res;
                        string name = iface.Basename;
@@ -431,6 +483,19 @@ namespace Mono.CSharp {
                        iterators.Add (i);
                }
 
+               public void AddType (TypeContainer tc)
+               {
+                       types.Add (tc);
+               }
+
+               public void AddPart (ClassPart part)
+               {
+                       if (parts == null)
+                               parts = new ArrayList ();
+
+                       parts.Add (part);
+               }
+
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
                        if (a.Type == TypeManager.default_member_type) {
@@ -451,14 +516,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public void RegisterOrder (Interface iface)
-               {
-                       if (interface_order == null)
-                               interface_order = new ArrayList ();
-
-                       interface_order.Add (iface);
-               }
-               
                public ArrayList Types {
                        get {
                                return types;
@@ -557,6 +614,12 @@ namespace Mono.CSharp {
                        }
                }
                
+               public ArrayList Parts {
+                       get {
+                               return parts;
+                       }
+               }
+
                public virtual TypeAttributes TypeAttr {
                        get {
                                return Modifiers.TypeAttr (ModFlags, this);
@@ -644,10 +707,116 @@ namespace Mono.CSharp {
                }
 
                /// <remarks>
-               ///  The pending methods that need to be implemented (interfaces or abstract methods)
+               ///  The pending methods that need to be implemented
+               //   (interfaces or abstract methods)
                /// </remarks>
                public PendingImplementation Pending;
 
+               public abstract void Register ();
+
+               public abstract PendingImplementation GetPendingImplementations ();
+
+               TypeExpr[] GetPartialBases (out TypeExpr parent, out bool error)
+               {
+                       ArrayList ifaces = new ArrayList ();
+
+                       parent = null;
+                       Location parent_loc = Location.Null;
+
+                       foreach (ClassPart part in parts) {
+                               TypeExpr new_parent;
+                               TypeExpr[] new_ifaces;
+
+                               new_ifaces = part.GetClassBases (out new_parent, out error);
+                               if (error)
+                                       return null;
+
+                               if ((parent != null) && (new_parent != null) &&
+                                   !parent.Equals (new_parent)) {
+                                       Report.Error (263, part.Location,
+                                                     "Partial declarations of `{0}' must " +
+                                                     "not specify different base classes",
+                                                     Name);
+
+                                       if (!Location.IsNull (parent_loc))
+                                               Report.LocationOfPreviousError (parent_loc);
+
+                                       error = true;
+                                       return null;
+                               }
+
+                               if ((parent == null) && (new_parent != null)) {
+                                       parent = new_parent;
+                                       parent_loc = part.Location;
+                               }
+
+                               if (new_ifaces == null)
+                                       continue;
+
+                               foreach (TypeExpr iface in new_ifaces) {
+                                       bool found = false;
+                                       foreach (TypeExpr old_iface in ifaces) {
+                                               if (old_iface.Equals (iface)) {
+                                                       found = true;
+                                                       break;
+                                               }
+                                       }
+
+                                       if (!found)
+                                               ifaces.Add (iface);
+                               }
+                       }
+
+                       error = false;
+
+                       TypeExpr[] retval = new TypeExpr [ifaces.Count];
+                       ifaces.CopyTo (retval, 0);
+                       return retval;
+               }
+
+               TypeExpr[] GetNormalBases (out TypeExpr parent, out bool error)
+               {
+                       parent = null;
+
+                       int count = Bases.Count;
+                       int start, i, j;
+
+                       if (Kind == Kind.Class){
+                               TypeExpr name = ResolveTypeExpr (
+                                       (Expression) Bases [0], false, Location);
+
+                               if (name == null){
+                                       error = true;
+                                       return null;
+                               }
+
+                               if (name.IsClass){
+                                       parent = name;
+                                       start = 1;
+                               } else {
+                                       start = 0;
+                               }
+                       } else {
+                               start = 0;
+                       }
+
+                       TypeExpr [] ifaces = new TypeExpr [count-start];
+                       
+                       for (i = start, j = 0; i < count; i++, j++){
+                               Expression name = (Expression) Bases [i];
+                               TypeExpr resolved = ResolveTypeExpr (name, false, Location);
+                               if (resolved == null) {
+                                       error = true;
+                                       return null;
+                               }
+                               
+                               ifaces [j] = resolved;
+                       }
+
+                       error = false;
+                       return ifaces;
+               }
+
                /// <summary>
                ///   This function computes the Base class and also the
                ///   list of interfaces that the class or struct @c implements.
@@ -658,25 +827,29 @@ namespace Mono.CSharp {
                ///   The @parent argument is set to the parent object or null
                ///   if this is `System.Object'. 
                /// </summary>
-               TypeExpr [] GetClassBases (bool is_class, bool is_iface, out bool error)
+               TypeExpr [] GetClassBases (out TypeExpr parent, out bool error)
                {
                        ArrayList bases = Bases;
-                       int count;
                        int start, j, i;
 
                        error = false;
 
-                       if (is_class || is_iface)
-                               parent_type = null;
+                       if (Kind == Kind.Struct)
+                               parent = TypeManager.system_valuetype_expr;
                        else
-                               parent_type = TypeManager.system_valuetype_expr;
+                               parent = null;
+
+                       TypeExpr[] ifaces;
+                       TypeExpr new_parent;
 
-                       if (bases == null){
-                               if (is_class){
+                       if (parts != null)
+                               ifaces = GetPartialBases (out new_parent, out error);
+                       else if (Bases == null){
+                               if (Kind == Kind.Class){
                                        if (RootContext.StdLib)
-                                               parent_type = TypeManager.system_object_expr;
+                                               parent = TypeManager.system_object_expr;
                                        else if (Name != "System.Object")
-                                               parent_type = TypeManager.system_object_expr;
+                                               parent = TypeManager.system_object_expr;
                                } else {
                                        //
                                        // If we are compiling our runtime,
@@ -684,64 +857,58 @@ namespace Mono.CSharp {
                                        // parent is `System.Object'.
                                        //
                                        if (!RootContext.StdLib && Name == "System.ValueType")
-                                               parent_type = TypeManager.system_object_expr;
+                                               parent = TypeManager.system_object_expr;
                                }
 
                                return null;
-                       }
+                       } else
+                               ifaces = GetNormalBases (out new_parent, out error);
+
+                       if (error)
+                               return null;
 
                        //
                        // Bases should be null if there are no bases at all
                        //
-                       count = bases.Count;
-
-                       if (is_class){
-                               TypeExpr name = ResolveTypeExpr ((Expression) bases [0], false, Location);
-
-                               if (name == null){
-                                       error = true;
-                                       return null;
-                               }
+                       if (Kind == Kind.Class){
+                               if (new_parent != null)
+                                       parent = new_parent;
+                               else
+                                       parent = TypeManager.system_object_expr;
 
-                               if (name is TypeParameterExpr){
+                               if (parent is TypeParameterExpr){
                                        Report.Error (
-                                               689, name.Location,
+                                               689, parent.Location,
                                                "Type parameter `{0}' can not be used as a " +
-                                               "base class or interface", name.Name);
+                                               "base class or interface", parent.Name);
                                        error = true;
                                        return null;
                                }
 
-                               if (IsGeneric && name.IsAttribute){
+                               if (IsGeneric && parent.IsAttribute){
                                        Report.Error (
-                                               698, name.Location,
+                                               698, parent.Location,
                                                "A generic type cannot derive from `{0}' " +
-                                               "because it is an attribute class", name.Name);
+                                               "because it is an attribute class",
+                                               parent.Name);
                                        error = true;
                                        return null;
                                }
 
-                               if (name.IsClass){
-                                       parent_type = name;
-                                       start = 1;
-                               } else {
-                                       parent_type = TypeManager.system_object_expr;
-                                       start = 0;
-                               }
-                               if (name.IsSealed){
+                               if (parent.IsSealed){
                                        string detail = "";
-                                       
-                                       if (name.IsValueType)
+                                       
+                                       if (parent.IsValueType)
                                                detail = " (a class can not inherit from a struct/enum)";
                                        
                                        Report.Error (509, "class `"+ Name +
                                                      "': Cannot inherit from sealed class `"+
-                                                     name.Name + "'" + detail);
+                                                     parent.Name + "'" + detail);
                                        error = true;
                                        return null;
                                }
 
-                               if (!parent_type.CanInheritFrom ()){
+                               if (!parent.CanInheritFrom ()){
                                        Report.Error (644, Location,
                                                      "`{0}' cannot inherit from special class `{1}'",
                                                      Name, parent_type.Name);
@@ -749,62 +916,62 @@ namespace Mono.CSharp {
                                        return null;
                                }
 
-                               if (!parent_type.AsAccessible (this, ModFlags))
+                               if (!parent.AsAccessible (this, ModFlags))
                                        Report.Error (60, Location,
                                                      "Inconsistent accessibility: base class `" +
-                                                     name.Name + "' is less accessible than class `" +
+                                                     parent.Name + "' is less accessible than class `" +
                                                      Name + "'");
-
-                       } else {
-                               start = 0;
                        }
 
-                       if (parent_type != null)
-                               base_class_name = parent_type.Name;
+                       if (parent != null)
+                               base_class_name = parent.Name;
 
-                       TypeExpr [] ifaces = new TypeExpr [count-start];
+                       if (ifaces == null)
+                               return null;
 
-                       for (i = start, j = 0; i < count; i++, j++){
-                               Expression name = (Expression) bases [i];
-                               TypeExpr resolved = ResolveTypeExpr (name, false, Location);
+                       int count = ifaces != null ? ifaces.Length : 0;
 
-                               if (resolved == null)
-                                       return null;
-                               
-                               bases [i] = resolved;
+                       for (i = 0; i < count; i++) {
+                               TypeExpr iface = (TypeExpr) ifaces [i];
 
-                               if (is_class == false && !resolved.IsInterface){
-                                       Report.Error (527, "In Struct `" + Name + "', type `"+
-                                                     name +"' is not an interface");
+                               if ((Kind != Kind.Class) && !iface.IsInterface){
+                                       string what = Kind == Kind.Struct ?
+                                               "Struct" : "Interface";
+
+                                       Report.Error (527, Location,
+                                                     "In {0} `{1}', type `{2}' is not "+
+                                                     "an interface", what, Name, iface.Name);
                                        error = true;
                                        return null;
                                }
-                               
-                               if (resolved.IsClass) {
-                                       if (parent_type != null){
-                                               Report.Error (527, "In Class `" + Name + "', type `"+
-                                                             name+"' is not an interface");
+
+                               if (iface.IsClass) {
+                                       if (parent != null){
+                                               Report.Error (527, Location,
+                                                             "In Class `{0}', `{1}' is not " +
+                                                             "an interface", Name, iface.Name);
                                                error = true;
                                                return null;
                                        }
                                }
-
-                               for (int x = 0; x < j; x++) {
-                                       if (resolved.Equals (ifaces [x])) {
-                                               Report.Error (528, "`" + name + "' is already listed in interface list");
+  
+                               for (int x = 0; x < i; x++) {
+                                       if (iface.Equals (ifaces [x])) {
+                                               Report.Error (528, Location,
+                                                             "`{0}' is already listed in " +
+                                                             "interface list", iface.Name);
                                                error = true;
                                                return null;
                                        }
                                }
 
-                               if (is_iface &&
-                                   !resolved.AsAccessible (Parent, ModFlags))
+                               if ((Kind == Kind.Interface) &&
+                                   !iface.AsAccessible (Parent, ModFlags))
                                        Report.Error (61, Location,
-                                                     "Inconsistent accessibility: base interface `" +
-                                                     name + "' is less accessible than interface `" +
-                                                     Name + "'");
-
-                               ifaces [j] = resolved;
+                                                     "Inconsistent accessibility: base " +
+                                                     "interface `{0}' is less accessible " +
+                                                     "than interface `{1}'", iface.Name,
+                                                     Name);
                        }
 
                        return TypeManager.ExpandInterfaces (ifaces);
@@ -847,7 +1014,6 @@ namespace Mono.CSharp {
                public override TypeBuilder DefineType ()
                {
                        TypeExpr parent;
-                       bool is_class, is_iface;
 
                        if (TypeBuilder != null)
                                return TypeBuilder;
@@ -863,20 +1029,9 @@ namespace Mono.CSharp {
                        
                        InTransit = true;
 
-                       if (this is Interface) {
-                               is_iface = true;
-                               is_class = false;
-                       } else {
-                               is_iface = false;
-                       if (this is Class)
-                               is_class = true;
-                       else
-                               is_class = false;
-                       }
-
                        ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags);
 
-                       ifaces = GetClassBases (is_class, is_iface, out error); 
+                       ifaces = GetClassBases (out parent_type, out error); 
 
                        if (error)
                                return null;
@@ -889,7 +1044,7 @@ namespace Mono.CSharp {
                                        }
                        }
                        
-                       if (!is_class && TypeManager.value_type == null)
+                       if ((Kind == Kind.Struct) && TypeManager.value_type == null)
                                throw new Exception ();
 
                        TypeAttributes type_attributes = TypeAttr;
@@ -965,7 +1120,7 @@ namespace Mono.CSharp {
                        // be specified.
                        //
 
-                       if (!is_class && !is_iface && !have_nonstatic_fields){
+                       if ((Kind == Kind.Struct) && !have_nonstatic_fields){
                                TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
                                                         FieldAttributes.Private);
                        }
@@ -998,49 +1153,48 @@ namespace Mono.CSharp {
                        } else if (!(this is Iterator))
                                RootContext.RegisterOrder (this); 
 
-                       if (!DoDefineType ()) {
+                       if (!DefineNestedTypes ()) {
                                error = true;
                                return null;
                        }
 
-                       if (Interfaces != null) {
-                               foreach (Interface iface in Interfaces)
-                                       if (iface.DefineType () == null) {
-                                               error = true;
-                                               return null;
+                       InTransit = false;
+                       return TypeBuilder;
                                        }
+
+               protected virtual bool DefineNestedTypes ()
+               {
+                       if (Interfaces != null) {
+                               foreach (TypeContainer iface in Interfaces)
+                                       if (iface.DefineType () == null)
+                                               return false;
                        }
                        
                        if (Types != null) {
                                foreach (TypeContainer tc in Types)
-                                       if (tc.DefineType () == null) {
-                                               error = true;
-                                               return null;
-                                       }
+                                       if (tc.DefineType () == null)
+                                               return false;
                        }
 
                        if (Delegates != null) {
                                foreach (Delegate d in Delegates)
-                                       if (d.DefineType () == null) {
-                                               error = true;
-                                               return null;
-                                       }
+                                       if (d.DefineType () == null)
+                                               return false;
                        }
 
                        if (Enums != null) {
                                foreach (Enum en in Enums)
-                                       if (en.DefineType () == null) {
-                                               error = true;
-                                               return null;
-                                       }
+                                       if (en.DefineType () == null)
+                                               return false;
                        }
 
-                       InTransit = false;
-                       return TypeBuilder;
+                       if (Parts != null) {
+                               foreach (ClassPart part in Parts) {
+                                       part.TypeBuilder = TypeBuilder;
+                                       part.parent_type = parent_type;
+                               }
                }
 
-               protected virtual bool DoDefineType ()
-               {
                        return true;
                }
 
@@ -1073,7 +1227,7 @@ namespace Mono.CSharp {
                                } else if (mc is MethodCore)
                                        ((MethodCore) mc).OverridesSomething = true;
 
-                               if (!mc.Define (this)){
+                               if (!mc.Define ()){
                                        remove_list.Add (mc);
                                        continue;
                                }
@@ -1137,7 +1291,7 @@ namespace Mono.CSharp {
                        foreach (Indexer i in Indexers) {
                                string name;
 
-                               i.Define (this);
+                               i.Define ();
 
                                name = i.IndexerName;
 
@@ -1192,14 +1346,6 @@ namespace Mono.CSharp {
                                parent_container = TypeManager.LookupMemberContainer (TypeBuilder.BaseType);
 #endif
 
-                       if (interface_order != null){
-                               foreach (Interface iface in interface_order)
-                                       if ((iface.ModFlags & Modifiers.NEW) == 0)
-                                               iface.DefineMembers (this);
-                                       else
-                                               Error_KeywordNotAllowed (iface.Location);
-                       }
-
                        if (RootContext.WarningLevel > 1){
                                Type ptype;
 
@@ -1247,7 +1393,7 @@ namespace Mono.CSharp {
                        if (fields != null)
                                DefineMembers (fields, defined_names);
 
-                       if (this is Class){
+                       if ((Kind == Kind.Class) && !(this is ClassPart)){
                                if (instance_constructors == null){
                                        if (default_constructor == null)
                                                DefineDefaultConstructor (false);
@@ -1258,7 +1404,7 @@ namespace Mono.CSharp {
                                        DefineDefaultConstructor (true);
                        }
 
-                       if (this is Struct){
+                       if (Kind == Kind.Struct){
                                //
                                // Structs can not have initialized instance
                                // fields
@@ -1271,8 +1417,14 @@ namespace Mono.CSharp {
                                        ReportStructInitializedInstanceError ();
                        }
 
-                       if (!(this is Interface))
-                       Pending = PendingImplementation.GetPendingImplementations (this);
+                       Pending = GetPendingImplementations ();
+
+                       if (parts != null) {
+                               foreach (ClassPart part in parts) {
+                                       if (!part.DefineMembers (this))
+                                               return false;
+                               }
+                       }
                        
                        //
                        // Constructors are not in the defined_names array
@@ -1281,8 +1433,8 @@ namespace Mono.CSharp {
                                DefineMembers (instance_constructors, null);
                
                        if (default_static_constructor != null)
-                               default_static_constructor.Define (this);
-                       
+                               default_static_constructor.Define ();
+
                        if (methods != null)
                                DefineMembers (methods, defined_names);
 
@@ -1315,9 +1467,15 @@ namespace Mono.CSharp {
 
 
 #if CACHE
+                       if (!(this is ClassPart))
                        member_cache = new MemberCache (this);
 #endif
 
+                       if (parts != null) {
+                               foreach (ClassPart part in parts)
+                                       part.member_cache = member_cache;
+                       }
+
                        if (iterators != null) {
                                foreach (Iterator iterator in iterators) {
                                        if (iterator.DefineType () == null)
@@ -1333,12 +1491,13 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public override bool Define (TypeContainer container)
+               public override bool Define ()
                {
-                       if (interface_order != null){
-                               foreach (Interface iface in interface_order)
-                                       if ((iface.ModFlags & Modifiers.NEW) == 0)
-                                               iface.Define (this);
+                       if (parts != null) {
+                               foreach (ClassPart part in parts) {
+                                       if (!part.Define ())
+                                               return false;
+                               }
                        }
 
                        return true;
@@ -1754,7 +1913,7 @@ namespace Mono.CSharp {
                                if (interfaces != null) {
                                        int len = interfaces.Count;
                                        for (int i = 0; i < len; i++) {
-                                               Interface iface = (Interface) interfaces [i];
+                                               TypeContainer iface = (TypeContainer) interfaces [i];
 
                                                if ((iface.ModFlags & modflags) == 0)
                                                        continue;
@@ -1868,7 +2027,7 @@ namespace Mono.CSharp {
                {
                        if (constants != null)
                                foreach (Const con in constants)
-                                       con.Emit (this);
+                                       con.Emit ();
                        return;
                }
 
@@ -1919,19 +2078,19 @@ namespace Mono.CSharp {
                ///   Emits the code, this step is performed after all
                ///   the types, enumerations, constructors
                /// </summary>
-               public void Emit ()
+               public void EmitType ()
                {
                        if (OptAttributes != null)
                                OptAttributes.Emit (ec, this);
 
-                       Emit (this);
+                       Emit ();
 
                        if (instance_constructors != null) {
                                if (TypeBuilder.IsSubclassOf (TypeManager.attribute_type) && IsClsCompliaceRequired (this)) {
                                        bool has_compliant_args = false;
 
                                        foreach (Constructor c in instance_constructors) {
-                                               c.Emit (this);
+                                               c.Emit ();
 
                                                if (has_compliant_args)
                                                        continue;
@@ -1942,28 +2101,28 @@ namespace Mono.CSharp {
                                                Report.Error_T (3015, Location, GetSignatureForError ());
                                } else {
                                foreach (Constructor c in instance_constructors)
-                                       c.Emit (this);
+                                               c.Emit ();
                                }
                        }
 
                        if (default_static_constructor != null)
-                               default_static_constructor.Emit (this);
+                               default_static_constructor.Emit ();
                        
                        if (methods != null)
                                foreach (Method m in methods)
-                                       m.Emit (this);
+                                       m.Emit ();
 
                        if (operators != null)
                                foreach (Operator o in operators)
-                                       o.Emit (this);
+                                       o.Emit ();
 
                        if (properties != null)
                                foreach (Property p in properties)
-                                       p.Emit (this);
+                                       p.Emit ();
 
                        if (indexers != null){
                                foreach (Indexer ix in indexers)
-                                       ix.Emit (this);
+                                       ix.Emit ();
                                if (IndexerName != null) {
                                        CustomAttributeBuilder cb = EmitDefaultMemberAttr ();
                                        TypeBuilder.SetCustomAttribute (cb);
@@ -1972,26 +2131,31 @@ namespace Mono.CSharp {
                        
                        if (fields != null)
                                foreach (Field f in fields)
-                                       f.Emit (this);
+                                       f.Emit ();
 
                        if (events != null){
                                foreach (Event e in Events)
-                                       e.Emit (this);
+                                       e.Emit ();
                        }
 
                        if (delegates != null) {
                                foreach (Delegate d in Delegates) {
-                                       d.Emit (this);
+                                       d.Emit ();
                                }
                        }
 
                        if (enums != null) {
                                foreach (Enum e in enums) {
-                                       e.Emit (this);
+                                       e.Emit ();
                                }
                        }
 
-                       if (Pending != null)
+                       if (parts != null) {
+                               foreach (ClassPart part in parts)
+                                       part.EmitType ();
+                       }
+
+                       if ((Pending != null) && !(this is ClassPart))
                                if (Pending.VerifyPendingMethods ())
                                        return;
 
@@ -1999,7 +2163,7 @@ namespace Mono.CSharp {
 
                        if (iterators != null)
                                foreach (Iterator iterator in iterators)
-                                       iterator.Emit ();
+                                       iterator.EmitType ();
                        
 //                     if (types != null)
 //                             foreach (TypeContainer tc in types)
@@ -2054,18 +2218,13 @@ namespace Mono.CSharp {
                                foreach (Enum en in Enums)
                                        en.CloseType ();
 
-                       if (interface_order != null){
-                               foreach (Interface iface in interface_order)
-                                       iface.CloseType ();
-                       }
-                       
                        if (Types != null){
                                foreach (TypeContainer tc in Types)
-                                       if (tc is Struct)
+                                       if (tc.Kind == Kind.Struct)
                                                tc.CloseType ();
 
                                foreach (TypeContainer tc in Types)
-                                       if (!(tc is Struct))
+                                       if (tc.Kind != Kind.Struct)
                                                tc.CloseType ();
                        }
 
@@ -2086,7 +2245,6 @@ namespace Mono.CSharp {
                        initialized_static_fields = null;
                        constants = null;
                        interfaces = null;
-                       interface_order = null;
                        methods = null;
                        events = null;
                        indexers = null;
@@ -2157,7 +2315,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if (this is Struct){
+                       if (Kind == Kind.Struct){
                                if ((flags & va) != 0){
                                        Modifiers.Error_InvalidModifier (loc, "virtual or abstract");
                                        ok = false;
@@ -2245,7 +2403,8 @@ namespace Mono.CSharp {
                ///   checks whether the `interface_type' is a base inteface implementation.
                ///   Then it checks whether `name' exists in the interface type.
                /// </summary>
-               public bool VerifyImplements (Type interface_type, string full, string name, Location loc)
+               public virtual bool VerifyImplements (Type interface_type, string full,
+                                                     string name, Location loc)
                {
                        bool found = false;
 
@@ -2308,7 +2467,7 @@ namespace Mono.CSharp {
 
                bool IMemberContainer.IsInterface {
                        get {
-                               return this is Interface;
+                               return Kind == Kind.Interface;
                        }
                }
 
@@ -2497,14 +2656,196 @@ namespace Mono.CSharp {
                
        }
 
-       public class ClassOrStruct : TypeContainer {
+       public class PartialContainer : TypeContainer {
+
+               public readonly Namespace Namespace;
+               public readonly int OriginalModFlags;
+               public readonly int AllowedModifiers;
+               public readonly TypeAttributes DefaultTypeAttributes;
+
+               static PartialContainer Create (NamespaceEntry ns, TypeContainer parent,
+                                               MemberName name, int mod_flags, Kind kind,
+                                               Location loc)
+               {
+                       PartialContainer pc;
+                       DeclSpace ds = (DeclSpace) RootContext.Tree.Decls [name];
+                       if (ds != null) {
+                               pc = ds as PartialContainer;
+
+                               if (pc == null) {
+                                       Report.Error (
+                                               260, ds.Location, "Missing partial modifier " +
+                                               "on declaration of type `{0}'; another " +
+                                               "partial implementation of this type exists",
+                                               name);
+
+                                       Report.LocationOfPreviousError (loc);
+                                       return null;
+                               }
+
+                               if (pc.Kind != kind) {
+                                       Report.Error (
+                                               261, loc, "Partial declarations of `{0}' " +
+                                               "must be all classes, all structs or " +
+                                               "all interfaces", name);
+                                       return null;
+                               }
+
+                               if (pc.OriginalModFlags != mod_flags) {
+                                       Report.Error (
+                                               262, loc, "Partial declarations of `{0}' " +
+                                               "have conflicting accessibility modifiers",
+                                               name);
+                                       return null;
+                               }
+
+                               return pc;
+                       }
+
+                       pc = new PartialContainer (ns, parent, name, mod_flags, kind, loc);
+                       RootContext.Tree.RecordDecl (name.GetName (true), pc);
+                       parent.AddType (pc);
+                       pc.Register ();
+                       return pc;
+               }
+
+               public static ClassPart CreatePart (NamespaceEntry ns, TypeContainer parent,
+                                                   MemberName name, int mod, Attributes attrs,
+                                                   Kind kind, Location loc)
+               {
+                       PartialContainer pc = Create (ns, parent, name, mod, kind, loc);
+                       if (pc == null) {
+                               // An error occured; create a dummy container, but don't
+                               // register it.
+                               pc = new PartialContainer (ns, parent, name, mod, kind, loc);
+                       }
+
+                       ClassPart part = new ClassPart (ns, pc, mod, attrs, kind, loc);
+                       pc.AddPart (part);
+                       return part;
+               }
+
+               protected PartialContainer (NamespaceEntry ns, TypeContainer parent,
+                                           MemberName name, int mod, Kind kind, Location l)
+                       : base (ns, parent, name, null, kind, l)
+               {
+                       this.Namespace = ns.NS;
+
+                       switch (kind) {
+                       case Kind.Class:
+                               AllowedModifiers = Class.AllowedModifiers;
+                               DefaultTypeAttributes = Class.DefaultTypeAttributes;
+                               break;
+
+                       case Kind.Struct:
+                               AllowedModifiers = Struct.AllowedModifiers;
+                               DefaultTypeAttributes = Struct.DefaultTypeAttributes;
+                               break;
+
+                       case Kind.Interface:
+                               AllowedModifiers = Interface.AllowedModifiers;
+                               DefaultTypeAttributes = Interface.DefaultTypeAttributes;
+                               break;
+
+                       default:
+                               throw new InvalidOperationException ();
+                       }
+
+                       int accmods;
+                       if (parent.Parent == null)
+                               accmods = Modifiers.INTERNAL;
+                       else
+                               accmods = Modifiers.PRIVATE;
+
+                       this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
+                       this.OriginalModFlags = mod;
+               }
+
+               public override void Register ()
+               {
+                       if (Kind == Kind.Interface)
+                               Parent.AddInterface (this);
+                       else if (Kind == Kind.Class)
+                               Parent.AddClass (this);
+                       else if (Kind == Kind.Struct)
+                               Parent.AddStruct (this);
+                       else
+                               throw new InvalidOperationException ();
+               }
+
+               public override PendingImplementation GetPendingImplementations ()
+               {
+                       return PendingImplementation.GetPendingImplementations (this);
+               }
+
+               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;
+                       }
+               }
+       }
+
+       public class ClassPart : TypeContainer {
+               public readonly PartialContainer PartialContainer;
+               public readonly bool IsPartial;
+
+               public ClassPart (NamespaceEntry ns, PartialContainer parent,
+                                 int mod, Attributes attrs, Kind kind, Location l)
+                       : base (ns, parent.Parent, parent.MemberName, attrs, kind, l)
+               {
+                       this.PartialContainer = parent;
+                       this.IsPartial = true;
+
+                       int accmods;
+                       if (parent.Parent == null)
+                               accmods = Modifiers.INTERNAL;
+                       else
+                               accmods = Modifiers.PRIVATE;
+
+                       this.ModFlags = Modifiers.Check (
+                               parent.AllowedModifiers, mod, accmods, l);
+               }
+
+               public override void Register ()
+               {
+               }
+
+               public override PendingImplementation GetPendingImplementations ()
+               {
+                       return PartialContainer.Pending;
+               }
+
+               public override bool VerifyImplements (Type interface_type, string full,
+                                                      string name, Location loc)
+               {
+                       return PartialContainer.VerifyImplements (
+                               interface_type, full, name, loc);
+               }
+       }
+
+       public abstract class ClassOrStruct : TypeContainer {
                bool hasExplicitLayout = false;
-               public ClassOrStruct (NamespaceEntry ns, TypeContainer parent, MemberName name,
-                                     Attributes attrs, Location l)
-                       : base (ns, parent, name, attrs, l)
+
+               public ClassOrStruct (NamespaceEntry ns, TypeContainer parent,
+                                     MemberName name, Attributes attrs, Kind kind,
+                                     Location l)
+                       : base (ns, parent, name, attrs, kind, l)
                {
                }
 
+               public override PendingImplementation GetPendingImplementations ()
+               {
+                       return PendingImplementation.GetPendingImplementations (this);
+               }
+
                protected override void VerifyMembers (EmitContext ec) 
                {
                        if (Fields != null) {
@@ -2562,7 +2903,7 @@ namespace Mono.CSharp {
 
                public Class (NamespaceEntry ns, TypeContainer parent, MemberName name,
                              int mod, Attributes attrs, Location l)
-                       : base (ns, parent, name, attrs, l)
+                       : base (ns, parent, name, attrs, Kind.Class, l)
                {
                        int accmods;
 
@@ -2595,13 +2936,21 @@ namespace Mono.CSharp {
                        }
                }
 
+               public override void Register ()
+               {
+                       CheckDef (Parent.AddClass (this), Name, Location);
+               }
+
+               public const TypeAttributes DefaultTypeAttributes =
+                       TypeAttributes.AutoLayout | TypeAttributes.Class;
+
                //
                // FIXME: How do we deal with the user specifying a different
                // layout?
                //
                public override TypeAttributes TypeAttr {
                        get {
-                               return base.TypeAttr | TypeAttributes.AutoLayout | TypeAttributes.Class;
+                               return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
        }
@@ -2620,7 +2969,7 @@ namespace Mono.CSharp {
 
                public Struct (NamespaceEntry ns, TypeContainer parent, MemberName name,
                               int mod, Attributes attrs, Location l)
-                       : base (ns, parent, name, attrs, l)
+                       : base (ns, parent, name, attrs, Kind.Struct, l)
                {
                        int accmods;
                        
@@ -2640,6 +2989,15 @@ namespace Mono.CSharp {
                        }
                }
 
+               public override void Register ()
+               {
+                       CheckDef (Parent.AddStruct (this), Name, Location);
+               }
+
+               public const TypeAttributes DefaultTypeAttributes =
+                       TypeAttributes.SequentialLayout |
+                       TypeAttributes.Sealed |
+                       TypeAttributes.BeforeFieldInit;
 
                //
                // FIXME: Allow the user to specify a different set of attributes
@@ -2648,10 +3006,7 @@ namespace Mono.CSharp {
                //
                public override TypeAttributes TypeAttr {
                        get {
-                               return base.TypeAttr |
-                                       TypeAttributes.SequentialLayout |
-                                       TypeAttributes.Sealed |
-                                       TypeAttributes.BeforeFieldInit;
+                               return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
        }
@@ -2673,7 +3028,7 @@ namespace Mono.CSharp {
 
                public Interface (NamespaceEntry ns, TypeContainer parent, MemberName name,
                                  int mod, Attributes attrs, Location l)
-                       : base (ns, parent, name, attrs, l)
+                       : base (ns, parent, name, attrs, Kind.Interface, l)
                {
                        int accmods;
 
@@ -2685,18 +3040,30 @@ namespace Mono.CSharp {
                        this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
                }
 
+               public override void Register ()
+               {
+                       CheckDef (Parent.AddInterface (this), Name, Location);
+               }
+
+               public override PendingImplementation GetPendingImplementations ()
+               {
+                       return null;
+               }
+
                public override AttributeTargets AttributeTargets {
                        get {
                                return AttributeTargets.Interface;
                        }
                }
 
-               public override TypeAttributes TypeAttr {
-                       get {
-                               return base.TypeAttr |
+               public const TypeAttributes DefaultTypeAttributes =
                                        TypeAttributes.AutoLayout |
                                        TypeAttributes.Abstract |
                                        TypeAttributes.Interface;
+
+               public override TypeAttributes TypeAttr {
+                       get {
+                               return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
        }
@@ -2704,8 +3071,8 @@ namespace Mono.CSharp {
        public abstract class MethodCore : MemberBase {
                public readonly Parameters Parameters;
                public readonly GenericMethod GenericMethod;
+               public readonly DeclSpace ds;
                protected Block block;
-               public DeclSpace ds;
                
                //
                // Parameters, cached for semantic analysis.
@@ -2723,15 +3090,21 @@ namespace Mono.CSharp {
 
                static string[] attribute_targets = new string [] { "method", "return" };
 
-               public MethodCore (DeclSpace ds, Expression type, int mod, int allowed_mod,
-                                  bool is_interface, MemberName name, Attributes attrs,
-                                  Parameters parameters, Location loc)
-                       : base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
+               public MethodCore (TypeContainer parent, GenericMethod generic,
+                                  Expression type, int mod, int allowed_mod, bool is_iface,
+                                  MemberName name, Attributes attrs, Parameters parameters,
+                                  Location loc)
+                       : base (parent, type, mod, allowed_mod, Modifiers.PRIVATE, name,
+                               attrs, loc)
                {
                        Parameters = parameters;
-                       IsInterface = is_interface;
-                       this.ds = ds;
-                       this.GenericMethod = ds as GenericMethod;
+                       IsInterface = is_iface;
+                       this.GenericMethod = generic;
+
+                       if (generic != null)
+                               ds = generic;
+                       else
+                               ds = parent;
                }
                
                //
@@ -2764,7 +3137,8 @@ namespace Mono.CSharp {
                {
                        // Check if arguments were correct
                        parameter_types = Parameters.GetParameterInfo (ds);
-                       if ((parameter_types == null) || !CheckParameters (ds, parameter_types))
+                       if ((parameter_types == null) ||
+                           !CheckParameters (ds, parameter_types))
                                return false;
 
                        parameter_info = new InternalParameters (ds, Parameters);
@@ -3004,10 +3378,11 @@ namespace Mono.CSharp {
                //
                // return_type can be "null" for VOID values.
                //
-               public Method (DeclSpace ds, Expression return_type, int mod, bool is_iface,
+               public Method (TypeContainer parent, GenericMethod generic,
+                              Expression return_type, int mod, bool is_iface,
                               MemberName name, Parameters parameters, Attributes attrs,
                               Location l)
-                       : base (ds, return_type, mod,
+                       : base (parent, generic, return_type, mod,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
                                is_iface, name, attrs, parameters, l)
                {
@@ -3155,9 +3530,9 @@ namespace Mono.CSharp {
                //
                // Checks our base implementation if any
                //
-               protected override bool CheckBase (TypeContainer container)
+               protected override bool CheckBase ()
                {
-                       base.CheckBase (container);
+                       base.CheckBase ();
                        
                        // Check whether arguments were correct.
                        if (!DoDefineParameters ())
@@ -3170,13 +3545,13 @@ namespace Mono.CSharp {
                                //
                                // Check in our class for dups
                                //
-                               ArrayList ar = container.Methods;
+                               ArrayList ar = Parent.Methods;
                                if (ar != null) {
                                        int arLen = ar.Count;
 
                                        for (int i = 0; i < arLen; i++) {
                                                Method m = (Method) ar [i];
-                                               if (IsDuplicateImplementation (container, m))
+                                               if (IsDuplicateImplementation (Parent, m))
                                                        return false;
                                        }
                                }
@@ -3187,7 +3562,7 @@ namespace Mono.CSharp {
                        // Verify if the parent has a type with the same name, and then
                        // check whether we have to create a new slot for it or not.
                        //
-                       Type ptype = container.TypeBuilder.BaseType;
+                       Type ptype = Parent.TypeBuilder.BaseType;
 
                        // ptype is only null for System.Object while compiling corlib.
                        if (ptype != null) {
@@ -3198,15 +3573,15 @@ namespace Mono.CSharp {
                                // an incorrect warning in corlib.
                                //
                                if (! IsExplicitImpl) {
-                                       parent_method = (MethodInfo)((IMemberContainer)container).Parent.MemberCache.FindMemberToOverride (
-                                               container.TypeBuilder, Name, ParameterTypes, false);
+                                       parent_method = (MethodInfo)((IMemberContainer)Parent).Parent.MemberCache.FindMemberToOverride (
+                                               Parent.TypeBuilder, Name, ParameterTypes, false);
                                }
                                
                                if (parent_method != null) {
                                        string name = parent_method.DeclaringType.Name + "." +
                                                parent_method.Name;
 
-                                       if (!CheckMethodAgainstBase (container, flags, parent_method, name))
+                                       if (!CheckMethodAgainstBase (Parent, flags, parent_method, name))
                                                return false;
 
                                        if ((ModFlags & Modifiers.NEW) == 0) {
@@ -3215,7 +3590,7 @@ namespace Mono.CSharp {
 
                                                if (!parent_ret.Equals (MemberType)) {
                                                        Report.Error (
-                                                               508, Location, container.MakeName (Name) + ": cannot " +
+                                                               508, Location, Parent.MakeName (Name) + ": cannot " +
                                                                "change return type when overriding " +
                                                                "inherited member " + name);
                                                        return false;
@@ -3225,20 +3600,20 @@ namespace Mono.CSharp {
                                        ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (parent_method);
                                        if (oa != null) {
                                                Report.SymbolRelatedToPreviousError (parent_method);
-                                               Report.Warning_T (672, Location, GetSignatureForError (container));
+                                               Report.Warning_T (672, Location, GetSignatureForError (Parent));
                                        }
                                } else {
                                        if (!OverridesSomething && ((ModFlags & Modifiers.NEW) != 0))
-                                               WarningNotHiding (container);
+                                               WarningNotHiding (Parent);
 
                                        if ((ModFlags & Modifiers.OVERRIDE) != 0){
                                                Report.Error (115, Location,
-                                                             container.MakeName (Name) +
+                                                             Parent.MakeName (Name) +
                                                              " no suitable methods found to override");
                                        }
                                }
                        } else if ((ModFlags & Modifiers.NEW) != 0)
-                               WarningNotHiding (container);
+                               WarningNotHiding (Parent);
 
                        return true;
                }
@@ -3246,31 +3621,28 @@ namespace Mono.CSharp {
                //
                // Creates the type
                //
-               public override bool Define (TypeContainer container)
+               public override bool Define ()
                {
-                       if (!DoDefineBase (container))
+                       if (!DoDefineBase ())
                                return false;
 
-                       DeclSpace decl;
                        MethodBuilder mb = null;
                        if (GenericMethod != null) {
-                               mb = container.TypeBuilder.DefineGenericMethod (Name, flags);
-                               if (!GenericMethod.Define (container, mb))
+                               mb = Parent.TypeBuilder.DefineGenericMethod (Name, flags);
+                               if (!GenericMethod.Define (mb))
                                        return false;
-                               decl = GenericMethod;
-                       } else
-                               decl = container;
+                       }
 
-                       if (!DoDefine (decl, container))
+                       if (!DoDefine (ds))
                                return false;
 
-                       if (!CheckBase (container))
+                       if (!CheckBase ())
                                return false;
 
                        MethodData = new MethodData (this, ParameterInfo, ModFlags, flags,
                                                     this, mb, GenericMethod);
 
-                       if (!MethodData.Define (container))
+                       if (!MethodData.Define (Parent))
                                return false;
 
                        //
@@ -3278,10 +3650,10 @@ namespace Mono.CSharp {
                        //
                        if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
                                Iterator iterator = new Iterator (
-                                       container, Name, MemberType, ParameterTypes,
+                                       Parent, Name, MemberType, ParameterTypes,
                                        ParameterInfo, ModFlags, block, Location);
 
-                               if (!iterator.Define ())
+                               if (!iterator.DefineIterator ())
                                        return false;
 
                                block = iterator.Block;
@@ -3295,10 +3667,10 @@ namespace Mono.CSharp {
                        if (Name == "Main" &&
                            ((ModFlags & Modifiers.STATIC) != 0) && RootContext.NeedsEntryPoint && 
                            (RootContext.MainClass == null ||
-                            RootContext.MainClass == container.TypeBuilder.FullName)){
+                            RootContext.MainClass == Parent.TypeBuilder.FullName)){
                                 if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
                                         if (RootContext.EntryPoint == null) {
-                                               if (container.IsGeneric){
+                                               if (Parent.IsGeneric){
                                                        Report.Error (-201, Location,
                                                                      "Entry point can not be defined in a generic class");
                                                }
@@ -3319,10 +3691,10 @@ namespace Mono.CSharp {
                //
                // Emits the code
                // 
-               public override void Emit (TypeContainer container)
+               public override void Emit ()
                {
-                       MethodData.Emit (container, this);
-                       base.Emit (container);
+                       MethodData.Emit (Parent, this);
+                       base.Emit ();
                        Block = null;
                        MethodData = null;
                }
@@ -3375,7 +3747,8 @@ namespace Mono.CSharp {
 
                public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
                {
-                       return new EmitContext (tc, ds, Location, ig, ReturnType, ModFlags, false);
+                       return new EmitContext (
+                               tc, ds, Location, ig, ReturnType, ModFlags, false);
                }
 
                public ObsoleteAttribute GetObsoleteAttribute ()
@@ -3649,9 +4022,9 @@ namespace Mono.CSharp {
                // The spec claims that static is not permitted, but
                // my very own code has static constructors.
                //
-               public Constructor (DeclSpace ds, string name, int mod, Parameters args,
+               public Constructor (TypeContainer ds, string name, int mod, Parameters args,
                                    ConstructorInitializer init, Location l)
-                       : base (ds, null, mod, AllowedModifiers, false,
+                       : base (ds, null, null, mod, AllowedModifiers, false,
                                new MemberName (name), null, args, l)
                {
                        Initializer = init;
@@ -3696,9 +4069,9 @@ namespace Mono.CSharp {
                        ConstructorBuilder.SetCustomAttribute (cb);
                }
 
-               protected override bool CheckBase (TypeContainer container)
+               protected override bool CheckBase ()
                {
-                       base.CheckBase (container);
+                       base.CheckBase ();
                        
                        // Check whether arguments were correct.
                        if (!DoDefineParameters ())
@@ -3707,7 +4080,7 @@ namespace Mono.CSharp {
                        if ((ModFlags & Modifiers.STATIC) != 0)
                                return true;
                        
-                       if (container is Struct && ParameterTypes.Length == 0) {
+                       if (Parent.Kind == Kind.Struct && ParameterTypes.Length == 0) {
                                Report.Error (568, Location, 
                                        "Structs can not contain explicit parameterless " +
                                        "constructors");
@@ -3717,13 +4090,13 @@ namespace Mono.CSharp {
                        //
                        // Check in our class for dups
                        //
-                       ArrayList ar = container.InstanceConstructors;
+                       ArrayList ar = Parent.InstanceConstructors;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
                                for (int i = 0; i < arLen; i++) {
                                        Constructor m = (Constructor) ar [i];
-                                       if (IsDuplicateImplementation (container, m))
+                                       if (IsDuplicateImplementation (Parent, m))
                                                return false;
                                }
                        }
@@ -3734,7 +4107,7 @@ namespace Mono.CSharp {
                //
                // Creates the ConstructorBuilder
                //
-               public override bool Define (TypeContainer container)
+               public override bool Define ()
                {
                        MethodAttributes ca = (MethodAttributes.RTSpecialName |
                                               MethodAttributes.SpecialName);
@@ -3760,11 +4133,12 @@ namespace Mono.CSharp {
                        }
 
                        // Check if arguments were correct.
-                       if (!CheckBase (container))
+                       if (!CheckBase ())
                                return false;
 
-                       ConstructorBuilder = container.TypeBuilder.DefineConstructor (
-                               ca, GetCallingConvention (container is Class), ParameterTypes);
+                       ConstructorBuilder = Parent.TypeBuilder.DefineConstructor (
+                               ca, GetCallingConvention (Parent.Kind == Kind.Class),
+                               ParameterTypes);
 
                        if ((ModFlags & Modifiers.UNSAFE) != 0)
                                ConstructorBuilder.InitLocals = false;
@@ -3780,10 +4154,10 @@ namespace Mono.CSharp {
                //
                // Emits the code
                //
-               public override void Emit (TypeContainer container)
+               public override void Emit ()
                {
                        ILGenerator ig = ConstructorBuilder.GetILGenerator ();
-                       EmitContext ec = new EmitContext (container, Location, ig, null, ModFlags, true);
+                       EmitContext ec = new EmitContext (Parent, Location, ig, null, ModFlags, true);
 
                        //
                        // extern methods have no bodies
@@ -3805,7 +4179,7 @@ namespace Mono.CSharp {
                        }
 
                        if ((ModFlags & Modifiers.STATIC) == 0){
-                               if (container is Class && Initializer == null)
+                               if (Parent.Kind == Kind.Class && Initializer == null)
                                        Initializer = new ConstructorBaseInitializer (
                                                null, Parameters.EmptyReadOnlyParameters, Location);
 
@@ -3829,7 +4203,7 @@ namespace Mono.CSharp {
                                !Location.IsNull (Location) &&
                                !Location.IsNull (block.EndLocation) &&
                                (Location.SymbolDocument != null)) {
-                               sw.OpenMethod (container, ConstructorBuilder, Location, block.EndLocation);
+                               sw.OpenMethod (Parent, ConstructorBuilder, Location, block.EndLocation);
 
                                generate_debugging = true;
                        }
@@ -3837,7 +4211,7 @@ namespace Mono.CSharp {
                        //
                        // Classes can have base initializers and instance field initializers.
                        //
-                       if (container is Class){
+                       if (Parent.Kind == Kind.Class){
                                if ((ModFlags & Modifiers.STATIC) == 0){
 
                                        //
@@ -3845,31 +4219,32 @@ namespace Mono.CSharp {
                                        // do not emit field initializers, they are initialized in the other constructor
                                        //
                                        if (!(Initializer != null && Initializer is ConstructorThisInitializer))
-                                               container.EmitFieldInitializers (ec);
+                                               Parent.EmitFieldInitializers (ec);
                                }
                        }
                        if (Initializer != null) {
-                               Initializer.CheckObsoleteAttribute (container, Location);
+                               Initializer.CheckObsoleteAttribute (Parent, Location);
                                Initializer.Emit (ec);
                        }
                        
                        if ((ModFlags & Modifiers.STATIC) != 0)
-                               container.EmitFieldInitializers (ec);
+                               Parent.EmitFieldInitializers (ec);
 
                        if (OptAttributes != null) 
                                OptAttributes.Emit (ec, this);
 
                        // If this is a non-static `struct' constructor and doesn't have any
                        // initializer, it must initialize all of the struct's fields.
-                       if ((container is Struct) && ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
-                               Block.AddThisVariable (container, Location);
+                       if ((Parent.Kind == Kind.Struct) &&
+                           ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
+                               Block.AddThisVariable (Parent, Location);
 
                        ec.EmitTopBlock (block, ParameterInfo, Location);
 
                        if (generate_debugging)
                                sw.CloseMethod ();
 
-                       base.Emit (container);
+                       base.Emit ();
 
                        block = null;
                }
@@ -4349,9 +4724,9 @@ namespace Mono.CSharp {
 
        public class Destructor : Method {
 
-               public Destructor (DeclSpace ds, Expression return_type, int mod, string name,
+               public Destructor (TypeContainer ds, Expression return_type, int mod, string name,
                                   Parameters parameters, Attributes attrs, Location l)
-                       : base (ds, return_type, mod, false, new MemberName (name),
+                       : base (ds, null, return_type, mod, false, new MemberName (name),
                                parameters, attrs, l)
                { }
 
@@ -4418,24 +4793,25 @@ namespace Mono.CSharp {
                //
                // The constructor is only exposed to our children
                //
-               protected MemberBase (Expression type, int mod, int allowed_mod, int def_mod,
-                                     MemberName name, Attributes attrs, Location loc)
-                       : base (name, attrs, loc)
+               protected MemberBase (TypeContainer parent, Expression type, int mod,
+                                     int allowed_mod, int def_mod, MemberName name,
+                                     Attributes attrs, Location loc)
+                       : base (parent, name, attrs, loc)
                {
                        explicit_mod_flags = mod;
                        Type = type;
                        ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, loc);
                }
 
-               protected virtual bool CheckBase (TypeContainer container)
+               protected virtual bool CheckBase ()
                {
-                       if ((container is Struct) || (RootContext.WarningLevel > 3)){
-                               if ((ModFlags & Modifiers.PROTECTED) != 0 && (container.ModFlags & Modifiers.SEALED) != 0){
-                                       if (container is Struct){
+                       if ((Parent.Kind == Kind.Struct) || (RootContext.WarningLevel > 3)){
+                               if ((ModFlags & Modifiers.PROTECTED) != 0 && (Parent.ModFlags & Modifiers.SEALED) != 0){
+                                       if (Parent.Kind == Kind.Struct){
                                                Report.Error (666, Location, "Protected member in struct declaration");
                                                return false;
                                        } else
-                                               Report.Warning (628, Location, "Member " + container.MakeName (Name) + " protected in sealed class");
+                                               Report.Warning (628, Location, "Member " + Parent.MakeName (Name) + " protected in sealed class");
                                }
                        }
                        return true;
@@ -4642,7 +5018,7 @@ namespace Mono.CSharp {
                        return !error;
                }
 
-               protected virtual bool DoDefineBase (TypeContainer container)
+               protected virtual bool DoDefineBase ()
                {
                        if (Name == null)
                                Name = "this";
@@ -4658,7 +5034,7 @@ namespace Mono.CSharp {
                                        MethodAttributes.NewSlot |
                                        MethodAttributes.Virtual;
                        } else {
-                               if (!container.MethodModifiersValid (ModFlags, Name, Location))
+                               if (!Parent.MethodModifiersValid (ModFlags, Name, Location))
                                        return false;
 
                                flags = Modifiers.MethodAttr (ModFlags);
@@ -4667,14 +5043,14 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               protected virtual bool DoDefine (DeclSpace decl, TypeContainer container)
+               protected virtual bool DoDefine (DeclSpace decl)
                {
                        // Lookup Type, verify validity
                        MemberType = decl.ResolveType (Type, false, Location);
                        if (MemberType == null)
                                return false;
 
-                       if ((container.ModFlags & Modifiers.SEALED) != 0){
+                       if ((Parent.ModFlags & Modifiers.SEALED) != 0){
                                if ((ModFlags & (Modifiers.VIRTUAL|Modifiers.ABSTRACT)) != 0){
                                        Report.Error (549, Location, "Virtual method can not be contained in sealed class");
                                        return false;
@@ -4682,7 +5058,7 @@ namespace Mono.CSharp {
                        }
                        
                        // verify accessibility
-                       if (!container.AsAccessible (MemberType, ModFlags)) {
+                       if (!Parent.AsAccessible (MemberType, ModFlags)) {
                                if (this is Property)
                                        Report.Error (53, Location,
                                                      "Inconsistent accessibility: property type `" +
@@ -4712,7 +5088,7 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (MemberType.IsPointer && !UnsafeOK (container))
+                       if (MemberType.IsPointer && !UnsafeOK (Parent))
                                return false;
 
                        //
@@ -4725,7 +5101,7 @@ namespace Mono.CSharp {
                                ShortName = Name;
 
                        if (ExplicitInterfaceName != null) {
-                               InterfaceType = container.ResolveType (
+                               InterfaceType = Parent.ResolveType (
                                        ExplicitInterfaceName, false, Location);
                                if (InterfaceType == null)
                                        return false;
@@ -4738,7 +5114,7 @@ namespace Mono.CSharp {
                                // Compute the full name that we need to export.
                                Name = InterfaceType.FullName + "." + ShortName;
                                
-                               if (!container.VerifyImplements (InterfaceType, ShortName, Name, Location))
+                               if (!Parent.VerifyImplements (InterfaceType, ShortName, Name, Location))
                                        return false;
                                
                                Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
@@ -4797,9 +5173,11 @@ namespace Mono.CSharp {
                //
                // The constructor is only exposed to our children
                //
-               protected FieldBase (Expression type, int mod, int allowed_mod, MemberName name,
-                                    object init, Attributes attrs, Location loc)
-                       : base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
+               protected FieldBase (TypeContainer parent, Expression type, int mod,
+                                    int allowed_mod, MemberName name, object init,
+                                    Attributes attrs, Location loc)
+                       : base (parent, type, mod, allowed_mod, Modifiers.PRIVATE,
+                               name, attrs, loc)
                {
                        this.init = init;
                }
@@ -4869,9 +5247,9 @@ namespace Mono.CSharp {
                        return init_expr;
                }
 
-               protected override bool DoDefine (DeclSpace ds, TypeContainer container)
+               protected override bool DoDefine (DeclSpace ds)
                {
-                       if (!base.DoDefine (ds, container))
+                       if (!base.DoDefine (ds))
                                return false;
 
                        if (MemberType == TypeManager.void_type) {
@@ -4940,23 +5318,23 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE |
                        Modifiers.READONLY;
 
-               public Field (Expression type, int mod, string name, Object expr_or_array_init,
-                             Attributes attrs, Location loc)
-                       : base (type, mod, AllowedModifiers, new MemberName (name),
+               public Field (TypeContainer parent, Expression type, int mod, string name,
+                             Object expr_or_array_init, Attributes attrs, Location loc)
+                       : base (parent, type, mod, AllowedModifiers, new MemberName (name),
                                expr_or_array_init, attrs, loc)
                {
                }
 
-               public override bool Define (TypeContainer container)
+               public override bool Define ()
                {
-                       MemberType = container.ResolveType (Type, false, Location);
+                       MemberType = Parent.ResolveType (Type, false, Location);
                        
                        if (MemberType == null)
                                return false;
 
-                       CheckBase (container);
+                       CheckBase ();
                        
-                       if (!container.AsAccessible (MemberType, ModFlags)) {
+                       if (!Parent.AsAccessible (MemberType, ModFlags)) {
                                Report.Error (52, Location,
                                              "Inconsistent accessibility: field type `" +
                                              TypeManager.CSharpName (MemberType) + "' is less " +
@@ -4964,11 +5342,11 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (MemberType.IsPointer && !UnsafeOK (container))
+                       if (MemberType.IsPointer && !UnsafeOK (Parent))
                                return false;
                        
                        if (RootContext.WarningLevel > 1){
-                               Type ptype = container.TypeBuilder.BaseType;
+                               Type ptype = Parent.TypeBuilder.BaseType;
 
                                // ptype is only null for System.Object while compiling corlib.
                                if (ptype != null){
@@ -4998,7 +5376,7 @@ namespace Mono.CSharp {
                                              (vt == TypeManager.float_type) ||
                                              (!vt.IsValueType))){
                                                Report.Error (
-                                                       677, Location, container.MakeName (Name) +
+                                                       677, Location, Parent.MakeName (Name) +
                                                        " A volatile field can not be of type `" +
                                                        TypeManager.CSharpName (vt) + "'");
                                                return false;
@@ -5015,17 +5393,17 @@ namespace Mono.CSharp {
 
                        FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
 
-                       if (container is Struct && 
+                       if (Parent.Kind == Kind.Struct && 
                            ((fa & FieldAttributes.Static) == 0) &&
-                           MemberType == container.TypeBuilder &&
+                           MemberType == Parent.TypeBuilder &&
                            !TypeManager.IsBuiltinType (MemberType)){
-                               Report.Error (523, Location, "Struct member `" + container.Name + "." + Name + 
+                               Report.Error (523, Location, "Struct member `" + Parent.Name + "." + Name + 
                                              "' causes a cycle in the structure layout");
                                return false;
                        }
 
                        try {
-                       FieldBuilder = container.TypeBuilder.DefineField (
+                               FieldBuilder = Parent.TypeBuilder.DefineField (
                                        Name, MemberType, Modifiers.FieldAttr (ModFlags));
 
                        TypeManager.RegisterFieldBase (FieldBuilder, this);
@@ -5038,14 +5416,16 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public override void Emit (TypeContainer tc)
+               public override void Emit ()
                {
                        if (OptAttributes != null) {
-                               EmitContext ec = new EmitContext (tc, Location, null, FieldBuilder.FieldType, ModFlags);
+                               EmitContext ec = new EmitContext (
+                                       Parent, Location, null, FieldBuilder.FieldType,
+                                       ModFlags);
                                OptAttributes.Emit (ec, this);
                }
 
-                       base.Emit (tc);
+                       base.Emit ();
                }
        }
 
@@ -5327,9 +5707,12 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       public override EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
+                       public override EmitContext CreateEmitContext (TypeContainer tc,
+                                                                      ILGenerator ig)
                        {
-                               return new EmitContext (tc, method.ds, method.Location, ig, ReturnType, method.ModFlags, false);
+                               return new EmitContext (
+                                       tc, method.ds, method.Location, ig, ReturnType,
+                                       method.ModFlags, false);
                        }
 
                        public override ObsoleteAttribute GetObsoleteAttribute ()
@@ -5349,11 +5732,11 @@ namespace Mono.CSharp {
 
                protected EmitContext ec;
 
-               public PropertyBase (DeclSpace ds, Expression type, int mod_flags,
+               public PropertyBase (TypeContainer parent, Expression type, int mod_flags,
                                     int allowed_mod, bool is_iface, MemberName name,
                                     Parameters parameters, Attributes attrs,
                                     Location loc)
-                       : base (ds, type, mod_flags, allowed_mod, is_iface, name,
+                       : base (parent, null, type, mod_flags, allowed_mod, is_iface, name,
                                attrs, parameters, loc)
                {
                }
@@ -5369,9 +5752,9 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected override bool DoDefine (DeclSpace decl, TypeContainer container)
+               protected override bool DoDefine (DeclSpace decl)
                {
-                       if (!base.DoDefine (decl, container))
+                       if (!base.DoDefine (decl))
                                return false;
 
                        if (MemberType == TypeManager.arg_iterator_type || MemberType == TypeManager.typed_reference_type) {
@@ -5380,7 +5763,7 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       ec = new EmitContext (container, Location, null, MemberType, ModFlags);
+                       ec = new EmitContext (Parent, Location, null, MemberType, ModFlags);
 
                        return true;
                }
@@ -5414,9 +5797,9 @@ namespace Mono.CSharp {
                //
                // Checks our base implementation if any
                //
-               protected override bool CheckBase (TypeContainer container)
+               protected override bool CheckBase ()
                {
-                       base.CheckBase (container);
+                       base.CheckBase ();
                        
                        // Check whether arguments were correct.
                        if (!DoDefineParameters ())
@@ -5428,13 +5811,13 @@ namespace Mono.CSharp {
                        //
                        // Check in our class for dups
                        //
-                       ArrayList ar = container.Properties;
+                       ArrayList ar = Parent.Properties;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
                                for (int i = 0; i < arLen; i++) {
                                        Property m = (Property) ar [i];
-                                       if (IsDuplicateImplementation (container, m))
+                                       if (IsDuplicateImplementation (Parent, m))
                                                return false;
                                }
                        }
@@ -5448,9 +5831,9 @@ namespace Mono.CSharp {
                                string name, base_name;
 
                                report_name = "this";
-                               name = TypeManager.IndexerPropertyName (container.TypeBuilder);
+                               name = TypeManager.IndexerPropertyName (Parent.TypeBuilder);
                                ms = new MethodSignature (name, null, ParameterTypes);
-                               base_name = TypeManager.IndexerPropertyName (container.TypeBuilder.BaseType);
+                               base_name = TypeManager.IndexerPropertyName (Parent.TypeBuilder.BaseType);
                                base_ms = new MethodSignature (base_name, null, ParameterTypes);
                        } else {
                                report_name = Name;
@@ -5461,12 +5844,12 @@ namespace Mono.CSharp {
                        // Verify if the parent has a type with the same name, and then
                        // check whether we have to create a new slot for it or not.
                        //
-                       Type ptype = container.TypeBuilder.BaseType;
+                       Type ptype = Parent.TypeBuilder.BaseType;
 
                        // ptype is only null for System.Object while compiling corlib.
                        if (ptype == null) {
                                if ((ModFlags & Modifiers.NEW) != 0)
-                                       WarningNotHiding (container);
+                                       WarningNotHiding (Parent);
 
                                return true;
                        }
@@ -5479,8 +5862,8 @@ namespace Mono.CSharp {
                        // an incorrect warning in corlib.
                        //
                        if (! IsExplicitImpl) {
-                               parent_member = ((IMemberContainer)container).Parent.MemberCache.FindMemberToOverride (
-                                       container.TypeBuilder, Name, ParameterTypes, true);
+                               parent_member = ((IMemberContainer)Parent).Parent.MemberCache.FindMemberToOverride (
+                                       Parent.TypeBuilder, Name, ParameterTypes, true);
                        }
 
                        if (parent_member is PropertyInfo) {
@@ -5500,7 +5883,7 @@ namespace Mono.CSharp {
                                else
                                        throw new Exception ("Internal error!");
 
-                               if (!CheckMethodAgainstBase (container, flags, parent_method, name))
+                               if (!CheckMethodAgainstBase (Parent, flags, parent_method, name))
                                        return false;
 
                                if ((ModFlags & Modifiers.NEW) == 0) {
@@ -5509,7 +5892,7 @@ namespace Mono.CSharp {
 
                                        if (parent_type != MemberType) {
                                                Report.Error (
-                                                       508, Location, container.MakeName (Name) + ": cannot " +
+                                                       508, Location, Parent.MakeName (Name) + ": cannot " +
                                                        "change return type when overriding " +
                                                        "inherited member " + name);
                                                return false;
@@ -5517,16 +5900,16 @@ namespace Mono.CSharp {
                                }
                        } else if (parent_member == null){
                                if ((ModFlags & Modifiers.NEW) != 0)
-                                       WarningNotHiding (container);
+                                       WarningNotHiding (Parent);
 
                                if ((ModFlags & Modifiers.OVERRIDE) != 0){
                                        if (this is Indexer)
                                                Report.Error (115, Location,
-                                                             container.MakeName (Name) +
+                                                             Parent.MakeName (Name) +
                                                              " no suitable indexers found to override");
                                        else
                                                Report.Error (115, Location,
-                                                             container.MakeName (Name) +
+                                                             Parent.MakeName (Name) +
                                                              " no suitable properties found to override");
                                        return false;
                                }
@@ -5534,7 +5917,7 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public override void Emit (TypeContainer tc)
+               public override void Emit ()
                {
                        //
                        // The PropertyBuilder can be null for explicit implementations, in that
@@ -5545,12 +5928,12 @@ namespace Mono.CSharp {
                                OptAttributes.Emit (ec, this);
 
                        if (Get != null)
-                               Get.Emit (tc);
+                               Get.Emit (Parent);
 
                        if (Set != null)
-                               Set.Emit (tc);
+                               Set.Emit (Parent);
 
-                       base.Emit (tc);
+                       base.Emit ();
                }
 
                protected override string[] ValidAttributeTargets {
@@ -5579,10 +5962,10 @@ namespace Mono.CSharp {
                const int AllowedInterfaceModifiers =
                        Modifiers.NEW;
 
-               public Property (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
-                                MemberName name, Attributes attrs, Accessor get_block,
-                                Accessor set_block, Location loc)
-                       : base (ds, type, mod_flags,
+               public Property (TypeContainer parent, Expression type, int mod_flags,
+                                bool is_iface, MemberName name, Attributes attrs,
+                                Accessor get_block, Accessor set_block, Location loc)
+                       : base (parent, type, mod_flags,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
                                is_iface, name, Parameters.EmptyReadOnlyParameters, attrs,
                                loc)
@@ -5594,22 +5977,22 @@ namespace Mono.CSharp {
                                Set = new SetMethod (this, set_block);
                }
 
-               public override bool Define (TypeContainer container)
+               public override bool Define ()
                {
-                       if (!DoDefineBase (container))
+                       if (!DoDefineBase ())
                                return false;
 
-                       if (!DoDefine (container, container))
+                       if (!DoDefine (Parent))
                                return false;
 
-                       if (!CheckBase (container))
+                       if (!CheckBase ())
                                return false;
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
 
                        if (Get != null) {
 
-                               GetBuilder = Get.Define (container);
+                               GetBuilder = Get.Define (Parent);
                                if (GetBuilder == null)
                                        return false;
 
@@ -5618,18 +6001,18 @@ namespace Mono.CSharp {
                                //
                                if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
                                        Iterator iterator = new Iterator (
-                                               container, "get", MemberType,
+                                               Parent, "get", MemberType,
                                                TypeManager.NoTypes, Get.ParameterInfo,
                                                ModFlags, Get.Block, Location);
                                        
-                                       if (!iterator.Define ())
+                                       if (!iterator.DefineIterator ())
                                                return false;
                                        Get.Block = iterator.Block;
                                }
                        }
 
                        if (Set != null) {
-                               SetBuilder = Set.Define (container);
+                               SetBuilder = Set.Define (Parent);
                                if (SetBuilder == null)
                                        return false;
 
@@ -5644,7 +6027,7 @@ namespace Mono.CSharp {
                        PropertyAttributes.SpecialName;
 
                        if (!IsExplicitImpl){
-                               PropertyBuilder = container.TypeBuilder.DefineProperty (
+                               PropertyBuilder = Parent.TypeBuilder.DefineProperty (
                                        Name, prop_attr, MemberType, null);
                                
                                if (Get != null)
@@ -5659,7 +6042,7 @@ namespace Mono.CSharp {
                                if (!TypeManager.RegisterProperty (PropertyBuilder, GetBuilder, SetBuilder)) {
                                        Report.Error (
                                                111, Location,
-                                               "Class `" + container.Name +
+                                               "Class `" + Parent.Name +
                                                "' already contains a definition for the property `" +
                                                Name + "'");
                                        return false;
@@ -5825,11 +6208,11 @@ namespace Mono.CSharp {
 
                static string[] attribute_targets = new string [] { "event", "property" };
 
-               public EventProperty (DeclSpace ds, Expression type, int mod_flags,
+               public EventProperty (TypeContainer parent, Expression type, int mod_flags,
                                      bool is_iface, MemberName name, Object init,
                                      Attributes attrs, Accessor add, Accessor remove,
                                      Location loc)
-                       : base (ds, type, mod_flags, is_iface, name, init, attrs, loc)
+                       : base (parent, type, mod_flags, is_iface, name, init, attrs, loc)
                {
                        Add = new AddDelegateMethod (this, add);
                        Remove = new RemoveDelegateMethod (this, remove);
@@ -5849,9 +6232,10 @@ namespace Mono.CSharp {
 
                static string[] attribute_targets = new string [] { "event", "field", "method" };
 
-               public EventField (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
-                                  MemberName name, Object init, Attributes attrs, Location loc)
-                       : base (ds, type, mod_flags, is_iface, name, init, attrs, loc)
+               public EventField (TypeContainer parent, Expression type, int mod_flags,
+                                  bool is_iface, MemberName name, Object init,
+                                  Attributes attrs, Location loc)
+                       : base (parent, type, mod_flags, is_iface, name, init, attrs, loc)
                {
                        Add = new AddDelegateMethod (this);
                        Remove = new RemoveDelegateMethod (this);
@@ -6040,9 +6424,12 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       public override EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
+                       public override EmitContext CreateEmitContext (TypeContainer tc,
+                                                                      ILGenerator ig)
                        {
-                               return new EmitContext (tc, method.ds, Location, ig, ReturnType, method.ModFlags, false);
+                               return new EmitContext (
+                                       tc, method.Parent, Location, ig, ReturnType,
+                                       method.ModFlags, false);
                        }
 
                        public override string GetSignatureForError (TypeContainer tc)
@@ -6052,7 +6439,7 @@ namespace Mono.CSharp {
 
                        public override ObsoleteAttribute GetObsoleteAttribute ()
                        {
-                               return method.GetObsoleteAttribute (method.ds);
+                               return method.GetObsoleteAttribute (method.Parent);
                        }
 
                        protected override string[] ValidAttributeTargets {
@@ -6082,18 +6469,17 @@ namespace Mono.CSharp {
                protected DelegateMethod Add, Remove;
                public MyEventBuilder     EventBuilder;
                public MethodBuilder AddBuilder, RemoveBuilder;
-               public DeclSpace ds;
 
                MethodData AddData, RemoveData;
                
-               public Event (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
-                             MemberName name, Object init, Attributes attrs, Location loc)
-                       : base (type, mod_flags,
+               public Event (TypeContainer parent, Expression type, int mod_flags,
+                             bool is_iface, MemberName name, Object init, Attributes attrs,
+                             Location loc)
+                       : base (parent, type, mod_flags,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
                                name, init, attrs, loc)
                {
                        IsInterface = is_iface;
-                       this.ds = ds;
                }
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
@@ -6107,25 +6493,25 @@ namespace Mono.CSharp {
                        }
                }
   
-               public override bool Define (TypeContainer container)
+               public override bool Define ()
                {
                        EventAttributes e_attr;
                        e_attr = EventAttributes.None;
 ;
-                       if (!DoDefineBase (container))
+                       if (!DoDefineBase ())
                                return false;
 
-                       if (!DoDefine (container, container))
+                       if (!DoDefine (Parent))
                                return false;
 
                        if (init != null && ((ModFlags & Modifiers.ABSTRACT) != 0)){
-                               Report.Error (74, Location, "'" + container.Name + "." + Name +
+                               Report.Error (74, Location, "'" + Parent.Name + "." + Name +
                                              "': abstract event can not have an initializer");
                                return false;
                        }
 
                        if (!TypeManager.IsDelegateType (MemberType)) {
-                               Report.Error (66, Location, "'" + container.Name + "." + Name +
+                               Report.Error (66, Location, "'" + Parent.Name + "." + Name +
                                              "' : event must be of a delegate type");
                                return false;
                        }
@@ -6133,30 +6519,30 @@ namespace Mono.CSharp {
                        Parameter [] parms = new Parameter [1];
                        parms [0] = new Parameter (Type, "value", Parameter.Modifier.NONE, null);
                        InternalParameters ip = new InternalParameters (
-                               container, new Parameters (parms, null, Location)); 
+                               Parent, new Parameters (parms, null, Location)); 
 
-                       if (!CheckBase (container))
+                       if (!CheckBase ())
                                return false;
 
                        //
                        // Now define the accessors
                        //
 
-                       AddBuilder = Add.Define (container, ip);
+                       AddBuilder = Add.Define (Parent, ip);
                        if (AddBuilder == null)
                                return false;
 
-                       RemoveBuilder = Remove.Define (container, ip);
+                       RemoveBuilder = Remove.Define (Parent, ip);
                        if (RemoveBuilder == null)
                                return false;
 
                        if (!IsExplicitImpl){
                                EventBuilder = new MyEventBuilder (this,
-                                       container.TypeBuilder, Name, e_attr, MemberType);
+                                       Parent.TypeBuilder, Name, e_attr, MemberType);
                                        
                                if (Add.Block == null && Remove.Block == null &&
                                    !IsInterface) {
-                                       FieldBuilder = container.TypeBuilder.DefineField (
+                                       FieldBuilder = Parent.TypeBuilder.DefineField (
                                                Name, MemberType,
                                                FieldAttributes.Private | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
                                        TypeManager.RegisterPrivateFieldOfEvent (
@@ -6169,7 +6555,7 @@ namespace Mono.CSharp {
 
                                if (!TypeManager.RegisterEvent (EventBuilder, AddBuilder, RemoveBuilder)) {
                                        Report.Error (111, Location,
-                                                     "Class `" + container.Name +
+                                                     "Class `" + Parent.Name +
                                                      "' already contains a definition for the event `" +
                                                      Name + "'");
                                        return false;
@@ -6179,19 +6565,20 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public override void Emit (TypeContainer tc)
+               public override void Emit ()
                {
                        if (OptAttributes != null) {
-                               EmitContext ec = new EmitContext (tc, Location, null, MemberType, ModFlags);
+                               EmitContext ec = new EmitContext (
+                                       Parent, Location, null, MemberType, ModFlags);
                                OptAttributes.Emit (ec, this);
                        }
 
                        if (!IsInterface) {
-                               Add.Emit (tc);
-                               Remove.Emit (tc);
+                               Add.Emit (Parent);
+                               Remove.Emit (Parent);
                        }
 
-                       base.Emit (tc);
+                       base.Emit ();
                }
 
                public override string GetSignatureForError ()
@@ -6302,10 +6689,11 @@ namespace Mono.CSharp {
                //
                // Are we implementing an interface ?
                //
-               public Indexer (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
-                               MemberName name, Parameters parameters, Attributes attrs,
-                               Accessor get_block, Accessor set_block, Location loc)
-                       : base (ds, type, mod_flags,
+               public Indexer (TypeContainer parent, Expression type, int mod_flags,
+                               bool is_iface, MemberName name, Parameters parameters,
+                               Attributes attrs, Accessor get_block, Accessor set_block,
+                               Location loc)
+                       : base (parent, type, mod_flags,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
                                is_iface, name, parameters, attrs, loc)
                {
@@ -6316,16 +6704,16 @@ namespace Mono.CSharp {
                                Set = new SetIndexerMethod (this, parameters, set_block);
                }
 
-               public override bool Define (TypeContainer container)
+               public override bool Define ()
                {
                        PropertyAttributes prop_attr =
                                PropertyAttributes.RTSpecialName |
                                PropertyAttributes.SpecialName;
                        
-                       if (!DoDefineBase (container))
+                       if (!DoDefineBase ())
                                return false;
 
-                       if (!DoDefine (container, container))
+                       if (!DoDefine (Parent))
                                return false;
 
                        if (OptAttributes != null) {
@@ -6361,21 +6749,21 @@ namespace Mono.CSharp {
                                Name = ShortName;
                        }
 
-                       if (!CheckNameCollision (container))
+                       if (!CheckNameCollision (Parent))
                                return false;
 
-                       if (!CheckBase (container))
+                       if (!CheckBase ())
                                return false;
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
                        if (Get != null){
-                               GetBuilder = Get.Define (container);
+                               GetBuilder = Get.Define (Parent);
                                if (GetBuilder == null)
                                        return false;
                        }
                        
                        if (Set != null){
-                               SetBuilder = Set.Define (container);
+                               SetBuilder = Set.Define (Parent);
                                if (SetBuilder == null)
                                        return false;
                        }
@@ -6416,7 +6804,7 @@ namespace Mono.CSharp {
                        //    explicit interface implementation.
                        //
                        if (!IsExplicitImpl) {
-                               PropertyBuilder = container.TypeBuilder.DefineProperty (
+                               PropertyBuilder = Parent.TypeBuilder.DefineProperty (
                                        IndexerName, prop_attr, MemberType, ParameterTypes);
 
                                if (Get != null)
@@ -6546,12 +6934,12 @@ namespace Mono.CSharp {
 
                static string[] attribute_targets = new string [] { "method", "return" };
 
-               public Operator (OpType type, Expression ret_type, int mod_flags,
-                                Expression arg1type, string arg1name,
+               public Operator (TypeContainer parent, OpType type, Expression ret_type,
+                                int mod_flags, Expression arg1type, string arg1name,
                                 Expression arg2type, string arg2name,
                                 Block block, Attributes attrs, Location loc)
-                       : base (ret_type, mod_flags, AllowedModifiers, Modifiers.PUBLIC,
-                               MemberName.Null, attrs, loc)
+                       : base (parent, ret_type, mod_flags, AllowedModifiers,
+                               Modifiers.PUBLIC, MemberName.Null, attrs, loc)
                {
                        OperatorType = type;
                        Name = "op_" + OperatorType;
@@ -6585,7 +6973,7 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public override bool Define (TypeContainer container)
+               public override bool Define ()
                {
                        int length = 1;
                        MethodName = "op_" + OperatorType;
@@ -6599,7 +6987,7 @@ namespace Mono.CSharp {
                                Report.Error (
                                        558, Location, 
                                        "User defined operators `" +
-                                       Prototype (container) +
+                                       Prototype (Parent) +
                                        "' must be declared static and public");
                                return false;
                        }
@@ -6611,14 +6999,14 @@ namespace Mono.CSharp {
                                                               Parameter.Modifier.NONE, null);
                        
                        OperatorMethod = new Method (
-                               container, ReturnType, ModFlags, false,
+                               Parent, null, ReturnType, ModFlags, false,
                                new MemberName (MethodName),
                                new Parameters (param_list, null, Location),
                                OptAttributes, Location);
 
                        OperatorMethod.Block = Block;
                        OperatorMethod.IsOperator = true;                       
-                       OperatorMethod.Define (container);
+                       OperatorMethod.Define ();
 
                        if (OperatorMethod.MethodBuilder == null)
                                return false;
@@ -6726,7 +7114,7 @@ namespace Mono.CSharp {
                        return true;
                }
                
-               public override void Emit (TypeContainer container)
+               public override void Emit ()
                {
                        //
                        // abstract or extern methods have no bodies
@@ -6734,7 +7122,7 @@ namespace Mono.CSharp {
                        if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
                                return;
                        
-                       OperatorMethod.Emit (container);
+                       OperatorMethod.Emit ();
                        Block = null;
                }
 
index aca30e3a83b7e4f5cf034324827052ee13236b44..76b96686f7e43757f6e425f2bac259e7c8325d40 100755 (executable)
@@ -818,7 +818,7 @@ namespace Mono.CSharp {
                        if (OptAttributes == null)
                                return null;
 
-                       EmitContext temp_ec = new EmitContext (new TypeContainer (), Mono.CSharp.Location.Null, null, null, 0, false);
+                       EmitContext temp_ec = new EmitContext (new RootTypes (), Mono.CSharp.Location.Null, null, null, 0, false);
                        Attribute a = OptAttributes.Search (TypeManager.cls_compliant_attribute_type, temp_ec);
                        if (a != null) {
                                a.Resolve (temp_ec);
index 79ae07b7716a62d744cf6bdb069398bd2bd6726c..575a4157a7856029a9a32e380b0490fa51e9da93 100755 (executable)
@@ -41,9 +41,9 @@ namespace Mono.CSharp {
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE;
 
-               public Const (Expression constant_type, string name, Expression expr,
-                             int mod_flags, Attributes attrs, Location loc)
-                       : base (constant_type, mod_flags, AllowedModifiers,
+               public Const (TypeContainer parent, Expression constant_type, string name,
+                             Expression expr, int mod_flags, Attributes attrs, Location loc)
+                       : base (parent, constant_type, mod_flags, AllowedModifiers,
                                new MemberName (name), null, attrs, loc)
                {
                        Expr = expr;
@@ -71,14 +71,14 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Defines the constant in the @parent
                /// </summary>
-               public override bool Define (TypeContainer parent)
+               public override bool Define ()
                {
-                       type = parent.ResolveType (Type, false, Location);
+                       type = Parent.ResolveType (Type, false, Location);
 
                        if (type == null)
                                return false;
 
-                       const_ec = new EmitContext (parent, Location, null, type, ModFlags);
+                       const_ec = new EmitContext (Parent, Location, null, type, ModFlags);
                        
                        Type ttype = type;
                        while (ttype.IsArray)
@@ -92,7 +92,7 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       Type ptype = parent.TypeBuilder.BaseType;
+                       Type ptype = Parent.TypeBuilder.BaseType;
 
                        if (ptype != null) {
                                MemberList list = TypeContainer.FindMembers (
@@ -101,12 +101,12 @@ namespace Mono.CSharp {
                                
                                if (list.Count == 0)
                                        if ((ModFlags & Modifiers.NEW) != 0)
-                                               WarningNotHiding (parent);
+                                               WarningNotHiding (Parent);
 
                        } else if ((ModFlags & Modifiers.NEW) != 0)
-                               WarningNotHiding (parent);
+                               WarningNotHiding (Parent);
 
-                       FieldBuilder = parent.TypeBuilder.DefineField (Name, type, FieldAttr);
+                       FieldBuilder = Parent.TypeBuilder.DefineField (Name, type, FieldAttr);
 
                        TypeManager.RegisterConstant (FieldBuilder, this);
 
@@ -291,7 +291,7 @@ namespace Mono.CSharp {
                /// <summary>
                ///  Emits the field value by evaluating the expression
                /// </summary>
-               public override void Emit (TypeContainer parent)
+               public override void Emit ()
                {
                        object value;
                        LookupConstantValue (out value);
@@ -300,7 +300,7 @@ namespace Mono.CSharp {
                                OptAttributes.Emit (const_ec, this);
                        }
 
-                       base.Emit (parent);
+                       base.Emit ();
                }
        }
 }
index baae918ed90f143d6a20afeaf2e38c9e688e2c9c..3cf203e82f4008eb3b9c971a5d416a980f763f9d 100755 (executable)
@@ -32,6 +32,7 @@ namespace Mono.CSharp
        public class CSharpParser {
                NamespaceEntry  current_namespace;
                TypeContainer   current_container;
+               TypeContainer   current_class;
        
                IIteratorContainer iterator_container;
 
@@ -48,14 +49,6 @@ namespace Mono.CSharp
                 /// </summary>
                 bool       create_toplevel_block;
 
-                /// <summary>
-               /// <summary>
-               ///   Current interface is used by the various declaration
-               ///   productions in the interface declaration to "add"
-               ///   the interfaces as we find them.
-               /// </summary>
-               Interface  current_interface;
-
                Delegate   current_delegate;
 
                /// <summary>
@@ -197,6 +190,7 @@ namespace Mono.CSharp
 %token WHERE
 %token WHILE   
 %token ARGLIST
+%token PARTIAL
 
 /* C# keywords which are not really keywords */
 %token GET           "get"
@@ -361,8 +355,9 @@ namespace_declaration
                        Report.Error_T (134, lexer.Location);
                }
 
-               current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, (string) $3, lexer.Location);
-       } 
+               current_namespace = new NamespaceEntry (
+                       current_namespace, file, (string) $3, lexer.Location);
+         } 
          namespace_body opt_semicolon
          { 
                current_namespace = current_namespace.Parent;
@@ -736,37 +731,52 @@ class_member_declaration
 struct_declaration
        : opt_attributes
          opt_modifiers
+         opt_partial
          STRUCT member_name
          { 
-               Struct new_struct;
-               MemberName full_struct_name = MakeName ((MemberName) $4);
+               MemberName name = MakeName ((MemberName) $5);
+               bool partial = (bool) $3;
+
+               if (partial) {
+                       ClassPart part = PartialContainer.CreatePart (
+                               current_namespace, current_container, 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,
+                               (Attributes) $1, lexer.Location);
+
+                       current_container = current_class;
+                       RootContext.Tree.RecordDecl (name.GetName (true), current_class);
+               }
 
-               new_struct = new Struct (current_namespace, current_container, full_struct_name,
-                                        (int) $2, (Attributes) $1, lexer.Location);
-               current_container = new_struct;
-               RootContext.Tree.RecordDecl (full_struct_name.GetName (true), new_struct);
                lexer.ConstraintsParsing = true;
          }
          opt_class_base
          opt_type_parameter_constraints_clauses
          {
                lexer.ConstraintsParsing = false;
+
+               if ($7 != null)
+                       current_class.Bases = (ArrayList) $7;
+
+               CheckDef (current_class.SetParameterInfo ((ArrayList) $8), current_class.Name,
+                         current_class.Location);
+
+               current_class.Register ();
          }
          struct_body
          opt_semicolon
          {
-               Struct new_struct = (Struct) current_container;
-
-               CheckDef (new_struct.SetParameterInfo ((ArrayList) $7), new_struct.Name, new_struct.Location);
-
-               if ($6 != null)
-                       new_struct.Bases = (ArrayList) $6;
+               $$ = current_class;
 
                current_container = current_container.Parent;
-               CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
-               $$ = new_struct;
+               current_class = current_container;
          }
-       | opt_attributes opt_modifiers STRUCT error {
+       | opt_attributes opt_modifiers opt_partial STRUCT error {
                CheckIdentifierToken (yyToken);
          }
        ;
@@ -815,7 +825,7 @@ constant_declaration
                        Location l = constant.Location;
 
                        Const c = new Const (
-                               (Expression) $4, (string) constant.identifier, 
+                               current_class, (Expression) $4, (string) constant.identifier, 
                                (Expression) constant.expression_or_array_initializer, (int) $2, 
                                (Attributes) $1, l);
 
@@ -867,7 +877,7 @@ field_declaration
                foreach (VariableDeclaration var in (ArrayList) $4){
                        Location l = var.Location;
 
-                       Field field = new Field (type, mod, var.identifier, 
+                       Field field = new Field (current_class, type, mod, var.identifier, 
                                                 var.expression_or_array_initializer, 
                                                 (Attributes) $1, l);
 
@@ -997,17 +1007,14 @@ method_header
 
                GenericMethod generic = null;
                if (name.TypeArguments != null) {
-                       generic = new GenericMethod (current_namespace, current_container,
+                       generic = new GenericMethod (current_namespace, current_class,
                                                     name, lexer.Location);
 
                        CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+               }
 
-                       method = new Method (generic, (Expression) $3, (int) $2, false, name,
-                                            (Parameters) $6, (Attributes) $1, lexer.Location);
-               } else
-                       method = new Method (current_container, (Expression) $3, (int) $2,
-                                            false, name, (Parameters) $6, (Attributes) $1,
-                                            lexer.Location);
+               method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
+                                    name, (Parameters) $6, (Attributes) $1, lexer.Location);
 
                current_local_parameters = (Parameters) $6;
 
@@ -1033,19 +1040,16 @@ method_header
                Method method;
                GenericMethod generic = null;
                if (name.TypeArguments != null) {
-                       generic = new GenericMethod (current_namespace, current_container,
+                       generic = new GenericMethod (current_namespace, current_class,
                                                     name, lexer.Location);
 
 
                        CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+               }
 
-                       method = new Method (generic, TypeManager.system_void_expr, (int) $2,
-                                            false, name, (Parameters) $6, (Attributes) $1,
-                                            lexer.Location);
-               } else
-                       method = new Method (current_container, TypeManager.system_void_expr,
-                                            (int) $2, false, name, (Parameters) $6,
-                                            (Attributes) $1, lexer.Location);
+               method = new Method (current_class, generic, TypeManager.system_void_expr,
+                                    (int) $2, false, name, (Parameters) $6, (Attributes) $1,
+                                    lexer.Location);
 
                current_local_parameters = (Parameters) $6;
 
@@ -1061,7 +1065,7 @@ method_header
                                Modifiers.Name ((int) $4)));
                MemberName name = (MemberName) $4;
 
-               Method method = new Method (current_container, TypeManager.system_void_expr,
+               Method method = new Method (current_class, null, TypeManager.system_void_expr,
                                            0, false, name, (Parameters) $6, (Attributes) $1,
                                            lexer.Location);
 
@@ -1300,42 +1304,51 @@ accessor_body
 interface_declaration
        : opt_attributes
          opt_modifiers
+         opt_partial
          INTERFACE member_name
          {
-               Interface new_interface;
-               MemberName full_interface_name = MakeName ((MemberName) $4);
+               MemberName name = MakeName ((MemberName) $5);
+               bool partial = (bool) $3;
 
-               new_interface = new Interface (current_namespace, current_container, full_interface_name,
-                                              (int) $2, (Attributes) $1, lexer.Location);
-               if (current_interface != null) {
-                       Location l = lexer.Location;
-                       Report.Error (-2, l, "Internal compiler error: interface inside interface");
+               if (partial) {
+                       ClassPart part = PartialContainer.CreatePart (
+                               current_namespace, current_container, 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,
+                               (Attributes) $1, lexer.Location);
+
+                       current_container = current_class;
+                       RootContext.Tree.RecordDecl (name.GetName (true), current_class);
                }
-               current_interface = new_interface;
-               current_container = new_interface;
-               RootContext.Tree.RecordDecl (
-                       full_interface_name.GetName (true), new_interface);
+
                lexer.ConstraintsParsing = true;
          }
          opt_class_base
          opt_type_parameter_constraints_clauses
          {
                lexer.ConstraintsParsing = false;
+
+               if ($7 != null)
+                       current_class.Bases = (ArrayList) $7;
+
+               CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
+                         current_class.Name, current_class.Location);
+
+               current_class.Register ();
          }
          interface_body opt_semicolon
          { 
-               Interface new_interface = (Interface) current_interface;
-
-               CheckDef (new_interface.SetParameterInfo ((ArrayList) $7), new_interface.Name, new_interface.Location);
-               if ($6 != null)
-                       new_interface.Bases = (ArrayList) $6;
+               $$ = current_class;
 
-               current_interface = null;
                current_container = current_container.Parent;
-               CheckDef (current_container.AddInterface (new_interface), 
-                         new_interface.Name, new_interface.Location);
+               current_class = current_container;
          }
-       | opt_attributes opt_modifiers INTERFACE error {
+       | opt_attributes opt_modifiers opt_partial INTERFACE error {
                CheckIdentifierToken (yyToken);
          }
        ;
@@ -1361,26 +1374,26 @@ interface_member_declaration
          { 
                Method m = (Method) $1;
 
-               CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
+               CheckDef (current_container.AddMethod (m), m.Name, m.Location);
          }
        | interface_property_declaration        
          { 
                Property p = (Property) $1;
 
-               CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
+               CheckDef (current_container.AddProperty (p), p.Name, p.Location);
           }
        | interface_event_declaration 
           { 
                if ($1 != null){
                        Event e = (Event) $1;
-                       CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
+                       CheckDef (current_container.AddEvent (e), e.Name, lexer.Location);
                }
          }
        | interface_indexer_declaration
          { 
                Indexer i = (Indexer) $1;
 
-               current_interface.AddIndexer (i);
+               current_container.AddIndexer (i);
          }
        ;
 
@@ -1412,17 +1425,14 @@ interface_method_declaration
 
                GenericMethod generic = null;
                if (name.TypeArguments != null) {
-                       generic = new GenericMethod (current_namespace, current_container,
+                       generic = new GenericMethod (current_namespace, current_class,
                                                     name, lexer.Location);
 
                        CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+               }
 
-                       $$ = new Method (generic, (Expression) $3, (int) $2, true, name,
-                                        (Parameters) $6, (Attributes) $1, lexer.Location);
-               } else
-                       $$ = new Method (current_container, (Expression) $3, (int) $2, true,
-                                        name, (Parameters) $6, (Attributes) $1,
-                                        lexer.Location);
+               $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
+                                (Parameters) $6, (Attributes) $1, lexer.Location);
          }
        | opt_attributes opt_new VOID namespace_or_type_name
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
@@ -1442,18 +1452,14 @@ interface_method_declaration
 
                GenericMethod generic = null;
                if (name.TypeArguments != null) {
-                       generic = new GenericMethod (current_namespace, current_container,
+                       generic = new GenericMethod (current_namespace, current_class,
                                                     name, lexer.Location);
 
                        CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+               }
 
-                       $$ = new Method (generic, TypeManager.system_void_expr, (int) $2,
-                                        true, name, (Parameters) $6, (Attributes) $1,
-                                        lexer.Location);
-               } else
-                       $$ = new Method (current_container, TypeManager.system_void_expr,
-                                        (int) $2, true, name, (Parameters) $6,
-                                        (Attributes) $1, lexer.Location);
+               $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
+                                true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
          }
        ;
 
@@ -1469,7 +1475,7 @@ interface_property_declaration
          {
                 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
 
-               $$ = new Property (current_container, (Expression) $3, (int) $2, true,
+               $$ = new Property (current_class, (Expression) $3, (int) $2, true,
                                   new MemberName ((string) $4), (Attributes) $1,
                                   pinfo.Get, pinfo.Set, lexer.Location);
          }
@@ -1493,7 +1499,7 @@ interface_accessors
 interface_event_declaration
        : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
          {
-               $$ = new EventField (current_container, (Expression) $4, (int) $2, true,
+               $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
                                     new MemberName ((string) $5), null,
                                     (Attributes) $1, lexer.Location);
          }
@@ -1522,7 +1528,7 @@ interface_indexer_declaration
          {
                InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
 
-               $$ = new Indexer (current_container, (Expression) $3, (int) $2, true,
+               $$ = new Indexer (current_class, (Expression) $3, (int) $2, true,
                                  MemberName.Null, (Parameters) $6, (Attributes) $1,
                                  info.Get, info.Set, lexer.Location);
          }
@@ -1537,8 +1543,10 @@ operator_declaration
          {
                OperatorDeclaration decl = (OperatorDeclaration) $3;
                
-               Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
-                                           decl.arg2type, decl.arg2name, (Block) $5, (Attributes) $1, decl.location);
+               Operator op = new Operator (
+                       current_class, decl.optype, decl.ret_type, (int) $2, decl.arg1type,
+                       decl.arg1name, decl.arg2type, decl.arg2name, (Block) $5,
+                       (Attributes) $1, decl.location);
 
                if (SimpleIteratorContainer.Simple.Yields)
                        op.SetYields ();
@@ -1718,7 +1726,7 @@ constructor_declarator
          opt_constructor_initializer
          {
                Location l = (Location) oob_stack.Pop ();
-               $$ = new Constructor (current_container, (string) $1, 0, (Parameters) $3,
+               $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $3,
                                      (ConstructorInitializer) $6, l);
          }
        ;
@@ -1779,7 +1787,7 @@ destructor_declaration
                         }
                         
                        Method d = new Destructor (
-                               current_container, TypeManager.system_void_expr, m, "Finalize", 
+                               current_class, TypeManager.system_void_expr, m, "Finalize", 
                                new Parameters (null, null, l), (Attributes) $1, l);
                  
                        d.Block = (Block) $7;
@@ -1805,7 +1813,7 @@ event_declaration
 
                        MemberName name = new MemberName (var.identifier);
 
-                       Event e = new EventField (current_container, (Expression) $4, (int) $2,
+                       Event e = new EventField (current_class, (Expression) $4, (int) $2,
                                                  false, name,
                                                  var.expression_or_array_initializer,
                                                  (Attributes) $1, lexer.Location);
@@ -1841,7 +1849,7 @@ event_declaration
                if (name.TypeArguments != null)
                        syntax_error (lexer.Location, "an event can't have type arguments");
 
-               Event e = new EventProperty (current_container, (Expression) $4, (int) $2,
+               Event e = new EventProperty (current_class, (Expression) $4, (int) $2,
                                             false, name, null, (Attributes) $1,
                                             (Accessor) pair.First, (Accessor) pair.Second,
                                             loc);
@@ -1949,7 +1957,7 @@ indexer_declaration
                else
                        name = MemberName.Null;
 
-               indexer = new Indexer (current_container, decl.type, (int) $2, false,
+               indexer = new Indexer (current_class, decl.type, (int) $2, false,
                                       name, decl.param_list, (Attributes) $1,
                                       get_block, set_block, loc);
 
@@ -3105,16 +3113,27 @@ boolean_expression
 class_declaration
        : opt_attributes
          opt_modifiers
+         opt_partial
          CLASS member_name
          {
-               Class new_class;
+               MemberName name = MakeName ((MemberName) $5);
+               bool partial = (bool) $3;
 
-               MemberName name = MakeName ((MemberName) $4);
+               if (partial) {
+                       ClassPart part = PartialContainer.CreatePart (
+                               current_namespace, current_container, name, (int) $2,
+                               (Attributes) $1, Kind.Class, lexer.Location);
 
-               new_class = new Class (current_namespace, current_container, name, (int) $2, 
+                       current_container = part.PartialContainer;
+                       current_class = part;
+               } else {
+                       current_class = new Class (
+                               current_namespace, current_container, name, (int) $2,
                                       (Attributes) $1, lexer.Location);
-               current_container = new_class;
-               RootContext.Tree.RecordDecl (name.GetName (true), new_class);
+
+                       current_container = current_class;
+                       RootContext.Tree.RecordDecl (name.GetName (true), current_class);
+               }
 
                lexer.ConstraintsParsing = true;
          }
@@ -3122,27 +3141,38 @@ class_declaration
          opt_type_parameter_constraints_clauses
          {
                lexer.ConstraintsParsing = false;
+
+               if ($7 != null) {
+                       if (current_class.Name == "System.Object") {
+                               Report.Error (537, current_class.Location,
+                                             "The class System.Object cannot have a base " +
+                                             "class or implement an interface.");
+                       }
+                       current_class.Bases = (ArrayList) $7;
+               }
+
+               CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
+                         current_class.Name, current_class.Location);
+
+               current_class.Register ();
          }
          class_body 
          opt_semicolon 
          {
-               Class new_class = (Class) current_container;
-
-               CheckDef (new_class.SetParameterInfo ((ArrayList) $7), new_class.Name, new_class.Location);
-               if ($6 != null) {
-                       if (new_class.Name == "System.Object") {
-                               Report.Error (537, new_class.Location, "The class System.Object cannot have a base class or implement an interface.");
-                       }
+               $$ = current_class;
 
-                       new_class.Bases = (ArrayList) $6;
-               }
                current_container = current_container.Parent;
-               CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
-
-               $$ = new_class;
+               current_class = current_container;
          }
        ;       
 
+opt_partial
+       : /* empty */
+         { $$ = (bool) false; }
+       | PARTIAL
+         { $$ = (bool) true; }
+       ;
+
 opt_modifiers
        : /* empty */           { $$ = (int) 0; }
        | modifiers
@@ -4367,40 +4397,7 @@ MakeName (MemberName class_name)
 void 
 CheckDef (DeclSpace.AdditionResult result, string name, Location l)
 {
-       if (result == DeclSpace.AdditionResult.Success)
-               return;
-
-       switch (result){
-       case DeclSpace.AdditionResult.NameExists:
-               Report.Error (102, l, "The container `" + current_container.Name + 
-                                "' already contains a definition for `"+
-                                name + "'");
-               break;
-
-
-               //
-               // This is handled only for static Constructors, because
-               // in reality we handle these by the semantic analysis later
-               //
-       case DeclSpace.AdditionResult.MethodExists:
-               Report.Error (
-                       111, l, "Class `"+current_container.Name+
-                       "' already defines a member called '" + 
-                       name + "' with the same parameter types (more than one default constructor)");
-               break;
-
-       case DeclSpace.AdditionResult.EnclosingClash:
-               Report.Error (542, l, "Member names cannot be the same as their enclosing type");
-               break;
-               
-       case DeclSpace.AdditionResult.NotAConstructor:
-               Report.Error (1520, l, "Class, struct, or interface method must have a return type");
-               break;
-
-       case DeclSpace.AdditionResult.Error:
-               // Error has already been reported.
-               break;
-       }
+       current_container.CheckDef (result, name, l);
 }
 
 void 
index e0e165314cc3a8d48f5e6c8df9b6a56b1f8ed4a5..fc0eeccb8a944cb7587c3d040efaeada5ca761ad 100755 (executable)
@@ -303,6 +303,7 @@ namespace Mono.CSharp
                        AddKeyword ("volatile", Token.VOLATILE);\r
                        AddKeyword ("where", Token.WHERE);\r
                        AddKeyword ("while", Token.WHILE);\r
+                       AddKeyword ("partial", Token.PARTIAL);\r
                }\r
 \r
                //\r
@@ -341,6 +342,7 @@ namespace Mono.CSharp
                                return -1;\r
                        if (handle_constraints == false && res == Token.WHERE)\r
                                return -1;\r
+\r
                        return res;\r
                        \r
                }\r
@@ -1776,6 +1778,36 @@ namespace Mono.CSharp
                        return Token.EOF;\r
                }\r
 \r
+               private int consume_identifier (int s)\r
+               {\r
+                       int res = consume_identifier (s, false);\r
+\r
+                       if (res == Token.PARTIAL) {\r
+                               // Save current position and parse next token.\r
+                               int old = reader.Position;\r
+                               int old_putback = putback_char;\r
+\r
+                               putback_char = -1;\r
+\r
+                               int next_token = token ();\r
+                               bool ok = (next_token == Token.CLASS) ||\r
+                                       (next_token == Token.STRUCT) ||\r
+                                       (next_token == Token.INTERFACE);\r
+\r
+                               reader.Position = old;\r
+                               putback_char = old_putback;\r
+\r
+                               if (ok)\r
+                                       return res;\r
+                               else {\r
+                                       val = "partial";\r
+                                       return Token.IDENTIFIER;\r
+                               }\r
+                       }\r
+\r
+                       return res;\r
+               }\r
+\r
                private int consume_identifier (int s, bool quoted) \r
                {\r
                        int pos = 1;\r
@@ -1803,9 +1835,9 @@ namespace Mono.CSharp
                        // Optimization: avoids doing the keyword lookup\r
                        // on uppercase letters and _\r
                        //\r
-                       if (s >= 'a' || s == '_'){\r
+                       if (!quoted && (s >= 'a' || s == '_')){\r
                                int keyword = GetKeyword (id_builder, pos);\r
-                               if (keyword != -1 && !quoted)\r
+                               if (keyword != -1)\r
                                return keyword;\r
                        }\r
 \r
@@ -1972,7 +2004,7 @@ namespace Mono.CSharp
 \r
                        if (is_identifier_start_character ((char)c)){\r
                                tokens_seen = true;\r
-                               return consume_identifier (c, false);\r
+                                       return consume_identifier (c);\r
                        }\r
 \r
                is_punct_label:\r
index f47402488eb82a99f3c49bf373ea4a040cef249a..bbddec47d885f8bff62bdb708fa963d5b2cea0b4 100755 (executable)
@@ -178,6 +178,8 @@ namespace Mono.CSharp {
                /// </summary>
                public int ModFlags;
 
+               public readonly TypeContainer Parent;
+
                /// <summary>
                ///   Location where this declaration happens
                /// </summary>
@@ -203,9 +205,11 @@ namespace Mono.CSharp {
                /// </summary>
                protected Flags caching_flags;
 
-               public MemberCore (MemberName name, Attributes attrs, Location loc)
+               public MemberCore (TypeContainer parent, MemberName name, Attributes attrs,
+                                  Location loc)
                        : base (attrs)
                {
+                       Parent = parent;
                        Name = name.GetName (!(this is GenericMethod) && !(this is Method));
                        MemberName = name;
                        Location = loc;
@@ -227,7 +231,7 @@ namespace Mono.CSharp {
                        AttributeTester.Report_ObsoleteMessage (obsolete_attr, type.FullName, Location);
                }
 
-               public abstract bool Define (TypeContainer parent);
+               public abstract bool Define ();
 
                // 
                // Returns full member name for error message
@@ -240,14 +244,14 @@ namespace Mono.CSharp {
                /// <summary>
                /// Base Emit method. This is also entry point for CLS-Compliant verification.
                /// </summary>
-               public virtual void Emit (TypeContainer container)
+               public virtual void Emit ()
                {
                        VerifyObsoleteAttribute ();
 
                        if (!RootContext.VerifyClsCompliance)
                                return;
 
-                       VerifyClsCompliance (container);
+                       VerifyClsCompliance (Parent);
                }
 
                // 
@@ -511,20 +515,18 @@ namespace Mono.CSharp {
                        get {
                                if (is_generic)
                                        return true;
-                               else if (parent != null)
-                                       return parent.IsGeneric;
+                               else if (Parent != null)
+                                       return Parent.IsGeneric;
                                else
                                        return false;
                        }
                }
 
-               TypeContainer parent;
-
                static string[] attribute_targets = new string [] { "type" };
 
                public DeclSpace (NamespaceEntry ns, TypeContainer parent, MemberName name,
                                  Attributes attrs, Location l)
-                       : base (name, attrs, l)
+                       : base (parent, name, attrs, l)
                {
                        NamespaceEntry = ns;
                        Basename = name.Name;
@@ -535,12 +537,11 @@ namespace Mono.CSharp {
                        }
                        if (parent != null)
                                count_type_params += parent.count_type_params;
-                       this.parent = parent;
                }
 
                public void RecordDecl ()
                {
-                       if ((NamespaceEntry != null) && (parent == RootContext.Tree.Types))
+                       if ((NamespaceEntry != null) && (Parent == RootContext.Tree.Types))
                                NamespaceEntry.DefineName (MemberName.Basename, this);
                }
 
@@ -649,12 +650,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public TypeContainer Parent {
-                       get {
-                               return parent;
-                       }
-               }
-
                /// <summary>
                ///   Looks up the alias for the name
                /// </summary>
@@ -673,8 +668,8 @@ namespace Mono.CSharp {
                //
                public bool IsTopLevel {
                        get {
-                               if (parent != null){
-                                       if (parent.parent == null)
+                               if (Parent != null){
+                                       if (Parent.Parent == null)
                                                return true;
                                }
                                return false;
@@ -720,8 +715,8 @@ namespace Mono.CSharp {
                        get {
                                if ((ModFlags & Modifiers.UNSAFE) != 0)
                                        return true;
-                               if (parent != null)
-                                       return parent.UnsafeContext;
+                               if (Parent != null)
+                                       return Parent.UnsafeContext;
                                return false;
                        }
                }
@@ -792,7 +787,7 @@ namespace Mono.CSharp {
                public TypeExpr ResolveTypeExpr (Expression e, bool silent, Location loc)
                {
                        if (type_resolve_ec == null)
-                               type_resolve_ec = GetTypeResolveEmitContext (parent, loc);
+                               type_resolve_ec = GetTypeResolveEmitContext (Parent, loc);
                        type_resolve_ec.loc = loc;
                        if (this is GenericMethod)
                                type_resolve_ec.ContainerType = Parent.TypeBuilder;
@@ -1311,7 +1306,7 @@ namespace Mono.CSharp {
                        caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
 
                        if (OptAttributes != null) {
-                               EmitContext ec = new EmitContext (parent, this, Location,
+                               EmitContext ec = new EmitContext (Parent, this, Location,
                                                                  null, null, ModFlags, false);
                                Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ec);
                                if (cls_attribute != null) {
@@ -1324,7 +1319,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if (parent == null) {
+                       if (Parent == null) {
                                if (CodeGen.Assembly.IsClsCompliant) {
                                        caching_flags |= Flags.ClsCompliantAttributeTrue;
                                        return true;
@@ -1332,7 +1327,7 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (parent.GetClsCompliantAttributeValue ()) {
+                       if (Parent.GetClsCompliantAttributeValue ()) {
                                caching_flags |= Flags.ClsCompliantAttributeTrue;
                                return true;
                        }
@@ -1414,7 +1409,7 @@ namespace Mono.CSharp {
                                                693, Location,
                                                "Type parameter `{0}' has same name " +
                                                "as type parameter from outer type `{1}'",
-                                               name, parent.GetInstantiationName ());
+                                               name, Parent.GetInstantiationName ());
 
                                return false;
                        }
@@ -1427,7 +1422,7 @@ namespace Mono.CSharp {
                        if (type_param_list != null)
                                return type_param_list;
 
-                       DeclSpace the_parent = parent;
+                       DeclSpace the_parent = Parent;
                        if (this is GenericMethod)
                                the_parent = null;
 
@@ -1539,8 +1534,8 @@ namespace Mono.CSharp {
                                return new TypeParameterExpr (type_param, loc);
                        }
 
-                       if (parent != null)
-                               return parent.LookupGeneric (name, loc);
+                       if (Parent != null)
+                               return Parent.LookupGeneric (name, loc);
 
                        return null;
                }
index 3dbede6206300525666b2c2929cf60a0edbf4260..03425e1468348e3dac02b46ba7c8f7972e22b645 100644 (file)
@@ -138,7 +138,7 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public override bool Define (TypeContainer container)
+               public override bool Define ()
                {
                        MethodAttributes mattr;
                        int i;
@@ -202,14 +202,14 @@ namespace Mono.CSharp {
 
                        // Check accessibility
                        foreach (Type partype in param_types){
-                               if (!container.AsAccessible (partype, ModFlags)) {
+                               if (!Parent.AsAccessible (partype, ModFlags)) {
                                        Report.Error (59, Location,
                                                      "Inconsistent accessibility: parameter type `" +
                                                      TypeManager.CSharpName (partype) + "` is less " +
                                                      "accessible than delegate `" + Name + "'");
                                        return false;
                                }
-                               if (partype.IsPointer && !UnsafeOK (container))
+                               if (partype.IsPointer && !UnsafeOK (Parent))
                                        return false;
                        }
                        
@@ -221,7 +221,7 @@ namespace Mono.CSharp {
                        if (ret_type == null)
                                return false;
 
-                       if (!container.AsAccessible (ret_type, ModFlags)) {
+                       if (!Parent.AsAccessible (ret_type, ModFlags)) {
                                Report.Error (58, Location,
                                              "Inconsistent accessibility: return type `" +
                                              TypeManager.CSharpName (ret_type) + "` is less " +
@@ -229,7 +229,7 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (ret_type.IsPointer && !UnsafeOK (container))
+                       if (ret_type.IsPointer && !UnsafeOK (Parent))
                                return false;
 
                        //
@@ -272,7 +272,7 @@ namespace Mono.CSharp {
                        InvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
 
                        TypeManager.RegisterMethod (InvokeBuilder,
-                                                   new InternalParameters (container, Parameters),
+                                                   new InternalParameters (Parent, Parameters),
                                                    param_types);
 
                        //
@@ -339,7 +339,7 @@ namespace Mono.CSharp {
                        
                        async_parameters.ComputeAndDefineParameterTypes (this);
                        TypeManager.RegisterMethod (BeginInvokeBuilder,
-                                                   new InternalParameters (container, async_parameters),
+                                                   new InternalParameters (Parent, async_parameters),
                                                    async_param_types);
 
                        //
@@ -384,21 +384,22 @@ namespace Mono.CSharp {
 
                        TypeManager.RegisterMethod (
                                EndInvokeBuilder,
-                               new InternalParameters (container, end_parameters),
+                               new InternalParameters (Parent, end_parameters),
                                end_param_types);
 
                        return true;
                }
 
-               public override void Emit (TypeContainer tc)
+               public override void Emit ()
                {
                        if (OptAttributes != null) {
-                               EmitContext ec = new EmitContext (tc, this, Location, null, null, ModFlags, false);
+                               EmitContext ec = new EmitContext (
+                                       Parent, this, Location, null, null, ModFlags, false);
                                Parameters.LabelParameters (ec, InvokeBuilder, Location);
                                OptAttributes.Emit (ec, this);
                        }
 
-                       base.Emit (tc);
+                       base.Emit ();
                }
 
                protected override string[] ValidAttributeTargets {
index 22a10381ca0783939d4cdae9568f0991e4cda111..505197967959780cbb758b90dde44d3ac6f29500 100755 (executable)
@@ -622,7 +622,7 @@ namespace Mono.CSharp {
                        return true;
                }
                
-               public override bool Define (TypeContainer parent)
+               public override bool Define ()
                {
                        //
                        // If there was an error during DefineEnum, return
@@ -689,9 +689,10 @@ namespace Mono.CSharp {
                        return true;
                }
                        
-               public override void Emit (TypeContainer tc)
+               public override void Emit ()
                {
-                               EmitContext ec = new EmitContext (tc, this, Location, null, null, ModFlags, false);
+                       EmitContext ec = new EmitContext (
+                               Parent, this, Location, null, null, ModFlags, false);
 
                        if (OptAttributes != null) {
                                OptAttributes.Emit (ec, this);
@@ -701,7 +702,7 @@ namespace Mono.CSharp {
                                em.Emit (ec);
                        }
 
-                       base.Emit (tc);
+                       base.Emit ();
                }
                
                protected override bool IsIdentifierClsCompliant (DeclSpace ds)
index b170ad2bb804cea1f2c2a32afca8c803a298f4da..2b13e2099ae70163f0b8b90422b9c0cd21725694 100644 (file)
@@ -500,7 +500,7 @@ namespace Mono.CSharp {
                        bool ok = true;
 
                        atypes = new Type [count];
-                       
+
                        for (int i = 0; i < count; i++){
                                TypeExpr te = ds.ResolveTypeExpr (
                                        (Expression) args [i], false, Location);
@@ -888,18 +888,18 @@ namespace Mono.CSharp {
                        throw new Exception ();
                }
 
-               public override bool Define (TypeContainer parent)
+               public override bool Define ()
                {
                        for (int i = 0; i < TypeParameters.Length; i++)
-                               if (!TypeParameters [i].Resolve (parent))
+                               if (!TypeParameters [i].Resolve (Parent))
                                        return false;
 
                        return true;
                }
 
-               public bool Define (TypeContainer parent, MethodBuilder mb)
+               public bool Define (MethodBuilder mb)
                {
-                       if (!Define (parent))
+                       if (!Define ())
                                return false;
 
                        GenericTypeParameterBuilder[] gen_params;
index e63a7b93570f4fea134670e23a57ec9ab2840aa2..bcf063369782967a30c8cfdeaebe8436d01f1729 100644 (file)
@@ -371,7 +371,7 @@ namespace Mono.CSharp {
                        is_static = (modifiers & Modifiers.STATIC) != 0;
                }
 
-               public bool Define ()
+               public bool DefineIterator ()
                {
                        if (!CheckType (return_type)) {
                                Report.Error (
@@ -429,7 +429,7 @@ namespace Mono.CSharp {
                //
                // Returns the new block for the method, or null on failure
                //
-               protected override bool DoDefineType ()
+               protected override bool DefineNestedTypes ()
                {
                        Define_Fields ();
                        Define_Constructor ();
@@ -446,7 +446,7 @@ namespace Mono.CSharp {
 
                        Create_Block ();
 
-                       return true;
+                       return base.DefineNestedTypes ();
                }
 
 
@@ -487,17 +487,18 @@ namespace Mono.CSharp {
                        Location loc = Location.Null;
 
                        pc_field = new Field (
-                               TypeManager.system_int32_expr, Modifiers.PRIVATE, "PC",
+                               this, TypeManager.system_int32_expr, Modifiers.PRIVATE, "PC",
                                null, null, loc);
                        AddField (pc_field);
 
                        current_field = new Field (
-                               iterator_type_expr, Modifiers.PRIVATE, "current",
+                               this, iterator_type_expr, Modifiers.PRIVATE, "current",
                                null, null, loc);
                        AddField (current_field);
 
                        if (!is_static) {
                                this_field = new Field (
+                                       this,
                                        new TypeExpression (container.TypeBuilder, Location),
                                        Modifiers.PRIVATE, "this", null, null, loc);
                                AddField (this_field);
@@ -509,6 +510,7 @@ namespace Mono.CSharp {
                                        "field{0}_{1}", i, parameters.ParameterName (i));
 
                                parameter_fields [i] = new Field (
+                                       this,
                                        new TypeExpression (parameters.ParameterType (i), loc),
                                        Modifiers.PRIVATE, fname, null, null, loc);
                                AddField (parameter_fields [i]);
@@ -637,7 +639,7 @@ namespace Mono.CSharp {
                void Define_MoveNext ()
                {
                        Method move_next = new Method (
-                               this, TypeManager.system_boolean_expr,
+                               this, null, TypeManager.system_boolean_expr,
                                Modifiers.PUBLIC, false, new MemberName ("MoveNext"),
                                Parameters.EmptyReadOnlyParameters, null,
                                Location.Null);
@@ -666,7 +668,7 @@ namespace Mono.CSharp {
                        MemberName name = new MemberName (left, "GetEnumerator", null);
 
                        Method get_enumerator = new Method (
-                               this, type, 0, false, name,
+                               this, null, type, 0, false, name,
                                Parameters.EmptyReadOnlyParameters, null,
                                Location.Null);
                        AddMethod (get_enumerator);
@@ -883,7 +885,7 @@ namespace Mono.CSharp {
                void Define_Reset ()
                {
                        Method reset = new Method (
-                               this, TypeManager.system_void_expr, Modifiers.PUBLIC,
+                               this, null, TypeManager.system_void_expr, Modifiers.PUBLIC,
                                false, new MemberName ("Reset"),
                                Parameters.EmptyReadOnlyParameters, null, Location);
                        AddMethod (reset);
@@ -895,7 +897,7 @@ namespace Mono.CSharp {
                void Define_Dispose ()
                {
                        dispose = new Method (
-                               this, TypeManager.system_void_expr, Modifiers.PUBLIC,
+                               this, null, TypeManager.system_void_expr, Modifiers.PUBLIC,
                                false, new MemberName ("Dispose"),
                                Parameters.EmptyReadOnlyParameters, null, Location);
                        AddMethod (dispose);
index 52b2618df140741b7d4ee4865dfe7b05a3552c3f..da4bcfdc4bf7ffb2cfea40e70271779191a8b694 100755 (executable)
@@ -113,7 +113,7 @@ namespace Mono.CSharp {
                        // If we do not have static constructors, static methods
                        // can be invoked without initializing the type.
                        if (!caller.UserDefinedStaticConstructor &&
-                           !(caller is Interface))
+                           (caller.Kind != Kind.Interface))
                                t |= TypeAttributes.BeforeFieldInit;
                                
                        return t;
index 00d77a6e423eb4cb1afedfc21ce5301faf1f4cc9..1963633a958a20b8f7bc43c85b33102955422cc5 100755 (executable)
@@ -590,7 +590,7 @@ namespace Mono.CSharp {
                /// </summary>
                public void VerifyUsing ()
                {
-                       TypeContainer dummy = new TypeContainer ();
+                       TypeContainer dummy = new RootTypes ();
                        EmitContext ec = new EmitContext (
                                dummy, Location.Null, null, null, 0, false);
 
index d1969d032fc340196f5a3d76cbfcd1bdaf28591f..aa14964408c42ee63063a7b1fd21edfebeb4136d 100755 (executable)
@@ -150,7 +150,7 @@ namespace Mono.CSharp {
                                Type t = missing.Type;
                                
                                if (t is TypeBuilder){
-                                       Interface iface;
+                                       TypeContainer iface;
 
                                        iface = TypeManager.LookupInterface (t);
                                        
index 0ebfe6737293616cadc77ba0b2895fee354742b3..b07fe6aea0ffa0f709ba3957d153ffc623321cbd 100644 (file)
@@ -199,7 +199,6 @@ namespace Mono.CSharp {
                        return sb.ToString ();
                }
                
-               [Obsolete ("Use SymbolRelatedToPreviousError for better error description")]
                static public void LocationOfPreviousError (Location loc)
                {
                        Console.WriteLine (String.Format ("{0}({1}) (Location of symbol related to previous error)", loc.Name, loc.Row));
index 8b5027e3696a44c4b49b7668646db1cc92ccbd1f..8239ea423f62ddf47cf6c36d71a962b28488cf28 100755 (executable)
@@ -46,7 +46,6 @@ namespace Mono.CSharp {
                // override).
                //
                static ArrayList type_container_resolve_order;
-               static ArrayList interface_resolve_order;
                static ArrayList attribute_types;
 
                //
@@ -83,7 +82,6 @@ namespace Mono.CSharp {
                static RootContext ()
                {
                        tree = new Tree ();
-                       interface_resolve_order = new ArrayList ();
                        type_container_resolve_order = new ArrayList ();
                }
 
@@ -101,11 +99,6 @@ namespace Mono.CSharp {
 
                static public string MainClass;
                
-               public static void RegisterOrder (Interface iface)
-               {
-                       interface_resolve_order.Add (iface);
-               }
-               
                public static void RegisterOrder (TypeContainer tc)
                {
                        type_container_resolve_order.Add (tc);
@@ -427,9 +420,6 @@ namespace Mono.CSharp {
                                foreach (TypeContainer tc in attribute_types)
                                        tc.CloseType ();
                        
-                       foreach (Interface iface in interface_resolve_order)
-                               iface.CloseType ();
-
                        //
                        // We do this in two passes, first we close the structs,
                        // then the classes, because it seems the code needs it this
@@ -437,13 +427,13 @@ namespace Mono.CSharp {
                        // make sure that we define the structs in order as well.
                        //
                        foreach (TypeContainer tc in type_container_resolve_order){
-                               if (tc is Struct && tc.Parent == tree.Types){
+                               if (tc.Kind == Kind.Struct && tc.Parent == tree.Types){
                                        tc.CloseType ();
                                }
                        }
 
                        foreach (TypeContainer tc in type_container_resolve_order){
-                               if (!(tc is Struct && tc.Parent == tree.Types))
+                               if (!(tc.Kind == Kind.Struct && tc.Parent == tree.Types))
                                        tc.CloseType ();                                        
                        }
                        
@@ -461,7 +451,6 @@ namespace Mono.CSharp {
                        }
                        
                        attribute_types = null;
-                       interface_resolve_order = null;
                        type_container_resolve_order = null;
                        helper_classes = null;
                        //tree = null;
@@ -586,20 +575,6 @@ namespace Mono.CSharp {
                        return LookupType (tc, name, true, loc);
                }
 
-               static public bool IsNamespace (string name)
-               {
-                       Namespace ns;
-
-                       if (tree.Namespaces != null){
-                               ns = (Namespace) tree.Namespaces [name];
-
-                               if (ns != null)
-                                       return true;
-                       }
-
-                       return false;
-               }
-
                static void Report1530 (Location loc)
                {
                        Report.Error (1530, loc, "Keyword new not allowed for namespace elements");
@@ -610,7 +585,7 @@ namespace Mono.CSharp {
                        DeclSpace ds = (DeclSpace) root.GetDefinition (name);
 
                        ds.DefineMembers (root);
-                       ds.Define (root);
+                       ds.Define ();
                }
                
                static public void BootCorlib_PopulateCoreTypes ()
@@ -635,15 +610,6 @@ namespace Mono.CSharp {
                        if (attribute_types != null)
                                foreach (TypeContainer tc in attribute_types)
                                        tc.DefineMembers (root);
-                       
-                       if (interface_resolve_order != null){
-                               foreach (Interface iface in interface_resolve_order)
-                                       if ((iface.ModFlags & Modifiers.NEW) == 0)
-                                               iface.DefineMembers (root);
-                                       else
-                                               Report1530 (iface.Location);
-                       }
-
 
                        if (type_container_resolve_order != null){
                                if (RootContext.StdLib){
@@ -710,14 +676,7 @@ namespace Mono.CSharp {
 
                        if (attribute_types != null)
                                foreach (TypeContainer tc in attribute_types)
-                                       tc.Define (root);
-                       
-                       if (interface_resolve_order != null){
-                               foreach (Interface iface in interface_resolve_order)
-                                       if ((iface.ModFlags & Modifiers.NEW) == 0)
-                                               iface.Define (root);
-                       }
-
+                                       tc.Define ();
 
                        if (type_container_resolve_order != null){
                                foreach (TypeContainer tc in type_container_resolve_order) {
@@ -730,7 +689,7 @@ namespace Mono.CSharp {
                                                continue;
 
                                        if ((tc.ModFlags & Modifiers.NEW) == 0)
-                                               tc.Define (root);
+                                               tc.Define ();
                                }
                        }
 
@@ -738,14 +697,14 @@ namespace Mono.CSharp {
                        if (delegates != null){
                                foreach (Delegate d in delegates)
                                        if ((d.ModFlags & Modifiers.NEW) == 0)
-                                               d.Define (root);
+                                               d.Define ();
                        }
 
                        ArrayList enums = root.Enums;
                        if (enums != null){
                                foreach (Enum en in enums)
                                        if ((en.ModFlags & Modifiers.NEW) == 0)
-                                               en.Define (root);
+                                               en.Define ();
                        }
                }
 
@@ -753,32 +712,27 @@ namespace Mono.CSharp {
                {
                        if (attribute_types != null)
                                foreach (TypeContainer tc in attribute_types)
-                                       tc.Emit ();
+                                       tc.EmitType ();
 
                        CodeGen.Assembly.Emit (Tree.Types);
                        CodeGen.Module.Emit (Tree.Types);
                         
                        if (Tree.Types.Enums != null) {
                                foreach (Enum e in Tree.Types.Enums)
-                                       e.Emit (Tree.Types);
+                                       e.Emit ();
                        }
 
-                        if (interface_resolve_order != null){
-                               foreach (Interface iface in interface_resolve_order)
-                                       iface.Emit (Tree.Types);
-                       }                        
-                       
                        if (type_container_resolve_order != null) {
                                foreach (TypeContainer tc in type_container_resolve_order)
                                        tc.EmitConstants ();
                                
                                foreach (TypeContainer tc in type_container_resolve_order)
-                                       tc.Emit ();
+                                       tc.EmitType ();
                        }
                        
                        if (Tree.Types.Delegates != null) {
                                foreach (Delegate d in Tree.Types.Delegates)
-                                       d.Emit (Tree.Types);
+                                       d.Emit ();
                        }                       
                        //
                        // Run any hooks after all the types have been defined.
index 0267f451d94ab24e91fff3a28be510f8f824d250..684450d678d9289e6a2ba7ab075c8bba5ee2ebab 100755 (executable)
@@ -33,11 +33,6 @@ namespace Mono.CSharp
        public class Tree {
                TypeContainer root_types;
 
-               // <summary>
-               //  Keeps track of namespaces defined in the source code
-               // </summary>
-               Hashtable namespaces;
-
                // <summary>
                //   Keeps track of all the types definied (classes, structs, ifaces, enums)
                // </summary>
@@ -45,19 +40,31 @@ namespace Mono.CSharp
                
                public Tree ()
                {
-                       root_types = new TypeContainer ();
+                       root_types = new RootTypes ();
 
                        decls = new Hashtable ();
-                       namespaces = new Hashtable ();
                }
 
                DoubleHash decl_ns_name = new DoubleHash ();
                
                public void RecordDecl (string name, DeclSpace ds)
                {
-                       if (decls.Contains (name)){
                                DeclSpace other = (DeclSpace) decls [name];
-                               Report.SymbolRelatedToPreviousError (other.Location, other.GetSignatureForError ());
+                       if (other != null){
+                               PartialContainer other_pc = other as PartialContainer;
+                               if ((ds is TypeContainer) && (other_pc != null)) {
+                                       Report.Error (
+                                               260, ds.Location, "Missing partial modifier " +
+                                               "on declaration of type `{0}'; another " +
+                                               "partial implementation of this type exists",
+                                               name);
+
+                                       Report.LocationOfPreviousError (other.Location);
+                                       return;
+                               }
+
+                               Report.SymbolRelatedToPreviousError (
+                                       other.Location, other.GetSignatureForError ());
 
                                Report.Error (
                                        101, ds.Location,
@@ -85,26 +92,6 @@ namespace Mono.CSharp
                        return (DeclSpace) res;
                }
                
-               public NamespaceEntry RecordNamespace (NamespaceEntry parent, SourceFile file, string name, Location loc)
-               {
-                       NamespaceEntry ns = new NamespaceEntry (parent, file, name, loc);
-
-                       if (namespaces.Contains (file)){
-                               Hashtable ns_ns = (Hashtable) namespaces [file];
-
-                               if (ns_ns.Contains (ns.FullName))
-                                       return (NamespaceEntry) ns_ns [ns.FullName];
-                               ns_ns.Add (ns.FullName, ns);
-                       } else {
-                               Hashtable new_table = new Hashtable ();
-                               namespaces [file] = new_table;
-
-                               new_table.Add (ns.FullName, ns);
-                       }
-
-                       return ns;
-               }
-
                //
                // FIXME: Why are we using Types?
                //
@@ -119,11 +106,23 @@ namespace Mono.CSharp
                                return decls;
                        }
                }
+       }
 
-               public Hashtable Namespaces {
-                       get {
-                               return namespaces;
+       public class RootTypes : TypeContainer
+       {
+               public RootTypes ()
+                       : base (null, null, MemberName.Null, null, Kind.Root,
+                               new Location (-1))
+               { }
+
+               public override void Register ()
+               {
+                       throw new InvalidOperationException ();
                        }
+
+               public override PendingImplementation GetPendingImplementations ()
+               {
+                       throw new InvalidOperationException ();
                }
        }
 }
index 3d6ec8eec9900a9dfa3a82f8ea075bb2ad540e2d..5edfc8279e27391315072b498d60845cec377c48 100755 (executable)
@@ -527,9 +527,13 @@ public class TypeManager {
                return TypeHandle.GetTypeHandle (t);
        }
 
-       public static Interface LookupInterface (Type t)
+       public static TypeContainer LookupInterface (Type t)
        {
-               return builder_to_declspace [t] as Interface;
+               TypeContainer tc = (TypeContainer) builder_to_declspace [t];
+               if ((tc == null) || (tc.Kind != Kind.Interface))
+                       return null;
+
+               return tc;
        }
 
        public static Delegate LookupDelegate (Type t)
@@ -1704,12 +1708,11 @@ public class TypeManager {
        
        public static bool IsInterfaceType (Type t)
        {
-               Interface iface = builder_to_declspace [t] as Interface;
-
-               if (iface != null)
-                       return true;
-               else
+               TypeContainer tc = (TypeContainer) builder_to_declspace [t];
+               if (tc == null)
                        return false;
+
+               return tc.Kind == Kind.Interface;
        }
 
        public static bool IsEqualGenericType (Type a, Type b)
@@ -2178,7 +2181,7 @@ public class TypeManager {
        public static bool CheckStructCycles (TypeContainer tc, Hashtable seen,
                                              Hashtable hash)
        {
-               if (!(tc is Struct) || IsBuiltinType (tc))
+               if ((tc.Kind != Kind.Struct) || IsBuiltinType (tc))
                        return true;
 
                //
@@ -2571,7 +2574,7 @@ public class TypeManager {
 
                if (t is TypeBuilder) {
                        if (t.IsInterface) {
-                               Interface i = LookupInterface (t);
+                               TypeContainer i = LookupInterface (t);
 
                                if ((i == null) || (i.IndexerName == null))
                                        return "Item";