2003-08-26 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Tue, 26 Aug 2003 18:50:23 +0000 (18:50 -0000)
committerMartin Baulig <martin@novell.com>
Tue, 26 Aug 2003 18:50:23 +0000 (18:50 -0000)
* decl.cs (MemberCore): Moved WarningNotHiding(),
Error_CannotChangeAccessModifiers() and CheckMethodAgainstBase()
into MemberBase.
(AdditionResult): Make this nested in DeclSpace.
(DeclSpace.ctor): The .ctor now takes an additional NamespaceEntry
argument; call NamespaceEntry.Define() unless we're nested in a
class or struct.

* namespace.cs (Namespace.DefineName): New public function.  This
is called from DeclSpace's .ctor to add
(Namespace.Lookup): Include DeclSpaces in the lookup.

* class.cs (Operator): Derive from MemberBase, not MemberCore.

* const.cs (Const): Derive from MemberBase, not MemberCore.

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

mcs/mcs/ChangeLog
mcs/mcs/class.cs
mcs/mcs/const.cs
mcs/mcs/cs-parser.jay
mcs/mcs/decl.cs
mcs/mcs/delegate.cs
mcs/mcs/enum.cs
mcs/mcs/interface.cs
mcs/mcs/namespace.cs
mcs/mcs/rootcontext.cs
mcs/mcs/tree.cs

index b48aa67c894c24b36ab6ab0767141e6b396ccadd..fa1fbb29d2a7f4bdd785d4c5567c4e513c5e161b 100755 (executable)
@@ -1,3 +1,21 @@
+2003-08-26  Martin Baulig  <martin@ximian.com>
+
+       * decl.cs (MemberCore): Moved WarningNotHiding(),
+       Error_CannotChangeAccessModifiers() and CheckMethodAgainstBase()
+       into MemberBase.
+       (AdditionResult): Make this nested in DeclSpace.
+       (DeclSpace.ctor): The .ctor now takes an additional NamespaceEntry
+       argument; call NamespaceEntry.Define() unless we're nested in a
+       class or struct.
+
+       * namespace.cs (Namespace.DefineName): New public function.  This
+       is called from DeclSpace's .ctor to add 
+       (Namespace.Lookup): Include DeclSpaces in the lookup.
+
+       * class.cs (Operator): Derive from MemberBase, not MemberCore.
+
+       * const.cs (Const): Derive from MemberBase, not MemberCore.     
+
 2003-08-25  Martin Baulig  <martin@ximian.com>
 
        * convert.cs (Convert.ExplicitReferenceConversion): When
index 50c168055980350eca426663f7c3976b068dfcc6..b580801ad3e62158fc5694f6095eaab4efda7590 100755 (executable)
@@ -134,8 +134,8 @@ namespace Mono.CSharp {
                //
                public string IndexerName;
 
-               public TypeContainer (TypeContainer parent, string name, Location l)
-                       : base (parent, name, l)
+               public TypeContainer (NamespaceEntry ns, TypeContainer parent, string name, Location l)
+                       : base (ns, parent, name, l)
                {
                        string n;
                        types = new ArrayList ();
@@ -885,7 +885,7 @@ namespace Mono.CSharp {
                                if (idx < 0){
                                        if (RootContext.WarningLevel >= 4){
                                                if ((mc.ModFlags & Modifiers.NEW) != 0)
-                                                       Warning_KewywordNewNotRequired (mc.Location, mc);
+                                                       Warning_KeywordNewNotRequired (mc.Location, mc);
                                        }
                                } else if (mc is MethodCore)
                                        ((MethodCore) mc).OverridesSomething = true;
@@ -1625,7 +1625,7 @@ namespace Mono.CSharp {
                                mi.ReflectedType.Name + "." + mi.Name + "'");
                }
 
-               public void Warning_KewywordNewNotRequired (Location l, MemberCore mc)
+               public void Warning_KeywordNewNotRequired (Location l, MemberCore mc)
                {
                        Report.Warning (
                                109, l, "The member " + MakeName (mc.Name) + " does not hide an " +
@@ -2095,8 +2095,8 @@ namespace Mono.CSharp {
                        Modifiers.SEALED |
                        Modifiers.UNSAFE;
 
-               public Class (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
-                       : base (parent, name, l)
+               public Class (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
+                       : base (ns, parent, name, l)
                {
                        int accmods;
 
@@ -2132,8 +2132,8 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE    |
                        Modifiers.PRIVATE;
 
-               public Struct (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
-                       : base (parent, name, l)
+               public Struct (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
+                       : base (ns, parent, name, l)
                {
                        int accmods;
                        
@@ -2181,7 +2181,7 @@ namespace Mono.CSharp {
 
                public MethodCore (Expression type, int mod, int allowed_mod, string name,
                                   Attributes attrs, Parameters parameters, Location loc)
-                       : base (type, mod, allowed_mod, name, attrs, loc)
+                       : base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
                {
                        Parameters = parameters;
                }
@@ -3476,12 +3476,12 @@ namespace Mono.CSharp {
                //
                // The constructor is only exposed to our children
                //
-               protected MemberBase (Expression type, int mod, int allowed_mod, string name,
+               protected MemberBase (Expression type, int mod, int allowed_mod, int def_mod, string name,
                                      Attributes attrs, Location loc)
                        : base (name, loc)
                {
                        Type = type;
-                       ModFlags = Modifiers.Check (allowed_mod, mod, Modifiers.PRIVATE, loc);
+                       ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, loc);
                        OptAttributes = attrs;
                }
 
@@ -3499,6 +3499,153 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               protected void WarningNotHiding (TypeContainer parent)
+               {
+                       Report.Warning (
+                               109, Location,
+                               "The member " + parent.MakeName (Name) + " does not hide an " +
+                               "inherited member.  The keyword new is not required");
+                                                          
+               }
+
+               void Error_CannotChangeAccessModifiers (TypeContainer parent, MethodInfo parent_method,
+                                                       string name)
+               {
+                       //
+                       // FIXME: report the old/new permissions?
+                       //
+                       Report.Error (
+                               507, Location, parent.MakeName (Name) +
+                               ": can't change the access modifiers when overriding inherited " +
+                               "member `" + name + "'");
+               }
+               
+               //
+               // Performs various checks on the MethodInfo `mb' regarding the modifier flags
+               // that have been defined.
+               //
+               // `name' is the user visible name for reporting errors (this is used to
+               // provide the right name regarding method names and properties)
+               //
+               protected bool CheckMethodAgainstBase (TypeContainer parent, MethodAttributes my_attrs,
+                                                      MethodInfo mb, string name)
+               {
+                       bool ok = true;
+                       
+                       if ((ModFlags & Modifiers.OVERRIDE) != 0){
+                               if (!(mb.IsAbstract || mb.IsVirtual)){
+                                       Report.Error (
+                                               506, Location, parent.MakeName (Name) +
+                                               ": cannot override inherited member `" +
+                                               name + "' because it is not " +
+                                               "virtual, abstract or override");
+                                       ok = false;
+                               }
+                               
+                               // Now we check that the overriden method is not final
+                               
+                               if (mb.IsFinal) {
+                                       // This happens when implementing interface methods.
+                                       if (mb.IsHideBySig && mb.IsVirtual) {
+                                               Report.Error (
+                                                       506, Location, parent.MakeName (Name) +
+                                                       ": cannot override inherited member `" +
+                                                       name + "' because it is not " +
+                                                       "virtual, abstract or override");
+                                       } else
+                                               Report.Error (239, Location, parent.MakeName (Name) + " : cannot " +
+                                                             "override inherited member `" + name +
+                                                             "' because it is sealed.");
+                                       ok = false;
+                               }
+                               //
+                               // Check that the permissions are not being changed
+                               //
+                               MethodAttributes thisp = my_attrs & MethodAttributes.MemberAccessMask;
+                               MethodAttributes parentp = mb.Attributes & MethodAttributes.MemberAccessMask;
+
+                               //
+                               // special case for "protected internal"
+                               //
+
+                               if ((parentp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
+                                       //
+                                       // when overriding protected internal, the method can be declared
+                                       // protected internal only within the same assembly
+                                       //
+
+                                       if ((thisp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
+                                               if (parent.TypeBuilder.Assembly != mb.DeclaringType.Assembly){
+                                                       //
+                                                       // assemblies differ - report an error
+                                                       //
+                                                       
+                                                       Error_CannotChangeAccessModifiers (parent, mb, name);
+                                                   ok = false;
+                                               } else if (thisp != parentp) {
+                                                       //
+                                                       // same assembly, but other attributes differ - report an error
+                                                       //
+                                                       
+                                                       Error_CannotChangeAccessModifiers (parent, mb, name);
+                                                       ok = false;
+                                               };
+                                       } else if ((thisp & MethodAttributes.Family) != MethodAttributes.Family) {
+                                               //
+                                               // if it's not "protected internal", it must be "protected"
+                                               //
+
+                                               Error_CannotChangeAccessModifiers (parent, mb, name);
+                                               ok = false;
+                                       } else if (parent.TypeBuilder.Assembly == mb.DeclaringType.Assembly) {
+                                               //
+                                               // protected within the same assembly - an error
+                                               //
+                                               Error_CannotChangeAccessModifiers (parent, mb, name);
+                                               ok = false;
+                                       } else if ((thisp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem)) != 
+                                                  (parentp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem))) {
+                                               //
+                                               // protected ok, but other attributes differ - report an error
+                                               //
+                                               Error_CannotChangeAccessModifiers (parent, mb, name);
+                                               ok = false;
+                                       }
+                               } else {
+                                       if (thisp != parentp){
+                                               Error_CannotChangeAccessModifiers (parent, mb, name);
+                                               ok = false;
+                                       }
+                               }
+                       }
+
+                       if (mb.IsVirtual || mb.IsAbstract){
+                               if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0){
+                                       if (Name != "Finalize"){
+                                               Report.Warning (
+                                                       114, 2, Location, parent.MakeName (Name) + 
+                                                       " hides inherited member `" + name +
+                                                       "'.  To make the current member override that " +
+                                                       "implementation, add the override keyword, " +
+                                                       "otherwise use the new keyword");
+                                               ModFlags |= Modifiers.NEW;
+                                       }
+                               }
+                       } else {
+                               if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0){
+                                       if (Name != "Finalize"){
+                                               Report.Warning (
+                                                       108, 1, Location, "The keyword new is required on " +
+                                                       parent.MakeName (Name) + " because it hides " +
+                                                       "inherited member `" + name + "'");
+                                               ModFlags |= Modifiers.NEW;
+                                       }
+                               }
+                       }
+
+                       return ok;
+               }
+
                protected virtual bool CheckParameters (TypeContainer container, Type [] parameters)
                {
                        bool error = false;
@@ -3638,7 +3785,7 @@ namespace Mono.CSharp {
                //
                protected FieldBase (Expression type, int mod, int allowed_mod, string name,
                                     object init, Attributes attrs, Location loc)
-                       : base (type, mod, allowed_mod, name, attrs, loc)
+                       : base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
                {
                        this.init = init;
                }
@@ -4589,7 +4736,7 @@ namespace Mono.CSharp {
                }
        }
 
-       public class Operator : MemberCore {
+       public class Operator : MemberBase {
 
                const int AllowedModifiers =
                        Modifiers.PUBLIC |
@@ -4644,27 +4791,24 @@ namespace Mono.CSharp {
                public readonly Expression FirstArgType, SecondArgType;
                public readonly string FirstArgName, SecondArgName;
                public Block           Block;
-               public Attributes      OptAttributes;
                public MethodBuilder   OperatorMethodBuilder;
                
                public string MethodName;
                public Method OperatorMethod;
 
-               public Operator (OpType type, Expression ret_type, int flags,
+               public Operator (OpType type, Expression ret_type, int mod_flags,
                                 Expression arg1type, string arg1name,
                                 Expression arg2type, string arg2name,
                                 Block block, Attributes attrs, Location loc)
-                       : base ("", loc)
+                       : base (ret_type, mod_flags, AllowedModifiers, Modifiers.PUBLIC, "", attrs, loc)
                {
                        OperatorType = type;
                        ReturnType = ret_type;
-                       ModFlags = Modifiers.Check (AllowedModifiers, flags, Modifiers.PUBLIC, loc);
                        FirstArgType = arg1type;
                        FirstArgName = arg1name;
                        SecondArgType = arg2type;
                        SecondArgName = arg2name;
                        Block = block;
-                       OptAttributes = attrs;
                }
 
                string Prototype (TypeContainer container)
index 4f54d70e887f0ba17388f384a81fe28fb700800e..fc7a29f672730e70660c52525c633ba879565f9d 100755 (executable)
@@ -24,10 +24,9 @@ namespace Mono.CSharp {
        using System.Reflection.Emit;
        using System.Collections;
 
-       public class Const : MemberCore {
+       public class Const : MemberBase {
                public Expression ConstantType;
                public Expression Expr;
-               public Attributes  OptAttributes;
                public FieldBuilder FieldBuilder;
                EmitContext const_ec;
 
@@ -45,13 +44,11 @@ namespace Mono.CSharp {
 
                public Const (Expression constant_type, string name, Expression expr, int mod_flags,
                              Attributes attrs, Location loc)
-                       : base (name, loc)
+                       : base (constant_type, mod_flags, AllowedModifiers, Modifiers.PRIVATE, name, attrs, loc)
                {
                        ConstantType = constant_type;
                        Name = name;
                        Expr = expr;
-                       ModFlags = Modifiers.Check (AllowedModifiers, mod_flags, Modifiers.PRIVATE, loc);
-                       OptAttributes = attrs;
                }
 
                public FieldAttributes FieldAttr {
@@ -98,7 +95,7 @@ namespace Mono.CSharp {
                        if (ptype != null) {
                                MemberList list = TypeContainer.FindMembers (
                                        ptype, MemberTypes.Field, BindingFlags.Public,
-                                       Type.FilterName, Name);
+                                       System.Type.FilterName, Name);
                                
                                if (list.Count == 0)
                                        if ((ModFlags & Modifiers.NEW) != 0)
index aa61878730a43bff26f53daa8542b575cb3f1346..e053aa6fdc666138c1c993bd59ac2ffdbea53414 100755 (executable)
@@ -341,7 +341,7 @@ namespace_declaration
                                        + " Expected class, delegate, enum, interface, or struct");
                }
 
-               current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, (string) $3);
+               current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, (string) $3, lexer.Location);
        } 
          namespace_body opt_semicolon
          { 
@@ -667,10 +667,9 @@ struct_declaration
                Struct new_struct;
                string full_struct_name = MakeName ((string) $4);
 
-               new_struct = new Struct (current_container, full_struct_name, (int) $2, 
-                                        (Attributes) $1, lexer.Location);
+               new_struct = new Struct (current_namespace, current_container, full_struct_name,
+                                        (int) $2, (Attributes) $1, lexer.Location);
                current_container = new_struct;
-               current_container.NamespaceEntry = current_namespace;
                RootContext.Tree.RecordDecl (full_struct_name, new_struct);
          }
          opt_class_base
@@ -1132,14 +1131,13 @@ interface_declaration
                Interface new_interface;
                string full_interface_name = MakeName ((string) $4);
 
-               new_interface = new Interface (current_container, full_interface_name, (int) $2, 
-                                              (Attributes) $1, lexer.Location);
+               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");
                }
                current_interface = new_interface;
-               new_interface.NamespaceEntry = current_namespace;
                RootContext.Tree.RecordDecl (full_interface_name, new_interface);
          }
          opt_interface_base
@@ -1750,8 +1748,8 @@ enum_declaration
                Location enum_location = lexer.Location;
 
                string full_name = MakeName ((string) $4);
-               Enum e = new Enum (current_container, (Expression) $5, (int) $2, full_name, 
-                                  (Attributes) $1, enum_location);
+               Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
+                                  full_name, (Attributes) $1, enum_location);
                
                foreach (VariableDeclaration ev in (ArrayList) $6) {
                        Location loc = (Location) ev.Location;
@@ -1762,8 +1760,6 @@ enum_declaration
                                  ev.identifier, loc);
                }
 
-               e.NamespaceEntry = current_namespace;
-
                CheckDef (current_container.AddEnum (e), full_name, enum_location);
                RootContext.Tree.RecordDecl (full_name, e);
 
@@ -1830,11 +1826,10 @@ delegate_declaration
          SEMICOLON
          {
                Location l = lexer.Location;
-               Delegate del = new Delegate (current_container, (Expression) $4, (int) $2, 
-                                            MakeName ((string) $5), (Parameters) $7, 
+               Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
+                                            (int) $2, MakeName ((string) $5), (Parameters) $7, 
                                             (Attributes) $1, l);
                  
-               del.NamespaceEntry = current_namespace;
                CheckDef (current_container.AddDelegate (del), del.Name, l);
          }     
        | opt_attributes
@@ -1847,11 +1842,10 @@ delegate_declaration
          {
                Location l = lexer.Location;
                Delegate del = new Delegate (
-                       current_container,
+                       current_namespace, current_container,
                        TypeManager.system_void_expr, (int) $2, MakeName ((string) $5), 
                        (Parameters) $7, (Attributes) $1, l);
 
-               del.NamespaceEntry = current_namespace;
                CheckDef (current_container.AddDelegate (del), del.Name, l);
          }
        ;
@@ -2790,10 +2784,9 @@ class_declaration
 
                name = MakeName ((string) $4);
 
-               new_class = new Class (current_container, name, (int) $2, 
+               new_class = new Class (current_namespace, current_container, name, (int) $2, 
                                       (Attributes) $1, lexer.Location);
                current_container = new_class;
-               current_container.NamespaceEntry = current_namespace;
                RootContext.Tree.RecordDecl (name, new_class);
          }
          opt_class_base
@@ -3887,7 +3880,7 @@ void Error_ExpectingTypeName (Location l, Expression expr)
 string 
 MakeName (string class_name)
 {
-       string ns = current_namespace.Name;
+       string ns = current_namespace.FullName;
        string container_name = current_container.Name;
 
        if (container_name == ""){
@@ -3904,13 +3897,13 @@ MakeName (string class_name)
 //   in the current declaration space
 // </summary>
 void 
-CheckDef (AdditionResult result, string name, Location l)
+CheckDef (DeclSpace.AdditionResult result, string name, Location l)
 {
-       if (result == AdditionResult.Success)
+       if (result == DeclSpace.AdditionResult.Success)
                return;
 
        switch (result){
-       case AdditionResult.NameExists:
+       case DeclSpace.AdditionResult.NameExists:
                Report.Error (102, l, "The container `" + current_container.Name + 
                                 "' already contains a definition for `"+
                                 name + "'");
@@ -3921,22 +3914,22 @@ CheckDef (AdditionResult result, string name, Location l)
                // This is handled only for static Constructors, because
                // in reality we handle these by the semantic analysis later
                //
-       case AdditionResult.MethodExists:
+       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 AdditionResult.EnclosingClash:
+       case DeclSpace.AdditionResult.EnclosingClash:
                Report.Error (542, l, "Member names cannot be the same as their enclosing type");
                break;
                
-       case AdditionResult.NotAConstructor:
+       case DeclSpace.AdditionResult.NotAConstructor:
                Report.Error (1520, l, "Class, struct, or interface method must have a return type");
                break;
 
-       case AdditionResult.Error:
+       case DeclSpace.AdditionResult.Error:
                // Error has already been reported.
                break;
        }
@@ -3947,7 +3940,7 @@ CheckDef (bool result, string name, Location l)
 {
        if (result)
                return;
-       CheckDef (AdditionResult.NameExists, name, l);
+       CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
 }
 
 Expression DecomposeQI (string name, Location loc)
@@ -4159,7 +4152,7 @@ public Tokenizer Lexer {
 
 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
 {
-       current_namespace = new NamespaceEntry (null, file, null);
+       current_namespace = new NamespaceEntry (null, file, null, Location.Null);
        this.name = file.Name;
        this.file = file;
        current_container = RootContext.Tree.Types;
@@ -4183,6 +4176,7 @@ public override void parse ()
                // Please do not remove this, it is used during debugging
                // of the grammar
                //
+               Console.WriteLine (e);
                Report.Error (-25, lexer.Location, "Parsing error");
                if (Driver.parser_verbose)
                        Console.WriteLine (e);
index f528e1be5dcc3ec7540bd843569a967bdd9ddb41..f3edd9474c0bcd9e5e7f83ff23017c3a520c819d 100755 (executable)
@@ -43,153 +43,6 @@ namespace Mono.CSharp {
                        Location = loc;
                }
 
-               protected void WarningNotHiding (TypeContainer parent)
-               {
-                       Report.Warning (
-                               109, Location,
-                               "The member " + parent.MakeName (Name) + " does not hide an " +
-                               "inherited member.  The keyword new is not required");
-                                                          
-               }
-
-               void Error_CannotChangeAccessModifiers (TypeContainer parent, MethodInfo parent_method,
-                                                       string name)
-               {
-                       //
-                       // FIXME: report the old/new permissions?
-                       //
-                       Report.Error (
-                               507, Location, parent.MakeName (Name) +
-                               ": can't change the access modifiers when overriding inherited " +
-                               "member `" + name + "'");
-               }
-               
-               //
-               // Performs various checks on the MethodInfo `mb' regarding the modifier flags
-               // that have been defined.
-               //
-               // `name' is the user visible name for reporting errors (this is used to
-               // provide the right name regarding method names and properties)
-               //
-               protected bool CheckMethodAgainstBase (TypeContainer parent, MethodAttributes my_attrs,
-                                                      MethodInfo mb, string name)
-               {
-                       bool ok = true;
-                       
-                       if ((ModFlags & Modifiers.OVERRIDE) != 0){
-                               if (!(mb.IsAbstract || mb.IsVirtual)){
-                                       Report.Error (
-                                               506, Location, parent.MakeName (Name) +
-                                               ": cannot override inherited member `" +
-                                               name + "' because it is not " +
-                                               "virtual, abstract or override");
-                                       ok = false;
-                               }
-                               
-                               // Now we check that the overriden method is not final
-                               
-                               if (mb.IsFinal) {
-                                       // This happens when implementing interface methods.
-                                       if (mb.IsHideBySig && mb.IsVirtual) {
-                                               Report.Error (
-                                                       506, Location, parent.MakeName (Name) +
-                                                       ": cannot override inherited member `" +
-                                                       name + "' because it is not " +
-                                                       "virtual, abstract or override");
-                                       } else
-                                               Report.Error (239, Location, parent.MakeName (Name) + " : cannot " +
-                                                             "override inherited member `" + name +
-                                                             "' because it is sealed.");
-                                       ok = false;
-                               }
-                               //
-                               // Check that the permissions are not being changed
-                               //
-                               MethodAttributes thisp = my_attrs & MethodAttributes.MemberAccessMask;
-                               MethodAttributes parentp = mb.Attributes & MethodAttributes.MemberAccessMask;
-
-                               //
-                               // special case for "protected internal"
-                               //
-
-                               if ((parentp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
-                                       //
-                                       // when overriding protected internal, the method can be declared
-                                       // protected internal only within the same assembly
-                                       //
-
-                                       if ((thisp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
-                                               if (parent.TypeBuilder.Assembly != mb.DeclaringType.Assembly){
-                                                       //
-                                                       // assemblies differ - report an error
-                                                       //
-                                                       
-                                                       Error_CannotChangeAccessModifiers (parent, mb, name);
-                                                   ok = false;
-                                               } else if (thisp != parentp) {
-                                                       //
-                                                       // same assembly, but other attributes differ - report an error
-                                                       //
-                                                       
-                                                       Error_CannotChangeAccessModifiers (parent, mb, name);
-                                                       ok = false;
-                                               };
-                                       } else if ((thisp & MethodAttributes.Family) != MethodAttributes.Family) {
-                                               //
-                                               // if it's not "protected internal", it must be "protected"
-                                               //
-
-                                               Error_CannotChangeAccessModifiers (parent, mb, name);
-                                               ok = false;
-                                       } else if (parent.TypeBuilder.Assembly == mb.DeclaringType.Assembly) {
-                                               //
-                                               // protected within the same assembly - an error
-                                               //
-                                               Error_CannotChangeAccessModifiers (parent, mb, name);
-                                               ok = false;
-                                       } else if ((thisp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem)) != 
-                                                  (parentp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem))) {
-                                               //
-                                               // protected ok, but other attributes differ - report an error
-                                               //
-                                               Error_CannotChangeAccessModifiers (parent, mb, name);
-                                               ok = false;
-                                       }
-                               } else {
-                                       if (thisp != parentp){
-                                               Error_CannotChangeAccessModifiers (parent, mb, name);
-                                               ok = false;
-                                       }
-                               }
-                       }
-
-                       if (mb.IsVirtual || mb.IsAbstract){
-                               if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0){
-                                       if (Name != "Finalize"){
-                                               Report.Warning (
-                                                       114, 2, Location, parent.MakeName (Name) + 
-                                                       " hides inherited member `" + name +
-                                                       "'.  To make the current member override that " +
-                                                       "implementation, add the override keyword, " +
-                                                       "otherwise use the new keyword");
-                                               ModFlags |= Modifiers.NEW;
-                                       }
-                               }
-                       } else {
-                               if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0){
-                                       if (Name != "Finalize"){
-                                               Report.Warning (
-                                                       108, 1, Location, "The keyword new is required on " +
-                                                       parent.MakeName (Name) + " because it hides " +
-                                                       "inherited member `" + name + "'");
-                                               ModFlags |= Modifiers.NEW;
-                                       }
-                               }
-                       }
-
-                       return ok;
-               }
-
                public abstract bool Define (TypeContainer parent);
 
                // 
@@ -211,10 +64,54 @@ namespace Mono.CSharp {
                }
        }
 
-       //
-       // FIXME: This is temporary outside DeclSpace, because I have to fix a bug
-       // in MCS that makes it fail the lookup for the enum
-       //
+       /// <summary>
+       ///   Base class for structs, classes, enumerations and interfaces.  
+       /// </summary>
+       /// <remarks>
+       ///   They all create new declaration spaces.  This
+       ///   provides the common foundation for managing those name
+       ///   spaces.
+       /// </remarks>
+       public abstract class DeclSpace : MemberCore {
+               /// <summary>
+               ///   this points to the actual definition that is being
+               ///   created with System.Reflection.Emit
+               /// </summary>
+               public TypeBuilder TypeBuilder;
+
+               /// <summary>
+               ///   This variable tracks whether we have Closed the type
+               /// </summary>
+               public bool Created = false;
+               
+               //
+               // This is the namespace in which this typecontainer
+               // was declared.  We use this to resolve names.
+               //
+               public NamespaceEntry NamespaceEntry;
+
+               public Hashtable Cache = new Hashtable ();
+               
+               public string Basename;
+               
+               /// <summary>
+               ///   defined_names is used for toplevel objects
+               /// </summary>
+               protected Hashtable defined_names;
+
+               TypeContainer parent;           
+
+               public DeclSpace (NamespaceEntry ns, TypeContainer parent, string name, Location l)
+                       : base (name, l)
+               {
+                       NamespaceEntry = ns;
+                       Basename = name.Substring (1 + name.LastIndexOf ('.'));
+                       defined_names = new Hashtable ();
+                       this.parent = parent;
+
+                       if ((NamespaceEntry != null) && (parent == RootContext.Tree.Types))
+                               NamespaceEntry.DefineName (Basename, this);
+               }
 
                /// <summary>
                ///   The result value from adding an declaration into
@@ -261,51 +158,6 @@ namespace Mono.CSharp {
                        Error
                }
 
-       /// <summary>
-       ///   Base class for structs, classes, enumerations and interfaces.  
-       /// </summary>
-       /// <remarks>
-       ///   They all create new declaration spaces.  This
-       ///   provides the common foundation for managing those name
-       ///   spaces.
-       /// </remarks>
-       public abstract class DeclSpace : MemberCore {
-               /// <summary>
-               ///   this points to the actual definition that is being
-               ///   created with System.Reflection.Emit
-               /// </summary>
-               public TypeBuilder TypeBuilder;
-
-               /// <summary>
-               ///   This variable tracks whether we have Closed the type
-               /// </summary>
-               public bool Created = false;
-               
-               //
-               // This is the namespace in which this typecontainer
-               // was declared.  We use this to resolve names.
-               //
-               public NamespaceEntry NamespaceEntry;
-
-               public Hashtable Cache = new Hashtable ();
-               
-               public string Basename;
-               
-               /// <summary>
-               ///   defined_names is used for toplevel objects
-               /// </summary>
-               protected Hashtable defined_names;
-
-               TypeContainer parent;           
-
-               public DeclSpace (TypeContainer parent, string name, Location l)
-                       : base (name, l)
-               {
-                       Basename = name.Substring (1 + name.LastIndexOf ('.'));
-                       defined_names = new Hashtable ();
-                       this.parent = parent;
-               }
-
                /// <summary>
                ///   Returns a status code based purely on the name
                ///   of the member being added
@@ -708,7 +560,7 @@ namespace Mono.CSharp {
                        // Attempt to lookup the class on our namespace and all it's implicit parents
                        //
                        for (NamespaceEntry ns = NamespaceEntry; ns != null; ns = ns.ImplicitParent) {
-                               t = LookupInterfaceOrClass (ns.Name, name, out error);
+                               t = LookupInterfaceOrClass (ns.FullName, name, out error);
                                if (error)
                                        return null;
                                
@@ -733,7 +585,7 @@ namespace Mono.CSharp {
 
                        for (NamespaceEntry ns = NamespaceEntry; ns != null; ns = ns.Parent){
 
-                               t = LookupInterfaceOrClass (ns.Name, name, out error);
+                               t = LookupInterfaceOrClass (ns.FullName, name, out error);
                                if (error)
                                        return null;
 
index f46b7c87abd0069dba72dc21d113ea6caece3c2d..35a9e43a0b5794c3d9ebb800d22b264539a2ca13 100644 (file)
@@ -46,10 +46,10 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE |\r
                        Modifiers.PRIVATE;\r
 \r
-               public Delegate (TypeContainer parent, Expression type, int mod_flags,\r
-                                string name, Parameters param_list,\r
+               public Delegate (NamespaceEntry ns, TypeContainer parent, Expression type,\r
+                                int mod_flags, string name, Parameters param_list,\r
                                 Attributes attrs, Location l)\r
-                       : base (parent, name, l)\r
+                       : base (ns, parent, name, l)\r
                {\r
                        this.ReturnType = type;\r
                        ModFlags        = Modifiers.Check (AllowedModifiers, mod_flags,\r
index c6f613bfadff70ecc972304d77c7c3a8f5f0c36e..06f4c9e0cf7e8e0263c831b685f425995711340a 100755 (executable)
@@ -49,8 +49,9 @@ namespace Mono.CSharp {
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE;
 
-               public Enum (TypeContainer parent, Expression type, int mod_flags, string name, Attributes attrs, Location l)
-                       : base (parent, name, l)
+               public Enum (NamespaceEntry ns, TypeContainer parent, Expression type, int mod_flags,
+                            string name, Attributes attrs, Location l)
+                       : base (ns, parent, name, l)
                {
                        this.BaseType = type;
                        ModFlags = Modifiers.Check (AllowedModifiers, mod_flags,
index 653ab1d9ebfd4e980fc3db63adf24c0fbfb5c68a..898513cf171c47dfb331c19df2f200295468f55e 100755 (executable)
@@ -71,8 +71,9 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE    |
                        Modifiers.PRIVATE;
 
-               public Interface (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
-                       : base (parent, name, l)
+               public Interface (NamespaceEntry ns, TypeContainer parent, string name, int mod,
+                                 Attributes attrs, Location l)
+                       : base (ns, parent, name, l)
                {
                        ModFlags = Modifiers.Check (AllowedModifiers, mod, Modifiers.PRIVATE, l);
                        OptAttributes = attrs;
index 414249a3142509b12bb8b888be68b642033d1934..584a20a0ff0de975f84dfc8c67ed34f9adaeb22c 100755 (executable)
@@ -23,6 +23,7 @@ namespace Mono.CSharp {
                string name, fullname;
                ArrayList entries;
                Hashtable namespaces;
+               Hashtable defined_names;
 
                /// <summary>
                ///   Constructor Takes the current namespace and the
@@ -43,6 +44,7 @@ namespace Mono.CSharp {
 
                        entries = new ArrayList ();
                        namespaces = new Hashtable ();
+                       defined_names = new Hashtable ();
 
                        all_namespaces.Add (this);
                        if (namespaces_map.Contains (fullname))
@@ -90,11 +92,22 @@ namespace Mono.CSharp {
 
                public object Lookup (DeclSpace ds, string name)
                {
+                       object o = Lookup (name);
+
+                       Type t;
+                       DeclSpace tdecl = o as DeclSpace;
+                       if (tdecl != null) {
+                               t = tdecl.DefineType ();
+
+                               if ((ds == null) || ds.CheckAccessLevel (t))
+                                       return t;
+                       }
+
                        Namespace ns = GetNamespace (name, false);
                        if (ns != null)
                                return ns;
 
-                       Type t = TypeManager.LookupType (DeclSpace.MakeFQN (fullname, name));
+                       t = TypeManager.LookupType (DeclSpace.MakeFQN (fullname, name));
                        if ((t == null) || ((ds != null) && !ds.CheckAccessLevel (t)))
                                return null;
 
@@ -106,6 +119,16 @@ namespace Mono.CSharp {
                        entries.Add (entry);
                }
 
+               public void DefineName (string name, object o)
+               {
+                       defined_names.Add (name, o);
+               }
+
+               public object Lookup (string name)
+               {
+                       return defined_names [name];
+               }
+
                static public ArrayList UserDefinedNamespaces {
                        get {
                                return all_namespaces;
@@ -241,11 +264,11 @@ namespace Mono.CSharp {
                        }
                }
 
-               public NamespaceEntry (NamespaceEntry parent, SourceFile file, string name)
-                       : this (parent, file, name, false)
+               public NamespaceEntry (NamespaceEntry parent, SourceFile file, string name, Location loc)
+                       : this (parent, file, name, false, loc)
                { }
 
-               protected NamespaceEntry (NamespaceEntry parent, SourceFile file, string name, bool is_implicit)
+               protected NamespaceEntry (NamespaceEntry parent, SourceFile file, string name, bool is_implicit, Location loc)
                {
                        this.parent = parent;
                        this.file = file;
@@ -261,21 +284,18 @@ namespace Mono.CSharp {
                        ns.AddNamespaceEntry (this);
 
                        if ((parent != null) && (parent.NS != ns.Parent))
-                               implicit_parent = new NamespaceEntry (parent, file, ns.Parent.Name, true);
+                               implicit_parent = new NamespaceEntry (parent, file, ns.Parent.Name, true, loc);
                        else
                                implicit_parent = parent;
+
+                       this.FullName = ns.Name;
                }
 
                static int next_id = 0;
+               public readonly string FullName;
                public readonly int ID;
                public readonly bool IsImplicit;
 
-               public string Name {
-                       get {
-                               return ns.Name;
-                       }
-               }
-
                public Namespace NS {
                        get {
                                return ns;
@@ -294,6 +314,11 @@ namespace Mono.CSharp {
                        }
                }
 
+               public void DefineName (string name, object o)
+               {
+                       ns.DefineName (name, o);
+               }
+
                /// <summary>
                ///   Records a new namespace for resolving name references
                /// </summary>
@@ -304,7 +329,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       if (ns == Name)
+                       if (ns == FullName)
                                return;
                        
                        if (using_clauses == null)
@@ -561,7 +586,7 @@ namespace Mono.CSharp {
                        if (NS == Namespace.Root)
                                return "NamespaceEntry (<root>)";
                        else
-                               return String.Format ("NamespaceEntry ({0},{1},{2})", Name, IsImplicit, ID);
+                               return String.Format ("NamespaceEntry ({0},{1},{2})", FullName, IsImplicit, ID);
                }
        }
 }
index f4a3824bb286e29bbb47509654c5862594fc3ce9..67ef6b9baf236d150ed3084a1fde317ff1fe1d4a 100755 (executable)
@@ -705,7 +705,7 @@ namespace Mono.CSharp {
                        //
                        if (global_attributes.Count > 0){
                                AssemblyBuilder ab = CodeGen.AssemblyBuilder;
-                               TypeContainer dummy = new TypeContainer (null, "", new Location (-1));
+                               TypeContainer dummy = new TypeContainer (null, null, "", new Location (-1));
                                EmitContext temp_ec = new EmitContext (
                                        dummy, Mono.CSharp.Location.Null, null, null, 0, false);
                        
index 4d571375ef38e6c80e57b7163cb4ec7f23f0eb3a..21c2134a1309fca42eb32050d874bb1f9ca392df 100755 (executable)
@@ -45,7 +45,7 @@ namespace Mono.CSharp
                
                public Tree ()
                {
-                       root_types = new TypeContainer (null, "", new Location (-1));
+                       root_types = new TypeContainer (null, null, "", new Location (-1));
 
                        decls = new Hashtable ();
                        namespaces = new Hashtable ();
@@ -83,21 +83,21 @@ namespace Mono.CSharp
                        return (DeclSpace) res;
                }
                
-               public NamespaceEntry RecordNamespace (NamespaceEntry parent, SourceFile file, string name)
+               public NamespaceEntry RecordNamespace (NamespaceEntry parent, SourceFile file, string name, Location loc)
                {
-                       NamespaceEntry ns = new NamespaceEntry (parent, file, name);
+                       NamespaceEntry ns = new NamespaceEntry (parent, file, name, loc);
 
                        if (namespaces.Contains (file)){
                                Hashtable ns_ns = (Hashtable) namespaces [file];
 
-                               if (ns_ns.Contains (ns.Name))
-                                       return (NamespaceEntry) ns_ns [ns.Name];
-                               ns_ns.Add (ns.Name, ns);
+                               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.Name, ns);
+                               new_table.Add (ns.FullName, ns);
                        }
 
                        return ns;